Why won't split() find \n?
- From: "jshock" <joeshockey@xxxxxxxxx>
- Date: 31 Jan 2007 13:05:21 -0800
I am writing a script to read the metadata from a bunch of mp4 flies
in a directory, then grab bits of info from the metatags. I am using
system("mdls $filename") to read the metadata.
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?
I've got a test print statement at the bottom that's supposed to ad
the text "EOL" at the end of each line. Here's my script so far:
#!/usr/bin/perl -w
###############
# Init Variables
$directory = "/Users/joe/Movies/Already Backed Up/";
###############
# Read the directory contents
opendir(DOCS, $directory); #opens the directory
@rawContents = readdir(DOCS);
foreach(@rawContents) {
if($_ !~ /^\./) { #Ignore files that start with a period.
push(@fileNames, $_); #Create a new array with just the live files
}
}
###############
# Convert filenames to unix paths
foreach(@fileNames) {
push(@filePath, $directory.$_); #Add the directory path to the file
names
}
foreach(@filePath) {
($_ =~ s/ /\\ /g);
push(@unixPaths, $_);
}
###############
# Get the metada
$metadata = system("mdls $unixPaths[0]"); #Run unix command mdls.
@metadataArray = split(/\n/, $metadata);
###############
# Test print
foreach(@metadataArray) {
print("$_ EOL\n");
}
For the record -- I'm a perl newbie using MacBook Pro OS 10.4.8. I'm
running perl scripts via terminal/bash.
.
- Follow-Ups:
- Re: Why won't split() find \n?
- From: Purl Gurl
- Re: Why won't split() find \n?
- Prev by Date: Capture Exit Code Using Pipe & Tee
- Next by Date: Re: Why won't split() find \n?
- Previous by thread: Capture Exit Code Using Pipe & Tee
- Next by thread: Re: Why won't split() find \n?
- Index(es):
Relevant Pages
|
|