codetoad.com
  ASP Shopping CartForum & BBS
  - all for $20 from CodeToad Plus!
  
  Home || ASP | ASP.Net | C++/C# | DHTML | HTML | Java | Javascript | Perl | VB | XML || CodeToad Plus! || Forums || RAM 
Search Site:
Search Forums:
  Creating Hash from text file  Quest101 at 13:57 on Wednesday, October 19, 2005
 

Hi, I am new to perl. I have a text file that is formatted as show below....

John 82387
chris 39779
mary 39743
Joan 73973


Now i would like to create a hash with the number being they keys and the name being the value and i am trying to find the easiest way to do it ? is there any perl function that could simplify this

Thanks in advance for any help you can give

Regards,
Quest101

  Re: Creating Hash from text file  mimir at 01:19 on Monday, February 26, 2007
 

Look at 9.2.1.2.
http://www.hermanningjaldsson.com/1/pdg/pdg.html


  Re: Creating Hash from text file  Sunil Kartikey at 12:40 on Tuesday, April 03, 2007
 

my %hash_table;
open(IN, "<ip1") or die "Couldn't open file for processing: $!";
while (<IN>) {
chomp;
( $hash_table{$key}, $key )= split(/ /,$_);
}
close IN;
foreach $key (keys %hash_table) {
print "$key = $hash_table{$key}\n";
}









CodeToad Experts

Can't find the answer?
Our Site experts are answering questions for free in the CodeToad forums
//








Recent Forum Threads
•  Date script issues
•  perl script help needed
•  onChange issue
•  perl remote execution
•  Chat application
•  How to send multiple perameters in SOAP request.
•  Java code for Insert picture on the table in spreadsheet
•  Re: Problem with concatenation
•  how to genrates the crystal report by sending a id at runtime


Recent Articles
ASP GetTempName
Decode and Encode UTF-8
ASP GetFile
ASP FolderExists
ASP FileExists
ASP OpenTextFile
ASP FilesystemObject
ASP CreateFolder
ASP CreateTextFile
Javascript Get Selected Text


© Copyright codetoad.com 2001-2007