R
richjungk
guys i really need help!!!
i'm a beginner in perl language.
for my code i want to look for matching criteria.
Here is an example of the contents of the file.
c_c_flag::
survey28::2
driver1_G2_date_month::12
driver1_student::N
current_amount::6700
driver1_suspensionstart_year::2004
p1::5217
car1_comprehensive_coverage::0
driver1_conviction_1_month::01
p2::6740
driver1_conviction_1_year::2005
c1::KNGN
postal_code_2::1L
As you can see, each line contains a pair of strings separated by
'::'
i need to open the file and process it line by line, and figuring out
how many driver profiles are stored in the file and store this in an
array.
Put the array values into a hash to make them unique, and put the hash
back into an array.
Close the file.
Reopen the file and loop through the array and create hashes for each
driver to provide the following aggregate information:
Number of:
male drivers under age 25 with a conviction
female drivers under age 25 with a conviction
and, here is my code that i did so far..............
#!/urs/bin/perl -w
my %DATA;
my $dnum;
my $conviction;
chdir("directory path") or die;
open(FH, "ID1234.txt") or die "$!\n";
while(<FH>){
if($_ =~ / (driver \d ) / ) { # $1 is first match
push @drivers, $1;
}
}
close FH or die;
foreach(@drivers){
$D{"$_")++;
}
@sorts = sort(keys(%D)); # "driver1" "%D"
foreach(@sorts){
open *FH, "ID1234.txt") or die;
$dnum = $_ ;
while(<FH>){
if($_ =~ / $dnum( _conviction ) / ){
$conviction = $1;
}
}
close FH or die;
}
from now on, how to i search for criteria for
Number of:
male drivers under age 25 with a conviction
female drivers under age 25 with a conviction
i'm a beginner in perl language.
for my code i want to look for matching criteria.
Here is an example of the contents of the file.
c_c_flag::
survey28::2
driver1_G2_date_month::12
driver1_student::N
current_amount::6700
driver1_suspensionstart_year::2004
p1::5217
car1_comprehensive_coverage::0
driver1_conviction_1_month::01
p2::6740
driver1_conviction_1_year::2005
c1::KNGN
postal_code_2::1L
As you can see, each line contains a pair of strings separated by
'::'
i need to open the file and process it line by line, and figuring out
how many driver profiles are stored in the file and store this in an
array.
Put the array values into a hash to make them unique, and put the hash
back into an array.
Close the file.
Reopen the file and loop through the array and create hashes for each
driver to provide the following aggregate information:
Number of:
male drivers under age 25 with a conviction
female drivers under age 25 with a conviction
and, here is my code that i did so far..............
#!/urs/bin/perl -w
my %DATA;
my $dnum;
my $conviction;
chdir("directory path") or die;
open(FH, "ID1234.txt") or die "$!\n";
while(<FH>){
if($_ =~ / (driver \d ) / ) { # $1 is first match
push @drivers, $1;
}
}
close FH or die;
foreach(@drivers){
$D{"$_")++;
}
@sorts = sort(keys(%D)); # "driver1" "%D"
foreach(@sorts){
open *FH, "ID1234.txt") or die;
$dnum = $_ ;
while(<FH>){
if($_ =~ / $dnum( _conviction ) / ){
$conviction = $1;
}
}
close FH or die;
}
from now on, how to i search for criteria for
Number of:
male drivers under age 25 with a conviction
female drivers under age 25 with a conviction