in reply to Regular Expression Help

With all due respect to jlistf, there were a couple of problems with his solution. Here's one that's easy to understand:
if ($filename =~ /^[A-Z]{5}/) { ($section_title = $filename) =~ s!:!:</B>\n<BR><BR>!; $filename = ""; }
For $filename, we're just testing for the first five letters, so the {5,} syntax just makes the regex engine do more work.

For the actual substitution, the slash in </B> needs to be escaped unless we choose different delimiters like I have above.

Also, we can't do

$section_title = ($filename =~ s/?[:]./':</B>\n< BR>< B>\n');
because the substitution returns a true/false value and if successful, $section_title receives a value of 1. The assignment to $section_title needs to be on a different line or assigned to as above (that's from a suggestion by KM).

Cheers,
Ovid

Update: Cleaned up the code in response to KM's point.

Replies are listed 'Best First'.
RE: (Ovid) RE: Regular Expression Help
by KM (Priest) on Aug 11, 2000 at 21:02 UTC
    You can do:

    ($section_title = $filename) =~ s!:!:</B>\n<BR><BR>!;

    This will set $section_title to the substituted value of $filename, and leave $filename unmodified.

    Cheers,
    KM