Hello dear PERL MONKS!

I am new to PERL, and i tryed to create a programm, which searches all FILES in the same directory as the programm is placed FOR a word that i type in and REPLACES it for NEXT WORD that i also type in ...

EXAMPLE: I hit start, it asks what word shall be replaced? I type in GIF. Which word shall be there in stead o GIF? I type in IMG. I hit ENTER and it shall search the whole directory for the word GIF and replace it with IMG.

My programm, which i made works on the same way, but it has some disadvantages. It does not SEARCH - i have no idea how to make it, i have to write always the name of the file which i want to be edited ... I tryed Tutorials but they did not help ... And the second disadvantage is, that it waork only with the first line of my TEXT FILE .. I also have no idea why ...

Could you please help me solve this two problems? Here is my source:

use warnings; system"cls"; print "Which TEXT File shall be changhed?\n"; my $datname = <STDIN>; chomp($datname); open(READFILE,"<$datname"); my $erssetz = <READFILE>; close(READFILE); print "\n"; my $vor = $erssetz; print "Which word you want to be REPLACED? \n"; my $wort = <STDIN>; chomp($wort); print "\n"; print "What word shall be there the REPLACER? \n"; my $ersetz = <STDIN>; chomp($ersetz); print "\n"; $erssetz =~ s/$wort/$ersetz/g; open(WRITEFILE,">Ersetzt_$datname"); print WRITEFILE $erssetz; close(WRITEFILE); print "Finished -> saved AS : REPLACED_$datname \n";

In reply to Word Replacing by xoddam

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.