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

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

by kcott (Canon)
on Feb 02, 2013 at 08:03 UTC ( #1016678=note: print w/replies, xml ) Need Help??


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

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

Replies are listed 'Best First'.
Re^4: How to store matched $1 values one by one to array?
by rekhasri (Initiate) on Feb 02, 2013 at 09:15 UTC
    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://1016678]
help
Chatterbox?
[Corion]: ambrus: Yeah, I read that, but it's somewhat vague as in what I really have to implement, and where/how my "other" mainloop should/needs to call AnyEvent
[Corion]: (or maybe I just work better from existing code that I munge until it works and I understand it rather than a short abstract text like "implement everything that's needed" ;) )
[ambrus]: Corion: I think in this case you can get away with only a stub for idle, one that always dies when you create it, because AnyEvent::HTTP doesn't use it, not even indirectly through AnyEvent::Handle or AnyEvent::Socket or AnyEvent::DNS.
[Corion]: The "and I understand it" part is optional.
[Corion]: ambrus: Yes but I also need to implement the file / IO watcher, because Prima has that (in Prima::File), and I need to supply the appropriate thing to make push_write etc. work with Prima
[ambrus]: Corion: yes, you need to implement the io watcher, which should be simple because Prima::File is basically that, and the timer watcher form Prima::Timer
[Corion]: ... or so I think. As I said, I'm somewhat vague on how to make AnyEvent cooperate with a callback-driven IO event loop that gives me callbacks when data is available or can be written

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (9)
As of 2016-12-08 12:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    On a regular basis, I'm most likely to spy upon:













    Results (141 votes). Check out past polls.