constant string in regular expression

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Michael Kiermaier

    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
  • Eric J. Roode

    #2
    Re: constant string in regular expression

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

    michael.kiermai er@gmx.net (Michael Kiermaier) wrote in
    news:72be1fd1.0 307120743.17033 888@posting.goo gle.com:
    [color=blue]
    > 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".[/color]

    Use the Readonly module instead:

    use Readonly;
    Readonly::Scala r 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/AwUBPxBRcGPeouI eTNHoEQKZ+ACgww aPHeGVyuvsaUQvD I2ZaKeVj/AAn10a
    /JHas78d/UX1jVjAPOz9NpTD
    =7rut
    -----END PGP SIGNATURE-----

    Comment

    • Eric J. Roode

      #3
      Re: constant string in regular expression

      michael.kiermai er@gmx.net (Michael Kiermaier) wrote in
      news:72be1fd1.0 307120743.17033 888@posting.goo gle.com:
      [color=blue]
      > 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".[/color]

      Use the Readonly module instead:

      use Readonly;
      Readonly::Scala r 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

      Comment

      Working...