Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: Limited Number of User Input

by 7stud (Deacon)
on Mar 22, 2013 at 06:36 UTC ( #1024881=note: print w/replies, xml ) Need Help??


in reply to Limited Number of User Input

It doesn't make much sense why you would ask the user for the number of file names they want to enter, then try to limit the number of files they enter to what they said. Why not just ask the user to enter the filenames in the first place--then there will never be a discrepancy between some number they entered and the number of file names they actually entered?

To limit the number of inputs, you can specify a LIMIT for split:

my $count = 4; my $fnames = "file1 file2 file3 file4 file5 file6"; my @fnames = split ' ', $fnames, $count + 1; if (@fnames > 4) { pop @fnames; } say "@fnames"; --output:-- file1 file2 file3 file4

But what if the user enters fewer names?

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1024881]
help
Chatterbox?
and !@monks...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (5)
As of 2016-12-10 09:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    On a regular basis, I'm most likely to spy upon:













    Results (160 votes). Check out past polls.