Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: How to store matched $1 values one by one to array?

by kcott (Chancellor)
on Feb 02, 2013 at 07:52 UTC ( #1016673=note: print w/replies, xml ) Need Help??


in reply to How to store matched $1 values one by one to array?

G'day rekhasri,

Welcome to the monastery.

Take a look at the push function.

I can't see anywhere in your code where you're adding anything to an array. However, what you've written is rather difficult to read: take a look at Markup in the Monastery.

You probably want something like:

my @agent_ids; # outside logfile reading loop ... if (...) { ... push @agent_ids, $agent_id; }

-- Ken

Replies are listed 'Best First'.
Re^2: How to store matched $1 values one by one to array?
by rekhasri (Initiate) on Feb 02, 2013 at 07:56 UTC
    I forgot to add that array line in my code. Now I have added that line in my first question. Sorry for the inconvenience.

      Well, it's not an inconvenience, but that does now highlight where you're going wrong.

      Declare your array outside of whatever loop iterates over your logfile and replace my @array=$agent_id; with a push statement, as I indicated.

      -- Ken

        if($line =~ /^.*:agent_id=>(.+?),/){ # Calls count based on call type my $agent_value=$1; my $agent_value=~s/\"//g; push @agent_ids, $agent_value; print Dumper\@agent_ids; }

        Before while loop I have declared the @agent_ids and then added the push function with array and scalar variable.

        While printing the @agent_ids variable it printed the undef in array.

        I don't know why it is printing the undef values instead of exact values.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1016673]
help
Chatterbox?
usemodperl can't get Module::CoreList to work in a script (one-liner ok)
[choroba]: Does the example from SYNOPSIS work for you?
[usemodperl]: yes, in script too, problem is find_modules but only in a script
[usemodperl]: one liner works, nothing from script, weird

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (6)
As of 2018-06-23 12:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?



    Results (125 votes). Check out past polls.

    Notices?