in reply to Anon Struct Instance
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"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
RE: Re: Anon Struct Instance
by ferrency (Deacon) on Jul 11, 2000 at 21:34 UTC |