in reply to Re^7: Use Perl's Sort to only sort certain lines in a file?
in thread Use Perl's Sort to only sort certain lines in a file?
Well this form of open is considered much worse thenopen(Input, '+<…') || die "No such file found!";
First, Input is a global variable and those are generally to be avoided. Second, when you don't specify the mode (here +<) separately, Perl will treat various funny characters (whilespace, |, etc) in filenames in a special way. Which is usually not what you want.open my $input, '+<', 'file...';
With your code, when I run it I receive a log file with all the data properly formatted. I simply cannot seem to find the right way to then print that out to my Output file.The easiest way would be to use the shell:
I'm pretty sure that works with cmd.exe too. Another easy way is to reopen STDOUT (this is where print prints by default - normally the terminal) at the beginning of the program:perl script.pl > output.txt
open STDOUT, '>', 'output.txt' or die $!
There are a few more edits I need to make to the file before writing out as well. Would I write another subroutine, such as "handle_section" and place it within the primary subroutine?Sure, that's one way to do it. Another one would be to write one more script and pipe the output of first script to the second (in the shell)
The first script prints to STDOUT and the second one reads from STDIN:perl first.pl | perl second.pl
while (my $line = <STDIN>) { ... }
|
|---|