What about a simple grep like this?

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

The syntax above might not be perfect, there may be a comma or something else needed, but it conveys the idea, I think.

UPDATE:

I typed the above without having a chance to test and I stupidly misplaced my "for". I really meant to write:

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

That probably makes much more sense (the "for" is totally useless between the grep block and the list, but, as placed now, it should give the grep results one by one aliased to $_ to the s/// statement), but that still does not work properly (for some reason, I have trouble using for and foreach with map or grep, it often does not really work the way I expect). So, having now a chance to test, I can change it somewhat to get it working the way I wanted:

my @result = map {s/^\s+|\s+$//g; $_}  grep {defined $_} ( $ipaddress, $prefix, $interface, $device, $location);

or simply

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

However, using map in this context is probably not be the best, because it is not completely obvious to the eye that the elements of the original list are modified by the command.


In reply to Re: Test if multiple variables are defined by Laurent_R
in thread Test if multiple variables are defined by stroke

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.