Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6592281
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T17:32:05+00:00 2026-05-25T17:32:05+00:00

I have the following code in in a Perl script I’m writing: #!/usr/bin/perl use

  • 0

I have the following code in in a Perl script I’m writing:

#!/usr/bin/perl
use DBI;
use Getopt::Long;
use Time::HiRes;
use Error qw(:try);

....

my $starttime = Time::HiRes::time;

try {
    my $dbh = DBI->connect("dbi:Sybase:$server", $username, $password);
    $dbh->do("use $database");
    my $query="exec OfflineDatabaseReport";

    $row = $dbh->selectrow_hashref($query);

    $dbh->disconnect();
} catch Error with {
    print "boom";
    exit 1;
};
my $endtime = Time::HiRes::time;
my $timetaken = $endtime - $starttime;

The script worked fine until I wrapped the data access portion in the try...catch block. Now I get the following exception thrown:

Can’t use string (“1316135985.90893”) as a HASH ref while “strict refs” in use at /usr/lib/perl5/site_perl/5.8.8/Error.pm line 217.

I did try setting:

no strict "refs";

But I still get the same error. Am I being naive in my usage of a try/catch block here?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T17:32:05+00:00Added an answer on May 25, 2026 at 5:32 pm

    This is how the parser sees the code:

    try({ ... }, catch(Error, with({ ... }, my $endtime = Time::HiRes::time)));
    

    Meaning, it passes the result of setting $endtime to Time::HiRes::time as the 2nd argument of the with BLOCK sub. Looking at the source of Error.pm, I see:

    sub with (&;$) {
        @_
    }
    

    Which means with BLOCK,SCALAR is a valid argument list. All it does is pass the arguments up to catch, which interprets my $endtime = Time::HiRes::time as its $clauses. catch itself returns $clauses, which turns the whole statement into:

    try({ ... }, my $endtime = Time::HiRes::time);
    

    try assumes $clauses is a hashref, as you can see by the call to

    $clauses->{'finally'}->()
        if(defined($clauses->{'finally'}));
    

    So perl tries to use the value of Time::HiRes::time as a hashref, which it most certainly cannot, since it’s actually a scalar with a value of “1316135985.90893”.

    So yeah, the semicolon at the end of the catch block.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code that uses 'paste' and AWK script inside Perl. use
I have a problem with the following code (Perl/Cygwin) #!/usr/bin/perl open FILE, >, filename.txt
Today, I have written a perl script, as the following code: my @files =
I have Perl code similar to the following: # -- start -- my $res;
I have following code snippet that i use to compile class at the run
I am writing a script in Perl and have a question about Perl's foreach
I have the following line in my Perl script: s/b(w+)b/ $replaces{$1} ? $replaces{$1} :
I'm still learning Perl and CLASS::DBI. I have a script that does a bunch
I have the following Perl code: STDOUT->autoflush(1); foreach(...) { ... foreach(...) { print(Processing $folder);
I have the following code in Perl which posts to my HTTP Servlet, calling

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.