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

  • Home
  • SEARCH
  • 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 76967
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T20:45:23+00:00 2026-05-10T20:45:23+00:00

I’ve run into what appears to be a variable scope issue I haven’t encountered

  • 0

I’ve run into what appears to be a variable scope issue I haven’t encountered before. I’m using Perl’s CGI module and a call to DBI’s do() method. Here’s the code structure, simplified a bit:

use DBI; use CGI qw(:cgi-lib); &ReadParse; my $dbh = DBI->connect(...............); my $test = $in{test}; $dbh->do(qq{INSERT INTO events VALUES (?,?,?)},undef,$in{test},'$in{test}',$test); 

The #1 placeholder variable evaluates as if it is uninitialized. The other two placeholder variables work.

The question: Why is the %in hash not available within the context of do(), unless I wrap it in double quotes (#2 placeholder) or reassign the value to a new variable (#3 placeholder)?

I think it’s something to do with how the CGI module’s ReadParse() function assigns scope to the %in hash, but I don’t know Perl scoping well enough to understand why %in is available at the top level but not from within my do() statement.

If someone does understand the scoping issue, is there a better way to handle it? Wrapping all the %in references in double quotes seems a little messy. Creating new variables for each query parameter isn’t realistic.

Just to be clear, my question is about the variable scoping issue. I realize that ReadParse() isn’t the recommended method to grab query params with CGI.

I’m using Perl 5.8.8, CGI 3.20, and DBI 1.52. Thank you in advance to anyone reading this.

@Pi & @Bob, thanks for the suggestions. Pre-declaring the scope for %in has no effect (and I always use strict). The result is the same as before: in the db, col1 is null while cols 2 & 3 are set to the expected value.

For reference, here’s the ReadParse function (see below). It’s a standard function that’s part of CGI.pm. The way I understand it, I’m not meant to initialize the %in hash (other than satisfying strict) for purposes of setting scope, since the function appears to me to handle that:

sub ReadParse {     local(*in);     if (@_) {       *in = $_[0];     } else {     my $pkg = caller();       *in=*{'${pkg}::in'};     }     tie(%in,CGI);     return scalar(keys %in); } 

I guess my question is what is the best way to get the %in hash within the context of do()? Thanks again! I hope this is the right way to provide additional info to my original question.

@Dan: I hear ya regarding the &ReadParse syntax. I’d normally use CGI::ReadParse() but in this case I thought it was best to stick to how the CGI.pm documentation has it exactly.

  • 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. 2026-05-10T20:45:23+00:00Added an answer on May 10, 2026 at 8:45 pm

    Per the DBI documentation: Binding a tied variable doesn’t work, currently.

    DBI is pretty complicated under the hood, and unfortunately goes through some gyrations to be efficient that are causing your problem. I agree with everyone else who says to get rid of the ugly old cgi-lib style code. It’s unpleasant enough to do CGI without a nice framework (go Catalyst), let alone something that’s been obsolete for a decade.

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

Sidebar

Ask A Question

Stats

  • Questions 92k
  • Answers 92k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Doing "A and not B" in a single regex is… May 11, 2026 at 6:32 pm
  • Editorial Team
    Editorial Team added an answer global-set-key is defined in subr.el as: (define-key (current-global-map) key command)) May 11, 2026 at 6:32 pm
  • Editorial Team
    Editorial Team added an answer You just need to call gdb with the executable (it… May 11, 2026 at 6:32 pm

Related Questions

I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I am currently running into a problem where an element is coming back from
Seemingly simple, but I cannot find anything relevant on the web. What is the
Configuring TinyMCE to allow for tags, based on a customer requirement. My config is
Is it possible to replace javascript w/ HTML if JavaScript is not enabled on

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.