Re: regex help




Anno Siegel wrote:
> si <smcbutler@xxxxxxxxxxx> wrote in comp.lang.perl.misc:
> >
> > hi all, i had a regex question for the group:
> >
> > i'm trying to do parse a string 'a = 3 b = 4 c = 5 d = 6'
>
> [...]
>
> > any idea of how I can do this with regex?
>
> my $str = 'a = 3 b = 4 c = 5 d = 6';
> my %hash = $str =~ /(\w+)\s*=\s*(\d+)/g;
>
> Anno

not as good but different:

#!/usr/bin/perl

use strict;
use warnings;

my $str = 'a = 3 b = 4 c = 5 d = 6';
$str =~ s/[^a-z0-9]+/ /g;
my %hash = split / /, $str;
print "$_ = $hash{$_}\n" for keys %hash;

wana

.



Relevant Pages

  • Re: new to Perl - please verify my script?
    ... > Anno Siegel wrote: ... >> you can simply access %shipping_cost to retrieve the result without ... > If you should get a chance to advise I would very much appreciate your ... Prev by Date: ...
    (comp.lang.perl.misc)
  • Re: line not exist
    ... Anno Siegel wrote: ... > the broken "Reply" link at the bottom of the article. ... > "Reply" at the bottom of the article headers. ... Prev by Date: ...
    (comp.lang.perl.misc)
  • Re: How do I parse certain "bits" out of bytes?
    ... Anno Siegel wrote: ... > Adam Schneider wrote in comp.lang.perl.misc: ... Oops. ... Prev by Date: ...
    (comp.lang.perl.misc)
  • Re: ignoring SIGCHLD
    ... Anno Siegel wrote: ... Is it really necessary to close the pipe then? ... Prev by Date: ...
    (comp.lang.perl.misc)
  • regular expression help needed
    ... I have a regex question. ... Regards ... Henrik ... Prev by Date: ...
    (microsoft.public.dotnet.languages.csharp)