----- Original Message ----- From: "Ramprasad" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Friday, January 03, 2003 1:48 AM Subject: deleting elements of an array and push into new
> Hello all, > 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; There is probably a mroe elegant way of doing this, but... my @arr = qw( 01.html index.html aa.html bb.html cc.html dd.html ); my @new; my $count=0; for(@arr) { if(/^(index|default).*/) { push @new,$_; @arr=@arr[0..$count-1,$count+1..$#arr]; } $count++; } print Dumper([\@new,\@arr]); Shawn [snip] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]