in reply to WHAT IS WRONG TO PASS PARAMETER TO THE ARRAY?

Are you trying to do

push @partofcookie, $incomingdata;

Your code is unreadable and it's not runnable.

Replies are listed 'Best First'.
Re^2: WHAT IS WRONG TO PASS PARAMETER TO THE ARRAY?
by Anonymous Monk on Aug 05, 2009 at 23:59 UTC
    hi monks. yes. uncomment line 5 means overwrite line 4's code. acttly line 5's code what i needed. i need it to pass in the new value. line4's code is only for testing only.

    the pamameter passed into @incomedata is a dynamic data from a loop out side of the sub. i have tested. that data has been passed into $incomedat sucessfully.

    but when i try to enable line 5. that mean i try to using the data from $incomedata. i get a blank screen. while the data of line 4 and line5 are virtually the same structure.

      courierb, may I just make a few things clear?

      Thank you. I realize you are new here, so I'll try to be gentle. First, this is an online *community*. Like a real-life community, it has a social structure, with social rules. Break those rules and you can expect... well, nothing good.

      In your post you've broken several of those rules, and many of us find this annoying.

      Let me make a few requests. If you want to be a part of this particular community, you will have to abide by The Rules. I'm sorry, there is no other way.

      • Don't write in all capitals. Ever. It's hard to read, and it's very distracting.
      • Please try to ask *clearly* for what you want. I suspect you are not a native speaker of English, so most of us will try to give some grace and allow for that
      • Also, it appears you (courierb) switch to posting anonymously part-way through your own thread. This makes it hard to follow for others - who is saying what?

      That said, thank you for posting your code. That is the single most helpful thing one can do when asking for help around here. :)

        sorry Monk. i will follow your rules here. forgive me as i really not familar here. . sorry again. i will carefully read your advice and suggestion again.
      i have tested. that data has been passed into $incomedat sucessfully.

      So what exactly does it contain? You still haven't shown the output of

      use Data::Dumper; print Dumper $incomingdata;

      If it's something like

      $VAR1 = [ { 'quantity' => 1, 'name' => 'abc1' }, { 'quantity' => 2, 'name' => 'abc2' } ];

      you probably want line 5 to read

      my @partofcookie= @$incomingdata;
        Dear almut. yes you are right.

        i just try to pass $incomedata in to the sub.
        which is part of cookie .
        and i save it as a sting in mysql db.
        but i know it looks like below without square brackets
        $VAR1 = { 'quantity' => 1, 'name' => 'abc1' }, { 'quantity' => 2, 'name' => 'abc2' }

        should i format it to

        $VAR1 = [ { 'quantity' => 1, 'name' => 'abc1' }, { 'quantity' => 2, 'name' => 'abc2' } ];

        is it a string format?
        sorry for my silly queestion .
        is it ok to pass a string to the sub ? the scirpt is taken partially from sample code of cgi::session cookbook
        http://search.cpan.org/~sherzodr/CGI-Session-3.94/Session/CookBook.pm

        sub display_cart { my ($cgi, $session) = @_; # getting the cart's contents my $cart = $session->param("CART") || []; my $total_price = 0; my $RV = q~<table><tr><th>Title</th><th>Price</th></tr>~; if ( $cart ) { for my $product ( @{$cart} ) { $total_price += $product->{price}; $RV = qq~ <tr> <td>$product->{name}</td> <td>$product->{price}</td> </tr>~; }
        .............the rest of code has been omitted from here

        i will give it a try after right after my pc is back to normal according your advice.

        thank you very much

        Dear sir
        in regards to use Data::Dumper; print Dumper $incomingdata; I really do not know how to put it in as the core code of the main pro +gramme is too difficult for me..... but i have test it in this way sub { # # splits them up into stuff like "{name => 'name222',colour => 'yellow +'}" #my @split = (split /\Q},{/, $_[0]); #my $value = $split[0]; my $value = $_[0]; return($value); } then i use a template tag to print its data out it looks exactly the same as it shored in db [{'quantity' => 1,'name' => 'abc1' }, {'quantity' => 2, 'name' => 'abc2'}]