in reply to Re^2: create hash with map
in thread create hash with map


 Use of uninitialized value in split

Depending on the input data (if inconsistent)
this might happen but doesnt't do any harm
to the whole thing

In order to sanitize the stuff, one has to check
for the existence of the second split field after
the ':'
Just by substitution of (split...)[1] with (split ...)[-1]
a workaroud is found
%cp_samp = map{ (split ':')[0],  [split ',', (split ':')[-1] ] }@ex_array;
(corrected, see below ... sorry)

or even

%cp_samp = map{ (split /:/)[0], [split /,/,  ( (split /:/)[1] || '')] }@ex_array;

But this is sth. I'd like the OP to have figured out ...

Regards
M.

Replies are listed 'Best First'.
Re^4: create hash with map
by ikegami (Patriarch) on Sep 24, 2007 at 15:55 UTC

    The OP didn't specify what he wanted for "sample3", but I doubt it's

    $VAR1 = { 'sample3' => [ 'sample3' ] };
      sorry, our writeups created
      some interferences ...


      Regards

      M.
Re^4: create hash with map
by ikegami (Patriarch) on Sep 24, 2007 at 16:19 UTC

    Your updated solution fails for "sample:0", which seems to be a likely input given the samples provided by the OP.

    But this is sth. I'd like the OP to have figured out ...

    Given your three failed attempts, it could very well be out of the reach of the OP.

    A reply falls below the community's threshold of quality. You may see it by logging in.