Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re^3: Test if multiple variables are defined

by Laurent_R (Parson)
on Jun 26, 2013 at 21:02 UTC ( #1040841=note: print w/ replies, xml ) Need Help??


in reply to Re^2: Test if multiple variables are defined
in thread Test if multiple variables are defined

Yes, you are right and I definitely know it. As noted in my update above, I really meant to write:

s/^\s+|\s+$//g for grep {defined $_} ( $ipaddress, $prefix, $interface, $device, $location);

But, as I also said in my update, that does not work as I expected, the "for" does not seem to deliver to the s/// statement the elements supplied by the grep. I got it working quite easily using a map instead of a for, but it no longer has the relative cleverness I was looking for.


Comment on Re^3: Test if multiple variables are defined
Download Code
Re^4: Test if multiple variables are defined
by Eily (Hermit) on Jun 26, 2013 at 22:06 UTC

    use strict; use warnings; use Data::Dumper; my ( $ipaddress, $prefix, $interface, $device, $location) = ('no_ws', +' some_ws ', undef, ' lotsa ws ', undef); s/^\s+|\s+$//g for grep {defined $_} ( $ipaddress, $prefix, $interface +, $device, $location); print Dumper ( $ipaddress, $prefix, $interface, $device, $location);
    (Thanks AnomalousMonk for the strings :D). So this yields:
    $VAR1 = 'no_ws'; $VAR2 = 'some_ws'; $VAR3 = undef; $VAR4 = 'lotsa ws'; $VAR5 = undef;
    It works fine.

Re^4: Test if multiple variables are defined
by Laurent_R (Parson) on Jun 28, 2013 at 18:52 UTC

    Alright, I must have done something else wrong in my test. Thank you for your message.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (10)
As of 2014-09-30 10:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

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











    Results (363 votes), past polls