fresher and inheriting perl code without perl knowledge

Hi
I just got into this job and inherited this piece of code. can someone
help.
I have a file with 1 column and 20000 rows.
i have a perl script that needs to be extended to pickup the data from
this file and execute the following.

file format is and is in c:\runscript\abc.csv

11111
22222
33333
44444
....
....
,,,

My perl script has to pick it up and store it all in an array as
[at] orders
How do i do this one. I have no clue on perl but have to do this work
but know programming and learn the bits and pieces.

Pl help
Seede
junkone [ Di, 27 Juni 2006 05:00 ] [ ID #1372670 ]

Re: fresher and inheriting perl code without perl knowledge

junkone [at] rogers.com wrote:
> Hi
> I just got into this job and inherited this piece of code. can someone
> help.
> I have a file with 1 column and 20000 rows.
> i have a perl script that needs to be extended to pickup the data from
> this file and execute the following.
>
> file format is and is in c:\runscript\abc.csv
>
> 11111
> 22222
> 33333
> 44444
> ...
> ...
> ,,,
>
> My perl script has to pick it up and store it all in an array as
> [at] orders
> How do i do this one. I have no clue on perl but have to do this work
> but know programming and learn the bits and pieces.
>
> Pl help
> Seede
>

Try this:

use strict;

my [at] values;

open FH, ">c:\runscript\abc.csv";

while (<FH>){
push( [at] values, $_);
}
close FH;

That should do what you want.
Dave Turner [ Di, 27 Juni 2006 18:12 ] [ ID #1372671 ]

Re: fresher and inheriting perl code without perl knowledge

In article <1151377244.088685.52870 [at] p79g2000cwp.googlegroups.com>,
<junkone [at] rogers.com> wrote:

> Hi
> I just got into this job and inherited this piece of code. can someone
> help.
> I have a file with 1 column and 20000 rows.
> i have a perl script that needs to be extended to pickup the data from
> this file and execute the following.
>
> file format is and is in c:\runscript\abc.csv
>
> 11111
> 22222
> 33333
> 44444
> ...
> ...
> ,,,
>
> My perl script has to pick it up and store it all in an array as
> [at] orders
> How do i do this one. I have no clue on perl but have to do this work
> but know programming and learn the bits and pieces.

You can read the file and store the lines in an array directly
(untested):

my $filename = 'c:/runscript/abc.csv'; # note forward slashes!
open( my $fh, '<', $filename) or die("Can't open $filename: $!");
my [at] orders = <$fh>;
close($fh);
chomp( [at] orders); # removes newline from end of each element
Jim Gibson [ Di, 27 Juni 2006 19:06 ] [ ID #1372672 ]

Re: fresher and inheriting perl code without perl knowledge

Dave Turner wrote:
> Try this:
>
> use strict;
>
> my [at] values;
>
> open FH, ">c:\runscript\abc.csv";

Should be open FH, "<c:\runscript\abc.csv"; otherwise you'll clobber
your file.

>
> while (<FH>){
> push( [at] values, $_);
> }
> close FH;
>
> That should do what you want.
drt [ Di, 27 Juni 2006 20:58 ] [ ID #1372673 ]
Perl » alt.perl » fresher and inheriting perl code without perl knowledge

Vorheriges Thema: Pls help me in finding solution of two problems
Nächstes Thema: Script Debugging