Charles K. Clarkson wrote:
Andrew Gaffney <[EMAIL PROTECTED]> wrote:
: : I've modified your code to be more like it is in my program:
: : #!/usr/bin/perl
: : use strict;
: use warnings;
: use Data::Dumper 'Dumper';
: : my $array1 = ['test1', 'test2', 'test3', 'test4', '!test5', : 'test6', 'test7'];
: : print Dumper $array1;
: : for my $lv (0..$#{$array1}) {
: splice @$array1, $lv, 1 if($array1->[$lv] =~ /^!/);
: }
: : print Dumper $array1;
: : This doesn't quite work because I'm removing elements
: from the array I'm looping through. What would be the
: best way to take care of this?



Don't use splice: :)

print Dumper $array1;

@$array1 = grep ! /^!/, @$array1;

print Dumper $array1;

Well, I'm working with the data in the array at the same time I'm trying to remove certain elements. I need to process the elements that start with a '!' and then remove them. I process all other elements differently.


--
Andrew Gaffney
Network Administrator
Skyline Aeronautics, LLC.
636-357-1548


-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>




Reply via email to