convenientstore has asked for the wisdom of the Perl Monks concerning the following question:
I thought setting $/ to undef would make record separated by one blank line or more.. and resulted in each record w/ separate line number
Instead I am getting number 1 and then entire information being printed.
Did I misunderstand the $/ ? or am I looping it wrong?I was expecting a result like this
--expected results-- 1hi hi hi 2hi hi 3hi hi
------------------------------------------
[root@myserver tmp]# cat perl_slurp.pl #!/usr/bin/perl -w use strict; sub slurpie { local $/ ; while (<DATA>) { print "$. $_\n"; } } slurpie(); __DATA__ hi hi hi hi hi hi hi [root@myserver tmp]# ./!$ ./perl_slurp.pl 1 hi hi hi hi hi hi hi ___________________________________________________________
*** UPDATE***
I am confused.. how does differ using $/ in inside of while loop vs outside.. local is immediate block so it should be inside of while loop?
#!/usr/bin/perl -w use strict; sub slurpie { while (<DATA>) { local $/ ; next unless /^\d+/; print "$. $_"; } } slurpie(); __DATA__ hi hi 234 hi hoi sdfsdfsdf23423 hi hi hi 1234 1 [root@myserver tmp]# ./!$ ./././././././././perl_slurp.pl 3 234 12 1234 14 1
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: $/ question
by davidrw (Prior) on Jan 13, 2008 at 02:56 UTC | |
by convenientstore (Pilgrim) on Jan 13, 2008 at 03:13 UTC | |
by convenientstore (Pilgrim) on Jan 13, 2008 at 03:40 UTC | |
by kyle (Abbot) on Jan 13, 2008 at 03:47 UTC | |
by convenientstore (Pilgrim) on Jan 13, 2008 at 03:55 UTC | |
|