constant string in regular expression

Discussion in 'Perl' started by Michael Kiermaier, Jul 12, 2003.

  1. 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, Jul 12, 2003
    #1
    1. Advertising

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

    (Michael Kiermaier) wrote in
    news::

    > 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-----
     
    Eric J. Roode, Jul 12, 2003
    #2
    1. Advertising

  3. (Michael Kiermaier) wrote in
    news::

    > 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
     
    Eric J. Roode, Jul 13, 2003
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. VSK
    Replies:
    2
    Views:
    2,349
  2. Replies:
    13
    Views:
    13,002
    Kai-Uwe Bux
    Jan 22, 2007
  3. Philipp
    Replies:
    26
    Views:
    2,380
    Ramon F Herrera
    Nov 25, 2007
  4. Adem
    Replies:
    42
    Views:
    2,851
    James Kuyper
    Nov 4, 2008
  5. Fritz Bayer

    Conditional constant in regular expression

    Fritz Bayer, Apr 9, 2005, in forum: Perl Misc
    Replies:
    7
    Views:
    200
    Fritz Bayer
    Apr 10, 2005
Loading...

Share This Page