Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

 
 
Thread Tools Display Modes
Prev Previous Post in Thread   Next Post in Thread Next
Old Jun 1st, 2006, 4:28 AM   #1
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
hash namesort::easy for perl buffs i'm sure

this program is stupid and gay, but i wnat constrctive criticism of what could be done more efficiently...

#!C:\perl\bin\perl -w

&alphasort("ben","bill","joe","john","gary","roy","steph");

sub firstName
{
    my($fname) = shift(@_);
    foreach (@_)
    {
        $fname=$fname ge $_ ? $_ : next;
    }
    return($fname);
}

sub alphasort
{
    $numVals = @_;
    my(@names) = @_;
    my(%namelist);
    
    for($i=1; $i<=$numVals; $i++)
    {
        $currentname = &firstName(@names);
        $namelist{$i} = $currentname;
        
        foreach (@names)
        {
            s/$currentname/zzzzzzzzzzzzzzzz/i;
        }
    }
    
    while (($key, $value) = each %namelist)
    {
        print("$key....$value\n");
    }
}

it calls alphasort which then will call a function that returns the smallest name in the array, sticks that name into the current loop var, then it replaces that name (and unfortunately all other identical without regard to case) with a bunch of z's. it places these values into an associative array which it then prints out.

some questions:

1-better way than making a bunch of z's?
(trying not to use external functions)

2-why does the hash print out like this?

6,4,1,3,7,2,5 ??????

seems like it starts on one end and is bouncing back and forth until it hits the center??? what's the point of this? (i'm sure there's a good one).
__________________
i put on my robe and wizard hat...

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

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 7:28 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC