0

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.

1
  • 2
    my $test = join(' ', @ARGV); "$test"; can also be written as "@ARGV". Commented Mar 19, 2013 at 22:27

1 Answer 1

5

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;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.