O Wise ones,
I am a summer intern, and my first perl script is to write a script that will open a dat file and move through it string be string commenting it out and writing each seperate instance to another dat file. So edit1.dat would have "$Blue Car Green" and edit2.dat would have "Blue $Car Green", etc... :
Here is what I have:
#!usr/bin/perl use File::Copy; print "What file would you like to edit? \n"; chomp($editfile = <>); copy($editfile, "edit.dat") || die "Cannot copy file: $!"; open(INFO,"edit.dat") || die "Can't open edit.dat: $!"; $header = <INFO>; undef $/; $sequence = <INFO>; my @twodarray = split(' ',$sequence); $list[0] = \@twodarray; $x=1; for ($j=0; $j<=$#{$list[0]}; $j++) { for ($k=0; $k<=$#list; $k++) { copy("edit".$x.".dat", "edit.dat"); open(OTHER, ">edit$x.dat"); seek OTHER, 0 ,0; $position = $list[$k][$j]; $commentout = "\$"; $commentout = $commentout .= $position; s/$position/$commentout/; print OTHER; $x++; } print "\n"; } close INFO;
Well it creates the files, but they are all empty. But I checked the $position and $commentout variables, and they hold the right values. I'm a noob to the ways of perl, so any help would be greatly appreciated. Thanks.
"theintern"
20070621 Janitored by Corion: Added formatting, code tags, as per Writeup Formatting Tips
In reply to Opening a file, editing, copying to another by theintern
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |