2

I have a few log files like these:

  • /var/log/pureftpd.log
  • /var/log/pureftpd.log-20100328
  • /var/log/pureftpd.log-20100322

Is it possible to load all of them into a single filehandle or will I need to load each of them separately?

brian d foy
  • 129,424
  • 31
  • 207
  • 592
rarbox
  • 486
  • 5
  • 14

3 Answers3

5

One ugly hack would be this:

local @ARGV = qw(
    /var/log/pureftpd.log 
    /var/log/pureftpd.log-20100328 
    /var/log/pureftpd.log-20100322
);

while(<>) {
    # do something with $_;
}
Sinan Ünür
  • 116,958
  • 15
  • 196
  • 339
Leon Timmermans
  • 30,029
  • 2
  • 61
  • 110
1

You could use pipes to virtually concat these files to a single one.

codymanix
  • 28,510
  • 21
  • 92
  • 151
1

It's not terribly hard to do the same thing with a different filehandle for each file:

foreach my $file ( @ARGV )
    {
    open my($fh), '<', $file or do { warn '...'; next };
    while( <$fh> )
         {
         ...
         }
    }
brian d foy
  • 129,424
  • 31
  • 207
  • 592