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.

DWIM is Perl's answer to Gödel

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
    Like I said, first time post, but thanks for the link read. I've been using Perl for all of 2 weeks, so sorry if I seem like a dummy. The problem was that I wasn't including the first if statement with tableSize2One and like you said had an orphan elseif. I figured I could just put the foreach inbetween, but I was wrong. That and the && needing to be switched to || my bad that was just a silly mistake. Thanks for your help I got it solved quickly with it. :D -T

      Welcome to Perl and to The Monastery.

      Newbie rather than dummy! Glad you sorted the problem out and happy to help.


      DWIM is Perl's answer to Gödel