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 5 of 7 Topic 11043 of 11509
Post > Topic >>

Re: one liner for for and if

by rob.dixon@[EMAIL PROTECTED] (Rob Dixon) May 9, 2008 at 04:26 AM

Richard Lee wrote:
> #!/usr/bin/perl
> 
> use warnings;
> use strict;
> 
> my @[EMAIL PROTECTED]
 = qw/one two three four/;
> 
> print "$_\n" for @[EMAIL PROTECTED]
 last if "$_" eq q/three/;
> 
> 
> [root@[EMAIL PROTECTED]
 tmp]# ./!$
> ././././testthis2.pl
> syntax error at ././././testthis2.pl line 8, near "@[EMAIL PROTECTED]
 last "
> Execution of ././././testthis2.pl aborted due to compilation errors.
> 
> Can someone fix my last statement on this program?
> 
> I thought maybe this will work   but guess not... is there no easy way 
> to do this?
> 
> I don't want to do
> 
> for (@[EMAIL PROTECTED]
) {
>      if .......
>      }
> }
> 
> 
> just trying to see what the correct format is that for one liner that I 
> am trying

And you want to write it in one line why?

print "$_\n" for grep /one/ .. /three/, @[EMAIL PROTECTED]
 there's nothing wrong with

foreach (@[EMAIL PROTECTED]
) {
  print "$_\n";
  last if /three/;
}

Rob
 




 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 Wed Jul 23 21:04:55 CDT 2008.