#!/usr/local/bin/perl sub density { local($line, $char) = @_; local($num); @junk = split(/$char/, $line); $num = $#junk; $num++ if ($line =~/^$char/); $num++ if ($line =~/$char$/); return sprintf("%3.2f \n", $num / length($line)); } print &density("This is a test", 't'); print &density("This is a test", 'a');
local()
operator.
When a subroutine is called with arguments, they are stored in a
special array variable @_
. Typically a subroutine will
grab its arguments and store them in local variables.
Comments to:
webmaster@geom.umn.edu
Created: May 08 1996 ---
Last modified: May 29 1996