[Chicago-talk] Removing "." from a string?

richard at rushlogistics.com richard at rushlogistics.com
Thu Jan 31 12:15:19 PST 2008


Thanks for all the replies. They were all good.
Sent via BlackBerry from T-Mobile

-----Original Message-----
From: Steven Lembark <lembark at wrkhors.com>

Date: Thu, 31 Jan 2008 15:14:06 
To:"Chicago.pm chatter" <chicago-talk at pm.org>
Subject: Re: [Chicago-talk] Removing "." from a string?


Richard Reina wrote:
> Does anyone know an easy way to remove "."s from a string like
> 192.168.2.16
>
> so I get 192168216?  Substring seems cumbersome and does not account for
> length between dots.
>
> Thanks for any help.

Here are four progessively more ridiculous solutions:

    $dotted_quad    =~ s/\D//g;

    my $digits      = join '', split /\D+/, $dotted_quad;

    my $digits      = join '', $dotted_quad =~ m{ (\d+) }gx;

    while( ( my $i = index $dotted_quad, '.' ) > 0 )
    {
        substr $dotted_quad, $i, 1, '';
    }

though the last one may actually be the fastest
due to the lack of recursion and extra data
structures.


-- 
Steven Lembark                                          +1 888 359 3508
Workhorse Computing                                       85-09 90th St
lembark at wrkhors.com                                 Woodhaven, NY 11421
_______________________________________________
Chicago-talk mailing list
Chicago-talk at pm.org
http://mail.pm.org/mailman/listinfo/chicago-talk


More information about the Chicago-talk mailing list