0

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.

Daniella
  • 171
  • 2
  • 3
  • 14
  • I'd say start by adding `use strict` and `use warnings` at the top of your script, and then correct the errors it displays. Once you get there, edit your question with the updated code. To open a file in Perl: http://stackoverflow.com/questions/318789/whats-the-best-way-to-open-and-read-a-file-in-perl – hmatt1 Jul 07 '14 at 23:57
  • Thank you I really appreciate the help. @jm666 I have tried that method also. @Matt for some reason whenever I use `use script` and `use warnings` it doesn't even let me input the file name. – Daniella Jul 08 '14 at 01:01

0 Answers0