I have a script as below which is taking input from a xml file
#!/usr/bin/perl -w
use strict;
use XML::Simple;
my $servers = XMLin('file.xml');
my %seen;
foreach my $server (@{$servers->{server}}) {
my $node = $server->{Node} . "\n";
my $lanip = $server->{LanIP} . "\n";
my $mask = $server->{Netmask} . "\n";
substr($lanip, 11, 3) = "0";
push(my @array, $lanip) if ! $seen{$lanip}++;
print "@array\n";
Here as you see I am substituting the last digit of the IP with '0' which gives me a bunch of IPs but I only want to grep unique IPs. With current script I get below output
192.169.30.0
192.169.31.0
192.169.32.0
192.169.72.0
Lots of blank spaces. I want to remove them and store it into a global variable/array which can be used later.
The output should be something like below
192.169.30.0
192.169.31.0
192.169.32.0
192.169.72.0
Also if possible I am trying to do this without List::MoreUtils Module.
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.