CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
What might this function do?

 



Alain
New User

Feb 12, 2002, 2:32 PM

Post #1 of 2 (563 views)
What might this function do? Can't Post

Can anyone maybe try to explain what this function is doing?

Especially what is in IDS finally? What is


Code
  while (<$HFat>) { 
($id,$rest)=split(/\t/,$_,2);
$IDS{$id}=$rest;
}



# prepares data structures for recNext

sub recAll {

local ($table) = @_;

undef %IDS;
($HData,$HFat) = &recOpen($table);
seek($HFat,0,0);
while (<$HFat>) {
($id,$rest)=split(/\t/,$_,2);
$IDS{$id}=$rest;
}

$IDS=$table;

return wantarray ? keys(%IDS) : '';
}


Coderifous
journeyman

Feb 12, 2002, 4:27 PM

Post #2 of 2 (559 views)
Re: [Alain] What might this function do? [In reply to] Can't Post

In that block, $HFat is a I/O-handle (most likely a handle to an opened file) and that handle is being iterated over, line by line (via the 'read-line' operator <>) and each line is being broken into two pieces separated by tabs: $id, and the $rest. Using the values a hash (or associative array, whatever floats your boat) is populated. %IDS is the hash being populated. It is being populated where you see the line:

$IDS{$id} = $rest;



So if the files that are being read, are just tables of data stored in text files, this subroutine is reading them into memory and storing them as hashes, which would provide quick access to the values in them, should that be desired.

Hope this helps!Smile

--Jim

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives