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
#! /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
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,
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
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
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,
>>
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;
> >>
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,
[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
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
>
10 matches
Mail list logo