I'm working with Strawberry Perl on windows and am running into a problem substituting strings in a text file. This is an example of the data in the file:
>CR:8A 55
CT:98 2
*CT:87 1
CR:98 88
CT:99 0
CT:80 80
+CT:87 5
I'm trying to replace for example: CR with Testing_Sub and 80 with NormalTest. So far I can't understand why what I have does not work for me:
print "Enter filename (include .txt):";
chomp($fname = <STDIN>); # save file name in variable $fname
# Open a file. If unsuccessful, print an error message and quit.
open (FPTR,$fname) || die "Can't Open File: $fname.txt\n";
@filestuff = <FPTR>; #Read the file into an array
print "The number of lines in this file: ",$#filestuff + 1,"\n";
#print @filestuff;
open FILE, "+>>", $workfile or die $!;
@filestuf = $workfile; #Read the file into an array
print "The number of lines in this file: ",$#filestuf + 1,"\n";
$line =~ s/^A_B_([^C])/X_Y_$1/;
This immediately closes the Perl Terminal. I've tried something like this:
my $t =~ s/^\.\///;
to see if I could get ./test to be replaced with test in my file and that hasn't worked either.
Any suggestions? Am I not understanding something important about Perl?
Any helpful hints would be great.
DM
Edit
The reason use strict
and use warnings
weren't working is because I was trying to execute the perl program directly from a file instead of the command line. The errors I now receive are:
-"my" variable $workfile masks earlier declaration in same scope
-Global symbol "$fname" requires explicit package name.