From: Charles Mills Date: 2004-08-17T00:49:24+09:00 Subject: Re: Rubish Way of extracting elements On Aug 16, 2004, at 8:06 AM, Daniel V�lkerts wrote: > I started written a little script to analyse my syslogs. The > development went on very fast, but today I'm searching the rubish way > to dissect a string into some parts. For example in my syslog there is > a line (valid as described in rfc3146) > > <165> Aug 16 17:01:35 localhost Just a test > > I was trying to reach this form > > var = content > > pri = 165 > timestamp = Aug 16 17:01:35 > device = localhost > msg = Just a test > > But how do I accomplish this? I read the pickaxe book, but the example > I found was about repeating values e.g. | as seperator. Is a suitable > regexp the way or should use another technique e.g. String#index etc.? > Probably use regular expressions. You could have one big regexp or one for each field like so: var =~ /<([0-9]+)>/ pri = $1 $' =~ /some regexp/ # I'm lazy timestamp = $1 # etc You could also use \A along with the post match ($') to make sure the fields come in the order you expect. -Charlie > > Thanks for your time helping me, I'll pay it back if I become a little > more rubisher ;) > > -- > Daniel V�lkerts :: > "Ich habe einen Drachen, und ich WERDE ihn benutzen!" - Esel in Shrek >