Gossamer Forum
Quote Reply
Global with arrays
I have a field "Prices"; there i save something like:

1|300,1.5|450,2|600

Now i want to split it with

@a = split(/,/,$t->{Prices});

I should have now something like:

$a[0] = 1|300
$a[1] = 1.5|450
$a[2] = 2|600

Now i walk tru with:

while (my ($key, $value) = each @a) {
@b = split(/\|/,$value);
}

Now i should have:

$a[1] = 300
$a[1.5] = 450
$a[2] = 600

again i want to walk tru:

while (my ($key, $value) = each @b) {
$output .= "For $key pieces you pay $value Dollar";
}

I got:

Unable to compile 'Rates': Type of arg 1 to each must be hash (not private array) at (eval 117) line 8, near "@a) " Type of arg 1 to each must be hash (not private array) at (eval 117) line 12, near "@b) "

and i have no idea what i should do now.
Quote Reply
Re: [Robert] Global with arrays In reply to
Hi,

Is there any reason you are doing it such a complicated way? :)

Try:
Code:
sub {

my $output;
foreach (split(/,/,$t->{Prices})) {
my @tmp = split /\|/, $_;
$output .= "For $tmp[0] pieces you pay $tmp[1] Dollar";
}

return $output;

}

(you don't show where $t comes from, so you will need to add that line in at the beginning)

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!
Quote Reply
Re: [Andy] Global with arrays In reply to
Thank you very much, Andy.

Last edited by:

Robert: Sep 1, 2016, 1:52 PM