develooper Front page | perl.beginners | Postings from April 2010

Using backtick operator output and feeding it into array

Thread Next
From:
Lonnie Ellis
Date:
April 21, 2010 12:48
Subject:
Using backtick operator output and feeding it into array
Message ID:
7EB1FF600E169C46A1720CAA52338F85062E381F@del-exchange1.nationwide.net
I'm pretty new to perl, and can't seem to get the following bit of code
to work.  If I print the array while in the sub, it returns what I want
but outside of the sub it doesn't recognize it.  Aren't all variable
global by default unless told otherwise with "my"?  Here is code below,
any help would be appreciated.

 

#!/usr/bin/perl

 use 5.010;

 use diagnostics;

 # use strict;

 use Data::Dumper;

 

 sub getDig {

    $net = "10.0.1";

    @num = (1..254);

    @digOutput = ();

 

    foreach (@num) {

       $ipaddie = $net . ".$_";

       (@digOutput) = `dig -x $ipaddie +short`;

    }

    return \@digOutput;

 }

 

my @c = getDig();

my $dumped = Dumper(\@c);

print $dumped;


Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About