perl - How to fix error to add prefix and suffix to certain set of numbers from a text file -


how add prefix , suffix set of numbers obtained text file. have written coding it's showing bugs.

my text file contain numbers like

1 2 3 4 5 6 

and output should come

                                3r_1.pdb                                 3r_2.pdb                                 .                                 .                                 3r_6.pdb 

the program:-

open(file,"text.txt"); open(out,">output.txt"); while($file=<file>) { $f= "3r_"; $e= ".pdb"; chomp($file); print out "$f$file$e\n";  } 

i unable understand bug actually.

since pattern same here how it:

use strict; use warnings;  open(my $in, "<", "text.txt") or die $!; open(my $out, ">", "output.txt") or die $!;  while (my $line = <$in>) {   chomp ($line);   print $out "3r_" . $line . ".pdb\n"; }  close ($in); close ($out); 

you should use strict; use warnings;. modern perl, best practice use three-argument open files well. more clear , lets program more efficient.


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -