in reply to converting strings to ints
I'm perfectly willing to explicitly convert the blank strings to 0. Is this the easiest way:
@arr1 = map {$_ eq "" ? 0 : $_} @arr1;
The blank strings are the only strings that cause a problem:
use strict; use warnings; use 5.010; say '1' + '2'; --output:-- 3
Why will perl silently convert non-blank strings to integers, but resist converting a blank string to 0? After all, perl converts a blank string to false in a boolean context. It seems like it would be a natural thing for perl to convert a blank string to 0 in a numeric operation.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: converting strings to ints
by BrowserUk (Patriarch) on Mar 20, 2010 at 14:29 UTC | |
|
Re^2: converting strings to ints
by Marshall (Canon) on Mar 20, 2010 at 16:35 UTC |