Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re^6: $dbh could not be passed to function unless another variable is also passed

by tukusejssirs (Beadle)
on Aug 08, 2019 at 14:53 UTC ( [id://11104183]=note: print w/replies, xml ) Need Help??


in reply to Re^5: $dbh could not be passed to function unless another variable is also passed
in thread $dbh could not be passed to function unless another variable is also passed

Corion: The error was Can't locate object method "prepare" via package "DBI::db=HASH(0x215bc78)" (perhaps you forgot to load "DBI::db=HASH(0x215bc78)"?)

Fletch and Corion:

You are right. When I removed the quotes (leaving only my $dbh = $_[0];), it works as expected.

Anyway, what exactly does ‘The solution is to not quote variables when you don't need it.’ mean? That I should quote only strings?

Thank you both!

Replies are listed 'Best First'.
Re^7: $dbh could not be passed to function unless another variable is also passed
by hippo (Bishop) on Aug 08, 2019 at 14:58 UTC
    I should quote only strings?

    Yes

Re^7: $dbh could not be passed to function unless another variable is also passed
by dsheroh (Monsignor) on Aug 09, 2019 at 07:24 UTC
    Anyway, what exactly does ‘The solution is to not quote variables when you don't need it.’ mean? That I should quote only strings?
    When you put quotes around something, you turn that thing into a string. You can quote whatever you want to, but, after you quote it, it will be a string, so you should only quote things that you want to be strings.

    But you should also remember what already is a string and avoid re-quoting existing strings, partly because it's wasted keystrokes, partly because it's potentially inefficient (it's less work to just use the existing string than to change the existing string into a new string and then use the new one), and partly because there could be some edge cases where quoting the existing string might change it or otherwise break something.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (4)
As of 2024-04-20 01:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found