in reply to Re: Reading IP from a file and SNMP
in thread Reading IP from a file and SNMP

There is still the question of the reading of the IPs in the file?? Thanks for wellcoming me and for the help already... I got some interseting piece of code :-) just got to understand it now.

Replies are listed 'Best First'.
Re^3: Reading IP from a file and SNMP
by radiantmatrix (Parson) on Aug 26, 2004 at 14:06 UTC
    I highly suggest getting copies of Learning Perl, Programming Perl, and The Perl Cookbook.

    To get you started, you can read files like this:

    open FH, '<', $filename or die ("Can't open $filename"); #FH is a "filehandle", and the '<' means "open in read mode" #('>' would be write) while (<FH>) { #the angles around FH mean "read a line" work_with_the_line($_); # $_ holds the current line in this case # work_with_the_line would be a subroutine defined by you } close FH; #don't forget to close files!
    Much perl code is out there "in the wild", I highly suggest searching to see if someone has solved a similar problem, then reading and learning from their source.
    --
    $me = rand($hacker{perl});
Re^3: Reading IP from a file and SNMP
by habit_forming (Monk) on Aug 26, 2004 at 14:11 UTC
    Well it depends on how they are stored in the file. If there is only one IP per line, this code will do:
    my @ip_array = (); if(open(F_IP,"<$filename")) { my %ip_hash = (); foreach my $ip (<F_IP>) { chomp($ip); #No duplicates! $ip_hash{$ip} = 1; } close(F_IP); @ip_array = keys(%ip_hash); } else { die "AHHHHH! Error Error go away!!"; } #Just keep doing your thing man...


    Note that I wrote this on the fly and have not tested it. It should give you a good start though. =)

    --habit