Whooohooo!! It is working.

For those of you who are keeping score, here is the final code, and what changes had to be made.

First, $foo->bar('$blah') puts "$blah" in bar, not the value of $blah. Whoops, stupid mistake.

%Unique_SN holds the unique serial number as the key and a pointer to the DEVICE struct associated with it as its value.

I can now 'use strict' agian, and I don't have to use the itermediate $sn. Now to finish this thing. I might be able to dump %Unique_DeviceType, but I'm holding on to it for now.

Thanks all. I think the orignal was not working because of the $$sn->datetime($datetime) line, not because of the $$sn = new DEVICE line. The failure was, I think, in not dereferencing. It didn't care about the anon $$sn, but $$sn was literally holding a memory address.

Wait... I think I may have just confused myself. Anyway, it is working, so no need to worry with it. I like this way better.

#!c:\perl\bin\ use strict; #must find way to use deref in +my statement use File::DosGlob 'glob'; use Class::Struct; use Getopt::Std; use vars qw($opt_a); getopts('a:'); my $logPath = "\\\\" . $opt_a . "\\d\$\\iims\\history"; print "Searching $logPath\n"; struct ( DEVICE => { datetime => '$', devicetype => '$', zip => '$', v +ersion => '$'}); my %Unique_DeviceType; my %Unique_SN; foreach my $logfile (glob("$logPath\\*")){ open (LOG, "<$logfile") or die "Can't open $logfile: $!"; while(<LOG>){ chomp; #pul +l off newline s/^\s+//; #pull + out leading whitespace s/\s+$//; #pull + out trailing whitespace s/\s*,\s*/,/g; #pul +l out whitespace around commas s/\[|\]//g; #re +move [ ] around date time stamp next unless length; #mo +ve to the next line unless there is something left in this one my @entry = split(/,/, $_); #sp +lit entry: Date Time DeviceType SN ZIP Version my @date = split(/:/, $entry[0]); #crea +te datetime YYYYMMDDHHMMSS my @time = split(/:/, $entry[1]); my $datetime = $date[2] . $date[1] . $date[0] . $time[0] . $ti +me[1] . $time[2]; $Unique_DeviceType{$entry[2]}++; #Add e +ntry to unique list of Device Types if (!exists $Unique_SN{$entry[3]}) { #If th +is is first occurance $Unique_SN{$entry[3]} = new DEVICE; #Ad +d entry to unique list of SNs $Unique_SN{$entry[3]}->datetime($datetime); $Unique_SN{$entry[3]}->devicetype($entry[2]); $Unique_SN{$entry[3]}->zip($entry[4]); $Unique_SN{$entry[3]}->version($entry[5]); } elsif ($datetime > $Unique_SN{$entry[3]}->datetime) { #If t +his occurance is newer $Unique_SN{$entry[3]}->datetime($datetime); $Unique_SN{$entry[3]}->zip($entry[4]); $Unique_SN{$entry[3]}->version($entry[5]); } } } foreach my $key (keys(%Unique_SN)){ print $key . "\n"; }

In reply to Re: Anon Struct Instance by THuG
in thread Anon Struct Instance by THuG

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.