Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'A set of scripts to translate iChat acronyms' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
A set of scripts to translate iChat acronyms
Authored by: galaher on Sep 02, '04 04:59:48PM

I've updated the perl script to use a single hash which is much easier to update and maintain. Thanks for everyone's comments. Here's what should be a better version:



[code]
#!/usr/bin/perl -w
use strict;

my $out = "";
my ($im_acronym) = &define_translation_hashes();
my %im_acronym = %{$im_acronym};


my $string = $ARGV[0];
$string = " " . $string;
my @string = ();


#################################################################

@string = &split_on_white($string);

&translate(\@string);

for(@string){
if($_ =~ m/^[.?!,]$/m){
$out .= "$_";
}
else{

$out .= " $_";

}

}

my $SCRIPT =<<EOS;
tell application "iChat"
activate
display dialog "$out" buttons {"OK"} default button "OK"
end tell
EOS

open (FH, "|/usr/bin/osascript");
print FH $SCRIPT;
close FH;

exit;

#################################################################

sub split_on_white(){
my $string = shift @_;

#all white space to single spaces
$string =~ s![ \t\r]+! !mig;
$string =~ s/([.,!?])/ $1/mig;
my @string = split (/ /, $string);

}

sub translate(){
my $string = shift @_;
for(@{$string}){

my $cur_string = $_;

#Check each for match to %im_acronym
foreach my $key(sort keys %im_acronym){
if($key =~ m#^\Q${cur_string}\E$#im){

$_ = $im_acronym{$key};

}
}

}

}

#alt untested force upper case comparision to make case insensitive.
#print $translate{uc $_} if ($translate{uc $_};


#################################################################

sub define_translation_hashes(){

my %im_acronym = (

#BUILD YOUR DICTIONARY HERE:
"BTW" => "by the way",
"HTH" => "hope that helps",
"IMHO" => "in my humble opinion",

);

my $im_acronym = \%im_acronym;

return ($im_acronym);
}


#################################################################

__END__
[/code]



[ Reply to This | # ]