in reply to Alternative values from array and print

Using a proper hash greatly simplifies this task (as you have been told many times already).
use strict; use warnings; use List::Util qw(first); my %data = ( date => ['', '2009-01-01', '2009-01-02', ''], correct => ['Article_text1', 'Article_text2'], ); my $correction = first { length($_) } @{$data{correct}}; my $date = first { length($_) } @{$data{date}};

Please read perldsc and perlreftut which both explain data structures in Perl very nicely.

(Update: change link from perlref to perlreftut, which is more introductory).

Replies are listed 'Best First'.
Re^2: Alternative values from array and print
by gem555 (Acolyte) on Jul 16, 2009 at 07:27 UTC
    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
      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
Re^2: Alternative values from array and print
by gem555 (Acolyte) on Jul 16, 2009 at 07:23 UTC
    The data is stored in the way as in @data_list. How to convert to hash only for key correct and date.