For Programmers: Free Programming Magazines  


Home > Archive > PERL Programming > March 2005 > Duplicate HashEntry









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Duplicate HashEntry
Michael.Ruehling@t-online.de

2005-02-28, 3:56 pm

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 (@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
Gunnar Hjalmarsson

2005-02-28, 3:56 pm

Michael.Ruehling@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 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
Michael.Ruehling@t-online.de

2005-02-28, 8:55 pm

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

>Michael.Ruehling@t-online.de wrote:
>
>Not sure what your query has to do with hashes...
>
>
>Yes, of course it is, and the question is asked frequently:
>
> perldoc -q "insert a line"
>
>To prevent that the loop gets 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)
>
>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
Gunnar Hjalmarsson

2005-02-28, 8:55 pm

Michael.Ruehling@t-online.de wrote:
> Gunnar Hjalmarsson wrote:
>
> 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
Michael.Ruehling@t-online.de

2005-03-01, 3:56 pm

Hi,
I think i give an exact example:


index.html (before):

<html>
<body>
<ul>
<li>< a href=(link_to_somedata>somedata</a></li>
</ul>
</body>
</html>


and after program execution:


<html>
<body
<ul>
<li>< a href=link_to_somedata>somedata</a></li>
<li>< a href=link_to_some_otherdata>someotherdata</a></li> # <- This
</li>
</ul>
</body>
</html>

I want to add the second line into the list of links !!!!
But not simply add one line but a few by program.
Everytime a user creates a subdir i want this subdir to be added to
this linklist. I don't want to format these lines to look better.




Michael
On Mon, 28 Feb 2005 21:10:57 +0100, Gunnar Hjalmarsson
<noreply@gunnar.cc> wrote:

>Michael.Ruehling@t-online.de wrote:
>
>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

2005-03-01, 3:56 pm

[ Please don't top post! ]

Michael.Ruehling@t-online.de wrote:
>
> <html>
> <body
> <ul>
> <li>< a href=link_to_somedata>somedata</a></li>
> <li>< a href=link_to_some_otherdata>someotherdata</a></li> # <- This
> </li>
> </ul>
> </body>
> </html>
>
> I want to add the second line into the list of links !!!!
> But not simply add one line but a few by program.
> Everytime a user creates a subdir i want this subdir to be added to
> this linklist. I don't want to format these lines to look better.


Okay, you want additional lines. Fine. HTML is off topic here anyway.

You said that you have a solution. If not, you did notice my pointer to
the FAQ, didn't you?

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com