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

That gives

Use of uninitialized value in split

Fix:

%cp = map{ (split /:/)[0], [split /,/, ((split /:/), '')[1] ] } @ex;

Note that using a string as the first argument of split is misleading, since it expects a regexp. You might as well provide a regexp directly.

Replies are listed 'Best First'.
Re^3: create hash with map
by mwah (Hermit) on Sep 24, 2007 at 15:49 UTC

     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.

      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.

      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.