The values of $status, $soc, and $subscriber are based on @row_text, but that array is never populated. Each of those scalars will be undef.
For other interested monks, here's my feeble attempt at reformatting:
use warnings; use strict; &readfile; sub readfile{ my $input_FL; my @file_row; my @row_text; my $row_data; my $row_text; my $line =0; my $status; my $soc; my $subscriber; my @ar_OR_STA; my @ar_OR_SOC; my @ar_OR_SUB; $input_FL = "C:\\taj.txt"; chomp $input_FL; #remove enter key or any spaces open(IN_FL, $input_FL) || die ("unable to open directory"); while (<IN_FL>){ @file_row=<IN_FL>; print $#file_row; }#while close IN_FL; foreach(@file_row) { while ($line < $#file_row +1){ $row_data =$file_row[$line]; chop ($row_data); next unless /\S/; # only use lines that contain +something + else than spaces #print "$row_data\n"; if ($row_data =~ /^[d]/) { $status = $row_text[0]; $status =~ s/(\W+)/ /gs; #Eliminate all non-+word char +acters followed by space. #$ar_OR_STA[$i]=$status; #Here $[=1, so @ar_STA[0] doe +s not have any value. Original Array of Status push (@ar_OR_STA,$status); print "@ar_OR_STA\n"; $soc = $row_text[1]; $soc =~ s/(\W+)/ /; #Eliminate all non-word characters + followed by space. #$ar_OR_SOC[$i-1]=$soc; #Here $[=1, so @ar_STA[0] does + not have any value. Original Array of Status $subscriber = $row_text[3]; $subscriber =~ s/(\D+)/ /; #Eliminate all non-digits f +ollowed by space. #$ar_OR_SUB[$i-1]=$subscriber; #Here $=1, so @ar_SUB[0 +] does not have any value.Original Array of Subscriber } else { print " File is invalid\n"; } $line++; }#while }#foeach } # Here, I get Uninitaialized value in substitution(s///) in the follow +ing lines?Anybody Know why? $status =~ s/(\W+)/ /gs; $soc =~ s/(\W+)/ /; $subscriber =~ s/(\D+)/ /; # and use of initialized value in join or s +tring at print "@ar_OR_STA\n";
As an aside, I think changing the value of $[ could have some very confusing unwanted consequences later in this code's life. (I quote perlvar: "Its use is highly discouraged.") If you must go through with that, use local to limit the scope (although I can't tell that you haven't from the code you posted).
In reply to Re: Use of Uninitialized value in substitution (s///)
by kyle
in thread Use of Uninitialized value in substitution (s///)
by taj
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |