I pray to the monastary for forgiveness. I am sorry for sounding pompous in my request for wisdom at 3am last night. Again, I am brand new to perl AND this site. I would never want anyone to do my homeowrk for me and I appreciate the insights that were given (although, I do have trouble understanding the syntax of much of the code). Anyway, I will try to be more thorough in my postings and not lead the monastary into believing they are "doing my homework for me". This snippet of code (the sort) is part of a much bigger project that I've left for the last minute (the script, that is, not the project). Anyway, I do have some pseudocode that I can share so that I can get the proper syntax on this "array sort" correct. Again, if this were Java, I'd know exactly how to handle this (if I was a racecar driver and Perl was a Maserati
as I hear it can be, I'd still be idling). But, here goes nothing (remember, this is pseudocode):
sub mysort
{
chomp(@entries = <STDIN>);
foreach $indexofleast (@entries)
{
$indexofleast = $firstelement;
foreach $counter (@entries)
{
if ($counter lt $indexofleast)
{
$indexofleast eq counter;
}
if ($indexofleast ne $firstelement)
{
$temp = $firstelement;
$firstelement = $indexofleast;
$indexofleast = $temp;
}
}
}
}
I hope you all can see what I'm TRYING to do here. Basically
I want to start at the beginning of an array, find the smallest value; if that value is not equal to the first value then I want to swap them, go on to the next sequential value in the array and iterate again until I have the array sorted from smallest (left) to largest (last). Again, I hope this message makes me sound less pompous than before and hope that I will be taken seriously in future attempts to "seek wisdom".
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.