[Canberra-pm] Stuff from CLUG

Jepri jepri at webone.com.au
Thu Sep 26 08:47:39 CDT 2002


I had a lively perl discussion with a few people tonight, and I thought 
I'd give a few samples.  Unfortunately I can only remember one of 
them.  Feel free to ask more, sometimes the 'simple' ones can require 
quite a long answer.  They are often hard to find in the perldocs, if 
they are there at all.

The one I can remember is:

- Can I get rid of the braces around the test in an if statement?

In C you can write:

if ( true )
	do something;

and C will only do something if true is true.

In Perl, you always have to write:

if ( $true ) { do something }

It's a language design choice that irritates C programmers but stops 
people writing:


if ( true )
	do something;
	do something else;

and then wondering what went wrong.

You can however drop all brackets and braces for very simple if 
statements like this:

print "True" if $true;


I also wandered way off course and started babbling about closures, and 
I managed to confuse lexical closures with dynamic closures.  My bad.





More information about the Canberra-pm mailing list