Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Instant message parser.

by damian1301 (Curate)
on Jun 26, 2001 at 00:35 UTC ( #91423=sourcecode: print w/ replies, xml ) Need Help??

Category: Miscellaneous
Author/Contact Info Instant messaging: damian1301. email: drus3113@cs.com. /msg me as well
Description: This is just a short script I wrote to parse instant messages from AIM, AOL, CS, and Yahoo!. It basically just reads through a conversation file or you can paste the conversation directly in the script, and it will give you info on how many messages were sent by each person, the word count, and the letter count. A couple of friends found it pretty neat and I like it. As always I am open to all criticism but remember, I didn't try to make everything all complex on this; just a simple script. The output of the script is like so (example):
1056 words total, 6045 total characters Damian1301 has 175 IMs sent while Other_name has 154 IMs sent. There w +ere 329 IMs total
#!/usr/bin/perl -w
use strict;
my $use_file = "no"; # yes or no
my $file = "convo.txt"; # the file to open if $use_file = 1
my $i=0;
my $j=0;
my $n = 0;
my $n2=0;
my @i;

get();
my $name2;
sub parse{
    my @i = @_;
    if(@i){
        my $name = $i[0];
        $name =~ s/^(.*?):\s+.*/$1/;
        my @words;
        foreach(@i){
            s/^(.*?):\s+(.*)/$1/;
            push @words,$2;
            if($name eq $_){
                $n++;
            }else{        
                $name2 = $_;
                $n2++;
            }
        }
        foreach(@words){
            $i++ foreach split/ /;
            $j++ foreach split//;
        }
        print "$i words total, $j total characters\n",
            "$name has $n IMs sent while $name2 has $n2 IMs sent. Ther
+e were ", $n + $n2," IMs total";
    }else{
        print "YOU NEED TO PUT STUFF IN $file OR PUT IT BETWEEN THE PI
+PES |BLAH|";
    }
}                        
sub get{
    if($use_file eq "yes"){
        if(-e $file){
            open(FH,$file) || die "$!";
                @i = <FH>;
            close FH;
        }else{
            open(FH,">$file") && die "The conversation file has been c
+reated.\n
             Paste your conversation in $file and run the program agai
+n.";
            close (FH);
        }
    }else{
        @i=split/\n/,qq|hey: yo\nyo: hey|; #paste the convo between th
+e pipes |convo here| make sure that it isn't
        # like |
        # convo here
        # |
    }
    
    parse(@i);         
}

Comment on Instant message parser.
Download Code

Back to Code Catacombs

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: sourcecode [id://91423]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (8)
As of 2014-08-29 06:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (275 votes), past polls