Thread Array, Match und $1 (14 answers)
Opened by IceRage at 2011-09-22 22:54

pq
 2011-09-23 01:02
#152604 #152604
User since
2003-08-04
12208 Artikel
Admin1
[Homepage]
user image
was mir gleich als erstes auffällt: ein globales matching, also mit /g, im skalaren kontext auszuführen ist sicher nicht gewollt, oder?
ein globales matching funktioniert im skalaren kontext so, dass bei jedem aufruf der nächste match versucht wird.

also wozu benutzt du das /g?

kleine demo:
Code: (dl )
1
2
3
4
5
6
7
8
9
10
11
12
$ perl -wE'
$_ = "foo bar baz";
m/(\w{3})/g;
say $1;
m/(\w{3})/g;
say $1;
m/(\w{3})/g;
say $1;
'
foo
bar
baz
Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live. -- Damian Conway in "Perl Best Practices"
lesen: Wiki:Wie frage ich & perlintro Wiki:brian's Leitfaden für jedes Perl-Problem

View full thread Array, Match und $1