nmerriweather has asked for the wisdom of the Perl Monks concerning the following question:

Python has something called list comprehension
myInts= [ int(i) for i in getItems() ]
i know there's some way to do this in perl using map, i just can't figure it out.
i'm specifically trying to int the y/m/d in a date
( y , m , d )= [ int(i) for i in date.split('-') ]

Replies are listed 'Best First'.
Re: list comprehension
by duckyd (Hermit) on Aug 25, 2006 at 19:01 UTC
    I suspect you want something like:
    my ( $y, $m, $d ) = map { int } split /-/, '2006-04-03.14159';
    Note that int operates on $_ by default, the above is equivalent to map { int($_) }
      Or:
      my ( $y, $m, $d ) = '2006-04-03.14159' =~ /\d+/g;
      thats it. thanks!

        Or even (TMTOWTDI):

        my ( $y, $m, $d ) = unpack 'A4xA2xA2', $str;