[13385] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 795 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Sep 14 17:07:25 1999

Date: Tue, 14 Sep 1999 14:05:29 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Tue, 14 Sep 1999     Volume: 9 Number: 795

Today's topics:
        /etc/passwd and *pwent <proberts@clark.net>
    Re: /etc/passwd and *pwent (Kragen Sitaker)
    Re: Anyone know what "premature script header means"? (Abigail)
    Re: Anyone know what "premature script header means"? (Abigail)
    Re: Anyone know what "premature script header means"? <gellyfish@gellyfish.com>
    Re: Anyone know what "premature script header means"? <AgitatorsBand@yahoo.com>
    Re: Array Problems (Abigail)
    Re: CGI from CGI without modules... <mike@yawp.com>
    Re: CGI Oracle problem (Joachim Zobel)
    Re: challenge results (Jack Applin)
    Re: challenge results <jerrad@networkengines.com>
    Re: challenge results (Abigail)
    Re: challenge results (Matthew Bafford)
    Re: Data structure for Dynamic Use of CGI.pm? (Kragen Sitaker)
    Re: Desperately searching for perl lint (T. Alex Beamish)
        Filtering ascii escape sequences in a text file <wpflum@my-deja.com>
    Re: Filtering ascii escape sequences in a text file <tchrist@mox.perl.com>
        Forcing Variable interpolation of string read from a fi <rdicke@wirespeednetworks.com>
    Re: Forcing Variable interpolation of string read from  <debot@xs4all.nl>
    Re: Forcing Variable interpolation of string read from  <makkulka@cisco.com>
    Re: Forcing Variable interpolation of string read from  <tchrist@mox.perl.com>
    Re: GD.pm question <maloy@goldinc.com>
    Re: Generating an email with form entry (CGI) <jgmtest@serviceteam.ltd.uk>
        Digest Administrivia (Last modified: 1 Jul 99) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: Tue, 14 Sep 1999 19:20:52 GMT
From: Paul D. Robertson <proberts@clark.net>
Subject: /etc/passwd and *pwent
Message-Id: <oexD3.1209$zI3.31828@iad-read.news.verio.net>

Is there an easy way to point the perl getpwent(), setpwent() type calls
at a file other than /etc/passwd?  For instance, if I had
/home/lusers/foo as a password-like file for an application, and I still
wanted to use setpwent(), how exactly could I go about doing so (or is it
not possible?)

I've tried the man pages, the Camel book, dejanews, and google to no
avail.  I'm going to have multiple passwd-alike files and chroot currently
isn't viable (though I'll go there if I must.)

Thanks,

Paul
-----------------------------------------------------------------------------
Paul D. Robertson      "My statements in this message are personal opinions
proberts@clark.net      which may have no basis whatsoever in fact."
                                                                     PSB#9280


------------------------------

Date: Tue, 14 Sep 1999 21:02:04 GMT
From: kragen@dnaco.net (Kragen Sitaker)
Subject: Re: /etc/passwd and *pwent
Message-Id: <gJyD3.10936$N77.819893@typ11.nn.bcandid.com>

In article <oexD3.1209$zI3.31828@iad-read.news.verio.net>,
Paul D. Robertson  <proberts@clark.net> wrote:
>Is there an easy way to point the perl getpwent(), setpwent() type calls
>at a file other than /etc/passwd?

Possibly if you're using PAM.

You could do some LD_PRELOAD hackery to redirect the C getpwent() etc.
functions (assuming your perl is dynamically linked.)

But I'd just split /:/ :)
-- 
<kragen@pobox.com>       Kragen Sitaker     <http://www.pobox.com/~kragen/>
Tue Sep 14 1999
55 days until the Internet stock bubble bursts on Monday, 1999-11-08.
<URL:http://www.pobox.com/~kragen/bubble.html>


------------------------------

Date: 14 Sep 1999 14:41:56 -0500
From: abigail@delanet.com (Abigail)
Subject: Re: Anyone know what "premature script header means"?
Message-Id: <slrn7tt9d4.g83.abigail@alexandra.delanet.com>

Lisa Saari (sculptural@aol.comnojunk) wrote on MMCCV September MCMXCIII
in <URL:news:19990914101610.01941.00000054@ng-fz1.aol.com>:
?? My scripts aren't going through and are instead coming back with a 500-Intern
?? Server Error message.  It does tell me that the script has "a premature scrip
?? header".  Can someone please respond ASAP!


It means you have a bug.

Or two.



Abigail
-- 
Three?


  -----------== Posted via Newsfeeds.Com, Uncensored Usenet News ==----------
   http://www.newsfeeds.com       The Largest Usenet Servers in the World!
------== Over 73,000 Newsgroups - Including  Dedicated  Binaries Servers ==-----


------------------------------

Date: 14 Sep 1999 14:44:47 -0500
From: abigail@delanet.com (Abigail)
Subject: Re: Anyone know what "premature script header means"?
Message-Id: <slrn7tt9ib.g83.abigail@alexandra.delanet.com>

Leon Mergen (leon@solatis.com) wrote on MMCCV September MCMXCIII in
<URL:news:7rlo1n$6am$1@zonnetje.nl.uu.net>:
== probably you forgot :
== 
== print "Content-type: text/html\n\n";

Why? Because you made that mistake once? I can easily come up with
hundreds of situations that cause the error described below, and
do have the above mentioned print statement.

I think Lisa has a bug in line 17.

And you are posting Jeopardy style. Stop that. We don't read from
bottom to top.

== Lisa Saari wrote in message
== <19990914101610.01941.00000054@ng-fz1.aol.com>...
== >My scripts aren't going through and are instead coming back with a
== 500-Internal
== >Server Error message.  It does tell me that the script has "a premature
== script
== >header".  Can someone please respond ASAP!



Abigail
-- 
perl -weprint\<\<EOT\; -eJust -eanother -ePerl -eHacker -eEOT


  -----------== Posted via Newsfeeds.Com, Uncensored Usenet News ==----------
   http://www.newsfeeds.com       The Largest Usenet Servers in the World!
------== Over 73,000 Newsgroups - Including  Dedicated  Binaries Servers ==-----


------------------------------

Date: 14 Sep 1999 17:46:55 -0000
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: Anyone know what "premature script header means"?
Message-Id: <7rm1mf$60t$1@gellyfish.btinternet.com>

On 14 Sep 1999 14:16:10 GMT Lisa Saari wrote:
> My scripts aren't going through and are instead coming back with a 500-Internal
> Server Error message.  It does tell me that the script has "a premature script
> header".  Can someone please respond ASAP!

Please see the section entitled:

    My CGI script runs from the command line but not the browser. 

in perlfaq9.

/J\
-- 
Jonathan Stowe <jns@gellyfish.com>
<http://www.gellyfish.com>
Hastings: <URL:http://dmoz.org/Regional/UK/England/East_Sussex/Hastings>


------------------------------

Date: Tue, 14 Sep 1999 20:40:44 GMT
From: Scratchie <AgitatorsBand@yahoo.com>
Subject: Re: Anyone know what "premature script header means"?
Message-Id: <gpyD3.568$n82.96093@news.shore.net>

Lisa Saari <sculptural@aol.comnojunk> wrote:
: My scripts aren't going through and are instead coming back with a 500-Internal
: Server Error message.  It does tell me that the script has "a premature script
: header".  Can someone please respond ASAP!

All CGI scripts have to output some sort of headers -- at the very least a
"Content-type" header -- before they output anything else. If you're
getting this error, it usually means that either you forgot to return a
header, or your program failed for some reason prior to returning the
headers. 

Using something like CGI::Carp("fatalsToBrowser") may help you debug such
a situation.

--Art

-- 
--------------------------------------------------------------------------
                    National Ska & Reggae Calendar
                  http://www.agitators.com/calendar/
--------------------------------------------------------------------------


------------------------------

Date: 14 Sep 1999 14:45:23 -0500
From: abigail@delanet.com (Abigail)
Subject: Re: Array Problems
Message-Id: <slrn7tt9jl.g83.abigail@alexandra.delanet.com>

Michael Scheferhoff (m.scheferhoff@gmx.de) wrote on MMCCV September
MCMXCIII in <URL:news:37DE17FF.1E54EE24@gmx.de>:
## 
## is it possible to put a value in the middle of an array, so that the
## ones behinds move one place down?


Yes. Use a slice, or splice.



Abigail
-- 
perl -e '* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
         / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / 
         % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %;
         BEGIN {% % = ($ _ = " " => print "Just Another Perl Hacker\n")}'


  -----------== Posted via Newsfeeds.Com, Uncensored Usenet News ==----------
   http://www.newsfeeds.com       The Largest Usenet Servers in the World!
------== Over 73,000 Newsgroups - Including  Dedicated  Binaries Servers ==-----


------------------------------

Date: Tue, 14 Sep 1999 15:38:03 -0500
From: <mike@yawp.com>
To: "John J. Straumann" <jstraumann@worldnet.att.net>
Subject: Re: CGI from CGI without modules...
Message-Id: <Pine.NEB.3.96.990914150923.10768C-100000@www.yawp.com>


> Thanks to everyone who answered my question about a CGI calling another
> CGI, but is there a way to do this without having to get all those
> modules? 

ouch.. statements like that sorta fly in the face of the Reuse Is Good
mindset.   try repeating 'Reuse Is Good' about 50,000 times, and you'll be
in the right mindset to use modules religiously.

as a more direct answer, pretty much anything that can be included as a
module can be done with straight code.   if you're doing something that's
implemented by a module and think you might want to wrap that
functionality into your top-level code, the module is one of the best
places to start looking for ideas.   the practice has several benefits:

 - you get exposure to code which has stood up in the real world.

 - you learn how someone else has solved the same type of problem you're
trying to solve.

 - you get a quick, front-end view of how big the problem actually is..
there are often a whole slew of hidden gotchas that make a job much bigger
than it seems at first glance.

 - you get a better understanding of the module's inner workings, which is
handy even if you do decide to import it.

 - you find out whether the module is worth using at all.   just because
10,000 worshippers have learned the API doesn't mean the internals aren't
crap.   i happen to take an heretical view toward CGI.pm for reasons
vaguely along those lines.


pick up a copy of LWP from CPAN and give it a read.   if you think you can
do a better job of what you need with top-level code, the module can serve
as your requirements and design reference.   if you can't read the module 
at all, you'll need to spend some more time doing research before you're
ready to think about rolling your own.




--
mike





------------------------------

Date: Tue, 14 Sep 1999 20:05:40 GMT
From: jzobel@my-dejanews.com (Joachim Zobel)
Subject: Re: CGI Oracle problem
Message-Id: <37dde8d7.496455@dilbert.crrrwg.de>

"Anthony Adams" <antoine@pacha.nl> wrote:

>At my work i'm working on a script that puts some values into a oracle 8
>database.
>
>The stupid this is:
>When we run it from the commandine it goes extremely fast (as it should)
>But when the data is posted from the webpage we designed for it and submit
>the data it takes about 20-30 seconds to return. The statement works, data
>is entered into the database but why does it take so damn long?

Two theories:

1. A DNS lookup (possibly reverse) fails.
2. Look for zombies. If you find them, read about wait.

hth,
Joachim

 --
"I read the news today oh boy"             - The Beatles - A Day In The Life

Althoug this message has a valid From header, replies 
to user@netcologne.de where user = nc-zobeljo 
are preferred.


------------------------------

Date: 14 Sep 1999 19:25:13 GMT
From: neutron@fc.hp.com (Jack Applin)
Subject: Re: challenge results
Message-Id: <7rm7ep$sue$1@fcnews.fc.hp.com>

Matthew Bafford (*@dragons.duesouth.net) wrote:
>	perl -pe 's/./rand(2)<1?uc$&:lc$&/ge'

This one's a bit shorter:
	perl -pe 's/./rand>.5?uc$&:lc$&/ge'

This one doesn't work, but I think it should:
	perl -0\\1pe '$_=rand>.5?uc:lc'

The 5.005_02 perlvar man page states:

	Setting $/ to a reference to an integer, scalar containing an
	integer, or scalar that's convertable to an integer will
	attempt to read records instead of lines, with the maximum
	record size being the referenced integer.

Given that, it seems that an argument of \1 to -0 should be valid.


					-Jack Applin
					 neutron@fc.hp.com



------------------------------

Date: Tue, 14 Sep 1999 15:35:22 -0400
From: jerrad pierce <jerrad@networkengines.com>
Subject: Re: challenge results
Message-Id: <37DEA37A.42F0955E@networkengines.com>

Those are remarkably close to mine
http://www.pthbb.org/software/bin/rcase

(the srand line just makes it more useable on some systems)


------------------------------

Date: 14 Sep 1999 14:59:55 -0500
From: abigail@delanet.com (Abigail)
Subject: Re: challenge results
Message-Id: <slrn7ttaet.g83.abigail@alexandra.delanet.com>

Steven de Rooij (srooij@wins.uva.nl) wrote on MMCCV September MCMXCIII in
<URL:news:37DE7E5D.1C172E3E@wins.uva.nl>:
 .. 
 .. (Everything on a new line:)
 .. perl -ne'$x{join"",sort split//}.=$_}{/.\n./&&print for%x'
 .. 
 .. (All anagrams on one line:)
 .. perl -lne'$x{join"",sort split//}.="$_ "}{/ ./&&print for%x'
 .. 
 .. If anyone knows how to squeeze another byte out of this I will start
 .. uttering strange sounds.


Start uttering ;-)  The first one can obviously be improved, as there's
no need to waste 2 bytes on indicating a newline:

perl -ne'$x{join"",sort split//}.=$_}{/.
 ./&&print for%x'


Abigail
-- 
perl -MTime::JulianDay -lwe'@r=reverse(M=>(0)x99=>CM=>(0)x399=>D=>(0)x99=>CD=>(
0)x299=>C=>(0)x9=>XC=>(0)x39=>L=>(0)x9=>XL=>(0)x29=>X=>IX=>0=>0=>0=>V=>IV=>0=>0
=>I=>$r=-2449231+gm_julian_day+time);do{until($r<$#r){$_.=$r[$#r];$r-=$#r}for(;
!$r[--$#r];){}}while$r;$,="\x20";print+$_=>September=>MCMXCIII=>()'


  -----------== Posted via Newsfeeds.Com, Uncensored Usenet News ==----------
   http://www.newsfeeds.com       The Largest Usenet Servers in the World!
------== Over 73,000 Newsgroups - Including  Dedicated  Binaries Servers ==-----


------------------------------

Date: Tue, 14 Sep 1999 20:41:20 GMT
From: *@dragons.duesouth.net (Matthew Bafford)
Subject: Re: challenge results
Message-Id: <slrn7ttbip.2l5.*@dragons.duesouth.net>

14 Sep 1999 19:25:13 GMT, a great smashing of the head occured against
Jack Applin)'s keyboard, causing comp.lang.perl.misc to receive this: 
: This one doesn't work, but I think it should:
: 	perl -0\\1pe '$_=rand>.5?uc:lc'

man perlrun:
 ...
       -0[digits]
            specifies the input record separator ($/) as an octal
            number.  If there are no digits, the null character
            is the separator.  Other switches may precede or
            follow the digits.  For example, if you have a
            version of find which can print filenames terminated
            by the null character, you can say this:
 ...

\\1 isn't an octal number.

perl -pe 'BEGIN{$/=\1}$_=rand>.5?uc:lc'

works but consumes more space...

: 					-Jack Applin

--Matthew


------------------------------

Date: Tue, 14 Sep 1999 20:59:16 GMT
From: kragen@dnaco.net (Kragen Sitaker)
Subject: Re: Data structure for Dynamic Use of CGI.pm?
Message-Id: <EGyD3.10933$N77.813936@typ11.nn.bcandid.com>

In article <7r35p3$qvj$1@macaw.cyberport.com>,
Linux GNUBEE <dchurch@kabana.net> wrote:
>I want to read in a file with four values on each line.  Each value is
>separated by a \t.  I want to display one of the variables (the fourth one
>from each line) from each line of four as a radio-button selection in a FORM
>(using CGI.pm).  If a particular radio-button is selected on the form, I
>want to pass all four variables to another script.  How can I efficiently
>identify which other three variables relate to the selected variable?  A
>hash table?  Any ideas on a data structure example?

while (<FILE_WITH_FOUR_VALUES>) {
	my $three, $one = /(.*)\t(.*)/;
	print qq(<option value="$three">$one</option>\n);
}

You can, of course, store it in a data structure instead of printing it
out immediately.

This requires that your second script not trust those three values; the
browser can send back any values it wants.  (The same is true of the
hidden field someone else posted.)

Kragen
-- 
<kragen@pobox.com>       Kragen Sitaker     <http://www.pobox.com/~kragen/>
Tue Sep 14 1999
55 days until the Internet stock bubble bursts on Monday, 1999-11-08.
<URL:http://www.pobox.com/~kragen/bubble.html>


------------------------------

Date: Tue, 14 Sep 1999 20:04:12 GMT
From: talexb@tabsoft.on.ca (T. Alex Beamish)
Subject: Re: Desperately searching for perl lint
Message-Id: <37deaa6b.175917658@news1.on.sympatico.ca>

On 06 Sep 1999 20:56:00 +0200, kaih=7ONAKsc1w-B@khms.westfalen.de (Kai
Henningsen) wrote:

>talexb@tabsoft.on.ca (T. Alex Beamish)  wrote on 26.08.99 in <37c4c19f.281564252@news1.on.sympatico.ca>:
>
>> Thank you all .. since the "perl -MO=Lint -Mstrict -w" that Abigail
>> suggested didn't work on the Linux platform I'm using, I will see if I
>> can write something myself.
>
>It certainly works on Linux. It does, however, need perl 5.005.

I get the following version string when I run perl -v

  This is perl, version 5.005_03 built for i386-linux

And

  perl -MO=Lint -Mstrict -c mkgraph.pl

just returns

  mkgraph.pl syntax OK

I expect perl's lint to complain about a fair number of things ..
Gimpel's PC-Lint worked very well for me .. it would give piles of
warnings that I could choose to ignore.

Hmm. Maybe I'll check to see if their web site has anything for perl.


   T. Alex Beamish -- TAB Software
Toronto, Ontario -- www.tabsoft.on.ca


------------------------------

Date: Tue, 14 Sep 1999 20:01:38 GMT
From: Bill <wpflum@my-deja.com>
Subject: Filtering ascii escape sequences in a text file
Message-Id: <7rm9is$1ut$1@nnrp1.deja.com>

I'm looking for either a module or a script that will filter out ascii
escape sequences from a text file. I'd rather not re-invent the wheel
if this has been done already.  What I'm doing is taking a screen dump
from a telnet session using Expect and temporarly saving it to a file,
real version of prog will do it in a string but its easier to test the
filter using a file that does not change. The problem is the telnet
session has escape control sequences in it which stop me from pulling
out the text info I'm looking for.  Now I cannot just replace using a
pattern match routine since the ansii sequences vary in lenght so I'm
looking for some thing that can translate those sequences into spaces
so I can filter out the garbage and get what I need.  If I don't get
any response I guess I'll start banging my head against the nearest
wall until the solution comes to me ;)

Thanks.


Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.


------------------------------

Date: 14 Sep 1999 14:54:42 -0700
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: Filtering ascii escape sequences in a text file
Message-Id: <37deb612@cs.colorado.edu>

     [courtesy cc of this posting mailed to cited author]

In comp.lang.perl.misc, 
    Bill <wpflum@my-deja.com> writes:
:I'm looking for either a module or a script that will filter out ascii
:escape sequences from a text file. I'd rather not re-invent the wheel
:if this has been done already.  

% man col | col -b

COL(1)			     UNIX Reference Manual			COL(1)

NAME
     col - filter reverse line feeds from input

SYNOPSIS
     col [-bfx] [-l num]

DESCRIPTION
     Col filters out reverse (and half reverse) line feeds so the output is in
     the correct order with only forward and half forward line feeds, and re-
     places white-space characters with tabs where possible.  This can be use-
     ful in processing the output of nroff(1) and tbl(1).

     Col reads from standard input and writes to standard output.

     The options are as follows:

     -b	    Do not output any backspaces, printing only the last character
	    written to each column position.

     -f	    Forward half line feeds are permitted (``fine'' mode).  Normally
	    characters printed on a half line boundary are printed on the fol-
	    lowing line.

     -x	    Output multiple spaces instead of tabs.

     -lnum  Buffer at least num lines in memory.  By default, 128 lines are
	    buffered.

     The control sequences for carriage motion that col understands and their
     decimal values are listed in the following table:

     ESC-7	      reverse line feed (escape then 7)
     ESC-8	      half reverse line feed (escape then 8)
     ESC-9	      half forward line feed (escape then 9)
     backspace	      moves back one column (8); ignored in the first column
     carriage return  (13)
     newline	      forward line feed (10); also does carriage return
     shift in	      shift to normal character set (15)
     shift out	      shift to alternate character set (14)
     space	      moves forward one column (32)
     tab	      moves forward to next tab stop (9)
     vertical tab     reverse line feed (11)

     All unrecognized control characters and escape sequences are discarded.

     Col keeps track of the character set as characters are read and makes
     sure the character set is correct when they are output.

     If the input attempts to back up to the last flushed line, col will dis-
     play a warning message.

SEE ALSO
     expand(1),	 nroff(1),  tbl(1)

HISTORY
     A col command appeared in Version 6 AT&T UNIX.

BSD Experimental		 June 17, 1991				     1
-- 
A computer scientist is someone who, when told to "Go to Hell," sees
the "go to," rather than the destination, as harmful.
                -- Dr. Roger M. Firestone, rfire@cais.cais.com


------------------------------

Date: Tue, 14 Sep 1999 15:32:51 -0400
From: Ronald Dicke <rdicke@wirespeednetworks.com>
Subject: Forcing Variable interpolation of string read from a file - How?
Message-Id: <37DEA2E3.F01F2720@wirespeednetworks.com>

If I have a file which contains the following line:
Have a nice day, $name
and I read this file using a perl script which has the variable $name
defined, how can I force the
interpolation of that variable in the string just read from the file, so
that is $today = "Genius" the result would be:
Have a nice day, Genius


Please copy me at rdicke@yahoo.com

Thanks
Ron



------------------------------

Date: Tue, 14 Sep 1999 22:26:42 +0200
From: Frank de Bot <debot@xs4all.nl>
Subject: Re: Forcing Variable interpolation of string read from a file - How?
Message-Id: <37DEAF82.ABA22F65@xs4all.nl>

I don't realy understand what you want, but I'll give it a try...

$name = "My name";  # Not important here...
$today = "Genius";

open (FILE, "file.txt");
@file = <FILE>;  # Let's pet every line in an part of the array
close (FILE);

print "$file[0]";  # STOP! This would return: Have a nice day, $name . The
only way to uses variables is in the script itself

# $file[0] is the first line of the file. $file[1] would be the second, and
so on...

$file[0] =~ s/$name/$today/g;  #Replaces every "$name" in the variable with
$today

print "$file[0]"; # Yes!. Now it return Nice day, Genius .


(Note. This script isn't yet debugged....)


I hope this is exactly what you have asked. If not, please try to explain
again.



Ronald Dicke wrote:

> If I have a file which contains the following line:
> Have a nice day, $name
> and I read this file using a perl script which has the variable $name
> defined, how can I force the
> interpolation of that variable in the string just read from the file, so
> that is $today = "Genius" the result would be:
> Have a nice day, Genius
>
> Please copy me at rdicke@yahoo.com
>
> Thanks
> Ron

--
Penpal International
http://www.debot.nl/ppi/
ppi@debot.nl or debot@xs4all.nl




------------------------------

Date: Tue, 14 Sep 1999 13:40:50 -0700
From: Makarand Kulkarni <makkulka@cisco.com>
Subject: Re: Forcing Variable interpolation of string read from a file - How?
Message-Id: <37DEB2D1.40A7294B@cisco.com>

[  Ronald Dicke wrote:

> .... how can I force the
> interpolation of that variable in the string just read from the file, so
> that is $today = "Genius" the result would be:
>
> Please copy me at rdicke@yahoo.com

Read this article on WebMonkey that discussed usage of basic
templates  --
http://www.hotwired.com/webmonkey/code/97/21/index2a.html?tw=backend
==



------------------------------

Date: 14 Sep 1999 14:53:07 -0700
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: Forcing Variable interpolation of string read from a file - How?
Message-Id: <37deb5b3@cs.colorado.edu>

     [courtesy cc of this posting mailed to cited author]

In comp.lang.perl.misc, 
    Ronald Dicke <rdicke@wirespeednetworks.com> writes:
:If I have a file which contains the following line:
:Have a nice day, $name
:and I read this file using a perl script which has the variable $name
:defined, how can I force the
:interpolation of that variable in the string just read from the file, so
:that is $today = "Genius" the result would be:
:Have a nice day, Genius

This is a FAQ, and you are doing it wrong.
The answer is that you set up a hash like

    %UserVars = (
	'name' => "whatever",
	'addresss' => "whatever",
	# ...
    );

Then you find something after the dollar and search 
in your %UserVars for it. You do NOT let it at your
own variables.

There are 22 template modules out there.  Please use one.



=head2 How can I use a variable as a variable name?

Beginners often think they want to have a variable contain the name
of a variable.

    $fred    = 23;
    $varname = "fred";
    ++$$varname;         # $fred now 24

This works I<sometimes>, but it is a very bad idea for two reasons.

The first reason is that they I<only work on global variables>.
That means above that if $fred is a lexical variable created with my(),
that the code won't work at all: you'll accidentally access the global
and skip right over the private lexical altogether.  Global variables
are bad because they can easily collide accidentally and in general make
for non-scalable and confusing code.

Symbolic references are forbidden under the C<use strict> pragma.
They are not true references and consequently are not reference counted
or garbage collected.

The other reason why using a variable to hold the name of another
variable a bad idea is that the question often stems from a lack of
understanding of Perl data structures, particularly hashes.  By using
symbolic references, you are just using the package's symbol-table hash
(like C<%main::>) instead of a user-defined hash.  The solution is to
use your own hash or a real reference instead.

    $fred    = 23;
    $varname = "fred";
    $USER_VARS{$varname}++;  # not $$varname++

There we're using the %USER_VARS hash instead of symbolic references.
Sometimes this comes up in reading strings from the user with variable
references and wanting to expand them to the values of your perl
program's variables.  This is also a bad idea because it conflates the
program-addressable namespace and the user-addressable one.  Instead of
reading a string and expanding it to the actual contents of your program's
own variables:

    $str = 'this has a $fred and $barney in it';
    $str =~ s/(\$\w+)/$1/eeg;		  # need double eval

Instead, it would be better to keep a hash around like %USER_VARS and have
variable references actually refer to entries in that hash:

    $str =~ s/\$(\w+)/$USER_VARS{$1}/g;   # no /e here at all

That's faster, cleaner, and safer than the previous approach.  Of course,
you don't need to use a dollar sign.  You could use your own scheme to
make it less confusing, like bracketed percent symbols, etc.

    $str = 'this has a %fred% and %barney% in it';
    $str =~ s/%(\w+)%/$USER_VARS{$1}/g;   # no /e here at all

Another reason that folks sometimes think they want a variable to contain
the name of a variable is because they don't know how to build proper
data structures using hashes.  For example, let's say they wanted two
hashes in their program: %fred and %barney, and to use another scalar
variable to refer to those by name.

    $name = "fred";
    $$name{WIFE} = "wilma";     # set %fred

    $name = "barney";           
    $$name{WIFE} = "betty";	# set %barney

This is still a symbolic reference, and is still saddled with the
problems enumerated above.  It would be far better to write:

    $folks{"fred"}{WIFE}   = "wilma";
    $folks{"barney"}{WIFE} = "betty";

And just use a multilevel hash to start with.

The only times that you absolutely I<must> use symbolic references are
when you really must refer to the symbol table.  This may be because it's
something that can't take a real reference to, such as a format name.
Doing so may also be important for method calls, since these always go
through the symbol table for resolution.

In those cases, you would turn off C<strict 'refs'> temporarily so you
can play around with the symbol table.  For example:

    @colors = qw(red blue green yellow orange purple violet);
    for my $name (@colors) {
        no strict 'refs';  # renege for the block
        *$name = sub { "<FONT COLOR='$name'>@_</FONT>" };
    } 

All those functions (red(), blue(), green(), etc.) appear to be separate,
but the real code in the closure actually was compiled only once.

So, sometimes you might want to use symbolic references to directly
manipulate the symbol table.  This doesn't matter for formats, handles, and
subroutines, because they are always global -- you can't use my() on them.
But for scalars, arrays, and hashes -- and usually for subroutines --
you probably want to use hard references only.
-- 
    X-Windows: More than enough rope.
	--Jamie Zawinski


------------------------------

Date: 14 Sep 1999 19:29:49 GMT
From: Bill Maloy <maloy@goldinc.com>
Subject: Re: GD.pm question
Message-Id: <7rm7nd$1fgp@enews3.newsguy.com>

Bernie <bfb@att.net> wrote:

> I've installed the following perl and c modules, and still
> receive the font error listed below.  What am I missing?

> -Thanks

> Graph-0.005.tar.gz
> libpng-1.0.3.tar.gz
> GD-1.21.tar.gz
> gd-1.6.3.tar.gz
> freetype-1.2.tar.gz
> zlib-1.1.3.tar.gz


> ERROR MESSAGE:
> perl: can't resolve symbol 'gdFontMediumBold'
> perl: can't resolve symbol 'gdFontTiny'
> perl: can't resolve symbol 'gdFontGiant'
> perl: can't resolve symbol 'gdFontSmall'
> perl: can't resolve symbol 'gdFontLarge'
> Can't load '/usr/lib/perl5/site_perl/5.005/i686-linux/auto/GD/GD.so' for
> module GD: U
> nable to resolve symbol at
> /usr/lib/perl5/5.00503/i686-linux/DynaLoader.pm line 169.

From http://www.aestus.net/gdchart/

"If you get complaints of bad references to "gdFontTiny" or not being able 
 to find "-lgd", you haven't built libgd."

Or, you have a run-time issue (/etc/ld.so.conf and/or LD_LIBRARY_PATH).
It may be that you "haven't built libgd" *properly*.

-- 
Bill Maloy (brm4)


------------------------------

Date: Tue, 14 Sep 1999 21:27:31 +0100
From: "James" <jgmtest@serviceteam.ltd.uk>
Subject: Re: Generating an email with form entry (CGI)
Message-Id: <C4yD3.95$cm.3905@wards>

First an explanation of my setup (...as a novice): .plx extensions are
associated with perlis.dll while .pl extensions are associated with
perl.exe.  Up until now I have been saving my files as .pl files, and
checking to see what error messages the perl compiler comes up with.  When
they seem OK I rename them to .plx files and then they work (all bar this
one) when called from a web page.

So when this file worked as a .pl file, I renamed it .plx and called it from
IE5.  I got a message '[path to script]/scriptname produced no output' which
I thought would be OK since I wasn't expecting any html output, only an
email to my account - no mail arrived though.  If I leave the file as a .pl
file, and call it from a web page I get a 'cgi - error - script misbehaved
by not outputting valid header information' (something to that effect).

James

Kragen Sitaker wrote in message ...
>In article <eRtD3.24$cm.720@wards>, JGM <jgmtest@serviceteam.ltd.uk> wrote:
>>I used net::smtp to test the email and it works fine from the command
>>prompt, but I can't translate that success to the web page.
>
>What happens?
>--
><kragen@pobox.com>       Kragen Sitaker     <http://www.pobox.com/~kragen/>
>Tue Sep 14 1999
>55 days until the Internet stock bubble bursts on Monday, 1999-11-08.
><URL:http://www.pobox.com/~kragen/bubble.html>




------------------------------

Date: 1 Jul 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 1 Jul 99)
Message-Id: <null>


Administrivia:

The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc.  For subscription or unsubscription requests, send
the single line:

	subscribe perl-users
or:
	unsubscribe perl-users

to almanac@ruby.oce.orst.edu.  

To submit articles to comp.lang.perl.misc (and this Digest), send your
article to perl-users@ruby.oce.orst.edu.

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.

The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq" from
almanac@ruby.oce.orst.edu. The real FAQ, as it appeared last in the
newsgroup, can be retrieved with the request "send perl-users FAQ" from
almanac@ruby.oce.orst.edu. Due to their sizes, neither the Meta-FAQ nor
the FAQ are included in the digest.

The "mini-FAQ", which is an updated version of the Meta-FAQ, is
available by requesting "send perl-users mini-faq" from
almanac@ruby.oce.orst.edu. 

For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V9 Issue 795
*************************************


home help back first fref pref prev next nref lref last post