Duplicate HashEntry

Hi,
I'm trying to write a Script that must have the ability
to duplicate a line in a HTML-Document.
Is is possible anyway?
e. G.


foreach $zeile ( [at] dateiinhalt)
{
if ($zeile =~ m/Platzhalter1\.jpg/o)
{
# duplicate that line before substitution and s///i
# 1 line afterwards
$zeile =~ s/Platzhalter1\.jpg/$Bild1Name/i;
}
else
{
if ($zeile =~ m/Platzhalter2\.jpg/o)
{
$zeile =~ s/Platzhalter2\.jpg/$Bild2Name/i;
}
}
print VORLAGE ("$zeile");
}
close (VORLAGE);

Please excuse the German names, but since i am german it is easier for
me to understand that lang.


Michael
Michael.Ruehling [ Mo, 28 Februar 2005 15:56 ] [ ID #669103 ]

Re: Duplicate HashEntry

Michael.Ruehling [at] t-online.de wrote:
>
> Subject: Duplicate HashEntry

Not sure what your query has to do with hashes...

> I'm trying to write a Script that must have the ability
> to duplicate a line in a HTML-Document.
> Is is possible anyway?

Yes, of course it is, and the question is asked frequently:

perldoc -q "insert a line"

To prevent that the loop gets confused when you add lines/elements, you
may want to loop through the array backwards.

However, since it's an HTML document, I don't understand why there is a
need to add lines. Can't you add whatever it is you want to add on
existing lines?

> Please excuse the German names, but since i am german it is easier for
> me to understand that lang.

What's easier for *you* to understand is irrelevant if you want that
others shall read your post. When asking for help, you should make it
easy for others to help you.

Now, personally I'm not bothered by those German var names, even if
Swedish names would of course have been much more convenient to me. ;-)

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
Gunnar Hjalmarsson [ Mo, 28 Februar 2005 17:30 ] [ ID #669104 ]

Re: Duplicate HashEntry

On Mon, 28 Feb 2005 17:30:35 +0100, Gunnar Hjalmarsson
<noreply [at] gunnar.cc> wrote:

>Michael.Ruehling [at] t-online.de wrote:
>>
>> Subject: Duplicate HashEntry
>
>Not sure what your query has to do with hashes...
>
>> I'm trying to write a Script that must have the ability
>> to duplicate a line in a HTML-Document.
>> Is is possible anyway?
>
>Yes, of course it is, and the question is asked frequently:
>
> perldoc -q "insert a line"
>
>To prevent that the loop gets confused when you add lines/elements, you
>may want to loop through the array backwards.
>
>However, since it's an HTML document, I don't understand why there is a
>need to add lines. Can't you add whatever it is you want to add on
>existing lines?
I take that file as a Template for an indexfile (index.html) and i
want to add lines usings Perl's Pattern matching functions.

e. g.:
<html>
<body>
<ul>
<li>< a href ="Placeholder">Placeholder</a></li> # duplicate this line
# add another <li>-Line (with correct links!)
</ul>
</body>
</html>
>


oohh, great. After thinking another two Hours, i think i have a
solution.
(just Pattern-Match on the first </li> and write a correct line AFTER
it)
>> Please excuse the German names, but since i am german it is easier for
>> me to understand that lang.
>
>What's easier for *you* to understand is irrelevant if you want that
>others shall read your post. When asking for help, you should make it
>easy for others to help you.
>
>Now, personally I'm not bothered by those German var names, even if
>Swedish names would of course have been much more convenient to me. ;-)
I may be incorrect, but since they all are var-names they should be
clear. Okay they are not hashes. Sorry for that.


Michael
Michael.Ruehling [ Mo, 28 Februar 2005 20:33 ] [ ID #669105 ]

Re: Duplicate HashEntry

Michael.Ruehling [at] t-online.de wrote:
> Gunnar Hjalmarsson wrote:
>> However, since it's an HTML document, I don't understand why there is
>> a need to add lines. Can't you add whatever it is you want to add on
>> existing lines?
>
> I take that file as a Template for an indexfile (index.html) and i
> want to add lines usings Perl's Pattern matching functions.
>
> e. g.:
> <html>
> <body>
> <ul>
> <li>< a href ="Placeholder">Placeholder</a></li> # duplicate this line
> # add another <li>-Line (with correct links!)
> </ul>
> </body>
> </html>

What I mean is that

<ul>
<li>something</li>
<li>somethingelse</li>
</ul>

is rendered exactly the same as

<ul>
<li>something</li><li>somethingelse</li>
</ul>

That's why I don't understand why you need to bother with adding extra
lines to the file.

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
Gunnar Hjalmarsson [ Mo, 28 Februar 2005 21:10 ] [ ID #669106 ]
Perl » alt.perl » Duplicate HashEntry

Vorheriges Thema: Registry monitor
Nächstes Thema: The Perl Review, Spring 2005