[Chicago-talk] Regex and the whitespace before it.

Mike Ferrari mikeferrari8 at yahoo.com
Wed Mar 26 11:21:46 PDT 2008


Awesome, thanks for all your help everyone, i will try this stuff out
tonight.. :-)

when i see this..  " my @aa = map {s/\n//g;$_} split /(\w+)\s*:\s*/,
$string; "

my eyes glaze over.. sort of like Homer Simpson when he sees doughnuts..

hehehe

Thanks
Mike

On Wed, Mar 26, 2008 at 1:19 PM, Mike Ferrari <mikeferrari8 at gmail.com>
wrote:

> Awesome, thanks for all your help everyone, i will try this stuff out
> tonight.. :-)
>
> when i see this..  " my @aa = map {s/\n//g;$_} split /(\w+)\s*:\s*/,
> $string; "
>
> my eyes glaze over.. sort of like Homer Simpson when he sees doughnuts..
>
> hehehe
>
> Thanks
> Mike
>
>
> On Wed, Mar 26, 2008 at 12:24 PM, Mike Fragassi <frag at ripco.com> wrote:
>
> >
> > Mike --
> >
> > You're welcome for the help.  Hopefully this will help with the current
> > problem:
> >
> >    split /(\w+)\s*:/
> >
> > Capturing parentheses in the split regex will return that portion of
> > the match in the output.
> >
> > my $string =<<STRING;
> > subject1 : description of a subject. subject2 : description of a
> > subject.
> > subject3 : description of a subject.  etc etc
> > STRING
> > my @aa = split /(\w+)\s*:\s*/, $string;
> > $,="\n";
> > print @aa;
> >
> > Of course, this assumes that colons don't naturally occur in the
> > descriptions, and that the subject is never more than one word.
> >
> > If your descriptions wrap across lines and you want to quickly get rid
> > of the internal newlines, you can just put a map block between the = and
> > the split, like this:
> >
> > my @aa = map {s/\n//g;$_} split /(\w+)\s*:\s*/, $string;
> >
> > -- Mike F.
> >
> > _______________________________________________
> > Chicago-talk mailing list
> > Chicago-talk at pm.org
> > http://mail.pm.org/mailman/listinfo/chicago-talk
> >
>
>
>
> --
> /dev/mike0
>
> http://www.mikeferrari.com
>



-- 
/dev/mike0

http://www.mikeferrari.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.pm.org/pipermail/chicago-talk/attachments/20080326/08a2dc0a/attachment.html 


More information about the Chicago-talk mailing list