Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: cool way of manipulating array elements

by BioLion (Curate)
on Aug 30, 2011 at 08:02 UTC ( [id://923139]=note: print w/replies, xml ) Need Help??


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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://923139]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (4)
As of 2024-04-19 23:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found