avatar
f*y
1
#!/usr/bin/perl
$line = "one two three...";
print "$line\n";
$line =~ s/^([^ ]+) +([^ ]+)/$2 $1/;
print "$line\n";
avatar
w*n
2

[^ ] stands for one char which is not space.
the third line reads like: find a token (one or more non space chars),
one or more spaces, and another token, and change them to the second
token ($2), space and the first token ($1).
+ stands for one or more, () are used to capture, everything matched
in the first () is stored in $1, $2 for the second (). BTW, the ^ at
the beginning of RE stands for match beginning of the string ($line).
get a perl book or "man perlre" for details.

【在 f***y 的大作中提到】
: #!/usr/bin/perl
: $line = "one two three...";
: print "$line\n";
: $line =~ s/^([^ ]+) +([^ ]+)/$2 $1/;
: print "$line\n";

相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。