in reply to Help on multiline regex

my %objects; my $object; while (<>) { chomp; if ( my ($object_type, $object_id) = /^\s*object-group\s+(\S+)\s+(\S+)/ ) { $objects{$object_id} = $object = { type => $object_type, entries => [], }; } elsif (my ($entry) = /^\s*\S+-object\s+(.*)/) { push @{ $object->{entries} }, $entry; } }

Replies are listed 'Best First'.
Re^2: Help on multiline regex
by LanX (Saint) on Jun 01, 2011 at 18:05 UTC
    better  elsif (my ($entry) = /^\s*${object_type}-object\s+(.*)/) {

    Cheers Rolf

      That should be
      elsif (my ($entry) = /^\s*\Q$object->{type}\E-object\s+(.*)/) {
      but I fixed it with something simpler.
        elsif (my ($entry) = /^\s*(\S+)-object\s+(.*)/)

        ehm, if you match the type, $entry is the second match...

        fun ... untested code reviews... like freestyle rapping xD

        Cheers Rolf