constant string in regular expression

M

Michael Kiermaier

hello!

i am new to perl. i searched the online documentation for this
problem, but i didn't find an answer.

here is a part of my code:

[...]
use constant _GROUP => "gruppe";
[...]
if ($configLine =~ /^\s*_GROUP\s+(.+?)\s*$/) {
[...]

of couse in the regexp the character sequence _GROUP does not get
replaced, but i want that it is regarded as the name of the constant
and therefore replaced by "gruppe".

i hope that my post is understandable enough.

many thanks in advance,

~michael
 
E

Eric J. Roode

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

(e-mail address removed) (Michael Kiermaier) wrote in
here is a part of my code:

[...]
use constant _GROUP => "gruppe";
[...]
if ($configLine =~ /^\s*_GROUP\s+(.+?)\s*$/) {
[...]

of couse in the regexp the character sequence _GROUP does not get
replaced, but i want that it is regarded as the name of the constant
and therefore replaced by "gruppe".

Use the Readonly module instead:

use Readonly;
Readonly::Scalar my $_GROUP => "gruppe";
....
if ($configLine =~ /\s*$_GROUP\s+(.+?)\s*$/) {
....

- --
Eric
$_ = reverse sort qw p ekca lre Js reh ts
p, $/.r, map $_.$", qw e p h tona e; print

-----BEGIN PGP SIGNATURE-----
Version: PGPfreeware 7.0.3 for non-commercial use <http://www.pgp.com>

iQA/AwUBPxBRcGPeouIeTNHoEQKZ+ACgwwaPHeGVyuvsaUQvDI2ZaKeVj/AAn10a
/JHas78d/UX1jVjAPOz9NpTD
=7rut
-----END PGP SIGNATURE-----
 
E

Eric J. Roode

(e-mail address removed) (Michael Kiermaier) wrote in
hello!

i am new to perl. i searched the online documentation for this
problem, but i didn't find an answer.

here is a part of my code:

[...]
use constant _GROUP => "gruppe";
[...]
if ($configLine =~ /^\s*_GROUP\s+(.+?)\s*$/) {
[...]

of couse in the regexp the character sequence _GROUP does not get
replaced, but i want that it is regarded as the name of the constant
and therefore replaced by "gruppe".

Use the Readonly module instead:

use Readonly;
Readonly::Scalar my $_GROUP => "gruppe";
....
if ($config
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top