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:

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 ); }
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.

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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.