[25540] in Perl-Users-Digest
Perl-Users Digest, Issue: 7784 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Feb 15 14:10:30 2005
Date: Tue, 15 Feb 2005 11:10:22 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Tue, 15 Feb 2005 Volume: 10 Number: 7784
Today's topics:
regexp experts, need some help <rhugga@yahoo.com>
Re: regexp experts, need some help <phaylon@dunkelheit.at>
Re: regexp experts, need some help <josef.moellers@fujitsu-siemens.com>
Re: regexp experts, need some help <phaylon@dunkelheit.at>
Re: regexp experts, need some help <rhugga@yahoo.com>
Re: regexp experts, need some help <phaylon@dunkelheit.at>
Re: regexp experts, need some help <rhugga@yahoo.com>
Re: regexp experts, need some help <phaylon@dunkelheit.at>
Re: regexp experts, need some help <1usa@llenroc.ude.invalid>
Re: regexp experts, need some help <rhugga@yahoo.com>
regular expression backreferences <mdudley@king-cart.com>
Sort hashes <raj.kothary@thus.net>
Re: Sort hashes <noreply@gunnar.cc>
Re: Standard regexps module? <please_post@nomail.edu>
Re: vi "power tools" for Perl coding? <beetfoundation@gmail.com>
Weird Error message <chris@sunderhauf.net>
Re: Weird Error message <phaylon@dunkelheit.at>
Re: Win32::OLE check if excel is English or Swedish <lambik@kieffer.nl>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 15 Feb 2005 06:44:19 -0800
From: "Rhugga" <rhugga@yahoo.com>
Subject: regexp experts, need some help
Message-Id: <1108478659.323833.165350@o13g2000cwo.googlegroups.com>
My perl is rusty and my regexps even rustier. I want to search and
replace a certain string from log files that I process and store into
oracle. Here is a sample entry:
Feb 14 11:14:05 db-0201 su: [ID 366847 auth.info] 'su oracle' succeeded
for root on /dev/???
The field I want to remove is [ID 366847 auth.info]
I don't know how large the ID number can be so I will just assume 2^64
and the auth.info part is standard syslog facility.priority.
Thanks for any help.
cc
------------------------------
Date: Tue, 15 Feb 2005 15:46:38 +0100
From: phaylon <phaylon@dunkelheit.at>
Subject: Re: regexp experts, need some help
Message-Id: <pan.2005.02.15.14.46.38.199937@dunkelheit.at>
Rhugga wrote:
> The field I want to remove is [ID 366847 auth.info]
Hm. s/\[.*?\]//g; or you haven't said something. Is this the only
point where the [ .. ] will come up in this log-messages?
--
http://www.dunkelheit.at/
thou shallst fear...
------------------------------
Date: Tue, 15 Feb 2005 16:00:02 +0100
From: Josef Moellers <josef.moellers@fujitsu-siemens.com>
Subject: Re: regexp experts, need some help
Message-Id: <cut2ls$2di$1@nntp.fujitsu-siemens.com>
phaylon wrote:
> Rhugga wrote:
>=20
>=20
>>The field I want to remove is [ID 366847 auth.info]
>=20
>=20
> Hm. s/\[.*?\]//g; or you haven't said something. Is this the only
> point where the [ .. ] will come up in this log-messages?
>=20
One can specify this in as much detail as desired:
s/\[ID\s\d+\s\w+\.\w+\]//
Josef
--=20
Josef M=F6llers (Pinguinpfleger bei FSC)
If failure had no penalty success would not be a prize
-- T. Pratchett
------------------------------
Date: Tue, 15 Feb 2005 15:57:24 +0100
From: phaylon <phaylon@dunkelheit.at>
Subject: Re: regexp experts, need some help
Message-Id: <pan.2005.02.15.14.57.24.644330@dunkelheit.at>
Josef Moellers wrote:
> One can specify this in as much detail as desired:
Yes. but there's also, like almost everywhere, a too much.
--
http://www.dunkelheit.at/
...and in darkness bind them.
------------------------------
Date: 15 Feb 2005 07:05:50 -0800
From: "Rhugga" <rhugga@yahoo.com>
Subject: Re: regexp experts, need some help
Message-Id: <1108479950.447309.202540@l41g2000cwc.googlegroups.com>
Yea, that is the only place it will appear and can only appear once. I
figured it it was something simple just haven't done regexp in 5 years,
heh.
Thx,
cc
------------------------------
Date: Tue, 15 Feb 2005 16:09:13 +0100
From: phaylon <phaylon@dunkelheit.at>
Subject: Re: regexp experts, need some help
Message-Id: <pan.2005.02.15.15.09.13.976395@dunkelheit.at>
Rhugga wrote:
> Yea, that is the only place it will appear and can only appear once. I
> figured it it was something simple just haven't done regexp in 5 years,
> heh.
Then go for it, you'll love it :D
--
http://www.dunkelheit.at/
The eternal mistake of mankind is to set up an attainable ideal.
-- Aleister Crowley
------------------------------
Date: 15 Feb 2005 07:58:37 -0800
From: "Rhugga" <rhugga@yahoo.com>
Subject: Re: regexp experts, need some help
Message-Id: <1108483117.371585.112800@o13g2000cwo.googlegroups.com>
Ok, down to one more roadblock. I am parsing the following sample log
entry and tokenizing it into fields and then shoving into oracle. The
problem is that some log messages will contain ' symbols. I am trying
to escape these so I can insert into oracle:
Here is a sample log message:
Feb 15 07:49:55 db-0201 su auth info su: [ID 366847 auth.info] 'su
oracle' succeeded for root on /dev/???
Here is the code where I'm trying to replace ' with \':
$log_message =~ s/\[.*?\]//g;
$log_message =~ s/ +/ /g;
$log_message =~ s/^ +//g;
$log_message =~ s/'/\'/g;
if ($DEBUG > 1) { print STDOUT "DEBUG: $log_message\n"; }
However, this is not working. here is a resulting query built using
$log_message:
DEBUG: $query = INSERT INTO SYSADMIN.SYSLOG VALUES (
SYSLOG_PKEY_SEQ.NEXTVAL, to_date('2005-Feb-15 07:44:54', 'YYYY-MON-DD
HH24:MI:SS'), '2', 'db-0201', 'su', 'auth', 'info', 'su: 'su oracle'
succeeded for root on /dev/???' )
Oracle is interpresting 'su: 'su oracle' succeeded for root on
/dev/???' as 2 fields and I need it to treat this as one field.
One option is to simply remove the ' or replace them with " or
something else but I really desire to keep the log mesage completely
intact with the exception of extra white space removed.
------------------------------
Date: Tue, 15 Feb 2005 16:57:35 +0100
From: phaylon <phaylon@dunkelheit.at>
Subject: Re: regexp experts, need some help
Message-Id: <pan.2005.02.15.15.57.35.136869@dunkelheit.at>
Rhugga wrote:
> $log_message =~ s/'/\'/g;
Double the \, else you are escaping ' for the regex:
phaylon@hamlett:~/ptests> perl
$a = "test ' abc";
$a =~ s/'/\\'/g;
print "$a\n";^D
test \' abc
phaylon@hamlett:~/ptests>
hth,phay
--
http://www.dunkelheit.at/
...and in darkness bind them.
------------------------------
Date: Tue, 15 Feb 2005 16:05:36 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: regexp experts, need some help
Message-Id: <Xns95FE70D9515DBasu1cornelledu@127.0.0.1>
"Rhugga" <rhugga@yahoo.com> wrote in news:1108483117.371585.112800
@o13g2000cwo.googlegroups.com:
> I am trying to escape these so I can insert into oracle:
>
> Here is a sample log message:
> Feb 15 07:49:55 db-0201 su auth info su: [ID 366847 auth.info] 'su
> oracle' succeeded for root on /dev/???
>
> Here is the code where I'm trying to replace ' with \':
>
> $log_message =~ s/\[.*?\]//g;
> $log_message =~ s/ +/ /g;
> $log_message =~ s/^ +//g;
> $log_message =~ s/'/\'/g;
> if ($DEBUG > 1) { print STDOUT "DEBUG: $log_message\n"; }
I don't know why this is necessary.
> However, this is not working. here is a resulting query built using
> $log_message:
> DEBUG: $query = INSERT INTO SYSADMIN.SYSLOG VALUES (
> SYSLOG_PKEY_SEQ.NEXTVAL, to_date('2005-Feb-15 07:44:54', 'YYYY-MON-DD
> HH24:MI:SS'), '2', 'db-0201', 'su', 'auth', 'info', 'su: 'su oracle'
> succeeded for root on /dev/???' )
Are you using DBI?
> Oracle is interpresting 'su: 'su oracle' succeeded for root on
> /dev/???' as 2 fields and I need it to treat this as one field.
Then you should quote it properly. Blind substitution is not going to
help you do it properly.
> One option is to simply remove the ' or replace them with " or
> something else but I really desire to keep the log mesage completely
> intact with the exception of extra white space removed.
You might want to look at the DBI documentation:
quote
$sql = $dbh->quote($value);
$sql = $dbh->quote($value, $data_type);
Quote a string literal for use as a literal value in an SQL
statement, by escaping any special characters (such as quotation marks)
contained within the string and adding the required type of outer
quotation marks.
Sinan.
------------------------------
Date: 15 Feb 2005 08:05:55 -0800
From: "Rhugga" <rhugga@yahoo.com>
Subject: Re: regexp experts, need some help
Message-Id: <1108483555.061142.254880@o13g2000cwo.googlegroups.com>
Made a mistake in that code,
$log_message =~ s/'/\'/g;
should be
$log_message =~ s/'/\\'/g;
Which then gives me the resulting query:
DEBUG: $query = INSERT INTO SYSADMIN.SYSLOG VALUES (
SYSLOG_PKEY_SEQ.NEXTVAL, to_date('2005-Feb-15 07:44:54', 'YYYY-MON-DD
HH24:MI:SS'), '4', 'db-0201', 'su', 'auth', 'info', 'su: \'su oracle\'
succeeded for root on /dev/???' )
So I think my problem is oracle related now and figuring out how to
insert ' into an oracle varchar2 column. Am I correct in this?
Thx,
cc
------------------------------
Date: Tue, 15 Feb 2005 13:28:42 -0500
From: Marshall Dudley <mdudley@king-cart.com>
Subject: regular expression backreferences
Message-Id: <42123F5A.60EC93D0@king-cart.com>
Given the following:
$string = "start:a-b,c-d,e-f";
$string =~ /start:(?:(\w+)\-(\w+),?)+/;
print "1 -> $1=$2\n2 -> $3=$4\n3 -> $5=$6\n";
I would expect:
1 -> a=b
2 -> c=d
3 -> e=f
but am getting:
1 -> e=f
2 -> =
3 -> =
Is there any way to loop an unknown number of pairs, and get them shoved
into the backreferences instead of them always overwriting the first
two? This is a simplication of the actual problem and I cannot use the
g)lobal designation in the match due to other constraints.
Thanks,
Marshall
------------------------------
Date: Tue, 15 Feb 2005 18:44:38 -0000
From: "Raj" <raj.kothary@thus.net>
Subject: Sort hashes
Message-Id: <cutfrd$clk$1$8302bc10@news.demon.co.uk>
Hi,
I have a need to sort a hash of hashes! I know it already sounds
complicated, but its the only way I can think of holding the results of the
analysis of some data.
The hash has entries like:
$ips{"F1234"}{"telephone"} = "02088887777"
$ips{"F1234"}{"charge"} = 1000
$ips{"F1234"}{"err_type"} = 0
$ips{"F6638"}{"telephone"} = "02077776666"
$ips{"F6638"}{"charge"} = 500
$ips{"F6638"}{"err_type"} = 2
$ips{"B7877"}{"telephone"} = "02077756666"
$ips{"B7877"}{"charge"} = 445
$ips{"B7877"}{"err_type"} = 2
I need to sort it using the key "err_type"....is this easy? I've never
understood sorting in Perl and so would appreciate any help you can give me.
"err_type" is always a number, if that's relevant!
Thanks in advance,
- raj
------------------------------
Date: Tue, 15 Feb 2005 20:03:44 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Sort hashes
Message-Id: <37ev8iF59lsg6U1@individual.net>
Raj wrote:
> I have a need to sort a hash of hashes!
perldoc -q "sort a hash"
> I've never understood sorting in Perl
perldoc -f sort
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Tue, 15 Feb 2005 14:21:44 +0000 (UTC)
From: bill <please_post@nomail.edu>
Subject: Re: Standard regexps module?
Message-Id: <cut0ho$mn2$1@reader2.panix.com>
In <37d76dF59oaf9U1@individual.net> Gunnar Hjalmarsson <noreply@gunnar.cc> writes:
>bill wrote:
>> After searching CPAN for a while, I was not able to find a Perl
>> module consisting of "standard" regular expressions (e.g. the
>> "standard" regular expression to match an internet IP address, or
>> a "number", or a "Perl identifier", etc.). I realize that in some
>> cases it is pretty easy to come up with the regexp oneself, but
>> this kind of code seems like a trivially good candidate for re-use.
>>
>> Pointers to the right CPAN module would be much appreciated.
>You seem to looking for Regexp::Common.
Yep. That'd be the one! Thanks!
bill
------------------------------
Date: 15 Feb 2005 08:52:04 -0800
From: "jopa" <beetfoundation@gmail.com>
Subject: Re: vi "power tools" for Perl coding?
Message-Id: <1108486324.758106.189110@c13g2000cwb.googlegroups.com>
I use these perl specific lines in my vimrc.
let perl_want_scope_in_variables=1
let perl_extended_vars=1
let perl_include_pod=1
Anyone know of other perl specific .vimrc options?
I also use things like:
iab _oIN open (IN, "") \|\| die "Pukeonfile : $!\n";<CR>@array =
<IN>;<CR>close IN;
Which lets me type "_oIN" then hit enter for an open file block.
Jopa
~~~~`
------------------------------
Date: Tue, 15 Feb 2005 19:59:51 +0100
From: =?ISO-8859-1?Q?Christoph_S=FCnderhauf?= <chris@sunderhauf.net>
Subject: Weird Error message
Message-Id: <cutgbt$5ca$1@online.de>
Use of uninitialized value in concatenation (.) or string at start.pl
line 54.
Does someone know what this means?
line 54 is:
print "$termine[($line + 1 )] \n\n";
------------------------------
Date: Tue, 15 Feb 2005 19:50:12 +0100
From: phaylon <phaylon@dunkelheit.at>
Subject: Re: Weird Error message
Message-Id: <pan.2005.02.15.18.50.12.239831@dunkelheit.at>
Christoph Sünderhauf wrote:
> print "$termine[($line + 1 )] \n\n";
Do you want
print $termine[ $line + 1 ]."\n\n";
? You may want to read upon interpolation.
hth,phay
--
http://www.dunkelheit.at/
The first rule of project mayhem is: you do not ask questions.
-- Fight Club
------------------------------
Date: Tue, 15 Feb 2005 12:20:00 +0100
From: Lambik <lambik@kieffer.nl>
Subject: Re: Win32::OLE check if excel is English or Swedish
Message-Id: <37e41iF5cd3qqU1@individual.net>
Brian Helterline wrote:
>
> <peter.moller@gmail.com> wrote in message news:u1xbjqf16.fsf@notvalid.se...
> >
> >
> > Does anyone know how to check if the Excel I'm talking to
> > with Win32::OLE is english or swedish?
>
> The LanguageSettings Property looks promising: (from Excel VBA)
>
> Returns the LanguageSettings object, which contains information about the
> language settings in Microsoft Excel. Read-only.
> expression.LanguageSettings
> expression Required. An expression that returns one of the objects in the
> Applies To list.
> Example
> This example returns the language identifier for the language you selected
> when you installed Microsoft Excel.
> Set objLangSet = Application.LanguageSettings
> MsgBox objLangSet.LanguageID(msoLanguageIDInstall)
>
> Translation into Perl left as an exercise ;)
>
>
#!/usr/bin/perl
use strict;
use Win32::OLE;
$Win32::OLE::Warn = 3;
my $Excel = Win32::OLE->GetActiveObject('Excel.Application')||
Win32::OLE->new('Excel.Application', 'Quit');
my $lang = $Excel->LanguageSettings->LanguageID(3);
print "$lang";
------------------------------
Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>
Administrivia:
#The Perl-Users Digest is a retransmission of the USENET newsgroup
#comp.lang.perl.misc. For subscription or unsubscription requests, send
#the single line:
#
# subscribe perl-users
#or:
# unsubscribe perl-users
#
#to almanac@ruby.oce.orst.edu.
NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
#To request back copies (available for a week or so), send your request
#to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
#where x is the volume number and y is the issue number.
#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V10 Issue 7784
***************************************