in reply to Prove me wrong,...please (yet more regex blues).

I think you want something like this:
my ( $vsan, $vname ) = ( $record =~ /^\s+vsan\s+(\d+)\s+name\s+(.+)/ ) +;
(the parens around the rhs are probably optional, but I like having them there; the ones around the lhs are mandatory, of course)

updated to include the literal string "name" in the regex match.

Replies are listed 'Best First'.
Re^2: Prove me wrong,...please (yet more regex blues).
by Anonymous Monk on Sep 23, 2005 at 13:15 UTC
    This might work:
    while (<DATA>) { s/name/=/; print "$_" if /^\s+/ && /=/; }
      While that kind of code is clever and fits a single case, it doesn't really explain what it's doing, and modifies the original data.

      Your choices of landmarks to match seem unlikely as the key determiners for the desired information. What if other lines are included (now or in the future) with similar formats that have leading spaces or equal signs? I would more likely guess that the keywords and string-delimited labels are the important parts to watch.

      Literate code helps the maintenance programmer (or yourself) figure out how it works later.

      while (<DATA>) { next if not /^ \s* vsan \s+ (\d+) \s+ # $1 name \s+ ( \" .*? \" ) # $2 $ /x; print "vsan $1 = $2\n"; }
      As you and your team of maintainers get more familiar with regular expressions, you may tighten that up with less spacing and less commentary, but the pattern is specific and includes the obvious visual landmarks which are important for the programmer to understand.

      --
      [ e d @ h a l l e y . c c ]