theintern has asked for the wisdom of the Perl Monks concerning the following question:
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Opening a file, editing, copying to another
by Grundle (Scribe) on Jun 20, 2007 at 21:55 UTC | |
by GrandFather (Saint) on Jun 20, 2007 at 23:30 UTC | |
by toolic (Bishop) on Jun 20, 2007 at 23:37 UTC | |
by GrandFather (Saint) on Jun 20, 2007 at 23:44 UTC | |
by Grundle (Scribe) on Jun 21, 2007 at 13:57 UTC | |
by GrandFather (Saint) on Jun 21, 2007 at 14:25 UTC | |
|
Re: Opening a file, editing, copying to another
by GrandFather (Saint) on Jun 21, 2007 at 14:39 UTC |