Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: Assign value

by bichonfrise74 (Vicar)
on Nov 04, 2009 at 16:33 UTC ( [id://804983]=note: print w/replies, xml ) Need Help??


in reply to Assign value

Where will you get the values for your hash keys? I think this is what you want.
#!/usr/bin/perl use strict; use warnings; my %record_for; while (<DATA>) { chomp; my ($key, $val) = /\{(\w+)\}\s*?(\w+)/; $record_for{$key} = $val; } print join ',', map { $record_for{$_} } keys %record_for; __DATA__ {NAME} John {AGE} 35 {SEX} M {ADDRESS} USA

Replies are listed 'Best First'.
Re^2: Assign value
by AnomalousMonk (Archbishop) on Nov 04, 2009 at 17:20 UTC
    Note that the statement
        map { $hash{$_} } keys %hash;
    produces exactly the same list as
        values %hash;
      Thanks. I was thinking about what the keyword for 'values' was but just totally forgot about it. Anyway, thanks again.
        #!/usr/bin/perl use strict; use warnings; my $names; my %names; while(<DATA>){ if(/{(.*)}/){ $names = $1; print $names; } } __DATA__ {NAME} {AGE} {SEX} {ADDRESS}
        While printing the $names,
        The values should be John 35 M USA.
        The values are not present in the input.
        So i have to create a hash map and assign the values.

Log In?
Username:
Password:

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

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

    No recent polls found