Go Back   Velocity Reviews > Newsgroups > PERL
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply

PERL - constant string in regular expression

 
Thread Tools Search this Thread
Old 07-12-2003, 04:43 PM   #1
Default constant string in regular expression


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


Michael Kiermaier
  Reply With Quote
Old 07-12-2003, 07:20 PM   #2
Eric J. Roode
 
Posts: n/a
Default Re: constant string in regular expression

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

(Michael Kiermaier) wrote in
news: om:

> 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+ACgwwaPHeGVyuvsaUQvDI2ZaK eVj/AAn10a
/JHas78d/UX1jVjAPOz9NpTD
=7rut
-----END PGP SIGNATURE-----
  Reply With Quote
Old 07-13-2003, 05:25 PM   #3
Eric J. Roode
 
Posts: n/a
Default Re: constant string in regular expression

(Michael Kiermaier) wrote in
news: om:

> 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




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


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump