For Programmers: Free Programming Magazines  


Home > Archive > PERL Beginners > September 2006 > help with expression









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author help with expression
hawk.alan@gmail.com

2006-09-25, 3:57 am

print $_>3 && (1..10)

gives me 45678910

however

print $_<3 && (1..10)

gives me
4567891012345678910

is this a bug or precendence problem?

Manish

2006-09-25, 7:58 am

How did you get "print $_>3 && (1..10)" to work? I couldn't.

However by breaking this into simpler statements
foreach (1..10)
{
my $temp = ($_ < 3) && $_;
print "$temp\n";
}
did result into what you were expecting

Regards,
Manish

hawk.alan@gmail.com wrote:
> print $_>3 && (1..10)
>
> gives me 45678910
>
> however
>
> print $_<3 && (1..10)
>
> gives me
> 4567891012345678910
>
> is this a bug or precendence problem?


Paul Lalli

2006-09-25, 7:58 am

hawk.alan@gmail.com wrote:
> print $_>3 && (1..10)
>
> gives me 45678910


Really? It gives me:
$ perl -wle'print $_>3 && (1..10);'
Use of uninitialized value in numeric gt (> ) at -e line 1.

I wonder what you did differently, and what makes you believe that any
other piece of your code can't possibly be relevant...

> however
>
> print $_<3 && (1..10)
>
> gives me
> 4567891012345678910
>
> is this a bug or precendence problem?


Neither, since what you're saying is completely nonsensical without any
context. Please post a short but COMPLETE script that demonstrates
whatever the heck you're doing...

Paul Lalli

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com