Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > regexp

Reply
Thread Tools

regexp

 
 
Alexandre Jaquet
Guest
Posts: n/a
 
      02-23-2005
Hi does someone could clear my mind and tell me what would mean :

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

thx in advance
 
Reply With Quote
 
 
 
 
Arndt Jonasson
Guest
Posts: n/a
 
      02-23-2005

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...
 
Reply With Quote
 
 
 
 
Gunnar Hjalmarsson
Guest
Posts: n/a
 
      02-23-2005
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
 
Reply With Quote
 
Anno Siegel
Guest
Posts: n/a
 
      02-23-2005
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
 
Reply With Quote
 
Alexandre Jaquet
Guest
Posts: n/a
 
      02-23-2005
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 =)
 
Reply With Quote
 
Anno Siegel
Guest
Posts: n/a
 
      02-24-2005
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
 
Reply With Quote
 
 
 
Reply

Thread Tools

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
new RegExp().test() or just RegExp().test() Matìj Cepl Javascript 3 11-24-2009 02:41 PM
[regexp] How to convert string "/regexp/i" to /regexp/i - ? Joao Silva Ruby 16 08-21-2009 05:52 PM
Ruby 1.9 - ArgumentError: incompatible encoding regexp match(US-ASCII regexp with ISO-2022-JP string) Mikel Lindsaar Ruby 0 03-31-2008 10:27 AM
Programmatically turning a Regexp into an anchored Regexp Greg Hurrell Ruby 4 02-14-2007 06:56 PM
RegExp.exec() returns null when there is a match - a JavaScript RegExp bug? Uldis Bojars Javascript 2 12-17-2006 09:50 PM



Advertisments