strange behaviour w.r.t get function

R

Rahul!!

Please take a look at this code snippet,

my $query = "SELECT itemid from items";

my $sh = $dz_dbh->prepare( $query );

$sh->execute || return( $dz_dbh->errstr );
while(my @row=$sh->fetchrow()) {
push (@item_id_arr,$row[0]);
}


foreach my $itemid (@item_id_arr){
print $itemid;

#statement 1
my $string="http://mymachine/mywebsite/show_item.cgi?id=$itemid";

#statement 2
my $content = get($string) || print "Unable to get page for $itemid
\n";

}

Strangely all itemids are displayed on the console as 111111111. If I
comment statement 1 and statement 2 itemids are displayed
correctly .Strangely something is wrong in this loop. Is it because of
the get() function called. Looks really weird ...

Can somebody help on this,
Thanks,
-Rahul
 
R

Rahul!!

This parses as:

    my $content = (get($string) || print "Unable to get page for $itemid\n");

So, $content will either be the return value from get() or the
return value from print().


print() returns a 1 when it succeeds...


Use the lower-precedence form (or) rather than the high-precedence one (||).

    my $content = get($string) or print "Unable to get page for $itemid\n";

--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.liamg\100cm.j.dat/"
The above message is a Usenet post.
I don't recall having given anyone permission to use it on a Web site.
Actually the above print statement is printing all 1111111s instead of
item ids. Not sure but statement 1 and statement 2 are affecting the
value of $itemids.
If I comment the statement 1 and 2, its printing the correct value :(

print $itemid
 
W

Willem

Rahul!! wrote:
)>>>>>>>>>>>>>
) print $itemid;
)>>>>>>>>>>>>>
) Actually the above print statement is printing all 1111111s instead of
) item ids. Not sure but statement 1 and statement 2 are affecting the
) value of $itemids.
) If I comment the statement 1 and 2, its printing the correct value :(
)
) print $itemid

Copy and paste the actual code you're using.


SaSW, Willem
--
Disclaimer: I am in no way responsible for any of the statements
made in the above text. For all I know I might be
drugged or something..
No I'm not paranoid. You all think I'm paranoid, don't you !
#EOT
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,577
Members
45,054
Latest member
LucyCarper

Latest Threads

Top