Here's the problem:
My input looks like the following:
C:\Perl\scripts\shots\sp2\shot_1\dir.txt C:\Perl\scripts\shots\sp2\shot_1\drames.txt C:\Perl\scripts\shots\sp2\shot_1\filename.0001.cin
[snip]
C:\Perl\scripts\shots\sp2\shot_1\sub_directory\basename.0008.rgb C:\Perl\scripts\shots\sp2\shot_1\sub_directory\basename.0009.rgb C:\Perl\scripts\shots\sp2\shot_1\sub_directory\basename.0010.rgb
I want my output from the subroutine to look like the following:
filename filename filename
[snip]
basename basename basename
The following is the code:
#!/usr/bin/perl -w use strict;
my @paths = `dir /b/s`; # print @paths;
Using back-ticks will return newline terminated strings that you have to chomp to remove the newlines.
chomp( my @paths = `dir /b/s` );
my @basenames = &basenames(@paths);
sub basenames { foreach (@_) { if ($_ =~ /(\w+)\.\d+\.\w+$/) { @basenames = $1; # print "@basenames\n"; } } }
Everything looks OK when I do the test prints. But, I'm not getting output from the subroutine. What's the correct way to get this return? The OS is Window$.
If you just want to fix the subroutine then this will work:
sub basenames { map /(\w+)\.\d+\.\w+$/, @_; }
However you may want to use the File::Find module instead of using `dir /b/s`.
#!/usr/bin/perl use warnings; use strict; use File::Find;
my @basenames; find( sub { push @basenames, /(\w+)\.\d+\.\w+$/ }, '.' );
print "$_\n" for @basenames;
__END__
John -- use Perl; program fulfillment
-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>