[7547] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 1173 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Oct 14 06:17:13 1997

Date: Tue, 14 Oct 97 03:00:23 -0700
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Tue, 14 Oct 1997     Volume: 8 Number: 1173

Today's topics:
     Re: 2000 time problem <seay@absyss.fr>
     ANNOUNCE: IndexMaker 1.0: an index.html maker from PDF  <pivari@geocities.com>
     Re: Can someone look at this and tell me why it doesn't <jgostin@shell2.ba.best.com>
     Re: Can someone look at this and tell me why it doesn't <jgostin@shell2.ba.best.com>
     Re: Can someone look at this and tell me why it doesn't <jgostin@shell2.ba.best.com>
     Re: Can someone look at this and tell me why it doesn't (Casper K. Clausen)
     Re: Checking for a file <seay@absyss.fr>
     Re: Database Management in UNIX <seay@absyss.fr>
     Re: DBM documentation <seay@absyss.fr>
     Re: Help: Text Formatter in Perl (robert)
     need advanced GUESTBOOK script <web@rnw.nl>
     Re: NEWBIE: How to read a file into a scalar <seay@absyss.fr>
     Re: Passing arguments to a script  in HTML <AndieC@msn.com>
     Re: Passing arguments to a script  in HTML (brian d foy)
     Problem with Time <Csaba.Csillag@sysdata.siemens.at>
     Re: Problems compiling perl under Solaris 2.5.1 (Casper H.S. Dik - Network Security Engineer)
     Re: Problems with flock (Peter J. Schoenster)
     Re: reg exp size limit !? (Ilya Zakharevich)
     Re: reg exp size limit !? (Ilya Zakharevich)
     Re: Searchable Database. <seay@absyss.fr>
     Sorting the values, getting right keyorder <hklein@ikp.uni-koeln.de>
     Re: Sorting the values, getting right keyorder <eike.grote@theo.phy.uni-bayreuth.de>
     Re: Sorting the values, getting right keyorder <seay@absyss.fr>
     Special Variables <jmalouf@uen.org>
     Re: Special Variables <seay@absyss.fr>
     Re: Special Variables (Ilya Zakharevich)
     Re: statics or const in perl ? <seay@absyss.fr>
     Re: statics or const in perl ? <seay@absyss.fr>
     Re: Testing for file <seay@absyss.fr>
     Re: uninitialized value warning for m// substrings (Mike Heins)
     Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)

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

Date: Tue, 14 Oct 1997 10:34:05 +0200
From: Doug Seay <seay@absyss.fr>
Subject: Re: 2000 time problem
Message-Id: <34432E7D.123ECD68@absyss.fr>

[posted, not mailed because addresses didn't match]

Bremen Lee wrote:
> 
> I try to use ctime and localtime to generate the time in Win32 Perl.
> I found that it will output wrong date when I set my win95 to 2050.

32-bit dates are only good until sometime in 2038 when they rollover
(become negative).  "Conventional wisdom" says that 64-bit dates will be
the norm before this becomes critical.

> Do you know is there any other way to generate correct date??

Nope.  You'll have to handle this manually.

- doug


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

Date: Tue, 14 Oct 1997 08:55:42 +0000
From: Fabrizio Pivari <pivari@geocities.com>
Subject: ANNOUNCE: IndexMaker 1.0: an index.html maker from PDF files
Message-Id: <3443338E.2F1C@geocities.com>

Hi,

I'm glad to announce the version 1.0 of IndexMaker a perl script to make
an index.html file from PDF files.
At the moment, it uses the /Author fild and the first /Title fild in
every matched PDF files.
It should work with PERL 4 and 5.

This is the URL where you can find the tool
http://www.geocities.com/CapeCanaveral/Lab/3469

Enjoy it!

Send me your suggestions.

-- 
     _/_/_/_/ _/_/_/    Fabrizio Pivari
    _/       _/    _/   mailto:pivari@hotmail.com
   _/_/_/   _/_/_/      mailto:pivari@geocities.com
  _/       _/           http://www.geocities.com/CapeCanaveral/Lab/3469/
 _/       _/


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

Date: 14 Oct 1997 06:32:28 GMT
From: Jeff Gostin <jgostin@shell2.ba.best.com>
Subject: Re: Can someone look at this and tell me why it doesn't work!!
Message-Id: <61v3ls$4j0$2@nntp1.ba.best.com>

Casper K. Clausen <ckc@dmi.min.dk> wrote:
: You tried it out, huh? Well, I just popped it off the top of my head, so
: it figures it wouldn't work :) It was a stupid mistake, though, no excuses
: there.

I _always_ try out code snippets people post in response to my questions,
after checking them out to see what they do. It's one of the best ways to
learn... dissect, understand, and attempt. :)

: You may still want to allow for \., since that would make
: floating-point numbers numeric--which sort of makes sense.
I agree... and I made one booboo in my code snippet. I put \w in the
beginning where I had intended \s (plus the (zero or more) modifier that I
can't remember off the top of my head). I intended whitespace, not
word-chars, and I _always_ make that mistake. Bad Rookie, no Output. ;)


				--Jeff


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

Date: 14 Oct 1997 06:33:58 GMT
From: Jeff Gostin <jgostin@shell2.ba.best.com>
Subject: Re: Can someone look at this and tell me why it doesn't work!!
Message-Id: <61v3om$4j0$3@nntp1.ba.best.com>

Toutatis <toutatis@_SPAMTRAP_toutatis.net> wrote:
: Nice to be easily pleased, but your code is wrong as well.
Yeah, I noticed the error. In fact, I just posted a response to a previous
article that indicated the change I'd make. I think I like your suggestion
better than my own, though. It's tight, it's neat, and it's an Interesting
Educational Thingie. :)

Thanks for the snippet. :)


				--Jeff


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

Date: 14 Oct 1997 06:37:42 GMT
From: Jeff Gostin <jgostin@shell2.ba.best.com>
Subject: Re: Can someone look at this and tell me why it doesn't work!!
Message-Id: <61v3vm$4j0$4@nntp1.ba.best.com>

Tad McClellan <tadmc@flash.net> wrote:
: Uh, Uh. I think you must have meant "If that is an RTFM" (the Q below)
: rather than "this" (what you quoted above)  ;-)
Agreed, and I'll be RTF-FAQ'ing on this. Thanks for pointing it out!

			--Jeff, who promises to be a less outwardly
                                enthusiastic student. :)


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

Date: 14 Oct 1997 09:18:58 +0200
From: ckc@dmi.min.dk (Casper K. Clausen)
Subject: Re: Can someone look at this and tell me why it doesn't work!!
Message-Id: <wvpyb3w24nx.fsf@hobbes.dmi.min.dk>

>>>>> "Jeff" == Jeff Gostin <jgostin@shell2.ba.best.com> writes:

Jeff> I _always_ try out code snippets people post in response to my
Jeff> questions, after checking them out to see what they do. It's one
Jeff> of the best ways to learn... dissect, understand, and
Jeff> attempt. :)

Hey, that's also a pretty good excuse for not checking out one's
answers before posting ;)

But yes, you're right. It IS a great way to learn. That's also the
reason why I'll often just give ideas instead of working code (that
and my tendency to hit send before REALLY thinking things through :)

Happy hacking,
Kvan.
-- 
-------Casper Kvan Clausen------ | 'Ah, Warmark, everything that passes
----------<ckc@dmi.dk>---------- |  unattempted is impossible.'
           Lokal  544            |   
I do not speak for DMI, just me. |        - Lord Mhoram, Son of Variol.      


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

Date: Tue, 14 Oct 1997 10:51:55 +0200
From: Doug Seay <seay@absyss.fr>
Subject: Re: Checking for a file
Message-Id: <344332AB.216D33E1@absyss.fr>

Randal Schwartz wrote:
> 
> >>>>> "John" == John Grimm <jgrimm@wireedm.com> writes:
> 
> John> How can I check to see if a file is there or not?
> 
> Try to remove it with unlink. If the result is 0, it wasn't there.
> If the result is 1, it's not there now.
> 
> :-)

As is this solution doesn't work for directories (not part of the
original question).  For that to work right, you have to be running as
root with the -U option.

- doug


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

Date: Tue, 14 Oct 1997 11:32:00 +0200
From: Doug Seay <seay@absyss.fr>
To: uprado01@shafika.vetri.com
Subject: Re: Database Management in UNIX
Message-Id: <34433C10.5A087112@absyss.fr>

[posted and mailed]

dominic@thiru.vetri.com wrote:
> 
> Hello Perlians,
> 
> I regret if it is a repeated question.

Why bother checking the docs/FAQ.  No one else does.

> So far I have been using Perl for Win32 in Win95 and Win NT machines.  In
> that I was using Dave Roth's Win32::ODBC module without any problem. Now
> I have to use something like a database management utility in my unix
> system.
> 
> I need to do the following in my UNIX machine
> 
>   1. Create a new database with 5 fields (or more).
> 
>   2. Add record(s) to that new database file.
> 
>   3. Grep some records and modify it and update it in the database.
> 
>   4. Delete some records with some specific field name.
> 
>   5. Generate a report (something like using SQL statement).
> 
> Is would like to know whether these are possible in UNIX side using a
> perlscript?

What is "perlscript"?  Is this like JavaScript?  But yes, you can do
this sort of thing.  Use a DBM_File to store the data and either use
pack/unpack yourself, or use MLDBM to have multi-level data elements. 
You'll need to build the report generator yourself, but that ain't too
complicated.

Of course, you could just use an Oracle module, if that is an
appropriate solution.  Again, check out CPAN.

> Is there any ready-made modules available?

Yes, they're at CPAN (actually, some are already installed on your
system as they come with the standard distribution).

> Kindly point me to the right direction.

man, CPAN, camel - they should do the trick

- doug


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

Date: Tue, 14 Oct 1997 10:56:53 +0200
From: Doug Seay <seay@absyss.fr>
Subject: Re: DBM documentation
Message-Id: <344333D5.1947F145@absyss.fr>

Mark Aurit wrote:
> 
> Can anyone point me to a good (perferably on-line) source of DBM
> documentation? The books I have say very little about it, and my
> searches on www.perl.com were all over the place. I just want to use
> some basic functionality (read from a file, write to the file, lookups,
> etc).

	perldoc AnyDBM_File

This module gives you a good overview of the whole DBM family of modules
(DBM, NDBM, GDBM, Berkeley DB, etc).  Note that not all of these
libraries are installed on every system.

- doug


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

Date: 14 Oct 1997 11:11:30 +0200
From: robert@il.fontys.nl (robert)
Subject: Re: Help: Text Formatter in Perl
Message-Id: <61vd02$35b@bsd1.hqehv-internal.ilse.net>

sean@delphi.glendon.yorku.ca (Blackthorne):
 >Does anyone know where or if there is a Perl Programme out there in some
 >archive that formats text?
 >Right now, I'm looking to see if there is already an existing file out there
 >in some archive.  But if anyone is crazy enough to want to code it for me
 >and themselves, they are welcome to contact me.  I really don't have the time
 >to learn Perl and code it myself.

If you're not too hung up on perl, you could get yourself the 'par'
textformatter, which is a pretty smart program. I really don't have
the time to search for a URL where you can find 'par', though ;)

                                                             robert

PS: do I smell 'homework assignment' here? Nah, I must be paranoid.


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

Date: 14 Oct 1997 08:37:48 GMT
From: "Caroline van Oosten de Boer" <web@rnw.nl>
Subject: need advanced GUESTBOOK script
Message-Id: <01bcd885$013790c0$f6ce3a91@VonB.rnw.nl>

For our company, <http://www.rnw.nl/> I am looking for
an advanced guestbook scripts that generates
its own new pages,say, each month.
We are currently using the guestbook script from Matt's
Script Archive and are looking either for a rewrite of this
or a completely new script.

If anyone's got any ideas, please mail us at web@rnw.nl

Caroline van Oosten de Boer
RN interactive
Radio Netherlands


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

Date: Tue, 14 Oct 1997 11:23:46 +0200
From: Doug Seay <seay@absyss.fr>
Subject: Re: NEWBIE: How to read a file into a scalar
Message-Id: <34433A22.223F73A@absyss.fr>

Tikki tikki tembo-no sa rembo-chari bari ruchi-pip peri pembo wrote:
> 
> I'm trying to read a text file into a scalar.  I was originally just
> setting the scalar equal to the filehandle, but I got coredumps when
> the file was too big.  I tried using the read command from page 170 of
> the camel book, but it would only work properly when LENGTH was set to
> 16000 or less (any more, and the script would hang or give memory
> errors), and when the file was smaller than LENGTH.

I normally don't bother with read().  It is a useful function, and I
don't knock you for trying it, but I think it is usually easier to read
whole files with

                   undef $/;
                   $_ = <FH>;          # whole file now here

This comes from "perlvar", namely the bit about the $/ variable
($INPUT_RECORD_SEPARATOR using the English.pm module).  Look it up for
more details.

As for your problem with read, is there any chance that fread() [the one
in the C library] on your system has a 15 bit limitation?  A signed
short in (in C speak) could cause this sort of problem.

- doug


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

Date: Tue, 14 Oct 1997 01:32:42 -0700
From: "Andie Crossland" <AndieC@msn.com>
Subject: Re: Passing arguments to a script  in HTML
Message-Id: <01bcd87b$15bfce40$c3933ec2@w95-acc.wilco.co.uk>

Try <FORM ACTION="/scripts/HelloWorld.pl?arg1=value1?arg2=value2.

Andie.




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

Date: Tue, 14 Oct 1997 05:40:33 -0400
From: comdog@computerdog.com (brian d foy)
Subject: Re: Passing arguments to a script  in HTML
Message-Id: <comdog-ya02408000R1410970540330001@news.panix.com>

In article <01bcd87b$15bfce40$c3933ec2@w95-acc.wilco.co.uk>, "Andie Crossland" <AndieC@msn.com> wrote:

>Try <FORM ACTION="/scripts/HelloWorld.pl?arg1=value1?arg2=value2.

when you find out that it doesn't work try:

    <FORM ACTION="/scripts/HelloWorld.pl?arg1=value1&arg2=value2">
                                                    ^          ^^
                                                    |          ||

-- 
brian d foy                                  <comdog@computerdog.com>
NY.pm - New York Perl M((o|u)ngers|aniacs)*  <URL:http://ny.pm.org/>
CGI Meta FAQ <URL:http://computerdog.com/CGI_MetaFAQ.html>


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

Date: Tue, 14 Oct 1997 08:56:15 +0200
From: Csillag Csaba <Csaba.Csillag@sysdata.siemens.at>
Subject: Problem with Time
Message-Id: <3443178F.E89F58D0@sysdata.siemens.at>

Hi,
I write a CGI script in Perl that receives two parameters, year and
month. The script should tell how many days in the given month are .  I
tried to use the timelocal() function, but i didn't have success. Has
anyone an idea, how to get the number of days of the given month?
Additionaly,I would like to know which day of the week the first day of
the given month is.

Thanks

                        Csaba



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

Date: 14 Oct 1997 08:57:36 GMT
From: Casper.Dik@Holland.Sun.Com (Casper H.S. Dik - Network Security Engineer)
Subject: Re: Problems compiling perl under Solaris 2.5.1
Message-Id: <casper.876819790@uk-usenet.uk.sun.com>

[[ Reply by email or post, don't do both ]]

jkstill@teleport.com writes:

>On Mon, 13 Oct 1997 16:09:56, in comp.lang.perl.misc you wrote:

>>I have been trying to compile  per l5.004_01 on a Solaris 2.5.1 machine with 
>>Sun's C compiler. I  get errors such as:

>You can't build Perl with Sun's compiler.  At least I couldn't.


Actually, it should be no problem.  It was't for me.


You will get into serious trouble if you use /usr/ucb/cc, though.


Building perl on Solaris with Sun's compielr is easy provided:

	you don't have /usr/ucb in $PATH (or have it last)
	you do have /opt/SUNWspro/bin in $PATH
	(that's where then Solaris native compiler lives)


Reconfigure after changing your $PATH and all should be well.

Casper
--
Expressed in this posting are my opinions.  They are in no way related
to opinions held by my employer, Sun Microsystems.
Statements on Sun products included here are not gospel and may
be fiction rather than truth.


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

Date: Tue, 14 Oct 1997 06:24:29 GMT
From: pschon@baste.magibox.net (Peter J. Schoenster)
Subject: Re: Problems with flock
Message-Id: <34430fb1.38842061@news.magibox.net>

Petri Backstrom <petri.backstrom@icl.fi> wrote:


>Just remove the unlocking code and leave the close. In no
>circumstances should you unlock before you close, because
>that opens up a window where some other process could get
>write access and write to the file before you get to the
>closing (and thus flushing any buffered data) - the result
>being corrupt data.


This is interesting.

I have always 

opened
flocked
unflocked
closed

But it seems as though I should

open
flock
close

Since the close will do the unflocking.  And it does make sense (and
I've wondered) that you could unflock and then the file could be
opened before closed.

Is all this true?

Thanks,

Peter



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

Date: 14 Oct 1997 06:44:18 GMT
From: ilya@math.ohio-state.edu (Ilya Zakharevich)
Subject: Re: reg exp size limit !?
Message-Id: <61v4c2$7qi$1@agate.berkeley.edu>

In article <61uv85$5m8$1@vixen.cso.uiuc.edu>,
Mike Heins <mheins@prairienet.org> wrote:
> No doubt your problem is this atom:
> 
> 	.+
> 
> That will not match a newline, so you need to
> either add the /s modifier to the regex or
> change the atom to:
> 
> 	[\000-\377]+

+ has no limit (unless in very old Perls).  something-harder+ _will_
have the limit 32K which the poster noticed.

This is *NOT* fixed in jumbo RE patch (which fixes, btw, limited size
of compiled RE).  Any trivial fix will case segfaults via stack
overruns (it so happens that on several OSes I tried the limit of the
stack size is pretty close (but bigger) to the size of stack generated
after 32k repetitions).

Ilya


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

Date: 14 Oct 1997 06:47:28 GMT
From: ilya@math.ohio-state.edu (Ilya Zakharevich)
Subject: Re: reg exp size limit !?
Message-Id: <61v4i0$7s4$1@agate.berkeley.edu>

In article <61v4c2$7qi$1@agate.berkeley.edu>,
Ilya Zakharevich <ilya@math.ohio-state.edu> wrote:
> + has no limit (unless in very old Perls).  something-harder+ _will_
> have the limit 32K which the poster noticed.

Hmm, in the message I sent out it was written:

  .+ has no limit (unless...

Some bad guy on the way ate dot.  Any ideas?

Ilya


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

Date: Tue, 14 Oct 1997 10:20:23 +0200
From: Doug Seay <seay@absyss.fr>
Subject: Re: Searchable Database.
Message-Id: <34432B47.62E4A677@absyss.fr>

Amy Dorsett wrote:
> 
> I am working on a project which entails implementing a searchable database
> via the internet using PERL/CGI.  I have programming experience (but
> none with PERL CGI) and know my database pretty well but combinig the two
> (and learning PERL) is not working...

You don't restrict yourself to a type of database.  I'd go with the
DBM_File stuff that comes with Perl5.  "perldoc AnyDBM_File" for
details.  Since this binds to a perl %hash variable, you can use all the
regular tricks for looking for a value in a hash.


> Do you have any suggestions at all on books, websites or anything else
> that may help me get started?

The DBM_File stuff comes standard with Perl, so read the camel, the man
pages, etc, etc.

- doug


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

Date: 14 Oct 1997 08:58:31 +0200
From: Heiko Klein <hklein@ikp.uni-koeln.de>
Subject: Sorting the values, getting right keyorder
Message-Id: <3pra9orfu0.fsf@hydra.ikp.uni-koeln.de>

Hi,

I try to sort a highscore with Name=>Points (and a bit more not
important here). And I would like to use "sort" for sorting the Points
and get the Names in the right order, too.

something like:(it doesn't work)

foreach $value (sort values %hash) {
	print "key_of_values($value) : values"
}	

Thanks in Advance

Heiko


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

Date: Tue, 14 Oct 1997 10:36:18 +0200
From: Eike Grote <eike.grote@theo.phy.uni-bayreuth.de>
Subject: Re: Sorting the values, getting right keyorder
Message-Id: <34432F02.167E@theo.phy.uni-bayreuth.de>

Hallo !

Heiko Klein wrote:
> 
> Hi,
> 
> I try to sort a highscore with Name=>Points (and a bit more not
> important here). And I would like to use "sort" for sorting the Points
> and get the Names in the right order, too.

Have a look at the Perl FAQ, part 5, question "How do I sort a hash 
(optionally by value instead of key)?".


Bye, Eike
-- 
=======================================================================
>>--->>    Eike Grote  <eike.grote@theo.phy.uni-bayreuth.de>    <<---<<
-----------------------------------------------------------------------
 Home Page, Address, PGP,...:  http://www.phy.uni-bayreuth.de/~btpa25/
-----------------------------------------------------------------------
 PGP fingerprint:      1F F4 AB CF 1B 5F 4B 1D 75 A1 F9 C5 7B 3F 37 06
=======================================================================


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

Date: Tue, 14 Oct 1997 11:35:15 +0200
From: Doug Seay <seay@absyss.fr>
Subject: Re: Sorting the values, getting right keyorder
Message-Id: <34433CD3.7DEE7DB3@absyss.fr>

Heiko Klein wrote:
> 
> Hi,
> 
> I try to sort a highscore with Name=>Points (and a bit more not
> important here). And I would like to use "sort" for sorting the Points
> and get the Names in the right order, too.
> 
> something like:(it doesn't work)
> 
> foreach $value (sort values %hash) {
>         print "key_of_values($value) : values"
> }

I'd do that with

foreach $value ( sort {$hash{$a} <=> $hash{$b}} keys %hash )
	{ ... }

because there ain't no way of converting a value to a key.  Remember
that keys have to be unique, values do not.  You could have several
people with a 0 points.

- doug


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

Date: Fri, 10 Oct 1997 14:30:46 -0600
From: John Malouf <jmalouf@uen.org>
Subject: Special Variables
Message-Id: <343E9076.FDDDC9E1@uen.org>

Is there a way in perl to find out the name of the
variable/array/hash you are working on?

For instance, if I am in a subroutine which I pass
a variable into, and I want to do a specific thing
based on the name of the variable I am currently
working on...can I get to it?

TIA for any help,

John
-- 
mailto:jmalouf@uen.org


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

Date: Tue, 14 Oct 1997 10:16:36 +0200
From: Doug Seay <seay@absyss.fr>
Subject: Re: Special Variables
Message-Id: <34432A64.5B92982D@absyss.fr>

John Malouf wrote:
> 
> Is there a way in perl to find out the name of the
> variable/array/hash you are working on?
> 
> For instance, if I am in a subroutine which I pass
> a variable into, and I want to do a specific thing
> based on the name of the variable I am currently
> working on...can I get to it?

I don't think so.  Normally you make subroutines that don't know where
they are called from.  They are usually much easier to manage.  If you
really need that, consider two functions that are similiar, but have
different names.  Perhaps one could call the other.

As for your actual question, try "perldoc -f caller".  It ends with the
semi-cryptic comment 

Furthermore, when called from within the DB package, caller returns more
detailed information: it sets the list variable @DB::args to be the
arguments with which the subroutine was invoked.

Perhaps you can play with this.

- doug


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

Date: 14 Oct 1997 08:57:23 GMT
From: ilya@math.ohio-state.edu (Ilya Zakharevich)
Subject: Re: Special Variables
Message-Id: <61vc5j$ap5$1@agate.berkeley.edu>

In article <34432A64.5B92982D@absyss.fr>, Doug Seay  <seay@absyss.fr> wrote:
> As for your actual question, try "perldoc -f caller".  It ends with the
> semi-cryptic comment 
> 
> Furthermore, when called from within the DB package, caller returns more
> detailed information: it sets the list variable @DB::args to be the
> arguments with which the subroutine was invoked.
> 
> Perhaps you can play with this.

Note that you can get to this list of arguments much easier:
	@{chr 5*19}
;-)

Ilya



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

Date: Tue, 14 Oct 1997 11:02:03 +0200
From: Doug Seay <seay@absyss.fr>
Subject: Re: statics or const in perl ?
Message-Id: <3443350B.FB80B9B@absyss.fr>

Jeremy D. Zawodny wrote:

>  *PI = \3.14159.

I prefer

	use constant PI => 3.14159;

I think Tom Phoenix's "constant.pm" started shipping with 5.004.  Maybe
it was with 5.003, I don't remember.

- doug


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

Date: Tue, 14 Oct 1997 11:11:17 +0200
From: Doug Seay <seay@absyss.fr>
Subject: Re: statics or const in perl ?
Message-Id: <34433735.41381864@absyss.fr>

Saviz Artang - MPG ~ wrote:
> 
> Is there a way to make a variable in perl a const. As in
> once it is set or when it is passed to a certain subroutine
> the variable can't be modified. I'm looking at something like
> this.
> 
> @array = ( "a", "b" ) ;
> 
> &mysub ( \@array ) ;
> 
> sub mysub {
>         my ( $arrayref ) = @_ ;
>         @$array[0] = "z" ;
> }
> 
> as you can see I can change the value of array[0] but how
> can i make it so arrayref is passed but read only and protected ?
> So I can't make changes to it.
> One way is ofcourse to copy it when passed but is there any
> command I can use to restrict changes to a variable ?

I don't think that you can do this.  I've never seen any keywords like
"const".  Just change your approach to

	@array = function(@array);

This gives &function() all the flexibility it wants/needs.  While
passing a bunch of elements is a bit slower than a reference, I doubt if
the cost is all that high.

As for "static", which you mention in your Subject: line, but not in the
question, there is no way to do this either.  Just create a package "my"
variable that is only used in one subroutine.

It looks like you are trying to code ANSI-C using Perl syntax.  As a
rule in Perl, we don't have all the little rules like that.  I'm not
saying that there aren't advatages to the ANSI-C approach, just that
this approach isn't the Perl way of thinking.   The "perlmodlib"
documentation has the following bit

NOTE
       Perl does not enforce private and public parts of its
       modules as you may have been used to in other languages
       like C++, Ada, or Modula-17.  Perl doesn't have an
       infatuation with enforced privacy.  It would prefer that
       you stayed out of its living room because you weren't
       invited, not because it has a shotgun.

The same reasoning is used with parameter passing.
 
- doug


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

Date: Tue, 14 Oct 1997 10:53:33 +0200
From: Doug Seay <seay@absyss.fr>
Subject: Re: Testing for file
Message-Id: <3443330D.458440BC@absyss.fr>

Jeremy D. Zawodny wrote:
> 
> [cc'd automagically to original author]
> 
> On Mon, 13 Oct 1997 06:59:12 -0700, John Grimm <jgrimm@wireedm.com>
> wrote:
> 
> >How can I test to see if a file is there?
> 
> if -e $file

-e says that there is an entry in the file system with this name.  It
might be a file, but it might not.  Directories, named pipes, Unix
Domain sockets and others all have file system entries.

- doug


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

Date: 14 Oct 1997 06:13:08 GMT
From: mheins@prairienet.org (Mike Heins)
Subject: Re: uninitialized value warning for m// substrings
Message-Id: <61v2hk$8qp$1@vixen.cso.uiuc.edu>

Daniel S. Lewart (d-lewart@uiuc.edu) wrote:
: systech@polarnet.com (Ken Irving) writes:
: 
: > I was hoping this would go away with 5.004_02, but the following
: > sample code gives a warning if one of the substring arguments in
: > the match is missing, because it is then used anyway.  The warning
: > is true, an uninitialized value is being used, but I know it will be
: > null, and the result is useful and convenient.  Perhaps this is a
: > lousy technique which I've used to good effect, but is there a way
: > to do this sort of thing without getting a warning?
: 
: > #!/perl/bin/perl -w
: > if ( "123" =~ /(\d)(\d)(\d)?/g ) { print $1,$2,$3,"\n" };
: > if ( "12"  =~ /(\d)(\d)(\d)?/g ) { print $1,$2,$3,"\n" };
: 
: Yes; this:
: 	print "$1\n" if "123" =~ /(\d\d\d?)/;
: 	print "$1\n" if "12"  =~ /(\d\d\d?)/;
: or this:
: 	print "$1\n" if "123" =~ /(\d{2,3})/;
: 	print "$1\n" if "12"  =~ /(\d{2,3})/;
: 

I also use this quite a bit, particularly when passing 
parameters to a subroutine:

 if ( "123" =~ /(\d)(\d)(\d)?/g ) { print $1,$2,$3 || undef,"\n" };
	
-- 
Regards,
Mike Heins

This post reflects the
opinion of my employer.


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

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


Administrivia:

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

	subscribe perl-users
or:
	unsubscribe perl-users

to almanac@ruby.oce.orst.edu.  

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

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

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

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

The "mini-FAQ", which is an updated version of the Meta-FAQ, is
available by requesting "send perl-users mini-faq". It appears twice
weekly in the group, but is not distributed in the digest.

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 V8 Issue 1173
**************************************

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