Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Perl Misc (http://www.velocityreviews.com/forums/f67-perl-misc.html)
-   -   prel doubt (http://www.velocityreviews.com/forums/t893564-prel-doubt.html)

rajesh 08-02-2005 12:21 PM

prel doubt
 
what is the meaning of


LINE:

for(;;){
statements;
last LINE if $foo;
next LINE if /^#/;
statemetns;
}

my doubt is what is this /^#/ represents?

I will be so thankful for clearing my doubt
SIva Rajesh


Brian Wakem 08-02-2005 12:32 PM

Re: prel doubt
 
rajesh wrote:

> what is the meaning of
>
>
> LINE:
>
> for(;;){
> statements;
> last LINE if $foo;
> next LINE if /^#/;
> statemetns;
> }
>
> my doubt is what is this /^#/ represents?
>
> I will be so thankful for clearing my doubt
> SIva Rajesh



It skips comments.

More precisely, if $_ begins with #, the current iteration of the loop is
ended and the next iteration of the loop begins.


--
Brian Wakem
Email: http://homepage.ntlworld.com/b.wakem/myemail.png

Jürgen Exner 08-02-2005 02:43 PM

Re: prel doubt
 
rajesh wrote:
> what is the meaning of


It is a poorly written loop

> LINE:
>
> for(;;){
> statements;
> last LINE if $foo;
> next LINE if /^#/;


Using last and next as the only loop control is very bad style. I agree they
come in handy for handling special exceptions, but normally a reader should
be able to tell the exit condition by looking at the loop control condition.

> statemetns;
> }
>
> my doubt is what is this /^#/ represents?


This is a very common Perl idiom. It tries to match $_ against the regular
expression ^#, i.e. checks if a line begins with the hashmark character (or
pound sign or Santa Fu or whatever you want to call it).

For details see
perldoc perlre
perldoc perlop, section "Quote and quote-like operators"

jue



John Bokma 08-02-2005 02:56 PM

Re: prel doubt
 
"Jürgen Exner" <jurgenex@hotmail.com> wrote:

>> for(;;){
>> statements;
>> last LINE if $foo;
>> next LINE if /^#/;

>
> Using last and next as the only loop control is very bad style.


According to?

--
John Small Perl scripts: http://johnbokma.com/perl/
Perl programmer available: http://castleamber.com/
Happy Customers: http://castleamber.com/testimonials.html



All times are GMT. The time now is 01:40 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.