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: Intermediate:
File Searching Problems....

 



KaoAtlantis
Novice

Sep 10, 2000, 12:08 PM

Post #1 of 2 (240 views)
File Searching Problems.... Can't Post

I have been trying to figure this out for awhile now, I can never seem to get this to work...

What I am trying to do is load a file into an Array... This File has lines like this "the command (*) text to send to the user"

I can split them apart...
...But I dont know how to Serarch the arrays so when someone types the command, it will look for it in the file... then send the text...

could someone please help me with this =)
-Thanks, Kao Atlantis

[This message has been edited by KaoAtlantis (edited 09-10-2000).]


japhy
Enthusiast

Sep 10, 2000, 2:50 PM

Post #2 of 2 (240 views)
Re: File Searching Problems.... [In reply to] Can't Post

Don't use an array for that; use a hash:

<BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR>


open FILE, $whatever;
while (<FILE> ) {
chomp;
($command, $text) = split /\t/; # for a tab-delimited file
$action{lc $command} = $text;
}
close FILE;
</pre><HR></BLOCKQUOTE>

Then access the text via $action{lc $foo}, where $foo is the command the user asked for.

------------------
Jeff "japhy" Pinyan -- accomplished author, consultant, hacker, and teacher


 
 


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

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