Re: Use of uninitialized value Error

2005-12-30 Thread JupiterHost.Net



David Gilden wrote:

Hello, 


Hello,


In the Script below the line:  last if ($num = 35)
is giving me this error: Use of uninitialized value in int 


How do I avoid this error?


a) Initialize it :)

  my $num = 0;

b) don't use warnings - but don't do that

c) turn off uninitialized wanrings (see perldoc warnings) - but don't do 
that either



Also please use strict, expecially on problem code you're posting to 
the list for help on. IN this case you waould have gotten an error about 
 this unless I looked at it wrong.


HTH

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Use of uninitialized value Error

2005-12-30 Thread Adriano Ferreira
On 12/30/05, David Gilden [EMAIL PROTECTED] wrote:
 In the Script below the line:  last if ($num = 35)
 is giving me this error: Use of uninitialized value in int

That's not an error, but a warning. You will find that execution goes
after this.

 How do I avoid this error?
@files probably contain a name which does not match /(\d+)/. In this
case, $1 turns to be undef, and so happens with $num (because
int(undef) - undef) up to the numeric comparison which (under -w)
emits the warning.

To avoid the warning, maybe you don't need to process such filenames

  ...
  $_ =~ /(\d+)/;
  next unless $1; # skip to the next item
  $num = int($1);
  ...

or you consider $num as 0 in this case, by replacing C$num = int($1)
with C$num = int($1 || 0)



 my @files contains: Gambia001.tiff through Gambia100.tiff

 #!/usr/bin/perl -w

 my @files =*;
 $tmp= 1;


 for (@files){
 my $old = $_;
 $_ =~ /(\d+)/;
 $num = int($1);
 #$_ =~s/Gambia_Pa_Bobo_kuliyo_\d+/Gambia_Pa_Bobo_kuliyo_$tmp/i;
 print $num\n;
 #$tmp++;
 last if ($num = 35);
 # rename($old,$_);
 }

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Use of uninitialized value Error

2005-12-30 Thread John W. Krahn
David Gilden wrote:
 Hello, 

Hello,

 In the Script below the line:  last if ($num = 35)
 is giving me this error: Use of uninitialized value in int 
 
 How do I avoid this error?

You are using the results of a regular expression match without verifying that
the regular expression matched successfully.  Don't do that.


 my @files contains: Gambia001.tiff through Gambia100.tiff 
 
 #!/usr/bin/perl -w
 
 my @files =*;
 $tmp= 1;
 
 
 for (@files){
 my $old = $_;
 $_ =~ /(\d+)/;
 $num = int($1);

if ( /(\d+)/ ) {
$num = int $1;
}

Or perhaps:

next unless /(\d+)/;
$num = int $1;


Or maybe only work on files that actually have digits in them:

my @files = *[0-9]*;


 #$_ =~s/Gambia_Pa_Bobo_kuliyo_\d+/Gambia_Pa_Bobo_kuliyo_$tmp/i;
 print $num\n;
 #$tmp++;
 last if ($num = 35); 
 # rename($old,$_);
 }


John
-- 
use Perl;
program
fulfillment

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Use of uninitialized value Error

2005-12-30 Thread Tom Phoenix
On 12/30/05, David Gilden [EMAIL PROTECTED] wrote:

 $_ =~ /(\d+)/;
 $num = int($1);

If there's no digit in $_, then $1 will be undef (or worse; see
below). I think that's probably your bug: Some filename isn't like the
others. Instead of this:

 my @files =*;

Consider something like this:

my @files = Gambia*.tiff;

Later, when you're trying to get the number from the string, you can
allow for the possibility that there isn't one by checking the value
of the pattern match. If it's false, the pattern didn't match, and you
shouldn't use $1.

if (/(\d+)/) {
$num = $1;
} else {
warn No digits found in '$_', continuing...\n;
next;
}

Hope this helps!

--Tom Phoenix
Stonehenge Perl Training

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




RE: Use of uninitialized value error message

2002-03-14 Thread Jason Larson

 -Original Message-
 From: John W. Krahn [mailto:[EMAIL PROTECTED]]
 Subject: Re: Use of uninitialized value error message
 
 Jason Larson wrote:
  
  I'm still new to Perl myself, so I can't tell you exactly 
 what's happening,
  but it looks like $result_value1 is undef when it gets to 
 the if statement.
  I think a better way to accomplish what you're trying to do 
 is simply:
  
my $result_value1;
if ($result_value) { #$result_value1 is defined
 ^^  ^^^
 This is _NOT_ testing whether $result_value1 is defined or 
 not (in fact
 it is not testing $result_value1 at all :-), it is testing whether
 $result_value1 is true or false which is not the same thing.
 
if ( defined $result_value1 ) { #$result_value1 is defined
 
Doh!  My bad...  You are, of course, correct.  Thanks for pointing out my
error.
(for any beginners reading this that may not understand the difference, let
me give a quick example...)
 use warnings;
 use strict;
 my $result_value = 0;
 if ($result_value) {
   print \$result_value is defined and is: $result_value;
 } else {
   print \$result_value is undefined
 }
 __END__

This prints out $result_value is undefined, which is obviously not true.
If we change the if statement as John pointed out, we get a better result

 if (defined $result_value) {

This prints out $result_value is defined and is: 0, which is a better
evaluation of the variable.

Sorry about the confusion, and I hope this helps...
Jason


CONFIDENTIALITY NOTICE:



The information contained in this ELECTRONIC MAIL transmission
is confidential.  It may also be privileged work product or proprietary
information. This information is intended for the exclusive use of the
addressee(s).  If you are not the intended recipient, you are hereby
notified that any use, disclosure, dissemination, distribution [other
than to the addressee(s)], copying or taking of any action because
of this information is strictly prohibited.





RE: Use of uninitialized value error message

2002-03-13 Thread Jason Larson

 -Original Message-
 From: Ho, Tony [mailto:[EMAIL PROTECTED]]
 Subject: Use of uninitialized value error message
 
 Hi guys
 I was wondering if you could help me with the following problem.
  
 I am getting the following error message:
  
 Use of uninitialized value in string ne at 
 format_imsi_msisdn.pl line 257.
 
 line 257 and beyond consist of the following:
  
 if ($result_value1 ne  ) {
   $a= substr($result_value1, 0, 8);
   $b= substr($result_value1, 8, 2);
   $c= substr($result_value1, 10, 2);
   return ($a, $b, $c);
 }
 else {
   return ( ,  ,  );
 }
  
 I declare the variable result_value1 at the begining of the method as
 follows
  
 my $result_value1 = ;
  
 Any ideas why ?

I'm still new to Perl myself, so I can't tell you exactly what's happening,
but it looks like $result_value1 is undef when it gets to the if statement.
I think a better way to accomplish what you're trying to do is simply:

  my $result_value1;
  if ($result_value) { #$result_value1 is defined
 $a= substr($result_value1, 0, 8);
 $b= substr($result_value1, 8, 2);
 $c= substr($result_value1, 10, 2);
  } else { #$result_value1 is still undef
 return ( ,  ,  );
  }

Hope this helps...
Jason


CONFIDENTIALITY NOTICE:



The information contained in this ELECTRONIC MAIL transmission
is confidential.  It may also be privileged work product or proprietary
information. This information is intended for the exclusive use of the
addressee(s).  If you are not the intended recipient, you are hereby
notified that any use, disclosure, dissemination, distribution [other
than to the addressee(s)], copying or taking of any action because
of this information is strictly prohibited.





RE: Use of uninitialized value error message

2002-03-13 Thread Nikola Janceski

that actually won't get rid of the warning. but you are right the
declaration at the top of the script of the varible goes out of scope when
it reaches the if.

you are using -w or 
use warnings; in your script that is causing the warning.

perhaps attaching the code would help but we can't tell where the varible
goes out of scope.



-Original Message-
From: Jason Larson [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, March 13, 2002 11:06 AM
To: 'Ho, Tony'; '[EMAIL PROTECTED]'
Subject: RE: Use of uninitialized value error message


 -Original Message-
 From: Ho, Tony [mailto:[EMAIL PROTECTED]]
 Subject: Use of uninitialized value error message
 
 Hi guys
 I was wondering if you could help me with the following problem.
  
 I am getting the following error message:
  
 Use of uninitialized value in string ne at 
 format_imsi_msisdn.pl line 257.
 
 line 257 and beyond consist of the following:
  
 if ($result_value1 ne  ) {
   $a= substr($result_value1, 0, 8);
   $b= substr($result_value1, 8, 2);
   $c= substr($result_value1, 10, 2);
   return ($a, $b, $c);
 }
 else {
   return ( ,  ,  );
 }
  
 I declare the variable result_value1 at the begining of the method as
 follows
  
 my $result_value1 = ;
  
 Any ideas why ?

I'm still new to Perl myself, so I can't tell you exactly what's happening,
but it looks like $result_value1 is undef when it gets to the if statement.
I think a better way to accomplish what you're trying to do is simply:

  my $result_value1;
  if ($result_value) { #$result_value1 is defined
 $a= substr($result_value1, 0, 8);
 $b= substr($result_value1, 8, 2);
 $c= substr($result_value1, 10, 2);
  } else { #$result_value1 is still undef
 return ( ,  ,  );
  }

Hope this helps...
Jason


CONFIDENTIALITY NOTICE:



The information contained in this ELECTRONIC MAIL transmission
is confidential.  It may also be privileged work product or proprietary
information. This information is intended for the exclusive use of the
addressee(s).  If you are not the intended recipient, you are hereby
notified that any use, disclosure, dissemination, distribution [other
than to the addressee(s)], copying or taking of any action because
of this information is strictly prohibited.





The views and opinions expressed in this email message are the sender's
own, and do not necessarily represent the views and opinions of Summit
Systems Inc.


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




RE: Use of uninitialized value error message

2002-03-13 Thread Jason Larson

  Original Message-
From: Ho, Tony [mailto:[EMAIL PROTECTED]]
Subject: RE: Use of uninitialized value error message

Hi Nikola/Jason 
Thanks for the help. 
The variable $result_value1 is declared within the subroutine and is never
used outside the subroutine. 
I originally had the following piece of code (which I forgot to show you
guys in the previous email): 
 
 $result_value1 = $database1{$input_key1}  
 
 But I changed the above code to the following and it worked (Use of
uninitialized value error message did not appear):
 
 $result_value1 = $database1{$input_key1} ||  ;  
 

ahh... that would do it, though I don't think that's the preferred way to
solve your problem.
 
You are getting the Use of uninitialized value warning message because
$database1{$input_key1} is undef.  You are simply bypassing that by making
$result_value1 a   if it would otherwise return undef.  By using your
original code ( $result_value1 = $database1{$input_key1}; ) with if
($result_value1); you do what you want and avoid the warning because you
are now checking to see if $result_value1 is defined.  I know that Nikola
says you will still get the warning, but it always works for me...  :)
 
Hope this helps...
Jason


CONFIDENTIALITY NOTICE:



The information contained in this ELECTRONIC MAIL transmission
is confidential.  It may also be privileged work product or proprietary
information. This information is intended for the exclusive use of the
addressee(s).  If you are not the intended recipient, you are hereby
notified that any use, disclosure, dissemination, distribution [other
than to the addressee(s)], copying or taking of any action because
of this information is strictly prohibited.





RE: Use of uninitialized value error message

2002-03-13 Thread Ho, Tony

Hi Nikola/Jason
Thanks for the help.
The variable $result_value1 is declared within the subroutine and is never
used outside the subroutine.
I originally had the following piece of code (which I forgot to show you
guys in the previous email):

$result_value1 = $database1{$input_key1}

But I changed the above code to the following and it worked (Use of
uninitialized value error message did not appear):

$result_value1 = $database1{$input_key1} ||  ; 
if ($result_value1 ne  ) {
 $a= substr($result_value1, 0, 8);
 $b= substr($result_value1, 8, 2);
 $c= substr($result_value1, 10, 2);
 return ($a, $b, $c);
}
else {
 return ( ,  ,  );
}

Cheers
Tony

-Original Message-
From: Nikola Janceski [mailto:[EMAIL PROTECTED]]
Sent: 13 March 2002 17:16
To: 'Jason Larson'; 'Ho, Tony'; '[EMAIL PROTECTED]'
Subject: RE: Use of uninitialized value error message


that actually won't get rid of the warning. but you are right the
declaration at the top of the script of the varible goes out of scope when
it reaches the if.

you are using -w or 
use warnings; in your script that is causing the warning.

perhaps attaching the code would help but we can't tell where the varible
goes out of scope.



-Original Message-
From: Jason Larson [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, March 13, 2002 11:06 AM
To: 'Ho, Tony'; '[EMAIL PROTECTED]'
Subject: RE: Use of uninitialized value error message


 -Original Message-
 From: Ho, Tony [mailto:[EMAIL PROTECTED]]
 Subject: Use of uninitialized value error message
 
 Hi guys
 I was wondering if you could help me with the following problem.
  
 I am getting the following error message:
  
 Use of uninitialized value in string ne at 
 format_imsi_msisdn.pl line 257.
 
 line 257 and beyond consist of the following:
  
 if ($result_value1 ne  ) {
   $a= substr($result_value1, 0, 8);
   $b= substr($result_value1, 8, 2);
   $c= substr($result_value1, 10, 2);
   return ($a, $b, $c);
 }
 else {
   return ( ,  ,  );
 }
  
 I declare the variable result_value1 at the begining of the method as
 follows
  
 my $result_value1 = ;
  
 Any ideas why ?

I'm still new to Perl myself, so I can't tell you exactly what's happening,
but it looks like $result_value1 is undef when it gets to the if statement.
I think a better way to accomplish what you're trying to do is simply:

  my $result_value1;
  if ($result_value) { #$result_value1 is defined
 $a= substr($result_value1, 0, 8);
 $b= substr($result_value1, 8, 2);
 $c= substr($result_value1, 10, 2);
  } else { #$result_value1 is still undef
 return ( ,  ,  );
  }

Hope this helps...
Jason


CONFIDENTIALITY NOTICE:



The information contained in this ELECTRONIC MAIL transmission
is confidential.  It may also be privileged work product or proprietary
information. This information is intended for the exclusive use of the
addressee(s).  If you are not the intended recipient, you are hereby
notified that any use, disclosure, dissemination, distribution [other
than to the addressee(s)], copying or taking of any action because
of this information is strictly prohibited.





The views and opinions expressed in this email message are the sender's
own, and do not necessarily represent the views and opinions of Summit
Systems Inc.



Re: Use of uninitialized value error message

2002-03-13 Thread John W. Krahn

Jason Larson wrote:
 
 I'm still new to Perl myself, so I can't tell you exactly what's happening,
 but it looks like $result_value1 is undef when it gets to the if statement.
 I think a better way to accomplish what you're trying to do is simply:
 
   my $result_value1;
   if ($result_value) { #$result_value1 is defined
^^  ^^^
This is _NOT_ testing whether $result_value1 is defined or not (in fact
it is not testing $result_value1 at all :-), it is testing whether
$result_value1 is true or false which is not the same thing.

   if ( defined $result_value1 ) { #$result_value1 is defined


  $a= substr($result_value1, 0, 8);
  $b= substr($result_value1, 8, 2);
  $c= substr($result_value1, 10, 2);
   } else { #$result_value1 is still undef
  return ( ,  ,  );
   }



John
-- 
use Perl;
program
fulfillment

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]