我在进行一个简单的搜索和替换时遇到了很多麻烦。我尝试了如何在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.
我尝试了几种方法,但都不能达到目标。
我的最终目标是自动化Linux环境中文件移动的某些方面,但有时文件名中会有空格,因此我想从变量中删除空格。