Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

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

by rekhasri (Initiate)
on Feb 02, 2013 at 07:56 UTC ( #1016675=note: print w/replies, xml ) Need Help??


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

I forgot to add that array line in my code. Now I have added that line in my first question. Sorry for the inconvenience.
  • Comment on Re^2: How to store matched $1 values one by one to array?

Replies are listed 'Best First'.
Re^3: How to store matched $1 values one by one to array?
by kcott (Chancellor) on Feb 02, 2013 at 08:03 UTC

    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.

        $agent_value is declared two times.
        The substitution should not be used with my.
        Just remove the second lexical declaration and the code works.

        Also, I recommend to use strict and warnings.

        'warnings' says: "my" variable $agent_value masks earlier declaration in same scope at ...
        Remove the second my before $agent_value. It resets its value. Also, turn on warnings to be warned against the practice of redeclaring a variable.
        لսႽ ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1016675]
help
Chatterbox?
[Tanktalus]: choroba: do I have to move? :)
Discipulus has too much roots in a 2770 yo town
[marioroy]: I want a job after completing MCE in about a week. But feel that I've moved to the wrong place.
[choroba]: I fear so. We have offices in Prague, Brno, Saigon and San Francisco.
[Discipulus]: choroba if let your company to hire Tanktalus and marioroy ... what a big fishing!
[Discipulus]: i choice prague!!
[choroba]: 1200 years is enough :-)
[marioroy]: Lady_Aleena my $ans = qx! find . -name "*.pl" -exec ls -l {} \\; !;
[Tanktalus]: My basic problem right now is that if I were willing to move, I could be back in Toronto with a pay raise. We have a number of reasons for not wanting to do that.
[marioroy]: I had to backslash the backslash inside qx.

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (9)
As of 2017-04-23 20:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I'm a fool:











    Results (432 votes). Check out past polls.