update: Hmmm, I saw no mention of that, oh well: "you live you die, it's all for perl and peanuts ;-)".#!/usr/bin/perl -w =head1 CONFUSION, SELF-DOUBT, AND BEER =begin text ## Well this test script was propted by a query on File::Slurp and la +ter file slurp which led me to 'Slurp a file' (http://perlmonks.com/i +ndex.pl?node_id=50525) by AnonymousMonk: Description: Slurp a file into a scalar. Jean-Daniel Gamache webmaster +@perls.org open (IN, "<myfile.txt"); {local $/; $file_content = <IN>;} print $file_content; ## Then davorg (man with the munchies) replies with: Oops. You've just left $/ set to undef for the rest of the program. Th +is can lead to all sorts of nastiness. Better to do something like this: my $file_text; { local $/; $file_text = <FILE>; } print $file_text; Which returns $/ to its original value once you leave the bare block. -- <http://www.dave.org.uk> "Perl makes the fun jobs fun and the boring jobs bearable" - me ## This really had me confused. The original post had a block, it doesn't matter (and 'the Rock' chime +s in 'It doesn't matter!') where you declare $file_content, as it has + no bearing on local or $/ since {;;;;;} is a valid block!.... I was kind of in doubt of my faculties for a split second, and then I +scrolled down the page, and found an AnonymousMonk node saying "Sorry +, you were right!" Then it came to me (in a vision =;:): davorg had been coding drunk aga +in. ... there's always a valuable lesson to be learned ... keep (c|n)ode +-ing =end =cut # some quick test code print '$/',"is = '$/';\n"; { local $/; # in effect, makes $/ uninitialized print '$/',"is = '$/';\n"; print <DATA>; } print '$/',"is = '$/';\n"; __DATA__ I AM DATA
___crazyinsomniac_______________________________________
Disclaimer: Don't blame. It came from inside the void
perl -e "$q=$_;map({chr unpack qq;H*;,$_}split(q;;,q*H*));print;$q/$q;"
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: CONFUSION, SELF-DOUBT, AND BEER
by davorg (Chancellor) on Jun 29, 2001 at 13:09 UTC | |
|