regexp

Discussion in 'Perl Misc' started by Alexandre Jaquet, Feb 23, 2005.

  1. Hi does someone could clear my mind and tell me what would mean :

    $loop_hs =~ s/\$HTML{\'$noteval\'}/\*HTML{\'$noteval\'}/g;

    thx in advance
    Alexandre Jaquet, Feb 23, 2005
    #1
    1. Advertising

  2. Alexandre Jaquet <> writes:
    > Hi does someone could clear my mind and tell me what would mean :
    >
    > $loop_hs =~ s/\$HTML{\'$noteval\'}/\*HTML{\'$noteval\'}/g;


    It assumes that the variable $noteval has a value; let's say it contains
    "foo".

    Then the statement takes the string $loop_hs and in it replaces all
    occurrences of the character '$' with '*' when they are followed by
    "HTML{'foo'}".

    I imagine "noteval" is to be read "not eval[uate]".

    I don't know if that will clear your mind...
    Arndt Jonasson, Feb 23, 2005
    #2
    1. Advertising

  3. Arndt Jonasson wrote:
    > Alexandre Jaquet <> writes:
    >> Hi does someone could clear my mind and tell me what would mean :
    >>
    >> $loop_hs =~ s/\$HTML{\'$noteval\'}/\*HTML{\'$noteval\'}/g;

    >
    > It assumes that the variable $noteval has a value; let's say it contains
    > "foo".
    >
    > Then the statement takes the string $loop_hs and in it replaces all
    > occurrences of the character '$' with '*' when they are followed by
    > "HTML{'foo'}".


    Since there are several redundant backslashes, i.e.

    $loop_hs =~ s/\$HTML{'$noteval'}/*HTML{'$noteval'}/g;

    would do the same, it also means that the programmer isn't very good at
    regular expressions in Perl. ;-)

    --
    Gunnar Hjalmarsson
    Email: http://www.gunnar.cc/cgi-bin/contact.pl
    Gunnar Hjalmarsson, Feb 23, 2005
    #3
  4. Alexandre Jaquet

    Anno Siegel Guest

    Alexandre Jaquet <> wrote in comp.lang.perl.misc:
    > Hi does someone could clear my mind and tell me what would mean :
    >
    > $loop_hs =~ s/\$HTML{\'$noteval\'}/\*HTML{\'$noteval\'}/g;


    Where did you get that? Whoever wrote it doesn't know Perl very well,
    evidenced by the use of unnecessary escapes. "'" is not special in a
    regex, so

    s/\$HTML{'$noteval'}/\*HTML{'$noteval'}/g;

    would do the same thing.

    What it *means* is impossible to say without context.

    What it *does* is basically change dollar signs ($) to asterisks (*)
    if the conditions are right. The conditions depend on the content of
    $loop_hs and $noteval.

    Example for the right conditions:

    my $loop_hs = q($HTML{'XXX'});
    my $noteval = 'XXX';
    print "$loop_hs -> ";
    $loop_hs =~ s/\$HTML{'$noteval'}/\*HTML{'$noteval'}/g;
    print "$loop_hs\n"; # $HTML{'XXX'} -> *HTML{'XXX'}

    Anno
    Anno Siegel, Feb 23, 2005
    #4
  5. Anno Siegel a écrit :
    > Alexandre Jaquet <> wrote in comp.lang.perl.misc:
    >
    >>Hi does someone could clear my mind and tell me what would mean :
    >>
    >>$loop_hs =~ s/\$HTML{\'$noteval\'}/\*HTML{\'$noteval\'}/g;

    >
    >
    > Where did you get that? Whoever wrote it doesn't know Perl very well,
    > evidenced by the use of unnecessary escapes. "'" is not special in a
    > regex, so
    >
    > s/\$HTML{'$noteval'}/\*HTML{'$noteval'}/g;
    >
    > would do the same thing.
    >
    > What it *means* is impossible to say without context.
    >
    > What it *does* is basically change dollar signs ($) to asterisks (*)
    > if the conditions are right. The conditions depend on the content of
    > $loop_hs and $noteval.
    >
    > Example for the right conditions:
    >
    > my $loop_hs = q($HTML{'XXX'});
    > my $noteval = 'XXX';
    > print "$loop_hs -> ";
    > $loop_hs =~ s/\$HTML{'$noteval'}/\*HTML{'$noteval'}/g;
    > print "$loop_hs\n"; # $HTML{'XXX'} -> *HTML{'XXX'}
    >
    > Anno


    thanks guyz =)
    Alexandre Jaquet, Feb 23, 2005
    #5
  6. Alexandre Jaquet

    Anno Siegel Guest

    Abigail <> wrote in comp.lang.perl.misc:
    >
    > I'd write it as:
    >
    > $loop_hs =~ s/\$(?=HTML{'$noteval'}/*/g;


    You'd close the parenthesis:

    $loop_hs =~ s/\$(?=HTML{'$noteval'})/*/g;

    Anno
    Anno Siegel, Feb 24, 2005
    #6
    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. Greg Hurrell
    Replies:
    4
    Views:
    152
    James Edward Gray II
    Feb 14, 2007
  2. Mikel Lindsaar
    Replies:
    0
    Views:
    467
    Mikel Lindsaar
    Mar 31, 2008
  3. Joao Silva
    Replies:
    16
    Views:
    344
    7stud --
    Aug 21, 2009
  4. Uldis  Bojars
    Replies:
    2
    Views:
    186
    Janwillem Borleffs
    Dec 17, 2006
  5. Matìj Cepl

    new RegExp().test() or just RegExp().test()

    Matìj Cepl, Nov 24, 2009, in forum: Javascript
    Replies:
    3
    Views:
    171
    Matěj Cepl
    Nov 24, 2009
Loading...

Share This Page