Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Creating .txt/.html file using perl script

Reply
Thread Tools

Creating .txt/.html file using perl script

 
 
jdblackford@gmail.com
Guest
Posts: n/a
 
      05-12-2007
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?

 
Reply With Quote
 
 
 
 
Mirco Wahab
Guest
Posts: n/a
 
      05-12-2007
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
> 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
 
Reply With Quote
 
 
 
 
Dr.Ruud
Guest
Posts: n/a
 
      05-13-2007
(E-Mail 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.

--
Affijn, Ruud

"Gewoon is een tijger."
 
Reply With Quote
 
Xicheng Jia
Guest
Posts: n/a
 
      05-13-2007
On May 12, 5:45 pm, (E-Mail 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

 
Reply With Quote
 
Xicheng Jia
Guest
Posts: n/a
 
      05-13-2007
On May 13, 11:53 am, Xicheng Jia <(E-Mail Removed)> wrote:
> On May 12, 5:45 pm, (E-Mail 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;
}
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>

 
Reply With Quote
 
Xicheng Jia
Guest
Posts: n/a
 
      05-13-2007
On May 13, 6:47 pm, Xicheng Jia <(E-Mail Removed)> wrote:
> On May 13, 11:53 am, Xicheng Jia <(E-Mail Removed)> wrote:
>
>
>
>
>
> > On May 12, 5:45 pm, (E-Mail 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 -



 
Reply With Quote
 
Xicheng Jia
Guest
Posts: n/a
 
      05-15-2007
On May 15, 12:59 am, (E-Mail Removed) wrote:
> On 13 May 2007 16:50:33 -0700, Xicheng Jia <(E-Mail Removed)> wrote:
>
>
>
>
>
> >On May 13, 6:47 pm, Xicheng Jia <(E-Mail Removed)> wrote:
> >> On May 13, 11:53 am, Xicheng Jia <(E-Mail Removed)> wrote:

>
> >> > On May 12, 5:45 pm, (E-Mail 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 ****in magic!!
>
> Hahahahahahaaaaaaaaaa.
>
> No time to do it right? Get off you fat ****in 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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem in passing values to perl script using another perl script vikrant Perl Misc 4 08-10-2005 06:20 PM
Execute another perl script from my perl script Petterson Mikael Perl Misc 3 01-05-2005 01:31 PM
problem calling perl script from SOAP server perl script pj Perl Misc 3 04-09-2004 10:23 PM
Perl Help - Windows Perl script accessing a Unix perl Script dpackwood Perl 3 09-30-2003 02:56 AM
How to make Perl Script "POST" call from another Perl Script??? Wet Basement Perl 1 07-15-2003 10:25 PM



Advertisments