I've made a function in perl script, and given three-parameter to replace words. I want to replace space with tabs, but it failed.
The command is below. perl ./test.pl " " "\t" "aaa"
#!/usr/bin/perl
my($from,$to,$file)=@ARGV;
while(<RH>){
my $str = $_;
$str =~ s/$from/$to/g;
print WH "$str";
}
The result is not expected.
aaa bbb Oct-12-20:21 → aaa\tbbb\tOct-12-20:21
CodePudding user response:
As written in the comments, modify your command to pass a tab instead of the characters \t
. If you are using Bash, you could for example use this command:
perl test.pl " " $'\t' aaa