# Parses nested quoted text and returns each quoted text. # Copyleft: 2001 Sakis Doupas, adoupas@xanthi.ilsp.gr $string = $ARGV[0] or die "gimme a string\n"; $quotes = "(,)" unless $quotes = $ARGV[1]; ($q1, $q2) = split(/,/, $quotes); @quotes = (); sub parse1 { my $str = shift(@_); if ($str =~ /\Q$q1\E/) { push @quotes, $'; &parse1($'); } &parse2; } sub parse2 { my $str = pop(@quotes); if ($str =~ m/\Q$q2\E/) { my $temp = $`; foreach $value (@quotes) { $value =~ s/\Q$q1$temp$q2\E/_lq_$temp\_rq_/; } $temp =~ s/_lq_/$q1/g; $temp =~ s/_rq_/$q2/g; print $q1 . $temp . $q2 . "\n"; } } &parse1($string);