PERL and DBI Programming,   I cannot create & assign  new STRING Variable  within $sth->fetch()???

Posted on 2004-11-10
Last Modified: 2006-11-17
My partial coding as followed  and I keeps getting compilation errors,  Please let me know why I cannot create and assign a new string variable:


use strict;
use DBI;

my $dbh = DBI->connect ('dbi:Oracle:temp', 'db', 'dboracle',
                      {RaiseError => 1, AutoCommit => 0 } );
#create SQL
my $sql = qq { SELECT userlabel, lineCoding, Attenuation from T1X};

#prepare the SQL execute
my($userlable,$linecoding, $attenuation);
my $sth = $dbh->prepare ( $sql );
$sth->bind_columns(undef,\$userlable, \$linecoding, \$attenuation);

while($sth->fetch() )
   if ($linecoding eq 0) { $new= 'AMI' }
    print "$new \t" ;
  print "Userlable=$userlable \t LineCoding=$linecoding \t Attenuation=$attenuation\n"

Here is the error message:
Global symbol "$new" requires explicit package name at line 38.
Global symbol "$new" requires explicit package name at line 40.
Execution of aborted due to compilation errors.

Please let me know how I can assign a string to a new variable after I evaluate the result from my Retrieval SQL!!!
Question by:wonggla
    LVL 2

    Accepted Solution


    Because you are using the strict pragma, you must declare all of your variables. You have declared several veriables using my(); However, you never declared the variable $new. Also, because you are only setting the value if the match is made you need to declare the variable before the if statement.

    my $new;
    if ($linecoding eq 0) { $new= 'AMI' }

    Author Comment

    THANKS,  I am new to PERL programming,   What is a Strict pragma?  Is there any good book that you can recommand me to use?

    THANKS so much,  it works!!!
    LVL 2

    Expert Comment

    This is a link to the Perl documentation for strict from ActivePerl, only because is not coming up for me.

    Featured Post

    Maximize Your Threat Intelligence Reporting

    Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

    Join & Write a Comment

    Suggested Solutions

    Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
    There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
    Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
    Hi everyone! This is Experts Exchange customer support.  This quick video will show you how to change your primary email address.  If you have any questions, then please Write a Comment below!

    754 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now