On Thu, Aug 23, 2012 at 05:19:34PM -0400, Shawn H Corey wrote:
> You're trying to do too much in one statement.
>
> for my $coord ( @coords ){
> if( $coords->[0] >= 0 ){
> print join( q{, }, @{ $coords } ), "\n";
> }
> }
Looks like you're trying to do too much too. ;) You are testing
$coords->[0] (an array reference) instead of testing $coord->[0].
You are also printing all elements of @{$coord->[0]} (erroneously
@coords in the original post, which would have printed array
references of the first element in @coords each iteration through
the loop) instead of printing the single $coord->[0] that
satisfies the condition this iteration. The newline might also be
undesirable, but that's easily resolved. :) Lastly, if the OP's
code depended on `$,' then you would need additional (ugly) code
to manage that properly within a single loop.
I'd say this is a lot easier to read than the loop:
print grep $_ >= 0, map $_->[0], @coords;
A more correct loop might look like:
for my $coord (@coords) {
my $field = $coord->[0];
if($field >= 0) {
print $field; # Assuming $, isn't being used.
}
}
I'd say the use of q// is unnecessary and noisy, and the use of
{} around the array dereferencing is also noisy. Assuming the
original print statement were correct, I think it would be
written a lot more clearly as:
print join(', ', @$coords), "\n";
B\
:-)
B-)
Disclaimer: I reserve the right to be completely wrong.
Regards,
--
Brandon McCaig <[email protected]> <[email protected]>
Castopulence Software <https://www.castopulence.org/>
Blog <http://www.bamccaig.com/>
perl -E '$_=q{V zrna gur orfg jvgu jung V fnl. }.
q{Vg qbrfa'\''g nyjnlf fbhaq gung jnl.};
tr/A-Ma-mN-Zn-z/N-Zn-zA-Ma-m/;say'
signature.asc
Description: Digital signature
