[PLUG] Long Perl regex...

Wil Cooley wcooley at nakedape.cc
Thu Sep 18 13:21:02 UTC 2003


On Thu, 2003-09-18 at 13:06, Jeff Schwaber wrote:

> Or, in a readable language, and without using regexes:
> 
> #!/usr/bin/python
> # get your string from somewhere, save it in variable line
> 
> i=0, end=-1, numbers=""
> while i < 6:
>     if line[end] != " ":
>         numbers = numbers + line[end]
>         i = i + 1
>     end = end - 1
> 
> Of course, you never said anything about this either running incredibly
> quickly (this is okay, but poky compared to a regex) or that spaces were
> the only non-numeric characters in the midst of those numbers. Plus you
> wanted to put it in a bash script.
> 
> But I'm just having fun. =)

It's faster to do a join on a list than to concatenate strings, if
you're doing it a lot.

Wil
-- 
Wil Cooley                                 wcooley at nakedape.cc
Naked Ape Consulting                        http://nakedape.cc
* * * * * * * Good, fast and cheap: Pick all 3! * * * * * * *
*   Naked Ape Consulting                http://nakedape.cc  *
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part
URL: <http://lists.pdxlinux.org/pipermail/plug/attachments/20030918/38a44c66/attachment.asc>


More information about the PLUG mailing list