Array Ref Error

Discussion in 'Perl Misc' started by doni, Mar 10, 2007.

  1. doni

    doni Guest

    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
     
    doni, Mar 10, 2007
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    0
    Views:
    341
  2. Replies:
    22
    Views:
    762
    peter koch
    Apr 30, 2008
  3. Replies:
    6
    Views:
    352
    James Kanze
    Apr 29, 2008
  4. Navindra Umanee

    strong ref from weak ref?

    Navindra Umanee, Feb 12, 2005, in forum: Ruby
    Replies:
    2
    Views:
    145
    Navindra Umanee
    Feb 12, 2005
  5. Juha Nieminen
    Replies:
    13
    Views:
    619
    Edek Pienkowski
    Aug 29, 2012
Loading...

Share This Page