Harry Putnam <[EMAIL PROTECTED]> wrote:
:
: "R. Joseph Newton" <[EMAIL PROTECTED]> writes:
:
: > > Something like:
: > > [...] snipped getopts and other unrelated stuff
: > > while(<FILE>){
: > > chomp;
: > > my $line = $_;
: >
: > Why here. Since you are doing this with each line,
: > you could write in the loop control:
: > while (my $line = <FILE>) {
:
: Not sure I understand the advantage. In my
: formulation, `$line' is minus the trailing newline...
: which I've found to be nearly always a plus.
I think Joseph was implying the 'chomp'. This is
still shorter and IMO clearer than using $_.
while ( my $line = <FILE> ) {
chomp $line;
: > > ## @hdregs is an array of several regex for the
: > > ## headers
: > > for($ii=0;$ii<=$#hdregs;$ii++){
: >
: > Why no space between clauses? Why no space around assignment
: > operators?
:
: Just how I've become accustomed to writing code.
: Probably not a good plan for when others need to read and
: revise it.
:
: > Why a C-style for loop? Are you using the index somewhere?
:
: Well yes, sort of.
Assuming a non-C maintainer comes along, I would
recommend the following. The C-style loop is confusing
to those of us who don't have a background in C. This
is very clear (to me).
foreach my $ii ( 0 .. $#hdregs ) {
: I wanted a way to ensure that each reg has hit at
: least once. Otherwise we don't print. So I used a
: formulation like this (Not posted previously for
: clarity):
:
: if ($data{$hdregs[$ii]}++ == 0) {
: ## it will only be 0 once
: $hdelem_hit_cnt++;
: }
: Then before printing we compare $hdelem_hit_cnt to
: ($#hdregs + 1):
:
: sub test_hdr_good {
: if ($hdelem_hit_cnt == ($#hdregs + 1)) {
: $test_hdr_good = "TRUE";
: $hdelem_hit_cnt = 0;
Generally, global variables should raise a giant,
blinking, annoying sign telling us we an are no
longer in Kansas.
: }
: }
:
: They should be the same if all regs have hit at least
: once. If not the same... we don't print.
Actually, they should be the same if all regs were
hit /only/ once.
Depending on where the 'if' block is located, this
is a roundabout way to test that @hdregs is an array of
unique values. It would be similar to this outside the
'for' loop.
my $test_hdr_good = is_unique( [EMAIL PROTECTED] ) ? 'TRUE' : 'FALSE';
sub is_unique {
my $array_ref = shift;
my %hash;
@hash{ @$array_ref }++;
return keys %hash == @$array_ref;
}
But as Randy mentioned, some mail headers are allowed
to appear more than once. Thus making this test invalid.
HTH,
Charles K. Clarkson
--
Mobile Homes Specialist
254 968-8328
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>