[6511] in Perl-Users-Digest
Perl-Users Digest, Issue: 136 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Mar 18 00:17:26 1997
Date: Mon, 17 Mar 97 21:00:22 -0800
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Mon, 17 Mar 1997 Volume: 8 Number: 136
Today's topics:
Re: [HELP] !@#$% sort subroutines... <rootbeer@teleport.com>
[Q] for loop - making multiple arrays <chchee@hercules.iti.gov.sg>
Re: [Q] userid in a client/server environment <rootbeer@teleport.com>
Re: Am I hosed? (Can't compile modules) (Danny Aldham)
ANNOUNCE: MailFolder-0.05 (Kevin Johnson)
Re: AntiSPAM is as bad as SPAM (was Can you help me wit (I R A Aggie)
Re: Basic $ENV questions (I R A Aggie)
Re: Calling html headers and footers (Dan Sumption)
Re: cgi-lib.pl <rootbeer@teleport.com>
help needed, PERL+FORMS <zrnaqvi@mailbox.syr.edu>
Re: help needed, PERL+FORMS <OperaGhost@NetTown.com>
Re: Help with Pattern Matching (Clay Irving)
Help <paul@flinet.com>
Re: HELP: delete and chmod file with perl (Tad McClellan)
I must be misunderstanding packages... enlighten me? (Michael T Decerbo)
Re: I must be misunderstanding packages... enlighten me <dbenhur@egames.com>
Re: IEEE arithmetic and exceptions <rootbeer@teleport.com>
Re: inheritance with hash variables <merlyn@stonehenge.com>
Re: Multiple substitutions (Michael Schuerig)
Re: Newbie Perl question (Tad McClellan)
Re: Odd behavior with numbers <dbenhur@egames.com>
Re: Perl Compiler (Clay Irving)
Re: Q: How can I read the full pathname <rootbeer@teleport.com>
Regex problem <pagib@aur.alcatel.com>
Re: simple glob fails under Linux <rootbeer@teleport.com>
Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Mon, 17 Mar 1997 20:27:54 -0800
From: Tom Phoenix <rootbeer@teleport.com>
To: Vladimir Alexiev <vladimir@cs.ualberta.ca>
Subject: Re: [HELP] !@#$% sort subroutines...
Message-Id: <Pine.GSO.3.96.970317202443.21931M-100000@kelly.teleport.com>
On 16 Mar 1997, Vladimir Alexiev wrote:
> In article <Pine.GSO.3.95q.970314192555.11801F-100000@linda.teleport.com> Tom Phoenix <rootbeer@teleport.com> writes:
>
> > Start with '0..$#_'. That's a list of the indices of the @_ array.
>
> Hey, shouldn't this be 0..$#_-1 ? We novices already have hard enough time
> with perl :-)
Apparently so. $#{array name} is the last array index of @{array name}.
Did it not work for you when you tried it before you posted? :-)
-- Tom Phoenix http://www.teleport.com/~rootbeer/
rootbeer@teleport.com PGP Skribu al mi per Esperanto!
Randal Schwartz Case: http://www.lightlink.com/fors/
------------------------------
Date: Tue, 18 Mar 1997 09:53:18 +0800
From: Benny Chee <chchee@hercules.iti.gov.sg>
Subject: [Q] for loop - making multiple arrays
Message-Id: <Pine.SOL.3.91.970318094638.1347B-100000@hercules.iti.gov.sg>
Hi,
I m trying to make muiltiple mutually independent arrays
using for loops, but was unsuccessful.
I need this output:
@num1=("$string[1]","$string[2]");
@num2=("$string[3]","$string[4]");
@num4=("$string[5]","$string[6]");
...
...
...
and so on till about @num20.
how can i write a for loop which can allow me to
create arrays (@num$i) by looping?
I know this can't work but my concept is :
for ($i=0;$i<20;$i++){
@num$i = ("$string[$i]","$string[$i+1]");
}
Benny Chee :) | "I used to have a life,
chchee@iti.gov.sg | but now I have a modem."
------------------------------
Date: Mon, 17 Mar 1997 20:09:33 -0800
From: Tom Phoenix <rootbeer@teleport.com>
To: Tan Tran <ttran@micro.ti.com>
Subject: Re: [Q] userid in a client/server environment
Message-Id: <Pine.GSO.3.96.970317195734.21931I-100000@kelly.teleport.com>
On 16 Mar 1997, Tan Tran wrote:
> I have a server process (owned by a particular useid) running on a
> remote host. The client process is invoked (by another userid) that
> communicates with the server via TCP/IP socket. The client sends a
> command to the server to be executed.
>
> My question is how can I make the server execute the command from the
> client using the userid of the person invoking the client process ?
>
> Is there any "su"-like function in perl ?
Well, yes... but how can you be sure that the person on the other end of
the TCP connection is who they say they are? And do you really want your
server process to be able to impersonate _any_ user? This has the
potential to be a major security hole!
One way to do what you ask would be for the client to send three items:
the request, a username, and a password. The server would then hand those
over to a process which is setuid to root, possibly after some initial
screening.
The suid process needs to be very careful. It initially doesn't know
whether it can trust the information it has been given. First, it should
check the username/password to see whether they are valid for a (non
root!) user who should be allowed this service. If they aren't, it should
refuse the operation (of course!) and inform the server, which can then
respond to the client. (Note that the suid process does not need to verify
that the message came from a trusted host, or even that it came in over a
TCP connection.)
If the username & password check out, the suid process can relinquish its
privileges and "become" that user. Now things are much safer, but it still
should probably scrutinize the request before completing it for the user.
Some folks may suggest making the server setuid root, rather than
requiring an external program. This is dangerous, because you don't want
your server having privileges that it doesn't absolutely require. This
way, you keep the privileged program simpler, and thus less likely to have
errors which could lead to security problems.
Hope this helps!
-- Tom Phoenix http://www.teleport.com/~rootbeer/
rootbeer@teleport.com PGP Skribu al mi per Esperanto!
Randal Schwartz Case: http://www.lightlink.com/fors/
------------------------------
Date: 17 Mar 1997 17:35:50 -0800
From: danny@hendrix.postino.com (Danny Aldham)
Subject: Re: Am I hosed? (Can't compile modules)
Message-Id: <5gkrhm$qfp@hendrix.postino.com>
Ross Carlson (webmaster@metacraft.com) wrote:
: I have an SGI Indy Webforce workstation that came very
: bare bones, and without the SGI developer's package.
: As a result, I have no compiler! (ARGH)
: Lately I have been trying to make use of some of the
: perl modules on CPAN, and it seems that they need to
: be compiled. Am I hosed?
No, most of the Perl modules do not need to be linked into
the perl executable. For those that do, you are hosed. For
the rest it may just be a matter of manually putting the modules
into the correct directories. Or , I seem to recall a perl
version of Make that might do this for you.
: The other deal is that I would like the log parsing scripts
: to be able to run on a Windows 95 machine if possible.
There is an NT version of perl. Check at www.hip.com .
Danny Aldham
------------------------------
Date: 18 Mar 1997 03:27:52 GMT
From: kjj@primenet.com (Kevin Johnson)
Subject: ANNOUNCE: MailFolder-0.05
Message-Id: <5gl23o$bkk$1@nadine.teleport.com>
Keywords: perl mail
The newest version (0.05) of the Mail::Folder module has been posted to
CPAN under my author id (KJOHNSON) and name (Kevin_Johnson).
Mail::Folder provides a perl module interface to email folders that is
independent from the physical folders. The actual work on folders is
done with folder interface modules lying 'beneath' the Mail::Folder
interface.
The module is in still alpha release. Think twice about using it to
modify folders that you consider important (at the very least make
backup copies :-). That being said, I'll mention that I use it as the
sole interface to my email at home.
The method interface is currently in an evaluation phase. Before it
goes to beta, I expect to make method interfaces changes that won't be
backwards compatible.
The current version has been tested against 5.003_24 or newer.
Here are some of the more notable new features and unmalfeatures added
since the last release:
+ Big improvements in the maildir (ala qmail) folder interface.
Sorry, the first whack at it was a botch.
+ Added get_mime_header and get_mime_message methods.
+ The beginnings of an NNTP folder interface.
+ An MUA based on pTk in the examples directory.
+ Various bug fixes, cleanups, and optimizations.
Refer to the provided README file for additional information.
I am keenly interested in feedback from folks doing interesting stuff
with the package.
Please report any bugs/suggestions to <kjj@pobox.com>.
Copyright (c) 1996-1997 Kevin Johnson <kjj@pobox.com>
All rights reserved. This program is free software; you can
redistribute it and/or modify it under the same terms as Perl itself.
--
thx,
kjj@pobox.com http://www.pobox.com/~kjj/
------------------------------
Date: Mon, 17 Mar 1997 12:34:27 -0500
From: fl_aggie@hotmail.com (I R A Aggie)
Subject: Re: AntiSPAM is as bad as SPAM (was Can you help me with this script?)
Message-Id: <fl_aggie-ya02408000R1703971234270001@news.fsu.edu>
In article <332D6099.3F54@hendel.mko.dec.com>, John M Chambers
<jc@hendel.mko.dec.com> wrote:
[about netscape]
+ They know better than an idiot
+ like me what the headers should look like, you know,
This netscape we're talking about...
They brought us such gems as [in no particular order]:
0. HTML standards? we don't need no stinkin' standards!
1. HTML posts to Usenet. See standards comment in 0.
2. JavaScript.
3. Multiple [re]postings of an article because the user keeps banging on
the submit button.
They wouldn't know a standard if it walked up and said 'hi'.
James - don't get me started on 'em...
--
Consulting Minster for Consultants, DNRC
To cure your perl CGI problems, please look at:
<url:http://www.perl.com/perl/faq/idiots-guide.html>
------------------------------
Date: Mon, 17 Mar 1997 12:55:42 -0500
From: fl_aggie@hotmail.com (I R A Aggie)
Subject: Re: Basic $ENV questions
Message-Id: <fl_aggie-ya02408000R1703971255420001@news.fsu.edu>
In article <01bc2d6b$da39c160$c74bb0cf@proach>, "Peter W. Roach"
<proach@cais.com> wrote:
+ Tom,
+ Re: "There aren't any more. I promise.." I am not so sure. I am running
+ PERL on Win95 to run CGI scripts for Microsoft Personal Web Server. When I
+ try this routine in a CGI script called via the server, I only get the
+ environment variables already referenced by the program. If I don't
+ reference $ENV{'HTTP_USER_AGENT'}, for instance, then that variable is not
+ listed by the "foreach" routine. Strange! Any ideas?
Because it isn't being set by your server!!
If you do:
print "User agent is: $ENV{'HTTP_USER_AGENT'}\n";
yes, you will get an entry. If the value is set to something, say
'Mozilla/2.0', then you'll get:
User agent is: Mozilla/2.0
But if the value is unset ('undef' in perl terms), then you'll get:
User agent is:
What's so difficult about this? if it's set, the foreach-loop Tom C.
told you about will find it. If it is not set, then no, the foreach-loop
will not find it BECAUSE IT DOESN'T EXIST. Just because you want to use a
particular environmental variable in a CGI program doesn't guarantee that
it will be made available.
James
--
Consulting Minster for Consultants, DNRC
To cure your perl CGI problems, please look at:
<url:http://www.perl.com/perl/faq/idiots-guide.html>
------------------------------
Date: Tue, 18 Mar 1997 00:53:37 GMT
From: dan@gulch.demon.co.uk (Dan Sumption)
Subject: Re: Calling html headers and footers
Message-Id: <332ecd6c.12783101@news.demon.co.uk>
On Sat, 15 Mar 1997 11:55:47 -0500, Bergy <webdesign@abacom.com>
wrote:
>I want to print an html response to a perl5 script and I would like to
>use .html files instead of placing 100% of the code in my source (icons
>bar and header...).
>
>I dont remeber the piece of code that could do this...
Something like this is one of the few useful functions I keep
stashed in a separate file which is require'd by pretty much all
my perl scripts. The only difference is, this code also does
variable interpolation - so if your html file has something like
'$myemail' in it, then it'll be replaced with the contents of the
variable $myemail. The code, which is adapted from something by
Bill Weinman (I think) goes:
sub inc_html
{
local ($filename) = shift;
local ($temptext) = '';
open(SCREEN, "<$filename") || print("cannot open
$filename<br>\n");
while (<SCREEN>)
{
s|\@|\\\@|;
s|\[|\\\[|;
$temptext .= (eval "qq\xa6$_\xa6");
}
close SCREEN;
return $temptext;
}
If you call &inc_html(filename.html) it will return a variable
containg the entire (variable-interpolated) text - to get it to
print it straight out, just remove the references to $temptext
and change
$temptext .= (eval "qq\xa6$_\xa6");
to
print (eval "qq\xa6$_\xa6");
(I like getting it back as a variable 'coz then I can do more
processing on it if necessary).
-------------------------------------------------------------------
Dan Sumption : dan@gulch.demon.co.uk
Hard Media, London SE1 dan@hardnet.co.uk
-------Yell/.net award winners-------
Home (meow!): http://www.hardnet.co.uk/dan/
Work (mooo!): http://www.hardnet.co.uk/
------------------------------
Date: Mon, 17 Mar 1997 20:13:36 -0800
From: Tom Phoenix <rootbeer@teleport.com>
To: Matthew Stich <mstich@erols.com>
Subject: Re: cgi-lib.pl
Message-Id: <Pine.GSO.3.96.970317201232.21931J-100000@kelly.teleport.com>
On Sun, 16 Mar 1997, Matthew Stich wrote:
> Subject: cgi-lib.pl
Use CGI.pm instead. You'll be happier and live longer. :-)
> Do all the files in your cgi-bin have to begin with "cgi-bin"?
See your server's manual.
Hope this helps!
-- Tom Phoenix http://www.teleport.com/~rootbeer/
rootbeer@teleport.com PGP Skribu al mi per Esperanto!
Randal Schwartz Case: http://www.lightlink.com/fors/
------------------------------
Date: Mon, 17 Mar 1997 21:02:51 -0500
From: "Zahid R. Naqvi" <zrnaqvi@mailbox.syr.edu>
Subject: help needed, PERL+FORMS
Message-Id: <Pine.SOL.3.95.970317205207.7234B-100000@rodan.syr.edu>
I am doing a project where I collect user suggestions through a form and
keep saving each form in a file(say a.txt). Each new suggestion is
appended to a.txt, separated by 20 *s. Now I want to edit a.txt and do
some actions. I do this through a PERL script, where I create a form which
reads the first record from a.txt, I edit this form and then "submit" it.
After I submit I want to read the next record from a.txt, this is where I
am stuck. How do I sort of "reset" the form so that it reads the next
record from a.txt. Although I have the form creating code in a loop but I
never get out of the first form I create.
How can I do this in HTML or PERL or JavaScript.
thanks in advance
Zahid
------------------------------
Date: Mon, 17 Mar 1997 21:43:17 +0000
From: Opera Ghost <OperaGhost@NetTown.com>
Subject: Re: help needed, PERL+FORMS
Message-Id: <332DBAF5.24A228DA@NetTown.com>
http is a stateless protocol, ergo
if u want sequential records from a.txt
you have to save it in the page...
via a...hidden tag!
ie
input type=hidden name=thisRecNum value=0
in angle brackets.(><)
the below may not work on some browsers, actual tag:
<input type=hidden name=thisRecNum value=0>
i guess u could use name=nextRecNum and value=1!
and ur server side perl script will get this hidden tag on a submit,
and do the right thing (watch them rollovers and unders :-)
or, if random is what u want,
use a textfield
and be sure and use CGI.pm! (for its stickyness!)
--
(hope i answered the right question?)
------------------------------
Date: 17 Mar 1997 20:43:36 -0500
From: clay@panix.com (Clay Irving)
Subject: Re: Help with Pattern Matching
Message-Id: <5gks08$clu@panix.com>
In <332DAAE6.4F14@toy.mem.ti.com> "M. Wick" <mwick@toy.mem.ti.com> writes:
>I've tried grep, index, and the matching sequence and nothing seems to
>be working. I'm opening a file, reading in a line, and trying to
>match a pattern from within the line. I have found that I can match
>the line if the parameter starts at the beginning on the line. I want
>to find the pattern in the middle of the line, and nothing seems to be
>working correctly.
>while( <FILE> ){
> if ( (index($_, $pattern)) >= 0 ) {
> if (grep($pattern, $_) != 0) { (even though grep works on an array,
> I still tried it)
> if (/$pattern/) { (matching on the $_ from the file)
> do this stuff if match;
> }
>}
>I've tried all 3 possibilities.
>Here are the lines that I'm looking at:
>NAME <-- Works fine here
><LI><A HREF="http://..../">NAME</A> <-- Doesn't match this line
>I'm trying to find NAME. Any suggestions?
I betcha it has something to do with those meta-characters in the second
example -- Maybe you need to quote 'em?
--
Clay Irving See the happy moron,
clay@panix.com He doesn't give a damn,
http://www.panix.com/~clay I wish I were a moron,
My God! Perhaps I am!
------------------------------
Date: Mon, 17 Mar 1997 06:37:43 -0500
From: Paul <paul@flinet.com>
Subject: Help
Message-Id: <332D2D07.3A59@flinet.com>
I am writing a program that creates a html page.
There is a text area that I set up to remove carriage returns and
replace with line breaks "<br>". The preview page I have , it works
great but when it writes to the actual html page the breaks <br> are
ignored.
Looking for program to print on html page something like the
following....
test<br>test<br>test
all I get written is "testtesttest" or just "test" and rest of text is
dropped...
I have tried all the quotation marks and stuff but still overlooking
something.
------------------------------
Date: Mon, 17 Mar 1997 17:37:42 -0600
From: tadmc@flash.net (Tad McClellan)
Subject: Re: HELP: delete and chmod file with perl
Message-Id: <6kkkg5.g44.ln@localhost>
Steven Sajous (steve@golf.com) wrote:
: You can use require "COMMAND";
: for both tasks, e.g:
: require "rm *.htm";
: require "chmod +x *.pl";
^^^^^^^^^^^^^^^^^^^^^^^^
Huh?
Have you tried that?
It won't work...
: On Sat, 15 Mar 1997 15:44:26 +0000, george <jalbertl@ere.umontreal.ca>
: wrote:
: >I need some help...
: >
: >How I should do to make my perl script to delete a file (like the rm
: >command) and how I could make my script to chmod a file.
: >
: >Thanks in advance,
: >
: >George.
--
Tad McClellan SGML Consulting
Tag And Document Consulting Perl programming
tadmc@flash.net
------------------------------
Date: 17 Mar 1997 23:07:55 GMT
From: mike@athena.mit.edu (Michael T Decerbo)
Subject: I must be misunderstanding packages... enlighten me?
Message-Id: <5gkisb$hu9@senator-bedfellow.MIT.EDU>
Hi everyone,
I wonder if someone can explain why it seems that my subroutines are
being called in one package, but executed in package main. Perhaps I
am missing something?
Here's the big picture. I have an array of references to hashes, and I
want to select a bunch of those hashes and put them in a new array.
The way I want to select them is by evaluating an expression which
uses the keys of each hash as a variable. In other words, if my
expression reads
($id eq "foo")
then I want to switch to a clean package, and set $id to
$$hashref{'id'}. Then I can evaluate the expression above, and decide
whether to push $hashref onto the array of selected hashrefs.
The thing I don't understand is that the following doesn't do what I expect.
Having defined (in package main), and using Perl 5.003:
sub import_vars_from_hashref_keys {
my ($hashref) = $_[0];
while (($key, $value) = each %$hashref) {
$$key = $value;
}
}
...I someplace do (within another sub, inside package main, if it matters):
foreach $hashref (@hashref_ary) {
printf "hashref's id is [%s]\n", $hashref->{'id'};
package temp;
&main::import_vars_from_hashref_keys($main::hashref);
print "temp::id is $temp::id\t";
print "main::id is $main::id\t";
print "id is $id\n";
[...other code...]
}
...but $temp::id does not get set; instead $main::utt_id does! The result is:
hashref's id is [wa15]
temp::utt_id is main::utt_id is wa15 utt_id is
However, if I just cut 'n' paste the body of import_vars_from_hashref_keys,
everything works as I'd expect:
foreach $hashref (@hashref_ary) {
printf "hashref's id is [%s]\n", $hashref->{'id'};
package temp;
while (($key, $value) = each %$main::hashref) {
$$key = $value;
}
print "temp::id is $temp::id\t";
print "main::id is $main::id\t";
print "id is $id\n";
[...other code...]
}
...and I in fact get:
hashref's id is [wa15]
temp::utt_id is wa15 main::utt_id is utt_id is wa15
Now, the 2nd ed. camel book says (p. 279):
The scope of a package declaration is from the declaration
itself through the end of the innermost enclosing block (or
until another package declaration at the same level, which
hides the earlier one).
This behavior sorta seems to contradict this statement, unless you're
exiting the block when you call a subroutine. Is this the case?
Would I have had to have defined sub import_vars_from_hashref_keys
inside package temp in order to get the effect I wanted?
If so, is there any way to define a subroutine to do what I was trying
to do, namely, read the keys of a hash and set variables with the same
name in any given package?
Thanks for reading this and even more if you can answer.
Mike
--
Michael Decerbo --- mike@mit.edu
------------------------------
Date: Mon, 17 Mar 1997 19:15:11 -0800
From: Devin Ben-Hur <dbenhur@egames.com>
To: Michael T Decerbo <mike@athena.mit.edu>
Subject: Re: I must be misunderstanding packages... enlighten me?
Message-Id: <332E08BF.341F@egames.com>
[mail&post]
Michael T Decerbo wrote:
> Having defined (in package main), and using Perl 5.003:
> sub import_vars_from_hashref_keys {
> my ($hashref) = $_[0];
> while (($key, $value) = each %$hashref) {
> $$key = $value;
> }
> }
> ...I someplace do (within another sub, inside package main, if it matters):
> foreach $hashref (@hashref_ary) {
> printf "hashref's id is [%s]\n", $hashref->{'id'};
> package temp;
> &main::import_vars_from_hashref_keys($main::hashref);
> print "temp::id is $temp::id\t";
> print "main::id is $main::id\t";
> print "id is $id\n";
> [...other code...]
> }
> Now, the 2nd ed. camel book says (p. 279):
>
> The scope of a package declaration is from the declaration
> itself through the end of the innermost enclosing block (or
> until another package declaration at the same level, which
> hides the earlier one).
>
> This behavior sorta seems to contradict this statement, unless you're
> exiting the block when you call a subroutine. Is this the case?
Looks like you kinda enlightened yourself here.
The subroutine has its own package scope (in your case
"main"). If you want the subroutine to use a different
package scope, define it that way. Package scope is
lexical not dynamic, so a subroutine doesn't inherit
the package of its caller.
> Would I have had to have defined sub import_vars_from_hashref_keys
> inside package temp in order to get the effect I wanted?
exactly.
> If so, is there any way to define a subroutine to do what I was trying
> to do, namely, read the keys of a hash and set variables with the same
> name in any given package?
Sure, pass the package name as a paramter and compose
a fully qualified reference in your symbolic assignment.
eg (untested):
sub import_vars_from_hashref_keys {
my ($hashref,$pck) = @_;
while (($key, $value) = each %$hashref) {
${"$pck::$key"} = $value;
}
}
import_vars_from_hashref_keys( \%myhash, "temp" );
HTH
--
Devin Ben-Hur <dbenhur@egames.com>
eGames.com, Inc. http://www.egames.com/
eMarketing, Inc. http://www.emarket.com/
"Sometimes you just have to step in it and see if it stinks" O-
-- Sonia Orin Lyris
------------------------------
Date: Mon, 17 Mar 1997 20:19:45 -0800
From: Tom Phoenix <rootbeer@teleport.com>
To: Bob Walton <walton@frontiernet.net>
Subject: Re: IEEE arithmetic and exceptions
Message-Id: <Pine.GSO.3.96.970317201620.21931K-100000@kelly.teleport.com>
On Sun, 16 Mar 1997, Bob Walton wrote:
> Is there any way of getting Perl to generate Inf and NaN
> values and suppress the error messages for division by zero
> and domain errors in built-in functions? Thank you.
Hmmm.... This could become a 'use ieee;' pragma. But there's a pesky
scoping problem: How can you make my module use ieee if I didn't think
about it when I wrote it? This might happen, if it won't break too many
things. Any ideas what would break? Do you want to make a patch and
find out? :-)
-- Tom Phoenix http://www.teleport.com/~rootbeer/
rootbeer@teleport.com PGP Skribu al mi per Esperanto!
Randal Schwartz Case: http://www.lightlink.com/fors/
------------------------------
Date: 17 Mar 1997 20:32:40 -0700
From: Randal Schwartz <merlyn@stonehenge.com>
Subject: Re: inheritance with hash variables
Message-Id: <8cenddg9if.fsf@gadget.cscaper.com>
>>>>> "Eric" == Eric Marc Mcmillan <emcmilla@cps.msu.edu> writes:
Eric> I am trying to do inheritance using anonymous hash to hold
Eric> instance variables. Inheritance doesn't seem to be working
Eric> the way I implement it. If I don't use anonymous hash to hold
Eric> the instance variables it works fine. I have a small snippit
Eric> of code that I thought should work. The code is in three separate
Eric> files:
Eric> package main;
Eric> require derived;
Eric> $a = Derived->new(pid => 999);
Eric> print "pid = ", $a->{pid}, "\n";
Eric> ============================================
Eric> package Base;
Eric> sub new {
Eric> my $type = shift;
Eric> my %param = @_;
Eric> my $self = {};
Eric> $self->{pid} = $param{pid};
Eric> return bless $self, $type;
Eric> }
Eric> 1;
Eric> ==============================================
Eric> package Derived;
Eric> use Base;
Eric> @ISA = qw( Base );
Eric> sub new {
Eric> my $type = shift;
Eric> my $self = Base->new;
You aren't passing any parameters to new! How could it get a pid =>
whatever here?
Eric> return bless $self, $type;
Eric> }
Eric> 1;
Eric> =============================================
Eric> Is there something I'm not implementing correctly?
Yes. Definitely. I don't even know why you have a "new" routine in
Derived. :-) It would have worked had you removed it.
print "Just another Perl hacker," # but not what the media calls "hacker!" :-)
## legal fund: $20,495.69 collected, $182,159.85 spent; just 532 more days
## before I go to *prison* for 90 days; email fund@stonehenge.com for details
--
Name: Randal L. Schwartz / Stonehenge Consulting Services (503)777-0095
Keywords: Perl training, UNIX[tm] consulting, video production, skiing, flying
Email: <merlyn@stonehenge.com> Snail: (Call) PGP-Key: (finger merlyn@ora.com)
Web: <A HREF="http://www.stonehenge.com/merlyn/">My Home Page!</A>
Quote: "I'm telling you, if I could have five lines in my .sig, I would!" -- me
------------------------------
Date: Tue, 18 Mar 1997 03:50:43 +0100
From: uzs90z@uni-bonn.de (Michael Schuerig)
Subject: Re: Multiple substitutions
Message-Id: <19970318035043293147@rhrz-ts2-p1.rhrz.uni-bonn.de>
Eric Bohlman <ebohlman@netcom.com> wrote:
> Michael Schuerig (uzs90z@uni-bonn.de) wrote:
>
> : I'm trying to do multiple substitutions in a file without iterating over
> : an array of old-new pairs. I had a look at the FAQ and read the thread
> : in this group about matching multiple patterns, but it wasn't of much
> : help to me. Apparently the problem is in the eval below. Can anyone give
> : me an idea of what I'm doing wrong?
>
> [snip]
> : $replacements .= "\$ln=s/$key/$value/go;";
>
> You want "...ln=~s...
>
> Remember that $scalar=s/old/new/ performs substitution on $_ and sets
> $scalar to the number of times the substitution took place (which will be
> 0 or 1 unless there's a g modifier on the s), whereas $scalar=~s/old/new/
> performs substitution on $scalar.
Yes, I see, the scales are falling from my eyes.
> 'tis a good idea to get ahold of the Camel book and read the section on
> regular expressions and matching several times (do something else in
> between the readings; otherwise your brain won't absorb everything).
Believe it or not, but I have the Camel book, first & second edition.
And I've even done some perl scripting recently. The thing is, I'm not
using perl regularly, only every now and then, to solve a problem that I
find it suitable for.
Michael
---
Michael Schuerig Failures to use one's frontal lobes can
mailto:uzs90z@uni-bonn.de result in the loss of them.
http://www.uni-bonn.de/~uzs90z/ -William H. Calvin
------------------------------
Date: Mon, 17 Mar 1997 19:51:07 -0600
From: tadmc@flash.net (Tad McClellan)
Subject: Re: Newbie Perl question
Message-Id: <beskg5.pl4.ln@localhost>
Unknown (zgeist@ee.net) wrote:
: Greetings all -
: I am trying to run an SQL script via my Perl script but it does not
: seem to be working. I started out using the MAIL example in the Learning
: Perl book (pg 23) using "open" and "print", but that is not working.
: I have something along the lines of
: open (ORASTUFF,"|sqlplus username/password ");
: print ORASTUFF "\@test.sql\n";
You are sending ten characters to the sqlplus thingie. What is
it _supposed_ to do when it gets: an 'at' sign, followed by a 't',
followed by a 'e', followed by 's' ...
Did you mean to send it the contents of an array named @test.sql
or something?
Where did array @test.sql get filed with some values?
: close (ORASTUFF);
: I did get it to work by using the following:
: $dummy = `sqlplus username/password < test.sql `;
Oh. It now appears that you want to send the contents of
_a file_ to the sqlplus?
What is it that you want to do?
: print "Dummy is $dummy";
: Yeah, I know this is horrible, but I cannot get the filehandle to work
: properly above.
You haven't really told us what you want to do. So I'll have to guess.
You want to open the sqlplus thingie, and send one line at a time
from a file named 'test.sql':
# read all the lines from test.sql
open(FILE, "test.sql") || die "could not open 'test.sql' $!";
@test_sql = <FILE>;
close(FILE);
# send them one at a time to sqlplus
open (ORASTUFF,"|sqlplus username/password ");
foreach (@test_sql) {
print ORASTUFF $_;
}
close(ORASTUFF) || die "Uh oh! Something bad happened...";
: If you can point me to a more detailed part of either volume of
: "Programming Perl" or "Learning PERl" that would be great.
A more detailed explanation of what you want to do would have
been helpful to getting the correct answer...
--
Tad McClellan SGML Consulting
Tag And Document Consulting Perl programming
tadmc@flash.net
------------------------------
Date: Mon, 17 Mar 1997 17:49:28 -0800
From: Devin Ben-Hur <dbenhur@egames.com>
To: "Nicholas J. Leon" <nicholas@neko.binary9.net>
Subject: Re: Odd behavior with numbers
Message-Id: <332DF4A8.A01@egames.com>
[mail&post]
Nicholas J. Leon wrote:
> print "a is $a.\n";
> $a-=.1;
> print "a is $a.\n";
> $a-=.1;
> print "a is $a.\n";
> $a-=.1;
> print "a is $a.\n";
> a is 0.2.
> a is 0.1.
> a is -2.77555756156289e-17.
> a is -0.1.
Not suprising it all. Perl does its numeric
calculations in floating point and you are repeatedly
subtracting 0.1 which has no finite precision
representation in binary (just like 1/3 is 0.33333... in
decimal, 1/10 is a repeating fraction in binary).
when you get near 0.0, you really get an enormously small
number (almost zero) and Perl's default print algorithm
prints the scientific notation you see.
If you want better control of the output, use [s]printf.
This isn't much different than the floating point
arithmetic and display issues you'll encounter in
any other language.
--
Devin Ben-Hur <dbenhur@egames.com>
eGames.com, Inc. http://www.egames.com/
eMarketing, Inc. http://www.emarket.com/
"Sometimes you just have to step in it and see if it stinks" O-
-- Sonia Orin Lyris
------------------------------
Date: 17 Mar 1997 20:34:26 -0500
From: clay@panix.com (Clay Irving)
Subject: Re: Perl Compiler
Message-Id: <5gkrf2$b2h@panix.com>
In <332d9693.3914652@news1.alterdial.uu.net> steve@golf.com (Steven Sajous) writes:
>Does anyone know where I can find a Perl compiler, and have any
>instr5uctions on how to use one?
Check:
http://www.perl.com/CPAN/authors/Malcolm_Beattie/
Specifically, these files:
Compiler-a3.readme
Compiler-a3.tar.gz
--
Clay Irving See the happy moron,
clay@panix.com He doesn't give a damn,
http://www.panix.com/~clay I wish I were a moron,
My God! Perhaps I am!
------------------------------
Date: Mon, 17 Mar 1997 20:37:26 -0800
From: Tom Phoenix <rootbeer@teleport.com>
To: Russ Allbery <rra@cs.stanford.edu>
Subject: Re: Q: How can I read the full pathname
Message-Id: <Pine.GSO.3.96.970317203523.21931O-100000@kelly.teleport.com>
On 17 Mar 1997, Russ Allbery wrote:
> To handle the recursion on multiple directories, you can either test
> each file in the directory with -d and recurse yourself if it's a
> directory,
Eek! Don't forget symbolic links! Any "directory" might be a symlink
to, say, the root directory. This could make recursion quite time
consuming!
> or you can use File::Find.
That's better. :-)
-- Tom Phoenix http://www.teleport.com/~rootbeer/
rootbeer@teleport.com PGP Skribu al mi per Esperanto!
Randal Schwartz Case: http://www.lightlink.com/fors/
------------------------------
Date: Mon, 17 Mar 1997 16:30:56 -0500
From: Bruno Pagis <pagib@aur.alcatel.com>
Subject: Regex problem
Message-Id: <332DB810.457F@aur.alcatel.com>
Is there a way to express a number range in a regular
expression. Say, I want to match a string like
CCCC-[1-48] (means 4 C char followed by a - followed by a
number between 1 and 48).
Thanks for your help. BRUNO.
--
-----------------------------------------------------------
Bruno Pagis, ALCATEL Network Systems
__ 2912 Wake Forest road RALEIGH, NC 27609
ALC\/TEL Phone: (919) 850-5174 Fax : (919) 850-6670
Email: bruno_pagis@aur.alcatel.com
http://aurwww.aur.alcatel.com/~pagib
-----------------------------------------------------------
------------------------------
Date: Mon, 17 Mar 1997 20:23:17 -0800
From: Tom Phoenix <rootbeer@teleport.com>
To: Sussex Silversmiths <sussex@interlog.com>
Subject: Re: simple glob fails under Linux
Message-Id: <Pine.GSO.3.96.970317202019.21931L-100000@kelly.teleport.com>
On Mon, 17 Mar 1997, Sussex Silversmiths wrote:
> I can't get directory globbing to work under the August 96 slackware
> distribution of Linux 2.0, Perl 5.003. The following expression yields no
> output in a rather full directory:
A rather full directory, huh? Maybe it's too full. Globbing (currently)
works by calling /bin/csh (usually). If there are too many matches,
though, it can fail. Or so I've heard.
As you pointed out, the workaround is readdir and friends.
On the other hand, maybe your /bin/csh isn't really /bin/csh. Does this
get you any closer to finding the problem? Hope this helps!
-- Tom Phoenix http://www.teleport.com/~rootbeer/
rootbeer@teleport.com PGP Skribu al mi per Esperanto!
Randal Schwartz Case: http://www.lightlink.com/fors/
------------------------------
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 136
*************************************