fresher and inheriting perl code without perl knowledge

fresher and inheriting perl code without perl knowledge

am 27.06.2006 05:00:44 von junkone

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
@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

Re: fresher and inheriting perl code without perl knowledge

am 27.06.2006 18:12:51 von Dave Turner

junkone@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
> @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 @values;

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

while (){
push( @values, $_);
}
close FH;

That should do what you want.

Re: fresher and inheriting perl code without perl knowledge

am 27.06.2006 19:06:29 von Jim Gibson

In article <1151377244.088685.52870@p79g2000cwp.googlegroups.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
> @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 @orders = <$fh>;
close($fh);
chomp(@orders); # removes newline from end of each element

Re: fresher and inheriting perl code without perl knowledge

am 27.06.2006 20:58:50 von drt

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

Should be open FH, " your file.

>
> while (){
> push( @values, $_);
> }
> close FH;
>
> That should do what you want.