On Feb 22, 2013, at 10:40 AM, Andy Bach wrote:
> On Fri, Feb 22, 2013 at 12:08 PM, Tiago Hori <[email protected]> wrote:
>
>> What I was wondering is: is there any way to force perl to use other line
>> ending characters, like MacOS CR?
>>
Another approach is to read the entire file into a scalar and then split on the
regular expression [\r\n]+
Read the file into a scalar:
my $content = do { local $/; <$fh> };
or using the File::Slurp module:
my $content = read_file($filename);
Then split into lines:
my @lines = split(/[\r\n]+/,$content);
You do end up with two copies of the file contents, so this method is not
efficient in terms of memory usage.
--
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
http://learn.perl.org/