Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: Having to specify $_

by dws (Chancellor)
on Dec 09, 2002 at 03:08 UTC ( #218439=note: print w/replies, xml ) Need Help??


in reply to Having to specify $_

You'd think (if you think like me) that $_ is assigned the value of $sth->fetchrow_hashref everytime through the loop.

I'd expect that $_ would be assigned during a for or foreach loop, but not during a while loop. Try

push @results, $_ foreach ($sth->fetchrow_hashref());


Update: It's possible to be mislead by   while ( <FILE> ) { ... Here, $_ does get set. But this is actually due to input operator behavior, as covered in the "I/O Operators" section in perlop.

Props to rob_au for prodding this clarification.

Replies are listed 'Best First'.
Re: Re: Having to specify $_
by sauoq (Abbot) on Dec 09, 2002 at 03:20 UTC
    I'd expect that $_ would be assigned during a for or foreach loop, but not during a while loop. Try
    push @results, $_ foreach ($sth->fetchrow_hashref());

    That will only work if the function actually returns a list (and in this case it doesn't.) It will not call the function repeatedly until it returns false.

    -sauoq
    "My two cents aren't worth a dime.";
    

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://218439]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (5)
As of 2022-10-05 16:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My preferred way to holiday/vacation is:











    Results (24 votes). Check out past polls.

    Notices?