in reply to Re: Alternative values from array and print
in thread Alternative values from array and print

The data is stored in the way as in @data_list. How to convert to hash only for key correct and date. When I print print " $correction : $date\n"; Only first pair of value is printed
  • Comment on Re^2: Alternative values from array and print

Replies are listed 'Best First'.
Re^3: Alternative values from array and print
by moritz (Cardinal) on Jul 16, 2009 at 07:59 UTC
    By iterating over your current data structure and building the desired one. Read the tutorials I pointed you to, they really help.
    Only first pair of value is printed

    Right, that's how I understood your requirements. If that's not what you want, you might try to formulate a bit clearer what you want.

      use strict; use warnings; use List::Util qw(first); my %data = ( date => ['2009-01-01', '2009-01-02', ''], correct => ['Article_text1', 'Article_text2'], ); print @{$data{correct}}; print @{$data{date}};
      This prints out the result.
      Article_text1 Article_text2 2009-01-01 2009-01-02
      But the output should be something like below. The values should be printed in alternative way.
      2009-01-01 Article_text2 2009-01-02

        I don't see the pattern - why do you want only one Article_text to be printed, but two dates?

        Or was that an error on you side, and you want all of them, interleaved? If yes, you can either use List::MoreUtils::natatime, or you can simply iterate over the indexes and extract the items by index, in parallel.

        Attention to details is important for a programmer - if you give us wrong example output, we can't give you right answers. If the rules to obtain the sample output are not obvious, you have to explain them verbally.

        Seriously, try things out yourself. Read the documentation. Read other code that works with data structures, the monastery is full of it.

        Read other questions, and ask yourself if you actually understood what the other monks wanted. Ask yourself if you would understand your own questions if you were somebody else, and didn't know it already.