Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: undefined elements in array

by tachyon (Chancellor)
on Sep 10, 2001 at 02:39 UTC ( #111344=note: print w/ replies, xml ) Need Help??


in reply to undefined elements in array

This is simple:

print $array[$i][$j] if defined $array[$i][$j];

Or alternatively:

if (defined $array[$i][$j]) { print $array[$i][$j]; } else { print ''; }

cheers

tachyon

s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print


Comment on Re: undefined elements in array
Select or Download Code
Re^2: undefined elements in array
by Anonymous Monk on Aug 20, 2013 at 13:35 UTC
    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);

      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://111344]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (10)
As of 2014-09-17 08:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (70 votes), past polls