strange behaviour w.r.t get function

Discussion in 'Perl Misc' started by Rahul!!, Mar 30, 2011.

  1. Rahul!!

    Rahul!! Guest

    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
    Rahul!!, Mar 30, 2011
    #1
    1. Advertising

  2. Rahul!!

    Rahul!! Guest

    On Mar 30, 8:58 pm, Tad McClellan <> wrote:
    > Rahul!! <> wrote:
    > >     my $content = get($string) || print "Unable to get page for $itemid
    > > \n";

    >
    > 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().
    >
    > > Strangely all itemids are displayed on the console as 111111111.

    >
    > print() returns a 1 when it succeeds...
    >
    > > Can somebody help on this,

    >
    > 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.
    >>>>>>>>>>>>>

    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
    Rahul!!, Mar 30, 2011
    #2
    1. Advertising

  3. Rahul!!

    Willem Guest

    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
    Willem, Mar 30, 2011
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. muser
    Replies:
    9
    Views:
    317
    Rolf Magnus
    Oct 14, 2003
  2. Replies:
    23
    Views:
    708
    Dave Thompson
    Nov 20, 2006
  3. Andy Chambers
    Replies:
    1
    Views:
    383
    Daniel Dyer
    May 14, 2007
  4. Paulo da Silva
    Replies:
    8
    Views:
    361
  5. sunrrrise
    Replies:
    2
    Views:
    409
    Chris Angelico
    May 23, 2011
Loading...

Share This Page