Hello
try this:
#!/usr/bin/perl -w
use strict; #always!
my $FILE1 = <@ARGV>;
print "$FILE1\n";
open INFILE, $FILE1 or die "Damn $!";
open OUTFILE, '> xyz.dat' or die "Cant open xyz.dat $!";
while(my $line = <INFILE>){
my @out = split ' ', $line;
my $count = @out;
print "$count\n";
print OUTFILE "@out\n";
}
/Stefan
Gufranul Haque wrote:
>
> Perl Gurus,
>
> need some help with File Processing. I am trying to process a file where each line
> is treated as a record. The fileds in the record are separated by whitespaces. The
> number of white spaces between two fields can be >=1.
>
> The idea is to read the input file, and copy it to an output file keeping the format
> of the records same (i.e same number of whitespaces betwwen two fileds).
>
> Here is the program that I have written,
> _____________________________________________
> $FILE1 = <@ARGV>;
> print($FILE1);
>
> open(INFILE, $FILE1);
> @array = <INFILE>;
> close(INFILE);
> open(OUTFILE,">>xyz.dat");
>
> foreach $line (@array) {
> @out = split(/ +/, $line);
> $count = @out;
> print($count);
> print("\n");
> for ($i=0;$i<$count;$i++)
> {print OUTFILE (@out[$i]);}
> }
> ______________________________________________
>
> Input File
> _________________________________________
> 101 2.00 2.00 2.00 2.00
> 101 2.00 2.00 2.00 2.00
> _________________________________________
>
> However the output file generated is:
>
> _____________________________________________
>
> 1012.002.002.002.00
> 1012.002.002.002.00
> _____________________________________________
>
> The spaces between the fields are missing. Please let me know how to get it working.
>
> Thanks,
>
> Gufran
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]