Perl regex extracting a match using braces -
i tested following code
#! /usr/bin/perl use strict; use english; #this code extracts current scripts filename #by removing path filepath $script_name = $program_name; ${script_name} =~ s/^.*\\//; #windows path #${script_name} =~ s/^.*\///; #unix based path print $script_name; and don't understand why these braces extract match without using /r modifier. can explain why , how works or point me documentation?
you're getting little confused!
the braces make no difference. ${script_name} identical $script_name.
you code first copies entire path script file $program_name $script_name.
then substitution removes , including last backslash, leaving file name.
the /r modifier used if wanted modify 1 string , put result of modification another, write code in 1 step as
$script_name = $program_name=~ s/^.*\\//r
Comments
Post a Comment