in reply to newbie parse Q
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
Is this vaguely what you were looking for?vdname
(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. "
|
|---|