CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner: Re: [amanjosan2008] How to skip 14 digits from a syslog file??: Edit Log



BillKSmith
Veteran

Jul 22, 2013, 6:51 AM


Views: 5433
Re: [amanjosan2008] How to skip 14 digits from a syslog file??

Your description of your variable is inconsistent due to misuse of the words "digit" and "number". I assume that you wish to match a 14 character field consisting of one period and 11 spaces and/or digits surrounded by square brackets. The period is always the seventh character.

Template: [xxxxx.xxxxxx] x = digit or space.


Laurnet's regex on DB<29> above will always match such a field.

I have written a slightly more explicit one which will also always match. The following code tests each regex against each of ten examples. All are valid (my interpretation) fields. Some intentionally chosen to look strange.


Code
use strict; 
use warnings;
my $REGEX_1 = qr/\[[\s\d.]{12}\]/; # Laurent
my $REGEX_2 = qr/\[[\s\d]{5}\.[\s\d]{6}\]/; # Bill
my @fields = (
# '[xxxxx.xxxxxx]', 'x' represents a digit or a space
'[15125.218403]',
'[ 23.453629]',
'[ 284.271544]',
'[ ]',
'[11111.111111]',
'[1 2 3. 4 5 6]',
'[ 2 ]',
'[ 1234.12345 ]',
'[01234.123450]',
'[01 3 .123 50]',
);
print "(1) All match\n" if !(scalar grep !$REGEX_1, @fields);
print "(2) All match\n" if !(scalar grep !$REGEX_2, @fields);


OUTPUT:

Code
(1) All match 
(2) All match


Sorry, even my code tags did not properly display all of the fields. Please refer to the attached copy of the code.
Good Luck,
Bill

(This post was edited by BillKSmith on Jul 22, 2013, 10:06 AM)
Attachments: amanj.pl (0.57 KB)


Edit Log:
Post edited by BillKSmith (Veteran) on Jul 22, 2013, 6:57 AM
Post edited by BillKSmith (Veteran) on Jul 22, 2013, 10:06 AM


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives