[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] Modifiers



Excerpt of message (sent 5 February 1999) by Emmanuel. M. Decarie:
> What I find ultra cool in Perl are modifiers
Like ...if and ...unless?

Me too.  Although in your example there is no need for an if.  When
@list ist empty, the foreach loop will never be executed.  So you can
safely

*    foreach(@list) {print "$_\n"}

But I assume you are aiming for something more general?
I suggest the following modifications to your examples.

> foreach(@list) {print "$_\n"} if (@list);  # Syntax error...

*    do {foreach(@list) {print "$_\n"}} if @list


> (@list) ? foreach(@list) {print "$_\n"} : print "Empty list\n";

*    @list and map print("$_\n"), @list;

Note that the Camel explicitly discourages this use of map (throwing
away the return value).

Hoping this helps

	Christian Brechbuehler
	
	Communication Technology Laboratory, Image Science Group
	Swiss Federal Institute of Technology (ETH), Zurich

***** Want to unsubscribe from this list?
***** Send mail with body "unsubscribe" to mac-perl-request@iis.ee.ethz.ch