Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re^3: Separate column results?!

by perlnoobster (Sexton)
on Aug 29, 2012 at 09:33 UTC ( #990417=note: print w/replies, xml ) Need Help??


in reply to Re^2: Separate column results?!
in thread Separate column results?!

update: I've changed it to the following:
print "\n$columns[0]\t$columns[1]";
works fine now :) however there is a blank space between the lines the chomp function doesn't seem to work?
#!/usr/bin/perl use warnings; use strict; my $PHONE_FILE = 'phones.txt'; open(PHONE_FILE, $PHONE_FILE) or die "Can't open file: $!\n"; my @lines = <PHONE_FILE>; foreach $_ (@lines) { my @columns = split('\t', $_); my $col1 = $columns[0]; my $col2 = $columns[1]; chomp $col1; chomp $col2; print "\n$columns[0]\t$columns[1]"; }
??

Replies are listed 'Best First'.
Re^4: Separate column results?!
by perlnoobster (Sexton) on Aug 29, 2012 at 09:36 UTC
    i got it to work :)
    foreach $_ (@lines) { my @columns = split('\t', $_); chomp @columns; my $col1 = $columns[0]; my $col2 = $columns[1]; chomp $col1; chomp $col2; print "\n$columns[0]\t$columns[1]"; }

      Or perhaps:

      use feature ":5.14"; use warnings FATAL => qw(all); use strict; my @lines = split /\n/, << 'END'; 111 aaa bbb 222 ccc ddd 333 eee fff END say join "\t", @{[split]}[0,1] for @lines;

      Produces:

      111	aaa
      222	ccc
      333	eee
      

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://990417]
help
Chatterbox?
[sierpinski]: I've never seen $#$var before.
[LanX]: $list cops be an array ref
[LanX]: could
[LanX]: $#array gives the length
[LanX]: no sorry ...
[sierpinski]: so that would just be deferencing it...
[LanX]: the last index!
[LanX]: yes
[sierpinski]: yeah I guess $list is a reference.. yeah
[sierpinski]: why is it the last index and not the first? because the length of the array becomes the index?

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (13)
As of 2017-12-13 16:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What programming language do you hate the most?




















    Results (369 votes). Check out past polls.

    Notices?