0

I tested the following code

#! /usr/bin/perl 

use strict;
use English;

#this code extracts the current scripts filename 
#by removing the path from the filepath

my $Script_Name = $PROGRAM_NAME;

${Script_Name} =~ s/^.*\\//; #windows path

#${Script_Name} =~ s/^.*\///; #Unix based path

print $Script_Name;

and i don't understand why these braces extract the match without using a /r modifier. can anyone explain why and how this works or point me to some documentation?

4

1 回答 1

0

你开始有点糊涂了!

牙套没什么区别。${Script_Name}与 相同$Script_Name

您的代码首先将脚本文件的整个路径从 复制$PROGRAM_NAME$Script_Name.

然后替换删除所有内容,包括最后一个反斜杠,只留下文件名。

如果您想修改一个字符串并将修改结果放入另一个字符串,则将使用/r修饰符,因此您可以一步编写代码

$Script_Name = $PROGRAM_NAME=~ s/^.*\\//r
于 2013-04-18T17:56:07.797 回答