OK, I've searched for this one and I'm coming up blank, so I submit to the Wiser Ones for help.
I am trying to split a text file into many smaller files, breaking it down by blank lines. I have isolated the problem to a split function, but I'm baffled why this wouldn't work.
The function looks like this:
{
open (FILE,"<$input_file") or die "Couldn't open file $input_file, $!\
+n";
local $/ = undef;
$slurp = <FILE>;
close FILE;
}
@data = split (/\n{2,}/,$slurp);
Once I've got the data into an array, the rest is cake and works fine.
Now, if I use an input file I create on a *NIX machine, it works flawlessly as written. But, if the input file comes from a Windows machine, it doesn't work.
Now before you go clicking "--" and screaming about newline conversion, let me tell you what I've tried...
If I first run the file through VI and do a
:%s/^$/-==-/g and then change the SPLIT to cut on that string, it works fine. If I change the SPLIT to
/^$/ it doesn't work, everything ends up in
@data[0]. I've also tried:
- split (/^\s+$/,$slurp);
- split (/\r\n\r\n/,$slurp);
- split (/\0x0D\0x0A/,$slurp);
- split (/(?:\cM\cJ){2,}/,$slurp);
- split (/^\s+$|^\n+$|^$/,$slurp);
...And a few others too desperate to mention. None of these have any affect on this intractable file, the whole file always ends up in
@data[0]. My CTS is acting up, so I'm probably missing something really obvious here, or there's some not-well-documented way to accomplish this on DOS/Windows text files that I can't figure out, but the really confusing thing is that vi can do it easy and Perl can't. Any clues???
Signature void where prohibited by law.
2001-04-05 Edit by Corion : Corrected title