lets say you have
create table BUGS(
bug_id number(20) is primary key,
owner varchar2(50),
subject varchar2(50),
status char(3),
assigned varchar2(8) );
You can use the following to get your table
to a hash of Array and do a sort on which ever column
you like, rather than using ORDER BY.
my $sth =
do->("SELECT bug_id, owner, subject, status, assigned FROM BUGS");
while (
my ( $bug_id, $owner, $subject, $status, $assigned ) =
$sth->fetechrow ) {
push @{$bugTable{$bug_id}},
( $owner, $subject, $status, $assigned );
}
print "Which column would you like to sort by?\n";
print "\t Bug_ID(1), Owner(2), Subject(3) ".
", Status(4) or Assigned_To(5) ?: ";
my $input = <STDIN>;
SWITCH: for ($input) {
/1/ && do {
@srtArr = sort { $a <=> $b } keys %bugTable;
last;
};
/2/ && do {
@srtArr =
sort { ${$bugTable{$a}}[0] cmp ${$bugTable{$b}}[0] } keys %bugTable;
last;
};
/3/ && do {
@srtArr =
sort { ${$bugTable{$a}}[1] cmp ${$bugTable{$b}}[1] } keys %bugTable;
last;
};
/4/ && do {
@srtArr =
sort { ${$bugTable{$a}}[2] cmp ${$bugTable{$b}}[2] } keys %bugTable;
last;
};
/5/ && do {
@srtArr =
sort { ${$bugTable{$a}}[3] cmp ${$bugTable{$b}}[3] } keys %bugTable;
last;
};
} # End of SWITCH.
for my $bug_id ( @srtArr ) {
print " @{$bugTable{$bug_id}} \n";
}
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.