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

  Main Index MAIN
Search Posts SEARCH
Who's Online WHO'S
Log in LOG

Home: Perl Programming Help: Intermediate:
File Searching Problems....



Sep 10, 2000, 12:08 PM

Post #1 of 2 (332 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).]


Sep 10, 2000, 2:50 PM

Post #2 of 2 (332 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> ) {
($command, $text) = split /\t/; # for a tab-delimited file
$action{lc $command} = $text;
close FILE;

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