develooper Front page | perl.beginners | Postings from December 2002

parse out parts of dir / files /

Thread Next
Johnson, Shaunn
December 10, 2002 10:44
parse out parts of dir / files /
Message ID:

I'm having problems trying to parse out part
of a directory into variables. 

I start with this:

[snip script]

/usr/local/bin/perl -w
use diagnostics;

my $dest="/i/'Depression Management'/Mailing/dec2002_iso_images";

# Where is data coming from?
my $source="/i/'Depression Management'/Mailing/Dec2002";

foreach $group ( split(/\n/,`ls -d1 $source/06/*`) ) {
        print $group, "\n";

[/snip script]

And this is the results:

[snip results]

/i/Local Test Dir/Mail/December2002/06/first workgroup (emi).pdf
/i/Local Test Dir/Mail/December2002/06/prof arrange (test).pdf
 . . .
 . . .

[/snip results]

What I want is to parse out the path into 3 variables:

[broken logic]

foreach my $group ( split(/\n/,`ls -d1 $source/0*/*`) ) {
      ($bu, $pcgname)=($group =~ m/$source\/(0\d)\/(.*)/i);

[/broken logic]

How can I split  $group in to $source, any number (06 in this example)
and any file name listed after that (which will most likely include
white spaces in the names)?  In the above, I thought I was only
getting the digit and everything else into the TWO variables (but
I guess not) ...

Thanks for any suggestions!


Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About