Perl s Function
Advertisements
Description
This is not a function. This is the regular expression-substitution operator. Based on the regular expression specified in PATTERN, data is replaced by REPLACE. Like m//, the delimiters are defined by the first character following s.
Syntax
Following is the simple syntax for this function −
s/PATTERN/REPLACE/
Return Value
This function returns 0 on failure and number of substitutions made on success.
Example
Following is the example code showing its basic usage −
Live Demo#!/usr/bin/perl -w $string = "This is Test"; # this will replcase Test with Best. $string =~ s/Test/Best/; print "$string\n";
When above code is executed, it produces the following result −
This is Best
perl_function_references.htm
Advertisements