Dear Monks,

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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.