in reply to Regexp problems
Note that this preserves the double quotes around attrib values. If there's a flaw in the data, like the one that BrowserUk pointed out, this will produce a very confused result -- which you would detect if you happened to find double-quote characters in any of the hash keys. So you could follow that split with:if ( /<gene_seq ([^>]+)>/ ) { my $attribString = $1; # The challenge is to split the line properly into key/val # pairs; first, let's get rid of boundary stuff that might # get in the way: $attribString =~ s{^\s+}{}; # initial whitespace $attribString =~ s{[/\s]+$}{}; # final whitespace and/or "/" # now split into key,val pairs, assuming that " = " falls # between attrib name and attrib value, while the boundary # between a value and the next attrib name is whitespace # preceded by double-quote and followed by alphanumeric: my %attribHash = split( /\s+=\s+|(?<=\w\")\s+(?=\w)/, $attribStrin +g ); # That's it; now work with the keys and values of that hash...
die "Bad xml tag:\n$_\n" if ( grep( /\"/, keys %attribHash );
|
|---|