Brian wrote:
Hello
Hello,
Years ago I used to work with FORTRAN, RPG GAP 2 and a smidgeon of basic.
Code was written one line at a time, the first section of code was Input
data, the next section was calculations, the last section was output.
(For example, in the sample of code below, the "while" line would have
been written on one line instead of 3)
Why is it "good practice" to write PERL the way it is done?
Why is it that some code has no curly braces after print; whilst in
others I sometimes see one or more curly braces after it?
Will there be a time when print; will fail because there isn't a curly
brace following it, even though an equal number of left & right braces
precede it?
I appreciate I have the right to lay out my code in any way I see fit, I
would just like to see the reasoning.
An example of something confusing me is in the sample below
find sub {
return unless -f;
open my $FH, '<', $_ or die "Cannot open '$_' $!";
while ( <$FH> ) {
/\Q$string/ && print $REPORT "$File::Find::name\n" and
return;
}}, '/test';
Why isn't the last line
}, '/test';}
The first } is the end of the while block and the second } is the end of
the anonymous subroutine and ", '/test';" is the second argument to
find() and not part of the anonymous subroutine. Another way to write
that is:
sub wanted {
return unless -f;
open my $FH, '<', $_ or die "Cannot open '$_' $!";
while ( <$FH> ) {
/\Q$string/ && print $REPORT "$File::Find::name\n" and return;
}
}
find \&wanted, '/test';
John
--
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order. -- Larry Wall
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/