Greg Sheridan wrote:
Hi everyone,

Hello,

I'm new to this list and I have a very basic question about
regular expressions.

Perl provides some documentation on regular expressions that should be installed on your hard drive.

perldoc perlrequick
perldoc perlretut
perldoc perlre

Also, documentation on the match (m//), substitution (s///) and
transliteration (tr///) operators can be found in the perlop.pod document.

perldoc perlop


I inherited a Perl script, and I'm trying to figure out what a specific line does.
Here's the line:
$dose_density =~ s/[A-Za-z\/ ]//g;

The regular expression consists of a character class, a list of characters inside the [] brackets. The list of characters also includes ranges of characters A-Z and a-z which means all characters in the range inclusive in the current character set. For example in ASCII, A-Z will produce the list ABCDEFGHIJKLMNOPQRSTUVWXYZ. The character class matches one of the characters in the list to the contents of $dose_density.

The regular expression is being used by the substitution operator which
replaces the string matched by the regular expression with an empty string and
does it for every match in the string because of the /g global option.

It would be more efficient to make the match longer instead of matching and
replacing individual characters:

$dose_density =~ s![A-Za-z/ ]+!!g;

And it would be more efficient still to not use a regular expression at all:

$dose_density =~ tr!A-Za-z/ !!d;



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