Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery

Re: Re: Consolidate info in a while() loop

by peppiv (Curate)
on Jan 21, 2003 at 21:41 UTC ( #228854=note: print w/replies, xml ) Need Help??

in reply to Re: Consolidate info in a while() loop
in thread Consolidate info in a while() loop

I understand the concept but I have no idea how to start this. How do you build a hash from a while loop?


  • Comment on Re: Re: Consolidate info in a while() loop

Replies are listed 'Best First'.
Re: Re: Re: Consolidate info in a while() loop
by poj (Prior) on Jan 21, 2003 at 22:43 UTC
    if (!defined $line[0]) { $line[0] = ""; } # $line[1] = &formatNumber($line[1]); ### take this out if (($report3 == 1101)) { printf("%-66s %13s\n", $line[0], $line[1]); #Here's the bugger. This is the line that prints what I need my $weekday = substr($line[0],0,3); ## add $total_day{$weekday} += $line[1]; ## add +. } elsif (defined $field{$report3}) { printf("%-66s %13s\n", $line[0], $line[($field{$report3}+1)]) +; } $count3++; } } # print totals in correct order my @days = qw(Mon Tue Wed Thu Fri Sat Sun); for (@days){ printf( "%-66s %13s\n",$_,formatNumber($total_day{$_}) ); }
      You!........You my friend are very good!

      No, I'm not!

      Yes, you are!

      No, no.

      Hey, I said you was good!

      Analyze that!


      Works like a charm! Had to declare %total_day and take out the formatting of the number before it was crunched, but hey, you is good!

Re: Re: Re: Consolidate info in a while() loop
by CountZero (Bishop) on Jan 21, 2003 at 22:17 UTC

    In your while-loop, obtain both the day of the week without the date (to be put into a variable $weekday) and the number (put this into $number).

    Once you have these data, then $total{$weekday} += $number; will add $number to the value of the hash %total keyed by $weekday.

    That's all there is to it.


    "If you have four groups working on a compiler, you'll get a 4-pass compiler." - Conway's Law

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://228854]
[Corion]: hippo: If you have a Unicode-wise Perl then likely some zero-width characters in $x would work. Maybe $x = "\x{200b}" works.
[Corion]: Hmm - no, that outputs 1 for me on 5.14 - perl -wle "my $x = qq(\x{200b}); warn $x; warn length $x"
[hippo]: Smart - I'll give that a go. Thanks.
[hippo]: Ah
[Corion]: But maybe there is some other Unicode string that will be true but have a zero width
[hippo]: For explanation, I've seen this construct in someone else's code (no names, no pack drill) and couldn't think of a situation to trigger it.
[Corion]: You'll have to look somewhere esoteric for that. Maybe some tied variable or special dualvar can also trigger that. But it's certainly not a common occurrence

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (9)
As of 2017-07-27 13:28 GMT
Find Nodes?
    Voting Booth?
    I came, I saw, I ...

    Results (413 votes). Check out past polls.