regl expression

B

bruno_storz

[] Hi there,
[]
[] I wonder, why this reg. expression does not replace this:
[]
[] $line = "<title><!-- HTML_titel --></title>";
[] $html{'titel'} = "my Titel";
[] $line =~ s/<!-- HTML_([a-z]+) -->/$htmlref->{$1}/gix;


What's in $htmlref?

a more complete code snipplet:

$html{'titel'} = "my Titel";
$template = "aFile.html";
.....
print &html_export( $template, \%html);

sub html_export {
$line = "<title><!-- HTML_titel --></title>";
my ($htmlref) = @_;
$line =~ s/<!-- HTML_([a-z]+) -->/$htmlref->{$1}/gix;
.....
}

I want to replace the comment ><!-- HTML_titel --> by somthing, which is in
the hash $html.
regards Bruno
 
J

Jeff 'japhy' Pinyan

print &html_export( $template, \%html);

You send TWO arguments here...
sub html_export {
$line = "<title><!-- HTML_titel --></title>";
my ($htmlref) = @_;

But you store the FIRST one as $htmlref. The second argument is the hash
ref.

my ($tpl, $htmlref) = @_;
$line =~ s/<!-- HTML_([a-z]+) -->/$htmlref->{$1}/gix;
....
}
 
B

bruno_storz

Hi there,

I wonder, why this reg. expression does not replace this:

$line = "<title><!-- HTML_titel --></title>";
$html{'titel'} = "my Titel";
$line =~ s/<!-- HTML_([a-z]+) -->/$htmlref->{$1}/gix;

Any ideas?

Regards
Bruno
 
E

Eric J. Roode

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi there,

I wonder, why this reg. expression does not replace this:

$line = "<title><!-- HTML_titel --></title>";
$html{'titel'} = "my Titel";
$line =~ s/<!-- HTML_([a-z]+) -->/$htmlref->{$1}/gix;

The x modifier changed the way spaces are interpreted in regular
expressions. Why do you have it there?

- --
Eric
$_ = reverse sort qw p ekca lre Js reh ts
p, $/.r, map $_.$", qw e p h tona e; print

-----BEGIN PGP SIGNATURE-----
Version: PGPfreeware 7.0.3 for non-commercial use <http://www.pgp.com>

iQA/AwUBPxldlWPeouIeTNHoEQLQZwCgzWrG9WEOlezA0KUp073CW34/YzAAoIs9
tjRALrK6lvgKbf7lo6QNy7fJ
=5PNc
-----END PGP SIGNATURE-----
 
M

Michele Dondi

This prints 1 which is not a prime !!

But this is a venial sin for 1 is (generally) not considered a prime
mostly for a technical reason: to avoid saying 'a prime different from
1' every here and there...


Michele
 
J

John Strauss

Hi there,

I wonder, why this reg. expression does not replace this:

$line = "<title><!-- HTML_titel --></title>";
$html{'titel'} = "my Titel";
$line =~ s/<!-- HTML_([a-z]+) -->/$htmlref->{$1}/gix;

Any ideas?

Regards
Bruno

first idea: i've got no idea what's in %$htmlref,
though i have some idea what's in %html.

second idea: unless you've given us an incomplete
or typo'd snippet, you've not used the warnings and
strict pragmas-- which would have caught the first
problem before you even posted.

third idea: you need either to drop the '/x' modifier
on your pattern matching, or escape the whitespace in
your regexp. if this makes no sense to you, read
"perldoc perlre" (the bit about "The `/x' modifier
itself needs a little more explanation.")

fourth idea: you are replacing all of your search
pattern "<!-- HTML_([a-z]+) -->" with "my Titel".
which may be what you actually want, but you haven't
told us what you expect $line to contain when you're
done with it. if i'm right, try
$line =~ s/(<!-- HTML_)([a-z]+)( -->)/$1$htmlref->{$2}$3/gi;






~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
drop the .thetenant to get me via mail
 

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

Similar Threads


Members online

No members online now.

Forum statistics

Threads
474,109
Messages
2,570,671
Members
47,262
Latest member
EffiePju4

Latest Threads

Top