Deb <[EMAIL PROTECTED]> writes: > Still struggling with multilevel hashes. <snip>
> while (<DATA>) { > chomp; > ($listname, $field) = split(/:/, $_); > print "\nListname is $listname,\nField is: $field\n"; > %hrLists = split(/\s+/, $field); > $Lists{$listname} = \%hrLists; > } > > __DATA__ > list-1: -x abc -r tenb > list-2: -x def -r ghi -h tenr > list-3: -x fel -h asci > list-4: -x foo -h nonasci -r bfab > > I'm getting this output: > > Listname is list-1, > Field is: -x abc -r tenb > Odd number of elements in hash assignment ... You're getting an empty leading field; $ perldoc -f split <relevant bits> Splits a string into a list of strings and returns that list. By default, empty leading fields are preserved, and empty trailing ones are deleted. If EXPR is omitted, splits the "$_" string. If PATTERN is also omitted, splits on whitespace (after skipping any leading whitespace). Anything matching PATTERN is taken to be a delimiter separating the fields. (Note that the delimiter may be longer than one character.) As a special case, specifying a PATTERN of space ("' '") will split on white space just as "split" with no arguments does. Thus, "split(' ')" can be used to emulate awk's default behavior, whereas "split(/ /)" will give you as many null initial fields as there are leading spaces. A "split" on "/\s+/" is like a "split(' ')" except that any leading whitespace produces a null first field. A "split" with no arguments really does a "split(' ', $_)" internally. So try something like this: use Data::Dumper; while (<DATA>) { chomp; my ($listname, $field) = split /:/; $Lists{$listname} = split ' ', $field; # # would have helped you spot it... # print "listname:'$listname'\n", "field: '$field'\n", Dumper $Lists{$listname}; } HTH -- Steve -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]