Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Use of uninitialized value in concatenation (.)

Status
Not open for further replies.

babcia01

IS-IT--Management
Jul 11, 2002
37
0
0
US
This is an extract from my code:
my $args1;
my $args2;
my $args3;
:
# the below done in a loop with many lines:
($cpu,$pid,$user,$ni,$time,$args1,$args2,$args3) = split(' ',$line);

$ps_out .= qq['"$args1 $args2 $args3"'];

On execution, I am getting this warning:
Use of uninitialized value in concatenation (.)

The args2 and args3 may often be with no value (spaces).

How do I eliminate the warning?

Thank you

 
Initialize them to a value, even if it is just "" before using them. ______________________________________________________________________
TANSTAAFL!
 
I did it: in the begining i assigned (my args1 = "", same for arsg2m args3)and also after the ps_out statement to take into consideration that the subsequent line may have space for args2 and args3. Still the same warning.
Thank you again
 
Instead of trying to do it inside the qq, why not do it as a set of if statements? ______________________________________________________________________
TANSTAAFL!
 
Add the following lines after the split statement:
Code:
$args2 ||= '';
$args3 ||= '';
If there are not enough fields in the line that you are splitting then $args2 and $args3 will be undefined, no matter what you initialize them to. This is the cause of the warning you get. The above two lines will assign the empty string to the two variables if they are undefined, otherwise it will leave them alone.

jaa
 
Thank you all. The last one from "jaa" worked as I wanted.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top