Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW

Re^2: help formatting output of particular loop

by eisdrache (Novice)
on Jan 29, 2007 at 09:00 UTC ( #597044=note: print w/replies, xml ) Need Help??

in reply to Re: help formatting output of particular loop
in thread help formatting output of particular loop

geez i do have brain damage.

what you have written i already figured out (thanks, though). but i completely forgot to add a crucial component to this problem.

if the start_time of the following day is earlier that 09:00, i want it printed with the previous day. for example, if this were the output:
id_number CA456789 2007-01-29 16:00:00 CA456712 2007-01-30 03:00:00
i would like it to be output like this:
2007-01-29 CA456789 16:00:00 CA456712 03:00:00
thanks again for you help

Replies are listed 'Best First'.
Re^3: help formatting output of particular loop
by shmem (Chancellor) on Jan 29, 2007 at 09:09 UTC
    Modify tinita's code as follows
    if ($row->{start_date} ne $last_date && (split/:/,$row->start_time)[0] + > 9) {

    update: Oops. That will output incorrect results if all entries for a day are from before 9:00. Make a hash keyed with unix timestamps of each date, push each entry onto an array for the appropriate day:

    use Time::Local; ... for my $row (@rows) { my @l = reverse split /-/, $row->{start_date}; $l[1]--; # months range is 0..11 my $key = timelocal(0,0,0,@l); my $line = join("\t", $row->{id_number}, $row->{start_time}); # wh +atever formatting if(split/:/,$row->start_time)[0] > 9) { push @{$hash{$key-86400}}, $line; } else { push @{$hash{$key}}, $line; } } foreach my $key (sort %hash) { my @l = (localtime $key)[5,4,3]; $l[1]++; # month... print join('-', @l), "\n"; print $_,"\n" for @{$hash{$key}}; }


    _($_=" "x(1<<5)."?\n".q·/)Oo.  G°\        /
                                  /\_¯/(q    /
    ----------------------------  \__(m.====·.(_("always off the crowd"))."·
    ");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}
      AHA! Thank you so much!

      That worked...oh man, I can finally start working on fixing any reversible damage all that thinking may have inflicted on my brain!
    A reply falls below the community's threshold of quality. You may see it by logging in.

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://597044]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (4)
As of 2022-05-16 12:47 GMT
Find Nodes?
    Voting Booth?
    Do you prefer to work remotely?

    Results (63 votes). Check out past polls.