http://www.perlmonks.org?node_id=923139


in reply to cool way of manipulating array elements

Maybe map? and a util function to test for whether each element is a number - Scalar::Util?

use strict; use warnings; # or some other util function that can tell if it is a number... use Scalar::Util qw(looks_like_number); my @array = ('1','2','45','65','what is this?'); my @mod = map {if (looks_like_number($_)){$_*2} else {$_}} @array; print "$_\n" for @mod;

Hope this helps... (I am a bit Rusty, so be gentle...)

Just a something something...

Replies are listed 'Best First'.
Re^2: cool way of manipulating array elements
by pashanoid (Scribe) on Aug 30, 2011 at 08:18 UTC
    thank you! works great!

      If you want to modify the original array contents then you could modify BioLion's code thus:

      $_ *= 2 for grep {looks_like_number($_)} @array;
      True laziness is hard work