in reply to Newbie question
That will work fine because the "-" character evaluates to zero in numeric context, anyway.my @digits = split //, abs; with: my @digits = split //, $_;
The warnings can be silenced by inserting:C:\_32\pscrpt>perl try.pl Argument "-" isn't numeric in addition (+) at try.pl line 10. Argument "-" isn't numeric in addition (+) at try.pl line 10. Argument "-" isn't numeric in addition (+) at try.pl line 10. -221 -21 1 1 3 5 21 34 89 144
into the oddDigitSum() subroutine:no warnings 'numeric';
Note that any "numeric" warnings triggered from outside the oddDigitSum() subroutine are still enabled.sub oddDigitSum { no warnings 'numeric'; my @ans; for(@_) { my @digits = split //, $_; my $sum; $sum += $_ for @digits; $sum % 2 && push @ans, $_; } return @ans; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Newbie question
by Marshall (Canon) on Aug 23, 2022 at 11:44 UTC | |
by NERDVANA (Priest) on Aug 23, 2022 at 19:57 UTC | |
by oldB51 (Sexton) on Aug 23, 2022 at 12:58 UTC | |
by Anonymous Monk on Aug 23, 2022 at 12:46 UTC | |
by Marshall (Canon) on Aug 23, 2022 at 15:48 UTC | |
|
Re^2: Newbie question
by oldB51 (Sexton) on Aug 23, 2022 at 12:49 UTC | |
by hippo (Archbishop) on Aug 23, 2022 at 15:31 UTC | |
by oldB51 (Sexton) on Aug 23, 2022 at 16:06 UTC |