in reply to Re: Parsing and Matching Text with Map
in thread Parsing and Matching Text with Map

Okay, now I made a little change. I'm storing the data in a hash and the key is the index.
# Create hash with employee index as key. my %employees = ( map { $_ =~ m/^employee\[(.*?)\] = new employee_element\((.*)\);/g } split "\n", $data );
Right now the "value" is a string. How can I get it to change to an array inside this map expression?

I can alter it outside the function using this:
$employees{$_} = \[split ",", $employees{$_} ] foreach keys %employees;

Replies are listed 'Best First'.
Re^3: Parsing and Matching Text with Map
by shmem (Chancellor) on Oct 05, 2006 at 19:55 UTC
    You process as advised, and at the end of the map block you return a key/value pair:
    map { ... $index, [ @list ]; }

    That will be fine to construct a hash.

    --shmem

    _($_=" "x(1<<5)."?\n".q·/)Oo.  G°\        /
                                  /\_¯/(q    /
    ----------------------------  \__(m.====·.(_("always off the crowd"))."·
    ");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}