[HRPM] scaler or array and why?

jeff jeff at alanne.com
Thu Aug 24 18:27:03 CDT 2000


chicks at chicks.net wrote:


> When i was doing
> lots of CGI programming and working with alternative name spaces for
> variables the program just wouldn't work under a total use strict.

 I might agree more with this, but Perl 5.6 introduced 'our', which lets
you declare a variable as global and still maintain the lexical scoping
requirements of the strict pragma. I use to complain loudly about having
to write things like $Foo::var in order to 'use strict', but now it's
just an issue of how lazy you want to be.


> The ampersand (&) is only necessary for perl4 compatibility or creating
> references and it's basically ugly for just a plain call.

 Okay, in this case I agree. 

> If you take the newline off the die it will give you the line number which
> is usually pretty helpful.

 Also cool.


> >    Better yet, stuff the names of your files into an array and use that
> > to call the sub:
> >
> > my @files = qw( /home/alphaudt/www/cgi-bin/0/includes/onmouseover.shtml
> >               /home/alphaudt/www/cgi-bin/0/includes/meta_data.shtml
> >               you_get_the_idea );
> >
> >     Then just:
> >
> > &post_it( $files[0] );
> > &post_it( $files[1] );

> foreach $file (@files) { post_it($file); } # :-)

 Bzzzzt! He wanted to incorporate other data between the output of each
sub. Here, you are running the outputs together, which doesn't do what
he was looking for.


> print 'Content-type: text/html
> 
> <head>
> <!--START META DATA -->
> ';
> 
> I used single quotes in this case and I recommend doing so by default.  If
> you need interpolation you can switch to double quotes and escape all the
> bad characters.

 This is also cool, but I was trying to give him the option of
interpolating the output of the subs as scalars so the whole page could
be printed at once. Using single quotes increases the number of print
statements by the number of subs, which I consider ugly.

 Having said all that, I would probably take another approach to
generating the content in any case, pulling in the HTML from somewhere
else and using pure Perl to automagically glue it all together.
TIMTOWTDI.

 Jeff



More information about the Norfolk-pm mailing list