我在进行简单的搜索和替换时遇到了很多麻烦.我尝试了如何在Perl字符串中删除空格中提供的解决方案 ? 但无法打印出来.
这是我的示例代码:
#!/usr/bin/perl
use strict;
my $hello = "hello world";
print "$hello\n"; #this should print out >> hello world
#now i am trying to print out helloworld (space removed)
my $hello_nospaces = $hello =~ s/\s//g;
#my $hello_nospaces = $hello =~ s/hello world/helloworld/g;
#my $hello_nospaces = $hello =~ s/\s+//g;
print "$hello_nospaces\n"
#am getting a blank response when i run this.
Run Code Online (Sandbox Code Playgroud)
我尝试了几种不同的方式,但我无法做到这一点.
我的最终结果是自动化在Linux环境中移动文件的某些方面,但有时文件名称中有空格,所以我想从变量中删除空格.