Gossamer Forum
Home : General : Perl Programming :

How can I parse a tab separated data file and group the extracted data in Perl

Quote Reply
How can I parse a tab separated data file and group the extracted data in Perl
I am newbie to Perl. I need to parse a tab separated text file. For example:

From name To name Timestamp I nteraction
a b Dec 2 06:40:23 IST 2000 comment
c d Dec 1 10:40:23 IST 2001 like
e a Dec 1 16:03:01 IST 2000 follow
b c Dec 2 07:50:29 IST 2002 share
a c Dec 2 08:50:29 IST 2001 comment
c a Dec 11 12:40:23 IST 2008 like
e c Dec 2 07:50:29 IST 2000 like
c b Dec 11 12:40:23 IST 2008 follow
b a Dec 2 08:50:29 IST 2001 share

After parsing I need to create groups base upon users interaction. In this example

a<->b
b<->a
c<->a
a<->c
b<->c
c<->b

for this we can create one group as (a,b,c). and we need to display list of groups. I need some pointers on how to parse the file and form group? Constraint-> at least 3 user required for creating group. Interaction is nothing but some communication is done between two user. It does not matter of which communication

Quote Reply
Re: [avs51386] How can I parse a tab separated data file and group the extracted data in Perl In reply to
Hi,

The "splitting" is easy:

Code:
my $foo = q|a b Dec 2 06:40:23 IST 2000 comment
c d Dec 1 10:40:23 IST 2001 like
e a Dec 1 16:03:01 IST 2000 follow
b c Dec 2 07:50:29 IST 2002 share
a c Dec 2 08:50:29 IST 2001 comment
c a Dec 11 12:40:23 IST 2008 like
e c Dec 2 07:50:29 IST 2000 like
c b Dec 11 12:40:23 IST 2008 follow
b a Dec 2 08:50:29 IST 2001 share |;

foreach (split /\n/, $foo) {
chomp;
my ($first,$second) = split /\t/, $_;
print qq|Got: $first and $second <br />|;|
}

I'm not really sure what you are trying to do after? (it sounds a bit like a school/collage project to me? Wink)

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] How can I parse a tab separated data file and group the extracted data in Perl In reply to
Hi Andy,
yes I agree that it sounds t like a school/collage program or even worse assignment.
I am newbie to perl and just trying my hands on it for first time. I feel writing program (any silly program) is good way to learn new things that why I am wasting my time on this silly problem.
Hope you will absolve me for asking silly question and provides some help to improve my knowledgeSmile

Thanks,
Amit
Quote Reply
Re: [avs51386] How can I parse a tab separated data file and group the extracted data in Perl In reply to
Hi,

You may be better posting on PerlMonks:

http://perlmonks.org/

Afraid I don't really have time to play around and come up with the other code for ya Wink

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Post deleted by avs51386 In reply to