parsing data from txt file

parsing data from txt file

am 23.12.2010 20:18:01 von Chris Stinemetz

--_000_D225040F2D0F75448937B83D9527991A0122FDAF20denex1crick et_
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: quoted-printable

Hello,

I hope someone can help me. I am trying to parse data from a txt file and o=
utput the results to a new file with timestamp in the name of the file.

The format of the txt file is ";" delimited and is several thousand records=
in length. Below is an example of the .txt format.

PACE | EVDOPCMD | 33.0 | 101218 | 07 |
8;1023240136;1218;0;1;00a000001a2bcdc7;0310003147702376;ac01 6d4a;;;5.6.128.=
8;0;;;;;43234169;43234349;;;10000;1;1;;0;;19;5.6.128.22;172. 30.151.5;304;3;=
304;3;;;;;15;175;15;175;15;175;1;1798;1251;0;0;2;19;20;;;;;1 ;1;1;0;128;5.6.=
128.8;;;;;;;301;5.6.128.8;;;8;304;3;;;;1;43244037;;;1;18;432 34169;0;;;;;;;;=
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;1;;;;;;43234416; 0;0;304;3;21;19=
;175;15;405;1;1;1;1;0;125;1;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;=
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;|;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;=
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;|
8;1023240137;1218;0;1;00a000001db74ace;;ac0174ca;43243423;16 78442111;5.6.12=
8.8;1;0;;43242544;43244207;43243423;43243647;;;1000;1;1;;0;; 19;5.6.128.26;;=
372;2;372;2;;43243012;0;43243562;15;175;15;175;15;175;1;;;;; 5;48;19;20;49;5=
0;;0;1;2;0;68;5.6.128.8;;;;;;;301;5.6.128.8;;;8;372;2;;;;1;4 3244207;;;1;18;=
43243423;0;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;1;;;;;;432425=
44;0;0;372;2;21;19;175;15;177;3;1;0;0;0;68;1;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;=
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;|43 243753;0;0;372;=
2;21;19;175;15;177;3;1;1;1;0;71;1;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;=
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;|
8;1023240138;1218;0;1;00a000002017ccdb;0310003147833882;aca3 44d7;;;5.6.128.=
13;0;;;;;43234160;43234358;;;10000;1;1;;0;;19;5.6.128.31;172 .30.151.5;320;2=
;320;2;;;;;15;75;15;75;15;75;1;2162;1317;0;0;2;19;20;;;;;1;1 ;1;0;104;5.6.12=
8.13;;;;;;;306;5.6.128.13;;;8;320;2;;;;1;43244164;;;1;18;432 34160;0;;;;;;;;=
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;1;;;;;;43234404; 0;0;320;2;21;19=
;75;15;279;6;1;1;1;0;64;1;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;=
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;|;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;=
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;|
8;1023240139;1218;0;1;00a1000009237b21;0310003147774000;aca3 141e;;;5.6.128.=
13;0;;;;;43235644;43235820;;;9000;1;1;;0;;19;5.6.128.19;172. 30.151.5;502;1;=
502;1;;;;;15;175;15;175;15;175;1;48;79;0;0;2;19;20;;;;;1;1;1 ;0;124;5.6.128.=
13;;;;;;;306;5.6.128.13;;;8;502;1;;;;1;43244194;;;1;18;43235 644;0;;;;;;;;;;=
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;1;;;;;;43235887;0; 0;502;1;21;19;1=
75;15;27;1;1;1;1;0;127;1;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;=
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;|;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;=
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;|

I am very new to perl so any help is appreciated.

Ideally I would like to extract the following columns 0, 5, 44, 31, 32, and=
give them the following headers indicated below.


%fieldmap =3D (
"Version" =3D> 0,
"MType" =3D> 5,
"RLPtxAT" =3D> 44,
"Cell" =3D> 31,
"Sector" =3D> 32,
);


Thank you,

Chris




--_000_D225040F2D0F75448937B83D9527991A0122FDAF20denex1crick et_--

Re: parsing data from txt file

am 23.12.2010 20:54:00 von Shawn Wilson

--000e0ce0424a1faf620498193b65
Content-Type: text/plain; charset=ISO-8859-1

On Dec 23, 2010 2:19 PM, "Chris Stinemetz" <
cstinemetz@cricketcommunications.com> wrote:
>
> Hello,
>
> I hope someone can help me. I am trying to parse data from a txt file and
output the results to a new file with timestamp in the name of the file.
>
> The format of the txt file is ";" delimited and is several thousand
records in length. Below is an example of the .txt format.
>

look at Text::CSV(_XS) to parse it. You should even be able to store each in
a hash with keys as the column names so that your code looks more readable.

>
> Ideally I would like to extract the following columns 0, 5, 44, 31, 32,
and give them the following headers indicated below.
>
>
> %fieldmap = (
> "Version" => 0,
> "MType" => 5,
> "RLPtxAT" => 44,
> "Cell" => 31,
> "Sector" => 32,
> );
>

Depending on what you're doing, you'll probably be better off using the
variable that you assign Text::CSV when you new that up.

>
> Thank you,
>
> Chris
>
>
>

--000e0ce0424a1faf620498193b65--

Re: parsing data from txt file

am 23.12.2010 22:50:57 von Jim Gibson

At 12:18 PM -0700 12/23/10, Chris Stinemetz wrote:
>Hello,
>
>I hope someone can help me. I am trying to parse data from a txt
>file and output the results to a new file with timestamp in the
>name of the file.


Look at the open function for reading existing files and creating new
ones: perldoc -f open

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

(where $outputfile can contain some sort of timestamp).

>
>The format of the txt file is ";" delimited and is several thousand
>records in length. Below is an example of the .txt format.


If all fields are delimited with ';' characters, and no field
contains a ';' character, you can use a simple split to extract the
fields into an array (perldoc -f split):

while( my $line = <$in> ) {
chomp($line);
my @fields = split(/;/,$line);

>
>PACE | EVDOPCMD | 33.0 | 101218 | 07 |
>8;1023240136;1218;0;1;00a000001a2bcdc7;0310003147702376;ac0 16d4a;;;5.6.128.8;0;;;;;43234169;43234349;;;10000;1;1;;0;;19 ;5.6.128.22;172.30.151.5;304;3;304;3;;;;;15;175;15;175;15;17 5;1;1798;1251;0;0;2;19;20;;;;;1;1;1;0;128;5.6.128.8;;;;;;;30 1;5.6.128.8;;;8;304;3;;;;1;43244037;;;1;18;43234169;0;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;1;;;;;;43234416 ;0;0;304;3;21;19;175;15;405;1;1;1;1;0;125;1;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;|;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;|
>8;1023240137;1218;0;1;00a000001db74ace;;ac0174ca;43243423;1 678442111;5.6.128.8;1;0;;43242544;43244207;43243423;43243647 ;;;1000;1;1;;0;;19;5.6.128.26;;372;2;372;2;;43243012;0;43243 562;15;175;15;175;15;175;1;;;;;5;48;19;20;49;50;;0;1;2;0;68; 5.6.128.8;;;;;;;301;5.6.128.8;;;8;372;2;;;;1;43244207;;;1;18 ;43243423;0;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;1;;;;;;43242544;0;0;372;2;21;19;175;15;177;3;1;0;0;0;68;1 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;|43243753;0;0;372;2;21;19;175;15 ;177;3;1;1;1;0;71;1;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;|
>8;1023240138;1218;0;1;00a000002017ccdb;0310003147833882;aca 344d7;;;5.6.128.13;0;;;;;43234160;43234358;;;10000;1;1;;0;;1 9;5.6.128.31;172.30.151.5;320;2;320;2;;;;;15;75;15;75;15;75; 1;2162;1317;0;0;2;19;20;;;;;1;1;1;0;104;5.6.128.13;;;;;;;306 ;5.6.128.13;;;8;320;2;;;;1;43244164;;;1;18;43234160;0;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;1;;;;;;43234404 ;0;0;320;2;21;19;75;15;279;6;1;1;1;0;64;1;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;|;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;|
>8;1023240139;1218;0;1;00a1000009237b21;0310003147774000;aca 3141e;;;5.6.128.13;0;;;;;43235644;43235820;;;9000;1;1;;0;;19 ;5.6.128.19;172.30.151.5;502;1;502;1;;;;;15;175;15;175;15;17 5;1;48;79;0;0;2;19;20;;;;;1;1;1;0;124;5.6.128.13;;;;;;;306;5 .6.128.13;;;8;502;1;;;;1;43244194;;;1;18;43235644;0;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;1;;;;;;43235887;0 ;0;502;1;21;19;175;15;27;1;1;1;1;0;127;1;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;|;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;|
>
>I am very new to perl so any help is appreciated.
>
>Ideally I would like to extract the following columns 0, 5, 44, 31,
>32, and give them the following headers indicated below.


Extract the data you want using array slices:

my @data = @fields[0,5,44,31,32];

or into named variables:

my( $version, $mtype, $rlptxat, $cell, $sector ) = @fields[0,5,44,31,32];

>
>
>%fieldmap = (
> "Version" => 0,
> "MType" => 5,
> "RLPtxAT" => 44,
> "Cell" => 31,
> "Sector" => 32,
>);

Print the headers (one time):

print $out "Version;MType;RLPtxAT;Cell;Sector\n";

For each record, print the data to the output file:

print $out join(';',@data), "\n";

You have not explained where the headers should go, or why there are
pipe characters in your input or what they mean, so I have ignored
them.

--
Jim Gibson
Jim@Gibson.org

--
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
http://learn.perl.org/

RE: parsing data from txt file

am 24.12.2010 04:55:48 von Chris Stinemetz

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.

Thank you,

Chris

1 #!/usr/bin/perl
2=20
3 use warnings;
4 use strict;
5=20
6 #Get data from EVDOPCMD.txt file and output to processed.txt file.
7=20
8 print "What file do you want to parse?";
9 $filename =3D ;
10=20
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=20
14 #split by line
15 while( my $line =3D <$in> ) {
16 chomp($line);
17 my @fields =3D split(/;/,$line);
18=20
19=20
20 #Extrac the data you want using array slices:
21=20
22 my @data =3D @fields[0,5,44,31,32];
23=20
24 #or into named variables:
25=20
26 #my( $version, $mtype, $rlptxat, $cell, $sector ) =3D @fields[0,5,44,=
31,32];@val =3D split (/;/, $line);
27=20
28 #Print the headers (one time):
29=20
30 print $out "Version;MType;RLPtxAT;Cell;Sector\n";
31=20
32 #For each record, print the data to the output file:
33=20
34 print $out join(';',@data), "\n";
35 }
36=20
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 li=
ne 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 lin=
e 12.
Bareword found where operator expected at ./smart_phone.pl line 30, near "p=
rint $out "Version"
(Might be a runaway multi-line "" string starting on line 12)
Global symbol "$filename" requires explicit package name at ./smart_phone.p=
l line 9.
Global symbol "$filename" requires explicit package name at ./smart_phone.p=
l line 11.
Global symbol "$filename" requires explicit package name at ./smart_phone.p=
l 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 li=
ne 12.
Global symbol "$line" requires explicit package name at ./smart_phone.pl li=
ne 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 li=
ne 12.
Global symbol "@data" requires explicit package name at ./smart_phone.pl li=
ne 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 l=
ine 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 li=
ne 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 lin=
e 12.
Global symbol "$line" requires explicit package name at ./smart_phone.pl li=
ne 12.
Global symbol "$out" requires explicit package name at ./smart_phone.pl lin=
e 12.
../smart_phone.pl has too many errors.

________________________________________
From: Jim Gibson [jimsgibson@gmail.com]
Sent: Thursday, December 23, 2010 3:50 PM
To: Chris Stinemetz; beginners@perl.org
Subject: Re: parsing data from txt file

At 12:18 PM -0700 12/23/10, Chris Stinemetz wrote:
>Hello,
>
>I hope someone can help me. I am trying to parse data from a txt
>file and output the results to a new file with timestamp in the
>name of the file.


Look at the open function for reading existing files and creating new
ones: perldoc -f open

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

(where $outputfile can contain some sort of timestamp).

>
>The format of the txt file is ";" delimited and is several thousand
>records in length. Below is an example of the .txt format.


If all fields are delimited with ';' characters, and no field
contains a ';' character, you can use a simple split to extract the
fields into an array (perldoc -f split):

while( my $line =3D <$in> ) {
chomp($line);
my @fields =3D split(/;/,$line);

>
>PACE | EVDOPCMD | 33.0 | 101218 | 07 |
>8;1023240136;1218;0;1;00a000001a2bcdc7;0310003147702376;ac0 16d4a;;;5.6.128=
..8;0;;;;;43234169;43234349;;;10000;1;1;;0;;19;5.6.128.22;17 2.30.151.5;304;3=
;304;3;;;;;15;175;15;175;15;175;1;1798;1251;0;0;2;19;20;;;;; 1;1;1;0;128;5.6=
..128.8;;;;;;;301;5.6.128.8;;;8;304;3;;;;1;43244037;;;1;18;4 3234169;0;;;;;;;=
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;1;;;;;;43234416 ;0;0;304;3;21;1=
9;175;15;405;1;1;1;1;0;125;1;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;=
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;|;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;=
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;|
>8;1023240137;1218;0;1;00a000001db74ace;;ac0174ca;43243423;1 678442111;5.6.1=
28.8;1;0;;43242544;43244207;43243423;43243647;;;1000;1;1;;0; ;19;5.6.128.26;=
;372;2;372;2;;43243012;0;43243562;15;175;15;175;15;175;1;;;; ;5;48;19;20;49;=
50;;0;1;2;0;68;5.6.128.8;;;;;;;301;5.6.128.8;;;8;372;2;;;;1; 43244207;;;1;18=
;43243423;0;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;1;;;;;;43242=
544;0;0;372;2;21;19;175;15;177;3;1;0;0;0;68;1;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;=
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;|4 3243753;0;0;372=
;2;21;19;175;15;177;3;1;1;1;0;71;1;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;=
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;|
>8;1023240138;1218;0;1;00a000002017ccdb;0310003147833882;aca 344d7;;;5.6.128=
..13;0;;;;;43234160;43234358;;;10000;1;1;;0;;19;5.6.128.31;1 72.30.151.5;320;=
2;320;2;;;;;15;75;15;75;15;75;1;2162;1317;0;0;2;19;20;;;;;1; 1;1;0;104;5.6.1=
28.13;;;;;;;306;5.6.128.13;;;8;320;2;;;;1;43244164;;;1;18;43 234160;0;;;;;;;=
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;1;;;;;;43234404 ;0;0;320;2;21;1=
9;75;15;279;6;1;1;1;0;64;1;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;=
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;|;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;=
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;|
>8;1023240139;1218;0;1;00a1000009237b21;0310003147774000;aca 3141e;;;5.6.128=
..13;0;;;;;43235644;43235820;;;9000;1;1;;0;;19;5.6.128.19;17 2.30.151.5;502;1=
;502;1;;;;;15;175;15;175;15;175;1;48;79;0;0;2;19;20;;;;;1;1; 1;0;124;5.6.128=
..13;;;;;;;306;5.6.128.13;;;8;502;1;;;;1;43244194;;;1;18;432 35644;0;;;;;;;;;=
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;1;;;;;;43235887;0 ;0;502;1;21;19;=
175;15;27;1;1;1;1;0;127;1;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;=
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;|;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;=
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;|
>
>I am very new to perl so any help is appreciated.
>
>Ideally I would like to extract the following columns 0, 5, 44, 31,
>32, and give them the following headers indicated below.


Extract the data you want using array slices:

my @data =3D @fields[0,5,44,31,32];

or into named variables:

my( $version, $mtype, $rlptxat, $cell, $sector ) =3D @fields[0,5,44,31,3=
2];

>
>
>%fieldmap =3D (
> "Version" =3D> 0,
> "MType" =3D> 5,
> "RLPtxAT" =3D> 44,
> "Cell" =3D> 31,
> "Sector" =3D> 32,
>);

Print the headers (one time):

print $out "Version;MType;RLPtxAT;Cell;Sector\n";

For each record, print the data to the output file:

print $out join(';',@data), "\n";

You have not explained where the headers should go, or why there are
pipe characters in your input or what they mean, so I have ignored
them.

--
Jim Gibson
Jim@Gibson.org

--
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
http://learn.perl.org/

Re: parsing data from txt file

am 24.12.2010 05:25:45 von Brandon McCaig

On Thu, Dec 23, 2010 at 10:55 PM, 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 =3D ;
>  10
>  11 open( my $in, '<', $filename) or die("Can't open $filename for r=
eading: $!");
>  12 open( my $out, '>', $outputfile) or die("Can't create file $outp=
utfile: $!);

$outputfile isn't declared/defined yet. Also, the string passed to die
isn't terminated by a double-quote, which is the ultimate cause of the
obscure errors that you're getting.


--=20
Brandon McCaig
V zrna gur orfg jvgu jung V fnl. Vg qbrfa'g nyjnlf fbhaq gung jnl.
Castopulence Software ..org>

--
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
http://learn.perl.org/

Re: parsing data from txt file

am 24.12.2010 15:49:36 von Jugurtha Hadjar

--------------050004020603050901000609
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

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 =;
> 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.


--------------050004020603050901000609--

Re: parsing data from txt file

am 24.12.2010 16:10:51 von Shawn H Corey

On 10-12-24 09:49 AM, Jugurtha Hadjar wrote:
> my @data =0;
> my @fields =0;
> my @val =0;

my @data = ();
my @fields = ();
my @val = ();


--
Just my 0.00000002 million dollars worth,
Shawn

Confusion is the first step of understanding.

Programming is as much about organization and communication
as it is about coding.

The secret to great software: Fail early & often.

Eliminate software piracy: use only FLOSS.

--
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
http://learn.perl.org/

RE: parsing data from txt file

am 24.12.2010 17:20:56 von Jim Gibson

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 = ;
> 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
Jim@Gibson.org

--
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
http://learn.perl.org/

RE: parsing data from txt file

am 24.12.2010 18:44:52 von Chris Stinemetz

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=20
5 # Intialization begins
6=20
7 my $cell =3D'';
8 my $filename =3D'';
9 my $in =3D'';
10 my $line =3D'';
11 my $mtype =3D'';
12 my $out =3D'';
13 my $outputfile =3D"processed.txt";
14 my $rlptxat =3D'';
15 my $sector =3D'';
16 my $version =3D'';
17=20
18=20
19 my @data =3D ();
20 my @fields =3D (0, 5, 44, 31, 32);
21 my @val =3D (split /:/, $line);
22=20
23 # Initialization ends
24=20
25 #Get data from EVDOPCMD.txt file and output to processed.txt file.
26=20
27 print "What file do you want to parse?";
28 $filename =3D ;
29=20
30 open($in, '<', $filename) or die("Can't open $filename for reading: $!"=
);
31 open($out, '>', $outputfile) or die("Can't create file $outputfile: $!"=
);
32=20
33 #split by line
34 while( my $line =3D <$in> ) {
35 chomp($line);
36 my @fields =3D ();
37 my @val =3D ();
38 }
39=20
40 #Extract the data you want into named variables:
41=20
42 # my( $version, $mtype, $rlptxat, $cell, $sector ) =3D @fields[0,5,44,=
31,32];@val =3D split (/;/, $line);
43=20
44 #Print the headers (one time):
45=20
46 print $out "Version;MType;RLPtxAT;Cell;Sector\n";
47=20
48 #For each record, print the data to the output file:
49=20
50 print $out join(';',@data), "\n";
51=20
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, line 1.

________________________________________
From: Jim Gibson [jimsgibson@gmail.com]
Sent: Friday, December 24, 2010 10:20 AM
To: beginners@perl.org
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 =3D ;
> 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 =3D <$in> ) {
> 16 chomp($line);
> 17 my @fields =3D split(/;/,$line);
> 18
> 19
> 20 #Extrac the data you want using array slices:
> 21
> 22 my @data =3D @fields[0,5,44,31,32];
> 23
> 24 #or into named variables:
> 25
> 26 #my( $version, $mtype, $rlptxat, $cell, $sector ) =3D
>@fields[0,5,44,31,32];@val =3D 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
Jim@Gibson.org

--
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
http://learn.perl.org/



--
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
http://learn.perl.org/

Re: parsing data from txt file

am 24.12.2010 18:45:01 von Uri Guttman

>>>>> "JH" == Jugurtha Hadjar writes:

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

this is very overkill and in some cases wrong. in general declare
variable just when they are needed. when i see a long list of
declarations at the beginning of a file, i know it can be improved.

JH> # Intialization begins

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

why always ''? some may be better with 0. i haven't looked at the data
needs yet.

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

that has to be wrong. that is setting the arrays to a list with the
element 0, not an empty list.

JH> # Initialization ends

useless comment.

JH> I also changed

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

JH> Into :

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

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

again, why? if you don't predeclare it, then a my handle works fine. and
the variable is declare where it is first used which is better. why
waste lines of code for no reason. also the second open there is missing
a close ".

uri

--
Uri Guttman ------ uri@stemsystems.com -------- http://www.sysarch.com --
----- Perl Code Review , Architecture, Development, Training, Support ------
--------- Gourmet Hot Cocoa Mix ---- http://bestfriendscocoa.com ---------

--
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
http://learn.perl.org/

Re: parsing data from txt file

am 24.12.2010 19:29:30 von Uri Guttman

>>>>> "CS" == Chris Stinemetz writes:

CS> 5 # Intialization begins

as i said elsewhere, don't declare vars before you need them. it is
noisy and in many cases redundant.
CS> 6
CS> 10 my $line ='';

CS> 21 my @val = (split /:/, $line);

what do you think that line does? $line is empty. why split it now? that
expression will only happen ONE time. my ESP says you are thinking it
will happen whenever @val is used later on.

CS> 22
CS> 23 # Initialization ends
CS> 24
CS> 25 #Get data from EVDOPCMD.txt file and output to processed.txt file.
CS> 26
CS> 27 print "What file do you want to parse?";
CS> 28 $filename = ;
CS> 29
CS> 30 open($in, '<', $filename) or die("Can't open $filename for reading: $!");

filename will have a newline on it. chomp it first or your dir listing
will be wacky and hard to deal with.


p CS> 31 open($out, '>', $outputfile) or die("Can't create file $outputfile: $!");
CS> 32
CS> 33 #split by line
CS> 34 while( my $line = <$in> ) {

you declared line earlier. why? as i said drop the early declarations as
they are mostly not needed.

CS> 35 chomp($line);
CS> 36 my @fields = ();
CS> 37 my @val = ();

same for those vars. don't declare them earlier as they aren't used
there and that confuses the reader.

CS> 38 }

on top of that you declare those inside a block and NEVER use them in
this block. you need to learn about scoping and declarations. you are
just guessing with this now.


CS> 40 #Extract the data you want into named variables:
CS> 41
CS> 42 # my( $version, $mtype, $rlptxat, $cell, $sector ) = @fields[0,5,44,31,32];@val = split (/;/, $line);

where did @fields get set? don't put two lines of code on one line.
it was set INSIDE the block and declared there. so its data is lost when
you exited the block.

uri

--
Uri Guttman ------ uri@stemsystems.com -------- http://www.sysarch.com --
----- Perl Code Review , Architecture, Development, Training, Support ------
--------- Gourmet Hot Cocoa Mix ---- http://bestfriendscocoa.com ---------

--
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
http://learn.perl.org/

RE: parsing data from txt file

am 24.12.2010 19:54:56 von Jim Gibson

At 10:44 AM -0700 12/24/10, Chris Stinemetz wrote:
>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 ='';

Do not declare $in here and give it a value. Using lexical variables
as file handles only works if the are undefined. You are assigning a
value to $in.

> 10 my $line ='';
> 11 my $mtype ='';
> 12 my $out ='';

Same here for $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 = ;
> 29
> 30 open($in, '<', $filename) or die("Can't open $filename for reading: $!");
> 31 open($out, '>', $outputfile) or die("Can't create file $outputfile: $!");

Replace with

open( my $in,...;
open( my $out, ...;

and do not declare $in and $out above,

--
Jim Gibson
Jim@Gibson.org

--
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
http://learn.perl.org/

Re: parsing data from txt file

am 24.12.2010 23:10:24 von John Delacour

On 24 December 2010 14:49, Jugurtha Hadjar wrot=
e:

> I rewrote your code and at the very beginning, just before any variable w=
as
> /used/ [i.e, just after "use strict", I added
>
>
> # Intialization begins
>
> my $cell        =3D'';
> my $filename    =3D'';

If you're going to an empty value (which is not necessary) then at
least you must close the quotes!:

my $cell =3D"'';
my $filename =3D''";

Easier to to

my ($cell, $filename, $etc);


JD

--
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
http://learn.perl.org/

Re: parsing data from txt file

am 24.12.2010 23:38:44 von Uri Guttman

>>>>> "JD" == John Delacour writes:

JD> On 24 December 2010 14:49, Jugurtha Hadjar > wrote:
>> I rewrote your code and at the very beginning, just before any variabl=
e was
>> /used/ [i.e, just after "use strict", I added
>>=20
>>=20
>> # Intialization begins
>>=20
>> my $cell =A0 =A0 =A0  ='';
>> my $filename =A0  ='';

JD> If you're going to an empty value (which is not necessary) then at
JD> least you must close the quotes!:

huh? those were pairs of single quotes.

JD> my $cell =3D"'';
JD> my $filename =3D''";

and those won't compile.

JD> Easier to to

JD> my ($cell, $filename, $etc);

easier to declare them when first used.

uri

--=20
Uri Guttman ------ uri@stemsystems.com -------- http://www.sysarch.com =
--
----- Perl Code Review , Architecture, Development, Training, Support ----=
--
--------- Gourmet Hot Cocoa Mix ---- http://bestfriendscocoa.com -------=
--

--
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
http://learn.perl.org/

Re: parsing data from txt file

am 25.12.2010 03:20:25 von Shawn H Corey

On 10-12-24 05:10 PM, John Delacour wrote:
> If you're going to an empty value (which is not necessary)

Don't assume it's not necessary. At one time, mod_perl did not
re-initialize the data space; it just reused it so you would get the
previous values in your variables. Always initialize your variables.


--
Just my 0.00000002 million dollars worth,
Shawn

Confusion is the first step of understanding.

Programming is as much about organization and communication
as it is about coding.

The secret to great software: Fail early & often.

Eliminate software piracy: use only FLOSS.

--
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
http://learn.perl.org/

Re: parsing data from txt file

am 27.12.2010 21:35:30 von Jugurtha Hadjar

Hello,


On 12/24/2010 06:45 PM, Uri Guttman wrote:
>>>>>> "JH" == Jugurtha Hadjar writes:
>
> JH> my @data =0;
> JH> my @fields =0;
> JH> my @val =0;
>
> that has to be wrong. that is setting the arrays to a list with the
> element 0, not an empty list.

Exactly. I tried to do something like

my @data = (0, 0, 0, 0, 0);

It's not even fun to write, and it didn't make sens at all so it had to
be wrong .. What if it was a list of 100 ? I just killed it to my @data= 0;

But as you and Shawn H Corey pointed out, an empty list was the thing to do.

My best,


~Jugurtha,




--
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
http://learn.perl.org/

Re: parsing data from txt file

am 27.12.2010 21:52:26 von Uri Guttman

>>>>> "JH" == Jugurtha Hadjar writes:

JH> Hello,
JH> On 12/24/2010 06:45 PM, Uri Guttman wrote:
>>>>>>> "JH" == Jugurtha Hadjar writes:
>>
JH> my @data =0;
JH> my @fields =0;
JH> my @val =0;
>>
>> that has to be wrong. that is setting the arrays to a list with the
>> element 0, not an empty list.

JH> Exactly. I tried to do something like

JH> my @data = (0, 0, 0, 0, 0);

JH> It's not even fun to write, and it didn't make sens at all so it had
JH> to be wrong .. What if it was a list of 100 ? I just killed it to my
JH> @data= 0;

my @data = (0) x 100 ;

learn more about perl ops and you will find most of what you REALLY want
is in there.


JH> But as you and Shawn H Corey pointed out, an empty list was the
JH> thing to do.

that is correct in this case. initializing an array to actual elements
is not needed that often. but when it is, know how to do it properly.

uri

--
Uri Guttman ------ uri@stemsystems.com -------- http://www.sysarch.com --
----- Perl Code Review , Architecture, Development, Training, Support ------
--------- Gourmet Hot Cocoa Mix ---- http://bestfriendscocoa.com ---------

--
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
http://learn.perl.org/