in reply to Re^2: Win32::EventLog->Backup(), appending contents of new log to a saved one.
in thread Win32::EventLog->Backup(), appending contents of new log to a saved one.
my $dst = "C:\\Users\\Administrator\\Desktop\\Perl_Scripts\\8312032_Se +curity.evtx"; my $src = "C:\\Users\\Administrator\\Desktop\\Perl_Scripts\\8312032_Sy +stem.evtx"; open (my $dsth, ">>", $dst) or die qq(can't open "$dst" for appending: $!); open (my $srch, "<", $src) or die qq(can't open "$src" for reading: $!); print {$dsth} <$srch>; close ($srch); close ($dsth);
or
use autodie; { open (my $dsth, ">>", $dst); open (my $srch, "<", $src); print {$dsth} <$srch>; }
That last block could be any type of block providing lexical scope. The print {$filehandle} LIST; construct makes it more obvious that you're printing to a filehandle object, rather than missing a comma in your arguments list, to both the programmer and to Perl. In list context, the diamond operator returns all lines from a file. You don't need to escape colons or underscores in a string or a regular expression.
For easy of readability, Perl can handle Windows paths with forward slashes (actually, Windows itself handles forward-slash paths fine, which is what Perl sends to the system -- its Windows built-in applications which force only backslash paths on you). So to prevent forgetting to backslash a directory separator and to minimize length of paths strings, you could represent them as:
my $dst = "C:/Users/Administrator/Desktop/Perl_Scripts/8312032_Securit +y.evtx"; my $src = "C:/Users/Administrator/Desktop/Perl_Scripts/8312032_System. +evtx";
|
|---|