Re: Why won't split() find \n?
- From: Purl Gurl <purlgurl@xxxxxxxxxxxx>
- Date: Wed, 31 Jan 2007 13:21:20 -0800
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
.
- References:
- Why won't split() find \n?
- From: jshock
- Why won't split() find \n?
- Prev by Date: Why won't split() find \n?
- Next by Date: Re: regexp
- Previous by thread: Why won't split() find \n?
- Index(es):