Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > What's the effect of a null input record separator?

Reply
Thread Tools

What's the effect of a null input record separator?

 
 
here@softcom.net
Guest
Posts: n/a
 
      10-19-2013
Given the one-liner:

perl -0ne 'print "$ARGV\n" if [some condition];' *

What effect does the -0 have on each file? I know the values for paragraph mode 00 and file slurp mode 0777, but I can't find a definitive answer on when $/ is set to the null character.
 
Reply With Quote
 
 
 
 
Bjoern Hoehrmann
Guest
Posts: n/a
 
      10-19-2013
* http://www.velocityreviews.com/forums/(E-Mail Removed) wrote in comp.lang.perl.misc:
>Given the one-liner:
>
>perl -0ne 'print "$ARGV\n" if [some condition];' *
>
>What effect does the -0 have on each file? I know the values for
>paragraph mode 00 and file slurp mode 0777, but I can't find a
>definitive answer on when $/ is set to the null character.


http://search.cpan.org/perldoc?perlvar "Trying to set the record size
to zero or less will cause reading in the (rest of the) whole file."
--
Björn Höhrmann · (E-Mail Removed) · http://bjoern.hoehrmann.de
Am Badedeich 7 · Telefon: +49(0)160/4415681 · http://www.bjoernsworld.de
25899 Dagebüll · PGP Pub. KeyID: 0xA4357E78 · http://www.websitedev.de/
 
Reply With Quote
 
 
 
 
sybilfriedman@gmail.com
Guest
Posts: n/a
 
      10-19-2013
On Saturday, October 19, 2013 8:38:35 AM UTC-7, (E-Mail Removed) wrote:
> Given the one-liner:
>
>
>
> perl -0ne 'print "$ARGV\n" if [some condition];' *
>
>
>
> What effect does the -0 have on each file? I know the values for paragraph mode 00 and file slurp mode 0777, but I can't find a definitive answer on when $/ is set to the null character.

 
Reply With Quote
 
here@softcom.net
Guest
Posts: n/a
 
      10-19-2013
On Saturday, October 19, 2013 8:38:35 AM UTC-7, (E-Mail Removed) wrote:
> Given the one-liner:
>
>
>
> perl -0ne 'print "$ARGV\n" if [some condition];' *
>
>
>
> What effect does the -0 have on each file? I know the values for paragraph mode 00 and file slurp mode 0777, but I can't find a definitive answer on when $/ is set to the null character.


########################

So does that mean that -0 on the command line is equivalent to:

undef $/;
while (<>) {
...
}

 
Reply With Quote
 
John W. Krahn
Guest
Posts: n/a
 
      10-19-2013
(E-Mail Removed) wrote:
> Given the one-liner:
>
> perl -0ne 'print "$ARGV\n" if [some condition];' *
>
> What effect does the -0 have on each file? I know the values for
> paragraph mode 00 and file slurp mode 0777, but I can't find a
> definitive answer on when $/ is set to the null character.


$ perl -MO=Deparse -0ne 'print "$ARGV\n" if [some condition];' *
BEGIN { $/ = "\000"; $\ = undef; }
LINE: while (defined($_ = <ARGV>)) {
print "$ARGV\n" if ['condition'->some];
}
-e syntax OK

The value "\0" will be used as the record separator so if you have a
"text" file it is the same as slurp mode but if you have a "binary" file
you will get as many records as there are "\0" characters in the file.


John
--
Any intelligent fool can make things bigger and
more complex... It takes a touch of genius -
and a lot of courage to move in the opposite
direction. -- Albert Einstein
 
Reply With Quote
 
Tim McDaniel
Guest
Posts: n/a
 
      10-19-2013
In article <(E-Mail Removed)>,
Ben Morrow <(E-Mail Removed)> wrote:
>
>Quoth (E-Mail Removed):
>> * (E-Mail Removed) wrote in comp.lang.perl.misc:
>> >Given the one-liner:
>> >
>> >perl -0ne 'print "$ARGV\n" if [some condition];' *
>> >
>> >What effect does the -0 have on each file? I know the values for
>> >paragraph mode 00 and file slurp mode 0777, but I can't find a
>> >definitive answer on when $/ is set to the null character.

>>
>> http://search.cpan.org/perldoc?perlvar "Trying to set the record
>> size to zero or less will cause reading in the (rest of the) whole
>> file."

>
>Not relevant. That's talking about $/ = \0,


Do you mean
$/ = 0
or is there something special about a scalar reference to 0?

--
Tim McDaniel, (E-Mail Removed)
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
What was the project that made you feel skilled in Python? Ned Batchelder Python 2 05-20-2013 03:16 PM
Re: What was the project that made you feel skilled in Python? Chris Angelico Python 0 05-19-2013 11:48 AM
What is the reason for defining classes within classes in Python? vasudevram Python 6 04-24-2013 01:29 PM
what is the advantage of using maven for java standalone app mcheung63@gmail.com Java 13 04-16-2013 01:42 AM
Windows 8 - so bad it's hastening the death of the PC? ~misfit~ NZ Computing 18 04-15-2013 04:15 AM



Advertisments