Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid

Re: Re: Not Matt's Scripts

by davorg (Chancellor)
on Aug 11, 2001 at 22:07 UTC ( #104167=note: print w/replies, xml ) Need Help??

in reply to Re: Not Matt's Scripts
in thread Not Matt's Scripts

It might be very instructive to show before and after versions of the scripts.

You can do that easily enough at the moment by pulling down my versions and comparing them with Matt's. I might consider putting Matt's versions in my distribution as a lesson to us all, but I think he's quite protective on things like that.

Finally, CPAN has a scripts archive, though it isn't widely used.

The deputy librarian of CPAN has already shown great interest in these scripts. They will, no doubt, appear there in due course.

I would recommend writing modules which can be scripted via it's API instead of writing scripts proper.

There's a chance that something like that might happen much later. The problem is that Matt's scripts are so popular precisely because they are so easy to use. There's no need to install modules from CPAN or do anything that a novice webmaster might find confusing. If these scripts are to find any kind of popularity they have to be just as simple to use.


Perl Training in the UK <>

Replies are listed 'Best First'.
(tye)Re: Not Matt's Scripts
by tye (Sage) on Aug 12, 2001 at 02:00 UTC

    Just write the functionality of the script as a module and put "standard usage" of it at the end like:

    package main; require File::Basename; File::Basename->import( qw(basename) ); if( &basename( $0 ) eq &basename( __FILE__ ) ) { require CGI; my $q= CGI->new(); # ... }
    that way you can make one file that is both a module and an all-in-one CGI script. This might even help the modulephobic slowly learn to like modules. (:

            - tye (but my friends call me "Tye")
      I've used a similar trick in the past, but rather than checking basename(), it's "unless ( caller ) { ...}", which seems to be equivalent.

        Ah, yes. Much better! I was also thinking of an improvement to prevent the example code from sticking around when it wasn't being used. For example:

        package main; BEGIN { my $isScript= ! caller(2); sub _isScript() { $isScript } } if( _isScript ) { require CGI; my $q= CGI->new(); # ... } undef &_isScript;
        would still require that the sample code be parsed the first time that the module is used but the optimizer would know to throw the resulting code away. Not quite as pretty, though.

        Another hack to prevent even the work of parsing can be done:

        package main; unless( caller ) { my $code= do { local($/); <DATA> }; my $file= __FILE__; my $line= __LINE__ + 5; eval "\n# line $line $file\n$code; 1" or die "$@\n"; } __END__ use CGI; # ... __END__

                - tye (but my friends call me "Tye")

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://104167]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (3)
As of 2022-12-04 05:50 GMT
Find Nodes?
    Voting Booth?

    No recent polls found