Hello Chris,

The variables aren't /initialized/ before they're used in this code.. So, something like print $out actually won't even know what the value of $out is in the first place, let alone write in it.

You mentionned "processed.txt", but it was in a comment, not in the actual code.. And it's only because I'm human that I "deduced" that this is the output file you /meant/ ..

I rewrote your code and at the very beginning, just before any variable was /used/ [i.e, just after "use strict", I added


# Intialization begins

my $cell        ='';
my $filename    ='';
my $in          ='';
my $line        ='';
my $mtype       ='';
my $out         ='';
my $outputfile  ="processed.txt";
my $rlptxat     ='';
my $sector      ='';
my $version     ='';


my @data   =0;
my @fields =0;
my @val    =0;

# Initialization ends


I also changed

open( my $in, '<', $filename) or die("Can't open $filename for reading: $!");
open( my $out, '>', $outputfile) or die("Can't create file $outputfile: $!);

Into :

open($in, '<', $filename) or die("Can't open $filename for reading: $!");
open($out, '>', $outputfile) or die("Can't create file $outputfile: $!);

Because there was an error that said they masked "earlier declaration in same scope"

Once done and run .. It gave

------------------------
Bareword found where operator expected at smartphone.pl line 55, near "print $out "Version"
  (Might be a runaway multi-line "" string starting on line 35)
    (Do you need to predeclare print?)
Backslash found where operator expected at smartphone.pl line 55, near "Sector\" String found where operator expected at smartphone.pl line 59, near "print $out join(';',@data), ""
  (Might be a runaway multi-line "" string starting on line 55)
    (Missing semicolon on previous line?)
String found where operator expected at smartphone.pl line 59, at end of line
    (Missing semicolon on previous line?)
syntax error at smartphone.pl line 55, near "print $out "Version"
syntax error at smartphone.pl line 55, near "Sector\"
Can't find string terminator '"' anywhere before EOF at smartphone.pl line 59.
------------------

As you notice it eliminated a good portion of error lines.. The rest, I don't know yet how to deal with it..This is the very first time I read and write in Perl [ You could say so by the baby writing style] so this is the most "correct" or should I say the "least wrong" I can make for now..



All my best,

~Jugurtha~



On 12/24/2010 04:55 AM, Chris Stinemetz wrote:
   1 #!/usr/bin/perl
   2
   3 use warnings;
   4 use strict;
   5
   6 #Get data from EVDOPCMD.txt file and output to processed.txt file.
   7
   8 print "What file do you want to parse?";
   9 $filename =<STDIN>;
  10
  11 open( my $in, '<', $filename) or die("Can't open $filename for reading: 
$!");
  12 open( my $out, '>', $outputfile) or die("Can't create file $outputfile: 
$!);
  13
  14 #split by line
  15  while( my $line =<$in>  ) {
  16      chomp($line);
  17      my @fields = split(/;/,$line);
  18
  19
  20 #Extrac the data you want using array slices:
  21
  22    my @data = @fields[0,5,44,31,32];
  23
  24 #or into named variables:
  25
  26   #my( $version, $mtype, $rlptxat, $cell, $sector ) = 
@fields[0,5,44,31,32];@val = split (/;/, $line);
  27
  28 #Print the headers (one time):
  29
  30    print $out "Version;MType;RLPtxAT;Cell;Sector\n";
  31
  32 #For each record, print the data to the output file:
  33
  34    print $out join(';',@data), "\n";
  35  }
  36
  37 close $out;
~
The errors I am getting are:
bash-3.2$ ./smart_phone.pl
Possible unintended interpolation of @fields in string at ./smart_phone.pl line 
12.
Possible unintended interpolation of @data in string at ./smart_phone.pl line 
12.
Possible unintended interpolation of @fields in string at ./smart_phone.pl line 
12.
Possible unintended interpolation of @fields in string at ./smart_phone.pl line 
12.
Possible unintended interpolation of @val in string at ./smart_phone.pl line 12.
Bareword found where operator expected at ./smart_phone.pl line 30, near "print $out 
"Version"
   (Might be a runaway multi-line "" string starting on line 12)
Global symbol "$filename" requires explicit package name at ./smart_phone.pl 
line 9.
Global symbol "$filename" requires explicit package name at ./smart_phone.pl 
line 11.
Global symbol "$filename" requires explicit package name at ./smart_phone.pl 
line 11.
Global symbol "$outputfile" requires explicit package name at ./smart_phone.pl 
line 12.
Global symbol "$outputfile" requires explicit package name at ./smart_phone.pl 
line 12.
Global symbol "$line" requires explicit package name at ./smart_phone.pl line 
12.
Global symbol "$line" requires explicit package name at ./smart_phone.pl line 
12.
Global symbol "@fields" requires explicit package name at ./smart_phone.pl line 
12.
Global symbol "$line" requires explicit package name at ./smart_phone.pl line 
12.
Global symbol "@data" requires explicit package name at ./smart_phone.pl line 
12.
Global symbol "@fields" requires explicit package name at ./smart_phone.pl line 
12.
Global symbol "$version" requires explicit package name at ./smart_phone.pl 
line 12.
Global symbol "$mtype" requires explicit package name at ./smart_phone.pl line 
12.
Global symbol "$rlptxat" requires explicit package name at ./smart_phone.pl 
line 12.
Global symbol "$cell" requires explicit package name at ./smart_phone.pl line 
12.
Global symbol "$sector" requires explicit package name at ./smart_phone.pl line 
12.
Global symbol "@fields" requires explicit package name at ./smart_phone.pl line 
12.
Global symbol "@val" requires explicit package name at ./smart_phone.pl line 12.
Global symbol "$line" requires explicit package name at ./smart_phone.pl line 
12.
Global symbol "$out" requires explicit package name at ./smart_phone.pl line 12.
./smart_phone.pl has too many errors.

Reply via email to