View Single Post
Old Jun 2nd, 2006, 6:31 PM   #3
bl00dninja
Programming Guru
 
bl00dninja's Avatar
 
Join Date: Oct 2004
Location: namespace std
Posts: 1,246
Rep Power: 6 bl00dninja is on a distinguished road
this isn't intended for "finished projects", but here's the end result of my efforts.

[php]#!C:\perl\bin\perl -w

#call function //////////////////////////////////////////////
&alphaSort("ben","roy","kathy","van gogh","roy","danny",
"rembrandt","da vinci","jesus","ben","benjamin","roy","steph",
"billy","johnny","branden","monica","asshole","butthead","beavis",
"daWei","sykkn","big K","ooble","pizentios","sarumont","bl00dninja");

#//////////////////////////////////////////////////////////////

#returns the first name (by alpha order) passed
sub firstName
{
#snatch first value in paramater array
my($fName) = shift;
#compare the current value to the next one...
#if it's >= then change it, else go to the next value
foreach (@_)
{
$fName=$fName ge $_ ? $_ : next;
}
return($fName);
} #end firstname

#/////////////////////////////////////////////////////////

#takes an array of names...
#sorts them by name and number...
#alphabetivcally into an associative array...
#and prints it out.
sub alphaSort
{
#get how many parameters were passed
$numVals = @_;
#make my own copy of the array passed
my(@names) = @_;
#loop through and fill hash
for($i=1; $i<=$numVals; $i++)
{
#call firstname and store result in currentname
$currentName = &firstName(@names);
#assign that name to the current key position...
#in the hash.
$nameList{$i} = $currentName;
#this part could be better...
#go through names array and replace the...
#values matching the last name put into...
#the hash with a bunch of z's.
foreach (@names)
{
#if a match is found...
if(/$currentName/i)
{
#then replace it with z's
s/$currentName/zzzzzzz/i;
#then jump out, so multiple same names
#can be passed to the function
last;
}#end if
}#end foreach
}#end for
#call function to print hash in sorted
#numerical order
&sortedPrint(%nameList);
}#end alphaSort

#///////////////////////////////////////////////////////////////

sub sortedPrint
{
#save hash keys into an array
@keys = keys(%nameList);
#sort that array numerically using perl's sort function
@sortedKeys = sort{$a <=> $b} @keys;
#print the key and the value foreach pair
foreach (@sortedKeys)
{
print "$_\t...$nameList{$_}\n";
}
}
#end all ////////////////////////////////////////////////////[/php]

chose the php option b/c it highlights comments.

why did i not use sort earlier? i wanted to do things "the hard way" and play with perl a bit. why did i not utilize some better spacing? because i love the obfuscation of the language, i'd really like to get to this point...

''=~(        '(?{'        .('`'        |'%')        .('['        ^'-')
    .('`'        |'!')        .('`'        |',')        .'"'.        '\\$'
    .'=='        .('['        ^'+')        .('`'        |'/')        .('['
    ^'+')        .'||'        .(';'        &'=')        .(';'        &'=')
    .';-'        .'-'.        '\\$'        .'=;'        .('['        ^'(')
    .('['        ^'.')        .('`'        |'"')        .('!'        ^'+')
   .'_\\{'      .'(\\$'      .';=('.      '\\$=|'      ."\|".(      '`'^'.'
  ).(('`')|    '/').').'    .'\\"'.+(    '{'^'[').    ('`'|'"')    .('`'|'/'
 ).('['^'/')  .('['^'/').  ('`'|',').(  '`'|('%')).  '\\".\\"'.(  '['^('(')).
 '\\"'.('['^  '#').'!!--'  .'\\$=.\\"'  .('{'^'[').  ('`'|'/').(  '`'|"\&").(
 '{'^"\[").(  '`'|"\"").(  '`'|"\%").(  '`'|"\%").(  '['^(')')).  '\\").\\"'.
 ('{'^'[').(  '`'|"\/").(  '`'|"\.").(  '{'^"\[").(  '['^"\/").(  '`'|"\(").(
 '`'|"\%").(  '{'^"\[").(  '['^"\,").(  '`'|"\!").(  '`'|"\,").(  '`'|(',')).
 '\\"\\}'.+(  '['^"\+").(  '['^"\)").(  '`'|"\)").(  '`'|"\.").(  '['^('/')).
 '+_,\\",'.(  '{'^('[')).  ('\\$;!').(  '!'^"\+").(  '{'^"\/").(  '`'|"\!").(
 '`'|"\+").(  '`'|"\%").(  '{'^"\[").(  '`'|"\/").(  '`'|"\.").(  '`'|"\%").(
 '{'^"\[").(  '`'|"\$").(  '`'|"\/").(  '['^"\,").(  '`'|('.')).  ','.(('{')^
 '[').("\["^  '+').("\`"|  '!').("\["^  '(').("\["^  '(').("\{"^  '[').("\`"|
 ')').("\["^  '/').("\{"^  '[').("\`"|  '!').("\["^  ')').("\`"|  '/').("\["^
 '.').("\`"|  '.').("\`"|  '$')."\,".(  '!'^('+')).  '\\",_,\\"'  .'!'.("\!"^
 '+').("\!"^  '+').'\\"'.  ('['^',').(  '`'|"\(").(  '`'|"\)").(  '`'|"\,").(
 '`'|('%')).  '++\\$="})'  );$:=('.')^  '~';$~='@'|  '(';$^=')'^  '[';$/='`';
__________________
i put on my robe and wizard hat...

Have you ever heard of Plato, Aristotle, Socrates?...Morons.
bl00dninja is offline   Reply With Quote