I think it is a mistake to keep $/ undefined during the call to scan() and I'd close the file before that point as well. So I get something more like:
I don't like autovivification of file handles. Putting the my inside of the open and flagging the script as requiring 5.6 makes them tolerable. I'd put "use 5.6" in there but I think "use 5.6" gives strange errors on rather recent versions of Perl, so I'm holding off on using it for a while longer.sub scanfile { croak "Usage: scanfile(\$filename)" unless 1 == @ARGV; my $data= do { my $filename= shift; require 5.6; # Autovivification of file handle: open my $handle, '<', $filename or croak "Can't read file [$filename], $!"; local $/; <$handle>; }; return scan( $data ); }
At first I just had a normal block and set $data inside of the block. That is fine. I just switched to a do block so that it becomes clear that the point of the block is to set $data. YMMV.
- tye (but my friends call me "Tye")In reply to (tye)Re: Code Review on Several Interesting Points
by tye
in thread Code Review on Several Interesting Points
by John M. Dlugosz
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |