Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re^4: restrict use of regex module in script

by AnomalousMonk (Archbishop)
on Apr 08, 2017 at 00:02 UTC ( [id://1187444]=note: print w/replies, xml ) Need Help??


in reply to Re^3: restrict use of regex module in script
in thread restrict use of regex module in script

{ local $/; # slurp in a file my $contents = <$fh> ... } # now we go back to reading a file line-by-line again while (<$fh>){ ... }

Parenthetic note: in the quoted example code, the  $fh file handle would become "exhausted" after the "slurp" read to  $contents and the subsequent while-loop read of the handle would produce nothing. A seek operation is needed to reset the logical file position back to the beginning of the file (update: or at least to somewhere other than the end) so that subsequent reads may be successful. Try the following code without the seek statement:

c:\@Work\Perl\monks\pmpmmpmp>perl -wMstrict -le "open my $fh, '<', 'junk.txt' or die $!; ;; my $contents = do { local $/; <$fh>; }; print qq{[[$contents]]}; ;; seek $fh, 0, 0; print 'now we go back to reading a file line-by-line again'; while (<$fh>){ print qq{<<$_>>}; } " [[line 1 fee fie foe line 2 wibble wobble line 3 blah yada ]] now we go back to reading a file line-by-line again <<line 1 fee fie foe >> <<line 2 wibble wobble >> <<line 3 blah yada >>


Give a man a fish:  <%-{-{-{-<

Replies are listed 'Best First'.
Re^5: restrict use of regex module in script
by stevieb (Canon) on Apr 08, 2017 at 00:37 UTC

    Indeed. I was going to create a second handle for the latter example, but forgot :)

    update: I've updated my original reply to the OP to point to your update, which technically is extremely informative./update

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1187444]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (5)
As of 2024-04-18 03:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found