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

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:


#!/usr/local/bin/perl

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->execute();
$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"
 }
  $sth->finish();

===================
Here is the error message:
perl oracle.pl
Global symbol "$new" requires explicit package name at oracle.pl line 38.
Global symbol "$new" requires explicit package name at oracle.pl line 40.
Execution of oracle.pl 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!!!
THANKS
wongglaAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

godspropyCommented:
wonggla,

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' }
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
wongglaAuthor Commented:
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!!!
0
godspropyCommented:
This is a link to the Perl documentation for strict from ActivePerl, only because perldoc.com is not coming up for me.

http://aspn.activestate.com/ASPN/docs/ActivePerl/lib/strict.html
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Perl

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.