in reply to grep unique values , remove the blank spaces and store it in a variable
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.sub print_as_lines { map { print "$_\n" } @_; }
The program also modifies user input without looking at it first. The following will look before leaping.
The following xml has four blank lines, and the original code will make them five.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
Do you see them all? The text node includes white space by default.<lanIP> 192.168.42.7 </lanIP>
Now you can add another function and wrap the for loop in a function.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
sub unique_network { ... for each return @array } sub print_address { print_as_lines @_: } print_address( unique_network($servers) );
|
|---|