Gossamer Forum
Home : General : Perl Programming :

Re: [delicia] problem with colon as delimiter

Quote Reply
Re: [delicia] problem with colon as delimiter In reply to
Hi,

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!
Subject Author Views Date
Thread; hot thread problem with colon as delimiter delicia 9945 May 7, 2020, 1:33 PM
Post; hot thread Re: [delicia] problem with colon as delimiter
delicia 9785 May 7, 2020, 1:36 PM
Thread; hot thread Re: [delicia] problem with colon as delimiter
Andy 9781 May 7, 2020, 11:33 PM
Thread; hot thread Re: [Andy] problem with colon as delimiter
delicia 9779 May 8, 2020, 5:43 AM
Thread; hot thread Re: [delicia] problem with colon as delimiter
Andy 9769 May 8, 2020, 5:52 AM
Thread; hot thread Re: [Andy] problem with colon as delimiter
delicia 9770 May 8, 2020, 5:59 AM
Thread; hot thread Re: [delicia] problem with colon as delimiter
delicia 9765 May 8, 2020, 6:10 AM
Post; hot thread Re: [delicia] problem with colon as delimiter
Andy 9758 May 8, 2020, 6:18 AM
Thread; hot thread Re: [delicia] problem with colon as delimiter
Andy 9754 May 8, 2020, 6:45 AM
Post; hot thread Re: [Andy] problem with colon as delimiter
delicia 9746 May 8, 2020, 7:05 AM
Thread; hot thread Re: [delicia] problem with colon as delimiter
Andy 9750 May 8, 2020, 6:48 AM
Thread; hot thread Re: [Andy] problem with colon as delimiter
delicia 9746 May 8, 2020, 7:06 AM
Thread; hot thread Re: [delicia] problem with colon as delimiter
Andy 9739 May 8, 2020, 7:27 AM
Thread; hot thread Re: [Andy] problem with colon as delimiter
delicia 9737 May 8, 2020, 7:34 AM
Post; hot thread Re: [delicia] problem with colon as delimiter
Andy 9707 May 8, 2020, 10:49 PM