AtomicSoft.com Add power to your website!
Home Products Services Support Free
EasyData/SQL
easy-to-use web interface for SQL databases with countless features
AtomicDesk
help desk, FAQ, knowledge base, live support chat - all in one product
Custom programming
Installation
Documentation
HelpDesk
Libraries
Join our newsletter for information on software updates and new releases. You may unsubscribe at any time.



Click here to download plain text source code.

# 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;
}
 
Copyright © 1999-2007 Atomicsoft Ltd. All Rights Reserved.