in reply to regexp parsing from a big string...

Don't do it with one regex, instead split it first into records.
use Data::Dumper; for my $record (split m/\n\n\n/, $tempStr){ my %user_info; for (split m/\n/, $record){ if (m/^User (.*)$/){ $user_info{name} = $1; } elsif (m/^(\w+)\s*=\s*(.*)$/){ $user_info{$1} = $2; } } print Dumper \%user_info if %user_info; }

(Update: Code now actually works).

Note that your email addresses a@b.com try to interpolate the array @b if the string is in double quotes, so please use single quotes (or even better, a here-doc) instead.

Replies are listed 'Best First'.
Re^2: regexp parsing from a big string...
by kyle (Abbot) on May 12, 2008 at 20:33 UTC

    A here-doc will interpolate the @b also, unless the delimiter is specifically put in single quotes.

    my @fruit = qw( apple banana cherry ); my $bare_heredoc = <<BARE_HEREDOC; I am kyle@fruit.com, I say. BARE_HEREDOC ; my $qq_heredoc = <<"QQ_HEREDOC"; I am kyle@fruit.com, I say. QQ_HEREDOC ; my $q_heredoc = <<'Q_HEREDOC'; I am kyle@fruit.com, I say. Q_HEREDOC ; print "bare: $bare_heredoc"; print "double quoted: $qq_heredoc"; print "single quoted: $q_heredoc"; __END__ bare: I am kyleapple banana cherry.com, I say. double quoted: I am kyleapple banana cherry.com, I say. single quoted: I am kyle@fruit.com, I say.