user2188468
user2188468

Reputation: 3

perl parsing command line arguments

i have a network and i want to assign all ip addresses a name. For this purpose i want to make a perl script that will print each ip on separate line from an ip range. I found a way via Net:IP but i can't figure out how to parse my command line ip range to the script (i am new with perl). My script looks like this:

#!/usr/local/bin/perl
use Net::IP;
my $test=join(' ',@ARGV);
my $ip = new Net::IP ('$test') || die;
do {
    print $ip->ip(), "\n";
} while (++$ip);

exit;

So my only problem is that the comand line syntax looks like this: perl ip.pl 192.168.10.1 - 192.168.10.255 and i can;t figure out how to parse this argument into my script after Net:IP (' here ').

Thanks for every idea.

Upvotes: 0

Views: 433

Answers (1)

Nate
Nate

Reputation: 1921

Change

my $ip = new Net::IP ('$test') || die;

to

my $ip = new Net::IP ($test) || die;

Single quotes will not evaluate your scalar.

Also, always

use strict;
use warnings;

Upvotes: 5

Related Questions