Regex - need help!

D

dutch disCo

Hi all,

the case seems to be easy-to-solve, but since I'm kind of new to perl I
have no idea how to cope:

I run:

find . -name "index.html"

which results in something like this:

../0223/html/index.html
../0357/html/index.html

and so forth.

Now, I want these lines to become:

<a href="./0223/html/index.html">./0223/html/index.html</a>
<a href="./0357/html/index.html">./0357/html/index.html</a>

respectively, and store the modified results in a file.

How to do this?

Any help appreciated

Best regards
dd
 
J

Josef Moellers

dutch said:
Hi all,

the case seems to be easy-to-solve, but since I'm kind of new to perl I
have no idea how to cope:

I run:

find . -name "index.html"

which results in something like this:

./0223/html/index.html
./0357/html/index.html

and so forth.

Now, I want these lines to become:

<a href="./0223/html/index.html">./0223/html/index.html</a>
<a href="./0357/html/index.html">./0357/html/index.html</a>

@modified = map { ' said:
respectively, and store the modified results in a file.

# Assuming $file is a file handle reference.
print $file join("\n", @modified), "\n";
 
D

dutch disCo

Josef said:
# Assuming $file is a file handle reference.
print $file join("\n", @modified), "\n";

Sorry, too rookie to use this. Could you please provide the whole script
entries?

Best regards
dd
 
T

Tad McClellan

dutch disCo said:
Subject: Re: Regex - need help!


Your post has nothing to do with regular expressions.

but since I'm kind of new to perl I
have no idea how to cope:

I run:

find . -name "index.html"


perldoc -q external

How can I capture STDERR from an external command?

There are three basic ways of running external commands: ...

Now, I want these lines to become:

<a href="./0223/html/index.html">./0223/html/index.html</a>
<a href="./0357/html/index.html">./0357/html/index.html</a>


Use interpolation in a double quotish string ("Quote and Quote-like Operators"
in perlop.pod) or the concatenation operator (also in perlop.pod).

and store the modified results in a file.


perldoc -f open
perldoc -f print
 
D

dutch disCo

A. Sinan Unur said:
Have you seen the posting guidelines for this group?

I know, I know. Sorry for that.
Please do go private if you're still willing to help:

dutchdisco /at/ postmaster /dot/ co \dot\ uk

Please replace unneeded characters as appropriate.
Best regards
dd
 
J

Josef Moellers

dutch said:
Sorry, too rookie to use this. Could you please provide the whole script
entries?

You mean, I should write the script for you?

Why not try yourself? You may learn something.
 
D

dutch disCo

You mean, I should write the script for you?
For this time, yes.
Why not try yourself? You may learn something.
I will, I promise. Only that I'm at work at the moment, it's hectic and
I urgently need this script.

Sincerely
dd
 
A

A. Sinan Unur

I know, I know. Sorry for that.
Please do go private if you're still willing to help:

I am willing to help, but not as a consultant. Answers provided on this
forum provide help to more than just the original poster: A well posed
question with an appropriate subject line allows people with similar
problems to locate the solution with a simple search. That is why I do
not answer questions by private email unless you are offering me a
lucrative consulting opportunity.

Here's something to ponder for everyone who wants urgent answers to be
provided to vague questions: What is the benefit to me of participating
in comp.lang.perl.misc?

Sadly, I do not share many genes with Mother Theresa. So, your happiness
is not my end. On the other hand, a well posed question where the poster
has given some thought stimulates my Perl neurons, gets me thinking, and
helps me more.

Even when I do not know about a topic to be able to provide an answer,
when a good discussion gets going about the finer points of programming,
I learn from that just by following the exchange.

There is nothing I can learn from a "write my script for me" post. In
fact, a lot of the people who regularly answer questions on clpm feel
the same way. That is why the posting guidelines recommend that you at
least make an attempt to solve your problem.

If the group gets flooded with "write me this", "write me that" kind of
requests (and believe you me, if we started answering each such post,
there would be a flood), then there would be no benefit to me from
participating in the group. Similarly for other whose expertise I trust
will catch my errors.

Now, this does not prevent anyone else from helping you if they so wish.

I just wanted to clarify to you why you will get much more help if you
put some effort into your post.

Sinan
 
J

John Bokma

dutch disCo said:
For this time, yes.

I will, I promise. Only that I'm at work at the moment, it's hectic and
I urgently need this script.

Contact me, and pay for it.
 
X

Xicheng

dutch said:
Hi all,

the case seems to be easy-to-solve, but since I'm kind of new to perl I
have no idea how to cope:

I run:

find . -name "index.html"

which results in something like this:

./0223/html/index.html
./0357/html/index.html

and so forth.

Now, I want these lines to become:

<a href="./0223/html/index.html">./0223/html/index.html</a>
<a href="./0357/html/index.html">./0357/html/index.html</a>

respectively, and store the modified results in a file.

How to do this?

hi, you dont need to write script, just do it on the command line:
 
J

Jürgen Exner

dutch said:
I run:
find . -name "index.html"

Well, ok, but if you are using Perl then File::Find does exist.
which results in something like this:

./0223/html/index.html
./0357/html/index.html

Now, I want these lines to become:

<a href="./0223/html/index.html">./0223/html/index.html</a>
<a href="./0357/html/index.html">./0357/html/index.html</a>

Why do you believe you need a regex?
A simple

while (<>) {
print "<a href=\"$_\">$_</a>";
}

should do
respectively, and store the modified results in a file.

Well if you are using an external "find" already then you can just as well
keep piping the output of the Perl script directly into that file.

jue
 

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,183
Messages
2,570,967
Members
47,520
Latest member
KrisMacono

Latest Threads

Top