[14052] in Perl-Users-Digest
Perl-Users Digest, Issue: 1462 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Nov 23 00:10:30 1999
Date: Mon, 22 Nov 1999 21:10:16 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <943333815-v9-i1462@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Mon, 22 Nov 1999 Volume: 9 Number: 1462
Today's topics:
oolazy Pragma (Simon Cozens)
Re: oolazy Pragma (Abigail)
Re: oolazy Pragma (Simon Cozens)
Re: OT Y2K, was Re: Problematic horizontal scrollbars (Mark-Jason Dominus)
perl and dns bj0rn@my-deja.com
Re: perl and dns (Simon Cozens)
Re: Perl Chat <cassell@mail.cor.epa.gov>
Re: Query String <rootbeer@redcat.com>
return some perl result into the calling shell script <mecks@ust.hk>
Re: return some perl result into the calling shell scri lee.lindley@bigfoot.com
Re: return some perl result into the calling shell scri lee.lindley@bigfoot.com
Re: Turing machine (Ilya Zakharevich)
Re: Turing machine <cassell@mail.cor.epa.gov>
Re: Turing machine (Abigail)
Re: Undefined error message I can't get rid of. (Brett W. McCoy)
Re: Undefined error message I can't get rid of. <cassell@mail.cor.epa.gov>
Re: Variable assignment confusion <silvenis@wavetech.net>
Re: Y2K in perl <ajs@ajs.com>
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 23 Nov 1999 04:09:10 GMT
From: simon@brecon.co.uk (Simon Cozens)
Subject: oolazy Pragma
Message-Id: <slrn83k4r5.gjv.simon@othersideofthe.earth.li>
The other day I decided it would be quite nice to be able to say
#!/usr/bin/perl
use oolazy;
my $fh = new IO::File;
$parser = new Parse::RecDescent ($grammar);
...
and have the modules get loaded automatically.
Yes, it allows you to shoot yourself in the foot.
Here's what I came up with:
sub UNIVERSAL::AUTOLOAD {
eval "use $_[0]" unless grep($_[0],keys %INC);
goto &$UNIVERSAL::AUTOLOAD;
}
However, this doesn't feel very clean to me. Any better ways of doing
it?
--
There seems no plan because it is all plan.
-- C.S. Lewis
------------------------------
Date: 22 Nov 1999 22:59:40 -0600
From: abigail@delanet.com (Abigail)
Subject: Re: oolazy Pragma
Message-Id: <slrn83k7vv.m2v.abigail@alexandra.delanet.com>
Simon Cozens (simon@brecon.co.uk) wrote on MMCCLXXV September MCMXCIII in
<URL:news:slrn83k4r5.gjv.simon@othersideofthe.earth.li>:
^^
^^ sub UNIVERSAL::AUTOLOAD {
^^ eval "use $_[0]" unless grep($_[0],keys %INC);
^^^^^^^^^^^^^^^^^^^^^
Eh? What's that supposed to do? It would be true if $_[0] is true,
and %INC isn't empty, but that's probably not what you want. I think
you want ... unless exists $INC {$_ [0]};
Furthermore, you don't need string eval:
sub UNIVERSAL::AUTOLOAD {
die "No function $UNIVERSAL::AUTOLOAD" unless @_;
my $class = $_ [0];
unless (exists $INC {$class}) {
eval {
require $class;
$class -> import;
};
die $@ if $@;
goto &$UNIVERSAL::AUTOLOAD;
}
die "No method ", $UNIVERSAL::AUTOLOAD =~ /.*::(.*)/, " in $class";
}
^^ goto &$UNIVERSAL::AUTOLOAD;
^^ }
^^
^^ However, this doesn't feel very clean to me. Any better ways of doing
^^ it?
I think the entire concept of what you want isn't very clean to start with.
Abigail
--
perl -wle 'print "Prime" if (1 x shift) !~ /^1?$|^(11+?)\1+$/'
-----------== 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: 23 Nov 1999 05:02:09 GMT
From: simon@brecon.co.uk (Simon Cozens)
Subject: Re: oolazy Pragma
Message-Id: <slrn83k7uh.gjv.simon@othersideofthe.earth.li>
Abigail (comp.lang.perl.misc):
>^^ eval "use $_[0]" unless grep($_[0],keys %INC);
> ^^^^^^^^^^^^^^^^^^^^^
>
>you want ... unless exists $INC {$_ [0]};
Uhm. Yes, I do, don't I? That was impressively bad.
>^^ However, this doesn't feel very clean to me. Any better ways of doing
>^^ it?
>I think the entire concept of what you want isn't very clean to start with.
Yes, but I want a good hack of a bad concept...
--
"I believe that Ronald Reagan will someday make this
country what it once was... an arctic wilderness."
-- Steve Martin
------------------------------
Date: Tue, 23 Nov 1999 04:25:16 GMT
From: mjd@op.net (Mark-Jason Dominus)
Subject: Re: OT Y2K, was Re: Problematic horizontal scrollbars
Message-Id: <81d4u8$ojr$1@monet.op.net>
In article <81c5h8$r2$1@internal-news.uu.net>,
Erik van Roode <newsposter@cthulhu.demon.nl> wrote:
> I assume that people that don't read localtime documentation
>also haven't found the address for the perl5-porters mailing list.
Just as a data point, it appears that at present P5P has gotten a
report of this type every two to three weeks this year.
------------------------------
Date: Tue, 23 Nov 1999 02:50:51 GMT
From: bj0rn@my-deja.com
Subject: perl and dns
Message-Id: <81cvea$1ch$1@nnrp1.deja.com>
Does anyone know how I can make perl restart DNS (bind on a Linux box)
from a cgi-bin directory on a webserver (Apache)?
I have made a small utility that sends my ip adress to a server and
this perl script should then take the ip, update the DNS records and
then restart bind....
Any help is appreciated!!
-Bj
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: 23 Nov 1999 03:52:51 GMT
From: simon@brecon.co.uk (Simon Cozens)
Subject: Re: perl and dns
Message-Id: <slrn83k3sj.gjv.simon@othersideofthe.earth.li>
bj0rn@my-deja.com (comp.lang.perl.misc):
>Does anyone know how I can make perl restart DNS (bind on a Linux box)
>from a cgi-bin directory on a webserver (Apache)?
>I have made a small utility that sends my ip adress to a server and
>this perl script should then take the ip, update the DNS records and
>then restart bind....
Well, this suggests that you've already done the bit that updates the
DNS records, which requires root privileges. Then you've got half the
battle won - the next bit is to send a SIGHUP to bind as root.
kill 1, `cat /var/run/named.pid`;
I'm not even going to *ASK* how you got a CGI running as nobody to
affect files as root, though, because I'm pretty sure I don't want to
know.
--
It is now pitch dark. If you proceed, you will likely fall into a pit.
------------------------------
Date: Mon, 22 Nov 1999 20:38:31 -0800
From: David Cassell <cassell@mail.cor.epa.gov>
Subject: Re: Perl Chat
Message-Id: <383A1A47.78D609F@mail.cor.epa.gov>
Matthew Polly wrote:
>
> Does anyone know of a Chat Room for primarily (if not specifically) Perl
> Programmers?
Nope. But there's an IRC. You'll never guess what comes after
the '#' part. :-)
David
--
David Cassell, OAO cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician
------------------------------
Date: Mon, 22 Nov 1999 18:25:49 -0800
From: Tom Phoenix <rootbeer@redcat.com>
Subject: Re: Query String
Message-Id: <Pine.GSO.4.10.9911221823560.16575-100000@user2.teleport.com>
On Mon, 22 Nov 1999 0_clock@my-deja.com wrote:
> I would like to know what is the best way to
> write an "if" using the Query String
Use the CGI module. That's the best way.
> I saw this at many places but it doesn't work.
>
> if ($ENV{'QUERY_STRING'} =~ /something/i) {
Yes, that is one of the many ways which don't work. Don't try to process
the QUERY_STRING directly; use a good module. The command 'perldoc CGI'
should tell you more about how to do this properly. You'll still need to
learn some Perl, though. :-)
Cheers!
--
Tom Phoenix Perl Training and Hacking Esperanto
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: Tue, 23 Nov 1999 10:45:36 +0800
From: mecks <mecks@ust.hk>
Subject: return some perl result into the calling shell script
Message-Id: <3839FFD0.221D485A@ust.hk>
Hi friend,
I have write a perl script which result some value( environment
variable, number and text) to
it's calling shell script. I have some approach for doing that, can
anyone comments on it and/or
suggest a better way to do that. Thanks
(1) For returnning enviroment variable. I use the print statement to
write on a separate file and
source it by the calling sheel script.
shell script
#!/bin/csh
#something
perl abc.pl somevalues
#source the perl returned file
souce abc_return
perl script
#!/bin/perl
#something open(OUT,">$SOMEPATH/abc_return");
print OUT "#This is the environment generated by the run_call.pl
\n";
print OUT "setenv YEARNEW $YEARNEW \n";
print OUT "setenv MONTHNEW $MONTHNEW \n";
print OUT "setenv DAYNEW $DAYNEW \n";
print OUT "setenv HOURNEW $HOURNEW \n";
print OUT "setenv MMOUTDIR $MMOUTDIR \n";
print OUT "setenv MMOUTDATE $MMOUTDATE \n";
print OUT "setenv longMMOUTDATE $longMMOUTDATE \n";
print OUT "setenv CHEATDATE $CHEATDATE \n";
print OUT "setenv shortCHEATDATE $shortCHEATDATE \n";
print OUT "setenv MMOUT_18km $MMOUT_18km \n";
close(OUT);
-------------------------------------------------------
For value and text
shell script
#!/bin/csh
#something
set test = `perl something.pl otherthing`
--------------------------------------------------------
It seems that the above method only work for small amount of values
and
environment variables. Can anyone suggest a better way.
I love perl, thus I do not use sed/awk/...... Unfortunatly, my
writing skill is still
young.
Thanks
Jim
------------------------------
Date: 23 Nov 1999 03:37:47 GMT
From: lee.lindley@bigfoot.com
Subject: Re: return some perl result into the calling shell script
Message-Id: <81d26b$sg$1@rguxd.viasystems.com>
mecks <mecks@ust.hk> wrote:
:>Hi friend,
:> I have write a perl script which result some value( environment
:>variable, number and text) to
:>it's calling shell script. I have some approach for doing that, can
:>anyone comments on it and/or
:>suggest a better way to do that. Thanks
:>(1) For returnning enviroment variable. I use the print statement to
:>write on a separate file and
:>source it by the calling sheel script.
[snip]
:>--------------------------------------------------------
:> It seems that the above method only work for small amount of values
:>and
:>environment variables. Can anyone suggest a better way.
:> I love perl, thus I do not use sed/awk/...... Unfortunatly, my
:>writing skill is still
:>young.
Young skills can be enhanced. Good thing too or we would all be
cursed to live with our youthful inadequacies forever.
1) Your method for allowing the calling shell script to set
variables in its own address space based on the
results of the Perl program is perfectly adequate.
2) You say that it only works for a small amount of values.
What happens when it doesn't work? Is it a limitation
of the shell? You will need to expand on that problem.
3) sed and awk are fine tools. Use them when it is convenient.
But I must admit that they are less convenient than Perl for
me most of the time now.
4) The shell script is what you should strive to replace. But I
sympathize. I still interface with and support large volumes of shell
scripts (csh and ksh!), many of which I wrote in my own ignorant
youth.
--
// Lee.Lindley /// I used to think that being right was everything.
// @bigfoot.com /// Then I matured into the realization that getting
//////////////////// along was more important. Except on usenet.
------------------------------
Date: 23 Nov 1999 03:52:54 GMT
From: lee.lindley@bigfoot.com
Subject: Re: return some perl result into the calling shell script
Message-Id: <81d32m$12g$1@rguxd.viasystems.com>
mecks <mecks@ust.hk> wrote:
[snip]
:> print OUT "#This is the environment generated by the run_call.pl
:>\n";
:> print OUT "setenv YEARNEW $YEARNEW \n";
:> print OUT "setenv MONTHNEW $MONTHNEW \n";
[snip]
Incidentally,
Whenever you find yourself doing multiple print statements,
you should learn to automatically reach for either a "here"
document or an array of terms to print.
print OUT
"setenv YEARNEW", $YEARNEW, "\n",
"setenv MONTHNEW", $MONTHNEW, "\n",
...;
# Or, what seems to be the preferred method in this newsgroup
print OUT <<EOF_VARS; # Don't forget the semicolon
setenv YEARNEW $YEARNEW
setenv MONTHNEW $MONTHNEW
...
EOF_VARS
Of course, I prefer that you store all of those variables in a hash
in your perl program instead of as individually named variables in
the symbol table so that you can write a nice perlish method for
creating the temporary file for your calling shell script.
#Assuming:
my %csh_vars = (
YEARNEW => $YEARNEW,
MONTHNEW => $MONTHNEW,
...
);
#Then,
print OUT map "setenv $_ = $csh_vars{$_}\n", keys %csh_vars;
But, you don't have to go there all at once. You are on the
right path.
--
// Lee.Lindley /// I used to think that being right was everything.
// @bigfoot.com /// Then I matured into the realization that getting
//////////////////// along was more important. Except on usenet.
------------------------------
Date: 23 Nov 1999 02:49:14 GMT
From: ilya@math.ohio-state.edu (Ilya Zakharevich)
Subject: Re: Turing machine
Message-Id: <81cvba$bat$1@charm.magnus.acs.ohio-state.edu>
[A complimentary Cc of this posting was sent to Craig Berry
<cberry@cinenet.net>],
who wrote in article <s3jrbfpu3ef11@corp.supernews.com>:
> Inspired by an offhand and facetious comment on a thread I can't presently
> recall, I have implemented a Turing machine in Perl.
I found a couple of old C-90 tapes. How do I insert them into the machine?
Ilya
------------------------------
Date: Mon, 22 Nov 1999 20:32:05 -0800
From: David Cassell <cassell@mail.cor.epa.gov>
Subject: Re: Turing machine
Message-Id: <383A18C5.73F99426@mail.cor.epa.gov>
Craig Berry wrote:
[snip]
> The program ended up being a bit long to post here (wow, I feel like
> Fermat)
[snip]
I hope not. Fermat has been dead a long time. :-)
David
--
David Cassell, OAO cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician
------------------------------
Date: 22 Nov 1999 23:00:55 -0600
From: abigail@delanet.com (Abigail)
Subject: Re: Turing machine
Message-Id: <slrn83k82c.m2v.abigail@alexandra.delanet.com>
Ilya Zakharevich (ilya@math.ohio-state.edu) wrote on MMCCLXXV September
MCMXCIII in <URL:news:81cvba$bat$1@charm.magnus.acs.ohio-state.edu>:
~~ [A complimentary Cc of this posting was sent to Craig Berry
~~ <cberry@cinenet.net>],
~~ who wrote in article <s3jrbfpu3ef11@corp.supernews.com>:
~~ > Inspired by an offhand and facetious comment on a thread I can't presently
~~ > recall, I have implemented a Turing machine in Perl.
~~
~~ I found a couple of old C-90 tapes. How do I insert them into the machine?
One by one.
Abigail
--
sub camel (^#87=i@J&&&#]u'^^s]#'#={123{#}7890t[0.9]9@+*`"'***}A&&&}n2o}00}t324i;
h[{e **###{r{+P={**{e^^^#'#i@{r'^=^{l+{#}H***i[0.9]&@a5`"':&^;&^,*&^$43##@@####;
c}^^^&&&k}&&&}#=e*****[]}'r####'`=437*{#};::'1[0.9]2@43`"'*#==[[.{{],,,1278@#@);
print+((($llama=prototype'camel')=~y|+{#}$=^*&[0-9]i@:;`"',.| |d)&&$llama."\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, 23 Nov 1999 03:50:05 GMT
From: bmccoy@news.lan2wan.com (Brett W. McCoy)
Subject: Re: Undefined error message I can't get rid of.
Message-Id: <slrn83k408.nvi.bmccoy@dragosani.lan2wan.com>
Also sprach ktb <xyf@inetnebr.com>:
>Use of uninitialized value at ./DB2.pl line 26, <STDIN> chunk 1 (#1)
>________________________________________________________________________
><snip>
>
>print "Enter string to search: ";
>chomp($SearchString = <STDIN>);
>
>if($SearchString =~ /^\s/) { # Makes sure you don't add a space.
> print "Sorry you must enter a character.\n";
>
>YESORNO ();
>
>} elsif($SearchString eq /^\r/) { #Give error if only hit return.
> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> print "You must enter a word.\n";
>
>YESORNO ();
>
>}
Is this pasted directly from your script? Which line is 26? The line
that looks suspicious is the one beginning with elsif -- you are trying to
assign a regexp to a scalar -- is this what you really want? Shouldn't
your operator be =~?
--
Brett W. McCoy
http://www.lan2wan.com/~bmccoy/
-----------------------------------------------------------------------
Practice is the best of all instructors.
-- Publilius
------------------------------
Date: Mon, 22 Nov 1999 20:25:12 -0800
From: David Cassell <cassell@mail.cor.epa.gov>
Subject: Re: Undefined error message I can't get rid of.
Message-Id: <383A1728.5F5EE186@mail.cor.epa.gov>
Brett W. McCoy wrote:
>
> Also sprach ktb <xyf@inetnebr.com>:
[snip]
> >} elsif($SearchString eq /^\r/) { #Give error if only hit return.
[snip]
> Is this pasted directly from your script? Which line is 26? The line
> that looks suspicious is the one beginning with elsif -- you are trying to
> assign a regexp to a scalar -- is this what you really want?
Brett:
Well, he's certainly doing something odd there, but are you
sure he's doing an assignment rather than a comparison using
the equality operator `eq' ?
ktb:
If you want to test equality there, you need to put that
in double quotes [apparently]. But I suspect that Brett is
right and you want to use =~ there. I also suspect that you'll
have a hard time matching \r, since if they hit a return only,
you will match /^$/ instead.
David
--
David Cassell, OAO cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician
------------------------------
Date: Mon, 22 Nov 1999 22:36:12 -0600
From: Eric Lengvenis <silvenis@wavetech.net>
Subject: Re: Variable assignment confusion
Message-Id: <383A19BC.21B512B5@wavetech.net>
Thanks,
I missed the point of that switch. Now at least I get it. I don't
necessarily understand why the author chose such obfuscated code, but I do
understand what they were doing.
Sam Holden wrote:
> On Sun, 21 Nov 1999 23:22:34 -0600,
> Eric Lengvenis <silvenis@wavetech.net> wrote:
> >I have looked hard for the answer to this before I posted, so forgive me
> >if it is obvious. I can't figure out where the two variables $f and $d
> >get their values. I am trying to read someone else's code (the solitaire
> >encryption code from Neal Stephenson's Cryptonomicon) and I understood
> >everything but the third line. The program references these variables,
> >but I never see them assigned anything. I understand that it is an
> >if..then..else, and I assume the value -1 or 1 is assigned $_.
> >
> >#!/usr/bin/perl -s
>
> That -s enables simplistic switch parsing. See the documentation that
> comes with perl for details. perldoc perlrun.
>
> >die "Usage: $0 [-d] 'key phrase' [infile ...]\n" unless $#ARGV >=0;
> >$f=$d ? -1 : 1;
>
> That sets $f to -1 if -d was specified on the command line, or 1 in not.
>
> --
> Sam
>
> Fifty years of programming language research, and we end up with C++ ???
> --Richard A. O'Keefe
------------------------------
Date: 22 Nov 1999 21:54:53 EST
From: Aaron Sherman <ajs@ajs.com>
Subject: Re: Y2K in perl
Message-Id: <m3hfidsys3.fsf@centauri.ajs.com>
gqc2017@my-deja.com writes:
> Hi, I am using localtime() in perl to get the current year. Now what
> can I do to make my code Y2K compliant?
Probably the best thing that you can do is not use localtime
directly. Use strftime which will force you to think in terms of the
exact format of strings you wish to use. For example:
use POSIX qw(strftime);
$year = strftime("%Y", localtime());
The documentation for strftime should be available on your system (in
the C documentation, not the Perl docs), but if it's not, take a look
at:
http://www.opengroup.org/onlinepubs/7908799/xsh/strftime.html]
This is an excellent function, and has saved me much time over the bad
old days in the early '90s when I had to use ctime.pl and parse out
the stuff I wanted or use localtime() directly (which would render me
more likely to make mistakes like interpreting the month incorrectly).
-AJS
--
Aaron Sherman
ajs@ajs.com finger ajskey@lorien.ajs.com for GPG info. Fingerprint:
www.ajs.com/~ajs BF8E 8987 1D58 E01E E0B8 4BB6 B388 2F80 97AE A001
"Do you come from a land downunder, where bitters flow and the
men chunder?" -Men at Work
------------------------------
Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 16 Sep 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.
| NOTE: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.
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 V9 Issue 1462
**************************************