ctaustin has asked for the wisdom of the Perl Monks concerning the following question:
This didn't seem to work. Part of this may be due to the fact that I can't figure out how to print the results, the other is that I am not convinced that the hashes are getting properly populated.my (%agency,(%url,(%module,(%type,$type_count)))); my $pass_count=0; my $fail_count=0; my $new_count=0; while ($line=<FILE>) { ($e1,$e2,$e3,$e4,$e5,$e6,$e7,$e8)=(split/\s+/,$line); $pf=substr($pf,0,4); if ($pf eq "pass") { $agency{$e4,{$e7,{$e6,$pass_count++}}}; if ($pf eq "fail) { $agency{$e4,{$e7,{$e6,$fail_count++}}}; if ($pf eq "new_") { $agency{$e4,{$e7,{$e6,$new_count++}}};
package Agency; sub new { my $class={}; $class-> {agency}=undef; $class->{url}=undef; $class->{pass}=undef; $class->{fail}=undef; $class->{new}=undef; $class->{module}=undef; bless $class; return $class; } sub init { my $class=shift; $class->{agency}=shift; $class->{url}=shift; $class->{pass}=shift; $class->{fail}=shift; $class->{new}=shift; $class->{module}=shift; } sub display { my $class=shift; print "Agency: $class->{agency} URL: $class->{url} Pass: $class- +>{pass} Fail: $class{fail} New: $class{new} Module: $class->{modu +le}\n" } package main; my $new_agency=Agency->new(); foreach $file (glob('file_name*.txt')) { open (FILE,$file)||die ("unable to open $file\n"); print "working on $file\n"; while ($line=<FILE>) { ($ts,$w,$agency,$url,$x,$pf,$module,$z)=(split/\s+/,$line); $pf=substr($pf,0,4); if ($pf eq "pass") { $new_agency->init($agency,$url,$pass_count++,$fail_coun +t,$new_count,$module); } elsif ($pf eq "fail") { $new_agency->init($agency,$url,$pass_count,$fail_count+ ++,$new_count,$module); } elsif ($pf eq "new_") { $new_agency->init($agency,$url,$pass_count,$fail_count, +$new_count++,$module); } } #while } # foreach $new_agency->display();
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: nested hashes or object oriented
by BrowserUk (Patriarch) on Jun 11, 2003 at 21:10 UTC | |
|
Re: nested hashes or object oriented
by djantzen (Priest) on Jun 11, 2003 at 20:55 UTC | |
|
(jeffa) Re: nested hashes or object oriented
by jeffa (Bishop) on Jun 11, 2003 at 21:34 UTC | |
|
Re: nested hashes or object oriented
by pzbagel (Chaplain) on Jun 11, 2003 at 20:48 UTC | |
by ctilmes (Vicar) on Jun 11, 2003 at 21:32 UTC | |
|
Re: nested hashes or object oriented
by artist (Parson) on Jun 11, 2003 at 21:35 UTC | |
by ctaustin (Sexton) on Jun 11, 2003 at 23:38 UTC |