problem with '>' character

J

JD

Hello,

I have a html-like string, and would like to remove the left part,
including the leftmost '>'. I use s/^.*>//;
but it does not work as expected (neither does s/^.*\076//;).
Something funny is going on, but I do not know what. It looks like a
shift-operator comes into action.

Can someone tell me what the problem might be, and how to get it right?

Thank you.
 
P

Peter Makholm

JD said:
I have a html-like string, and would like to remove the left part,
including the leftmost '>'. I use s/^.*>//;
but it does not work as expected (neither does s/^.*\076//;).

Do you string consist of multipli lines, then you'll have to remember
that . doesn't matches the newline character unless you put you regexp
in multi line mode (with either m og s - read the docs).

//Makholm
 
J

JD

_
JD ([email protected]) wrote on VCCLXXIII September MCMXCIII in
<URL:&&
&& Hello,
&&
&& I have a html-like string, and would like to remove the left part,
&& including the leftmost '>'. I use s/^.*>//;
&& but it does not work as expected (neither does s/^.*\076//;).
&& Something funny is going on, but I do not know what. It looks like a
&& shift-operator comes into action.
&&
&& Can someone tell me what the problem might be, and how to get it right?


Could you give an example of what you did, and what you had expected?
I know one thing that's wrong about s/^.*>//, but that's not "funny",
nor does it have anything to do with a shift-operator.

code:
while (<IN>) {
print "$_ \n";
s/^.*\076//;
print "$_ \n";
.....

output:
[long string, ending with] size="1">PASTEL
ASTEL

note the space
 
J

JD

_

That seems like a bug.

Found it: It was a a file from a MS-Windows system, with CRLF line ends.
chomp removed the LF, but the CR was still there :(


dos2unix solved it.
 
T

Tad J McClellan

Peter Makholm said:
Do you string consist of multipli lines, then you'll have to remember
that . doesn't matches the newline character unless you put you regexp
in multi line mode (with either m og s - read the docs).
^^^^^^^^^^^^^


Only one of those makes dot match a newline...
 
U

Uri Guttman

PM> Yes, I'm quite aware of that and the documentation will surly tell you
PM> which one.

so why do you mention both and not report what the docs said there?

uri
 
P

Peter Makholm

Uri Guttman said:
PM> Yes, I'm quite aware of that and the documentation will surly tell you
PM> which one.

so why do you mention both and not report what the docs said there?

Because I don't need to know. I rarely use multi line regexps so I
would have to look up 'perldoc perlre' to give a more precise
answer. If my assumption had been right, the original poster would
have been able to do it just as easy.

//Makholm
 
U

Uri Guttman

PM> Yes, I'm quite aware of that and the documentation will surly tell you
PM> which one.
PM> Because I don't need to know. I rarely use multi line regexps so I
PM> would have to look up 'perldoc perlre' to give a more precise
PM> answer. If my assumption had been right, the original poster would
PM> have been able to do it just as easy.

then you shouldn't answer such questions. you made an assumption which
is useless even if correct.

uri
 
P

Peter Makholm

Uri Guttman said:
then you shouldn't answer such questions. you made an assumption which
is useless even if correct.

I don't agree, but I should have refered to 'perldoc perlre' instead
of just the docs.

//Makholm
 

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
474,209
Messages
2,571,088
Members
47,686
Latest member
sparada

Latest Threads

Top