Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

I love perl but....

by costas (Scribe)
on May 22, 2001 at 14:03 UTC ( #82195=perlquestion: print w/replies, xml ) Need Help??

costas has asked for the wisdom of the Perl Monks concerning the following question:

I love using Perl as I find it can do much more than asp, php.... the only problem i have with Perl is its lack of web oriented functions and abilities (like embedding perl in html, 'includes' as in asp and php etc).

Does anyone know if Perl is going to be altered in future releases and give us those ASP/PHP style functions that make programing for the web all that much easier?

Thanks Costas

Replies are listed 'Best First'.
Re: I love perl but....
by Beatnik (Parson) on May 22, 2001 at 14:09 UTC
Re: I love perl but....
by jeroenes (Priest) on May 22, 2001 at 14:10 UTC
    I guess we share our love ;-).

    Embedding perl in html can be done, but the reverse is more versatile. Generate HTML with perl! Look at CGI and the Template toolkit for convenient methods.

    Including is no problem at all. Example:

    open INCL, "path_to_include_file"; { local $/ = undef; print <INCL>; } close INCL;
    The local and {} make the code cleaner, it works even without them.

    On unix, you can also use the following shorthand:

    print `cat path_to_include_file`;
    Hope this helps,

    Jeroen
    "We are not alone"(FZ)
    Fixed error. See Why or why not? - local undef $/

Re:(Zigster) I love perl but....
by zigster (Hermit) on May 22, 2001 at 14:45 UTC
    Install Active Perl on your NT box and you get PerlScript

    Quote:
    PerlScript is an ActiveX scripting engine that allows you to use Perl with any ActiveX scripting host. At this time, ActiveX scripting hosts include:

    • Internet Information Server 3.0/4.0
    • Peer Web Services 3.0/4.0
    • Microsoft Internet Explorer 4.0x
    • Windows Scripting Host

    In truth tho, perl is a very flexible language as you will often see on this site TIMTOWTDI (there is more than one way to do it) your are placing the solution before the problem. ASP and the like are cool SOLUTIONS but so is perl it's SOLUTIONS are just different. I would suggest taking a look at perl script. It will allow you to map your current methodology. I would futher sugest taking a fresh look at your PROBLEMS and see how you may solve them in perl. The rest of this thread gives some excellent advice regarding using perl with web based applications.
    --

    Zigster

      Zigster,
      Perhaps it is just my local configuration but I've found PerlScript to be very slow. I'd assumed that it was suffering from reloading the interpreter everytime the page was displayed - i.e. the problem that mod_perl fixes at the server end. Do you find the performance to be acceptable?
        To be honest I have not used perlscript in anger. I use CGI where I can. I have played with it enuff to know it exists and may help out in this circumstance.
        --

        Zigster
Re: embedding PERL in HTML
by gregor42 (Parson) on May 22, 2001 at 19:25 UTC
    the only problem i have with Perl is its lack of web oriented functions and abilities (like embedding perl in html, 'includes' as in asp and php etc)

    Well I won't belabor the point of "lack of web oriented functions" other than to suggest looking at http://search.cpan.org and putting HTML into the search field.

    However, I will underline a point made briefly by my fellow monks above:

    Mixing Programming Code & HTML is a Bad Idea.

    There are a lot of reasons for this, but the basic idea is that HTML coders & programmers are not usually the same people. They have different skill-sets & pay-scales.

    Most companies are smart enough not to waste a programmer's salary to have someone make changes to web pages that are buried in code.

    Further, it is an unofficial, but still hard & fast rule that programmers are not designers & designers are not programmers. As such you will find that companies tend to go outside to agencies when giving the web site a 'face lift.' This introduces a lot of people with no business having access to the programming code mucking around in the HTML.

    Active Server Pages & Java Server Pages have the ability to embed code directly in them. However you will notice that JSP aithors are encouraged to encapsulate their code in JavaBeans to keep the HTML clean and ASP is currently migrating towards the '.NET' paradigm which is similar.

    So I would also advise you, as others have above, to have a look at the Module in CPAN called HTML::Template. It's a very good starting point for thinking in terms of separation of logic & content with PERL.



    Wait! This isn't a Parachute, this is a Backpack!
Re: I love perl but....
by Hero Zzyzzx (Curate) on May 22, 2001 at 18:19 UTC

    If you really want to bump up your perl/HTML skillz, check out HTML::Template. I love this module. It's very simple, and it allows you to plug perl output into pure HTML files.

    Very elegant and powerful, and works EXCELLENTLY with mod_perl. It's not embedding perl in HTML, but I think it makes for MUCH more maintainable and understandable web apps by separating code from HTML clearly.

    Using HTML::Template, you don't end up with nasty code that mixes HTML in to perl scripts, seriously impeding maintability.

    Update:Umm, yeah. . . what gregor42 said below. . .

Re: I love perl but....
by runrig (Abbot) on May 22, 2001 at 19:57 UTC
    Another interesting alternative is HTML::Tree. There's an old version on CPAN, but I don't know why the author doesn't put the new version there. It's a module that allows you to create templates kind of like HTML::Template except that the template is 100% valid HTML, thereby completely separating your code and presentation.

    Update: Hero Zzyzzx is right, HTML::Template could be made valid HTML, but then your template is even uglier than before. And viewing the file in a browser, you have blank areas where data would go (unless you actually run the 'program'), whereas with HTML::Tree you can view real sample data (in a WYSIWYG sort of way).

      Not to be nitpicky, but you can have 100% valid HTML with HTML::Template too. You can embed the variables, if-thens, and loops in HTML comments. You can then run the HTML through a validator, if you desire.

Re: I love perl but....
by ozzy (Sexton) on May 22, 2001 at 20:52 UTC
    I find it that i have more fun with Perl than JSP/Servlets. Perl has just as many ASP/JSP style functions that make my life much easier.

    HTML::Mason
    HTML::Embperl
    HTML::Template


    Are great templating systems, which will make your life just as easy as those ASP/JSP style functions.

    -= Ozzy =-
Re: I love perl but....
by Anonymous Monk on May 22, 2001 at 21:36 UTC
Re: I love perl but....
by blue_cowdawg (Monsignor) on May 23, 2001 at 00:44 UTC

    I'm sorry, but you must not have checked out the CPAN site very closely. There are scads of (well maybe not scads... how many is a scad anyway...) ways to embed Perl inside of HTML.

    As far as ASP goes I must say that in my experience I haven't really seen anything done with ASP that either embedded perl, mod_perl, or just plain CGI couldn't accomplish.

    I also seem to remember that benchmark comparisons between PHP and Perl seemed to favor Perl FWIW.

    Check out the following on CPAN:

    • HTML::EP
    • HTML::Mason
    • Apache::ASP

    ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    Peter L. Berghold --- Peter@Berghold.Net
    "Those who fail to learn from history are condemned to repeat it."
    
Re: I love perl but....
by tachyon (Chancellor) on May 22, 2001 at 22:46 UTC
    You are aware of CGI.pm I presume.
    
    After a review of the free standard modules, what functionality
    do you miss??? 
    
    Here is a list of web related free modules that come with 
    the *standard* distribution of perl. Sincere apologies to 
    the hundred of authors of thousands of modules not 
    explicitly mentioned. For details see http://www.CPAN.org
    
    NB: CPAN is the Comprehensive Perl Archive Network.
    
    tachyon
    
       Benchmark
       Bundle
         DBD
             CSV
             mysql
         DBI
         LWP
       Business
         CreditCard
       Carp
       CGI
         Apache
         Carp
         Cookie
         Fast
         Imagemap
         Pretty
         Push
         Screen
         Switch
         XMLForm
       Chart
       Class
       Compress
         Zlib
       Config
       CPAN
       Crypt
       Date
         Calc
         Format
         Manip
         Parse
       DB
       DBD
         ADO
         CSV
         DB2
         dbd-sybase
         File
         Multiplex
         mysql
         ODBC
         Oracle
         Proxy
         Sybase
       DBI
         DBD
         FAQ
         Format
         ProxyServer
         Shell
         W32ODBC
       DB_File
       Digest
       DirHandle
       Fatal
       Fcntl
       File
         Basename
         CheckTree
         Compare
         Copy
         CounterFile
         DosGlob
         Find
         Glob
         Listing
         Path
         Recurse
         Slurp
         Spec
             Functions
             Mac
             OS2
             Unix
             VMS
             Win32
         stat
         Tools
       FileCache
       FileHandle
       Filter
         cpp
         decrypt
         exec
         sh
         tee
         Util
             Call
             Exec
       FindBin
       Font
         AFM
       Graph
         Kruskal
       HTML
         AsSubs
         Element
         Entities
         Filter
         Form
         FormatPS
         Formatter
         FormatText
         HeadParser
         LinkExtor
         Parse
         Parser
         Stream
         Template
         TokeParser
         TreeBuilder
       HTTP
         Cookies
         Daemon
         Date
         Headers
             Util
         Message
         Negotiate
         Request
             Common
         Response
         Status
       I18N
       Image
         Size
       IO
         AtomicFile
         Dir
         File
         Handle
         Lines
         Pipe
         Poll
         Scalar
         ScalarArray
         Seekable
         Select
         Socket
             INET
             UNIX
         Stringy
         Wrap
         WrapTie
       IPC
       Locale
         Country
         Language
       LWP
         Debug
         MediaTypes
         MemberMixin
         Protocol
         RobotUA
         Simple
         UserAgent
       Mail
         POP3Client
       Math
       MD5
       MIME
         Base64
         Lite
         QuotedPrint
       MLDBM
       Mysql
       NDBM_File
       Net
         Bind
             Resolv
             Utils
         Cmd
         DNS
             Header
             Packet
             Question
             Resolver
             RR
                 A
                 AAAA
                 AFSDB
                 CNAME
                 EID
                 HINFO
                 ISDN
                 LOC
                 MB
                 MG
                 MINFO
                 MR
                 MX
                 NAPTR
                 NIMLOC
                 NS
                 NSAP
                 NULL
                 PTR
                 PX
                 RP
                 RT
                 SOA
                 SRV
                 TXT
                 X25
             Update
         Domain
         DummyInetd
         FTP
         hostent
         LDAP
             BER
             Constant
             Entry
             FAQ
             Filter
             LDIF
             Message
             Reference
             Schema
             Search
             Util
         netent
         Netrc
         NNTP
         PH
         Ping
         POP3
         protoent
         servent
         SMTP
         SNPP
         Telnet
         Time
         Whois
       Netscape
         History
         HistoryURL
       News
         Newsrc
         NNTPClient
       POE
       POSIX
       PPM
         SOAPClient
         SOAPServer
       SGMLS
         Output
         Refs
       SHA
       Shell
       SOAP
         Defs
         Envelope
         EnvelopeMaker
         GenericHashSerializer
         GenericInputStream
         GenericScalarSerializer
         OutputStream
         Packager
         Parser
             HTTP
                 Apache
                 CGI
                 Client
                 Server
         TypeMapper
       Socket
       Sort
         PolySort
       SQL
         Eval
         Statement
       Statistics
       Storable
       String
       Sybase
         BCP
       Symbol
       Sys
         Hostname
         Syslog
       Test
         Harness
       Text
         Abbrev
         CSV_XS
         German
         Metaphone
         ParseWords
         Soundex
         Striphigh
         Tabs
         Template
         Vpp
         Wrap
       Thread
         Queue
         Semaphore
         Signal
         Specific
       Tie
       Time
         gmtime
         HiRes
         Local
         localtime
         Period
         tm
         Zone
       Tk
       User
       Win32
       Win32API
       WWW
         RobotRules
             AnyDBM_File
         Search
             AltaVista
                 AdvancedNews
                 AdvancedWeb
                 Careers
                 Intranet
                 News
                 Web
                 Classifieds
                     Employment
             Crawler
             Dice
             EuroSeek
             Excite
                 News
             ExciteForWebServers
             Fireball
             FolioViews
             Google
             Gopher
             GoTo
             HeadHunter
             HotFiles
             Infoseek
                 Companies
                 Email
                 News
                 Web
             Livelink
             LookSmart
             Lycos
                 Pages
                 Sites
             MetaCrawler
             Metapedia
             Monster
             MSIndexServer
             NetFind
             NorthernLight
             Null
             PLweb
             Search97
             SFgate
             Simple
             Snap
             Test
             Verity
             VoilaFr
             WebCrawler
                 Classifieds
                     Employment
             ZDNet
         SearchResult
       XML
         DOM
         Element
         Parser
             Expat
         PPD
         PPMConfig
         ValidatingElement
    
    
Re: I love perl but....
by Anonymous Monk on May 23, 2001 at 01:37 UTC
    There are lots of different solutions to this issue, depending on what problem you are addressing. here's a couple of pretty darn good ones http://www.template-toolkit.org/ http://perl.apache.org/embperl/ among others hth --mark

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://82195]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (4)
As of 2022-05-24 19:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you prefer to work remotely?



    Results (84 votes). Check out past polls.

    Notices?