Re: Reading a line as an array

Justin Allegakoen <[email protected]>
Newsgroups gmane.comp.lang.perl.active-perl
Message-ID <[email protected]>
On 22 September 2010 13:11, zilore mumba <[email protected]> wrote:

> Excuse me for the missing attachments. As I composed the mail in gmail
> which is
> not recognised on the mailing list. The attachments are now included.
>
>
>
> ----- Original Message ----
> From: "Roode, Eric" <[email protected]>
> To: [email protected]
> Cc: zilore mumba <[email protected]>
> Sent: Tue, September 21, 2010 4:36:19 PM
> Subject: RE: Reading a line as an array
>
> On Tuesday, September 21, 2010 11:27 AM, zilore mumba wrote:
>
> > Hello Perl Community,
> > This mail was posted on gmail but may have been vetted by the
> moderator.
> > firstly my apologies for 1) a very basic question, 2) something I
> > should do in C.
> > 1. I have rainfal data (attached as sample.txt) month by month in
> > mixed float and integer which I cannot handle in fortran. I need to
> > first rewrite the data all in real (float) before I can use fortran.
> > 2. The perl script I have written read line by line, but then how do I
> > split the line into 31 values?
> > 3. as it is, the script rewrites each line and does not change any int
> > into float, I tried printf (with format) it doesn't work.
> > Is it possible?
> > Assistance will be appreciated.
> > Zilore
>


I think you should name your filehandles the other way around - it would be
less confusing.

Anyway something like the below should work, but others may have more
elegant solutions.


while (<OUT>)
{
    my @rain = split;    # default is to split on white space and $_

    print IN "\t$rain[0]\t$rain[1]\t";
    printf IN "%02.1f\t", $_ for @rain[ 2 .. $#rain ];
    print IN qq{\n};
}

Just in

_______________________________________________
ActivePerl mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.