Okay I appreciate everyones help. I feel like i am getting closer. Below is my
current code and error I get.
Thank you all!
1 #!/usr/bin/perl
2 use warnings;
3 use strict;
4
5 # Intialization begins
6
7 my $cell ='';
8 my $filename ='';
9 my $in ='';
10 my $line ='';
11 my $mtype ='';
12 my $out ='';
13 my $outputfile ="processed.txt";
14 my $rlptxat ='';
15 my $sector ='';
16 my $version ='';
17
18
19 my @data = ();
20 my @fields = (0, 5, 44, 31, 32);
21 my @val = (split /:/, $line);
22
23 # Initialization ends
24
25 #Get data from EVDOPCMD.txt file and output to processed.txt file.
26
27 print "What file do you want to parse?";
28 $filename = <STDIN>;
29
30 open($in, '<', $filename) or die("Can't open $filename for reading: $!");
31 open($out, '>', $outputfile) or die("Can't create file $outputfile: $!");
32
33 #split by line
34 while( my $line = <$in> ) {
35 chomp($line);
36 my @fields = ();
37 my @val = ();
38 }
39
40 #Extract the data you want into named variables:
41
42 # my( $version, $mtype, $rlptxat, $cell, $sector ) =
@fields[0,5,44,31,32];@val = split (/;/, $line);
43
44 #Print the headers (one time):
45
46 print $out "Version;MType;RLPtxAT;Cell;Sector\n";
47
48 #For each record, print the data to the output file:
49
50 print $out join(';',@data), "\n";
51
52 close $out;
What file do you want to parse?10121807.EVDOPCMD
Can't use string ("") as a symbol ref while "strict refs" in use at
./smart_phone.pl line 30, <STDIN> line 1.
________________________________________
From: Jim Gibson [[email protected]]
Sent: Friday, December 24, 2010 10:20 AM
To: [email protected]
Subject: RE: parsing data from txt file
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
[email protected]
--
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
http://learn.perl.org/
--
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
http://learn.perl.org/