[prev in list] [next in list] [prev in thread] [next in thread]
List: ruby-talk
Subject: Re: principle of most suprise
From: "Robert Klemme" <bob.news () gmx ! net>
Date: 2004-02-02 9:14:48
Message-ID: bvl4cg$t7di7$1 () ID-52924 ! news ! uni-berlin ! de
[Download RAW message or body]
"tony summerfelt" <snowzone5@hotmail.com> schrieb im Newsbeitrag
news:NbeTb.1048$_62.314@read1.cgocable.net...
> On Fri, 30 Jan 2004 at 21:24 GMT, Maik Schmidt <contact@maik-schmidt.de>
wrote:
>
> > split will always return an Array (see "Ruby in a nutshell, p. 54).
>
> i read that a number of times before i posted...that's why i was stumped
>
> > You do not have to force this explicitly by using the Array
constructor.
>
> i don't know what i was thinking...you'd never know it, but i'm a better
> programmer than that :/
>
> > And if you want to do so, you have to use '()' not '[]' :-))
>
> i want to thank everyone for the polite replies :) it must have been
hard
> restraining yourselves :)
Just to keep improving: change
logline=String.new("+ 30 Jan 12:20:09 [3988] addr: x.x.x.x")
to
logline="+ 30 Jan 12:20:09 [3988] addr: x.x.x.x"
which saves you a superfluous object creation. :-)
To make results look a bit nicer you could also do
result = logline.split(/\s*\[\d+\]\s*/).first
to make the regexp eat up all white space that surrounds your split mark.
Regards
robert
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic