When boring is arround, and you can't sleep ... perl programming could be a great remedy (headache will come, and surely you can go to sleep ... of course you must try to code a one-liner-obfuscated-perl-snippet-chunk) ...

I'm not sure this is the more chaotic code (surely not), nor the last of the year not the most useless, but is a good title, isn't it? ;) ... Though, good intentions are good intentions, and here are my best wishes for all the monks for this new year 2006.

The code:
cat oration |perl -ne '(our $line.=join("",("\n"," "x15,$`)),next) if +/\\$/; ($_=($line.=join("",("\n"," "x15,$_))),undef $line) if defined + $line; print "Monk\x{27}s Pope: ",$_,((length) < 64?scalar(undef $ +skip,"Fellow Monks: "):scalar(our $skip=1,"")); %myself=(i,me,me,i,w +e,us,us,we); sub i{my $final; ($_=shift)=~s/_//g; print ((join " ",(r +everse map { $myself{$_}?$myself{$_} : ((m/^(\S+).*/, exists $myself{ +$1})? scalar((($final=$_)=~s/^(\S+)\s+//, $myself{$1})) : $_)} @_)), +(substr($_[0],-1,1) eq q|s|? "\b" : ""),(substr($_[1],-1,1) eq q|s|)? + q|| : q|s|," ",$myself{$_}?$myself{$_} : $_," $final\n") }; s/(\S+)\ +s+(\S+)\s+(.*)/$1 _$1_, $2, "$3"/; *$1=\&i if ($1); %dicc=(map { (@{$ +_},reverse @{$_}) } ([guide,follow],[love,love])); $pattern=join "|", + keys %dicc; s/($pattern)/$dicc{$1}/; $text=$_; map { (eval $text, go +to END) if $text=~m/$_/ } keys %dicc; print "Amen\n" unless defined $ +skip; END:'

The text which i feed to the code:
# cat new_year Welcome Brothers in Arms Here's to the bright New Year, \ and a fond farewell to the old; \ here's to the things that are yet to come, \ and to the memories that we hold Happy New Year!!

And the result:
Monk's Pope: Welcome Brothers in Arms Fellow Monks: Amen Monk's Pope: Here's to the bright New Year, and a fond farewell to the old; here's to the things that are yet to come, and to the memories that we hold Monk's Pope: Happy New Year!! Fellow Monks: Amen

The history of this foolish and useless code.

When I've begined to write this /(ch|j)unk/ of code, my aim was to do something cool, for my own amusement (then i was reading the greatest 'Programming Perl' book (i have not finished it yet), and i was enthusiasmed for having solved some problems in a fast and good looking way):
echo 'i love perl' | perl -ne 's/(\S+)\s(\S+)\s(\S+)/... and $3 $2s yo +u .../; print'
But that was not exactly what i wanted, and i continuing writing and rewriting:
perl -e 'sub i; i love, perl; sub i { print "... and ", ((join " ",(re +verse @_)),substr($_[1],-1,2) eq q|s|? q|| : q|s| ," you ...\n") }'
This was i wanted to do, a function called 'i', which functions in list mode, so i can pass the parameters without any parenthesis. It was simple, and it remmebered me the elisa or the doctor emacs (i suppose this is one of the strange thing that emacs has, and vi not; though who really cares?) ... so i started to write the code necessary to treat littel phrases without having any diccionary.
echo perl loves all of us | perl -ne '%myself=(i,me,me,i,we,us,us,we) +; sub i{($_=shift)=~s/_//g; print ((join " ",(reverse map { $myself{$ +_}?$myself{$_} : $_} @_)),(substr($_[0],-1,1) eq q|s|? "\b" : ""),(s +ubstr($_[1],-1,1) eq q|s|)? q|| : q|s|," ",$myself{$_}?$myself{$_} : +$_,"\n") }; s/(\S+)\s+(\S+)\s+(.*)/$1 _$1_, $2, "$3"/; *$1=\&i if ($1 +); eval;'
But it stills don't like me, so i continuing writing and rewriting ...
cat reciprocity | perl -ne '%myself=(i,me,me,i,we,us,us,we); sub i{my + $final; ($_=shift)=~s/_//g; print ((join " ",(reverse map { $myself{ +$_}?$myself{$_} : ((m/^(\S+).*/, exists $myself{$1})? scalar((($final +=$_)=~s/^(\S+)\s+//, $myself{$1})) : $_)} @_)),(substr($_[0],-1,1) e +q q|s|? "\b" : ""),(substr($_[1],-1,1) eq q|s|)? q|| : q|s|," ",$myse +lf{$_}?$myself{$_} : $_," $final\n") }; s/(\S+)\s+(\S+)\s+(.*)/$1 _$1 +_, $2, "$3"/; *$1=\&i if ($1); %dicc=(map { (@{$_},reverse @{$_}) } ( +[guide,follow],[jump,unjump])); s/(guide|follow)/$dicc{$1}/;eval;'

Then i started to think (i was very tired, and too close to have a good dream even over my keyboard), of writing some code for invert any phrase, but when i started to think the method for distinghish between verbs, nouns, adverbs, adjetives, subjects, etc; my headache started ... then i've remembered some old language classes ... some minutes later, boom, i felt like my head were not over my shoulders ... so i go to my bed to sleep ...

Finally, days after, I've decided to tune this code to bring some good year wishes to the monks ... and here is the result (a little bit ugly ^_^).

Anyway, Happy New Year 2006 to all of you Perl Monks!!

turo

perl -Te 'print map { chr((ord)-((10,20,2,7)[$i++])) } split //,"turo"'

Replies are listed 'Best First'.
A reply falls below the community's threshold of quality. You may see it by logging in.