Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

Re: need help to print some lines

by toolic (Bishop)
on Nov 28, 2012 at 18:10 UTC ( #1006084=note: print w/replies, xml ) Need Help??

in reply to need help to print some lines

One way is to store the 2nd column in an array as you read the lines:
use warnings; use strict; my @c2; while (<DATA>) { my @cols = split; push @c2, $cols[1]; print "$cols[0]\n"; } print "$_\n" for @c2; __DATA__ a f b g c h d i e j

Replies are listed 'Best First'.
Re^2: need help to print some lines
by Anonymous Monk on Nov 29, 2012 at 00:41 UTC

    without taking anything away from toolic beautiful solution, one can also still write this:

    use warnings; use strict; my $array_organizer = [ [], [] ]; while (<DATA>) { push @{ $array_organizer->[0] }, [split]->[0]; push @{ $array_organizer->[1] }, [split]->[1]; } for my $value ( @{$array_organizer} ) { print map { $_ } @{$value}, $/; } __DATA__ a f b g c h d i e j

      Instead of repeating push function, why not:

      ... while (<DATA>) { for my $index ( 0 .. 1 ) { push @{ $array_organizer->[$index] }, [split]->[$index]; } } ...

      If you tell me, I'll forget.
      If you show me, I'll remember.
      if you involve me, I'll understand.
      --- Author unknown to me

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1006084]
Discipulus never noticed there was subtitles... can I call them with &subtitle or is too much perl 4?
[LanX]: YT=youtube
[Discipulus]: ;=) yes i'm not SO dumb
[LanX]: SO=StackOverflow
[Discipulus]: :=(
[perldigious]: I watched some video on YT awhile back with auto-subtitle on and the speaker had a very thick cockney sort of English accent... hillarity ensued in the subtitles.
[Discipulus]: IHAA=I hate acronyms anyway

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (8)
As of 2017-06-23 16:39 GMT
Find Nodes?
    Voting Booth?
    How many monitors do you use while coding?

    Results (552 votes). Check out past polls.