taj_ritesh has asked for the wisdom of the Perl Monks concerning the following question:

This node falls below the community's threshold of quality. You may see it by logging in.

Replies are listed 'Best First'.
Re: How to get the column from lines
by Corion (Patriarch) on Apr 14, 2014 at 11:44 UTC

    What is this line supposed to do?

    my @table = push (split ( / /, @lines) );

    If you use warnings, Perl will tell you that this line makes little sense:

    Useless use of push with no values at -e line 1.

    Maybe you can explain what error message you get and how you have tried to address the error message?

Re: How to get the column from lines
by Lennotoecom (Pilgrim) on Apr 14, 2014 at 12:30 UTC
    @a = ( 'a b c d e', 'f g h i j', 'k l m n o', 'p q r s t', 'u v w x y' ); @b = map (join(' ', (split /\s/)[1, 4]), @a); print "$_\n" for @b;
    output
    b e g j l o q t v y
Re: How to get the column from lines
by GotToBTru (Prior) on Apr 14, 2014 at 16:11 UTC

    Firstly, it would be very helpful to see an example of the data. Secondly, zero-based indexing trips up a lot of people. (split / /)[2,5] will give you the 3rd and 6th columns of your data.

      Best guess is that this is an example of the data.

Re: How to get the column from lines
by Laurent_R (Canon) on Apr 14, 2014 at 16:01 UTC
    If you need to store the data in a new array (I'll assume an array of arrays), you could do this (reusing the data kindly provided by Lennotoecom):
    my @table = ('a b c d e', 'f g h i j', 'k l m n o', 'p q r s t', 'u +v w x y'); my @table2 = map { [(split / /, $_)[1, 4]] } @table;
    The @table2 array now looks like this:
    0 ARRAY(0x803cc6d8) 0 ARRAY(0x8042f630) 0 'b' 1 'e' 1 ARRAY(0x8042f828) 0 'g' 1 'j' 2 ARRAY(0x8042f840) 0 'l' 1 'o' 3 ARRAY(0x8042f540) 0 'q' 1 't' 4 ARRAY(0x8042f870) 0 'v' 1 'y'
    If you want an array of lines, changing the second line to:
    my @table2 = map { join " ", (split / /, $_)[1, 4] } @table;
    And the resulting array is now:
    0 'b e' 1 'g j' 2 'l o' 3 'q t' 4 'v y'
    Edit: I did not look at it very carefully at the time, but I see now that the second solution I suggested just above is almost the same as the one suggested by Lennotoecom. Sorry for repeating almost the same thing, although this was not intentional.