Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: user input / reg exp's

by janx (Monk)
on Jun 14, 2002 at 16:11 UTC ( [id://174603]=note: print w/replies, xml ) Need Help??


in reply to user input / reg exp's

Hi! You are open'ing the input handle FH on you first argument. So far so good.
Inside your main event loop (the do {} while stuff) you read in the complete file with:
while (<FH>) { ... }

Obviously the second time round (when the user is presented the main menu again) the <FH> is going to fail instantly because the read pointer is at the end of the file from the previous reads. Otherwise you wouldn't have returned from the while loop.
If the file isn't too large, I would recommend to first (outside the menu loop) read in the whole file (in an array perhaps) and to do you matching on that, rather than reading the file while you match. Another solution would be to seek (perldoc seek) to the beginning of the file each time you get a choice from the user, but that would be lossage (You don't want to read in the file each time you want to read it, do you ;-)?)

As to your regex problems:
It generally is a bit hard to help improving a regex if one doesn't know the input data.
Thus, if you have a decent short example of input data, I'm sure we can work out a solution.


Hope that helps,
Kay

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://174603]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (9)
As of 2024-04-23 11:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found