Click here to get back home

Use of "return" in place of "last" (newbie question)?

 HomeNewsGroups | Search | About
 comp.lang.perl.misc    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
Use of "return" in place of "last" (newbie question)? Michael 03-09-2008
Posted by Ted Zlatanov on March 10, 2008, 10:44 am
Please log in for more thread options

M> Just as a matter of interest, so far as I could see, my technique of
M> setting a flag was the simplest way of maintaining the integrity of the
M> foreach (terminating it with "last" rather than jumping out of it with
M> "return"), whilst not wasting processor cycles performing irrelevant loops
M> later in the function. I am a newbie and don't know much - is there a
M> more elegant alternative which would satisfy the functional programmers?

Don't worry about satisfying functional programmers or anyone else. Get
the task done, write correct maintainable code, and that's enough.

Ted

Posted by David Formosa (aka ? the Platy on March 9, 2008, 5:28 pm
Please log in for more thread options
> I am new to perl, and I am wondering whether it is a bad thing to jump out
> of a foreach loop with return. I have a function which searches for a
> value in one of several arrays.

You might look at the function "first" from the core module List::Util
which implements that for you.


Posted by Michael on March 9, 2008, 6:07 pm
Please log in for more thread options
On Sun, 09 Mar 2008 21:28:36 +0000, David Formosa (aka ? the Platypus)
wrote:
<snip>

> You might look at the function "first" from the core module List::Util
> which implements that for you.

Thank-you. I had no idea that existed. Perl is a rather extensive
wonderland.

/M


Similar ThreadsPosted
If you are looking for a place to Buy and sell your used stuff and promote your small business..here is the place to go July 19, 2008, 3:55 am
Perl newbie - getting "system()" to return January 31, 2005, 4:05 am
MS Perl question -- how to use hacked script to work correctly(was Question on loops and return values or sumpin) December 8, 2004, 12:59 pm
Question on loops and return values December 3, 2004, 3:02 pm
multiple return regex question December 11, 2007, 4:04 pm
Return Codes in Perl: Question on implementing good patterns April 27, 2005, 9:32 am
newbie question September 12, 2004, 11:06 am
A newbie question October 14, 2004, 7:51 pm
Newbie Question November 6, 2004, 6:10 am
newbie-ish question November 18, 2004, 3:53 am

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap