Could you give us a few lines you actually intend to process, and the output you would like to see?

Using something like split, on the (stated) assumption that the field locations are fixed or that double quotes (") are present would probably break in the future.

To give some (virtually untested!) code:

#!perl use strict; use warnings; my $string = "add vdisk \"\\vdisks\\type 1\\vdname\" ". "disk_group=\"\\d gs\\diskgrp1\" size=500"; # split on quotes my @quotes = split(/\"/, $string); print "\@quotes:\n\t" . join("\n\t", @quotes) ."\n";; # @quotes should be 'add vdisk'. # '\\vdisks\\type 1\\vdname', # 'disk_group=', # '\\d gs\\diskgrp1\\', # 'size=500' # split the second element on backslashes... my @back = split(/\\/, $quotes[1]); print "\@back:\n\t" . join("\n\t",@back)."\n"; # and popout the last element... my $is_this_it = pop(@back); print $is_this_it,"\n";

produces

vdname
Is this vaguely what you were looking for?

(One of the regex wizards here could probably reduce that to 1 line; I could probably reduce it to about 3, but I was deliberately verbose.)

emc

"Being forced to write comments actually improves code, because it is easier to fix a crock than to explain it. "
—G. Steele

In reply to Re: newbie parse Q by swampyankee
in thread newbie parse Q by whatperl

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.