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