This example shows an array slice, which can be very useful from time to time (although the example Briac wrote saves a step). This would make a good one liner.
#!/usr/local/bin/perl -w use strict; my %HASH; while(<DATA>){ my @array=split; #split on space by default $HASH{ $array[0] } = @array[1,2]; # Above is the slice. Notice the @arry[1,2]; it's in array context. } #Confirm: while( my ($key,$value)= each %HASH) { print " $key => $value \n"; } __END__ Happy Cat Male Evil Snake Female Patches Dog Male Bubbles Fish Female Harley dog Female Goldy Fish Male -- Matt --- Briac Pilpré <[EMAIL PROTECTED]> wrote: > On Sat, 09 Feb 2002 13:49:59 +0000, Terri Harrison > <[EMAIL PROTECTED]> wrote: > > What do I do so that the Name is the key and the Species and Gender > > together are the value? > > You were not too far from what you wanted to do. > > #!/usr/bin/perl -w > use strict; > > my %zoo; > > while (<DATA>){ > chomp; > # Split the line in two elements, after the first space > my @elements = split(/ /, $_, 2); > # Assign the first element as the key and the last as the value > $zoo{$elements[0]} = $elements[1]; > } > > # Let's check the results: > print "$_ => $zoo{$_}\n" foreach keys %zoo; > > > __DATA__ > Happy Cat Male > Evil Snake Female > Patches Dog Male > Bubbles Fish Female > Harley dog Female > Goldy Fish Male > __END__ > > -- > briac > << dynamic .sig on strike, we apologize for the inconvenience >> > > > -- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > __________________________________________________ Do You Yahoo!? Send FREE Valentine eCards with Yahoo! Greetings! http://greetings.yahoo.com -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]