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: Chris Biagini on Aug 13, '04 11:38:02AM

I was.

Just thought that using a single hash would make additions a little easier.



[ Reply to This | # ]
A set of scripts to translate iChat acronyms
Authored by: galaher on Aug 13, '04 03:10:12PM

I initially had one hash as you suggest, but found that acronyms in my 'dictionary' often had characters that were illegal in the name of a key. e.g. im_acronym11 => "24/7", or im_acronym1 => "::POOF::". I couldn't have 24/7 => "24 hours a day, 7 days a week", so I went with two hashes. Since I scraped my acronyms off the web, it was easier to accommodate those things than try and manually clean up and edit it.



[ Reply to This | # ]
A set of scripts to translate iChat acronyms
Authored by: gancho on Aug 13, '04 10:04:06PM

Any string can be the key of a hash, including "24/7". You just need to quote the key, because smart quotes (=>) only quote what's on the left side if it's a set of word characters.



[ Reply to This | # ]
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 | # ]