Ramprasad wrote:
> 
> Hello all,

Hello,

>     I have to remove elements from an array if they match a particualr
> string and put it into another array
> 
> eg if element matches index or default I want it to be in a new array
> 
> I am trying this
> my @arr = qw( 01.html index.html aa.html bb.html cc.html dd.html );
> 
> # the following does not compile
> #map {s/^(index|default).*/{push @new,$_}/e && delete $_  } @arr;
> 
> #This works but it does not remove the array element
> map {s/^(index|default).*/{push @new,$_}/e && undef $_  } @arr;
> 
> print Dumper([\@new,\@arr]);
> 
> I get
>   $VAR1 = [
>            [
>              'index.html'
>            ],
>            [
>              '01.html',
>              undef,
>              'aa.html',
>              'bb.html',
>              'cc.html',
>              'dd.html'
>            ]
>          ];
> 
> the element $arr[1] is undefed but not removed from the array
> 
> Can I delete the element somehow
> I am going to run this for about 60,000 arrays and I cant afford
> needless if's and foreach's


my @new;
my @arr = qw( 01.html index.html aa.html bb.html cc.html dd.html );

push @{ /^(?:index|default)/ ? \@new : \@arr }, $_ for splice @arr;

print Dumper( [ \@new, \@arr ] );




John
-- 
use Perl;
program
fulfillment

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to