in reply to Re: Idiomatic Perl
in thread Idiomatic Perl

In the spirit of TIMTOWTDI and my well-beloved ternary abuse (which I like since many other languages have it):

$total += looks_like_number($increment) ? $increment : 0

Replies are listed 'Best First'.
Re: Re: Re: Idiomatic Perl
by Limbic~Region (Chancellor) on Mar 02, 2004 at 20:24 UTC
    flyingmoose,
    This won't work for the reason I described above. If $increment is undefined looks_like_number will still return true.
    #!/usr/bin/perl use strict; use warnings; use Scalar::Util 1.10 'looks_like_number'; my $total = 4; my $increment; $total += looks_like_number($increment) ? $increment : 0 __END__ Use of uninitialized value in addition (+) at blah.pl line 9.
    Cheers - L~R
      Fair enough. That was typed in the middle of a boring telecom (as are most of my posts), so that explains my inability to read.