Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Array Ref Error

Reply
Thread Tools

Array Ref Error

 
 
doni
Guest
Posts: n/a
 
      03-10-2007
Hi,
I am having some problem with ARRAY ref in my test program.
The test program contains multiple arrays to extract the data from the
output based upon certain conditions. I am also extracting an user
input to a variable where the user is expected to input any one of the
array names existing
in the program.
When I am trying to pass the user input variable to a subroutine as an
initialized array, I am getting this error message: Can't use string
("junk") as an ARRAY ref while "strict refs".

Actually, what I am expecting to do is have the user input an already
existing array name in the program and pass that array name to a
subroutine.

Here is the program:

#! /usr/bin/perl

use strict;

my $ex_data = 'log_messages';
open (NETSTAT,$ex_data) || die("Cannot Open File: $!");

### Variables ###
my %gw_route = ();
my %route = ();
my %no_of_times = ();
my $segment;
my @new_device; my @route_update;
my @received_hello; my @removing_l2;
my $key; my $i;

### User Input
$segment = <STDIN>;
chomp($segment);

### ROUTE SUBROUTINE ###
sub route {
my (@received_message) = @_;
@received_message = split;
if (/Received Hello/i) {
push (@received_hello, $received_message[9]);
}
elsif (/Removing L2/) {
push (@removing_l2, $received_message[9]);
push @{$route{removing_l2}{$key}}, $received_message[9];
}
else {}
}

### GWD SUBROUTINE ###
sub gw_route {
my (@received_message) = @_;
@received_message = split;
if (/Got ROUTE_UPDATE/i) {
(my $gw_route_update = $received_message[7]) =~ s/address=/ /;
push (@route_update, $gw_route_update);
push @{$gw_route{route_update}{$key}}, $gw_route_update;
}
}

### SUBROUTINE TO COUNT NO OF TIMES A PARTICULAR VALUE IS PRESENT IN
THE HASH
sub no_of_times {
my (@mac_id) = @_;
for $key (@mac_id) {
$no_of_times{$key}++;
}
for $key (keys %no_of_times) {
print "$no_of_times{$key} $key\n";
}
}

while (<NETSTAT>) {
chomp;
if (/rfrouted/i) {
route($_);
}
elsif (/gwd/i) {
gw_route($_);
}
}
close(NETSTAT) || die("Cannot close $ex_data: $!");
no_of_times(@$segment); #### This is where I am creating an error


Thanks,
doni

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Giving an rvalue ref to a function taking an rvalue ref Juha Nieminen C++ 13 08-29-2012 09:25 PM
passing ref to ptr again as ref to ptr.... osama178@gmail.com C++ 22 04-30-2008 10:42 AM
passing ref to ptr again as ref to ptr.... osama178@gmail.com C++ 6 04-29-2008 08:09 AM
passing ref to ptr again as ref to ptr.... osama178@gmail.com C++ 0 04-24-2008 08:23 PM
strong ref from weak ref? Navindra Umanee Ruby 2 02-12-2005 05:06 PM



Advertisments