Hi,
That looks a bit messy :) I would go more for something like:
# --------------------------------------------------------
# Takes one line of the database as input and returns an
# array of all the values. It replaces special mark up that
# join_encode makes such as replacing the '``' symbol with a
# newline and the '~~' symbol with a database delimeter.
my ($input) = shift;
$input =~ s/\:/__DELIM__/g; # Add a space if we have delimiter new line.
my @array = split /\:/g, $input;
foreach (@array) {
s/__DELIM__/:/g; # Convert __DELIM__ back into :
s/~~/:/g; # Retrieve Delimiter..
s/``/\n/g; # Change '' back to newlines..
s/&/&/g; # encode ampersand 02/01/2017
}
return @array;
}
If $db_delim won't ever change, you may as well just hard-code it (to make things simpler). I guess it had $db_delim as it was copied from original code where this needed to be flexible.
All my new code does is convert : into __DELIM__, and then convert it back once we have done the split.
Hope that helps
Cheers
Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
That looks a bit messy :) I would go more for something like:
Code:
sub split_decode { # --------------------------------------------------------
# Takes one line of the database as input and returns an
# array of all the values. It replaces special mark up that
# join_encode makes such as replacing the '``' symbol with a
# newline and the '~~' symbol with a database delimeter.
my ($input) = shift;
$input =~ s/\:/__DELIM__/g; # Add a space if we have delimiter new line.
my @array = split /\:/g, $input;
foreach (@array) {
s/__DELIM__/:/g; # Convert __DELIM__ back into :
s/~~/:/g; # Retrieve Delimiter..
s/``/\n/g; # Change '' back to newlines..
s/&/&/g; # encode ampersand 02/01/2017
}
return @array;
}
If $db_delim won't ever change, you may as well just hard-code it (to make things simpler). I guess it had $db_delim as it was copied from original code where this needed to be flexible.
All my new code does is convert : into __DELIM__, and then convert it back once we have done the split.
Hope that helps
Cheers
Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!