Thanks Cripps & Members,
What should be the way to simplify the undermentioned working code as Part 1
and part 2 are repetition.
@array = qw ( hello world hello how are you );
$match = 'HEllo';
print "Your search for $match return ";
&count;
print " records<br>\n";
## part 1 ##
foreach $record (@array){
if (grep /$match/i, $record) {
print "$record<br>";
};
};
## part 2 ##
sub count {
$count =0;
foreach $record (@array){
if (grep /$match/i, $record) {
$count++;
};
};
print $count;
};
#### end of script #####
----- Original Message -----
From: "J.E. Cripps" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Cc: <[EMAIL PROTECTED]>
Sent: Friday, November 16, 2001 4:17 PM
Subject: Re: [PBML] sub-routine help needed.
>
> Given this code:
> > 1. @array = qw ( hello world hello how are you );
> > 2. $match = 'HEllo';
> > 3. print "Your search for $match returns $subroutine $count
> > records<br>\n";
> > $subroutine = &count;
> > sub count {
> > foreach $record (@array){
> > if (grep /$match/i, $record) {
> > print $record;
> > $count++;
> > };
> > };
> > };
>
>
> One of us lamented:
> > Sigh ! My mind simply refuses to work. What must I do to print the
number of
> > records $count in line 3.
>
> Put one line of code earlier in the script. You're getting an
> "uninitialized variable" msg. That's because one of the
> variables in the print statement is undef. Think about
> where it gets its value.
>
> > Thanks
>
> You're welcome. JEC.
>
> P.S. Read up on the "use strict" pragma for next post.
>
_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]