Ah, sorry for the confusion, I'll try to clarify. I'll even post all of my code (just don't laugh).

You are right, it is not a reference or meant to be. I'm trying to create an instance of the struct anonymously. The value stored in the scalar $sn (which was in the third element of the array @entry) is going to be the name of the new struct. If that value were K123456, then $K123456 would be the name of the struct. I know this sort of anonymous calling is valid, I've used it before.

The actual names will be stored in a hash as keys. Their value pair is simply a count of how many times they are listed in the log files. In the end, when I want to tabulate and output the data, I will call each key out of the hash (foreach my $key (keys(%Unique_SN))) and then call the DEVICE struct associated with it ($$key).

That much I have done before, but it was with referenced arrays and stuff, never with a struct.

Anyway, here is my code, or what I have of it so far. It is in an early testing stage, so I don't actually do anything with the data, yet.

#!c:\perl\bin\ no strict; 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; s/^\s+//; s/\s+$//; s/\s*,\s*/,/g; s/\[|\]//g; next unless length; my @entry = split(/,/, $_); #split entry: Date Time Devic +eType SN ZIP Version my @date = split(/:/, $entry[0]); #create datetime YYYYMM +DDHHMMSS my @time = split(/:/, $entry[1]); my $datetime = $date[2] . $date[1] . $date[0] . $time[0] . $ti +me[1] . $time[2]; my $sn = $entry[3]; $Unique_DeviceType{$entry[2]}++; #Add entry to unique list + of Device Types $Unique_SN{$sn}++; #Add entry to unique list of SNs if ($Unique_SN{$sn} == 1) { #If this is first occurance $$sn = new DEVICE; $$sn->datetime('$datetime'); $$sn->devicetype('$entry[2]'); $$sn->zip('$entry[4]'); $$sn->version('$entry[5]'); } elsif ($datetime > $$sn->datetime) { $$sn->datetime('$datetime'); $$sn->zip('$entry[4]'); $$sn->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.