in reply to How to parse the logs in a generic manner

Write a module:

package Vasuperl; use strict; use warnings; use Exporter; use vars qw($VERSION @ISA @EXPORT_OK ); $VERSION = 1.00; @ISA = qw(Exporter); @EXPORT_OK = qw(parse_log); sub parse_log { my ( $log_file, $pattern ) = @_; # parse your log # and return something useful } 1;

Use it:

#!/usr/bin/env perl use strict; use warnings; use lib q(.); use Vasuperl qw (parse_log); my $log_file = shift || die $!; my $pattern = qr(.); my $result = parse_log( $log_file, $pattern ); # do something with $result __END__

Update: Changed legacy code on special request by choroba:

package Vasuperl; use strict; use warnings; use Exporter qw(import); our ( $VERSION, @EXPORT_OK ); $VERSION = 1.01; @EXPORT_OK = qw(parse_log); sub parse_log { my ( $log_file, $pattern ) = @_; # parse your log # and return something useful + } 1;

What is so difficult with this that you can't figure it out your self?

Karl

«The Crux of the Biscuit is the Apostrophe»

Replies are listed 'Best First'.
Re^2: How to parse the logs in a generic manner
by choroba (Cardinal) on Jan 02, 2015 at 17:12 UTC
    Manually changing @ISA is not needed. Just use
    use Exporter qw{ import };

    Also, use vars can be replaced by prefixing the variable assignments with our:

    our $VERSION = 1.01; our @EXPORT_OK = qw{ parse_log };
    لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ
      "...changing @ISA is not needed...prefixing the variable assignments with our..."

      Sure, you are right. Thank you for clarifying this.

      It seems that i'm a bit "outdated", right?

      Best regards, Karl

      «The Crux of the Biscuit is the Apostrophe»