SPUG: interesting while() behavior and hosting recs

Joel Grow joel at largest.org
Thu Sep 30 00:36:04 CDT 2004


Hey Perl gurus, I recently noticed this very strange (to me at least)
while() behavior:

 my $count = 1;
 while() {     # this evaluates to true(!)
    print "hello world\n";
    last if (++$count > 3);
 }

Prints "hello world" 3 times.  How is () evaluated to true?!?

If I put "0", "undef", "", or a scalar set to any of those in the parens,
it does what I expect--it skips the while loop.  I thought "Hmm, maybe
this is a strange empty list issue?", but no, the code below still skips
the while loop:

 my $count = 1;

 my @empty = ();

 while(@empty) {  # skips this while loop, as I'd expect
    print "hello world\n";
    last if (++$count > 3);
 }

In desperation, I thought maybe while() was evaluating $_ by default,
since you can of course do:

 while (<STDIN>) {

but printing out $_ just before the while() loop showed it is undefined.

What's going on?

Also, does anyone have a web hosting company recommendation?  I'm doing
some tech work with a nonprofit and they're currently using XO.  They have
a Unix account with Perl access, but the only shell access is through this
thing called VDE (virtual domain environment), basically a sandbox for CGI
scripts.  My main complaint is I'd have to telnet to the VDE.  And to get
mysql access they'd have to spend $50/month.  I use pair.com for a
personal site (and am generally happy with it), and have some experience
with johncompanies.com.  johncompanies.com is cool, but for this I'd like
someone else to take care of making sure the web and mail servers are
running and doing software updates.  So a relatively simple unix account
with Perl and rdbms (mysql or postgres preferably).

Thanks!

Joel


More information about the spug-list mailing list