i have 10 data notepad files (with column x= 1 to 5 and column y = some random number)
x y
1 12
2 13
3 8
4 6
5 2
i want to multiply the 1st file's second column with 3, and save it as new data file
Increase the data file no. and muliply the data file no 2nd to 7th with 8 and keep 8th to 10th file same. I want to save these data files differently as new notepad files and i require a perl program for it. Can someone help?
mona_j05
0
Newbie Poster
Recommended Answers
Jump to PostWhat are the names of your input files? Before you run your program you have 10 files. After you run it you will have 20 (10 input plus the 10 new output files). If you run your program more than once, the program will need to specify the names of …
Jump to PostTry this:
use strict; use warnings; my $x=0; for ($x=1;$x<11;$x++){ my $pad="000"; $pad="00" if($x==10); open (INF,"<","./ls_$pad$x\_$x\.dat"); open (OUT, ">", "./New_ls_$pad$x\_$x\.dat"); my $y=0; while(<INF>){ chomp; $y++; if($y==1){ print OUT "X Y\n"; next; } my ($line,$value)=split(/ /); my $mult=1; if($x==1){ $mult=3; }elsif($x<8){ $mult=8; } my $newval=$value*$mult; print OUT "$line …
Jump to PostThe changes are marked below:
use strict; use warnings; my $x=0; for ($x=1;$x<11;$x++){ #my $pad="000"; #remove not necessary any more # $pad="00" if($x==10); #remove open (INF,"<","./ ls_00045_mythen_\$x.dat"); #change file spec open (OUT, ">", "./new__00045_mythen_\$x.dat"); #change file spec my $y=0; while(<INF>){ chomp; $y++; if($y==1){ print OUT "X Y\n"; …
All 9 Replies
d5e5
109
Master Poster
mona_j05
0
Newbie Poster
mitchems
12
Posting Whiz in Training
mona_j05
0
Newbie Poster
mitchems
12
Posting Whiz in Training
mona_j05
0
Newbie Poster
mitchems
12
Posting Whiz in Training
mitchems
12
Posting Whiz in Training
mona_j05
0
Newbie Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.