next up previous
Next: 4. Modules Up: 6. What Perl looks Previous: 2. Control constructs

3. Regular expressions

Regular expressions are easy with Perl:

while (<>) {		# read stdin
	s/foo/bar/g;	# replace foo with bar globally

# We can use any character to delimit regexps, for ease of reading,
# especially when dealing with directories, URLs, etc:

print "Using source directory..." if ($directory = m#/src/#);
$directory =~ s!/usr/bin!/usr/local/bin!;

Kirrily Robert