[Chicago-talk] Why won't this work?

Richard Reina richard at rushlogistics.com
Wed Aug 1 08:31:57 PDT 2007


Andy,

Thanks so much for the response.  Your suggestion was vert elegant and efficient.

Thanks again,

Richard

Andy Lester <andy at petdance.com> wrote: 
On Aug 1, 2007, at 8:56 AM, Richard Reina wrote:

> foreach $def (@arr) {
>         if ($def eq "b") {
>              my $trash = shift  # get rid of (trash) b
>         }
> }
>
> print "@arr\n";
>
> "b" does not get eliminated?

Because you're shifting from @ARGV, not @arr.

The better way to do it is to replace the entire for loop with:

   @arr = grep { $_ ne 'b' } @arr;

xoxo,
Andy

--
Andy Lester => andy at petdance.com => www.petdance.com => AIM:petdance




_______________________________________________
Chicago-talk mailing list
Chicago-talk at pm.org
http://mail.pm.org/mailman/listinfo/chicago-talk



Your beliefs become your thoughts.  Your thoughts become your words.  Your words become your actions.  Your actions become your habits.  Your habits become your values.  Your values become your destiny.  -- Mahatma Gandhi
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.pm.org/pipermail/chicago-talk/attachments/20070801/1a64aa46/attachment.html 


More information about the Chicago-talk mailing list