Re: Why won't split() find \n?



jshock wrote:

The problem I am having is that I can't seem to split the metadata
into individual lines. I am using split(/\n/, $metadata) to split by
EOL characters, but it doesn't work.

I've tried replacing \n with other EOL characters: \lf, \cr, \nel,
\ff, \ls, ps -- but nothing seems to work. What am I doing wrong?


$metadata = system("mdls $unixPaths[0]"); #Run unix command mdls.
@metadataArray = split(/\n/, $metadata);

Examine your input data to verify a multi-line format, this is,
be sure line breaks are there as expected.


For the record -- I'm a perl newbie using MacBook Pro OS 10.4.8

@metadataArray = split(/\r/, $metadata);

Use "\r" for a Macintosh.

You can test to be sure,

$metadata =~ tr/\r/\n/;

This will convert \r to \n for your data.

Another method to test and confirm,

$metadata =~ s/\r/#\r/g;

You should see a pound sign (#) at the end of each line.

Other similar tests will verify what you have at
the end of each line.

Unix - \n
Windows - \r\n
Macintosh - \r

Purl Gurl

.