Creating .txt/.html file using perl script

J

jdblackford

Hello,

I was wondering if it was possible to create simple program that will
create .txt (or .html) files based on information provided via
prompts. If so, would someone be willing to assist me with this? I
know absolutely nothing about Perl (or any other programming language
for that matter)

For instance, if I wanted to create a file called 01.20.07.html based
off of a specific date (01 is MM, 20 is DD, 07 is YY) that looked like
this:

<html>
<body>
<table>
<tr><td><img src="http://www.mywebsite.com/01.20.07/1.JPG">
<td><img src="http://www.mywebsite.com/01.20.07/2.JPG">
<td><img src="http://www.mywebsite.com/01.20.07/3.JPG">
</tr>
<tr><td><img src="http://www.mywebsite.com/01.20.07/4.JPG">
<td><img src="http://www.mywebsite.com/01.20.07/5.JPG">
<td><img src="http://www.mywebsite.com/01.20.07/6.JPG">
</tr>
</body>
</html>

I would like to be able to enter the following information when
prompted by the program:

MM
DD
YY
Number of images

If possible, I would like to have the code know how many table rows to
create (in intervals of 3) based on the number of images.

Is this something someone here can assist with?
 
M

Mirco Wahab

I was wondering if it was possible to create simple program that will
create .txt (or .html) files based on information provided via
prompts. If so, would someone be willing to assist me with this? I
know absolutely nothing about Perl (or any other programming language
for that matter)

For instance, if I wanted to create a file called 01.20.07.html based
off of a specific date (01 is MM, 20 is DD, 07 is YY) that looked like
this:

So you would like call it like

perl myprogram.pl 01 20 07 9

to produce the desired output?

I would like to be able to enter the following information when
prompted by the program:
MM
DD
YY
Number of images

You already had to type the program name in order
to start it, so adding the parameters directly would
simplify the program and allows to mechanize your work
later.

Or did you think of 'clicking a file in explorer and
entering info then'?
If possible, I would like to have the code know how many table rows to
create (in intervals of 3) based on the number of images.
Is this something someone here can assist with?

I'm not really sure what you intend to solve and
what would be the best way to do it.

Your specification is 'proforma' (without "entering info then")
fulfilled by a short perl script like:
==>
use strict;
use warnings;
use CGI qw':standard';


my $link = 'http://www.mywebsite.com/$$D.$$M.$$Y/$$N.JPG';
my %transf = ( D => shift, M => shift, Y => shift );
$link =~ s/\$\$$_/$transf{$_}/ for keys %transf;
my ($n, $rows) = (1, (shift)/3);

my $html =
start_html('Image Gallery')
. table(
Tr([
map
td([ map {my $l=$link; $l=~s/\$\$N/$n++/e; img({src=>$l})."\n"} 1..3 ] ),
1..$rows
])
)
. end_html();

open my $fhd, '>', 'jdblackford.html' or die "cant't write files: $!";
print $fhd $html;
close $fhd;
<==


which you might invoke as said on line 14 of this posting.

But maybe you give us some more information first -
why Perl for example (if you didn't ever touch it)
and so on.

Regards

Mirco
 
D

Dr.Ruud

(e-mail address removed) schreef:
I was wondering if it was possible to create simple program that will
create .txt (or .html) files based on information provided via
prompts. [...]
<td><img src="http://www.mywebsite.com/01.20.07/1.JPG">
<td><img src="http://www.mywebsite.com/01.20.07/2.JPG">
<td><img src="http://www.mywebsite.com/01.20.07/3.JPG">
</tr>
<tr>
<td><img src="http://www.mywebsite.com/01.20.07/4.JPG">
<td><img src="http://www.mywebsite.com/01.20.07/5.JPG">
<td><img src="http://www.mywebsite.com/01.20.07/6.JPG">

It looks like you already know the filenames up ahead.
So why not let your code work from that infomation?

perldoc -f glob
perldoc -f readdir


Or create a file like

2007-01-20,6
2007-01-21,2

etc., and let your code use that.
 
X

Xicheng Jia

Hello,

I was wondering if it was possible to create simple program that will
create .txt (or .html) files based on information provided via
prompts. If so, would someone be willing to assist me with this? I
know absolutely nothing about Perl (or any other programming language
for that matter)

For instance, if I wanted to create a file called 01.20.07.html based
off of a specific date (01 is MM, 20 is DD, 07 is YY) that looked like
this:

<html>
<body>
<table>
<tr><td><img src="http://www.mywebsite.com/01.20.07/1.JPG">
<td><img src="http://www.mywebsite.com/01.20.07/2.JPG">
<td><img src="http://www.mywebsite.com/01.20.07/3.JPG">
</tr>
<tr><td><img src="http://www.mywebsite.com/01.20.07/4.JPG">
<td><img src="http://www.mywebsite.com/01.20.07/5.JPG">
<td><img src="http://www.mywebsite.com/01.20.07/6.JPG">
</tr>
</body>
</html>

I would like to be able to enter the following information when
prompted by the program:

MM
DD
YY
Number of images

If possible, I would like to have the code know how many table rows to
create (in intervals of 3) based on the number of images.

Is this something someone here can assist with?

You might want to check any Perl templating modules like TT(Template
Toolkits),

http://search.cpan.org/dist/Template-Toolkit/

which could possibly make your stuff much easier.(in your case, the
template file need just several inputs and a simple loop.)

BTW. if you can use <div> elements instead of table to organize your
output, that might be much easier, my 2 cents. :)

Regards,
Xicheng
 
X

Xicheng Jia

You might want to check any Perl templating modules like TT(Template
Toolkits),

http://search.cpan.org/dist/Template-Toolkit/

which could possibly make your stuff much easier.(in your case, the
template file need just several inputs and a simple loop.)

BTW. if you can use <div> elements instead of table to organize your
output, that might be much easier, my 2 cents. :)

Regards,
Xicheng- Hide quoted text -
- Show quoted text -

Below is a TT test code for your needs, you actually only need to
figure a data structure and then TT can do the other stuff pretty
easily:

you run it this way: ./ex1.pl 01.20.70 13 5

If you can use <div> and set CSS styles to control their (float|
width|...)s, then a plain 1-D array will do all stuff...

Regards,
Xicheng

#### ex1.pl ####
#!/usr/bin/perl
use warnings;
use strict;
use Template;

if (@ARGV < 2) {
print "./ex1.pl mm.dd.yy numPic [numCol]\n";
exit;
}
my ($date, $numPic) = @ARGV;
my $numCol = $ARGV[2] || 3;

my $residuals = $numCol - ($numPic % $numCol);
my $items;
my $n = 0;

for my $item (1..$numPic) {
push @{$items->[$n]}, $item;
$n++ if not $item % $numCol;
}
push @{$items->[$n]}, (0) x $residuals;

my $tt = Template->new();
my $input = 'ex1.tt';
my $args = {
site => $date,
items => $items,
};
$tt->process($input, $args, "$date.html") or die $tt->error( );

__END__

#### ex1.tt ####
<html>
<head>
<title>TT test page</title>
</head>
<body>
<table>
[% FOREACH item IN items -%]
<tr>
[% FOREACH cell IN item -%]
[% IF !cell -%]
<td>&nbsp;</td>
[% ELSE -%]
<td><img src="http://www.mywebsite.com/[% site %]/[% cell
%].JPG"></td>
[% END -%]
[% END -%]
</tr>
[% END -%]
</table>
</body>
</html>
 
X

Xicheng Jia

On May 12, 5:45 pm, (e-mail address removed) wrote:
You might want to check any Perl templating modules like TT(Template
Toolkits),

which could possibly make your stuff much easier.(in your case, the
template file need just several inputs and a simple loop.)
BTW. if you can use <div> elements instead of table to organize your
output, that might be much easier, my 2 cents. :)
Regards,
Xicheng- Hide quoted text -
- Show quoted text -

Below is a TT test code for your needs, you actually only need to
figure a data structure and then TT can do the other stuff pretty
easily:

you run it this way: ./ex1.pl 01.20.70 13 5

If you can use <div> and set CSS styles to control their (float|
width|...)s, then a plain 1-D array will do all stuff...

Regards,
Xicheng

#### ex1.pl ####
#!/usr/bin/perl
use warnings;
use strict;
use Template;

if (@ARGV < 2) {
print "./ex1.pl mm.dd.yy numPic [numCol]\n";
exit;}

my ($date, $numPic) = @ARGV;
my $numCol = $ARGV[2] || 3;

my $residuals = $numCol - ($numPic % $numCol);
my $items;
my $n = 0;

for my $item (1..$numPic) {
push @{$items->[$n]}, $item;
$n++ if not $item % $numCol;}

XC> push @{$items->[$n]}, (0) x $residuals;

A bug from the above line, should be :

push @{$items->[$n]}, (0) x $residuals if not $residuals == $numCol;

Regards,
Xicheng
my $tt = Template->new();
my $input = 'ex1.tt';
my $args = {
site => $date,
items => $items,};

$tt->process($input, $args, "$date.html") or die $tt->error( );

__END__

#### ex1.tt ####
<html>
<head>
<title>TT test page</title>
</head>
<body>
<table>
[% FOREACH item IN items -%]
<tr>
[% FOREACH cell IN item -%]
[% IF !cell -%]
<td>&nbsp;</td>
[% ELSE -%]
<td><img src="http://www.mywebsite.com/[% site %]/[% cell
%].JPG"></td>
[% END -%]
[% END -%]
</tr>
[% END -%]
</table>
</body>
</html>- Hide quoted text -

- Show quoted text -
 
X

Xicheng Jia

On May 12, 5:45 pm, (e-mail address removed) wrote:
Hello,
I was wondering if it was possible to create simple program that will
create .txt (or .html) files based on information provided via
prompts. If so, would someone be willing to assist me with this? I
know absolutely nothing about Perl (or any other programming language
for that matter)
For instance, if I wanted to create a file called 01.20.07.html based
off of a specific date (01 is MM, 20 is DD, 07 is YY) that looked like
this:
<html>
<body>
<table>
<tr><td><img src="http://www.mywebsite.com/01.20.07/1.JPG">
<td><img src="http://www.mywebsite.com/01.20.07/2.JPG">
<td><img src="http://www.mywebsite.com/01.20.07/3.JPG">
</tr>
<tr><td><img src="http://www.mywebsite.com/01.20.07/4.JPG">
<td><img src="http://www.mywebsite.com/01.20.07/5.JPG">
<td><img src="http://www.mywebsite.com/01.20.07/6.JPG">
</tr>
</body>
</html>
I would like to be able to enter the following information when
prompted by the program:
MM
DD
YY
Number of images
If possible, I would like to have the code know how many table rows to
create (in intervals of 3) based on the number of images.
Is this something someone here can assist with?
You might want to check any Perl templating modules like TT(Template
Toolkits),
http://search.cpan.org/dist/Template-Toolkit/
which could possibly make your stuff much easier.(in your case, the
template file need just several inputs and a simple loop.)
BTW. if you can use <div> elements instead of table to organize your
output, that might be much easier, my 2 cents. :)
Regards,
Xicheng- Hide quoted text -
- Show quoted text -
Below is a TT test code for your needs, you actually only need to
figure a data structure and then TT can do the other stuff pretty
easily:
you run it this way: ./ex1.pl 01.20.70 13 5
If you can use <div> and set CSS styles to control their (float|
width|...)s, then a plain 1-D array will do all stuff...
Regards,
Xicheng
#### ex1.pl ####
#!/usr/bin/perl
use warnings;
use strict;
use Template;
if (@ARGV < 2) {
print "./ex1.pl mm.dd.yy numPic [numCol]\n";
exit;}
my ($date, $numPic) = @ARGV;
my $numCol = $ARGV[2] || 3;
my $residuals = $numCol - ($numPic % $numCol);
my $items;
my $n = 0;
for my $item (1..$numPic) {
push @{$items->[$n]}, $item;
$n++ if not $item % $numCol;}
XC> push @{$items->[$n]}, (0) x $residuals;
A bug from the above line, should be :
push @{$items->[$n]}, (0) x $residuals if not $residuals == $numCol;
Regards,
Xicheng
my $tt = Template->new();
my $input = 'ex1.tt';
my $args = {
site => $date,
items => $items,};
$tt->process($input, $args, "$date.html") or die $tt->error( );
__END__
#### ex1.tt ####
<html>
<head>
<title>TT test page</title>
</head>
<body>
<table>
[% FOREACH item IN items -%]
<tr>
[% FOREACH cell IN item -%]
[% IF !cell -%]
<td>&nbsp;</td>
[% ELSE -%]
<td><img src="http://www.mywebsite.com/[% site %]/[% cell
%].JPG"></td>
[% END -%]
[% END -%]
</tr>
[% END -%]
</table>
</body>
</html>- Hide quoted text -
- Show quoted text -

Hahahaha, you make me lafff.
Systematic/programmable/generalization code.......

"Well, if you could just get it to here, then if so, manually do this step".
Its just fuckin magic!!

Hahahahahahaaaaaaaaaa.

No time to do it right? Get off you fat fuckin ass and do it by hand losers!!!!
Or you could pay an expert to give you a million dolla, 1 time use gem <---

losers- Hide quoted text -

- Show quoted text -

Hi, thank you for your comments. You are half right, and I just
started learning TT and am still far from touching the gory details of
this tool. :-( ....... clpm for me is pretty much like a classroom
where I practice myself and listen from others (especially those
professionals). I really apprecdiate all your input and suggestions.

Best regards,
Xicheng
 

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
473,997
Messages
2,570,241
Members
46,833
Latest member
BettyeMacf

Latest Threads

Top