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
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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |