substitute char

A

alexjaquet

Hi,

I got a little trouble when I'm been trying to replace char & by &
example :
local our $entities = '&';
$OPTIONS{'category'} =~ s/[&]/$entities/eg;

but the result still doesn't contain &

any idea

thks
 
G

Gunnar Hjalmarsson

I got a little trouble when I'm been trying to replace char & by &
example :
local our $entities = '&';
$OPTIONS{'category'} =~ s/[&]/$entities/eg;
----------------------------^-^-----------^
Why the character class?
Why the /e modifyer?
but the result still doesn't contain &

Please post a short but complete program that people can copy and run,
and that demonstrates your observation, just as is recommended in the
posting guidelines for this Usenet group:
http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html
 
P

Paul Lalli

Hi,

I got a little trouble when I'm been trying to replace char & by &
example :
local our $entities = '&';
$OPTIONS{'category'} =~ s/[&]/$entities/eg;

but the result still doesn't contain &

any idea

Yes. You're doing something wrong. Actually, you're doing several
somethings wrong. However, you have not provided enough code for us to
determine *all* of them. The only ones we can determine are not a part
of your problem. Your problems:
1) The character class is not needed
2) The /e modifier is not needed
3) Unknown, because you haven't shown the relevant code.

We can determine that there is a 3) by creating a short-but-complete
program which models your situation and examining the results, like so:
#!/usr/bin/env perl
use strict;
use warnings;

my $entities = '&';
my $string = 'foo&bar';
$string =~ s/[&]/$entities/ge;
print "String: $string\n";
__END__
String: foo&bar

Clearly, there is something else going on, and you have misdiagnosed
the problem. You should be interested to know that if you had read the
Posting Guidelines for this group, you would have already taken this
step and saved yourself a lot of time.

Please go read those posting guidelines now, and post again if you
still can't figure out your problem.

Paul Lalli
 
T

Tad McClellan

I got a little trouble when I'm been trying to replace char & by &


What if the data is:

larry & moe & curly

you want to change it to:

larry & moe & curly

??


There is probably a module that will do it right, but we can't
recommend one, because you haven't told us what kind of data
you are really processing. HTML? XML? other?

local our $entities = '&';


I've asked you this before, but I don't think you responded, so in
an effort to repair your obvious misunderstanding, I'll try asking
once again:

You should always prefer lexical variables over package variables,
except when you can't.

Why do you think that you cannot use lexical variables there?

my $entities = '&';

would work just as well, or better.



Post a short and complete program that we can run that illustrates
your problem, and we will surely be able to help you fix it.
 
R

robic0

What if the data is:

larry & moe & curly

you want to change it to:

larry & moe & curly

??


There is probably a module that will do it right, but we can't
recommend one, because you haven't told us what kind of data
you are really processing. HTML? XML? other?




I've asked you this before, but I don't think you responded, so in
an effort to repair your obvious misunderstanding, I'll try asking
once again:

You should always prefer lexical variables over package variables,
except when you can't.

Why do you think that you cannot use lexical variables there?

my $entities = '&';

would work just as well, or better.




Post a short and complete program that we can run that illustrates
your problem, and we will surely be able to help you fix it.

Whats a "lexical" variable Tad? Is it a variable in-scope or out?
Or, is it a expensive car you can buy? No, thats a Lexus.
 
P

Paul Lalli

robic0 said:
Whats a "lexical" variable Tad? Is it a variable in-scope or out?
Or, is it a expensive car you can buy? No, thats a Lexus.

Are you kidding me? How long have you been using Perl now? Do you
even *attempt* to learn anything about the language you're using?

Do us all a favor. Read some of the Perl documentation. In fact, read
*any* of the Perl documentation. Here's some good ones you should
start with:

perldoc perlintro
perldoc -f my
perldoc perldata

Paul Lalli
 
J

Josef Moellers

Hi,

I got a little trouble when I'm been trying to replace char & by &
example :
local our $entities = '&';
$OPTIONS{'category'} =~ s/[&]/$entities/eg;

but the result still doesn't contain &

any idea

thks

Strange: works for me:

% perl
$OPTIONS{'category'} = 'This is an amp&';
local our $entities = '&';
$OPTIONS{'category'} =~ s/[&]/$entities/eg;
print $OPTIONS{'category'}, "\n";
This is an amp&
% perl -v
This is perl, v5.8.5 built for i586-linux-thread-multi
 
J

Josef Moellers

Paul said:
Are you kidding me? How long have you been using Perl now? Do you
even *attempt* to learn anything about the language you're using?

Do us all a favor. Read some of the Perl documentation. In fact, read
*any* of the Perl documentation. Here's some good ones you should
start with:

Better yet, he should read _all_ of the Perl documentation ;-)

Josef
 
J

Jürgen Exner

Josef said:
Better yet, he should read _all_ of the Perl documentation ;-)

I would settle for reading 5% _and_understanding_those_10%_.
It would improve the noise-to-signal ratio of that person considerably.

jue
 
R

robic0

Pardon me, but your ignorance is showing yet again.


perldoc -q lexical

What's the difference between dynamic and lexical (static) scoping?
Between local() and my()?
Oh yea, you can displace the notion of a globally scoped variable temporarily
and reassign it within a block and is valid within the block and any functions
called from therein that scope. Of course, should have picked up on that.
No wonder they named it after a Lexus...
 
R

robic0

Hi,

I got a little trouble when I'm been trying to replace char & by &
example :
local our $entities = '&';
$OPTIONS{'category'} =~ s/[&]/$entities/eg;

but the result still doesn't contain &

any idea

thks

think you should consider sign painting for a living instead of
writing markup entities. no indication of w3c standard here.
in another analogy, you should try writing the disassembler before
the assembler. if you want to play and name drop things like
entities and $amp make sure you don't show your perl shortcomings.

should have stated a simple perl question like
I'm trying to replace all the 's' in 'jass is some nice musak'
and this don't work
"jass is some nice musak" =~ s/z/s/g;

this way nobody will think your trying to write a replacement Apache tool
and concentrate on your future job... sign painting
 
R

robic0

Hi,

I got a little trouble when I'm been trying to replace char & by &
example :
local our $entities = '&';
$OPTIONS{'category'} =~ s/[&]/$entities/eg;

but the result still doesn't contain &

any idea

thks

think you should consider sign painting for a living instead of
writing markup entities. no indication of w3c standard here.
in another analogy, you should try writing the disassembler before
the assembler. if you want to play and name drop things like
entities and $amp make sure you don't show your perl shortcomings.

should have stated a simple perl question like
I'm trying to replace all the 's' in 'jass is some nice musak'
and this don't work
"jass is some nice musak" =~ s/z/s/g;

this way nobody will think your trying to write a replacement Apache tool
and concentrate on your future job... sign painting

oh, you didn't catch that s/s/z/g did ya?
 
R

robic0

Are you kidding me? How long have you been using Perl now? Do you
even *attempt* to learn anything about the language you're using?

Do us all a favor. Read some of the Perl documentation. In fact, read
*any* of the Perl documentation. Here's some good ones you should
start with:

perldoc perlintro
perldoc -f my
perldoc perldata

Paul Lalli

sheeeetttt, I printed out the perl cheat sheat 2 years ago, thats
all anybody needs...
 
R

robic0

Better yet, he should read _all_ of the Perl documentation ;-)

Josef

i did read _all_ the perl documentation, but i have the 1 hour short term
memory disease so i forgot it.... i think
 
R

robic0

I would settle for reading 5% _and_understanding_those_10%_.
It would improve the noise-to-signal ratio of that person considerably.

jue

hmmm, %10 of %5 of %100 = %5000
scale it down, i know too much now, don't want to be audited...
 
R

robic0

On Tue, 17 Jan 2006 20:38:05 -0800, robic0 wrote:

oh, you didn't catch that s/s/z/g did ya?

Actually, yes.

The diagnostic:

Can't modify constant item in substitution (s///) at robic.pl line 1, near
"s/z/s/g;"
robic.pl had compilation errors.

Changing the pattern to "s/s/z/g" does not alter the fact that the code is
incorrect.

Perhaps you meant to write:

($_ = "jass is some nice musak") =~ s/s/z/g; #Ref: PP, 2nd ed., p. 73

which produces "jazz iz zome nice muzak" -- apparently what you were trying
to demonstrate, but still nonsense.

What we (those of us who haven't already killfiled you) also caught was that
your recommendation is inappropriate for this newsgroup, i.e., "this don't
[sic] work" is not a problem description that is viewed favorably here.


Hey, you read between the lines asshole .......

use strict;
use warnings;
my $asshole = "jass is some nice musak";
if ($asshole =~ s/s/z/g) {
print "What a fuckin asshole you are: $asshole\n";
}

__DATA__

What a fuckin asshole you are: jazz iz zome nice muzak
 
R

robic0

What we (those of us who haven't already killfiled you) also caught was that
your recommendation is inappropriate for this newsgroup, i.e., "this don't
[sic] work" is not a problem description that is viewed favorably here.
"this don't work" is something I never said asshole. And if I were you I would
killfile me on all your machines. Your attitude is the kind I "will" punctuate!
To me your nothing but a zero = 0. You know nothing, contribute nothing.
Your a "pile-on" jackoff with a pea-brain. You better consult the stars before
calling me out... Only the stars will help you, and some whishfull thinking.
Bring it on USA boy....

robic0 -- AMERICAN, and PROUD of it !!!!!
 

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

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top