Wrong statement

R

Roland Mösl

This statement is wrong

$display =~ s/\//\ \&nbsp\; \/\ \&nbsp\; /g;

It was in a sub routine and caused about

500 MB memory usage after 2000 calls



Why?
 
A

Andreas Kahari

This statement is wrong

$display =~ s/\//\ \&nbsp\; \/\ \&nbsp\; /g;

"Replace every occurance of '/' with '  /   '".

If that was what consumed all the memory, I don't know, but I
can see that a HTML file could grow a bit if you apply this
substitution to it.
 
G

Gunnar Hjalmarsson

Roland said:
This statement is wrong

$display =~ s/\//\ \&nbsp\; \/\ \&nbsp\; /g;

It was in a sub routine and caused about

500 MB memory usage after 2000 calls

Why?

Don't know.

The only thing that makes it "wrong" is that it includes a few
redundant backslashes, which indicates that the author doesn't know
Perl very well. This does the same:

$display =~ s/\//   \/   /g;
 
C

Chris Mattern

Roland said:
This statement is wrong

$display =~ s/\//\ \&nbsp\; \/\ \&nbsp\; /g;

I'll say; most of the escapes are completely
pointless and rest can be avoided. Try this:

$display =~ s#/#   /   #g;

Much easier to read.
It was in a sub routine and caused about

500 MB memory usage after 2000 calls



Why?
Not knowing:

a) what $display contains,
b) how $display is declared,
c) how you decided the regex was the problem,
d) anything at all about your program except
one fairly innocuous-looking regex,

it is pretty much impossible to answer that
question.

Chris Mattern
 
G

Glenn Jackman

=?Windows-1252?Q?Roland_M=F6sl?= said:
This statement is wrong

$display =~ s/\//\ \&nbsp\; \/\ \&nbsp\; /g;

It was in a sub routine and caused about

500 MB memory usage after 2000 calls

How many times are you doing that substitution on the same string?

$display='~/public_html/manual';
$display =~ s{/}{   /   }g for (1..3);
print "$display\n";

You might want to encode the slash in the replacement string:

$display =~ s{/}{   /   }g;
 
R

Roland Mösl

This statement is wrong
How many times are you doing that substitution on the same string?

Not the same, the sub is calle always with different parameters
 
C

Chris Mattern

Roland said:
Not the same, the sub is calle always with different parameters
Are you sure $display has what you think it has? My guess,
knowing absolutely nothing about your program, is that you're
not using "use strict", you haven't declared $display with my()
(and it is therefore global) and every call you make, you're
running that substitution again over the same data in $display.
Since you won't post any relevant data, I have no way of tellling
if I'm right, but that's my guess.

Chris Mattern
 

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,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top