Click here to get back home

handle tab-delimited file

 HomeNewsGroups | Search | About
 comp.lang.perl.misc    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
handle tab-delimited file Ela 03-14-2008
Posted by Ela on March 14, 2008, 8:57 pm
Please log in for more thread options
\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



Posted by Gunnar Hjalmarsson on March 14, 2008, 9:22 pm
Please log in for more thread options
Ela wrote:
> \t matches BOTH tab and space.

No, it doesn't.

> How can I split the following line into 2 words instead of 5?
>
> 1234\tI am a boy\n

split /\t/, "1234\tI am a boy\n"

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl

Posted by Tad J McClellan on March 15, 2008, 10:10 am
Please log in for more thread options

> \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


--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher0cmdat/"

Posted by Ben Bullock on March 16, 2008, 12:00 am
Please log in for more thread options
On Sat, 15 Mar 2008 14:10:12 +0000, Tad J McClellan wrote:

> \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
                , " 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".

Similar ThreadsPosted
syswrite "Bad file descriptor" after successfully writing to that file handle January 7, 2008, 10:31 am
file handle problem December 4, 2004, 7:29 pm
file handle problem December 4, 2004, 10:42 pm
File Handle Problem September 9, 2006, 2:42 pm
How to decoding a file handle? April 10, 2007, 1:02 am
Print on closed file handle September 28, 2005, 4:08 pm
file handle and variable issues... November 13, 2005, 7:04 am
Way to return a file handle from a XSUB? June 2, 2006, 1:37 am
String buffer instead of file handle? September 13, 2006, 1:36 pm
Have sub routine handle file OR array? December 15, 2007, 10:49 am

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap