I have seen this perl
code on the cpan
documentation for a module:
$filename =~ s[^.+/][];
What does this mean? I am used to the s//
notation for the s
function.
Perl allows any non-whitespace character to be used as a string delimiter. See Quote and Quote-like Operators
Bracketing characters are used in pairs, like <...>
, [...]
, (...)
, and {...}
, while single-quotes prevent interpolation. Otherwise the functionality is identical to that of the default delimiter
In this case
$filename =~ s[^.+/][]
is the same as
$filename =~ s/^.+\///
but is far more readable
I tend to prefer the pipe character |
which looks similar to the usual slash
$filename =~ s|^.+/||
but the choice is up to you
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With