Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

question on strings

by kprasanna_79 (Hermit)
on Mar 26, 2007 at 16:31 UTC ( [id://606612]=perlquestion: print w/replies, xml ) Need Help??

kprasanna_79 has asked for the wisdom of the Perl Monks concerning the following question:

Hi Revered monks,

i have a variable which holds a value returned from a subroutine

$var = $pack->get_proj();

i am using this value for connecting the db

new myproj::DB(["dbi:Oracle:$db",$var,$var.length($var)]);

But this thows time out error. But when i hardcode the value it works fine

new myproj::DB(["dbi:Oracle:$db","proj",$var.length($var)]);

The only difference is the doublequote present in the character (proj), which is nothng but string. Is there any way i can make the $var as string like to_string($var).


I have verified all the ways and only this is the matter

Please throw some light on this.
-Prasanna.K

Replies are listed 'Best First'.
Re: question on strings
by mreece (Friar) on Mar 26, 2007 at 16:56 UTC
    are you sure $var contains what you think it does?
    use Data::Dumper; warn Dumper($var);
    if you think stringifying $var will really help, you can do it via concatenation to an empty string ($var.'') or by interpolating it in quotes ("$var").
Re: question on strings
by Fletch (Bishop) on Mar 26, 2007 at 17:06 UTC

    Original question aside:

    • using indirect object notation for method calls is advised against; that'd be better written as myproj::DB->new( ... )
    • lowercase package names are reserved for use as compiler pragmas; granted "myproj" is probably safe, but it just . . . looks wrong
    • Passing the list of args in an arrayref also looks strange. You're building an anonymous array which you're probably going to deference in your new method after copying it from $_[0] anyhow; doesn't make sense to wrap things up in an extra layer (then again there may be a perfectly good reason; but again, looks strange)

    As for forcing $var to be a string, if it is it is. There's not really any coercion needed, but if you absolutely must then "$var" would force stringification (but it's usually not needed). Given the other weirdness the problem probably lies elsewhere; as was suggested above make sure that $var contains what you think it does through an extra print or in the debugger.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (6)
As of 2024-03-28 23:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found