PDA

View Full Version : PERL AutoFormat


DELOCH
08-09-2006, 03:41 AM
Is there a way to autoformat in CGI::PERL because If not I will have to write it by hand...

if you do not get what I mean I will perform:


<html>
<head>
</head>
<body>
</body>
</html>

To

<html>
<head>
</head>
<body>
</body>
</html>


Is it possible in PERL? Thanks :D

FishMonger
08-09-2006, 04:45 AM
http://search.cpan.org/~lds/CGI.pm-3.20/CGI/Pretty.pm

DELOCH
08-09-2006, 05:23 AM
Where do I put it? the Bin? Lib or wherelse?

FishMonger
08-09-2006, 06:00 AM
Done properly, you'd use ppm or cpan to install modules. Since you're using XAMPP, you should check their documentation to see if they have ppm or some other utility to install modules.

If you want to install via cpan, you'd start by using this commad to get into the cpan shell.

perl -MCPAN -e shell

If this is the first time you've entered the shell, it will ask you (I forget the exact wording) if you're ready to manually configure cpan. Answer 'yes' and then it will "walk" you through its configuration.

Once you're at the shell prompt, you can install the module with this command.

install CGI::Pretty

http://cpan.org/misc/cpan-faq.html#How_install_Perl_modules

KevinADC
08-09-2006, 06:41 AM
I'm not going to recommend XAMPP anymore. There is virtually no documentation and the support forum is in German. I tried to see what version of perl XAMPP uses and it is no where on the website that I could find.

FishMonger
08-09-2006, 07:16 AM
I've never used XAMPP, but based on all the problems that I've run across where people are having problems with not having the most basic modules, I would never consider recommending it. They make you pay a very heavy price in inconvenience and troubleshooting just to save a little extra time in the initial installation.

DELOCH
08-09-2006, 05:21 PM
I tried installing PHP, Apache, MySQL by hand 50 times if not more, and the best I got was to install the Apache with PHP, but I then couldnt connect to Mysql and use PERL or PHPMyAdmin which was a huge problem :\

plus I put PERL sepperately into both C:/ and D:/ usr/bin's so I can access from both

but does it go into the bin/lib or what?

edit: by initial time you mean 9 hrs right? since that is how long it takes to get the apache to work properly with PHP

note: XAMPP has everything, I been using it for a long time now(like 2 months i believe... or was it one...) and It never failed me... except when I was trying to access a php querystring using $name :D

KevinADC
08-09-2006, 06:53 PM
I installed apache and perl and php and mysql with virtually no problems. The first install of apache was a little confusing at first but there are more than enough step-by-step tutorials on the internet that tell you exactly what to do.

From what I remember, php, perl and mysql all installed with no problems at all.

FishMonger
08-09-2006, 07:20 PM
It took me about 10 minutes to install them and about another 10 minutes to make a few apache configuration adjustments.

DELOCH
08-10-2006, 03:46 AM
erm... may I remind you I am 13...

and plus I never worked with ini files in my whole life... or conf

plus, this isnt why I made the topic... just tell me where to put the files

to the perl/bin perl/lib or what?

FishMonger
08-10-2006, 04:18 AM
perl/lib/CGI/Pretty.pm

DELOCH
08-10-2006, 04:33 AM
Oops... It appears I already had all those files...

edit: how do i get it to indent 4 pixels? instead of... lots

FishMonger
08-10-2006, 04:46 AM
The module's documentation tells you how to change the amount of indentation.

http://search.cpan.org/~lds/CGI.pm-3.20/CGI/Pretty.pm

DELOCH
08-10-2006, 06:05 AM
Thanks!

There is one more thing though...

how can i generate methods?

<a> is not the same as <a href="Hi">;

I thank you for your help :D

also how do I get pretty to work... it does it wrong...


#!/usr/bin/perl

use CGI qw(:standard);
use CGI::Pretty qw(:xhtml1);
use CGI::Pretty::INDENT = " ";

print header(), start_html();

print "I am not what I want me to be!";

print end_html();


How do i fix it?

FishMonger
08-10-2006, 06:15 AM
Can you elaborate on exactly what you need/want to do?

DELOCH
08-10-2006, 06:39 AM
I want to indent the start_html()

<html>
<head>
</head>
<body>
</body>
</html>

to indented form... is it posible?

FishMonger
08-10-2006, 06:41 AM
Did you try using the CGI::Pretty module?

FishMonger
08-10-2006, 06:56 AM
Is this what you want?
#!c:/perl/bin/perl

use CGI;
use CGI::Pretty;

$cgi = new CGI;

print $cgi->header, $cgi->start_html("CGI Pretty test page"),
$cgi->h1("CGI Pretty test page"),
$cgi->end_html;

With the moduleContent-Type: text/html; charset=ISO-8859-1

<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en-US" xml:lang="en-US">
<head>
<title>CGI Pretty test page</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
</head>
<body>
<h1>
CGI Pretty test page
</h1>
<p>
This is a test to see the effect of using the CGI::Pretty module
</p>

</body>
</html>
Without the module
Content-Type: text/html; charset=ISO-8859-1

<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en-US" xml:lang="en-US">
<head>
<title>CGI Pretty test page</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
</head>
<body>
<h1>CGI Pretty test page</h1><p>This is a test to see the effect of using the CGI::Pretty module</p>
</body>
</html>

KevinADC
08-10-2006, 08:13 AM
there is no standard for formatting HTML syntax or indentation of HTML or indentation of specific tags or areas of an html document (like the head section), so when you say CGI::Pretty does it wrong that doesn't mean anything.

CGI::Pretty uses formatting rules the author of the script thought were good, that is all. About the only things you can change are LINEBREAK, INDENT and AS_IS.

CGI::Pretty just sends back whatever the CGI module sent it for start_html as seen here in the CGi::Pretty source code:

sub start_html {
return CGI::start_html( @_ ) . $CGI::Pretty::LINEBREAK;
}

DELOCH
08-10-2006, 03:09 PM
ok it is just that I use:



<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en-US" xml:lang="en-US">
<head>
<title>CGI Pretty test page</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
</head>
<body>
<h1>CGI Pretty test page</h1>
<p>
This is a test to see the effect of using the CGI::Pretty module
</p>
</body>
</html>

KevinADC
08-10-2006, 06:16 PM
then you have to hard code that into your script, CGI::Pretty can not do that, nor can the CGI module. You can search CPAN and see if there are more html formatting modules available but I am not aware of any.

DELOCH
08-11-2006, 03:17 AM
Ok thanks ^_^

KevinADC
08-11-2006, 06:49 AM
You're welcome. :)

DELOCH
08-13-2006, 02:18 PM
I got it,

Is there a way to add a custom doctype? I really need it...