Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

how can push value from regex to a array of hash of hashes

by Sombrerero_loco (Beadle)
on Jan 07, 2009 at 14:17 UTC ( [id://734637]=perlquestion: print w/replies, xml ) Need Help??

Sombrerero_loco has asked for the wisdom of the Perl Monks concerning the following question:

Hi there.!

Im seeking for your wisdom!

I need to know how i can push this calue $ServiceRef fomr this piece of code to an array of hash of hashes:
elsif (/<ServiceRef>(.+?)<\/ServiceRef>/) { $serviceref = $1; $index{"ID$counter"}{"sons"} = [$serviceref]; }
As you see im capturing a regex expresion into $serviceref and i want toload every matches has been found into the array into de hash of hashes $index{"ID$counter"}{"sons"}[here should be an array reference, isnt ?].

As i has wrote its seems doesnt running properly, maybe something its mistakes. I need to do that because i need to keep every matched result of the regex expression because "a father could have more than a son".

Thanks in advance!

Replies are listed 'Best First'.
Re: how can push value from regex to a array of hash of hashes
by ikegami (Patriarch) on Jan 07, 2009 at 14:21 UTC

    With an array, you'd do

    push @array, $value;

    So with an array ref, you do

    push @{ $array_ref }, $value;

    In this case, that means

    push @{ $index{"ID$counter"}{"sons"} }, $serviceref;

    What you currently have,

    $index{"ID$counter"}{"sons"} = [ $serviceref ];

    replaces the that currently exists at $index{"ID$counter"}{"sons"}.

    By the way, please wrap code in <c>...</c> tags.

      Thanks ikegami. But this will push me the value obtained from the regex passes to $serviceref to an array under the hash %index{"ID$counter"}{"sons"} ?? I mean, sons will contain all the matches in an array ?
        yes

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://734637]
Approved by ikegami
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (7)
As of 2024-04-25 08:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found