Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re^4: uninitialized value in join or string

by Win (Novice)
on Oct 31, 2005 at 14:40 UTC ( #504273=note: print w/replies, xml ) Need Help??


in reply to Re^3: uninitialized value in join or string
in thread uninitialized value in join or string

How could I substitute all the NULL values in an array and replace them with ' ' characters?
  • Comment on Re^4: uninitialized value in join or string

Replies are listed 'Best First'.
Re^5: uninitialized value in join or string
by Roy Johnson (Monsignor) on Oct 31, 2005 at 16:02 UTC
    @values = map { defined $_ ? $_ : '' } @values;
    Update: don't use map for transforming something into itself. If you're getting from a different source, though, this would be an appropriate technique.

    Caution: Contents may have been coded under pressure.
      This looks great. However, I would be very pleased if somebody could describe it in English. ;>
        map acts like a foreach loop, walking through an array (or list) and aliasing $_ to each element in turn. In addition to walking the list, though, map also constructs an array. The upshot is that you can transform an array with it.

        But explaining that just made me realize that you can get the same result with a foreach loop in this case:

        foreach (@values) { $_ = '' unless defined; }
        That should be more clear. It updates each undefined element of @values to be the empty string.

        Caution: Contents may have been coded under pressure.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (5)
As of 2022-05-18 09:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you prefer to work remotely?



    Results (70 votes). Check out past polls.

    Notices?