[18758] in Perl-Users-Digest
Perl-Users Digest, Issue: 926 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu May 17 18:11:58 2001
Date: Thu, 17 May 2001 15:05:06 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <990137106-v10-i926@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Thu, 17 May 2001 Volume: 10 Number: 926
Today's topics:
Re: "listen" to a file <uri@sysarch.com>
Re: An Example Of A Polite FAQ <me@my_no_spam.org>
Re: An Example Of A Polite FAQ <me@my_no_spam.org>
Re: An Example Of A Polite FAQ <godzilla@stomp.stomp.tokyo>
Re: An Example Of A Polite FAQ <godzilla@stomp.stomp.tokyo>
Re: An Example Of A Polite FAQ (Craig Berry)
Re: An Example Of A Polite FAQ <lmoran@wtsg.com>
Re: An Example Of A Polite FAQ <godzilla@stomp.stomp.tokyo>
Re: Bits and bytes (James Weisberg)
Re: Bits and bytes (Dave Bailey)
Re: Excluding certain output variables? <Jenda@Krynicky.cz>
Re: Excluding certain output variables? <davsoming@lineone.net>
Re: Excluding certain output variables? <davsoming@lineone.net>
Re: Excluding certain output variables? (Tad McClellan)
Re: FOUND IT dynamic name for hashtable ... (Jay Tilton)
Re: Random Numbers Script (E.Chang)
Re: Random Numbers Script (Craig Berry)
Re: Random Numbers Script (E.Chang)
Re: Writing to Unix passwd (Charles DeRykus)
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Thu, 17 May 2001 18:14:59 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: "listen" to a file
Message-Id: <x74ruj9717.fsf@home.sysarch.com>
>>>>> "PS" == Peter Søgaard <peter.sogaard@tjgroup.com> writes:
PS> Is it possible to have perl "listen to" a certain file, and then
PS> trigger some event when this file is updated( i.e. overwritten ).
PS> I can probably use sleep x seconds and then check the file status
PS> once in a while and decide whether the file has been updated since
PS> last time i checked...but is there a more correct way of doing
PS> this?...if so, how? :)
there are tail modules in cpan that do this. the unix tail program (also
in the ppt kit in perl) also does it. and stem (at stemsystems.com) has
a powerful tail/logging mechanism that works over networks and with
multiple files.
uri
--
Uri Guttman --------- uri@sysarch.com ---------- http://www.sysarch.com
SYStems ARCHitecture and Stem Development ------ http://www.stemsystems.com
Learn Advanced Object Oriented Perl from Damian Conway - Boston, July 10-11
Class and Registration info: http://www.sysarch.com/perl/OOP_class.html
------------------------------
Date: Thu, 17 May 2001 14:58:14 -0400
From: Dave VP <me@my_no_spam.org>
Subject: Re: An Example Of A Polite FAQ
Message-Id: <3B041F46.43621805@my_no_spam.org>
"Godzilla!" wrote:
>
[ much snippage]
> Another problem with instructions, are switches.
> Suggesting, " perldoc -f somefunction " is very
> confusing. What does " -f " mean?
>
> **
>
> Many switches are avaiable for use. A switch is nothing
> more than an abbreviation for an instruction. For example,
>
> perldoc -f reset
>
> This means, in Plain English,
>
> "Look in Perl Documentation, FIND information on the reset function."
>
> This switch, -f , simply means "Find."
>
> Read about and research switches available for use to better
> understand how to use them.
>
Eeek! Good intentions rendered as bad advice.
It may be convenient to think of '-f' as a FINDer, but it restricts the
search to 'built-in functions', as per the perldoc:
NAME
perldoc - Look up Perl documentation in pod format.
-f perlfunc
The -f option followed by the name of a perl built in
function will extract the documentation of this function
from the perlfunc manpage.
[ rest snipped ]
Dave
------------------------------
Date: Thu, 17 May 2001 15:32:45 -0400
From: Dave VP <me@my_no_spam.org>
Subject: Re: An Example Of A Polite FAQ
Message-Id: <3B04275D.37F4B25D@my_no_spam.org>
"Godzilla!" wrote:
>
> Dave VP wrote:
>
> > "Godzilla!" wrote:
>
> (significant snippage)
>
> > > (possible examples of using the Perl search feature)
>
> > Yes! Having some concrete examples in these sections would be very
> > helpful to the uninitiated. Maybe the first suggestion should be
>
> > perldoc perlfaq
>
>
> I've elected to treat this as a unique topic.
>
> In a parallel article, I mention a problem with difficulties
> in following instructions and, suggest simple step-by-step
> instructions for examples. Here is a clear problem which
> is not clear at all.
>
> At your command line prompt type in:
>
> perldoc perlfaq
>
> Press your enter key:
>
> Lots of documentation appears!
>
> This example is sorely lacking. A person may not know a requirement
> is to change to a directory within or under your Perl install directory.
> My example also lacks qualification of a command line prompt; is it
> a unix prompt, a dos prompt or other?
>
> I become annoyed with documentation which simply states, "%"
> for a command line prompt. What the heck is that?
>
> **
>
> If you are on a Win32 system, open a DOS window,
>
> (instructions)
>
> In your DOS window, at your command line prompt, C:\Windows
>
> type in:
>
> cd c:\path\to\perl\execute\directory
>
> press ENTER
>
> type in:
>
> perldoc perlfaq
>
> press ENTER
>
> Lots of documentation!
>
You have assumed the reader has perl installed on the machine.
How far do you take the instructions?
[ snip]
> Doing this affords me an ability to "speak at a language level" which
> is customized for each student. For a student who is very keen, for
> one-on-one dialog, my language level is high. For lower abilities,
> I adjust my language level downward. This affords each student a
> chance to understand at his or her own skill level.
>
> When addressing a class as a whole, like during lectures, I use
> a language level aimed at the "average" skill level of a given
> class. This presents the best chances for understanding by all.
>
> Few realize how much talent is required to be a good teacher.
> It is a very challenging occupation.
>
Yes...yes....
And you may have also found out, as a teacher, that the more you know
about a subject, the more challenging it becomes to convey your
knowledge clearly to others.
> As to this FAQ being developed, it would be prudent to set examples
> which speak at a knowledge level reflecting the average for those
> relatively new to Perl. It would be prudent to provide instructions
> which are more informative than what we, as more experienced people,
> would expect.
>
> This is why I have entertained a thought of suggesting periodic
> postings of instructions on how to use Perl faq functions, as
> documents separate from the actual FAQ for this group. The FAQ
> could provide one or two quick examples, then provide links
> to documents with more detailed instructions.
>
> Godzilla!
And if I'm following you correctly, you are suggesting that there be a
"FAQ on the FAQ". I honestly believe that isn't such a far-out idea.
This is a technical newsgroup. The concepts and language here should be
reflective of that. Having 'polite' links to other docs which may be
more descriptive and useful for newer users is worth pursuing.
As I've read through the various threads on FAQs and guidelines posted
in clpm the past few days, I've come to realize that:
1. There are folks who just *won't* RTFM
2. There are folks who have never programmed in *any* language.
3. There are extremely knowledgeable and helpful people in this group.
4. There are those who would *like* to learn,
but are having trouble getting up the slope.
There's nothing to be done about nos. 1 & 2. They're everywhere!
The people in #3 already know how to use the tools, whether they have
written the docs or at least
know how to read them.
I believe that targeting the guidelines to this last group would be of
the greatest benefit.
I *hope* that it would cut down some of the wasted bandwidth.
Dave
------------------------------
Date: Thu, 17 May 2001 12:37:22 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: An Example Of A Polite FAQ
Message-Id: <3B042872.79DCEECB@stomp.stomp.tokyo>
Dave VP wrote:
> Godzilla! wrote:
(various snips)
> > Another problem with instructions, are switches.
> > Suggesting, " perldoc -f somefunction " is very
> > confusing. What does " -f " mean?
> > perldoc -f reset
> > This means, in Plain English,
> > "Look in Perl Documentation, FIND information on the reset function."
> > This switch, -f , simply means "Find."
> Eeek! Good intentions rendered as bad advice.
> It may be convenient to think of '-f' as a FINDer, but it restricts the
> search to 'built-in functions', as per the perldoc:
> NAME
> perldoc - Look up Perl documentation in pod format.
> -f perlfunc
> The -f option followed by the name of a perl built in
> function will extract the documentation of this function
> from the perlfunc manpage.
Otherwords,
"Look in Perl Documentation, FIND information on the reset function."
I also said,
"Read about and research switches available for use to better
understand how to use them."
Within some internet micro-cultures, I am known as,
"Semantic Guerrilla"
However, these geographic regions of our internet are places
none here would venture to visit. Think of me as an emissary
from the Land of Language here to wreak semantic havoc within
your cozy Perl Perl Land.
This nit-picking thing is highly inefficient. My choice is
to use a verbal flame thrower to rid nits and, nit-pickers.
Godzilla! Queen Of Nits.
------------------------------
Date: Thu, 17 May 2001 12:52:17 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: An Example Of A Polite FAQ
Message-Id: <3B042BF1.6EA07C77@stomp.stomp.tokyo>
Dave VP wrote:
> Godzilla! wrote:
> > Dave VP wrote:
> > > Godzilla! wrote:
(snipped generalized instructions on accessing pod)
> > If you are on a Win32 system, open a DOS window....
> You have assumed the reader has perl installed on the machine.
Some assumptions are to be made. Nonetheless a qualifying
preample would clear this.
Here are links to built-in Perl documentation....
If you have Perl installed at home or....
> How far do you take the instructions?
My philosophy is to take all things to the max,
much like my two-hundred mile per hour Mako Shark.
You die only once, you know.
> And you may have also found out, as a teacher, that the more you know
> about a subject, the more challenging it becomes to convey your
> knowledge clearly to others.
My experience is just the opposite. The more I learn about
a given topic, the easier I am able to speak about it.
> And if I'm following you correctly, you are suggesting that there be a
> "FAQ on the FAQ". I honestly believe that isn't such a far-out idea.
It is a matter of efficiency. It is very inefficient to address all
topics in detail within one document. It is efficient to provide
referrals to more elaborate details, elsewhere. This is already
being done in the FAQ in the form of links. This is not a novel
notion; this has been in practice for ages.
Godzilla!
------------------------------
Date: Thu, 17 May 2001 20:43:23 -0000
From: cberry@cinenet.net (Craig Berry)
Subject: Re: An Example Of A Polite FAQ
Message-Id: <tg8dvbo752mpf3@corp.supernews.com>
Godzilla! (godzilla@stomp.stomp.tokyo) wrote:
: > -f perlfunc
: > The -f option followed by the name of a perl built in
: > function will extract the documentation of this function
: > from the perlfunc manpage.
:
: Otherwords,
:
: "Look in Perl Documentation, FIND information on the reset function."
That's the effect of it in this instance, but it's a poor mnemonic. Using
'perldoc -f CGI', for example, won't FIND information on the CGI.pm
module; it will find nothing, in fact. The -f switch specifally searches
for perl functions, and nothing else. Thus, 'FUNCTION' is a better
mnemonic than 'FIND' for -f.
--
| Craig Berry - http://www.cinenet.net/~cberry/
--*-- "God becomes as we are that we may be as he is."
| - William Blake
------------------------------
Date: Thu, 17 May 2001 16:51:24 -0400
From: Lou Moran <lmoran@wtsg.com>
Subject: Re: An Example Of A Polite FAQ
Message-Id: <f9e8gtsf2kkdrojo1vhirmsdqeeu0knnvb@4ax.com>
On Wed, 16 May 2001 22:11:56 -0700, "Godzilla!"
<godzilla@stomp.stomp.tokyo> wrote wonderful things about sparkplugs:
>
>
>Welcome to comp.lang.perl.misc newsgroup!
>
SNIP
I read the Subject line and never looked right to the author; I am
totally shocked! I am awed, floored and amazed.
Excellent. Excellent reworking here.
This is a good day to read CLPM.
>Godzilla!
can this be?
Let this be.
--
print "\x{263a}"
------------------------------
Date: Thu, 17 May 2001 14:14:35 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: An Example Of A Polite FAQ
Message-Id: <3B043F3B.6FAF8FCF@stomp.stomp.tokyo>
Craig Berry wrote:
> Godzilla! wrote:
(unnoted snippage by Berry, context deliberately changed)
> : > -f perlfunc
> : > The -f option followed by the name of a perl built in
> : > function will extract the documentation of this function
> : > from the perlfunc manpage.
> : Otherwords,
> : "Look in Perl Documentation, FIND information on the reset function."
> That's the effect of it in this instance, but it's a poor mnemonic. Using
> 'perldoc -f CGI', for example, won't FIND information on the CGI.pm
> module; it will find nothing, in fact. The -f switch specifally searches
> for perl functions, and nothing else. Thus, 'FUNCTION' is a better
> mnemonic than 'FIND' for -f.
Clearly you geeks are hyperopic sighted.
"Read about and research switches available for use to better
understand how to use them."
Appears I may need more than my verbal flamethrower to
rid this place of nits and, nit-pickers. I do have a few
surplus Vietnam era napalm bombs out back. I dunno, like
modules, this might be overkill.
Beaucoup Dinky Dou!
However, a small quantity of ratio mixed liquid Tide and gasoline...
Nah, gasoline is more expensive than milk now.
I'll get back to you on this.
Godzilla!
------------------------------
Date: Thu, 17 May 2001 20:13:17 GMT
From: chadbour@wwa.com (James Weisberg)
Subject: Re: Bits and bytes
Message-Id: <xhWM6.5513$DW1.242835@iad-read.news.verio.net>
Dave Bailey <dave@sydney.daveb.net> wrote:
>On Wed, 16 May 2001 23:17:25 GMT, James Weisberg <chadbour@wwa.com> wrote:
Dave,
Let me first say that I've really appreciated your help on these
programming matters. I did a great deal of work both thinking up and
programming what I already laid out. But your assistance with a 2-bit
at a time vec() solution was extraordinarily helpful in speeding up
the processing.
>Well, I can squeeze about a factor of 4.5 out of dbrec_pack and a factor
>of about 2.5 out of dbrec_unpack by modifying them so that they operate
>two bits at a time (below).
Yeah, as I stated earlier, I didn't do much to optimize the packing
function yet. The unpacking function was where I was concentrating most.
>For the other array,
>my @a = (20010315,9,1,10,100,1,0,0,-1);
>
>I can only get about a 20 to 30% speedup, but packing and unpacking those
>records is much faster than packing valid records, it seems. I don't
>think it can get much faster in Perl.
Agreed. There's always a tradeoff between performance and memory.
These are the two functions I was using originally before I attempted
any bitstring solution:
sub ORIG_dbrec_pack {
my $ird = shift; # put ird before packing header for quick access
my $packstr;
for (@_) {
$_ = -1 if not defined $_;
if ( $_ < 128 )
{ $packstr .= 'c'}
elsif ( $_ < 65536 )
{ $packstr .= 'S'}
elsif ( $_ < 4294967296)
{ $packstr .= 'L'}
else { ccmsg(0, "Field record $_ too large to pack.")}
}
$packstr =~ s/(([A-Za-z])\2+)/$2 . length $1/eg; # Thanx Larry Rosler!
my $packlen = length($packstr);
return pack("lCa$packlen$packstr", $ird, $packlen, $packstr, @_);
}
sub ORIG_dbrec_unpack {
my $packlen=unpack("x4C" , $_[0]); # skip 4 bytes for len
my $packstr=unpack("x5a$packlen" , $_[0]); # skip 5 bytes for str
return unpack("lxx$packlen$packstr", $_[0]); # return ird + rest
}
They do run faster than the vector solution, but they also use up more
than twice the memory for the data set I have been using. That's mainly due
to the fact that the two most common values, 0 and -1, are each taking up
an entire byte. The other common case, an "unfilled" record, is taking up
4 bytes for the ird + 1 byte for the pack length + 3 bytes for the pack
string "cSZ", where SZ is the record size, + SZ bytes for the data. This
latter case takes only 6 bytes in the vector solution. Another common case
is a record of all 0s and -1s, which takes up the same number of bytes as
the "unfilled" record case above. The vector solution uses 4 bytes for the
ird, 1 byte for the record size, and SZ/4 bytes for all the 0s and -1s.
At this point, the only thing that would take up less memory or less
processing is a different way of encoding the data. Believe me, I spent
days playing with different combinations. Some used 3 bit headers, some
used 4 bit headers, but none of them really saved much beyond what I have
explained here, and the two functions for storage and retrieval became
more complicated and ran slightly slower.
I even thought of maybe taking the bitstring as created by the function
and then using a second pass to count repeated patterns of 0 and 1. Any
record with a bunch of consecutive 0s or -1s could be condensed at the
expense of non-repeating values. The idea sounds good, but I couldn't
figure a way to actually save any memory with a different encoding scheme.
Finally, one thing that the vector solution does that indirectly saves
processing time is that it creates smaller records which I am saving to a
database on disk. The process which then comes along and reads databases
now does less disk I/O to read those blocks and that actually saves a
significant amount of time in program execution.
>If unpacking speed is still a
>bottleneck, you'll have to go to XS and C.
I've completed some benchmarking tests based on the two functions I
posted compared to ones based on what you have written. At this point I
am satisfied with the performance. I don't think it warrants going the
XS/C route right now. I'm not really prepared to step into that realm
anyway!
[your code snipped]
I made some minor alterations to what you did. Primarily, they were
stylistic changes, but others had more to do with flow. One main difference
was that I don't like using push() if I don't need to. Maybe it's just as
fast as pre-extending the array, but since I need to return a packet of $sz,
I am comfortable initializing it first and then filling fields as they are
calculated. Internally, I assume perl would do some data copying after some
push neccessitates a larger array. I also assume that "$a[$i++] = $value"
is generally faster than "push @a, $value", but I could be wrong.
I also took care of the II = 01 case first in my unpacking function and
got it out of the foreach loop. Data which isn't a 0 or a -1 must then be
encoded further in the bitstring and I can skip two elsifs that way. I also
prefer to use "<" or ">" over "<=" or ">=" whenever possible. You can look
at the rest of my changes, if you prefer, to see what's different logically
rather than stylistically.
Other than that, I thank you again for your diligence and expertise
in helping me with this code. I didn't really post with a problem, and I
didn't really expect this much response. Still, I'm extremely satisfied
with the results! ;-)
#! /usr/local/bin/perl -w
my $vector = dbrec_pack2(@ARGV);
my @packet = dbrec_unpack2($vector);
$"=","; print "[$#packet] packet: (@packet)\n";
sub dbrec_pack2 {
my $ird = pack("l", shift);
my $v = ''; vec($v,0,8)=2+$#_; # recsize
if($_[0]) {
if($_[0] > 16) {print "$_[0] overflow\n"; exit}
else {vec($v,2,4)=2; vec($v,3,4)=$_[0]-1} # II = 01
} else {
my $o = 4;
for ( @_ ) {
if ($_ == 0) {vec($v,$o++,2) = 0} # II = 00
elsif ($_ == -1) {vec($v,$o++,2) = 1} # II = 10
else {
my ($a,$b,$c,$h) = ($_,0,0,0);
if ($a < 17) {$b = 1; $c = 4; $h = 0} # HH = 00
elsif ($a < 273) {$b = 17; $c = 8; $h = 1} # HH = 10
elsif ($a < 65809) {$b = 273; $c = 16; $h = 2} # HH = 01
elsif ($a < 16843025) {$b = 65809; $c = 24; $h = 3} # HH = 11
else {print "$_ overflow\n"; exit}
vec($v,$o++,2) = 3; # II = 11
vec($v,$o++,2) = $h;
for(my $i = 0, $a-= $b; $i < $c; $i+= 2) {
vec($v,$o++,2) = $a>>$i; # value-b
}
}
} }
return $ird.$v; # concatenate ird and vector
}
sub dbrec_unpack2 {
my($ird,$sz,$v) = (unpack("lC",$_[0]),substr($_[0],5));
my $bits = unpack("b*", $v);
print "ird=$ird, size=$sz, length=", length($_[0]),"\nbitstr: ($bits)\n";
my @l = (4, 8, 16, 24);
my @s = (1, 17, 273, 65809);
my @p = (-1) x $sz; $p[0] = $ird; # initialize
my $o = 0;
my $n = vec($v,$o++,2);
if($n == 2){ # II = 01
my $m; map{$m|= vec($v,$o++,2)<<$_} (0..3);
$p[1] = $m+1; # recflag
} else {
for ( my $i = 1; $i<$sz;) {
if($n == 0){$p[$i++] = 0} # II = 00
elsif($n == 1){$p[$i++] =-1} # II = 10
else { $n = vec($v,$o++,2); # II = 11
my $k = vec($v,$o++,2);
for ( my $j = 2; $j < $l[$n]; $j+=2 ) {
$k|= vec($v,$o++,2)<<$j;
} $p[$i++] = $k+$s[$n];
} $n = vec($v,$o++,2);
} }
return @p;
}
--
World's Greatest Living Poster
------------------------------
Date: 17 May 2001 21:02:48 GMT
From: dave@sydney.daveb.net (Dave Bailey)
Subject: Re: Bits and bytes
Message-Id: <slrn9g84s1.7ik.dave@sydney.daveb.net>
On Thu, 17 May 2001 20:13:17 GMT, James Weisberg <chadbour@wwa.com> wrote:
>Dave Bailey <dave@sydney.daveb.net> wrote:
[...]
>>If unpacking speed is still a
>>bottleneck, you'll have to go to XS and C.
>
> I've completed some benchmarking tests based on the two functions I
>posted compared to ones based on what you have written. At this point I
>am satisfied with the performance.
I was trying to teach myself some more XS last night and I did this:
http://daveb.net/Code/Perl/VecStore-0.01.tar.gz
There's not much to it. Basically you implement the algorithm in C,
which pretty much amounts to copying it from Perl with a few minor
changes, and call a few Perl macros to handle function arguments and
return values. You may or may not find it useful. It gives an order
of magnitude speedup (over the Perl 2-bit vec version) for unpacking,
and about a factor of 25 speedup for packing. Anyway, I got to learn
some cool stuff, so thanks for posting.
--
Dave Bailey
davidb54@yahoo.com
------------------------------
Date: Thu, 17 May 2001 18:11:22 GMT
From: Jenda Krynicky <Jenda@Krynicky.cz>
Subject: Re: Excluding certain output variables?
Message-Id: <1108_990123082@JENDA>
On Thu, 17 May 2001 09:19:51 +0100, "David Soming" <davsoming@lineone.net> wrote:
> Hi new to perl,
> I have this script which displays SSI environment variables in browser:
> #!/usr/local/bin/perl
> print "Content-type: text/html\n\n";
> print "<tt>\n";
> foreach $key (sort keys(%ENV)) {
> print "$key = $ENV{$key}<p>";
> }
>
> Using: <!--#exec cgi="cgi-bin/ALL_ENV.cgi"-->
>
> How can I exclude specific variables in the output namely;
> UNIQUE_USER_ID=
> REDIRECT_UNIQUE_ID=
> REDIRECT_USER_NAME=
> What do I need to do to exclude these? Any suggestions what I need to read
> up on please?
> Thanks very much.
#!/usr/local/bin/perl
print "Content-type: text/html\n\n";
print "<tt>\n";
%exclude = map { ($_, 1) } qw(UNIQUE_USER_ID REDIRECT_UNIQUE_ID REDIRECT_USER_NAME);
# this ugly line creates a hash like $exclude{UNIQUE_USER_ID} = 1; ...
foreach $key (sort keys(%ENV)) {
print "$key = $ENV{$key}<p>"
unless $exclude{$key};
}
Jenda
------------------------------
Date: Thu, 17 May 2001 20:08:37 +0100
From: "David Soming" <davsoming@lineone.net>
Subject: Re: Excluding certain output variables?
Message-Id: <tg882g7ru8bg46@corp.supernews.co.uk>
> #!/usr/local/bin/perl -w
The -w switch reports errors suggesting: "No such file or directory"
although I'm certain this is correct including permissions/path/transfer
mode.
Without the switch it appears to work but still outputs the "UNIQUE_ID = " +
excludes rather more variables too?
> use strict;
When I do (as below if I have used it correctly?) I get "internal server
error notice". Unfortunately I don't have access to my logs. cheap hosting!
hmm
Anyway here's my modified script:
#!/usr/bin/perl -w
use strict;
print "Content-type: text/html\n\n";
print "<tt>\n";
foreach $key (sort keys(%ENV)) {
next if $key =~ /^(UNIQUE_USER_ID|REDIRECT_UNIQUE_ID|REDIRECT_USER_NAME)$/;
print "$key = $ENV{$key}<p>";
}
> > foreach $key (sort keys(%ENV)) {
>
> next if $key =~
/^(UNIQUE_USER_ID|REDIRECT_UNIQUE_ID|REDIRECT_USER_NAME)$/;
>
> > print "$key = $ENV{$key}<p>";
> > }
>
> >How can I exclude specific variables in the output namely;
> >UNIQUE_USER_ID=
> >REDIRECT_UNIQUE_ID=
> >REDIRECT_USER_NAME=
>
>
>
> --
> Tad McClellan SGML consulting
> tadmc@augustmail.com Perl programming
> Fort Worth, Texas
------------------------------
Date: Thu, 17 May 2001 20:28:06 +0100
From: "David Soming" <davsoming@lineone.net>
Subject: Re: Excluding certain output variables?
Message-Id: <tg8972n5jun5c@corp.supernews.co.uk>
This works!
Thanks.
However it still displays UNIQUE__ID !
BTW I'm on a server with the following software installed: Apache/1.3.12
Cobalt (Unix) mod_ssl/2.6.4 OpenSSL/0.9.5a PHP/4.0.3pl 1 mod_auth_pam/1.0a
FrontPage/4.0.4.3 mod_perl/1.24
David Soming
"Jenda Krynicky" <Jenda@Krynicky.cz> wrote in message
news:1108_990123082@JENDA...
> On Thu, 17 May 2001 09:19:51 +0100, "David Soming" <davsoming@lineone.net>
wrote:
> > Hi new to perl,
> > I have this script which displays SSI environment variables in browser:
> > #!/usr/local/bin/perl
> > print "Content-type: text/html\n\n";
> > print "<tt>\n";
> > foreach $key (sort keys(%ENV)) {
> > print "$key = $ENV{$key}<p>";
> > }
> >
> > Using: <!--#exec cgi="cgi-bin/ALL_ENV.cgi"-->
> >
> > How can I exclude specific variables in the output namely;
> > UNIQUE_USER_ID=
> > REDIRECT_UNIQUE_ID=
> > REDIRECT_USER_NAME=
> > What do I need to do to exclude these? Any suggestions what I need to
read
> > up on please?
> > Thanks very much.
>
> #!/usr/local/bin/perl
> print "Content-type: text/html\n\n";
> print "<tt>\n";
>
> %exclude = map { ($_, 1) } qw(UNIQUE_USER_ID REDIRECT_UNIQUE_ID
REDIRECT_USER_NAME);
> # this ugly line creates a hash like $exclude{UNIQUE_USER_ID} = 1;
...
>
> foreach $key (sort keys(%ENV)) {
> print "$key = $ENV{$key}<p>"
> unless $exclude{$key};
> }
>
> Jenda
>
>
------------------------------
Date: Thu, 17 May 2001 14:39:49 -0400
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Excluding certain output variables?
Message-Id: <slrn9g86nl.qn3.tadmc@tadmc26.august.net>
David Soming <davsoming@lineone.net> wrote:
>> #!/usr/local/bin/perl -w
>The -w switch reports errors
No, it reports "warnings". "errors" are a much more serious thing.
>suggesting: "No such file or directory"
That is not a message from perl (because it is does not appear in
perldiag.pod). That is a message from your operating system.
-w cannot affect that.
>although I'm certain this is correct including permissions/path/transfer
>mode.
And it makes no such warning when -w is omitted?
I am disbelieving.
>Without the switch it appears to work but still outputs the "UNIQUE_ID = "
That is not one of the ones you listed as being skippable,
so it is not being skipped. All is as it should be.
>+
>excludes rather more variables too?
I dunno what that means.
>> use strict;
>When I do (as below if I have used it correctly?) I get "internal server
>error notice".
_That_ is a real "error".
Run your program from the command line before moving it under
a CGI environment.
>Unfortunately I don't have access to my logs. cheap hosting!
perldoc -q CGI
"How can I get better error messages from a CGI program?"
or, better yet, install your _own_ free web server, and do all
of your testing without needing to access the lame ISP.
>Anyway here's my modified script:
>
>#!/usr/bin/perl -w
>
>use strict;
>
>print "Content-type: text/html\n\n";
>print "<tt>\n";
> foreach $key (sort keys(%ENV)) {
^^^
There is your fatal error. "use strict" requires that you declare
your variables before you use them. You have not declared $key.
foreach my $key (sort keys(%ENV)) {
>> >How can I exclude specific variables in the output namely;
>> >UNIQUE_USER_ID=
>> >REDIRECT_UNIQUE_ID=
>> >REDIRECT_USER_NAME=
See? You did not say anything about a "UNIQUE_ID" env var.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Thu, 17 May 2001 19:26:09 GMT
From: tiltonj@erols.com (Jay Tilton)
Subject: Re: FOUND IT dynamic name for hashtable ...
Message-Id: <3b042315.383979834@news.erols.com>
On Thu, 17 May 2001 14:11:52 +0200, Marc GRIETENS
<Marc.Grietens@REMOVE-THIS.alcatel.be> wrote:
>This worked for me :)
>
>@_[0]->{@_[1]}=@_[1];
You're still using one-element slices of the @_ array when you should
be using the individual elements as scalars.
$_[0]->{$_[1]} = $_[2]; #Changed '[1]' on RHS to '[2]'
>and in the main:
>Addline(\%table,$key,$value)
Excellent. The text and code in the original article strongly
suggested you were trying to use symbolic references. Whether by
accident or by design, you found the right way.
------------------------------
Date: Thu, 17 May 2001 18:37:52 GMT
From: echang@netstorm.net (E.Chang)
Subject: Re: Random Numbers Script
Message-Id: <Xns90A495423E3Bechangnetstormnet@207.106.93.86>
AvA <a.v.a@home.nl> wrote in <3B039A3A.FA1BA48B@home.nl>:
>sas wrote:
>
>> Does anyone have a script that will generate random numbers?
>> Someone told me I could do it with Perl but I don't know where to
>> start. It must be a 5 digit random number which will be associated
>> with a specific name, (an "ID" number), I want to check against a
>> log file to be sure the number hasn't been used already and then
>> add the number and associated name to that log file. Any help
>> will be greatly appreciated. Thanks sas saras@gj.net
>
>creating a random number aint so difficult:
>
>for ($i = 0; $i < 5; $i++){
> $number .= $array[rand(@array = (0..9))];
>}
>print $number , "\n";
>
There are many ways to produce a (more or less) random five-digit
number. Here are a couple of simple ones.
For a string of five digits, including leading zeros, you could use
$id = sprintf("%05d", rand(100000))
If you want a number with five significant digits.
$id = int rand(100000);
if ($id <= 9999){
$id = 9 * $id + 9999 + int rand(10);
}
This version could also be written more compactly as
$id = (($id = int rand(100000)) > 9999 ? $id :9 * $id + 10000 + int
rand(9) );
Both approaches are much more efficient than using a loop, which could
make a difference if the computation is used frequently, especially if
you create slightly longer strings (up to 9 digits for the sprintf
expression, 15 for the conditional on my system.) The delay of
searching a log file for duplicates would be even more of a factor - be
sure to consider the alternatives mentioned by Chris Stith.
use Benchmark qw(cmpthese);
cmpthese (1000000, {
'sprf' => sub {$id = sprintf("%05d", rand(100000))},
'cond' => sub {$id = (($id = int rand(100000)) > 9999 ?
$id : 9 * $id + 9999 + int rand(10))},
'loop' => sub { for ($i = 0; $i < 5; $i++){
$number .= $array[rand(@array = (0..9))];}}
});
Benchmark: timing 1000000 iterations of cond, loop, sprf...
cond: 1 wallclock secs ( 1.78 usr + 0.00 sys = 1.78 CPU) @
561797.75/s
loop: 74 wallclock secs (71.97 usr + 2.44 sys = 74.41 CPU) @
13439.05/s
sprf: 3 wallclock secs ( 2.16 usr + 0.01 sys = 2.17 CPU) @
460829.49/s
As a side note, if you are using a version of Perl earlier than 5.004,
you also need look into the srand function as well as rand.
--
EBC
------------------------------
Date: Thu, 17 May 2001 19:00:20 -0000
From: cberry@cinenet.net (Craig Berry)
Subject: Re: Random Numbers Script
Message-Id: <tg87u4l25237fe@corp.supernews.com>
E.Chang (echang@netstorm.net) wrote:
: If you want a number with five significant digits.
:
: $id = int rand(100000);
: if ($id <= 9999){
: $id = 9 * $id + 9999 + int rand(10);
: }
Easier, faster, and better distributed:
$id = 10_000 + int rand 90_000;
--
| Craig Berry - http://www.cinenet.net/~cberry/
--*-- "God becomes as we are that we may be as he is."
| - William Blake
------------------------------
Date: Thu, 17 May 2001 21:57:05 GMT
From: echang@netstorm.net (E.Chang)
Subject: Re: Random Numbers Script
Message-Id: <Xns90A4B70996493echangnetstormnet@207.106.93.86>
cberry@cinenet.net (Craig Berry) wrote in
<tg87u4l25237fe@corp.supernews.com>:
> E.Chang (echang@netstorm.net) wrote:
> : If you want a number with five significant digits.
> :
> : $id = int rand(100000);
> : if ($id <= 9999){
> : $id = 9 * $id + 9999 + int rand(10);
> : }
>
> Easier, faster, and better distributed:
>
> $id = 10_000 + int rand 90_000;
>
Right! Just goes to show the problem with getting stuck with one
initial idea about doing things and not stepping away from it for a few
moments.
--
EBC
------------------------------
Date: Thu, 17 May 2001 18:27:59 GMT
From: ced@bcstec.ca.boeing.com (Charles DeRykus)
Subject: Re: Writing to Unix passwd
Message-Id: <GDHsMn.As1@news.boeing.com>
In article <Pine.OSF.4.33.0105171244590.27644-100000@bert.WPI.EDU>,
Neil A. Beardsley <nabeards@wpi.edu> wrote:
>Hi,
>
>I'm trying to use the Unix/Linux command passwd from a script. I used
>open, and try to print to it, but it doesn't work. Are there any other
>ways to do this? Does anyone know of a module to perform this?
>
>Here's the code:
>
>open(PASSWD, "|passwd $username") || die "Can't fork to passwd: $!";
>local $SIG{PIPE} = sub { die "Passwd pipe broke." };
>print PASSWD "$password" || die "Can't write password.";
>print PASSWD "$password" || die "Can't write password 2.";
>close PASSWD || die "Failed to close: $! $?";
>
No, passwd writes directly to /dev/tty so the pipe won't
work. The Expect.pm module, however, can help you:
http://search.cpan.org/search?dist=Expect
--
Charles DeRykus
------------------------------
Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 6 Apr 01)
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.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.
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 V10 Issue 926
**************************************