in reply to matching the line which has special characters in it
my $seek = '@#]$%(*&Y^%'; my $test = 'This is a test to look for @#]$%(*&Y^% in text data'; print "found it\n" if ( $test =~ /\Q$seek\E/ );
Update: I realized I answered only part of your question. It looks like you can minimize the regex and substitution to just this:
But if that pattern occurs next to things other than "utime(", and you need to restrict the pattern more carefully, then you need to handle the parens -- a couple ways come to mind:s/(STARTDATE &) (STARTTIME)/$1 " " & $2/;
In any case, don't bother making the regex match string any longer than it needs to be.# don't try to match the paren explicitly -- use "." instead: s/(utime.STARTDATE &) (STARTTIME)/$1 " " & $2/; # or match it explicity, with an escape: s/(utime\(STARTDATE &) (STARTTIME)/$1 " " & $2/;
|
|---|