handle tab-delimited file

E

Ela

\t matches BOTH tab and space.

How can I split the following line into 2 words instead of 5?

1234\tI am a boy\n
 
T

Tad J McClellan

Ela said:
\t matches BOTH tab and space.


No it doesn't.

\s matches tab and space (and 3 other characters).

Is that what you meant?

(we wouldn't need to ask this if you had posted real Perl code.)

How can I split the following line into 2 words instead of 5?

1234\tI am a boy\n


use PSI::ESP;

By spliting on \t rather than spliting on \s
 
B

Ben Bullock

\s matches tab and space (and 3 other characters).

Don't forget your Ogham space mark:

#!/usr/bin/perl
use warnings;
use strict;
use Unicode::UCD 'charinfo';
sub count_match
{
my ($re)=@_;
my $c;
for my $n (0x00 .. 0xD7FF, 0xE000 .. 0xFDCF, 0xFDF0.. 0xFFFD) {
if (chr($n) =~ /$re/) {
my $ci = charinfo($n);
print sprintf ('%02X', $n), " which is ", $$ci{name}
, " matches\n";
$c++;
}
}
print "There are $c characters matching \"$re\".\n";
}
count_match('\s');

which gives:

09 which is <control> matches
0A which is <control> matches
0C which is <control> matches
0D which is <control> matches
20 which is SPACE matches
1680 which is OGHAM SPACE MARK matches
180E which is MONGOLIAN VOWEL SEPARATOR matches
2000 which is EN QUAD matches
2001 which is EM QUAD matches
2002 which is EN SPACE matches
2003 which is EM SPACE matches
2004 which is THREE-PER-EM SPACE matches
2005 which is FOUR-PER-EM SPACE matches
2006 which is SIX-PER-EM SPACE matches
2007 which is FIGURE SPACE matches
2008 which is PUNCTUATION SPACE matches
2009 which is THIN SPACE matches
200A which is HAIR SPACE matches
2028 which is LINE SEPARATOR matches
2029 which is PARAGRAPH SEPARATOR matches
202F which is NARROW NO-BREAK SPACE matches
205F which is MEDIUM MATHEMATICAL SPACE matches
3000 which is IDEOGRAPHIC SPACE matches
There are 23 characters matching "\s".
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,189
Latest member
CryptoTaxSoftware

Latest Threads

Top