courierb has asked for the wisdom of the Perl Monks concerning the following question:
########################################sub { ### this sub works well. # splits them up into stuff like "{name => 'name222',colour => 'yellow +'}" my @split = (split /\Q},{/, $_[0]); my @loop; foreach (@split) { s/^{//; s/}$//; my $hash; my $hash1; my @tmp = split /,/, $_; # now lets split them at ', my @subloop; foreach my $tmp (@tmp) { my $hash; my ($name,$value) = split / => /, $tmp; $hash->{name} = $name; $hash->{value} = $value; $hash->{value} =~ s/^\'//; $hash->{value} =~ s/\'$//; push @subloop, $hash; } #$hash1->{name} = "subtotal"; #$hash1->{value} = "999"; #push(@subloop, $hash1); push @loop, { subloop => \@subloop }; } return { split_loop => \@loop }; }
sub { my ($cgi, $session,$product,$tags,$itemmaxtemp,$itemID, $incomingdata) +; #my @incomingdata = @_ ; #my @incomingdata = $_[0]; #my @incomingdata = (@_); #my @incomingdata = $_; my $incomingdata = split /\Q},{/, $_[0];
###########################my @partofcookie= ({name => 'ddd111',quantity => 11,price => '11',col +our => '11red',size => '11xxl',itemID => '1111tiem'},{quantity => '2' +,name => '222gmailoknow',price => '228',itemID => '222item'}); foreach my $product ( @partofcookie ) { ##### $product->{prod_subtotal} = $product->{price} * $product->{quantity}; $tags->{total_price} += $product->{prod_subtotal}; $tags->{itemmaxtemp}=$itemmaxtemp; $tags->{itemID}=$itemID; push @{$tags->{cart_loop}}, $product; } my @xxx; @xxx = @{$tags->{cart_loop}}; return { orderdetail_loop => \@xxx}; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: passing string to sub and string split
by Marshall (Canon) on Aug 02, 2009 at 07:56 UTC | |
by BioLion (Curate) on Aug 02, 2009 at 10:33 UTC | |
by Marshall (Canon) on Aug 02, 2009 at 14:36 UTC | |
by BioLion (Curate) on Aug 02, 2009 at 10:32 UTC | |
|
Re: passing string to sub and string split
by ig (Vicar) on Aug 02, 2009 at 19:02 UTC |