CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
$@ gives SCALAR(0x...)

 



rohant
Novice

Jan 21, 2007, 9:31 PM

Post #1 of 6 (1034 views)
$@ gives SCALAR(0x...) Can't Post

Dear all,
i am a new bee to perl
i am using eval block to trap errors in the script.
when a error occurs i am printing the $@ variable which actually should print the error message/detail.
but it is printing something like SCALAR(0x...).
i am not that comfortable yet on references. if its is a reference as it looks like how to dereference it and print the error string.what could be the reason i am getting the error string as above and not regular string?can anyone help me out in above issue?

thanks in advance
-Rohant


davorg
Thaumaturge / Moderator

Jan 22, 2007, 5:21 AM

Post #2 of 6 (1026 views)
Re: [rohant] $@ gives SCALAR(0x...) [In reply to] Can't Post

You're right that $@ will normally contain a simple scalar value. You're also right that what you are seeing is probably a reference to a scalar.

So the question is how are you getting a reference into $@. And that's impossible to answer without seeing some code. Is it possible to give us a short (10 - 20 lines) program that demostrates this problem?

--
Dave Cross, Perl Hacker, Trainer and Writer
http://www.dave.org.uk/
Get more help at Perl Monks


rohant
Novice

Jan 22, 2007, 7:28 AM

Post #3 of 6 (1023 views)
Re: [davorg] $@ gives SCALAR(0x...) [In reply to] Can't Post

Right now i dont have the source code in front of me.
i will tell you a psuedo code

i have a server.cgi file
from which i am calling another module functions say Pg.pm
this code will give you both the question scenario that i am looking for.

my server.cgi looks like this
------------------

Code
sub login   { 
eval{
# connect to DBI calling new method of Pg.pm
which returns $conn object

};
if($@){
print "Error:$DBI:errstr" #1
}

eval{
# some more methods from Pg.pm

}
if($@){
print "Error:$@" #2
}

}


Query 1.

here at #1 i am using $DBI::errstr which is a global variable i guess.but as multiple clients will be using the application at a time.and this being a server side script, so actaully i want the error message for the specific user whose DB connection request failed and not the global one.
(my understanding might be wrong please correct if it is)


Query 2.
here at #2 the variable $@ is printing some scalar reference value as said in the post.

i hope this much info would suffice.
as i cant put the code here being confidential.
Please let me know if there is solution on these issues.
thanks again for your prompt reply and waiting for it again.
Rohant


rohant
Novice

Jan 22, 2007, 7:32 AM

Post #4 of 6 (1021 views)
Re: [rohant] $@ gives SCALAR(0x...) [In reply to] Can't Post

the query 1 in previous reply is for one more post to which you have answered in beginners section.
i thought it would be easier for you to get the psuedo code for both in one place so posting the code for both queries here only


davorg
Thaumaturge / Moderator

Jan 23, 2007, 8:31 AM

Post #5 of 6 (1007 views)
Re: [rohant] $@ gives SCALAR(0x...) [In reply to] Can't Post

1/ $DBI::errstr is global within one instance of your program. Other instances won't effect it. You should be able to use it without a problem.

2/ All I know about Pg.pm is that it has been deprecated for some time. You should really be using DBI and DBD::Pg instead.

--
Dave Cross, Perl Hacker, Trainer and Writer
http://www.dave.org.uk/
Get more help at Perl Monks


rohant
Novice

Jan 23, 2007, 3:02 PM

Post #6 of 6 (1004 views)
Re: [davorg] $@ gives SCALAR(0x...) [In reply to] Can't Post

no no. the Pg.pm is a custom class created by me to handle database interations.it contains methods to access the database information.thats it. i am using DBI only.

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives