in reply to Hash Variable

I know this isn't what you asked, but I'm not following the logic of the regexes. Are you trying to remove whitespace before and after the input? If so, make it part of what you split on:

my @vars = split(/\s*,\s*/,$rec);

Also, if you are only interested in $var3 for the hash, why work on the rest? Do something like:

open (DATA, "<data.txt") or die "Can't open file $!\n"; @DATA = <DATA>; close (DATA); foreach $rec (@DATA) { chomp $rec; my @vars = split(/\s*,\s*/,$rec); # debug - you might want to join with '|' to see # whitespace in any vars print "VARS = " . join('|', @vars). "\n"; # now insert into the hash $var_hash{$vars[2]} = 'whatever'; }
If you could relay more info the format of the input and how you want to make use of the hash you might get more (better) suggestions.

best of luck

--telesto

Replies are listed 'Best First'.
Re: Re: Hash Variable
by qball (Beadle) on Apr 06, 2001 at 00:31 UTC
    I want to print out each variable--$var1 through $var4--using $var3 as the primary key. And I want the data to be printed on each row according to my specifications. For example, if I want to:
    print "Row Data: $var1, $var2, $var4, $var3\n"; -or- print "Row Data: $var3, $var1, $var2\n";
    I do want to trim whitespace before and after the input.

    Many thanks to all your input.

    qball~"I have node idea?!"