Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
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?
[stevieb]: battery was at about 95% capacity when the test began
[stevieb]: in the meantime while it was on battery, I got my shift register issues fixed, as well as certain interrupt issues

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (9)
As of 2017-03-26 15:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Should Pluto Get Its Planethood Back?



    Results (315 votes). Check out past polls.