Thank you everyone, very much appreciate all the assistance. Turns out the code in fact wasn't working correctly after all.

Especially thanks to 'Loops' for the suggestion of using a hash to track exits. I had been worrying about loading the whole dataset into program memory and this suggestion resolved that.

Finally ended up with the following - probably not perfect but it is definitely working and thoroughly tested. It does seem to have been an awful lot of effort for a relatively trivial program, but I suppose you have to expect that when you're trying to learn a new language.

#! /usr/bin/perl use DBI; $dbc= DBI->connect('dbi:Pg:dbname=redacted;host=localhost', 'redacted' +, '', { AutoCommit=>1, RaiseError=>1, PrintError=>0 }); $sth = $dbc->prepare (" SELECT TO_CHAR(SN_EVENTS.CREATED, 'YYYY-MM-DD HH24:MI:SS') AS DAT +ETIMED, SN_CAMERAS.TYPE AS DIRECTION, sefs.ocr_1 as OCR FROM SN_EVENTS INNER JOIN sn_events_fusions sefs ON sefs.fk_event = s +n_events.pk_event INNER JOIN SN_CAMERAS ON SN_CAMERAS.PK_CAMERA = SN_EVE +NTS.FK_CAMERA INNER JOIN SN_RULES ON SN_RULES.PK_RULE = SN_EVENTS.FK +_RULE WHERE SN_CAMERAS.TYPE = 'entrance' OR SN_CAMERAS.TYPE = 'exit' AND SN_RULES.key = 'plate-recognition' AND SN_EVENTS.FK_EVENT_STATUS = 1 ORDER BY SN_EVENTS.CREATED DESC "); $sth->execute or die $sth->errstr; while (@event = $sth->fetchrow_array()){ if ($event[1] eq "exit"){ $exited{$event[2]}=1; } if (not $exited{$event[2]}){ push @recordset, [@event]; } }; $sth->finish; reverse(@recordset); for $row ( @recordset ){ print "@$row\n"; }

In reply to Re: Trouble with array of arrays by trew
in thread Trouble with array of arrays by trew

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.