Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?

Re: selecting columns from a tab-separated-values file

by Tux (Abbot)
on Jan 22, 2013 at 07:37 UTC ( #1014590=note: print w/replies, xml ) Need Help??

in reply to selecting columns from a tab-separated-values file

Nobody suggested Text::CSV_XS yet. If your data is straightforward: no quotations, no embedded tabs or other hiding disasters, it will be slower than a plain split on TAB, but it is very versatile when dealing with the data

use Text::CSV_XS; my $csv = Text::CSV_XS->new ({ binary => 1, sep_char => "\t", auto_d +iag => 1 }); my @row = ("") x 50; $csv->bind_columns (\(@row)); while ($csv->getline ($fh)) { my @capture = @row[0, 2, 5]; }

Enjoy, Have FUN! H.Merijn

Replies are listed 'Best First'.
Re^2: selecting columns from a tab-separated-values file
by ibm1620 (Monk) on Jan 22, 2013 at 22:39 UTC
    Good point; I have used CSV_XS to great advantage before! (However, nothing complicated about this input.)

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1014590]
[ovedpo15]: it isn't homework. its a module I use at work. The process to add additional module isn't worth it. p.s never heard a university course which teach perl
[marto]: there are many, to this day.
[ovedpo15]: @Corion Yes I use the regex you showed me. its very good regex. although now i need to know that substring unit that comma
marto mad corrections to one around 18 months ago
[ovedpo15]: my code checks the value after that comma, if it isn't valid it will remove it. so I would like to remove the substring after that comma meaning getting the string before comma.
[hippo]: Are you sure that Text::CSV_XS isn't already installed at your work? It's such a useful module that it might well be there.
[marto]: pointing out the advantages of cpan modules is well worth in, as both developer and $client/$company benefit greatly
[Tux]: $src =~ m{^(.*),(.*)$/ and $2 !~ $valid and $src = $1;
[Tux]: s,/,},

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (9)
As of 2018-05-27 10:51 GMT
Find Nodes?
    Voting Booth?