OK, according to Randal, (Learning Perl 1st Edition), and brian d foy, (perlfaq5), this code I've got should work. It prompts an in file, an out file, a pattern and a replacement from the user, then executes the replacement based on STDIN between the two files.
#!usr/bin/perl use strict; my $in_file; my $out_file; my $answer; my $pattern; my $replacement; # This program prompts user for an input file, an output file, a searc +h pattern and a replacement string, then executes the search and repl +acement between the two files. print "Enter the in_put file"; chomp($in_file = <STDIN>); print "Enter the out_put file"; chomp($out_file = <STDIN>); print "Enter the pattern"; chomp($pattern = <STDIN>); print "Enter the replacement"; chomp($replacement = <STDIN>); open (IN, "$in_file") || die "not a rockstar today"; die "will not overwrite $out_file" if -e $out_file; open (OUT, ">$out_file") || die "not a rockstar today"; while (<IN>) { # S/$pattern/$replacement/g; print OUT $_; } # end while close (IN); close (OUT);
Please note, I understand how ridiculous it is for the user to have enter the entire path of the file, and everything else exactly, but that's just really not the point here, I'm trying to learn basic file manipulation. I had a separate program without the substitution going on, or the user prompts, but everything else the same, and it worked fine, however in this one, even if I adjust it just to copy lines from the in file to the out, it still won't...?
As I said, in all examples and documentations I can find, all the examples are the same as my code, aside from the user prompts and the substitutions of course, so I'm rather confused at this point, not too mention my currently glazed over eyes are slowly dying from staring at the screen for so long...help, anyone, buellar, buellar....?
update: sorry brian, fixed it, I think
In reply to Not A Rockstar File Manipulator Today by koolgirl
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |