Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot

Re: user input / reg exp's

by janx (Monk)
on Jun 14, 2002 at 16:11 UTC ( #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,

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (3)
As of 2023-04-01 07:26 GMT
Find Nodes?
    Voting Booth?

    No recent polls found