Perl rename utility assistance

parv at pair.com parv at pair.com
Fri Dec 19 01:35:43 UTC 2014


in message <201412171838.sBHIcOht031153 at host203.r-bonomi.com>,
wrote Robert Bonomi thusly...
>
...
> Your regex "^[:digit:]_" says:
>            "^"             start at the beginning of the name
>             "[:digit:]"    match one character from the following list ':digt'
>                      "_"   match an underscore
>
> For some strange reason, this does not cause a match where there
> are leading digits, .
> to match a single character in the range '0'-'9', the syntax is
> '[[digit:]]'
...

The proper character class to match a digit is "[[:digit:]]",
similar to "[0-9]". Pattern "[:digit:]" is to match numbers in the
locale set, to match any number not just those in range "0-9"
(ASCII).

When run with "warnings" pragma when trying to match /^[:digit:]/,
the problem is shown  ...

  perl -Mwarnings -e 'my $x = q[234y] ; print $x =~ m/^([:digit:])/ '
  POSIX syntax [: :] belongs inside character classes in regex; \
  marked by <-- HERE in m/^([:digit:] <-- HERE )/ at -e line 1.


... (mind that nothing is printed as nothing was matched, but not
due to the warning message itself).


Run the above with "diagnostics" pragma for more information ....

  perl -Mdiagnostics -Mwarnings -e ' ... '


On a side note ...

  perl -Mwarnings -e 'my $x = q[xyz] ; $x =~ s/x(y)/y\1/ ; print $x'
  \1 better written as $1 at -e line 1.
  yyz


-- 



More information about the freebsd-questions mailing list