in reply to Inline substitution regex
Your second question:#!/usr/bin/perl -w use strict; my $text = "this text"; $text =~ /this/that; #### WRONG syntax ##### print $text; #------ Bareword found where operator expected at C:\TEMP\temp1.pl line 5, near "/this/that" (Missing operator before that?) syntax error at C:\TEMP\temp1.pl line 5, near "/this/that" Execution of C:\TEMP\temp1.pl aborted due to compilation errors. =============================================== #!/usr/bin/perl -w use strict; my $text = "this text"; $text =~ s/this/that/; #note s needed as well as '/' after "that" print $text; #prints: that text
The result of a match is True/False. print $text =~ m/this/; is the same thing.my $text = "this text"; print $text =~ /this/;
Update:#match can be used like a boolean T/F if($text =~ m/this/) { blah ...}
$text =~ /this/ vs $text =~ m/this/ is a matter of style. When using the default '/' you can leave off the "m". if you use a different character to delimit the match, say $text =~ m|this|;, then you definitely need the "m".
|
|---|