There are not really gaping errors, but there are a few things that could be cleaned up in various ways.

You use -w in the shebang line which enables warnings, but you should add a use strict; line too.

It is strongly recommended that you use a three parameter open, especially when you obtain the name of the file from the user (as in this case).

You have a redundant assignment to $temp. The declaration for temp can be moved into the conditional expression for the while loop or omited all together. However that impinges somewhat on another decision - should you output in the input loop, or should you slurp (at present you are slurping).

A better way to slurp is:

my $input = do {local $/; <AA>;};

That replaces your whole while loop by setting the input line seperator to null and reading everything into $input in one big slurp (you begin to see where the name comes from perhaps). That is ok for small files, but gets to be a problem if the file is large. For large files it is much better to process the file a line at a time like this:

#!/usr/bin/perl -w use strict; print "Please enter the file name\n"; my $in = <STDIN>; open inFile, '<', $in; open outFile, '>', 'out.txt'; while (<inFile>) { my $line = $_; # ... do stuff to $line here print outFile $line; } close inFile; close outFile;

That way only one line of data is in memory at a time so memory usage remains low. The down side is that if you need to manipulate multiple lines as a unit things can get messy. When you bump up against that situation come back and we will help again, or Super Search for 'multiple lines' and read through some of the past questions that are relevant.

Update: s|%/|$/|g


DWIM is Perl's answer to Gödel

In reply to Re^3: What is the right way of concatenating strings by GrandFather
in thread What is the right way of concatenating strings by cool

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.