Visit Our UNIX and Linux User Community


Using Perl to add hyperlink to html files


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Using Perl to add hyperlink to html files
# 8  
Old 10-30-2007
Quote:
Originally Posted by Raynon
How about the ftp part ?
I personally wouldn't do that in Perl.

a. edit $HOME/.netrc to add username/password

b. use the following shell script

Code:
ftp server <<EOF
put x.html /some/directory/x.html
EOF

# 9  
Old 10-30-2007
Can i do the appending of lines to file name " webfile " so as to ease the ftp portion by shell ? I try to perform the below but it's showing some error . Can you help ?


#!/usr/bin/perl

print "<html>\r\n" > webfile ;
print "\t<head>\r\n" >> webfile ;
print "\t\t<title>My webpage</title>\r\n" >> webfile;
print "\t<head>\r\n" >> webfile ;
print "\t<body>\r\n" >> webfile ;
print "\t\t<a href=\"some-url\">XX</a> 20 \$50<br>\r\n" >> webfile;
print "\t\t<a href=\"some-url\">YY</a> 30 \$60<br>\r\n" >> webfile;
print "\t\t<a href=\"some-url\">ZZ</a> 40 \$70<br>\r\n" >> webfile;
print "\t</body>\r\n" >> webfile;
print "</html>\r\n" >> webfile;
# 10  
Old 10-30-2007
That is because you are trying to write shell code in a Perl script.

Assuming you put your Perl in "myperl.pl" then do the following from shell...

Code:
./myperl.pl >webpage.html

# 11  
Old 10-30-2007
Code:
#!/usr/bin/perl
use Net::FTP;
open(OUT,">>fileout.html");
$XX="XX";
$XXval="20";
$var = <<"EOF";
<html>
<head>
    <title>My webpage</title>
    <head>
    <body>
    a href="some-url"> $XXval </a> $XX <br>
EOF
print OUT $var;
close(OUT);

$ftp = Net::FTP-> new
(
 "ftp.server.com",
 Timeout=>30
 
) or die "Cannot connect: $!"
$username="me";
$pass="password";
$ftp->login($username,$pass) or die "Could not log on: $!";
$ftp->cwd('/path');
$ftp->put("fileout.html");
$ftp->quit;

just an example. you do the rest. If you want to use Perl, learn it first.
# 12  
Old 10-30-2007
Hi GhostDog,

Thanks for your code.
I roughly know how your perl code works now.
But just one more question.

My shell script created a file named " shelloutput "

where " shelloutput " is the below:
XX 20 $50
YY 30 $60
ZZ 40 $70


How can i pass each term in this file as a variable to the perl code?
In your earlier code, you have assumed 20 as the term for your $XXval variable but in actual fact we do not know until we actually look at the shelloutput file ourself. What we know is that the ouput will be in the form of a 3 x 3 matrix where each term is seperated by spaces and the $XXval will always be the 2nd field if "XX" is the first field
# 13  
Old 10-30-2007
Quote:
Originally Posted by Raynon
How can i pass each term in this file as a variable to the perl code?
In your earlier code, you have assumed 20 as the term for your $XXval variable but in actual fact we do not know until we actually look at the shelloutput file ourself. What we know is that the ouput will be in the form of a 3 x 3 matrix where each term is seperated by spaces and the $XXval will always be the 2nd field if "XX" is the first field
you just have to open the file and read the contents. An example reference. pls get a Perl book and start learning.
# 14  
Old 10-31-2007
Hi GhostDog,

Thanks for the example. I think i have got it!

Code:
#!/usr/bin/perl
use Net::FTP;
$[ = 1;                 # set array base to 1
open( FILE, "< filename" ) or die "Can't open $filename : $!";

    while( <FILE> ) {
    chomp;      # strip record separator
    @Fld = split(' ', $_, 9999);
    if ($Fld[1] eq 'XX') {
    $TESTER = $Fld[1];
    $ID = $Fld[2];
    $QTY = $Fld[3];
    }
    close FILE;
}

open(OUT,">>fileout.html");
$var = <<"EOF";
<html>
<head>
    <title>My webpage</title>
    <head>
    <body>
    <a href="some-url"> $TESTER </a> $ID  $QTY <br>
</head>
</html>

EOF
print OUT $var;
close(OUT);

However, when i introduce the path reference " $filename = "/scripts/myperl/filename" ", there's some error , can you give some guidance on that ?


Code:
#!/usr/bin/perl
use Net::FTP;
$[ = 1;                 # set array base to 1
$filename = "/scripts/myperl/filename"
open( FILE, "< $filename" ) or die "Can't open $filename : $!";

    while( <FILE> ) {
    chomp;      # strip record separator
    @Fld = split(' ', $_, 9999);
    if ($Fld[1] eq 'XX') {
    $TESTER = $Fld[1];
    $ID = $Fld[2];
    $QTY = $Fld[3];
    }
    close FILE;
}

open(OUT,">>fileout.html");
$var = <<"EOF";
<html>
<head>
    <title>My webpage</title>
    <head>
    <body>
    <a href="some-url"> $TESTER </a> $ID  $QTY <br>
</head>
</html>

EOF
print OUT $var;
close(OUT);


Previous Thread | Next Thread
Test Your Knowledge in Computers #204
Difficulty: Easy
The BGP routing protocol runs over User Datagram Protocol (UDP).
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Need to add code to hundreds of .html files

Need assistance to add code to hundreds of .html Code will look like below and needs to be added below <html> tag: <script> Some .js code here </script> This will be used in Fedora release 7 (Moonshine). I will appreciate any type of help and/or orientation. Thank you! (4 Replies)
Discussion started by: Ferocci
4 Replies

2. UNIX for Dummies Questions & Answers

Writing an HTML file in perl

I'm writing a perl script that writes an html file. use Tie::File; my ($dir) = @ARGV; open (HTML,">","$dir/file.html") || die $!; #-----Building HTML file--------------------------- print HTML "<!DOCTYPE html> <html> <head> <title>Output</title> <link... (3 Replies)
Discussion started by: jrymer
3 Replies

3. Web Development

Dynamic Hyperlink

Hi Guys/ Gals, I am trying to create a link based on the current date however it doesnt seem to work. Could someone please point me in the right direction. Here is what i have so far.. <html> <head> <script type="text/javascript" language="JavaScript"> function... (2 Replies)
Discussion started by: robfwauk
2 Replies

4. AIX

hyperlink settings

Does anyone know the hyperlink settings to look at an AIX5L box? (1 Reply)
Discussion started by: vbagwell
1 Replies

5. Shell Programming and Scripting

Perl + Korn + HTML

I have a perl script that prints up the html code and executes a few korn scripts to populate the web code. Disclaimer === I can throw together some korn scripts pretty quick. This code changes pretty frequently. I don't know enough about perl to do everything I need. One day maybe I'll get... (4 Replies)
Discussion started by: i9300
4 Replies

6. UNIX for Dummies Questions & Answers

Create Hyperlink

Hi Everybody, I am new to this forum. I need help. Here is the details: I have a .csv file in unix server which is 2MB size I am attaching this file and sending to all users who are in my team thru Microsoft outlook. All users requested me to send the link where we can click and open... (1 Reply)
Discussion started by: utham1
1 Replies

7. Shell Programming and Scripting

HTML parsing by PERL

i have a HTML report file..its in attachment(a part of the whole report is attached..name "input html.doc").also its source is attached in "report source code.txt" i just want to seperate the datas like in first line it should be.. NHTEST-3848498958-NHTEST-10.2-no-baloo a and so on for whole... (3 Replies)
Discussion started by: avik1983
3 Replies

8. Shell Programming and Scripting

How to add Hyperlink with shell script(using mail client)

Hi ! plz let me suggest ..... By using of mail client methods I am trying to send mails through shell script. like.... To: From: Sub: Body: some sample text..... <my requirement is how to add hyper link to some text(click me) ... (0 Replies)
Discussion started by: rsukumar
0 Replies

9. Shell Programming and Scripting

perl and html

hi. im very new to perl. is it possible to fill up a web form and submit it using perl? example, i would like to sign up for a yahoo account though a perl script (ofcourse, granting the "type the characters as shown in imgage" is absent)? (8 Replies)
Discussion started by: marcpascual
8 Replies

10. UNIX for Dummies Questions & Answers

Moving .html files while preserving hyperlink integrity?

Hi, I use a Windows-based program called <a href="http://www.coast.com">Coast Webmaster</a> for moving large numbers of HTML files in one directory to another directory. As you drag and drop each file or entire directory of files to new locations in the web root directory tree, this utility... (1 Reply)
Discussion started by: Buddy123
1 Replies

Featured Tech Videos