Shaunn Johnson wrote:
>
> Howdy:
Hello,
> 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/*`) ) {
Ick, ick, ick! Calling an external program through backticks and then
splitting the results. You should use the tools that Perl provides for
reading directory entries.
foreach my $group ( glob "$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) ...
foreach my $group ( glob "$source/0[0-9]/*" ) {
my ( $bu, $pcgname ) = $group =~ m!\Q$source\E/(0\d)/(.*)!;
# OR
chdir $source or die "Cannot chdir to $source: $!";
foreach my $group ( glob "0[0-9]/*" ) {
my ( $bu, $pcgname ) = split /\//, $group;
John
--
use Perl;
program
fulfillment
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]