Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

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

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


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

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.


Comment on Re^4: How to store matched $1 values one by one to array?
Download Code
Re^5: How to store matched $1 values one by one to array?
by trizen (Friar) on Feb 02, 2013 at 11:12 UTC
    $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 ...
Re^5: How to store matched $1 values one by one to array?
by choroba (Abbot) on Feb 02, 2013 at 11:12 UTC
    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://1016685]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (7)
As of 2014-07-10 08:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    When choosing user names for websites, I prefer to use:








    Results (203 votes), past polls