On Wed, Oct 09, 2002 at 11:18:34AM +0100, Martin Bower 
([EMAIL PROTECTED]) wrote:
> Could anyone suggest a better way to split $text into a hash, using the keys
> stored in @header ?
> Any tips would be appreciated.
> 
> my $text = "first second    Third    fourth    fifth  sixth";
> my @header = ( '1st', '2nd' , '3rd' , '4th' , '5th' , '6th' );
> my @fields = split(' ',$text,6);
> 
> my %end_hash = ( $header[0] , $fields[0],
>                  $header[1] , $fields[1],
>                  $header[2] , $fields[2],
>                  $header[3] , $fields[3],
>                  $header[4] , $fields[4],
>                  $header[5] , $fields[5] );

my %end_hash;
@end_hash{@header} = split ' ', $text, 6;

Hash slices rock.

Dave...

-- 
  .sig missing...

Reply via email to