in reply to Re: how to parse to get only the replica names in an array
in thread how to parse to get only the replica names in an array

The third would return rd_v_dialer" "v_dialer replica for Redmond instead of the wanted rd_v_dialer. You need the non-greedy quantifier with "?" to match the nearest closing '"' (as little as possible). So it should be /replica\s+"(.+?)"/;.

Open source softwares? Share and enjoy. Make profit from them if you can. Yet, share and enjoy!

Replies are listed 'Best First'.
Re^3: how to parse to get only the replica names in an array
by citromatik (Curate) on Aug 08, 2007 at 10:42 UTC

    Hmmm, Are you sure? the dot "." matches everything but "\n", so it will not expand through newlines (see perlretut):

    use strict; use warnings; use Data::Dumper; { local $/; my @replica = <DATA> =~ /replica\s+"(.+)"/g; print Dumper \@replica; } __DATA__ 2005-04-01 root replica "ml_v_dialer" 2004-06-22 root replica "pu_v_dialer" 2006-02-11 ccvob01 replica "rd_v_dialer" "v_dialer replica for Redmond" 2003-11-25 root replica "v_dialer_drcalvin"

    Outputs:

    $VAR1 = [ 'ml_v_dialer', 'pu_v_dialer', 'rd_v_dialer', 'v_dialer_drcalvin' ];

    And:

    use strict; use warnings; use Data::Dumper; my @replica; while (<DATA>){ next if (! /^\d+/); /replica\s+"(.+)"/; push @replica,$1; } print Dumper \@replica; __DATA__ 2005-04-01 root replica "ml_v_dialer" 2004-06-22 root replica "pu_v_dialer" 2006-02-11 ccvob01 replica "rd_v_dialer" "v_dialer replica for Redmond" 2003-11-25 root replica "v_dialer_drcalvin"

    Prints the same:

    $VAR1 = [ 'ml_v_dialer', 'pu_v_dialer', 'rd_v_dialer', 'v_dialer_drcalvin' ];

    citromatik

      Oh my, we have different interpretation about the input lines :-) You have five lines, I only have four because I thought that the "v_dialer replica for Redmond" line was lined up with "rd_v_dialer". Of course, your codes are just fine in your situation (with five lines of input). Now I know what that next... line is for. And yes, I know about "." and "\n" and "/s".

      Open source softwares? Share and enjoy. Make profit from them if you can. Yet, share and enjoy!