Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re^2: undefined elements in array

by Anonymous Monk
on Aug 20, 2013 at 13:35 UTC ( #1050183=note: print w/replies, xml ) Need Help??


in reply to Re: undefined elements in array
in thread undefined elements in array

mapping function can quite nice for this type of thing..
e.g. @a = (1,2,3,undef,5); print $#a; @b = map(defined, @a); print join(',',@b);

Replies are listed 'Best First'.
Re^3: undefined elements in array
by Athanasius (Chancellor) on Aug 20, 2013 at 14:17 UTC

    I think you meant grep, not map:

    0:14 >perl -wE "@a = (1,2,3,undef,5); say scalar @a; @b = map(defined +, @a); print join(',', @b);" 5 1,1,1,,1 0:14 >perl -wE "@a = (1,2,3,undef,5); say scalar @a; @b = grep(define +d, @a); print join(',', @b);" 5 1,2,3,5 0:14 >

    Hope that helps,

    Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1050183]
help
Chatterbox?
[stevieb]: agreed. That's why I said at least a half-dozen. If enough of the different formats are present, the date/time folk may not have to request more. If they do, then at least there was a decent base to start with
[stevieb]: I do date and time transformations in both Perl and Python, but not frequently enough to not have to search for the format params etc ;)

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (3)
As of 2017-04-29 02:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I'm a fool:











    Results (531 votes). Check out past polls.