On Sunday 28 October 2007 16:13, Jo for Groups and Lists wrote: > What I want are these array members from a string in a database. I'm > almost there, just need to strip off the trailing pipe, but I am > getting empty members too, so will have to test for that and dump the > empty ones before proceeding. Is this the best solution? {No, we > can't change the database format} > > Many thanks in advance, > Jo > > > police record > dwelling=(apt|condo) > pet=(dog|cat) > marital=single > vacation > ================================= > #!/usr/bin/perl -Tw > > use strict; > > print "\n"; > my $one=""; > my $string="police > record|dwelling=(apt|condo)|pet=(dog|cat)|marital=single|vacation"; > my @items = split > (/([^|()]+\|{1}|[^|()]+[(][^()]+[)]\|{1})/,$string); foreach $one > (@items) { > print "_".$one."_\n"; > } > exit; > ================================= > __ > _police record|_ > __ > _dwelling=(apt|condo)|_ > __ > _pet=(dog|cat)|_ > __ > _marital=single|_ > _vacation_
Did you want something like this: $ perl -e' my $string = "police record|dwelling=(apt|condo)|pet=(dog|cat)|marital=single|vacation"; my @items = split /\|(?=[^()]+(?:=|$))/, $string; for my $one ( @items ) { print "_${one}_\n"; } ' _police record_ _dwelling=(apt|condo)_ _pet=(dog|cat)_ _marital=single_ _vacation_ John -- use Perl; program fulfillment -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/