O
OllyP
_____________________________________________________________
Tue Jun 06 00:43:59 CDT 2006
I am not a programmer or an IT guy, but have an interest in learning
Perl. I am attempting to take a list of filepaths and rework them into
an html index so as to click them into a browser easily.
Perl, v5.8.3 Linux
The list format is:
/home/olly/aasys/perl/sandtr.html
(and on etc, for 80/90 files)
I ran:
#!/usr/bin/perl
#use warnings;
#use strict;
#use diagnostics;
use Tie::File;
tie @hot, 'Tie::File', "dead.html" or die;
for (@hot) {
s/^/<a href="file:/g;
}
for (@hot) {
s/$/">X<\/a><br>/g;
}
# At this point each line in the whole list appears similar to this:
# <a href="file:/home/olly/aasys/perl/sandtr.html">X</a><br>
# This is exactly what I want, and the X is clickable in the browser.
# However I want the filename to display instead of the X.
for (@hot =~ m/perl\/.+html/){
s/\X/\1/g;
}
# It does not displace the X with the filename.
print \1, "\n";
untie @hot, "\n";
----cut----
I have tried $& , $1 etc, but can't find the filename
The best I can do is: SCALAR(0x8186eec), however it does not replace X.
The filename will appear with the match above if I do:
-----------
my $string="<a href=\"file:/home/olly/aasys/perl/sandtr.html\">X</a><br>";
if($string =~ m/perl\/.+html/)
{s/\X/$&/};
print $&, "\n";
print $string. "\n";
#Ollynotes: this works to grab $&, but the string is unchanged?
return:
perl/sandtr.html <-- This is $& as I wanted.
<a href="file:/home/olly/aasys/perl/sandtr.html">X</a><br>
But no change .................................. ^^ here.
--------
Obviously I am violating some basic principals but can't find it in the
reams of documentation I have. I do find simple substitution aplenty
but nothing about picking up a portion and tacking it back.
Where would I look for this type of substitution?
Is there a better procedure to approach my project?
Should I throw in the towel and become a street musician?
All replies will be thoroughly read and saved.
Thank you
Tue Jun 06 00:43:59 CDT 2006
I am not a programmer or an IT guy, but have an interest in learning
Perl. I am attempting to take a list of filepaths and rework them into
an html index so as to click them into a browser easily.
Perl, v5.8.3 Linux
The list format is:
/home/olly/aasys/perl/sandtr.html
(and on etc, for 80/90 files)
I ran:
#!/usr/bin/perl
#use warnings;
#use strict;
#use diagnostics;
use Tie::File;
tie @hot, 'Tie::File', "dead.html" or die;
for (@hot) {
s/^/<a href="file:/g;
}
for (@hot) {
s/$/">X<\/a><br>/g;
}
# At this point each line in the whole list appears similar to this:
# <a href="file:/home/olly/aasys/perl/sandtr.html">X</a><br>
# This is exactly what I want, and the X is clickable in the browser.
# However I want the filename to display instead of the X.
for (@hot =~ m/perl\/.+html/){
s/\X/\1/g;
}
# It does not displace the X with the filename.
print \1, "\n";
untie @hot, "\n";
----cut----
I have tried $& , $1 etc, but can't find the filename
The best I can do is: SCALAR(0x8186eec), however it does not replace X.
The filename will appear with the match above if I do:
-----------
my $string="<a href=\"file:/home/olly/aasys/perl/sandtr.html\">X</a><br>";
if($string =~ m/perl\/.+html/)
{s/\X/$&/};
print $&, "\n";
print $string. "\n";
#Ollynotes: this works to grab $&, but the string is unchanged?
return:
perl/sandtr.html <-- This is $& as I wanted.
<a href="file:/home/olly/aasys/perl/sandtr.html">X</a><br>
But no change .................................. ^^ here.
--------
Obviously I am violating some basic principals but can't find it in the
reams of documentation I have. I do find simple substitution aplenty
but nothing about picking up a portion and tacking it back.
Where would I look for this type of substitution?
Is there a better procedure to approach my project?
Should I throw in the towel and become a street musician?
All replies will be thoroughly read and saved.
Thank you