EOF issue

P

Peter Wyzl

Uri Guttman said:
PW> default.
PW> {
PW> local $/ = ''; #slurp mode

that is paragraph mode. undef is the value for slurp mode.
and File::Slurp is faster and a nicer API IMO :).

Oops. For the benefit of OT, I got away with that while testing because
there happen to be no 'paragraphs' in the sample file, so it all slurps into
one paragraph. Were there paragraphs in the file, strange things could
result. 'Slurp' mode is what I wanted. I also meant to add the caveat that
with large files this will consume lots of memory, but since you seem to be
assigning all the file to @chunk anyway I didn't think it would be a
problem.

Seems my sig got broken too... :(
 
I

IanW

Ben Morrow said:
Quoth "IanW said:
[..]

I don't understand the program logic here..
local $/ = '=' x 15 . "\n";

ok, so changing the input record separater to '=' x 15 . "\n" (referred to
as "=15" hereafter for convenience), effectively specifying how you're going
to split the file (I actually need the =15 when I output the chunks after
processing them, but I can add that back in when printing out to file).

...and you can get Perl to do that for you too, with

local $\ = $/;

in this case I've just done a:

print LH '=' x 15 ."\n";

before printing each chunk out, as the =15 needs to be before each chunk,
rather than after. However that's useful to know.

Thanks
IanW
 
I

IanW

[..]
that's going to slurp in all text up to and including "Line 3" in my
original example on the first pass of the loop.

Up to and including the first Line 3, and also including the =15 after it.
removes any newline characters from the very end of $chunk

It removes $/, which in this case is not just any newline, but also =15 [..]
So this says that we're going to process $chunk if it has an alphanumeric
character in it, which it would if the first chunk has been successfuly
slurped int?

The normal use of $/ implies the =15 would come after each of your records.
What you actually have is a =15 before each record. What's is the
difference? Well, you have an extra =15 at the start, which results (after
chomp) in an empty "record" the first time through the loop. So you have
to ignore that empty record.

OK, I see.. that's a clear explanation (well, even I understood it, first
read :)

I've used that method in the actual script and it's working nicely.

Thanks
IanW
 

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
474,163
Messages
2,570,897
Members
47,434
Latest member
TobiasLoan

Latest Threads

Top