in reply to Hash from a file

Is this what you had in mind?
use warnings; use strict; use Data::Dumper; my %hash; while (<DATA>) { my ($id, @description) = split; $hash{$id} = [@description]; } # let's print out what we have print Dumper( \%hash ); __DATA__ Data_Type:1234567890 data data data data data Data_Type:1237834810 data2 data2 data2 data2 data2

This prints out:

$VAR1 = { 'Data_Type:1234567890' => [ 'data', 'data', 'data', 'data', 'data' ], 'Data_Type:1237834810' => [ 'data2', 'data2', 'data2', 'data2', 'data2' ] };

Replies are listed 'Best First'.
Re^2: Hash from a file
by Anonymous Monk on Oct 04, 2007 at 15:43 UTC
    Kind of...what I want is it to be split like...
    'Data_Type:1237834810' => ['data2 data2 data2 data2 data2']
    Can't say how grateful I am for this btw!
      Be careful. Saying ['data2 data2 data2 data2 data2'] means that the value is an array reference with a single element, 'data2 data2 data2 data2 data2', which is a string. It's not the same as ['data2', 'data2', 'data2', 'data2', 'data2'] which is an array reference consist of some elements that are all strings. If what you want is the latter, then toolic has given the answer.

      However, if what you want is the former then you can join back @description separated by, for example, spaces. This also replaces tabs with single spaces. From toolic's code:

      my ($id, @description) = split; $hash{$id} = [join ' ', @description];

      Open source softwares? Share and enjoy. Make profit from them if you can. Yet, share and enjoy!