develooper Front page | perl.beginners | Postings from February 2002

Re: Sorting a hash table - Advanced;)

Thread Previous | Thread Next
From:
Vitali
Date:
February 28, 2002 06:07
Subject:
Re: Sorting a hash table - Advanced;)
Message ID:
06c501c1c05f$b7229e90$160101c8@PDFCLIENT.local
Dear friends!

Please consult me!
How I must change the code ,so that "Raport page" prints on the begining of
file,not in the end?
Code reads the lines,count $env and $page  and print those to the report
page...

Thank you,
VItali Pokrovski
------------------------------
Here is input file:
10Arve nr 1
20
 0
30
 0
90_ _
A01
10Arve nr 2
20
 0
30
 0
90__
A02
-----------------------------

while (<STDIN>) {   # Read line by line
chomp;
 if (substr($_,0,2) eq "10") {
 s/10/\x0c10/;              }
 if (substr($_,0,1) ne " ") {
 $pos = substr($_,0,1)} else {
  substr ($_,0,1) = $pos; }

 if (substr($_,0,5) eq "90_ _"){
    ++$env}

 if (substr($_,0,2) eq "A0"){
       ++$page}

print "$_\n";
}

print "\x0c10                             RAPORT PAGE\n";
print "10";
print "#" x 74;
print "\n";
print "10#Total is: $page pages and $env envelopes\n";
print "10#\n" x 10;
print "10";
print "#" x 74;   # };
__EOF__

---------------------------------------
Now output file look like this:

10Arve nr 1
20
20
30
30
90_ _
A01
10Arve nr 2
20
20
30
30
90__
A02
10                             RAPORT
10##########################################################################
10#Total is: 2 pages and 1 envelopes
10#
10#
10#
10#
10#
10#
10#
10#
10#
10#
10##########################################################################

----- Original Message -----
From: "Tor Hildrum" <torhildr@mac.com>
To: "Perl" <beginners@perl.org>; "Steven M. Klass" <Steven.Klass@nsc.com>
Sent: Thursday, February 28, 2002 3:01 PM
Subject: Re: Sorting a hash table - Advanced;)


> On 27/2/02 17:33, "Steven M. Klass" <Steven.Klass@nsc.com> wrote:
>
> > Hi all,
> >
> > ok here is the fundamental code
> >
> > print "\n\n**Summary**\n";
> > foreach my $key (keys %runset){
> >   printf ( "%-20s %-20s\n",$key, $runset{$key});
> > }
> >
> > Now I want to sort this hash for example
> > print "\n\n**Summary**\n";
> > foreach my $key (keys %runset){
> >   print "Name        $runset{foo}"
> >   # .. other specific keys
> >   printf ( "%-20s %-20s\n",$key, $runset{$key});
> > }
> >
> > The question is how can I sort the remaining keys that I haven't already
> > printed before.
> >
> > Basically I want to format this so certain keys get printed in a certain
> > order, but there may be some remaining keys that I want printed that I
really
> > don't care about.  (a "catch-all" if you will)
> >
> > Thanks
>
> print "\n\n**Summary**\n";
> foreach my $key (keys %runset){
> print "Name        $runset{foo}"
> # .. other specific keys
> foreach $key (sort keys %runset) {  ## sort the remaining in ASCII order.
> printf ( "%-20s %-20s\n",$key, $runset{$key});
> }
>
> Something like that?
>
> --
> T.
>
>
>
> --
> To unsubscribe, e-mail: beginners-unsubscribe@perl.org
> For additional commands, e-mail: beginners-help@perl.org
>


Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About