[18715] in Perl-Users-Digest
Perl-Users Digest, Issue: 883 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat May 12 14:06:50 2001
Date: Sat, 12 May 2001 11:05:12 -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: <989690712-v10-i883@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Sat, 12 May 2001 Volume: 10 Number: 883
Today's topics:
array loses place if variable is null <mdudley@execonn.com>
Re: array loses place if variable is null (John Joseph Trammell)
Re: array loses place if variable is null <mdudley@execonn.com>
Re: array loses place if variable is null <godzilla@stomp.stomp.tokyo>
Re: array loses place if variable is null nobull@mail.com
Re: array loses place if variable is null <godzilla@stomp.stomp.tokyo>
Re: Base 6 sieve. (Anno Siegel)
Re: Base 6 sieve. (Anno Siegel)
Re: can Perl do multiplexed output? (M.J.T. Guy)
Re: can Perl do multiplexed output? nobull@mail.com
criteria for bulit-in functions (Wei-hao Lin)
Re: criteria for bulit-in functions <gtoomey@usa.net>
Re: criteria for bulit-in functions nobull@mail.com
Re: criteria for bulit-in functions (Anno Siegel)
Re: dbmopen and tie <SiStie@nuclear-network.com>
Re: dbmopen and tie (Anno Siegel)
Decoding Net::SNMP get_request return <jr@stink.cfl.rr.com>
Re: first use of 'use strict' - getting Global symbol x nobull@mail.com
Re: first use of 'use strict' - getting Global symbol x <m.grimshaw@salford.ac.uk>
Re: first use of 'use strict' - getting Global symbol x (Villy Kruse)
Re: first use of 'use strict' - getting Global symbol x (Garry Williams)
Re: first use of 'use strict' - getting Global symbol x <m.grimshaw@salford.ac.uk>
Re: first use of 'use strict' - getting Global symbol x (Garry Williams)
first use of 'use strict' - getting Global symbol xxx r <m.grimshaw@salford.ac.uk>
Freaky hash <crud_alex@yahoo.com>
Re: Freaky hash <keesh@users.pleaseremovethisbit.sourceforge.net>
Re: Help nobull@mail.com
Re: how to write OO interfaces `a la' Java? nobull@mail.com
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sat, 12 May 2001 11:41:01 -0400
From: Marshall Dudley <mdudley@execonn.com>
Subject: array loses place if variable is null
Message-Id: <3AFD598D.54807813@execonn.com>
With the operation:
@entries = split /,/$string;
We get the following:
for $string = "a,b,c,d"
and $string = "a,b,c,d,
we get an array of a,b,c,d which is expected.
And for a,b,,d you get a,b,[null],d as expected
But for $string = a,b,c,d,,
We get an array of a,b,c,d, but if you push on "f" we end up with
a,b,c,d,f instead of a,b,c,[null],f
which I find unexpected (and spend quite a long time tracking down).
Does perl automatically parse arrays down if the last value is null? Is
there any way to prevent that action? Needless to say it can cause
havoc when used with forms, where a person may leave a field blank, and
one expects certain entrires to be in specific spots. (This abnormality
exhibits itself in the popular commerce.cgi script if you enter nothing
for shipping price, then the price becomes the line number!)
Marshall
------------------------------
Date: Sat, 12 May 2001 15:54:48 GMT
From: trammell@bayazid.hypersloth.invalid (John Joseph Trammell)
Subject: Re: array loses place if variable is null
Message-Id: <slrn9fqksa.dr6.trammell@bayazid.hypersloth.net>
On Sat, 12 May 2001 11:41:01 -0400, Marshall Dudley <mdudley@execonn.com> wrote:
[snip]
> But for $string = a,b,c,d,,
>
> We get an array of a,b,c,d, but if you push on "f" we end up with
> a,b,c,d,f instead of a,b,c,[null],f
[snip]
This is in the documentation for split().
--
Rule #0: Spam is theft.
------------------------------
Date: Sat, 12 May 2001 12:05:18 -0400
From: Marshall Dudley <mdudley@execonn.com>
To: John Joseph Trammell <trammell@bayazid.hypersloth.invalid>
Subject: Re: array loses place if variable is null
Message-Id: <3AFD5F3E.CC106DBE@execonn.com>
Your right, I missed it the when looking before. Guess that is what I get for
looking in "Perl Black Book" instead of the Camel book.
So all I have to do is specify a -1 limit, and the problem is solved. Certainly
easier than the
unless ($cart_row[6]) { $cart_row[6] = 0; }
That I used as a patchup
Thanks,
Marshall
John Joseph Trammell wrote:
> On Sat, 12 May 2001 11:41:01 -0400, Marshall Dudley <mdudley@execonn.com> wrote:
> [snip]
> > But for $string = a,b,c,d,,
> >
> > We get an array of a,b,c,d, but if you push on "f" we end up with
> > a,b,c,d,f instead of a,b,c,[null],f
> [snip]
>
> This is in the documentation for split().
>
> --
> Rule #0: Spam is theft.
------------------------------
Date: Sat, 12 May 2001 09:37:39 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: array loses place if variable is null
Message-Id: <3AFD66D3.C6159C02@stomp.stomp.tokyo>
Marshall Dudley wrote:
> With the operation:
> @entries = split /,/$string;
> We get the following:
How many programmers are involved in writing
your code? This is rather odd.
(snipped details about a null last element and push problem)
> We get an array of a,b,c,d, but if you push on "f" we end up with
> a,b,c,d,f instead of a,b,c,[null],f
Read about and research both arrays and the push function.
You will find your answer with a bit of invested time and effort.
> which I find unexpected (and spend quite a long time tracking down).
However, it is clear you did not spend a lot of time tracking
down why this happens.
(more snippage)
> Is there any way to prevent that action? Needless to say it can cause
> havoc when used with forms, where a person may leave a field blank, and
> one expects certain entrires to be in specific spots.
Why are you allowing your users to leave a required field
blank rather than generating an error message to prevent
a null field from entering your program? You have set
yourself up for this problem.
Godzilla!
------------------------------
Date: 12 May 2001 17:55:59 +0100
From: nobull@mail.com
Subject: Re: array loses place if variable is null
Message-Id: <u9wv7my09s.fsf@wcl-l.bham.ac.uk>
"Godzilla!" <godzilla@stomp.stomp.tokyo> writes:
> Marshall Dudley wrote:
> > @entries = split /,/$string;
>
> Read about and research both arrays and the push function.
Your attempt at misdirection will fail, the OP has already
successfully been directed to read the relevant manual entry, namely
that for the "split" function.
If you want to start handing out you own special variety of poisoned
advice again you'll have to get in quicker, before someone posts the
right answer.
I still think this sport of yours of sending people who fail to RTFM
off on wild goose chases is rather cruel.
> You will find your answer with a bit of invested time and effort.
True, but if you follow Godzilla's advice it will take more time than
if you don't.
> Why are you allowing your users to leave a required field
> blank rather than generating an error message to prevent
> a null field from entering your program?
Time to adjust your medication again. There was nothing in the OP's
post to indicate that a null entry in the field was not perfectly
valid.
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: Sat, 12 May 2001 10:30:11 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: array loses place if variable is null
Message-Id: <3AFD7323.FEA0269A@stomp.stomp.tokyo>
nobull@mail.com wrote:
> Godzilla! wrote:
> > Marshall Dudley wrote:
(clearly snipped)
Your time will be better spent and this
newsgroup will benefit more if you write
articles which are both pertinent and
informative, rather than writing your
daily troll articles using myriad fake
names, directed at me exclusively, Frank.
Godzilla!
------------------------------
Date: 12 May 2001 14:32:50 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Base 6 sieve.
Message-Id: <9djhii$rbd$1@mamenchi.zrz.TU-Berlin.DE>
According to Abigail <abigail@foad.org>:
> Anno Siegel (anno4000@lublin.zrz.tu-berlin.de) wrote on MMDCCCX September
> MCMXCIII in <URL:news:9dgmsd$s3q$1@mamenchi.zrz.TU-Berlin.DE>:
> %%
> %% > bitindices. So, it should be much faster to keep track of the bit
> %% > indices, as that's the only thing we are interested in.
> %%
> %% It's strange but true that the algorithm doesn't need to know the
> %% non-prime number it is about to scrub. Going directly from one sieve
> %% index to the next is certainly a possibility, though I don't see
> %% first sight why it would have to be faster. The relationship of one
> %% sieve index to the next looks rather complex.
> %%
> %% Lessee... it looks as though for each n there are two alternating
> %% increments involved. If this were provable it could indeed speed
> %% up the scrub loop, even if we have to invest some time to find what
> %% the increments are for each n and which comes first.
>
>
> The calculations for that are pretty straigthforward.
Sez you!
> See program (which is identical to the one posted a few days ago,
> except for the scrub routine. This one has a core loop that rocks).
It screams, as Larry once commented a bit of his code.
I have a similar solution where I try to find the starting value and
the two increments for the core loop using a binary search. It has
two drawbacks: 1) I can't prove that it works. 2) It doesn't work.
But my core loop looks just like yours :).
So let me just contribute an inlined core loop:
use Inline C => <<'END_OF_CODE';
int scrub_core( int b, int b1, int b2, int l, char *sieve) {
while ( b <= l ) {
sieve[ b / 8] &= ~(1 << (b % 8));
b += b1;
sieve[ b / 8] &= ~(1 << (b % 8));
b += b2;
}
return(b);
}
Substituting the loop with "$b = scrub_core($b, $b1, $b2, $l, $sieve);"
gives the expected speedup for sufficiently many primes (more than
100000).
Anno
------------------------------
Date: 12 May 2001 15:10:41 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Base 6 sieve.
Message-Id: <9djjph$sqv$1@mamenchi.zrz.TU-Berlin.DE>
According to Abigail <abigail@foad.org>:
> Anno Siegel (anno4000@lublin.zrz.tu-berlin.de) wrote on MMDCCCX September
> MCMXCIII in <URL:news:9dgmsd$s3q$1@mamenchi.zrz.TU-Berlin.DE>:
> %%
> %% > bitindices. So, it should be much faster to keep track of the bit
> %% > indices, as that's the only thing we are interested in.
> %%
> %% It's strange but true that the algorithm doesn't need to know the
> %% non-prime number it is about to scrub. Going directly from one sieve
> %% index to the next is certainly a possibility, though I don't see
> %% first sight why it would have to be faster. The relationship of one
> %% sieve index to the next looks rather complex.
> %%
> %% Lessee... it looks as though for each n there are two alternating
> %% increments involved. If this were provable it could indeed speed
> %% up the scrub loop, even if we have to invest some time to find what
> %% the increments are for each n and which comes first.
>
>
> The calculations for that are pretty straigthforward.
Sez you!
> See program (which is identical to the one posted a few days ago,
> except for the scrub routine. This one has a core loop that rocks).
It screams, as Larry once commented a bit of his code.
I have a similar solution where I try to find the starting value and
the two increments for the core loop using a binary search[1]. It has
two drawbacks: 1) I can't prove that it works. 2) It doesn't work.
But my core loop looks just like yours :).
So let me just contribute an inlined core loop:
use Inline C => <<'END_OF_CODE';
int scrub_core( int b, int b1, int b2, int l, char *sieve) {
while ( b <= l ) {
sieve[ b / 8] &= ~(1 << (b % 8));
b += b1;
sieve[ b / 8] &= ~(1 << (b % 8));
b += b2;
}
return(b);
}
Substituting the loop with "$b = scrub_core($b, $b1, $b2, $l, $sieve);"
gives the expected speedup for sufficiently many primes (more than
100000).
Anno
[1] Why a binary search? The function that gives you the number
represented by the b-th bit in the sieve is relatively
straightforward, even for other bases than 6. It's the reverse
calculation where magical constants crop up. I tried to avoid
these by searching for the sieve indices.
A starting interval for the binary search should be easy to find.
Earlier in this exchange you said that the relationship between
sieve indices and corresponding numbers was linear. I rejected
that, but it is true to some extent. If a linear integer function
is represented by repeated steps of a given width and height, what
we have is a repeated pattern of steps of given widths and heights.
It still makes sense to speak of a mean incline. This should allow
to estimate the inverse function close enough for a fast search.
------------------------------
Date: 12 May 2001 15:20:54 GMT
From: mjtg@cus.cam.ac.uk (M.J.T. Guy)
Subject: Re: can Perl do multiplexed output?
Message-Id: <9djkcm$o3k$1@pegasus.csx.cam.ac.uk>
kalasend at YAHOO dot COM <dontuspamme@nospammers.com> wrote:
>Hi,
>
> I need to write a program that outputs to both STDOUT and a disk file.
>Is there anyway I can do this without calling "print" twice?
There's a module IO::Tee on CPAN.
Not used it myself, though.
Mike Guy
------------------------------
Date: 12 May 2001 16:21:27 +0100
From: nobull@mail.com
Subject: Re: can Perl do multiplexed output?
Message-Id: <u9ofsyzj7s.fsf@wcl-l.bham.ac.uk>
"kalasend at YAHOO dot COM" <dontuspamme@nospammers.com> writes:
> Newsgroups: comp.lang.perl.misc,comp.lang.perl.modules
So you've guessed you are possibly looking for a module.
FAQ: "What modules and extensions are available for Perl? What
is CPAN? What does CPAN/src/... mean?"
The module you want is there, I've just checked.
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: 12 May 2001 14:46:15 GMT
From: whlin@Venus.bblab.cgmh.com.tw (Wei-hao Lin)
Subject: criteria for bulit-in functions
Message-Id: <slrn9fqigq.v2f.whlin@Venus.bblab.cgmh.com.tw>
While writing codes of copying files in PERL, a question strikes me.
Why are some *nix commands (chown(1), chmod(1), just name a few) built-in
while others (cp(1), mv(1), etc) are not? What are the criteria?
--
------------------------------
Date: Sun, 13 May 2001 01:40:31 +1000
From: "Gregory Toomey" <gtoomey@usa.net>
Subject: Re: criteria for bulit-in functions
Message-Id: <OBcL6.25152$482.120462@newsfeeds.bigpond.com>
"Wei-hao Lin" <whlin@Venus.bblab.cgmh.com.tw> wrote in message
news:slrn9fqigq.v2f.whlin@Venus.bblab.cgmh.com.tw...
>
> While writing codes of copying files in PERL, a question strikes me.
> Why are some *nix commands (chown(1), chmod(1), just name a few) built-in
> while others (cp(1), mv(1), etc) are not? What are the criteria?
The chown, chmod, unlink etc commands are implemented in *nix as a single
operating system call, and may take just microseconds to finish.
cp, mv are implemented in *nix as C programs, which parse their arguments
and perform various system calls. So "cp -r dir1 dir2" may do hundreds of
system calls. This could take ages to finish.
Perl is Posix compliant http://language.perl.com/newdocs/lib/POSIX.html
Posix is a standard *nix interface.
Certainly cp and mv would be very useful though.
gtoomey
------------------------------
Date: 12 May 2001 16:36:21 +0100
From: nobull@mail.com
Subject: Re: criteria for bulit-in functions
Message-Id: <u9g0eaziiy.fsf@wcl-l.bham.ac.uk>
whlin@Venus.bblab.cgmh.com.tw (Wei-hao Lin) writes:
> While writing codes of copying files in PERL, a question strikes me.
> Why are some *nix commands (chown(1), chmod(1), just name a few) built-in
> while others (cp(1), mv(1), etc) are not? What are the criteria?
Those numbers in brackets are the clue. It is not chown(1) and
chmod(1) that are builtins in Perl but chown(2) and chmod(2).
Perl provides builtins for some of the most useful Unix system
calls. Most of the rest can be found in the POSIX module.
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: 12 May 2001 16:07:31 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: criteria for bulit-in functions
Message-Id: <9djn43$1ft$1@mamenchi.zrz.TU-Berlin.DE>
According to Wei-hao Lin <whlin at jan.csie.ntu.edu.tw>:
> While writing codes of copying files in PERL, a question strikes me.
Ahem. You don't write in "PERL", you write in Perl. See the
FAQ for the difference, perldoc -q 'difference between' takes
you there.
> Why are some *nix commands (chown(1), chmod(1), just name a few) built-in
> while others (cp(1), mv(1), etc) are not? What are the criteria?
Perl doesn't even attempt to implement the whole Unix command set
(whatever that may be). Would you expect Perl to implement say,
traceroute, or vi? Not to mention perl itself.
Perl gives you access to most Unix system calls (all, if you count
syscall) under their original name. Some of these calls also have
counterparts as Unix commands, these are the ones you recognize,
chown and chmod among them. Others do have command counterparts,
but under a different name: the mv command you are missing is
based on a call named rename, and under that name perl offers
(part of) the functionality of the mv command.
Then there are those Unix commands, that are not just a text interface
to a system call, but programs in their own right. The mv command
just mentioned actually belongs there, as does cp, and, of course,
things like traceroute or vi, .nd perl Perl doesn't implement these,
but they could be implemented in Perl, and quite a few have been. The
functionality of the cp command, for instance, can be found in the
standard module File::Copy.
Anno
------------------------------
Date: Sat, 12 May 2001 16:21:01 +0200
From: Simon Stiefel <SiStie@nuclear-network.com>
Subject: Re: dbmopen and tie
Message-Id: <Pine.LNX.4.31.0105121610590.1994-100000@server.stiefel.priv>
On 10 May 2001, Anno Siegel wrote:
> > > Why do you think you need both? I can't think of anything you can
> > > do with dbmopen that can't be done with tie.
> >
> > Because I have one database (*.pag & *.dir) which I want to make to a
> > single file (like craeting a database with tie).
>
> No, you misunderstand the relationship between dbmopen and tie. The
> structure of the database (which also governs whether it is stored in
> a single file or in a .dir/.pag pair) is determined by the database
> module you use: DB_GDBM, DB_File, etc. All of these can be used with
> the deprecated dbmopen and the current tie. There is no reason to use
> both in one program.
Hmm, so, how can I write a "converter", which converts a database (created
with dbmopen, 2 Files) to another which shall be used with tie (1 File)?
afaik I have to open the old database with dbmopen and, at the same time,
I have to create a new one with tie, so that I can "convert" the old one
with a "foreach"-function.
I think, this can't be so difficult.
I just want to convert a 2-file-database to a 1-file-database.
> Anno
So long...
Mit freundlichen Gr=FC=DFen, .~. Open Minds.
with best regards /V\ Open Sources.
// \\ Open Future!
Simon Stiefel /( )\_ I N U X
^ ~ ^
--=20
|Simon Stiefel | Zwerbachstrasse 17 | 72555 Metzingen-Glems | Germany |
|SimonStiefel@nuclear-network.com | http://www.nuclear-network.com |
|ICQ#: 20196644 | phone: +49(0)7123/379070 | fax: +49(0)179/335990106 |
|Tux#: 114751 | PingoS - Linux-User helfen Schulen | Powered by LiNUX |
------------------------------
Date: 12 May 2001 14:43:53 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: dbmopen and tie
Message-Id: <9dji79$rbd$2@mamenchi.zrz.TU-Berlin.DE>
According to Simon Stiefel <SimonStiefel@nuclear-network.com>:
> On 10 May 2001, Anno Siegel wrote:
>
> > > > Why do you think you need both? I can't think of anything you can
> > > > do with dbmopen that can't be done with tie.
> > >
> > > Because I have one database (*.pag & *.dir) which I want to make to a
> > > single file (like craeting a database with tie).
> >
> > No, you misunderstand the relationship between dbmopen and tie. The
> > structure of the database (which also governs whether it is stored in
> > a single file or in a .dir/.pag pair) is determined by the database
> > module you use: DB_GDBM, DB_File, etc. All of these can be used with
> > the deprecated dbmopen and the current tie. There is no reason to use
> > both in one program.
>
> Hmm, so, how can I write a "converter", which converts a database (created
> with dbmopen, 2 Files) to another which shall be used with tie (1 File)?
>
> afaik I have to open the old database with dbmopen and, at the same time,
> I have to create a new one with tie, so that I can "convert" the old one
> with a "foreach"-function.
>
> I think, this can't be so difficult.
It isn't difficult at all. All I wanted to get across is that
there is no need to use the deprecated dbmopen in the process.
> I just want to convert a 2-file-database to a 1-file-database.
Tie (or dbmopen, if you must) the old database to one hash, using
the database module it was created with. Tie (or dbmopen) the
new database to another hash, using a database module of your
choice (DB_File, presumably). The copy the old hash to the new
one. If the database is small, you can do that with a simple
hash assignment. If it is bigger than you want to fit into memory,
use a while-loop with each(). That's it.
Anno
------------------------------
Date: Sat, 12 May 2001 16:47:55 GMT
From: "joeybach" <jr@stink.cfl.rr.com>
Subject: Decoding Net::SNMP get_request return
Message-Id: <20010512.125722.1529195746.7254@stink.cfl.rr.com>
Does some know how I can decode the output of a NET::SNMP get_request
$session->get_request("1.3.6.1.2.1.1.5.0");
$result = $session
It returns $result as "Net::SNMP=HASH(0x1a7f118)
the oid returns the hostname of the switch in this case (NYC1-S01-1) with
a command line snmpget. How can I decode The HASH?
I tried $result=$session->TRANSLATE_OPAQUE and the others from the docs
from cpan. Can anyone offer any suggestions ?
------------------------------
Date: 12 May 2001 16:32:40 +0100
From: nobull@mail.com
Subject: Re: first use of 'use strict' - getting Global symbol xxx requires explicit package name
Message-Id: <u9itj6zip3.fsf@wcl-l.bham.ac.uk>
Mark Grimshaw <m.grimshaw@salford.ac.uk> writes:
> Tried 'our' but got "use of reserved word 'our' is deprecated..."
> message
> None of my 3 books mentions 'our' is this in a later version of Perl
> (using 5.005_02)?
5.6
> perldiag??? - 'man perldiag' does nothing for me.... Perldiag seems
> useful from what you say - where is it?
Not all sysadmins will install the Perl manuals in the main manpage
tree. Try using "perldoc" rather than "man". If that fails speak to
your sysadmin and ask where (s)he put the Perl manuals.
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: Sat, 12 May 2001 16:54:56 +0100
From: Mark Grimshaw <m.grimshaw@salford.ac.uk>
Subject: Re: first use of 'use strict' - getting Global symbol xxx requires explicit package name
Message-Id: <3AFD5CD0.48BF8DB@salford.ac.uk>
Thank you very much!
> The pragma was introduced in 5.6.0. See the perldelta manual page for
> 5.6.0 under "Core Enhancements".
>
> Prior to 5.6.x, declare a package variable with `use vars' like this:
>
> use vars qw(@ISA @EXPORT);
>
> Then you can just assign to them the way you intended originally:
>
> @ISA = qw(Exporter);
> @EXPORT = qw(t_tie);
>
> > perldiag??? - 'man perldiag' does nothing for me.... Perldiag seems
> > useful from what you say - where is it?
>
> Try perldoc perldiag. Or just place this near the top of your
> program:
>
> use diagnostics;
>
> and perl will look up error and warning messages in the perldiag
> manual page for you.
>
> HTH
>
> --
> Garry Williams
------------------------------
Date: 12 May 2001 15:19:45 GMT
From: vek@pharmnl.ohout.pharmapartners.nl (Villy Kruse)
Subject: Re: first use of 'use strict' - getting Global symbol xxx requires explicit package name
Message-Id: <slrn9fql24.6i2.vek@pharmnl.ohout.pharmapartners.nl>
On Sat, 12 May 2001 15:47:24 +0100,
Mark Grimshaw <m.grimshaw@salford.ac.uk> wrote:
>
> Tried 'our' but got "use of reserved word 'our' is deprecated..."
>message
>None of my 3 books mentions 'our' is this in a later version of Perl
>(using 5.005_02)?
>and...
>
>perldiag??? - 'man perldiag' does nothing for me.... Perldiag seems
>useful from what you say - where is it?
Probably MANPATH doesn't include the perl manual pages. Try
"perldoc perldiag".
Villy
------------------------------
Date: Sat, 12 May 2001 15:34:32 GMT
From: garry@ifr.zvolve.net (Garry Williams)
Subject: Re: first use of 'use strict' - getting Global symbol xxx requires explicit package name
Message-Id: <slrn9fqm08.mb.garry@zfw.zvolve.net>
On Sat, 12 May 2001 15:47:24 +0100, Mark Grimshaw
<m.grimshaw@salford.ac.uk> wrote:
>> The perldiag manual page will explain what this means and precisely
>> what to do about it.
>>
>> our (@ISA) = qw(Exporter);
>> our (@EXPORT) = qw(t_tie);
>>
>> or:
>>
>> @TEST::ISA = qw(Exporter);
>> @TEST::EXPORT = qw(t_tie);
>
> Last one's done it - thanks.
>
> Tried 'our' but got "use of reserved word 'our' is deprecated..."
> message
> None of my 3 books mentions 'our' is this in a later version of Perl
> (using 5.005_02)?
The pragma was introduced in 5.6.0. See the perldelta manual page for
5.6.0 under "Core Enhancements".
Prior to 5.6.x, declare a package variable with `use vars' like this:
use vars qw(@ISA @EXPORT);
Then you can just assign to them the way you intended originally:
@ISA = qw(Exporter);
@EXPORT = qw(t_tie);
> perldiag??? - 'man perldiag' does nothing for me.... Perldiag seems
> useful from what you say - where is it?
Try perldoc perldiag. Or just place this near the top of your
program:
use diagnostics;
and perl will look up error and warning messages in the perldiag
manual page for you.
HTH
--
Garry Williams
------------------------------
Date: Sat, 12 May 2001 15:47:24 +0100
From: Mark Grimshaw <m.grimshaw@salford.ac.uk>
Subject: Re: first use of 'use strict' - getting Global symbol xxx requires explicit package name
Message-Id: <3AFD4CFC.357860D2@salford.ac.uk>
> The perldiag manual page will explain what this means and precisely
> what to do about it.
>
> our (@ISA) = qw(Exporter);
> our (@EXPORT) = qw(t_tie);
>
> or:
>
> @TEST::ISA = qw(Exporter);
> @TEST::EXPORT = qw(t_tie);
Last one's done it - thanks.
Tried 'our' but got "use of reserved word 'our' is deprecated..."
message
None of my 3 books mentions 'our' is this in a later version of Perl
(using 5.005_02)?
and...
perldiag??? - 'man perldiag' does nothing for me.... Perldiag seems
useful from what you say - where is it?
------------------------------
Date: Sat, 12 May 2001 14:02:55 GMT
From: garry@ifr.zvolve.net (Garry Williams)
Subject: Re: first use of 'use strict' - getting Global symbol xxx requires explicit package name
Message-Id: <slrn9fqgkf.l2.garry@zfw.zvolve.net>
On Sat, 12 May 2001 14:34:11 +0100, Mark Grimshaw
<m.grimshaw@salford.ac.uk> wrote:
> Investigating 'use strict' but getting above error message when
> running script.
[snip]
> package TEST;
> use strict;
> use Exporter;
> @ISA = qw(Exporter);
> @EXPORT = qw(t_tie);
The perldiag manual page will explain what this means and precisely
what to do about it.
our (@ISA) = qw(Exporter);
our (@EXPORT) = qw(t_tie);
or:
@TEST::ISA = qw(Exporter);
@TEST::EXPORT = qw(t_tie);
--
Garry Williams
------------------------------
Date: Sat, 12 May 2001 14:34:11 +0100
From: Mark Grimshaw <m.grimshaw@salford.ac.uk>
Subject: first use of 'use strict' - getting Global symbol xxx requires explicit package name
Message-Id: <3AFD3BD3.C31EB469@salford.ac.uk>
Investigating 'use strict' but getting above error message when running
script.
The script:
#!/usr/local/bin/perl -w
use strict;
use TEST;
use DB_File;
my $db = '/music/cgi-bin/q3aforum/topicdb';
&opendb;
exit;
sub opendb
{
my %DB;
&t_tie(\%DB, "DB_File", $db, (O_RDONLY));
print "$DB{'0'}\n";
untie(%DB);
undef(%DB);
}
...and the package:
#!/usr/local/bin/perl -w
package TEST;
use strict;
use Exporter;
@ISA = qw(Exporter);
@EXPORT = qw(t_tie);
sub t_tie
{
my($D) = $_[0];
my($mode) = $_[3];
tie(%{$D}, $_[1], $_[2], $mode) || die print "can't open\n\n";
}
1;
Commenting out 'use strict' in the package TEST makes the script run
fine. Uncommenting produces the 'Global symbol...' error message re.
@ISA and @EXPORT. None of the 3 books I'm referencing seems to have the
solution (can't find it - don't know where to look) and all examples
I've typed in from the books abort when I try 'use strict' with them.
Anyone know the proper way to explicitly qualify the package these two
global variables use? (Plain English for a non-Perl-guru please!)
------------------------------
Date: Sat, 12 May 2001 23:13:12 +0800
From: "´Z©Ò¤ô@!¡±o^" <crud_alex@yahoo.com>
Subject: Freaky hash
Message-Id: <9djjh6$223$1@taliesin.netcom.net.uk>
i got the following codes :
#!perl
my $output = the_sub(7,9);
print "So now : \nThe result of $output\n";
#the sub begin
sub the_sub{
my %eng_lower_set =
qw(1 one 2 two 3 three 4 four 5 five
6 six 7 seven 8 eight 9 nine);
my %eng_upper_set =
qw(1 One 2 Two 3 Three 4 Four 5 Five
6 Six 7 Seven 8 Eight 9 Nine);
my($a,$b) = @_;
$sum = $a+$b;
print "$a $b\n";
print "$sum\n";
print values(%eng_upper_set),"\n";
$a = $eng_upper_set{$a};
$b = $eng_lower_set{$b};
print "$sum\n";
print "$a $b\n";
return ("$a plus $b equals $sum")
}
~
then , i got the output like this :
~
7 9
16
OneTwoThreeFourFiveSixSevenEightNine
16
Seven nine
So now :
The result of Seven plus nine equals 16
~
isn't it that the values order of the hashed are arbitary?
so how come i got ordered output like onetwothreefourfive......
------------------------------
Date: Sat, 12 May 2001 16:54:28 +0100
From: "Ciaran McCreesh" <keesh@users.pleaseremovethisbit.sourceforge.net>
Subject: Re: Freaky hash
Message-Id: <9djm7j$dop$1@news6.svr.pol.co.uk>
In article <9djjh6$223$1@taliesin.netcom.net.uk>, "´Z©Ò¤ô@!¡±o^"
<crud_alex@yahoo.com> wrote:
> isn't it that the values order of the hashed are arbitary? so how come i
> got ordered output like onetwothreefourfive......
Because that's the order they happen to hash to with the particular
version of perl you're using. You can't assume that the order won't
change...
--
Ciaran McCreesh
mail: keesh@users.sourceforge.net
web: http://www.opensourcepan.com/
------------------------------
Date: 12 May 2001 16:29:52 +0100
From: nobull@mail.com
Subject: Re: Help
Message-Id: <u9lmo2zitr.fsf@wcl-l.bham.ac.uk>
"scott.bell1" <scott.bell1@ntlworld.com> writes:
> Can anyone tell me of a website that explains the basics of CGI?
Can "anyone" use a web portal site or search engine? (E.g. Yahoo)
Can "anyone" explain why you think this is on-topic here, rather than
say a newsgroup about CGI?
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: 12 May 2001 16:10:47 +0100
From: nobull@mail.com
Subject: Re: how to write OO interfaces `a la' Java?
Message-Id: <u9r8xuzjpk.fsf@wcl-l.bham.ac.uk>
fxn@isoco.com (F. Xavier Noria) writes:
> In Java one has both classes and interfaces and this could
> be a clear case to use the latter, what is the standard idiom
> in Perl to get that? Is the interface just documented? Would
> one write a dummy class
Either approach is perfectly valid.
> package Foo::ToBeSubclassed;
>
> sub method {
> my ($self) = @_;
> die "method() is not implemented in $self.\n";
> }
Personnally I'd only bother writing a base class if the interface has
optional parts, particualarly if it has optional method for which a
meaningful default exists.
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
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 883
**************************************