in reply to Re: Hash of arrays
in thread Hash of arrays

A variation on a theme
use strict; use Data::Dumper; my %hoa; while(<DATA>) { chomp; my($k, $v) = split /\s*:\s*/ => $_, 2; $hoa{$k} = [ split ';' => $v ]; } print Dumper(\%hoa); __DATA__ t-98: 12;3;56;24 t-56: 1;98 t-3 : 12;56

HTH

_________
broquaint

Replies are listed 'Best First'.
Re: Re: Re: Hash of arrays
by tachyon (Chancellor) on Nov 04, 2002 at 14:38 UTC

    Golf.......

    do{split/: |;|\n/;$h{$_[0]}=[@_[1..$#_]]}for<DATA>

    cheers

    tachyon

    s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print

      Four!
      %h=map{split/: |;|\n/;shift@_,[@_]}<DATA>;

      HTH

      _________
      broquaint

      Not quite as good as broquaint's score, but close:

      y/:;/ /,split,$i=shift@_,$h{$i}=[@_]for<DATA>;

      Points to anybody who can explain why $above_code =~ s/$i=shift@_,$h{$i}=/$h{shift()}=/ won't work the same as $above_code.
      --

      Love justice; desire mercy.
      Shioo.
      my %h = map { chomp; /:\s+/ ? ( $` => [split ';', $'] ) : () } <DATA>;
      Or, perhaps a little more comprehensible (but less safe):
      my %h = map { $_->[0] => [split ';', $_->[1]] } map { chomp; [split /:\s+/] } <DATA>;