<?xml version="1.0" encoding="windows-1252"?>
<node id="698270" title="Perlbotics's scratchpad" created="2008-07-17 07:27:39" updated="2008-07-17 03:27:39">
<type id="182711">
scratchpad</type>
<author id="636534">
Perlbotics</author>
<data>
<field name="doctext">

&lt;p&gt;
This snipped doesn't add much to the thread...

&lt;code&gt;
use strict;
use warnings;
use Data::Dumper;
$Data::Dumper::Sortkeys = 1;

my $string = q{AA(aa),AB(a(b),b),AC(Departament d'Astronomia i Astrofísica. Universitat de València. C/Dr. Moliner 50, 46100 Burjassot (València), Spain),AD(a,c,XX(ignored!)),AE(Neumann,AE(+++)),AF(FAILS in rare case where value contains next token (here:AG),AG(blah)),AG(last)};

my $range  = join(',', 'A'..'Z');
my %result;

for (my $key = 'AA'; $key ne 'AAA'; $key++) {  # AA..ZZ
  last if $string !~ /(?:^|\),)$key\(/;  # stop if xx( or ),xx( missing
  my $key2 = $key; $key2++;

  # match AA(...),BB(
  if ( $string =~ / $key \( (.*?) \) (?: ,$key2\( | $) /x ) {
    $result{ $key } = $1;
  } else { #TODO: Error handling
    warn "No match for $key(...),$key2!\n";
  }

}

print "Result from '$string':\n", Dumper( \%result ), "\n";

__DATA__

$VAR1 = {
          'AA' =&gt; 'aa',
          'AB' =&gt; 'a(b),b',
          'AC' =&gt; 'Departament d\'Astronomia i Astrofísica. Universitat de València. C/Dr. Moliner 50, 46100 Burjassot (València), Spain',
          'AD' =&gt; 'a,c,XX(ignored!)',
          'AE' =&gt; 'Neumann,AE(+++)',
          'AF' =&gt; 'FAILS in rare case where value contains next token (here:AG',
          'AG' =&gt; 'blah)),AG(last'
        };

&lt;/code&gt;
&lt;/p&gt;

&lt;hr&gt;

&lt;p&gt;
&lt;em&gt;... found in a dusty part of the monasteries scriptorium ...&lt;/em&gt;

&lt;blockquote&gt;
Into this wilde Abyss,&lt;br&gt;
The Womb of nature and perhaps her Grave,&lt;br&gt;
Of neither Sea, nor Shore, nor Air, nor Fire,&lt;br&gt;
But all these in thir pregnant causes mixt&lt;br&gt;
Confus'dly, and which thus must ever fight,&lt;br&gt;
Unless th' Almighty Maker them ordain&lt;br&gt;
[wp://His_Dark_Materials|His dark materials] to create more Worlds,&lt;br&gt;
Into this wilde Abyss the warie fiend&lt;br&gt;
Stood on the brink of Hell and look'd a while,&lt;br&gt;
Pondering his Voyage ...&lt;br&gt;
&lt;/blockquote&gt;
&lt;em&gt;Milton / Paradise Lost&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;
&lt;p&gt;
Darkly fills an otherwise empty scratchpad - and 
some books by [wp://Philip Pullman].
&lt;/p&gt;</field>
</data>
</node>
