[EMAIL PROTECTED] wrote:
Assign each line to the $_ variable and try this to get the number of
instances of < and >

The match operator works on $_ by default. If you match on < or > globally
and assign it to an array like so:

@rights = m/\</g;
@lefts = m/\>/g;

See the FAQ for a more efficient way to do this.

perldoc -q "How can I count the number of occurrences of a substring within a string"


You are left with arrays that contain all the matches. Now all you need to
do is count the number of elements in each array like so:

$number_of_rights = $#rights;
$number_of_lefts = $#lefts;

An array in scalar context returns the number of elements in that array. You are using the index of the last element of the array which *may* (or may not!) be one less than the number of elements.



John -- use Perl; program fulfillment

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>




Reply via email to