Leser: 1
8 Einträge, 1 Seite |
1 2 3
use magrathea::generic; # use a generic log function like xlog(LOG_DEBUG,"This is a debug log");
#! /usr/bin/perl -w
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
#! /usr/bin/perl # load libs use strict; use warnings; use POSIX 'uname'; use Unix::Syslog; use Unix::Syslog qw(:macros); require Win32::EventLog; # global vars ( arrrghhh, like an undeath mattress ;-) my $handle = undef; my ($sys) = &uname; # some lines later.... if($sys =~ /window/i) { #init win32 event log $handle = Win32::EventLog->new("Zaphod"); } else { # init UNIX syslog &openlog("Trillian","pid, ndelay, nowait",LOG_LOCAL4); } # some functions/lines later part of generic xlog() function... :-) if($sys =~ /window/i) { my %win; $win{'Computer'} = "Eddy"; $win{'Source'} = "Hard of Gold"; $win{'Category'} = undef; $win{'EventID'} = 42; $win{'Data'} = undef; $win{'Strings'} = "Dont interrupt me, I computing real earth Tee!" $handle->Report(\%win); } else { &syslog(LOG_DEBUG,"Where is Marvin??"); } # And now close all... if($sys =~ /window/i) { $handle->Close; } else { &closelog(); }
1 2 3
require Unix::Syslog; require Unix::Syslog qw(:macros); require Win32::EventLog;
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
package MyLogger; use strict; use warnings; sub new { if( $^O =~ /win32/i ){ require MyLogger::Win32; return MyLogger::Win32->new; } else{ require MyLogger::Default; return MyLogger::Default->new; } } 1;
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
package MyLogger::Win32; use strict; use warnings; use all_Win32_stuff; sub new{ my ($class) = @_; my $self = bless {}, $class; $self->{handle} = Win32::EventLog->new("Zaphod"); } sub log { my ($self) = @_; my %win; $win{'Computer'} = "Eddy"; $win{'Source'} = "Hard of Gold"; $win{'Category'} = undef; $win{'EventID'} = 42; $win{'Data'} = undef; $win{'Strings'} = "Dont interrupt me, I computing real earth Tee!" $self->{handle}->Report(\%win); } ...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
package MyLogger::Default; use strict; use warnings; use all_Unix_stuff; sub new{ my ($class) = @_; return bless {}, $class; } sub log { &syslog(LOG_DEBUG,"Where is Marvin??"); } ...
Schnullux+2008-07-24 16:37:18--Code (perl): (dl )1 2 3require Unix::Syslog; require Unix::Syslog qw(:macros); require Win32::EventLog;
Dieser code führt aber zu einem Syntax-error bei require Unix::Syslog qw(:macros);
Schnullux+2008-07-24 16:04:35--1) Wird die interpreterZeilebei Win tatsächlich ignoriert wenn ich die *.pl Endung registriert habe und mit dem entsprechenden perl binary verküpft habe?Code: (dl )#! /usr/bin/perl -w
QuoteThe #! line is always examined for switches as the line is being parsed. Thus, if you're on a machine that allows only one argument with the #! line, or worse, doesn't even recognize the #! line, you still can get consistent switch behavior
regardless of how Perl was invoked, even if -x was used to find the beginning of the program.
8 Einträge, 1 Seite |