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

H

here

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.
 
B

Bjoern Hoehrmann

* (e-mail address 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."
 
S

sybilfriedman

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.
 
H

here

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 (<>) {
...
}
 
J

John W. Krahn

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
 
T

Tim McDaniel

Quoth (e-mail address removed):
* (e-mail address 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?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,822
Latest member
israfaceZa

Latest Threads

Top