[ Please do not top-post.
Please remove the quoted text that is not applicable.
Please use single-spaced formatting and indent your code properly.
]
Gufranul Haque wrote:
>
> From: "John W. Krahn" <[EMAIL PROTECTED]>
> >
> > If you do need to modify the fields:
> >
> > use warnings;
> > use strict;
> >
> > open OUTFILE, '>>xyz.dat' or die "Cannot open xyz.dat: $!";
> >
> > while ( <> ) { # reads the file(s) in @ARGV line by line
> > # preserve leading whitespace
> > my $lead = $1 if /^(\s+)/;
> > my @data = map [ /(\S+)(\s*)/ ], /\S+\s*/g;
> > # modify the non-whitespace fields
> > $_->[0] += 5 for @data;
> > print @data . "\n"; # count - @data in scalar context
> > print OUTFILE $lead;
> > print OUTFILE @$_ for @data;
> > }
> >
> > __END__
>
> Thanks for the mail. Yes you are right, I need to modify the contents of the
> file. But need some clarification with some of the statements you have used
>
> my @data = map [ /(\S+)(\s*)/ ], /\S+\s*/g; - what exactly is happening over
> here?
The current line from the file is divided into non-whitespace -
whitespace chunks which are then divided between non-whitespace and
whitespace and stored in an anonymous array and the reference to the
anon. array is stored in @data. So if $_ = "3.00 5.12 7.32\n" then
@data = ( [ '3.00', ' ' ], [ '5.12', ' ' ], [ '7.32', "\n" ] )
> $_->[0] += 5 for @data; ????? and
Adds 5 to each non-whitespace element of @data
> my $lead = $1 if /^(\s+)/; ?
Stores any leading whitespace in $lead
> Output xyz.dat after using your program. you will notice thatinstead of 7.00
> it is showing 7, how to preserve the decimal point and trailing zeros??
perldoc -f sprintf
> I will try to explain the problem I am facing in detail:
> File to be processed (Input File)
> ________________________________________________________
>
> 10111 2.00 2.00 2.00 2.00
> 10111 2.00 2.00 2.00 2.00
> _________________________________________________
>
> Restriction First field to remain same.
> Parameter File
> _______________________________________________
>
> 1,0.3,0.5,1
> _________________________________________
>
> Each filed in the parameter file corresponds to a field in the input file.
> Logic -
> From 2nd field to eof in input file
> If value in parameter file < 1
> split that filed into two fields
> i.e for the value in the 3rd field (2.00), corresponding parameter value is
> 0.3, so it should be splitted into two fields (0.60 and 1.40)
>
> I am using the following program
Please, please, please use warnings and strict while developing your
program. Please tell us which book/website you picked up this coding
style from so we can warn everyone to avoid it like the plague.
perldoc perlstyle
John
--
use Perl;
program
fulfillment
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]