Duarte Cordeiro wrote:
>
> Hi,
Hello,
> Background:
> I have a @filelist that can have (guess what) several filenames.
> I want to split the filenames in 3 arrays:
> - if the file is in a directory *\templatedata\*\data\ it should go to array1;
> - if the file is in a directory \binaries\* it should go to array2;
> - any other file should go to array3;
>
> My program is as follows, but I think someone around can make the same thing in 4 ir
>5 lines :)
> Several questions:
>
> 1) is there a way to specify on what var s/// works ?
> 2) any better way to see if the pattern matched ?
> 3) any smaller and faster way to do the same ?
>
>
> sub is_data {
> my $file = shift;
> $file=~s/(.*?)templatedata(*.?)data\\//sig;
> return $file;
> }
>
> sub is_binary {
> my $file = shift;
> $file=~s/^binaries//sig;
> return $file;
> }
>
> my @array1=();
> my @array2=();
> my @array3=();
> my @filelist=( "templatedata\\MyDir\\data\\0001.txt", "otherdir\\test.yxy",
>"binaries\\movie.jpeg");
> my $dummy;
> foreach my $file (@filelist){
> $dummy=is_data($file);
> if($dummy eq $file){
> $dummy=is_binary($file);
> if($dummy eq $file){
> push @array3, $dummy;
> }
> else
> {
> push @array2, $dummy;
> }
> }
> else
> {
> push @array1, $dummy;
> }
> }
push @{ /\btemplatedata\\[^\\]+\\data\\/ ? \@array1 :
/\bbinaries\\/ ? \@array2 :
\@array3
}, $_ for @filelist;
John
--
use Perl;
program
fulfillment
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]