The output function adds an extra blank line. We can specify the format, map an array and name the function.
sub print_as_lines { map { print "$_\n" } @_; }
This can not remove all the extra lines, because new lines were added while capturing the data, and before processing. The original line preformats the data for presentation. The function print_as_lines encapsulates the presentation operation.

The program also modifies user input without looking at it first. The following will look before leaping.

my $lanip = $server->{LanIP}; # no change on block entry # oops, this will format for output before processing $lanip .= "\n" unless $lanip =~ /\n$/; # no change if present #oops, did not validate input
The following xml has four blank lines, and the original code will make them five.
<lanIP> 192.168.42.7 </lanIP>
Do you see them all? The text node includes white space by default.
my $lanip = $server->{LanIP}; die "Value Error: not dotted quad notation->($lanip)" unless $lanip =~ + /(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})/; my $lanip = $1; # now this house is clean
Now you can add another function and wrap the for loop in a function.
sub unique_network { ... for each return @array } sub print_address { print_as_lines @_: } print_address( unique_network($servers) );

In reply to Re: grep unique values , remove the blank spaces and store it in a variable by brother_m
in thread grep unique values , remove the blank spaces and store it in a variable by deep27ak

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.