Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Perl Beginners > Re: one liner f...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 3 of 7 Topic 11043 of 11531
Post > Topic >>

Re: one liner for for and if

by Uri Guttman <uri@[EMAIL PROTECTED] > May 9, 2008 at 03:20 AM

>>>>> "YG" == Yitzchok Good <anexpert@[EMAIL PROTECTED]
> writes:

  YG> if ("$_" eq q/three/) {print "$_\n" for @[EMAIL PROTECTED]
 last};

it helps if you quote SOME of the previous post for context.

that does not do what the OP asked for. that last is not proper syntax
either.

this is the original code:

my @[EMAIL PROTECTED]
 = qw/one two three four/;
print "$_\n" for @[EMAIL PROTECTED]
 last if "$_" eq q/three/;

the first thing to note is that you can have only one statement modifier
and that has 'for' and 'if' so it is illegal.

also the quotes on $_ are useless and possibly a bug waiting to happen.


and don't use q// unless you need to. it is distracting otherwise. there
are no quote chars in that string so normal single quotes are fine.

trying to make that into a legal one liner is not a good idea. there is
too much going on and it will be cluttered. but here is one way:

print "$_\n" && $_ eq 'three' && last for @[EMAIL PROTECTED]
 ;

uri

-- 
Uri Guttman  ------  uri@[EMAIL PROTECTED]
  --------  http://www.sysarch.com
--
-----  Perl Code Review , Architecture, Development, Training, Sup****t
------
--------- Free Perl Training --- http://perlhunter.com/college.html
---------
---------  Gourmet Hot Cocoa Mix  ----  http://bestfriendscocoa.com
---------
 




 7 Posts in Topic:
one liner for for and if
rich.japh@[EMAIL PROTECTE  2008-05-08 18:25:55 
Re: one liner for for and if
anexpert@[EMAIL PROTECTED  2008-05-08 21:37:11 
Re: one liner for for and if
Uri Guttman <uri@[EMAI  2008-05-09 03:20:26 
Re: one liner for for and if
rob.dixon@[EMAIL PROTECTE  2008-05-09 04:29:21 
Re: one liner for for and if
rob.dixon@[EMAIL PROTECTE  2008-05-09 04:26:53 
Re: one liner for for and if
Uri Guttman <uri@[EMAI  2008-05-09 03:56:57 
Re: one liner for for and if
rich.japh@[EMAIL PROTECTE  2008-05-08 23:47:36 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Sat Jul 26 1:06:10 CDT 2008.