Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Define Hash with $1 & $2

Status
Not open for further replies.

mikawin

Technical User
Apr 15, 2009
28
US
I have a file with 5 columns and want to use the data in the file to define a hash with key-value pair as shown below:

key - c1, c2, c3
value - c1, c2, c3, c4, c5

Code:
my(%myHash);

my ($c1, $c2, $c3, $c4, $c5);
open(IN,"file1") 
while(my $current = <IN>)
{
    $current =~ /^(($c1\t$c2\t$c3)\t$c4\t$c5)/;
    $myHash{$2} = $1;
}

print %myHash;

However, %myHash is empty. What needs to be done differently?

Thanks,
MW
 
Could you put example of your data? As well you could print values of $1 and $2 before build the hash, just to make sure your regex match the lines...

Code:
$current =~ /^(($c1\t$c2\t$c3)\t$c4\t$c5)/;    
print "1->$1, 2->$2\n";
$myHash{$2} = $1;

dmazzini
GSM/UMTS System and Telecomm Consultant

 
Duh, me! Once I printed $1 and $2 out, got it figured. Mental note - check the obvious before posting a query.

Thanks dmazzini.
~MW
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top