in reply to Use of uninitialized value in concatenation (.) or string error after adding new arguement on command line

First, you have unbalanced curly brackets in your posted code. This means I am guessing at how your code is actually structured. In the future, please post code that a monk can just download and run to replicate your issue - see How (Not) To Ask A Question.

Assuming that the cause of your error in present within your code snippet, the warning is being thrown by your print statement. Specifically, variable interpolation within double quotes is implicitly done with the concatenation operator, thus when you attempt to print without first initializing $csa_file, warnings notes you are concatenating with an undefined value. See String interpolation. I suspect this error is the result from your misplaced curly bracket. Perhaps you mean something like this:

#_ Command line options & setup filenames for ($i=0; $i<=$#ARGV; $i++) { if($ARGV[$i] eq "-a") { $alignment_file = $ARGV[$i+1]; } if($ARGV[$i] eq "-s") { $scorecons_file = $ARGV[$i+1]; } if($ARGV[$i] eq "-i") { $image_file = $ARGV[$i+1]; } if($ARGV[$i] eq "-m") { $numbered_model = $ARGV[$i+1]; } if($ARGV[$i] eq "-c") { $csa_file = $ARGV[$i+1]; } } print "test $csa_file\n"; #_ Check for minimum number of command line argument variables if($#ARGV < 6) { Usage(); print "NOT ENOUGH COMMAND LINE ARGUMENTS\n"; exit 0; } $fh_csa = new FileHandle($csa_file, "r") || die "Cannot open CSA file: + $csa_file ($!)";

Some side notes on style:

  1. Generally, the lower precedence or is used in testing in place of the high precedence || you have used to test your file open. It doesn't matter here, but it will matter in similar constructs, such as if you omit parentheses on an argument list.
  2. Foreach constructs tend to be more resilient than C-style for loops. Consider that replacing your for loop with:

    foreach my $i (0 .. $#ARGV)

  3. You are obviously using warnings given then message you report, but are not using strictures. You can avoid a lot of headaches if you use strict.

Update: Your update supports the conclusion that you have a brackets probelm. You are only evaluating the first term of your argument list opening your file and continuing.

  • Comment on Re: Use of uninitialized value in concatenation (.) or string error after adding new arguement on command line
  • Select or Download Code

Replies are listed 'Best First'.
Re^2: Use of uninitialized value in concatenation (.) or string error after adding new arguement on command line
by Angharad (Pilgrim) on May 07, 2009 at 15:39 UTC
    Well actually I am using strict. But thanks for the help :)I will see if that helps
      My update was poorly worded (fixed). The supported conclusion is that your blocks are not structured like you expect. Try it with the posted code.

      I find it surprising that you are using strict, given that there are no my statements in your snippet. It is a bad idea to use loop variables that are not limited to that loop in scope. This is particularly risky with C-style loops.

        Oh I see. Well, I declared all the variables at the beginning of the script - so are you saying I should have declared them elsewhere?
Re^2: Use of uninitialized value in concatenation (.) or string error after adding new arguement on command line
by Angharad (Pilgrim) on May 07, 2009 at 15:43 UTC
    yep, that sorted it. Thanks