-----Original Message----- From: John W. Krahn [mailto:[EMAIL PROTECTED] Sent: Monday, July 24, 2006 3:36 PM To: Perl Beginners Subject: Re: Regex find and replace - delete line
Chris Charley wrote: > > ----- Original Message ----- From: ""John W. Krahn"" <[EMAIL PROTECTED]> >> >> And if you want to do it with one loop: >> >> >> for my $i ( reverse 0 .. $#file ) { >> splice @file, $i, 1 if /foo/; >> } > > Hi John > > Shouldn't the above read like: > > for my $i ( reverse 0 .. $#file ) { > splice @file, $i, 1 if $file[$i] =~ /foo/; Yes it should, sorry about that mistake. John -- use Perl; program fulfillment -- I tested this code #!/usr/bin/perl use strict; use warnings; my @file = (); @file = qq(foo, derek, smith, bar); for my $i ( reverse 0 .. $#file ) { splice @file, $i, 1 if $file[$i] =~ /foo/; } print @file; and it prints nothing. I thought the goal was to just splice the element that matched foo??? I changed it to #!/usr/bin/perl use strict; use warnings; my @file = (); @file = qq(foo, derek, smith, bar); for my $i ( reverse 0 .. $#file ) { splice @file, $i, 1 if $file[$i] eq "foo"; } print @file; and it prints foo, derek, smith, bar _________________________________________________ This message is for the designated recipient only and may contain privileged, proprietary, or otherwise private information. If you have received it in error, please notify the sender immediately and delete the original. Any other use of the email by you is prohibited. Dansk - Deutsch - Espanol - Francais - Italiano - Japanese - Nederlands - Norsk - Portuguese - Svenska: www.cardinalhealth.com/legal/email -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>