in reply to loop to remove negatives
Hi BluGeni,
You should prefer the more idiomatic syntax in Eliya’s solution.
Just thought I’d mention that the code snippet you give, which you say “doesn’t seem to do the job,” should actually work fine, except that there’s a semicolon missing after $i=0; in the for loop:
#!/usr/bin/perl use strict; use warnings; my @busi = ( -1, -42, 7, -17 ); for (my $i = 0; $i < @busi; $i++) { $busi[$i] =~ s/-//g; print "\$busi[$i] = $busi[$i]\n"; } __END__
Gives me:
$busi[0] = 1 $busi[1] = 42 $busi[2] = 7 $busi[3] = 17
as required.
HTH,
Athanasius <°(((>< contra mundum
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: loop to remove negatives
by dsheroh (Monsignor) on May 15, 2012 at 09:53 UTC |