[27246] in Perl-Users-Digest
Perl-Users Digest, Issue: 9022 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Mar 6 09:06:01 2006
Date: Mon, 6 Mar 2006 06:05:03 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Mon, 6 Mar 2006 Volume: 10 Number: 9022
Today's topics:
Re: 'require'ing globals without 'used only once' compl <nospam@comcast.net>
Re: 'require'ing globals without 'used only once' compl <noreply@gunnar.cc>
Re: 'require'ing globals without 'used only once' compl <noreply@gunnar.cc>
Re: 'require'ing globals without 'used only once' compl <erco@3dsite.com>
Re: A Problem With GD <matthew.garrish@sympatico.ca>
Re: Accessibility of the Higher-Order Perl E-book in Am (Anno Siegel)
Re: merge event loops and threads (was Re: simple point <tassilo.von.parseval@rwth-aachen.de>
Re: Question about sub calling other sub (Anno Siegel)
Re: Win32::TieRegistry <january.weiner@gmail.com>
xsub and gcc 4.0.2, static variables <thorsten.kracht@desy.de>
Re: xsub and gcc 4.0.2, static variables (Anno Siegel)
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sun, 5 Mar 2006 23:02:52 -0500
From: "thrill5" <nospam@comcast.net>
Subject: Re: 'require'ing globals without 'used only once' complaints from 'perl -w'?
Message-Id: <ldydnbhbrMMIKZbZnZ2dnUVZ_sOdnZ2d@comcast.com>
Add "no warnings('once');" to the beginning of config.pl. This will turn
off the "used only once" warnings.
Scott
"Greg Ercolano" <erco@3dsite.com> wrote in message
news:uKLOf.1084$RC4.663@fe03.lga...
> I'm trying to figure out a way to load global variables using 'require'
> with 'perl -w' enabled, but without getting "<varname> used only once"
> errors.
>
> The only "solution" I've seen is to make sure all globals are referenced
> more than once, but that gets hard to manage when you scale up the
> project.
>
> My situation is a project of cgi-bin scripts, where there are several
> scripts
> all wanting to load global settings from a single 'config.pl' file.
>
> My current way of doing things is to make a 'config.pl' file that has the
> global settings, ie:
>
> $G::bgcolor = "#ff0000";
> $G::cgibin = "/cgi-bin/MyApp/";
> # ..etc..
> 1;
>
> ..and then all the actual scripts load these settings with 'require', eg:
>
> #!/usr/bin/perl -w
> use strict;
> require "config.pl";
> ..
>
> ..that being in each of the potentially many script files that make up
> the project.
>
> Trouble is, if a script only refers to a global once, a "used only once"
> error is printed, once per variable, which clogs the httpd daemon's error
> logs with errors, one per variable.
>
> The easy solution is to turn off the -w flag, but often it's useful to
> leave it on during production to catch runtime errors.
>
> From a developer's point of view, it's a real PITA to manually ensure
> having no-op references for each global in /each/ script, eg:
>
> #!/usr/bin/perl -w
> use strict;
> require "config.pl";
> $G::bgcolor = $G::bgcolor; # silence 'used once' errors
> $G::cgibin = $G::cgibin; # ""
>
> ..that becomes unmanageable fast.
>
> Is there a 'right way' to do this without getting too 'hacky',
> and without disabling -w? Maybe making the globals into a package?
>
> Code examples welcome..
>
>
>
------------------------------
Date: Mon, 06 Mar 2006 05:15:10 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: 'require'ing globals without 'used only once' complaints from 'perl -w'?
Message-Id: <471reaFdgn5hU1@individual.net>
[ Please apply a sensible quoting style. Do not top post! ]
thrill5 wrote:
> Greg Ercolano wrote:
>> I'm trying to figure out a way to load global variables using
>> 'require' with 'perl -w' enabled, but without getting "<varname>
>> used only once" errors.
<snip>
>> The easy solution is to turn off the -w flag, but often it's useful
>> to leave it on during production to catch runtime errors.
>
> Add "no warnings('once');" to the beginning of config.pl. This will
> turn off the "used only once" warnings.
Did you try that?
Since the warnings pragma is lexically scoped, doing as you suggest
won't make a difference.
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Mon, 06 Mar 2006 05:28:12 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: 'require'ing globals without 'used only once' complaints from 'perl -w'?
Message-Id: <471s6pFdff2vU1@individual.net>
Greg Ercolano wrote:
> I'm trying to figure out a way to load global variables using
> 'require' with 'perl -w' enabled, but without getting "<varname> used
> only once" errors.
<snip>
> Is there a 'right way' to do this without getting too 'hacky', and
> without disabling -w? Maybe making the globals into a package?
The warning shows up because config.pl is loaded only at run time.
Consequently, renaming config.pl to config.pm and use()ing it would be
enough. A BEGIN block is another possibility:
BEGIN { require 'config.pl' }
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Sun, 05 Mar 2006 23:12:37 -0800
From: Greg Ercolano <erco@3dsite.com>
Subject: Re: 'require'ing globals without 'used only once' complaints from 'perl -w'?
Message-Id: <FhROf.2160$3S6.1940@fe04.lga>
Gunnar Hjalmarsson wrote:
> .. renaming config.pl to config.pm and use()ing it would be enough.
Wow, that worked!
Easy and clean solution -- very much thanks.
------------------------------
Date: Sun, 5 Mar 2006 21:29:01 -0500
From: "Matt Garrish" <matthew.garrish@sympatico.ca>
Subject: Re: A Problem With GD
Message-Id: <L7NOf.287$_b.45010@news20.bellglobal.com>
"Mark Manning" <markem@airmail.net> wrote in message
news:120miji6jveb657@corp.supernews.com...
>
> David H. Adler wrote:
>
>> Regardless, I'm sure that you see no reason to act any differently and I
>> suppose that's your right. It is also the right of everyone here to call
>> you on inappropriate behavior and/or killfile you. I certainly hope you
>> never need any more assistance - regardless of how *you* see it. You
>> probably won't get it.
>
> I haven't asked for assistance on Usenet in well over a decade.
>
So we know you're at least ten. Somehow that seems about right for the
stunted vocabulary and make-pretend conversations...
Matt
------------------------------
Date: 6 Mar 2006 10:20:43 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Accessibility of the Higher-Order Perl E-book in Amazon (Was: Emulating Generators)
Message-Id: <duh2dr$q8c$1@mamenchi.zrz.TU-Berlin.DE>
Veli-Pekka Tätilä <vtatila@mail.student.oulu.fi> wrote in comp.lang.perl.misc:
> Steven N. Hirsch wrote:
> > Veli-Pekka Tätilä wrote:
> >> What would be a good way to do an iterator for a sequence of values to be
> >> returned, also called a generator, in Perl?
> > You will probably find Mark-Jason Dominus' book "Higher Order Perl" of
> > interest.
> Hey thanks for the tip. I visited the books Web site and it seems to be just
> what I need. Especially as I'd like to know more about functional
> programming in general, not just in the context of Perl alone. I'm planning
> to give lisp a try to see how it's like.
Consider going straight to Haskell instead.
Lisp is an amazing language and learning it thoroughly can change and
extend your outlook on programming. I know because I have been a
Lisp programmer (almost to the exclusion of other languages) for many
years. But, man, the language is older than Fortran! Haskell was
conceived by people with the Lisp experience under their belts. If
my instinct is any good, it is going to take over Lisp's role of "the
functional language", or already has.
Anno
--
If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers.
------------------------------
Date: Mon, 6 Mar 2006 08:59:07 +0100
From: "Tassilo v. Parseval" <tassilo.von.parseval@rwth-aachen.de>
Subject: Re: merge event loops and threads (was Re: simple pointer operations (newbe))
Message-Id: <4728ecFdfs8oU1@news.dfncis.de>
Also sprach Uri Guttman:
>>>>>> "TvP" == Tassilo v Parseval <tassilo.von.parseval@rwth-aachen.de> writes:
> TvP> Well, I know that you know that. But for Event::Lib, I received
> TvP> quite a few mails from people who were apparently under the
> TvP> misapprehension that each event handler is triggered in its own
> TvP> process or thread. An event-based application is still running
> TvP> sequentially so it will not always spare one the pain to use
> TvP> fork() or threads.
>
> i have an idea and most of the design for a module that will allow event
> loops to work well with kernel (not perl!) threads that will run
> blocking operations. of course it involves xs which i have done very
> little with. would you (or anyone else) be interested in working on it
> with (or for :) me? one variation on it (which could use this new module
> or be its own module) would do true async file i/o and be synchronized
> with the event loop. i have done such a beast before in pure c and it
> worked very well. i think these modules are wanted and would be useful
> to many event loop apps. imagine a simple api for async file i/o in perl
> that was actually portable and bypasses all those wacko kernel aio apis
> that each OS provides.
The specifications sound tempting although you didn't state how you'd
actually want to achieve the asynchronity when you avoid the existing
async IO mechanisms (of which each is unportable by nature). Does your
plan include rolling your own async IO scheme?
Also, I don't yet see how kernel threads come into this. Perl programs
don't have access to them other than through perl's ithreads.
Anyway, Event::Lib is soon at 1.0 and I can already sense how I am
running out of projects to work on. That could mean that I soon have
some tuits left. :)
Tassilo
--
use bigint;
$n=71423350343770280161397026330337371139054411854220053437565440;
$m=-8,;;$_=$n&(0xff)<<$m,,$_>>=$m,,print+chr,,while(($m+=8)<=200);
------------------------------
Date: 6 Mar 2006 12:57:30 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Question about sub calling other sub
Message-Id: <duhbjq$2uf$1@mamenchi.zrz.TU-Berlin.DE>
<xhoster@gmail.com> wrote in comp.lang.perl.misc:
> anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) wrote:
> > >
> > > Actually when I started I had three very simliar looking subs which I
> > > now put together into one. By passing flags ($action) I trigger what
> > > they are supposed to do.
> >
> > The flag mechanism is sometimes used to avoid code duplication. In
> > general, I'd go with Randal and try to factor out the common part(s).
> > "In a good program, every routine does almost nothing".
>
> I can't say I agree with that. If each sub does almost nothing, i.e. no
> more or even less than a simple perl expression does, there is little point
> in having them.
If the perl expression involves calling other do-almost-nothing
routines, who may again call others, the end result can be some
quite complex processing you don't want to expand every time you
call it.
Like all such sayings, especially when quoted without context, this must
be taken with a grain of salt. I don't remember where I read that
sentence, but I do remember that "routine" was defined as "any sequence
of statements that solve a particular problem", so a single sub could
consist of more than one routine in this sense. It is also language
dependent. Well-written FORTH programs often consist of lots of tiny
routines (in the strict sense of user-defined named functions). The
main problem with that is coming up with reasonable names for all the
stuff.
It can happen in Perl too. Here is an example of a set of benchmark
timing routines each one of which does almost nothing:
#!/usr/bin/perl
use strict; use warnings; $| = 1;
start_timing( my $coll_cpu);
1 for 1 .. 1_000_000;
print break_timing( $coll_cpu), " s cpu time\n";
resume_timing( $coll_cpu);
1 for 1 .. 1_000_000;
print break_timing( $coll_cpu), " s cpu time\n";
######################################################################
sub start_timing { resume_timing( $_[ 0] = 0) }
sub resume_timing { $_[ 0] -= cpu() }
sub break_timing { $_[ 0] += cpu() }
sub cpu { return $_->[ 0] + $_->[ 1] for [ times] }
__END__
Anno
--
If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers.
------------------------------
Date: Mon, 6 Mar 2006 11:30:17 +0100 (CET)
From: January Weiner <january.weiner@gmail.com>
Subject: Re: Win32::TieRegistry
Message-Id: <duh2vp$tkb$3@sagnix.uni-muenster.de>
Andreas Pürzer <pue@gmx.net> wrote:
> I think that $ENV{'USERPROFILE'} is also worth checking.
> But please let me recommend yet another way (if the module dependency is ok with
> the OP):
> http://search.cpan.org/~adamk/File-HomeDir-0.54/lib/File/HomeDir.pm
> gives you a very simple yet reliable way to cope with $HOME-related tasks.
Great! This one is perfect. I do not have to care about the intricates of
a Windows system myself.
j.
--
------------------------------
Date: Mon, 06 Mar 2006 09:43:35 +0100
From: thorsten kracht <thorsten.kracht@desy.de>
Subject: xsub and gcc 4.0.2, static variables
Message-Id: <dugsqf$3ee7b$1@claire.desy.de>
Dear All,
I have a problem with static variables (file scope static
variables), if I call my C code from Perl via XSUB.
This problem does not arise with the gcc 3.3 compiler
on a 2.4.20 system (and all versions before). I occurs
with gcc 4.0.2 under 2.6.13.
The static variables change their addresses (and also their
values) in these cases:
1. I run my C code and reach the print statement from
C alone.
2. I run my C code, then call Perl and from Perl I call
my C code again.
Has anybodey else seen this behavious and mayby give me
some help? Compiler switch or some keyword in C.
For me it would be a hufe task to change my static variables
to glogal variables.
Thanks for reading my message and best regards, Thorsten
------------------------------
Date: 6 Mar 2006 09:45:12 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: xsub and gcc 4.0.2, static variables
Message-Id: <duh0b8$oki$2@mamenchi.zrz.TU-Berlin.DE>
thorsten kracht <thorsten.kracht@desy.de> wrote in comp.lang.perl.misc:
>
> Dear All,
> I have a problem with static variables (file scope static
> variables), if I call my C code from Perl via XSUB.
> This problem does not arise with the gcc 3.3 compiler
> on a 2.4.20 system (and all versions before). I occurs
> with gcc 4.0.2 under 2.6.13.
>
> The static variables change their addresses (and also their
> values) in these cases:
>
> 1. I run my C code and reach the print statement from
> C alone.
Do you say "print" for a reason? Perl has a "print" statement,
C only has printf.
> 2. I run my C code, then call Perl and from Perl I call
> my C code again.
>
> Has anybodey else seen this behavious and mayby give me
> some help? Compiler switch or some keyword in C.
> For me it would be a hufe task to change my static variables
> to glogal variables.
Could you reduce the problem to a minimal case that you can post and
we can run?
Anno
--
If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers.
------------------------------
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.
NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice.
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 9022
***************************************