# subroutine name: text2struct # Input: string with structure written in Perl language # Returns: data structure, which is parsed from passed text, # previously created with struct2text # Note: old_text2struct is kept for compatibility with older versions. # Subroutine without older format support will look like this: # sub text2struct { # my ($text) = @_; # return &evaluate($text); # } sub text2struct { my ($text) = @_; if (substr($text,0,1) ne "{") { # New format return &evaluate($text,"ignore"); } else { return &old_text2struct($text); } } sub old_text2struct { my ($text) = @_; my $res; my $fl=substr($text,0,1); if ($text=~m/^\/'(.*)'$/is) { # SCALAR $res=\&unsafe($1); } elsif ($text=~m/^\[(.*)\]$/is) { # ARRAY my $idx=0; foreach (split(/\s*,\s*/,$1)) { ${$res}[$idx++]=&old_text2struct(unsafe($_)); }; } elsif ($text=~m/^\{(.*)\}$/is) { # HASH foreach (split(/\s*,\s*/,$1)) { if (m/'(.*?)'=>(.*)/is) { my ($var,$val)=($1,$2); ${$res}{&unsafe($var)}=&old_text2struct(unsafe($val)); } }; } elsif ($text=~m/^\\'(.*)'$/is) { # REF $res=\&old_text2struct(unsafe($1)); } elsif ($text=~m/^'(.*)'$/is) { # NOT REF $res=&unsafe($1); }; return $res; }