#!/usr/bin/perl # # garble.pl # # Uses Babelfish to mangle text. Useless but fun :-) # # Usage: # perl garble.pl <options> # # Options: # Options marked with a * are required # # -i <filename> - Loads a file to mangle* # -o <filename> - File to write mangled text to* # -s <language> - Singlepass mode, with the specified language # -b <language> - Base language. English by default. # -m <language>,... - Multipass mode. Any number of languages # seperated by commas. Default is # -m French,Spanish # -t <language> - Translates one language to another # use Getopt::Std; use WWW::Babelfish; # #=================[ Support Subs ]==================================== # sub DoTranslation { my($in_text,$language_1,$language_2)=@_; my $obj = new WWW::Babelfish( 'agent' => 'GarbleText/1.0' ); die( "Babelfish server unavailable\n" ) unless defined($obj); my $altered = $obj->translate( 'source' => "$language_1", 'destination' => "$language_2", 'text' => "$in_text"); die("Could not translate: " . $obj->error) unless defined($alter +ed); return $altered; } sub PrintBanner { print "\n=========\n"; print "garble.pl\n"; print "=========\n\n"; print "(c)Copyleft #include 2003\n\n"; } # #=================[ Main ]============================================ # my $default_language="English"; my $multipass_mode=1; my $singlepass_mode=0; my @mpass=("French","Spanish"); my $singlepass_lang="English"; getopt('iosbmt'); if( ($opt_i) && ($opt_o) ) # Everything we need { PrintBanner(); if($opt_s) { $singlepass_mode=1; $multipass_mode=0; $singlepass_lang=$opt_s; } if($opt_t) { $singlepass_mode=0; $multipass_mode=0; } if($opt_m) { @mpass=split(',',$opt_m); } if($opt_b) { $default_language=$opt_b; } } else { PrintBanner(); print "Usage:\n"; print "perl garble.pl <options>\n\n"; print "Options:\n"; print "Options marked with a * are required\n\n"; print "-i <filename> - Loads a file to mangle*\n"; print "-o <filename> - File to write mangled text to*\n"; print "-s <language> - Singlepass mode, with the specified +language\n"; print "-b <language> - Base language. English by default.\ +n"; print "-m <language>,... - Multipass mode. Any number of langu +ages\n"; print " seperated by commas. Default is\n"; print " -m French,Spanish\n"; print "-t <language> - Translates one language to another\n +\n"; exit; } # Everything's in place, let the mangling begin! # Load in the text print "Reading $opt_i..."; open(TEXTFILE,"<$opt_i"); my @tfile=<TEXTFILE>; my $tt = join('',@tfile); close TEXTFILE; print "done!\n"; my $at; my $mangled_text; if($opt_t) { # Simple translation mode print "Simple Translation Mode\n"; print "Language: $opt_t\n"; $at=DoTranslation($tt,$default_language,$opt_t); $mangled_text=$at; } # Singlepass mode first if($singlepass_mode==1) { print "Singlepass Mode\n"; print "Language: $singlepass_lang\n"; print "Translating $default_language to $singlepass_lang...\n"; $at=DoTranslation($tt,$default_language,$singlepass_lang); print "Translating $singlepass_lang to $default_language...\n"; $tt=DoTranslation($at,$singlepass_lang,$default_language); $mangled_text=$tt; } if($multipass_mode==1) { print "Multipass Mode\n"; print "Passes: ".($#mpass +1)."\n"; foreach $lang (@mpass) { print "Translating $default_language to $lang...\n"; $at=DoTranslation($tt,$default_language,$lang); print "Translating $lang to $default_language...\n"; $tt=DoTranslation($at,$lang,$default_language); } $mangled_text=$tt; } # Now that we've got the mangled text, let's print it print "Writing $opt_o..."; open(DUMPTEXT,">$opt_o"); print DUMPTEXT "$mangled_text\n"; close DUMPTEXT; print "done!\n";

In reply to Babelfish Text Mangler by #include

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.