how to read the formatted data from the file?

2008-07-14 Thread vikingy
Hi all, There is a file created likes this: open File ">file.txt" or die $!; foreach .. <..> { printf File "%5d %11.2f\n", $data1,data2; } close File; and my question is, how to read these data follow the same format as "%5d %11.2f' from this file again? thanks in advance

Re: how to read the formatted data from the file?

2008-07-14 Thread Amit Saxena
#! /usr/bin/perl use warnings; use strict; open (PTR1, ")) { sscanf($str, "%5d %11.2f", $data1, $data2); # do whatever processing. } close (PTR1); Regards, Amit Saxena On Mon, Jul 14, 2008 at 8:23 PM, vikingy <[EMAIL PROTECTED]> wrote: > Hi all, > > There is a file created l

Re: how to read the formatted data from the file?

2008-07-14 Thread Rob Dixon
Amit Saxena wrote: > > On Mon, Jul 14, 2008 at 8:23 PM, vikingy <[EMAIL PROTECTED]> wrote: > >> There is a file created likes this: >> >> open File ">file.txt" or die $!; >> foreach .. <..> { >> printf File "%5d %11.2f\n", $data1,data2; >> } >> close File; >> >> and my question is,

Re: how to read the formatted data from the file?

2008-07-14 Thread Rob Dixon
Rob Dixon wrote: > > Amit Saxena wrote: >> >> while (chomp ($str = )) > > That will exit the loop if an empty line is encountered before the end of the > file, and will throw a warning at the end of the file because of chomp having > an > uninitialized value My apologies; chomp returns the numb

Re: how to read the formatted data from the file?

2008-07-14 Thread Brad Baxter
Amit Saxena wrote: #! /usr/bin/perl use warnings; use strict; open (PTR1, ")) { sscanf($str, "%5d %11.2f", $data1, $data2); # do whatever processing. } close (PTR1); Regards, Amit Saxena sscanf()? -- Brad -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional comma

Re: how to read the formatted data from the file?

2008-07-14 Thread Rob Dixon
Brad Baxter wrote: > Amit Saxena wrote: >> #! /usr/bin/perl >> >> use warnings; >> use strict; >> >> open (PTR1, "> $!\n\n"; >> >> while (chomp ($str = )) >> { >> sscanf($str, "%5d %11.2f", $data1, $data2); >> >> # do whatever processing. >> } >> >> close (PTR1); >> >> Regards, >>

Re: how to read the formatted data from the file?

2008-07-14 Thread Amit Saxena
oops I was thinking along "C" lines on that one ! Please remove sscanf part from the loop. Regards Amit Saxena On Tue, Jul 15, 2008 at 2:29 AM, Rob Dixon <[EMAIL PROTECTED]> wrote: > > Brad Baxter wrote: > > Amit Saxena wrote: > >> #! /usr/bin/perl > >> > >> use warnings; > >> use strict; > >>

Re: how to read the formatted data from the file?

2008-07-18 Thread MedranoEnrique
On Jul 14, 10:57 am, [EMAIL PROTECTED] (Amit Saxena) wrote: > #! /usr/bin/perl > > use warnings; > use strict; > > open (PTR1, " $!\n\n"; > > while (chomp ($str = )) > { >       sscanf($str, "%5d %11.2f", $data1, $data2); > >       # do whatever processing. > > } > > close (PTR1); > > Regards,

Re: how to read the formatted data from the file?

2008-07-18 Thread Gunnar Hjalmarsson
[EMAIL PROTECTED] wrote: On Jul 14, 10:57 am, [EMAIL PROTECTED] (Amit Saxena) wrote: open (PTR1, " what dose $! mean perldoc perlvar -- Gunnar Hjalmarsson Email: http://www.gunnar.cc/cgi-bin/contact.pl -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL

Re: Re: how to read the formatted data from the file?

2008-07-15 Thread bin . lv
utomation, >> Chinese Academy of Sciences. >> ---------- >> *发件人:* Amit Saxena >> *发送时间:* 2008-07-14 22:57:03 >> *收件人:* vikingy >> *抄送:* beginners >> *主题:* Re: how to read the formatted data from the file? >> #! /usr/bin/perl >