in reply to Can an if statement run within a foreach loop?
After looking at you code for a while I trimmed it down to the following code. I suggest you use it as a starting point for rephrasing your question.
#!/usr/bin/perl use strict; use warnings; use CGI ':standard'; print "Size of party? "; chomp (my $size = <DATA> ); print "Party name? "; chomp (my $name = <DATA> ); my @arrayPartyNames; my @tableSize = ( "tableSize2One", "tableSize2Two", "tableSize2Three", "tableSize2Fo +ur", "tableSize2Five", "tableSize2Six", "tableSize2Seven", "tableSize2E +ight" ); exit if $size > 8 || $size < 1; my $randomInt = int(rand 11); my $time1 = 30 + $randomInt; unshift(@arrayPartyNames, $name); foreach my $table (@tableSize) { next if -z $table; open FILE, '>', $table; print FILE "$arrayPartyNames[0]"; close(FILE); print "\nYou have $table reserved.\n"; last; } __DATA__ 2 Joe
Prints:
Size of party? Party name? You have tableSize2One reserved.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Can an if statement run within a foreach loop?
by terms5 (Initiate) on Apr 21, 2006 at 04:09 UTC | |
by GrandFather (Saint) on Apr 21, 2006 at 04:31 UTC |