David Buddrige wrote:
>
> Hi all,
Hello,
> I have a bunch of C++ source files that contain the string
>
> PCN: sometext
>
> where somtext is an arbitary sequence of characters.
>
> Whenever the text "PCN:" occurs, I want to remove it and everything else
> to the end of the line.
>
> To do this, I have written the following script:
>
> while(<>)
> {
> my $current_line;
>
> $current_line = $_;
> $current_line =~ s/PCN:[.]*//g;
>
> print $current_line;
> }
>
> However this only removes the "PCN:" part, leaving the rest of the
> string that occurs between the PCN: and the new-line undisturbed. Is
> there some way that I can tell perl that I want it to remove everything
> from PCN: onwards to the end of the line?
Putting the period in a character class [.] means to match a literal
period character. You want to use the dot metacharacter that matches
any character except newline.
while ( my $current_line = <> )
{
$current_line =~ s/PCN:.*//;
print $current_line;
}
John
--
use Perl;
program
fulfillment
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]