At 8:55 PM -0700 12/23/10, Chris Stinemetz wrote:
Jim,
Thank you for your help!
My perl program contains the following code. I am getting errors
when I run the program. Any insight is greatly appreciated.
I gave you some program fragments to help you get started. You are
going to have to use those fragments in the context of a working
program. You need to understand what each of those program fragments
does and how they should relate to your whole program.
Thank you,
Chris
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: $!);
I forgot the closing double quote on the above line. Sorry. If you
fix that line, the program should compile OK.'
The $outputfile variable is not defined here, and does not have a
value. You said you wanted a file name with a time tag, so it is up
to you to add the statements to define $outputfile the way you want
it.
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";
The above line should probably not be inside the loop, as it
represents a header line at the beginning of the output file.
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:
Most of the errors are probably a result of not closing the quote.
--
Jim Gibson
j...@gibson.org
--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/