[8670] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 2287 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Apr 9 23:07:31 1998

Date: Thu, 9 Apr 98 20:00:28 -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           Thu, 9 Apr 1998     Volume: 8 Number: 2287

Today's topics:
    Re: BIG RENAME QUESTION??? <sowmaster@juicepigs.com>
    Re: BIG RENAME QUESTION??? (Craig Berry)
    Re: BIG RENAME QUESTION??? <sowmaster@juicepigs.com>
    Re: Bill Gates should be invited to O'Reilly's "Free So (Rodger Donaldson)
    Re: Can somebody help me understand the internals of "C <vladimir@cs.ualberta.ca>
        Child .bat inheriting Perl %ENV <bldadmin@esd.sgi.com>
        keys in hashs (Ali Mehdizadeh)
        Launched Win32 apps grabbing input focus <bldadmin@esd.sgi.com>
        Lay off O'reilly <tony@corcoll.demon.co.uk>
    Re: Looking for Polling/Voting CGI/java Script <sneaker@mediaone.net>
    Re: Looking for Polling/Voting CGI/java Script (Henning Petersen)
    Re: Looking for Polling/Voting CGI/java Script <sneaker@mediaone.net>
    Re: Looking for Polling/Voting CGI/java Script <sneaker@mediaone.net>
    Re: Need a web login script (Abigail)
    Re: Oops ( was:Re: Simple Unix Question,  ( Simple for  (Tad McClellan)
    Re: Perl and ODBC <j_moyle@hia.net>
        problem printing long line to file (Hello570)
    Re: problem with output (Craig Berry)
    Re: RMS should be invited to O'Reilly's "Free Software  (Alexander Viro)
    Re: s/PATTERN/<how to concat here>/g (Michael J Gebis)
    Re: scanf substitute in perl <rjk@coos.dartmouth.edu>
        Sharing a constant between scripts <rsgoheen@pobox.com>
    Re: Sharing a constant between scripts (Kevin Reid)
    Re: Strange "Modification of a read-only value attempte <rjk@coos.dartmouth.edu>
    Re: substituting text in a var (beginner question) (Craig Berry)
    Re: Tail-like functionality (Kees Hendrikse)
    Re: Tail-like functionality <rjk@coos.dartmouth.edu>
    Re: Week of Month (I R A Aggie)
        Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)

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

Date: Thu, 09 Apr 1998 19:28:09 -0400
From: Bob Trieger <sowmaster@juicepigs.com>
To: Tom Phoenix <rootbeer@teleport.com>
Subject: Re: BIG RENAME QUESTION???
Message-Id: <352D5989.4480@juicepigs.com>

Tom Phoenix wrote:
> 
> On Thu, 9 Apr 1998, Mark Polakow wrote:
 
> > rename ("$file","$newname") or die "$!";
> 
> Those double quotes are superfluous. (They make it look as if they're
> doing something, but they're not.)

They are needed on my Win95 machine running the standard win32 port. May
seem silly but it is Microsoft. Bill Gates may have bought the rights to
the double quote and is collecting residuals on their use.

-- 
Bob Trieger               |  Titanic: big boat, bigger
sowmaster@juicepigs.com   |           iceberg, big deal


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

Date: 9 Apr 1998 23:51:53 GMT
From: cberry@cinenet.net (Craig Berry)
Subject: Re: BIG RENAME QUESTION???
Message-Id: <6gjmup$33t$4@marina.cinenet.net>

Bob Trieger (sowmaster@juicepigs.com) wrote:
: Tom Phoenix wrote:
: > On Thu, 9 Apr 1998, Mark Polakow wrote:
: > > rename ("$file","$newname") or die "$!";
: > 
: > Those double quotes are superfluous. (They make it look as if they're
: > doing something, but they're not.)
: 
: They are needed on my Win95 machine running the standard win32 port. May
: seem silly but it is Microsoft. Bill Gates may have bought the rights to
: the double quote and is collecting residuals on their use.

I can't imagine how or why they'd be needed -- in any normal circumstance,
the result of $var and "$var" should be identical in your context.  What
happens to you if you leave off the quotes? 

---------------------------------------------------------------------
   |   Craig Berry - cberry@cinenet.net
 --*--    Home Page: http://www.cinenet.net/users/cberry/home.html
   |      Member of The HTML Writers Guild: http://www.hwg.org/   
       "Every man and every woman is a star."


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

Date: Thu, 09 Apr 1998 22:06:44 -0400
From: Bob Trieger <sowmaster@juicepigs.com>
Subject: Re: BIG RENAME QUESTION???
Message-Id: <352D7EB4.5AE4@juicepigs.com>

Craig Berry wrote:
> 
> Bob Trieger (sowmaster@juicepigs.com) wrote:
> : Tom Phoenix wrote:
> : > On Thu, 9 Apr 1998, Mark Polakow wrote:
> : > > rename ("$file","$newname") or die "$!";
> : >
> : > Those double quotes are superfluous. (They make it look as if they're
> : > doing something, but they're not.)
> :
> : They are needed on my Win95 machine running the standard win32 port. May
> : seem silly but it is Microsoft. Bill Gates may have bought the rights to
> : the double quote and is collecting residuals on their use.
> 
> I can't imagine how or why they'd be needed -- in any normal circumstance,
> the result of $var and "$var" should be identical in your context.  What
> happens to you if you leave off the quotes?

I spoke too soon. From the command line it gives an error, but works
fine otherwise.

-- 
Bob Trieger               |  Titanic: big boat, bigger
sowmaster@juicepigs.com   |           iceberg, big deal


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

Date: Thu, 9 Apr 1998 22:04:10 +0000
From: rodgerd@orwell.rm.gen.nz (Rodger Donaldson)
Subject: Re: Bill Gates should be invited to O'Reilly's "Free Software Summit" (was Re: RMS should be invited to O'Reilly's "Free Software Summit")
Message-Id: <slrn6iqhep.99s.rodgerd@orwell.rm.gen.nz>

On Thu, 09 Apr 1998 12:07:32 -0600, ben@hayamasa.demon.co.uk 
<ben@hayamasa.demon.co.uk> wrote:

[Rantings of "they have too killed free software, I just can't tell you what
it is, snipped.  Since there are no examples, it would be as pointless to
refute them]

>My point is that O'Reilly is a proprietory software and
>publishing company which really has no more right to hold a free
>software conference than Microsoft.

>From the Linux Network Administrator's Guide, published by ORA:

"In autumn 1993, Andy Oram ... asked me about publishing my book at O'Reilly
& Associates.  I was very excited about this; I had never imagined my book
being that successful.  We finally agreed that O'Reilly would produce an
Official Printied Version of the Networking Guide with me, while I retained
the original copyright so the source of the book could be freely
distributed.  This means you can choose freely: you can get the LaTeX source
distributed on the network (or the preformatted DVI or PostScript versions,
for that matter) and print it out, or you can purchase the official printed
version from O'Reilly.

 .. 

The point of the LDP license is to make sure no one gets shut out.  Other
people can print out copies of the book, and no one will blame you if you 
get one of those copies."

You clearly do not have a clue what you are are talking about.  Kindly fuck
off and don't come back until you do.

-- 
Rodger Donaldson		rodgerd@ihug.co.nz
The Pinguin Patrol


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

Date: 09 Apr 1998 17:00:35 -0600
From: Vladimir Alexiev <vladimir@cs.ualberta.ca>
Subject: Re: Can somebody help me understand the internals of "Carp"?
Message-Id: <omwwcyk3cc.fsf@tees.cs.ualberta.ca>

Andy Wardley writes:
		    if (ref $_) {
			# dunno what this is for...
			$_ .= '';
			s/'/\\'/g;
		    }
Conversion to string, ie basically the same thing as $_ = "$_".
If $_ was a ref blessed into Foo then it will look like
Foo=HASH(0x1234). I don't see how it can contain a ' unless the class
overloads the '""' method.

Interestingly, s/// converts to string only in case it is successful.
Eg, s/\(/\(/ converts a ref to string, but s/\[/\[/ doesn't.



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

Date: Thu, 09 Apr 1998 17:06:30 -0700
From: Build Administrator <bldadmin@esd.sgi.com>
Subject: Child .bat inheriting Perl %ENV
Message-Id: <352D6286.6CD98A9A@esd.sgi.com>

Under NT, when I system("somefile.bat") it doesn't have the environment
I've established with %ENV.

Is there a way to do this?   Example below prints nothing for TEST_ENV.

Thanks.

JR



# test.pl script

$ENV{"TEST_ENV"} = 101;
system("test.bat");

#-------------------


REM test.bat script

echo off
echo TEST_ENV: %TEST_ENV%

REM ------------------



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

Date: 9 Apr 1998 23:49:57 GMT
From: amehdiza@joule.ee.calpoly.edu (Ali Mehdizadeh)
Subject: keys in hashs
Message-Id: <6gjmr5$252$1@isnews.csc.calpoly.edu>

Hi,
What is the difference between these two:

$myhash{'key'} = 12;
$myhash{key} = 12;

seems to me that the first way was the 'old' way of doing it, and
the second way is the new (perl5) way of doing it.  Which one is 
better and why did they change it?

Thanks,
-Ali M.


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

Date: Thu, 09 Apr 1998 17:47:45 -0700
From: Build Administrator <bldadmin@esd.sgi.com>
Subject: Launched Win32 apps grabbing input focus
Message-Id: <352D6C30.80C9DD0B@esd.sgi.com>

Running a script that launches Win32 apps.  Each time an app is
launched it grabs input focus (NT) and disrupts workflow elsewhere
on the system.

Anyone know how to prevent this?



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

Date: Thu, 9 Apr 1998 05:58:52 +0100
From: tony Hitchinson <tony@corcoll.demon.co.uk>
Subject: Lay off O'reilly
Message-Id: <C455575623CED111941500409520680E36E5@BETTY>

	O'reilly Press have given up the best books on, Perl, C++, UNIX,
CGI, Javascript, HTML, PGP, the only book worth buying on send mail
don't forget Linux as well. Also O'Reilly books are cheaper than an
other book publisher in the UK. and now they are doing it for NT as
well. I have learnt a great deal from these book and I don't think I
would have the expertise to do my job as well as I do without these
book. As DG  said and I quote  "What, prey tell, have you written and
released lately, that gives you the
	right to throw stones at him?"

	The man Does have some right to earn a living and if sets up a
conference he can invite who ever he damn will pleases to invite.

	Tony Hitchinson 
	Support and Development Engineer



> -----Original Message-----
> From:	dg50@chrysler.com [SMTP:dg50@chrysler.com]
> Posted At:	Wednesday, April 08, 1998 10:04 PM
> Posted To:	misc
> Conversation:	Bill Gates should be invited to O'Reilly's "Free
> Software Summit" (was Re: RMS should be invited to O'Reilly's "Free
> Software Summit")
> Subject:	Re: Bill Gates should be invited to O'Reilly's "Free
> Software Summit" (was Re: RMS should be invited to O'Reilly's "Free
> Software Summit")
> 
> In article <6ggguu$lds$1@nnrp1.dejanews.com>,
>   ben@hayamasa.demon.co.uk wrote:
> >
> > In article <6ggdss$h5s$1@nnrp1.dejanews.com>,
> >   ben@hayamasa.demon.co.uk wrote:
> >
> > > (I don't know if O'Reilly's proprietory software was developed
> using
> > > free sources: I wouldn't be surprised.)
> >
> > I forgot that the O'Reilly proprietory Perl extensions (written
> > by Larry Wall) here which are a good example of where O'Reilly has
> made
> > free software into proprietory software.
> >
> > Also reading the original page which sparked this
> > discussion I was astonished to see that Tim O'Reilly describes
> > himself as a Free Software Luminary, which perhaps means that
> > he thinks Richard Stallman is a proprietory software luminary.  That
> > would explain why RMS wasn't invited to O'Reilly's conference.
> > On the other hand the other great free software luminary Bill Gates
> > should be invited of course.
> 
> Are you _completly_ nuts, or just trolling?
> 
> - O'Reilly publishes the best books on free software. In many cases,
> they
> publish the _only_ books on free software.
> 
> - O'Reilly actively promote free software at every opportunity, and
> are doing
> everything they can to help "legitimise" free software in the
> corporate world.
> 
> - O'Reilly are paying at least one noted free software developer
> (Larry Wall)
> to develop free software - and to the best of my knowledge, there's no
> strings
> attached with this. Perl is still free, and will always remain so.
> 
> - As for "proprietary" books... you can still DL all the LDP stuff
> they
> publish, and I believe their pick books (no longer in print) have been
> GPLed.
> 
> So IMHO, Tim O'Reilly has every right to refer to himself as a "free
> software
> luminary" if he so chooses. He's done stuff to back it up.
> 
> What, prey tell, have you written and released lately, that gives you
> the
> right to throw stones at him?
> 
> DG
> 
> These are my opinions, not Chrysler's.
> 
> 
> -----== Posted via Deja News, The Leader in Internet Discussion
> ==-----
> http://www.dejanews.com/   Now offering spam-free web-based
> newsreading



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

Date: Thu, 09 Apr 1998 23:28:33 GMT
From: Sneaker's Nest <sneaker@mediaone.net>
Subject: Re: Looking for Polling/Voting CGI/java Script
Message-Id: <352D581D.2583@mediaone.net>

brian d foy wrote:
> 
> In article <352D47D0.58D6@mediaone.net>, Sneaker's Nest <sneaker@mediaone.net> posted:
> 
> >PS - A Hint, keep a server side record of all IP addresses which has
> >voted and not allow another from that IP address.  Could be a problem
> >with data tracking in a CGI...
> 
> sorry, but that doesn't work (as Tom Phoenix has already pointed
> out).


Must have missed that one...
But I will write the code and post it.

HTH,
Sneex :-)


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

Date: Fri, 10 Apr 1998 00:22:21 GMT
From: henning.petersen.nospam.9814@hpc.dk (Henning Petersen)
Subject: Re: Looking for Polling/Voting CGI/java Script
Message-Id: <352d5d91.9997887@news.inet.tele.dk>

On Thu, 09 Apr 1998 22:18:59 GMT, Sneaker's Nest
<sneaker@mediaone.net> wrote:

> PS - A Hint, keep a server side record of all IP addresses which has
> voted and not allow another from that IP address.  Could be a problem
> with data tracking in a CGI...

This is a bad idea. What about all us using dynamic IP's og proxy/NAT?
That would mess things up at his side ;-)

-- 
Venlig hilsen / Best regards
	Henning

  _H_P_C_o_n_s_u_l_t_     E-mail:  mailto:henning.petersen@hpc.dk
  Skoletoften 9, Blans    Work:    http://www.hpc.dk
  DK - 6400 Soenderborg   Private: http://home1.inet.tele.dk/oz1lln


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

Date: Fri, 10 Apr 1998 02:05:15 GMT
From: Sneaker's Nest <sneaker@mediaone.net>
Subject: Re: Looking for Polling/Voting CGI/java Script
Message-Id: <352D7CD7.199D@mediaone.net>

Sneaker's Nest wrote:
> 
> brian d foy wrote:
> >
> > sorry, but that doesn't work (as Tom Phoenix has already pointed
> > out).
> 
> Must have missed that one...
> But I will write the code and post it.
> 
> HTH,
> Sneex :-)

Just teasing :-)

PS - I loved your recent article about die :-)


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

Date: Fri, 10 Apr 1998 02:06:48 GMT
From: Sneaker's Nest <sneaker@mediaone.net>
Subject: Re: Looking for Polling/Voting CGI/java Script
Message-Id: <352D7D34.60E3@mediaone.net>

Henning Petersen wrote:
> 
> On Thu, 09 Apr 1998 22:18:59 GMT, Sneaker's Nest
> <sneaker@mediaone.net> wrote:
> 
> > PS - A Hint, keep a server side record of all IP addresses which has
> > voted and not allow another from that IP address.  Could be a problem
> > with data tracking in a CGI...
> 
> This is a bad idea. What about all us using dynamic IP's og proxy/NAT?
> That would mess things up at his side ;-)


I agree.  I use a dynamically assign IP address here.  So, that is why I
said "As long as they never turn off their machines"  :-)


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

Date: 10 Apr 1998 02:50:48 GMT
From: abigail@fnx.com (Abigail)
Subject: Re: Need a web login script
Message-Id: <6gk1e8$rjn$1@client2.news.psi.net>

David Schwab (dschwab@wolfe.net) wrote on MDCLXXXII September MCMXCIII in
<URL: news:352C9571.FD3BAB78@wolfe.net>:
++ Yes I need a weblogin script that allows people to pass a login and
++ password thru a prompt and then have another way for an admin to add
++ users and remove something like .Htaccess please help if you can.


So, what's your Perl question? 

This group is not about the web, nor is it a gimme, gimme, gimme group.



Abigail
-- 
perl -wle 'print "Prime" if (0 x shift) !~ m 0^\0?$|^(\0\0+?)\1+$0'


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

Date: Thu, 9 Apr 1998 12:39:17 -0500
From: tadmc@flash.net (Tad McClellan)
Subject: Re: Oops ( was:Re: Simple Unix Question,  ( Simple for you maybe ))
Message-Id: <541jg6.0v1.ln@localhost>

Rob Tanner (rtanner@linfield.edu) wrote:
: In article <rtanner-0804980819030001@wildflower.linfield.edu>,
: rtanner@linfield.edu (Rob Tanner) wrote:

: Oops, I goofed!  :-(

: Since I first misinformed and now must repent -- as the bible teaches,
: it's payback plus 20%.  


That's a good attitude ;-)


: open(LS, "ls -l |");     # the "|" is a UNIX pipe symbol


Ack!

An open() call without checking the return value.

Please don't promote such fragile practices.

   open(LS, "ls -l |") || die "could not fork  $!";


And then, have a look at this FAQ (part 8):

   "Why doesn't open() return an error when a pipe open fails?"


It would be nice if your program aborted if the shell cannot
find or execute the 'ls' command rather than continuing to
execute and generating strange results...


: That's my plus 20%.  Sorry if I mislead anybody with my earlier erroneous
: posting.


It happens. Don't worry about it.

I guess you owe another 10% or so...    ;-)


--
    Tad McClellan                          SGML Consulting
    tadmc@metronet.com                     Perl programming
    Fort Worth, Texas


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

Date: Thu, 9 Apr 1998 19:56:28 -0500
From: "Joe Moyle" <j_moyle@hia.net>
Subject: Re: Perl and ODBC
Message-Id: <352d60a9.0@news.hia.net>

I hope I can help.  Check out
http://www.perl.com/CPAN-local/authors/Dave_Roth/ and
http://www.activestate.com/reference/aspSamples/index.htm .  These are good
places to help figure out this kind of question.

--
Joe Moyle
j_moyle@hia.net
DANG-TRUNG K.N. wrote in message <352A9764.119C@mail.dotcom.fr>...
>Hello,
>
>I wonder how I could link my web home page with an ODBC database like
>Access ? I heard that I would have to program a Perl module but I have
>no more informations about that ...
>
>Can anybody help me ?
>Thanks,
>
>Khoi.




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

Date: 10 Apr 1998 00:57:44 GMT
From: hello570@aol.com (Hello570)
Subject: problem printing long line to file
Message-Id: <1998041000574401.UAA20086@ladder01.news.aol.com>

        I tried printing a line to a file using both of the
 following methods, but the output was split into two 
lines.  Is there a way to force the string to be printed all 
on one line?

print PROJFILE <<WWW;
<!-- xxxxxxxxxxr --><LI>xxxxxxxxxxxr:<a
href=\"mailto:$p_xxxx_coord_email\">*$p_xxxxxxxx_coord_name</a>*$p_xxxxxx_
coord_phone\n
WWW

print PROJFILE "<!-- xxxxxxxxxxxr --><LI>xxxxxxxxxxxxx:<a
href=\"mailto:$p_xxxxxxx_manager_email\">*$p_xxxxxxx_manager_name</a>*$p_x
xxxxx_manager_phone\n";

Susan


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

Date: 9 Apr 1998 23:02:07 GMT
From: cberry@cinenet.net (Craig Berry)
Subject: Re: problem with output
Message-Id: <6gjk1f$33t$3@marina.cinenet.net>

shane michael harwood (sharwood@cs.uiowa.edu) wrote:
: i have written a script that takes input from a form, and prints it to a
: file..the problem i am having is that one of the fields is a text box
: and can spread for many lines....when the script prints it to the file
: it prints it as one long line...is there anyway to format this so it
: goes over multiple lines.

perldoc Text::Wrap

---------------------------------------------------------------------
   |   Craig Berry - cberry@cinenet.net
 --*--    Home Page: http://www.cinenet.net/users/cberry/home.html
   |      Member of The HTML Writers Guild: http://www.hwg.org/   
       "Every man and every woman is a star."


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

Date: 9 Apr 1998 19:13:14 -0400
From: viro@riemann.math.psu.edu (Alexander Viro)
Subject: Re: RMS should be invited to O'Reilly's "Free Software Summit"
Message-Id: <6gjkma$gu4@riemann.math.psu.edu>

In article <6gjem4$f61$1@mathserv.mps.ohio-state.edu>,
Ilya Zakharevich <ilya@math.ohio-state.edu> wrote:
[snip]
>Wrong.  They should use AL or BSD-type license.  Fortunately, I know
>only one piece of fine software which uses GPL and does not come from
>FSF, and it is EMX.
	Ilya, it is crossposted to c.o.l.m. You should know better, IMHO.
WTFH, everybody is free to use whatever license he likes. Stop this
bullshit, please. We already went through that flamewar in Dec-Jan. 


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

Date: 9 Apr 1998 22:54:27 GMT
From: gebis@albrecht.ecn.purdue.edu (Michael J Gebis)
Subject: Re: s/PATTERN/<how to concat here>/g
Message-Id: <6gjjj3$r3i@mozo.cc.purdue.edu>

mjd@op.net (Mark-Jason Dominus) writes:

}In article <6ghru1$frl$1@solaris.cc.vt.edu>,
}Michael Barnes  <mibarnes@mail.vth.vt.edu> wrote:
}>Use this instead:
}>
}>s/(STT,\d\d*\-\w\w*\-)(\d\d)/${1}19${2}/g;

}That'll work great for....hmmm... about another 600 days or so.
}After that, bang.  01-Jan-1900.

}Come on, folks.  When programmers in 1970 write COBOL programs that
}will break in the year 2000, it's not too hard to excuse their
}shortsightedness.  

}It's the middle of 1998.   Who can excuse a failure to see ahead now?
}Is there a competition to see how short we can make our
}shortsightedness?   Will we still be doing this in Novermber 1999?

Easy there.

Suppose I've got server logs going back to 1984.  They have two digit
years.  My new software produces four digit years, but I'd like to
convert my old logs so I can be nice and tidy-like.

Explain to me again how this will break in 600 days?

-- 
Mike Gebis  gebis@ecn.purdue.edu  mgebis@eternal.net


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

Date: Thu, 09 Apr 1998 22:15:40 -0400
From: Ronald J Kimball <rjk@coos.dartmouth.edu>
Subject: Re: scanf substitute in perl
Message-Id: <352D80CE.E7F5F6F9@coos.dartmouth.edu>

Andrew M. Langmead wrote:
> 
> Ronald J Kimball <rjk@coos.dartmouth.edu> writes:
> 
> >> Andrew M. Langmead wrote in message ...
> >>
> >> >($string1, $string2, $num) = ( $line =~ /(\S+)\s+(\S+)\s+([-+]?\d+)/ );
> 
> >These two incorrectly assume there must be whitespace after each string,
> >so change '\s+' to '\s*'.
> 
> But scanf() terminates scanning the "%s" format (with no maximum field
> width) at the first whitespace character, so \s+ is necessary.

Oops, you're right.  The documentation for scanf says that a whitespace
character terminates the %s input field.

So, if you want to emulate scanf, you should use '\s+', as Andrew originally suggested.

-- 
 _ / '  _      /         - aka -             rjk@coos.dartmouth.edu
( /)//)//)(//)/(    Ronald J. Kimball           chipmunk@m-net.arbornet.org
    /                                   http://www.ziplink.net/~rjk/
        "It's funny 'cause it's true ... and vice versa."


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

Date: Thu, 09 Apr 1998 18:31:53 -0700
From: Robert Goheen <rsgoheen@pobox.com>
Subject: Sharing a constant between scripts
Message-Id: <352D7689.299ACE08@pobox.com>

Ok, so I have a few scripts that share a few common constants (a couple
scalars, one array).  I want to maintain these constant separately, so
that I can edit a single file, rather than several.  My question is:
what is the "best practices" way to do this?

The way that I was going to approach this was by creating a package to
hold the constants:

package myConstants;

sub new {
  my $self = {};
  bless $self;
}

sub Constant1 { return ('rsgoheen@pobox.com');}
sub Constant2 { return ('Robert Goheen');}

  .....


# and then calling them like:

my $c = new myConstants;
print $c->Constant1, $c->Constant2;


Though I'm thinking that there must be a better way, especially since
I'm stumbling towards higher Perl enlightenment right now, and don't
have a full apreciation of OOP in Perl . . . .


-------
Robert S. Goheen
rsgoheen@pobox.com


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

Date: Thu, 9 Apr 1998 22:11:05 -0400
From: kpreid@ibm.net (Kevin Reid)
Subject: Re: Sharing a constant between scripts
Message-Id: <1d78n3x.md661l36dsg0N@slip166-72-108-123.ny.us.ibm.net>

Robert Goheen <rsgoheen@pobox.com> wrote:

> Ok, so I have a few scripts that share a few common constants (a couple
> scalars, one array).  I want to maintain these constant separately, so
> that I can edit a single file, rather than several.  My question is:
> what is the "best practices" way to do this?
> 
> The way that I was going to approach this was by creating a package to
> hold the constants:
> 
> package myConstants;
> 
> sub new {
>   my $self = {};
>   bless $self;
> }
> 
> sub Constant1 { return ('rsgoheen@pobox.com');}
> sub Constant2 { return ('Robert Goheen');}
> 
>   .....
> 
> 
> # and then calling them like:
> 
> my $c = new myConstants;
> print $c->Constant1, $c->Constant2;
> 
> 
> Though I'm thinking that there must be a better way, especially since
> I'm stumbling towards higher Perl enlightenment right now, and don't
> have a full apreciation of OOP in Perl . . . .

First of all, write your constants like this, so that Perl will optimize
them into "true" constants:

sub Constant1 () {'rsgoheen@pobox.com'}

Then, just put your constants into a file that ends with "1;" and put
this in your script:

require "myConstants.pl"; # or whatever you want to call the file

You can then use the constants like this:

$email = Constant1;

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

Another way to make constants is this:

*Constant1 = \'rsgoheen@pobox.com';

You can then use $Constant1.

(This might be slightly less efficient, I'm not sure)

-- 
  Kevin Reid.      |         Macintosh.
   "I'm me."       |      Think different.


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

Date: Thu, 09 Apr 1998 22:21:48 -0400
From: Ronald J Kimball <rjk@coos.dartmouth.edu>
Subject: Re: Strange "Modification of a read-only value attempted" error
Message-Id: <352D823E.5A5ED8E4@coos.dartmouth.edu>

James A Squire 312 M 193884 wrote:
> 
> Any other possibilities?

Tom Phoenix suggested another way.  Here are some explicit examples.

foo($1);
sub foo {
  # $_[0] is a read only value
}

foreach ($1) {
  # $_ is a read only value
}


> In the meantime, if I "use diagnostics" as was suggested in the WELCOME
> message I got after my first post to this group, will perl actually tell
> me which entity on line 302 (or whatever) it thinks is the read-only
> value instead of just giving me the line number?  That additional
> information might help me.  I'm just guessing it was talking about the
> array, but I could be wrong.

No, it won't tell you that.  use diagnostics just saves you a trip to the
perldiag manpage, which gives more detail about the error messages:

     Modification of a read-only value attempted
         (F) You tried, directly or indirectly, to change the value of a
         constant.  You didn't, of course, try "2 = 1", since the compiler
         catches that.  But an easy way to do the same thing is:

             sub mod { $_[0] = 1 }
             mod(2);

         Another way is to assign to a substr() that's off the end of the
         string.

Note another example; assigning to a substr() off the end of the string.

So, just what is line 302 in your program, anyway???

-- 
 _ / '  _      /         - aka -             rjk@coos.dartmouth.edu
( /)//)//)(//)/(    Ronald J. Kimball           chipmunk@m-net.arbornet.org
    /                                   http://www.ziplink.net/~rjk/
        "It's funny 'cause it's true ... and vice versa."


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

Date: 9 Apr 1998 23:01:22 GMT
From: cberry@cinenet.net (Craig Berry)
Subject: Re: substituting text in a var (beginner question)
Message-Id: <6gjk02$33t$2@marina.cinenet.net>

jf@medianook.com wrote:
: I'm new to Perl and have one quick problem with a program. In the program, I
: am establishing the following variables:
: 
: ###
: $referer=$ENV{"HTTP_REFERER"};
: $hiddenreferrer="<INPUT TYPE=\"hidden\" NAME=\"myreferrer\" VALUE=\
: "$myreferer\">";

Notice that you define '$referer', but then use '$myreferer' in the
string.  Also, you can't seem to decide how many Rs there are in
'referer'. :) If this is your actual code, that's one problem -- though it
wouldn't account for your symptom. 

Also, your string would be a lot easier to write using the qq syntax:

  qq!<INPUT TYPE="hidden" NAME="myreferrer" VALUE="$myreferer">!;

: Then, in my template file, I place:
: 
:    $hiddenreferrer
: 
: When I view the HTML source it writes:
: 
:    <INPUT TYPE="hidden" NAME=myreferrer" VALUE="$myreferrer">
: 
: What it should read is:
: 
:    <INPUT TYPE="hidden" NAME=myreferrer" VALUE="http://domain.com/file.html">

Are you really missing the " between 'NAME=' and 'myreferrer'?

: It looks like Perl is resolving it almost correctly. Am I not escaping it
: correctly to write the full referrer?

Given the typo-laden nature of the code above, I suspect we're not seeing 
your actual running code...and one character misplaced could explain a 
lot, in this case.  Please either clean up the name and spelling errors, 
or post the clean actual code, and I'll take another look.

---------------------------------------------------------------------
   |   Craig Berry - cberry@cinenet.net
 --*--    Home Page: http://www.cinenet.net/users/cberry/home.html
   |      Member of The HTML Writers Guild: http://www.hwg.org/   
       "Every man and every woman is a star."


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

Date: Thu, 9 Apr 1998 22:27:56 GMT
From: kees@echelon.nl (Kees Hendrikse)
Subject: Re: Tail-like functionality
Message-Id: <Er63qK.rp@echelon.nl>

In <352d5a47.164338488@news.oz.net> tgy@chocobo.org (Kuma) writes:

> Does this do what you want?
> 
>   use IO::Tail;
>   $fh = new IO::Tail '-20 largefile';
>   @last_20_lines = <$fh>;

Mm, not in my script; I read in a large file, do some processing on all
lines, drop all but the last n lines, print n lines.

-- 
Kees Hendrikse                               | email:     kees@echelon.nl
                                             | web:        www.echelon.nl
ECHELON consultancy and software development | phone: +31 (0)53 48 36 585
PO Box 545, 7500AM Enschede, The Netherlands | fax:   +31 (0)53 43 37 415


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

Date: Thu, 09 Apr 1998 22:48:18 -0400
From: Ronald J Kimball <rjk@coos.dartmouth.edu>
To: Kees Hendrikse <kees@echelon.nl>
Subject: Re: Tail-like functionality
Message-Id: <352D8875.CA90530B@coos.dartmouth.edu>

[posted and mailed]

Kees Hendrikse wrote:
> 
> In <Er3MzG.HE@world.std.com> aml@world.std.com (Andrew M. Langmead) writes:
> 
> > push @output, $line;
> > shift @output if @output > 20;
> > print @output;
> 
> Thanks, this idea was just what I needed. To make it work, you have to
> take into account the length of the lines, as $#output increases by
> the length of $line, not by 1.

Umm, no it doesn't  $#output will always be the index of the last element in
@output.  It has nothing to do with the lengths of the elements in @output.

Whereever did you get this odd idea?

> Luckily, my lines are all of equal length,
> so this works fine:
>         $length = 73;
>         $tail = 10;
>         push @output, $line;
>         shift @output while @output > $length * $tail;

Are you sure you're not pushing the characters onto @output individually?

-- 
 _ / '  _      /         - aka -             rjk@coos.dartmouth.edu
( /)//)//)(//)/(    Ronald J. Kimball           chipmunk@m-net.arbornet.org
    /                                   http://www.ziplink.net/~rjk/
        "It's funny 'cause it's true ... and vice versa."


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

Date: Thu, 09 Apr 1998 19:29:18 -0500
From: fl_aggie@thepentagon.com (I R A Aggie)
Subject: Re: Week of Month
Message-Id: <fl_aggie-0904981929190001@aggie.coaps.fsu.edu>

In article <01bd63ff$2bc9d5e0$053763c3@dns.btinternet.com>, "Duncan
Cameron" <dcameron@nospam.bcs.org.uk> wrote:

+ Brian
+ 
+ If all you want is days 1-7 to be week 1, days 8-14 to be week 2 etc then,
+ in a non-Perl language with integer arithmetic, you want:

+ $week = int(($day - 1) / 7) + 1;

Nah, that doesn't help the problem. Example:

   June 1998
 S  M Tu  W Th  F  S
    1  2  3  4  5  6   #week 1
 7  8  9 10 11 12 13   #week 2
14 15 16 17 18 19 20   #week 3
21 22 23 24 25 26 27   #week 4
28 29 30               #week 5

$day=28;
$week = int(($day - 1) / 7) + 1;
print "Day $day is in week $week\n";

Result: Day 28 is in week 4

Not quite...but my brain is too fried at the moment to come up with
a complete solution. However, your formulation *is* correct if the first
falls on a Sunday.

Hmmm...if you know the day of the week (DOTW) for the first, you can
figure out what the following Sunday's numeric value is. Once you know
the Sundays, then everything prior to that first Sunday is in week one,
the days of $sunday[1]+6; is in week two, $sunday[2]+6 is week 3, 
$sunday[3]+6 is week 4, and $sunday[4]+6 {less than or equal to 
(28|29|30|31)}.

Twould appear that there are 4 Sundays in every month, with most months
having days spread out over 5 weeks. The only exception is a non-leap
year February that starts on a Sunday -- 4 weeks exactly.

There's a basic algorithm. I'll leave it to someone more motivated to
code it up...

James

-- 
Consulting Minister for Consultants, DNRC
The Bill of Rights is paid in Responsibilities - Jean McGuire
To cure your perl CGI problems, please look at:
<url:http://www.perl.com/CPAN-local/doc/FAQs/cgi/idiots-guide.html>


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

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 2287
**************************************

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