regexp

A

Alexandre Jaquet

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

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

thx in advance
 
A

Arndt Jonasson

Alexandre Jaquet said:
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...
 
G

Gunnar Hjalmarsson

Arndt said:
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. ;-)
 
A

Anno Siegel

Alexandre Jaquet said:
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
 
A

Alexandre Jaquet

Anno Siegel a écrit :
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 =)
 

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,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top