[27897] in Perl-Users-Digest
Perl-Users Digest, Issue: 9261 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Jun 8 11:10:30 2006
Date: Thu, 8 Jun 2006 08:10:24 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Thu, 8 Jun 2006 Volume: 10 Number: 9261
Today's topics:
How to hobble a CPU <y_simard@yahoo.fr>
How to hobble a CPU <y_simard@yahoo.fr>
Re: How to hobble a CPU <tzz@lifelogs.com>
Re: How to hobble a CPU <bugbear@trim_papermule.co.uk_trim>
Re: How to hobble a CPU xhoster@gmail.com
Re: How to hobble a CPU <cbigam@somewhereelse.nucleus.com>
Re: how to read Chinese filenames? <rvtol+news@isolution.nl>
how to search through file for certain criteria richjungk@gmail.com
Re: how to search through file for certain criteria <someone@example.com>
Re: how to search through file for certain criteria richjungk@gmail.com
Re: how to search through file for certain criteria <jgibson@mail.arc.nasa.gov>
Re: how to search through file for certain criteria <tadmc@augustmail.com>
how to search through file for matching criteria richjungk@gmail.com
Re: how to search through file for matching criteria <someone@example.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 7 Jun 2006 08:08:35 -0700
From: "Solostian" <y_simard@yahoo.fr>
Subject: How to hobble a CPU
Message-Id: <1149692915.727680.258290@c74g2000cwc.googlegroups.com>
Hi,
I need to conduct a series of performance tests. Unfortunately, my
workstation way more powerful than the targeted workstations. I need to
design a script that will allow me to cut down the overall CPU power by
a set % value.
Does anyone knows if this is possible at all with Perl?
Where would I first need to look?
Regards,
Solostian
------------------------------
Date: 7 Jun 2006 08:08:47 -0700
From: "Solostian" <y_simard@yahoo.fr>
Subject: How to hobble a CPU
Message-Id: <1149692927.471601.314030@i39g2000cwa.googlegroups.com>
Hi,
I need to conduct a series of performance tests. Unfortunately, my
workstation is way more powerful than the targeted workstations. I need
to design a script that will allow me to cut down the overall CPU power
by a set % value.
Does anyone knows if this is possible at all with Perl?
Where would I first need to look?
Regards,
Solostian
------------------------------
Date: Wed, 07 Jun 2006 12:09:52 -0400
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: Re: How to hobble a CPU
Message-Id: <g69fyih9cbz.fsf@CN1374059D0130.kendall.corp.akamai.com>
On 7 Jun 2006, y_simard@yahoo.fr wrote:
> I need to conduct a series of performance tests. Unfortunately, my
> workstation is way more powerful than the targeted workstations. I need
> to design a script that will allow me to cut down the overall CPU power
> by a set % value.
>
> Does anyone knows if this is possible at all with Perl?
> Where would I first need to look?
You can use a program like `vmstat' to get the current CPU load as a
percentage, or look at the CPAN Sys::Load module (or just run
`uptime') to get the system load. System load is sometimes more
accurate that CPU usage, because it takes into account all factors
affecting performance (it's the average number of processes that are
waiting for execution at any given time during the last N minutes).
If you're using hyper-threading or multiple processors, it's hard to
load the processor with a simple idle loop. You should consider
starting multiple processes.
Also this:
http://dcs.nac.uci.edu/~strombrg/slowdown/
may be what you need, if you just want to slow down your program, not
the whole system. There may be other ways to accomplish this...
Finally, it's not very meaningful to artificially slow down a
performance test. Instead, benchmark both systems in a standard way
(which depends on what exactly you are benchmarking), and you will
have a standard scaling factor. The Perl Benchmark module may be
useful here.
Ted
------------------------------
Date: Wed, 07 Jun 2006 17:26:44 +0100
From: bugbear <bugbear@trim_papermule.co.uk_trim>
Subject: Re: How to hobble a CPU
Message-Id: <4486fe44$0$22892$ed2619ec@ptn-nntp-reader01.plus.net>
Solostian wrote:
> Hi,
>
> I need to conduct a series of performance tests. Unfortunately, my
> workstation way more powerful than the targeted workstations. I need to
> design a script that will allow me to cut down the overall CPU power by
> a set % value.
>
> Does anyone knows if this is possible at all with Perl?
In general I'm not sure it's possible at all;
"power" is a complex combination of disc speed, caching,
bandwidth, ram size, clock speed, and many other factors.
Trying to (semi-accurately) degrade one machine
to fit another's spec sounds killingly difficult.
BugBear
------------------------------
Date: 07 Jun 2006 16:03:39 GMT
From: xhoster@gmail.com
Subject: Re: How to hobble a CPU
Message-Id: <20060607130847.373$zN@newsreader.com>
"Solostian" <y_simard@yahoo.fr> wrote:
> Hi,
>
> I need to conduct a series of performance tests. Unfortunately, my
> workstation is way more powerful than the targeted workstations.
Trade workstations.
> I need
> to design a script that will allow me to cut down the overall CPU power
> by a set % value.
I fail to see the point. Why do you need to hobbler your workstation? If
your job is purely CPU bound, then just take the time on your workstation
and multiply it by the scaling factor.
Xho
--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service $9.95/Month 30GB
------------------------------
Date: Wed, 07 Jun 2006 19:39:29 GMT
From: "Colin B." <cbigam@somewhereelse.nucleus.com>
Subject: Re: How to hobble a CPU
Message-Id: <44872b70@news.nucleus.com>
Solostian <y_simard@yahoo.fr> wrote:
> Hi,
>
> I need to conduct a series of performance tests. Unfortunately, my
> workstation way more powerful than the targeted workstations. I need to
> design a script that will allow me to cut down the overall CPU power by
> a set % value.
>
> Does anyone knows if this is possible at all with Perl?
> Where would I first need to look?
The first place to look is at the question. Do you really need to scale your
computer down, or can you scale the results down instead? If the job is CPU
bound, it should certainly be possible.
Secondly, you might be able to use zones and CPU partitioning to accomplish
it. Create a second zone that is able to use 2/3 of the total CPU cycles,
and then run something in it that will peg it 100%. In another zone, you are
then limited to only the remaining third of CPU power. Roughly.
------------------------------
Date: Wed, 7 Jun 2006 01:00:12 +0200
From: "Dr.Ruud" <rvtol+news@isolution.nl>
Subject: Re: how to read Chinese filenames?
Message-Id: <e658g2.1ds.1@news.isolution.nl>
ckyang74@gmail.com schreef:
> I remember filenames in Windows XP are encoded in utf8, is that
> correct?
No. See also http://www.perlmonks.org/?node_id=526169
--
Affijn, Ruud
"Gewoon is een tijger."
------------------------------
Date: 7 Jun 2006 17:03:45 -0700
From: richjungk@gmail.com
Subject: how to search through file for certain criteria
Message-Id: <1149725025.133241.188560@f6g2000cwb.googlegroups.com>
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
------------------------------
Date: Thu, 08 Jun 2006 00:30:46 GMT
From: "John W. Krahn" <someone@example.com>
Subject: Re: how to search through file for certain criteria
Message-Id: <WcKhg.33612$JX1.461@edtnps82>
richjungk@gmail.com wrote:
> 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
I don't see any records that show the sex or age of the driver so you probably
can't do that.
John
--
use Perl;
program
fulfillment
------------------------------
Date: 7 Jun 2006 17:38:32 -0700
From: richjungk@gmail.com
Subject: Re: how to search through file for certain criteria
Message-Id: <1149727112.387924.219860@i39g2000cwa.googlegroups.com>
here is all contents in file (file name is ID1234.txt)
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
search_alternative_coverage::N
car1_liability_coverage::500
car1_stats::No
renew::July
client_phone3::7509
driver1_status::S
driver1_conviction_1_month::01
p2::6740
driver1_conviction_1_year::2005
c1::KNGN
driver1_birth_month::03
driver1_license::G
car1_km::0
LANG::
driver1_insured::2000
driver1_sex::M
postal_code_2::1L5
driver1_suspensionend_year::2004
driver1_convictions::1
driver1_suspensionend_month::08
c3::RBC
b_c_flag::
HabDateCompany_month::01
city::BRAMPTON
driver1_convictiontype_1::Criminal=CD
driver1_insured_now::Y
how_find::Sun Newspaper
current_company::echelon
car1_annual_mileage::10000
car1_drivers::1
rate_alert_period::30
driver1_training::Y
postal_code::L6P
driver_number::1
driver1_claims::0
client_phone2::888
driver1_license_date_month::12
car_number::1
driver1_birth_day::15
car1_annual_mileage_business::0
driver1_G1_date_year::1999
driver1_G1_date_month::03
driver1_nonpayment::0
driver1_suspensionstart_month::05
p3::8973
car1_make::ACURA
client_name::Stan Duhan
c2::PAF
car1_collision_coverage::0
driver1_suspension::Y
car1_model::INTEGRA RS 2DR
client_email::get4life@hotmail.com
driver1_birth_year::1983
driver1_license_date_year::2003
car1_primary::1
client_phone1::416
driver1_first_name::Stan
driver1_retired::N
HabDateCompany_year::Not Applicable
car1_year::1991
driver1_G2_date_year::1999
AssumeMultiLine::N
car1_use::P
>
> I don't see any records that show the sex or age of the driver so you probably
> can't do that.
>
>
>
> John
> --
> use Perl;
> program
> fulfillment
------------------------------
Date: Wed, 07 Jun 2006 18:00:57 -0700
From: Jim Gibson <jgibson@mail.arc.nasa.gov>
Subject: Re: how to search through file for certain criteria
Message-Id: <070620061800571170%jgibson@mail.arc.nasa.gov>
In article <1149725025.133241.188560@f6g2000cwb.googlegroups.com>,
<richjungk@gmail.com> wrote:
> 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
> '::'
The first line has only one string. Does that matter?
>
> 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.
What is "this" that you are storing in an array? A driver profile? A
unique driver name? Where does a driver profile begin and where does it
end? You only show lines with "driver1". Are there also "driver2" lines
in the file?
> Put the array values into a hash to make them unique, and put the hash
> back into an array.
What are the "array values"? I am guessing unique driver identifiers.
If so, there is no need to store the driver IDs in an array and then in
a hash; just put them in a hash when they are read.
>
> Close the file.
>
> Reopen the file and loop through the array and create hashes for each
> driver to provide the following aggregate information:
No need to close and reopen a file. Just use seek. Who is giving you
these requirements? Are you generating them yourself, or is this a
homework problem?
>
> Number of:
> male drivers under age 25 with a conviction
> female drivers under age 25 with a conviction
Where in the sample data is the age of the driver given?
>
> and, here is my code that i did so far..............
>
> #!/urs/bin/perl -w
Is this your real code? There is no /urs directory on my system. Is
there one on yours? If not, please cut-and-paste your code so we don't
have to fix your typos.
You should have these lines at the beginning of your program (after the
above line):
use strict;
use warnings;
The second of these two lines replaces the '-w' option these days,
because it is better and more flexible.
>
> my %DATA;
> my $dnum;
> my $conviction;
>
> chdir("directory path") or die;
>
> open(FH, "ID1234.txt") or die "$!\n";
You earn high marks for testing the return of the chdir and open
functions. You will get higher marks if you use lexical file handles:
open( my $fh, ...
>
> while(<FH>){
> if($_ =~ / (driver \d ) / ) { # $1 is first match
This regular expression doesn't match any of your sample data. Spaces
in your RE must be matched by spaces in your data unless you use the /x
modifier to the RE, which you have not done.
> push @drivers, $1;
Just add an entry to your hash here:
$D{$1}++;
> }
> }
> close FH or die;
>
> foreach(@drivers){
> $D{"$_")++;
This line has a syntax error. Please post code that compiles and runs!
Also, there is no need to put $_ in quotes.
> }
>
> @sorts = sort(keys(%D)); # "driver1" "%D"
>
> foreach(@sorts){
> open *FH, "ID1234.txt") or die;
Another syntax error.
>
> $dnum = $_ ;
>
> while(<FH>){
> if($_ =~ / $dnum( _conviction ) / ){
This RE does not match any of your sample data. Maybe you mean
/${dnum}_conviction/. Braces are necessary becase $dnum_conviction is
another variable.
> $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 would advise saving all of the data to a complex data structure as it
is read, using an array of hashes or a hash of hashes. With a hash for
each driver, you can save the age of the driver and the number of
convictions. Then, you can traverse the data structure looking for
drivers that match any criteria.
Good luck!
Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com
------------------------------
Date: Wed, 7 Jun 2006 20:28:39 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: how to search through file for certain criteria
Message-Id: <slrne8eva7.v9i.tadmc@magna.augustmail.com>
richjungk@gmail.com <richjungk@gmail.com> wrote:
> guys i really need help!!!
Then you should take some care to avoid wearing out your welcome
on your very first post.
> and, here is my code that i did so far..............
It is not Perl code!
> #!/urs/bin/perl -w
^^^
^^^
Is this your real code?
Probably not. So then, are you wasting our time by having us
debug a program that does not even exist?
Probably.
That is Not Good.
> foreach(@drivers){
> $D{"$_")++;
^ ^
^ ^
If you open with a curly, then you should close with a curly.
See also:
perldoc -q vars
What's wrong with always quoting "$vars"?
> open *FH, "ID1234.txt") or die;
^
^
Where is the opening parenthesis?
I am now quite sure that you have a lack of respect for the
hundreds of people here. You are on your own.
So long!
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: 7 Jun 2006 17:41:29 -0700
From: richjungk@gmail.com
Subject: how to search through file for matching criteria
Message-Id: <1149727289.421759.71440@g10g2000cwb.googlegroups.com>
guys i really need help!!!
i'm a beginner in perl language.
for my code i want to look for matching criteria.
here is the contents of 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
search_alternative_coverage::N
car1_liability_coverage::500
car1_stats::No
renew::July
client_phone3::7509
driver1_status::S
driver1_conviction_1_month::01
p2::6740
driver1_conviction_1_year::2005
c1::KNGN
driver1_birth_month::03
driver1_license::G
car1_km::0
LANG::
driver1_insured::2000
driver1_sex::M
postal_code_2::1L5
driver1_suspensionend_year::2004
driver1_convictions::1
driver1_suspensionend_month::08
c3::RBC
b_c_flag::
HabDateCompany_month::01
city::BRAMPTON
driver1_convictiontype_1::Criminal=CD
driver1_insured_now::Y
how_find::Sun Newspaper
current_company::echelon
car1_annual_mileage::10000
car1_drivers::1
rate_alert_period::30
driver1_training::Y
postal_code::L6P
driver_number::1
driver1_claims::0
client_phone2::888
driver1_license_date_month::12
car_number::1
driver1_birth_day::15
car1_annual_mileage_business::0
driver1_G1_date_year::1999
driver1_G1_date_month::03
driver1_nonpayment::0
driver1_suspensionstart_month::05
p3::8973
car1_make::ACURA
client_name::Stan Duhan
c2::PAF
car1_collision_coverage::0
driver1_suspension::Y
car1_model::INTEGRA RS 2DR
client_email::get4life@hotmail.com
driver1_birth_year::1983
driver1_license_date_year::2003
car1_primary::1
client_phone1::416
driver1_first_name::Stan
driver1_retired::N
HabDateCompany_year::Not Applicable
car1_year::1991
driver1_G2_date_year::1999
AssumeMultiLine::N
car1_use::P
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
------------------------------
Date: Thu, 08 Jun 2006 02:32:02 GMT
From: "John W. Krahn" <someone@example.com>
Subject: Re: how to search through file for matching criteria
Message-Id: <C_Lhg.19911$A8.16973@clgrps12>
richjungk@gmail.com wrote:
> guys i really need help!!!
> i'm a beginner in perl language.
> for my code i want to look for matching criteria.
>
> here is the contents of 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
> search_alternative_coverage::N
> car1_liability_coverage::500
> car1_stats::No
> renew::July
> client_phone3::7509
> driver1_status::S
> driver1_conviction_1_month::01
> p2::6740
> driver1_conviction_1_year::2005
> c1::KNGN
> driver1_birth_month::03
> driver1_license::G
> car1_km::0
> LANG::
> driver1_insured::2000
> driver1_sex::M
> postal_code_2::1L5
> driver1_suspensionend_year::2004
> driver1_convictions::1
> driver1_suspensionend_month::08
> c3::RBC
> b_c_flag::
> HabDateCompany_month::01
> city::BRAMPTON
> driver1_convictiontype_1::Criminal=CD
> driver1_insured_now::Y
> how_find::Sun Newspaper
> current_company::echelon
> car1_annual_mileage::10000
> car1_drivers::1
> rate_alert_period::30
> driver1_training::Y
> postal_code::L6P
> driver_number::1
> driver1_claims::0
> client_phone2::888
> driver1_license_date_month::12
> car_number::1
> driver1_birth_day::15
> car1_annual_mileage_business::0
> driver1_G1_date_year::1999
> driver1_G1_date_month::03
> driver1_nonpayment::0
> driver1_suspensionstart_month::05
> p3::8973
> car1_make::ACURA
> client_name::Stan Duhan
> c2::PAF
> car1_collision_coverage::0
> driver1_suspension::Y
> car1_model::INTEGRA RS 2DR
> client_email::get4life@hotmail.com
> driver1_birth_year::1983
> driver1_license_date_year::2003
> car1_primary::1
> client_phone1::416
> driver1_first_name::Stan
> driver1_retired::N
> HabDateCompany_year::Not Applicable
> car1_year::1991
> driver1_G2_date_year::1999
> AssumeMultiLine::N
> car1_use::P
>
>
> 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.
Why an array?
> Put the array values into a hash to make them unique,
Why not just put them into a hash in the first place?
> and put the hash back into an array.
Why?
> Close the file.
>
>
> Reopen the file and loop through the array and create hashes for each
> driver to provide the following aggregate information:
There should be no need to read the file twice, you should be able to collect
all of the data you need in one pass.
> Number of:
> male drivers under age 25 with a conviction
> female drivers under age 25 with a conviction
You will probably need the Date::Calc module to calculate the age of the
driver from the birth date provided.
Something like this should work (UNTESTED):
#!/usr/bin/perl
use warnings;
use strict;
use Date::Calc 'Delta_YMD';
my $dir = 'directory path';
my $file = 'ID1234.txt';
chdir $dir or die "Cannot chdir '$dir' $!";
open my $fh, '<', $file or die "Cannot open '$file' $!";
my ( $today_year, $today_month, $today_day ) = ( localtime )[ 5,4,3 ];
$today_year += 1900;
$today_month++;
my ( %data, $current_driver );
while ( <$fh> ) {
if ( /^(driver\d+)_sex::([MF])/ ) {
$data{ $1 }{ sex } = $2;
}
if ( /^(driver\d+)_convictions::(\d+)/ ) {
$data{ $1 }{ convictions } = $2;
}
if ( /^(driver\d+)_birth_(year|month|day)::(\d+)/ ) {
$data{ $current_driver = $1 }{ $2 } = $3;
}
if ( exists $data{ $current_driver }{ year } and
exists $data{ $current_driver }{ month } and
exists $data{ $current_driver }{ day } ) {
my ( $delta_year, $delta_month, $delta_day ) =
Delta_YMD( @{ $data{ $current_driver } }{ qw/year month day/ },
$today_year, $today_month, $today_day );
$data{ $current_driver }{ age } =
$delta_month > 0 ? $delta_year
: $delta_day >= 0 ? $delta_year
: $delta_year - 1;
delete @{ $data{ $current_driver } }{ qw/year month day/ }
}
}
close $fh;
my %stats;
for my $driver ( keys %data ) {
$stats{ $data{ $driver }{ sex } }++
if $data{ $driver }{ convictions } and
$data{ $driver }{ age } < 25;
}
print <<STATS;
Number of:
male drivers under age 25 with a conviction is $stats{M}
female drivers under age 25 with a conviction is $stats{F}
STATS
__END__
John
--
use Perl;
program
fulfillment
------------------------------
Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>
Administrivia:
#The Perl-Users Digest is a retransmission of the USENET newsgroup
#comp.lang.perl.misc. For subscription or unsubscription requests, send
#the single line:
#
# subscribe perl-users
#or:
# unsubscribe perl-users
#
#to almanac@ruby.oce.orst.edu.
NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
#To request back copies (available for a week or so), send your request
#to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
#where x is the volume number and y is the issue number.
#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V10 Issue 9261
***************************************