one liner for for and if
  Home FAQ Contact Sign in
perl.beginners only
 
Advanced search
POPULAR GROUPS

more...

perl.beginners Profile…
 Up
one liner for for and if         


Author: Richard Lee
Date: May 8, 2008 15:25

#!/usr/bin/perl

use warnings;
use strict;

my @array = qw/one two three four/;

print "$_\n" for @array last if "$_" eq q/three/;

[root@server tmp]# ./!$
././././testthis2.pl
syntax error at ././././testthis2.pl line 8, near "@array 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 (@array) {
if .......
}
}

just trying to see what the correct format is that for one liner that I
am trying
Show full article (0.63Kb)
4 Comments
Re: one liner for for and if         


Author: Yitzchok Good
Date: May 8, 2008 18:37

if ("$_" eq q/three/) {print "$_\n" for @array last};
no comments
Re: one liner for for and if         


Author: Rob Dixon
Date: May 8, 2008 20:26

Richard Lee wrote:
> #!/usr/bin/perl
>
> use warnings;
> use strict;
>
> my @array = qw/one two three four/;
>
> print "$_\n" for @array last if "$_" eq q/three/;
>
>
> [root@server tmp]# ./!$
> ././././testthis2.pl
> syntax error at ././././testthis2.pl line 8, near "@array 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? ...
Show full article (0.88Kb)
no comments
Re: one liner for for and if         


Author: Rob Dixon
Date: May 8, 2008 20:29

Yitzchok Good wrote:
>
> if ("$_" eq q/three/) {print "$_\n" for @array last};

That won't even compile. Please don't publish nonsense.

Rob
no comments
Re: one liner for for and if         


Author: Richard Lee
Date: May 8, 2008 20:47

Rob Dixon wrote:
> Richard Lee wrote:
>
>> #!/usr/bin/perl
>>
>> use warnings;
>> use strict;
>>
>> my @array = qw/one two three four/;
>>
>> print "$_\n" for @array last if "$_" eq q/three/;
>>
>>
>> [root@server tmp]# ./!$
>> ././././testthis2.pl
>> syntax error at ././././testthis2.pl line 8, near "@array last "
>> Execution of ././././testthis2.pl aborted due to compilation errors.
>>
>> Can someone fix my last statement on this program?
>> ...
Show full article (1.82Kb)
no comments