add another condition to the if/unless
poj#!/usr/bin/perl use strict; use XML::Simple; my $xml = do {local $/='';<DATA>} ; my $servers = XMLin($xml); my %seen=(); my @array=(); foreach my $server (@{$servers->{server}}) { my $lanip = $server->{LanIP}; $lanip =~s/\d+$/0/; push(@array, $lanip) unless ( $seen{$lanip}++ || $lanip eq ''); } print join "\n",@array; __DATA__ <xml> <server LanIP="192.169.30.123"/> <server LanIP=""/> <server LanIP="192.169.30.24"/> <server LanIP=""/> <server LanIP="192.169.31.126"/> <server LanIP="192.169.32.127"/> </xml>
In reply to Re^3: grep unique values , remove the blank spaces and store it in a variable
by poj
in thread grep unique values , remove the blank spaces and store it in a variable
by deep27ak
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |