i have a

workiing script shows below(the first sub below)

. basically it handling strings passed in subroutine and make a loop which shows below. ( it is working sciprt) the string passed in is an array or sting. {name => 'name222',colour => 'yellow'} or {name => 'name222',colour => 'yellow'},{name => 'name333',colour => 'yellow333'}
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 }; }
########################################
since its output is not so easy to be formated into a desired layout.

i try to rewrite it based on first subroutine's concpets.

here is my one. but it doese not work. i suspect it is not passed the scalar value properly to the sub or it is not split it well as when i replace it with directly. it produce a result as i expected. I have already stuck on this issue for long time . could any senoir could solve the problem or light me up for this problem?
sub { my ($cgi, $session,$product,$tags,$itemmaxtemp,$itemID, $incomingdata) +; #my @incomingdata = @_ ; #my @incomingdata = $_[0]; #my @incomingdata = (@_); #my @incomingdata = $_; my $incomingdata = split /\Q},{/, $_[0];


# i have tried all above possibility and all failed.
# have been returned a blank page.
# when i filling @partofcookie directly with
#({name => 'ddd111',quantity => 11,price => '11',colour => '11red',size => '11xxl',itemID => '1111tiem'},{quantity => '2',name => '222gmailoknow',price => '228',itemID => '222item'});
# it works well. while once i replace
#@partofcookie with the value of @incomingdata , i will be
return a blank screen. whywhy?
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}; }
###########################
i believe the possible reason is i wrongly understand what is passing in the sub? so i did not split it out correctly? could
could any one help me a bit?

Many thanks in advance












In reply to passing string to sub and string split by courierb

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.