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.