Thread Regex bei tr (2 answers)
Opened by bianca at 2010-01-31 17:00

bianca
 2010-01-31 17:00
#131659 #131659
User since
2009-09-13
6977 Artikel
BenutzerIn

user image
Kurze Frage zum Regex bei tr
Normalerweise darf man doch das Minus innerhalb eckiger Klammern am Anfang oder Ende ohne Backslash verwenden, richtig?

Wenn ich das aber innerhalb von tr versuche kommt das hier:

Code: (dl )
1
2
3
4
5
6
7
8
Ambiguous range in transliteration operator at test14.pl line 7 (#1)
(F) You wrote something like tr/a-z-0// which doesn't mean anything at
all. To include a - character in a transliteration, put it either
first or last. (In the past, tr/a-z-0// was synonymous with
tr/a-y//, which was probably not what you would have expected.)

Uncaught exception from user code:
Ambiguous range in transliteration operator at test14.pl line 7.


Da steht ja, dass ich das Minus an den Anfang oder an das Ende packen muss, was ich getan habe.

Was soll mir diese Fehlermeldung sagen?

Test:

Code (perl): (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
#!/usr/bin/perl -w
use strict;
use warnings;
use diagnostics;

my $string = '-12,89';
if (($string =~ tr/[0-9-]//c) > 1) {
        print "Zuviel Muell drin!\n";
}


if ($string =~ /[0-9-]/) {
        print "Ja, Zahlen und/oder Minus drin!\n";
}


Danke
10 print "Hallo"
20 goto 10

View full thread Regex bei tr