in reply to Re: Round numbers?
in thread Round numbers?

Because I am new to Perl and don't understand it that much, can you please tell me how these lines interpret?
for my $n (@nra) { my $fmt = $n > 0.001 ? '%5.2g' : '%5.3g'; printf qq{$fmt \n}, $n; }

It's like:
for my $n (@nra) { my $fmt=$n; if($n>0.001){ ????? } else { ?????? } printf qq{$fmt \n}, $n; }

Thank you for your time!

Replies are listed 'Best First'.
Re^3: Round numbers?
by AnomalousMonk (Archbishop) on Oct 02, 2009 at 00:05 UTC
    No, like:
    for my $n (@nra) { my $fmt; if ($n > 0.001){ $fmt = '%5.2g'; } else { $fmt = '%5.3g'; } printf qq{$fmt \n}, $n; }
    See Conditional Operator in perlop.

    Note that
        $x = $y > $z ? 'foo' : 'bar';
    is perhaps more clearly written as
        $x = ($y > $z) ? 'foo' : 'bar';

      A million thanx to you! It was very kind you explained all that to me!