Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: Limited Number of User Input

by 7stud (Deacon)
on Mar 22, 2013 at 06:36 UTC ( [id://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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1024881]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (3)
As of 2024-04-18 22:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found