S [] [] notation in perl

I saw this perlcode in the documentation cpanfor the module:

$filename =~ s[^.+/][];

What does it mean? I use notation s//for function s.

+4
source share
2 answers

Perl allows you to use any character without spaces as a line separator. See Quotations and query-like operators.

Breketingovye symbols are used in pairs, such as <...>, [...], (...)and {...}, while the single quotes prevent the interpolation. Otherwise, the functionality is identical to the default separator functionality.

In this case

$filename =~ s[^.+/][]

coincides with

$filename =~ s/^.+\///

but much more readable

|,

$filename =~ s|^.+/||

+10

. - , - , , . , , :

$filename =~ s/^.+\///;

, , . , , .

0