in reply to Re: changing a string to a numeric variable
in thread changing a string to a numeric variable

Why do you use grep here?
$_ = 'word 0 word'; my @a = grep {s/(?<=\d),(?=\d)//g || $_} split;
...will of course lose data.
$_ = 'word 0 word0,0word'; my @a = map {s/(?<=\d),(?=\d)//g; $_} split;
...will be better (as if there can be one wrong way better of another wrong way), but lose data too, btw.

Replies are listed 'Best First'.
Re: Re: Re: changing a string to a numeric variable
by pbeckingham (Parson) on Mar 19, 2004 at 00:24 UTC

    Tell me how it would "of course" lose data? It does work.

      web07:~[0]% perl $_ = 'word 0 word'; my @a = grep {s/(?<=\d),(?=\d)//g || $_} split; print join ':', @a, "\n"; ^D word:word: web07:~[0]%
      That '0' vanished because the grep-condition (s/...//g || $_) is false and grep is a filter.