[9507] in Perl-Users-Digest
Perl-Users Digest, Issue: 3101 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Jul 8 22:07:23 1998
Date: Wed, 8 Jul 98 19: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 Wed, 8 Jul 1998 Volume: 8 Number: 3101
Today's topics:
Re: -- Abigail, Another Observation <dfsdf@ziplink.net>
Re: -- Abigail, Here's an update for you. <tchrist@mox.perl.com>
Re: -w on production code (was Re: better way of gettin <ljz@asfast.com>
Re: -w on production code (was Re: better way of gettin <ljz@asfast.com>
Re: -w on production code (was Re: better way of gettin <rra@stanford.edu>
Re: -w on production code (was Re: better way of gettin (Martien Verbruggen)
Re: Abigail - Another Question for you. (Tad McClellan)
Re: attachment to email (-)
Re: Bar and Line Charts in Perl <tchrist@mox.perl.com>
Can PERL RENAME a user account on an NT workstation? <dontspamme@dontspam.com>
Re: Do I understand this? (Phillip George Geiger)
Re: Do I understand this? (Gabor)
getting hostname and ip addr when you don't have either chrisoc@ans.net
Re: How much space left on disk? (Martien Verbruggen)
Re: How to use 'system ("...")' on WIN32. (Bob Trieger)
Re: manipulate /etc/passwd without expect ?? (Jeremy D. Zawodny)
Re: Need slick code: How to CWD to executable's directo (Craig Berry)
Re: Need slick code: How to CWD to executable's directo (Martien Verbruggen)
Re: NEVER "call warn() and return undef" (Re: question <zenin@bawdycaste.org>
Re: NT Sysadmin scripts (Jeffrey Drumm)
Re: Oh man, DO I love Perl ! (References to things that <zenin@bawdycaste.org>
Re: PERL & mSql help needed <simonf@conduit.co.uk>
Perl and Win NT porting? <cycleman@usouthal.campus.mci.net>
Re: Placeholders in Perl? <simonf@conduit.co.uk>
Resize windows (was: Re: Pod::Text -- Unix only?) (Tom Grydeland)
Re: Searching a file (Craig Berry)
Re: Searching a file (Martien Verbruggen)
Re: Searching a file (Tad McClellan)
Re: Searching a file (Craig Berry)
Splitting a difficult CSV file <mgiles@mindspring.com>
Re: tough regexp - help needed (Craig Berry)
Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Tue, 07 Jul 1998 20:01:04 -0400
From: Webcruiser <dfsdf@ziplink.net>
Subject: Re: -- Abigail, Another Observation
Message-Id: <35A2B6C0.2502@ziplink.net>
Abigail, I did some more analysis by taking the @STATUS variable and
writing it to a file called debug.dta, using the &updatestatus routine
in my program. Up to the point where the code shown below is called, the
debug.dta file shows the file WITHOUT spaces! Once the form code is
called, the @STATUS variable gets screwed up. Here is the code section:
<table border="1" cellpadding="0" cellspacing="0" width="100%"
bgcolor="#89D8FA">
<tr>
<td width="20%" valign="top"><strong><font face="Arial">Account
Status:</font></strong></td>
<td width="80%"><textarea rows="10" name="STATUS"
cols="50">@STATUS</textarea></td>
</tr>
</table>
Only at this point does the @STATUS info get displayed with spaces after
the first line. Of course, unless I delete them out, the info gets saved
that way.
What would be causing this? Is it anything I have control over? At least
I know nothing is wrong with the rest of the PERL code.
Thanks for all your help. I made me look harder at the program to get
this far.
------------------------------
Date: 9 Jul 1998 01:52:22 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: -- Abigail, Here's an update for you.
Message-Id: <6o17om$1hp$1@csnews.cs.colorado.edu>
[courtesy cc of this posting sent to cited author via email]
In comp.lang.perl.misc, Webcruiser <dfsdf@ziplink.net> writes:
: read (STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
That code is wrong.
--tom
--
"Espousing the eponymous /cgi-bin/perl.exe?FMH.pl execution model is like
reading a suicide note -- three days too late."
--Tom Christiansen <tchrist@mox.perl.com>
------------------------------
Date: 08 Jul 1998 20:21:39 -0400
From: Lloyd Zusman <ljz@asfast.com>
Subject: Re: -w on production code (was Re: better way of getting the last modified file?)
Message-Id: <ltk95n7u24.fsf@asfast.com>
On NPGE - V, Randal Schwartz <merlyn@stonehenge.com> writes:
> [ ... ]
>
> If -w ever becomes the default, I'm switching to python.
>
> -w is training wheels. Yes, when I'm writing casual code for long
> term maintenance, I don't mind coding in the narrowed style that -w
> demands. However, for a quick-n-dirty script, -w often makes me add a
> bunch of extra steps that get in my way. Remember, you can't lean
> hard into the corner with training wheels. :)
>
> Just think of it as "two perls in one". :-)
In an earlier message, I wondered if perhaps one of the reasons for
the non-manditoriness and non-defaultness of `-w' might be because of
a possible difference of opinion about it among the Perl developers.
I guess that this is indeed the case.
Your reasons, Randal, make sense to me. What's your opinion about
using `-w' in production Perl code?
--
Lloyd Zusman ljz@asfast.com
perl -e '$n=170;for($d=2;($d*$d)<=$n;$d+=(1+($d%2))){for($t=0;($n%$d)==0;
$t++){$n=int($n/$d);}while($t-->0){push(@r,$d);}}if($n>1){push(@r,$n);}
$x=0;map{$x+=(($_>0)?(1<<log($_-0.5)/log(2.0)+1):1)}@r;print"$x\n"'
------------------------------
Date: 08 Jul 1998 20:53:08 -0400
From: Lloyd Zusman <ljz@asfast.com>
Subject: Re: -w on production code (was Re: better way of getting the last modified file?)
Message-Id: <lthg0r7sln.fsf@asfast.com>
On NPGE - V, abigail@fnx.com (Abigail) writes:
> [ ... ]
>
> Each run is a test, and if it triggers a warning, it means the program
> encountered a (possible dangerous) situation you had not anticipated.
> (Else the warning wouldn't have been triggered).
Consider the following fairly typical usage of the Getopt::Std module:
#!/usr/bin/perl -w
# -*- perl -*-
($program = $0) =~ s:^.*/::;
use Getopt::Std;
unless (Getopt::Std::getopts('a')) {
die "usage: $program [ -a ] ...\n";
}
if (defined($opt_a)) {
handleOptionA();
}
# ... etc. ...
exit(0);
sub handleOptionA {
# whatever
}
__END__
This generates the following warning under `-w':
Name "main::opt_a" used only once: possible typo at testscript line 12.
Sure, this is *potentially* dangerous, but it takes someone who
understands Perl less than a second to realize that in actuality,
there is nothing harmful or dangerous about this particular case at
all.
Of course I could make this warning go away by strategically inserting
a `my $opt_a;', or by making use of the second, hash-reference
argument to `getopts'. And in many cases, I would do that. But there
is no intrinsic advantage in doing so in this particular case,
especially given the fact that removing the very useful, helpful, and
informative `-w' switch after debugging the script is a perfectly
viable option.
> [ ... ]
--
Lloyd Zusman ljz@asfast.com
perl -e '$n=170;for($d=2;($d*$d)<=$n;$d+=(1+($d%2))){for($t=0;($n%$d)==0;
$t++){$n=int($n/$d);}while($t-->0){push(@r,$d);}}if($n>1){push(@r,$n);}
$x=0;map{$x+=(($_>0)?(1<<log($_-0.5)/log(2.0)+1):1)}@r;print"$x\n"'
------------------------------
Date: 08 Jul 1998 18:00:34 -0700
From: Russ Allbery <rra@stanford.edu>
Subject: Re: -w on production code (was Re: better way of getting the last modified file?)
Message-Id: <m3sokb3kjx.fsf@windlord.Stanford.EDU>
Lloyd Zusman <ljz@asfast.com> writes:
> Consider the following fairly typical usage of the Getopt::Std module:
> #!/usr/bin/perl -w
> # -*- perl -*-
> ($program = $0) =~ s:^.*/::;
> use Getopt::Std;
> unless (Getopt::Std::getopts('a')) {
> die "usage: $program [ -a ] ...\n";
> }
[...]
> This generates the following warning under `-w':
> Name "main::opt_a" used only once: possible typo at testscript line 12.
[...]
> Of course I could make this warning go away by strategically inserting
> a `my $opt_a;',
No, you can't, actually. Getopt::Std requires that it be a global, so if
you declare it as a my variable, Getopt::Std will still create a global
behind the scenes which you'll then be unable to access because it will be
masked behind your global.
> or by making use of the second, hash-reference argument to `getopts'.
You have to do this.
> And in many cases, I would do that. But there is no intrinsic advantage
> in doing so in this particular case, especially given the fact that
> removing the very useful, helpful, and informative `-w' switch after
> debugging the script is a perfectly viable option.
Yup. On the other hand, one can also predeclare $opt_a in use vars, which
is what I usually do for this. (I do write -w clean code; I just don't
leave -w on in production because the people who would see the errors will
not benefit from them in the slightest.)
--
#!/usr/bin/perl -- Russ Allbery, Just Another Perl Hacker
$^=q;@!>~|{>krw>yn{u<$$<[~||<Juukn{=,<S~|}<Jwx}qn{<Yn{u<Qjltn{ > 0gFzD gD,
00Fz, 0,,( 0hF 0g)F/=, 0> "L$/GEIFewe{,$/ 0C$~> "@=,m,|,(e 0.), 01,pnn,y{
rw} >;,$0=q,$,,($_=$^)=~y,$/ C-~><@=\n\r,-~$:-u/ #y,d,s,(\$.),$1,gee,print
------------------------------
Date: 9 Jul 1998 01:39:34 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: -w on production code (was Re: better way of getting the last modified file?)
Message-Id: <6o170m$1ai$4@comdyn.comdyn.com.au>
In article <lthg0r7sln.fsf@asfast.com>,
Lloyd Zusman <ljz@asfast.com> writes:
> unless (Getopt::Std::getopts('a')) {
> die "usage: $program [ -a ] ...\n";
> }
>
> if (defined($opt_a)) {
> handleOptionA();
> }
[snip]
> Name "main::opt_a" used only once: possible typo at testscript line 12.
> Of course I could make this warning go away by strategically inserting
> a `my $opt_a;',
That won't work. You'll need use vars qw( $opt_a );
> or by making use of the second, hash-reference
> argument to `getopts'.
You can also switch off the warnings around your getopts part of the
code. I would call this a problem with getopts, not with perl. And I
would even go so far to say that I think that maybe getopts should
never have allowed the silent setting of these variables. It should
enforce the use of a hash or provide access methods to variables
within the package. This behaviour is even worse than having
non-private variables.
But that's a different issue, and a different discussion :)
Martien
--
Martien Verbruggen |
Webmaster www.tradingpost.com.au | For heaven's sake, don't TRY to be
Commercial Dynamics Pty. Ltd. | cynical. It's perfectly easy to be
NSW, Australia | cynical.
------------------------------
Date: Wed, 8 Jul 1998 20:06:46 -0500
From: tadmc@flash.net (Tad McClellan)
Subject: Re: Abigail - Another Question for you.
Message-Id: <6351o6.338.ln@localhost>
Abigail (abigail@fnx.com) wrote:
: Webcruiser (dfsdf@ziplink.net) wrote on MDCCLXXI September MCMXCIII in
: <URL: news:35A2967F.1372@ziplink.net>:
: ++ Please try to address these questions again. Also, now what is still
: ++ causing a leading white space to show up each time?
: ++ http://webcruiser.com/manager/mmadmin.htm
: ++
: ++ >
: ++ > What's the point of this? Have you any idea what
: ++ > @status="New";
: ++ > does?
: ++
: ++ No. Tell me what it does. All I want to do is start off the file with
: ++ the word "New".
That is what it does. (but it is the first element of the array,
no 'file' here yet...)
It is just not apparent that you intended that.
: ++ What is a better way?
See below.
: It makes the array @status equal to ("New"). The array as one element.
So the way to write it so that people can tell that you knew what
you were doing would be any of the below:
@status = ('New'); # see the 'List value constructors' section
# in the perldata man page
@status = qw(New); # see the 'qw/STRING/' entry in the
# perlop man page
push @status, 'New'; # perlfunc describes push()
[ I believe that it is misleading to use double quotes when there
is no interpolation. Single quotes are more appropriate in
that case.
]
: ++ > And
: ++ > $STATUS=@status[0];
: ++ > does something else than you think it does.
: ++ OK, what does this actually do?
: @status [0] is a slice, and it's evaluated in scalar context.
: Since it is a slice with one element, it evaluates to 1.
: $STATUS = 1; is a different way to write the above.
I expect that you need to write it as below, unless you wanted
it to get the value that Abigail pointed out above:
$STATUS=$status[0];
^
^
$ means it is a scalar
@ means that it is an array
--
Tad McClellan SGML Consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Thu, 09 Jul 1998 00:07:54 GMT
From: root.noharvest.\@not_even\here.com (-)
Subject: Re: attachment to email
Message-Id: <35a404ae.9987575@nntp.idsonline.com>
Charles Maier <maierc@chesco.com> Said this:
>Gangadhar Vaddepalli wrote:
>>
>> Hi There,
>> I'm wondering whether we can attach another file to email using Perl.
>> I want to send an attchment which is also an HTML file along with the
>> message.
>>
>
>I typically run on a UNIX system and have tied to figger this too. I
>HAVE read the sendmail manpage (my email interface) and it does not
>explain this very well. Anyone had success with sending atachment(S)
>with sendmail??
>
I'm trying to do just the opposite... pipe incoming mail to a perl
script throug the .forward file, and if it encounters any of the
various encoding methods for file attachements, it should decode and
write the contents to a file. Just as eudora or other clients do, but
on my linux box, with a perl script.
I should think the simplest way to attach a file is to invoke uuencode
inside your perl script prior to the part where you open a pipe to
sendmail, and send uuncode the file to encode, and then place the
resulting uuencoded text into the file.
Here's an excerpt from the manpage for uuencode.
EXAMPLES
The following example packages up a source tree, compresses it,
uuencodes it and mails it to a user on another
system. When uudecode is run on the target system, the file
``src_tree.tar.Z'' will be created which may then
be uncompressed and extracted into the original tree.
tar cf - src_tree | compress | uuencode src_tree.tar.Z | mail
sys1!sys2!user
Obviously, you could do something along the lines of
$encoded_file = `uuencode $file_in final_name`;
#!/usr/bin/perl
$uuencoded = `uuencode web.htm encoded.txt`;
open (MAIL, "|/usr/sbin/sendmail -t");
print MAIL "From: bob\@lmnet.com (Bob) \n";
print MAIL "To: webmaster\@lmnet.com (Webmaster) \n";
print MAIL "Subject: Test Attachment\n";
print MAIL "\n";
print MAIL <<"END_OF_MESSAGE";
Hello, this is a message. I want to send an attachment with it, to see
how that works
END_OF_MESSAGE
print MAIL $uuencoded;
print MAIL "\n";
close MAIL
This script encoded a file in the current directory named web.htm and
sent it to webmaster \@ lmnet . com and I received it as "encoded.txt"
in my windows based mail client.
------------------------------
Date: 9 Jul 1998 00:49:43 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: Bar and Line Charts in Perl
Message-Id: <6o1437$p89$1@csnews.cs.colorado.edu>
[courtesy cc of this posting sent to cited author via email]
In comp.lang.perl.misc, "Jim Babbington" <jwb79@mail.idt.net> writes
using X-Newsreader: Microsoft Internet News 4.70.1155:
(Innumerable bad wraps by a cruddy newsreader deleted.)
:If I could do this with excess, I would run out and give MS my money
:for a copy of excell!!
I sincerely and totally hope you wouldn't get the same quality as the
Gods of Redmond apparently gave you with your "newsreader".
--tom
--
Weinberg's Second Law: If builders built buildings the way programmers
write programs, the first woodpecker to come along would destroy civilization.
------------------------------
Date: Wed, 08 Jul 1998 17:17:14 -0700
From: Jessie Indracusin <dontspamme@dontspam.com>
Subject: Can PERL RENAME a user account on an NT workstation?
Message-Id: <35A40C0A.C0711896@dontspam.com>
I know how to delete and add users, I have the NTRESKIT and am looking
for a way of doing this through a Perl script.
------------------------------
Date: 9 Jul 1998 00:16:57 GMT
From: geiger@cs.ucdavis.edu (Phillip George Geiger)
Subject: Re: Do I understand this?
Message-Id: <6o125p$54j$1@mark.ucdavis.edu>
Abigail (abigail@fnx.com) wrote:
: Please read the RFC.
Thanks for the suggestion. I'll look into it.
: This is not a Perl question.
My apologies if it's off topic here. Which newsgroup would be a
better place to ask it?
--
Phil Geiger
Visit the Linux Book Guide
http://members.bellatlantic.net/~ptgeiger/guidehome.htm
------------------------------
Date: 9 Jul 1998 00:55:59 GMT
From: gabor@vmunix.com (Gabor)
Subject: Re: Do I understand this?
Message-Id: <slrn6q85b2.1h7.gabor@localhost.vmunix.com>
In comp.lang.perl.misc, Scratchie <upsetter@ziplink.net> wrote :
# Tom Christiansen <tchrist@mox.perl.com> wrote:
# : In comp.lang.perl.misc,
# : geiger@cs.ucdavis.edu (Phillip George Geiger) writes:
# : :I want to put some advertising banners on my web site.
#
# : Gosh, that'll sure win you a lot of friends.
#
# What planet do you live on?
What does that have to do with anything? And your perl question was?
------------------------------
Date: Thu, 09 Jul 1998 00:01:58 GMT
From: chrisoc@ans.net
Subject: getting hostname and ip addr when you don't have either
Message-Id: <6o119m$n86$1@nnrp1.dejanews.com>
What is the easiest and most platform-independent way to
get the current hostname and IP address from inside a Perl
script, when you don't have either one? If this were in
a shell script I'd ping myself and grep and awk the output.
I dislike escaping into shell calls from Perl and want to see
what folks who think easily in Perl can show me about this.
I cannot depend on having any modules installed on the box.
Thank you in advance,
Chris O'Connor
-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/rg_mkgrp.xp Create Your Own Free Member Forum
------------------------------
Date: 8 Jul 1998 23:45:34 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: How much space left on disk?
Message-Id: <6o10au$to$2@comdyn.comdyn.com.au>
In article <6o04d7$60$1@nz12.rz.uni-karlsruhe.de>,
Marc.Haber-usenet@gmx.de (Marc Haber) writes:
> Hi!
>
> I am looking for a way to determine how many bytes of disk space I can
> still use with my current privileges, much like the statfs(2) system
> call. That call should take quotas and free space into account. I have
> looked on the CPAN, but didn't seem to find anything appropriate.
There have been many discussions about this on this group in the past.
You can use www.dejanews.com.au to read some of them.
statfs is not portable at all, which is why perl doesn't have it. You
can always call it yourself with syscall, or by wrapping it in an
XSub. It will be highly unportable though.
Maybe a call to quota and df might be easier to implement. Just as
unportable of course.
Martien
--
Martien Verbruggen |
Webmaster www.tradingpost.com.au | I think I think, therefore I think I
Commercial Dynamics Pty. Ltd. | am.
NSW, Australia |
------------------------------
Date: Wed, 08 Jul 1998 23:58:34 GMT
From: sowmaster@juicepigs.com (Bob Trieger)
Subject: Re: How to use 'system ("...")' on WIN32.
Message-Id: <6o117g$1if$1@strato.ultra.net>
[ posted and mailed ]
Michael Pham <mpham@cts.com> wrote:
-> I have a script that calls another script using 'system()' function.
-> It works fine on Unix. I tried to port it to WIN32 and find that it
-> does not work as expected. Any WIN32 gurus?
Doesn't work?
My sister doesn't work. She has a rich husand.
My brother doesn't work. He is lazy.
My boss doesn't work. He is management.
My father doesn't work. He is retired.
My grandfather doesn't work. He is dead.
`Doesn't work' can mean a lot of things.
- What are you calling with it?
- What does it do?
- Does it give you an error? What error?
- Does the script die?
Bob Trieger
sowmaster@juicepigs.com
" Cost a spammer some cash: Call 1-800-400-1972
Ext: 1949 and let the jerk that answers know
that his toll free number was sent as spam. "
------------------------------
Date: 08 Jul 1998 20:45:08 -0400
From: jzawodn@wcnet.org (Jeremy D. Zawodny)
To: Randal Schwartz <merlyn@stonehenge.com>
Subject: Re: manipulate /etc/passwd without expect ??
Message-Id: <m3yau3kg2z.fsf@peach.z.org>
Randal Schwartz <merlyn@stonehenge.com> writes:
> >>>>> "Jeremy" == Jeremy D Zawodny <jzawodn@wcnet.org> writes:
>
> Jeremy> Seeing the need for it lately, I've resurrect that project and
> Jeremy> am working on converting the core pieces to a Perl module
> Jeremy> which will many peoples' lives easier, I hope.
>
> You mean to replace the core module HTTPD::UserAdmin, which has been
> there some twelve months or so?
Certainly not.
HTTPD::UserAdmin is for the httpd's user databases (.htaccess and
friends). The work I'm doing is for /etc/passwd and /etc/shadow access
(among other things).
If the previous poster was after something along the lines of
HTTPD::UserAdmin, I apologize. That's the way I interpreted it.
Jeremy
--
Jeremy D. Zawodny Web Geek, Perl Hacker, etc.
http://www.wcnet.org/~jzawodn/ jzawodn@wcnet.org
LOAD "LINUX",8,1
------------------------------
Date: 9 Jul 1998 00:37:14 GMT
From: cberry@cinenet.net (Craig Berry)
Subject: Re: Need slick code: How to CWD to executable's directory
Message-Id: <6o13bq$a38$4@marina.cinenet.net>
Chris Schoenfeld (chris@ixlabs.com) wrote:
: I have programs that need to cwd to the directory they live in, rather
: than the user's cwd.
:
: I usually just parse $0, but would like to know if there is a slicker,
: less artistic way.
The latter criterion depends on your artistry metric, but:
perldoc FindBin
---------------------------------------------------------------------
| 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 Jul 1998 01:13:56 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: Need slick code: How to CWD to executable's directory
Message-Id: <6o15gk$1ai$1@comdyn.comdyn.com.au>
In article <35A3E53E.E1086266@ixlabs.com>,
Chris Schoenfeld <chris@ixlabs.com> writes:
> I have programs that need to cwd to the directory they live in, rather
> than the user's cwd.
#perldoc FindBin
Martien
--
Martien Verbruggen |
Webmaster www.tradingpost.com.au | If at first you don't succeed, try
Commercial Dynamics Pty. Ltd. | again. Then quit; there's no use being
NSW, Australia | a damn fool about it.
------------------------------
Date: 9 Jul 1998 00:47:56 GMT
From: Zenin <zenin@bawdycaste.org>
Subject: Re: NEVER "call warn() and return undef" (Re: question about objects)
Message-Id: <899945815.606388@thrush.omix.com>
Gisle Aas <aas@sn.no> wrote:
: The problem is that the "Undefined subroutine &main::do_something"-exception
: is caught by your RE and invokes handle_do_something_error(), and if
: the die inside eval is invoked you misspelled somthing so it wouldn't
: match.
Yep, which is a major problem IMO.
: If you are afraid of typos, you can always do something like this:
>snip<
That's assuming (danger) you're throwing the exception in the
same package you're catching it in. If you're throwing it
from another package (from a method call for instance), you'll
either have to import the "exceptions" (read: namespace
pollution), or risk uncheckable typos when creating your
constants. End result, it doesn't help much and can make code
in general much worse overall.
: With perl5.005 you will be able to throw objects, and then you can set
: up an exception handler like this:
>snip<
Yep. This (and the fields pragma), will be a major win for large
Perl applications. As simple as the current eval/die/$@ system
is, it doens't scale well at all. It's also the single argument
that has made some projects I've worked with use Java when Perl
was arguably a better choice for the particular task.
--
-Zenin
zenin@archive.rhps.org
------------------------------
Date: Thu, 09 Jul 1998 01:47:25 GMT
From: drummj@mail.mmc.org (Jeffrey Drumm)
Subject: Re: NT Sysadmin scripts
Message-Id: <35a41a5c.610273818@news.mmc.org>
[posted and mailed]
On Wed, 08 Jul 1998 18:02:01 GMT, keydet89@yahoo.com wrote:
>Does anyone know were I can find Perl on Win32 sysadmin
>scripts for maintaining a NT/win95 network?
I somehow managed to wind up with an unsolicited free subscription to
_Windows_NT_Systems_ magazine, and they've published system administration
scripts written in Perl virtually every month since I started receiving it.
I haven't checked their web site, but I'm pretty sure they post the code
from their articles there . . . http://www.ntsystems.com.
The modules relied on for those scripts are available for both the Sarathy
and ActiveState ports.
--
Jeffrey R. Drumm, Systems Integration Specialist
Maine Medical Center Information Services
420 Cumberland Ave, Portland, ME 04101
drummj@mail.mmc.org
"Broken? Hell no! Uniquely implemented." -me
------------------------------
Date: 9 Jul 1998 01:33:00 GMT
From: Zenin <zenin@bawdycaste.org>
Subject: Re: Oh man, DO I love Perl ! (References to things that go out of scope)
Message-Id: <899948519.401073@thrush.omix.com>
Gisle Aas <aas@sn.no> wrote:
: Zenin <zenin@bawdycaste.org> writes:
: > Is everything else public/protected, unless declared with use fields?
: Everything not declared with fields is regarded as a typo.
>snip<
I think I said that wrong. I meant that anything not declared with
fields in the current package as opposed to never being declared
anywere. Eg, B declares "foo", so unless D declares "foo" too,
it's public/protected (everyone uses B's foo, until someone down
the line declares it again at which point it's their foo until
another sub package declares it again).
Yes, no?
: This is a very good idea. I have been playing privately with stupid
: syntaxes like:
: use fields [a => "private"];
: use fields "a:private";
Until we learned of the fields pragma, Steve Farrell and I where
working on a "member_vars" pragma that would give similar
functionality by using an array and enumerated constants for
field names (yes, it polluted the hell out of the namespace :-).
We were using stuff like:
use member_vars qw(
:PRIVATE foo bar
:PUBLIC cat dog
);
I never liked this syntax much either.
: I like it. I don't think "protected" makes much sense in perl where
: you can enter and leave classes whenever you want.
I was thinking that a "protected" could check the compiled in
package name and if it wasn't within that object's @ISA somewhere,
it would be disallowed. Such that this would work as expected:
package Foo;
use protected qw(foo);
sub new { my __PACKAGE__ $self = {}; bless $self, shift }
package Foo::Bar;
use base 'Foo';
sub make_dog { $_[0]->{foo} = "dog" }
package main;
my Foo::Bar $foo = new Foo::Bar;
$foo->make_dog();
print "I'm a $foo->{foo}!";
## Compile error, we're not in Foo::Bar or anywere in it's @ISA
Of course, this goes against Perl's shotgun ban, but Perl never
stopped people from using shotgun, it just advises against it.
: It was just a first shot at implementing the mechanisms to support
: private fields. Implementing your idea with two different pragmas is
: easy with the current fields.pm.
Cool. I'm also thinking, that to satisfy the "Everything should
go though a set/get method" camp (who I'll agree have a good
point, in many cases, but not all), "private" fields maybe
have a set/get pragma option to allow them to be changed from
normal fields to actual set/get method access:
use public qw(foo bar);
use set foo => sub { push @{ $_[0]->{foo} }, $_[1] };
use get foo => sub { shift @{ $_[0]->{foo} };
Which would automatically tie the particular field's SV to a tied
scalar class with these as STORE/FETCH methods (default methods
would just set or return the given field value).
For easier typing, it could be rolled into a larger set:
sub setField { $_[0]->{$_[1]} = $_[2] }
use set (
foo => sub { $_[0]->setField (foo => $_[1]) },
bar => sub { $_[0]->setField (bar => $_[1]) },
);
This would allow safe public access via $obj->{field} with all the
speed efficiencies this gains over set/get methods, but still
keeping the option of abstracting this into set/get methods at a
later time should the need arise. Sure, this can be done with
tied scalars now, but that pretty much needs to be done one by one
within the constructor, which (IMO) isn't too clean (especially if
you override the constructor without calling your super).
Comments?
--
-Zenin
zenin@archive.rhps.org
------------------------------
Date: Wed, 8 Jul 1998 17:31:14 +0100
From: "Simon Fairey" <simonf@conduit.co.uk>
Subject: Re: PERL & mSql help needed
Message-Id: <35a39e0b.0@nnrp1.news.uk.psi.net>
You need the DBI module and then the M(y)SQL module to allow perl to access
an msql database I did something very similar to what you are trying to do
modifying data in a database over the web ) using a mysql database quite
recently. You will end up with something like:
use DBI;
then the connection to the database will have the required driver name in
(msql in this case) if you read the DBI documentation its pretty
straightforward.
Simon
Reinhard Hoefler wrote in message ...
>Hello all,
>
>I have worked a bit with perl and I am completely new at mSQL. I have
>made my first steps and wonder how to make msql and perl work together to
>allow visitors, to request from/write to a database over the web.
>
>The problem seems to be, that the server does not accept:
>use Msql;
>
>Maybe I have to install something (I rent a virtual server at VServers -
>the system is a modified Unix BSD 3). Could someone please help me?
>
>Thank you in advance,
>Reinhard
------------------------------
Date: Wed, 8 Jul 1998 20:46:53 -0400
From: "Pascal7" <cycleman@usouthal.campus.mci.net>
Subject: Perl and Win NT porting?
Message-Id: <6o17hp$4r6$1@news.campus.mci.net>
Hi, does anyone know where I can find information on Perl NT porting? Thank
you.
------------------------------
Date: Wed, 8 Jul 1998 17:39:46 +0100
From: "Simon Fairey" <simonf@conduit.co.uk>
Subject: Re: Placeholders in Perl?
Message-Id: <35a3a008.0@nnrp1.news.uk.psi.net>
All you need are two different regexps, something along the lines of:
/nmos_ M2\( \.SUBSTRATE\([^)]+\), \.G\([^)]+\), \.D\([^)]+\),
\.S\([^)]+\)\);/
/pmosob M1\( \.SUBSTRATE\([^)]+\), \.D\([^)]+\), \.S\([^)]+\),
\.BG\([^)]+\), \.G\([^)]+\)\);/
The only things to consider are escaping brackets and full stops etc, the
pattern [^)]+ simply matches 1 or more characters which are not a right
parenthesis ( not sure if that is particularly good english but you get my
drift)
The only other thing you might want to consider is changing the blank spaces
to match on \s+ but that is only if you are likely to get a different number
of spaces between elements.
Simon
Brian Coffey wrote in message <35A3555B.EBCC81E8@analog.com>...
>Hi,
>
>
>the problem:
>
>nmos_ M2( .SUBSTRATE(VSS), .G(I), .D(ZN), .S(VSS));
>pmosob M1( .SUBSTRATE(VSS), .D(ZN), .S(VDD), .BG(VDD), .G(I));
>
>I want to use the above two lines as regular expressions on a file that
>contains
>similar lines but has different strings in the brackets. For example :
>
>nmos_ M2( .SUBSTRATE(VSS), .G(I_DIFF), .D(ZN), .S(VSS));
>pmosob M1( .SUBSTRATE(VSS), .D(ZN), .S(VDD), .BG(VDD), .G(I_DIFF));
>
>should also match the reg. expression. Is there such a thing as a
>template or
>placeholder in Perl? Something like this?
>
>nmos_ M2( .SUBSTRATE(X1), .G(X2), .D(X3), .S(X1));
>pmosob M1( .SUBSTRATE(X1), .D(X3), .S(X4), .BG(X4), .G(X2));
>
>So no matter what strings are in the brackets as long as they match like
>
>in the order above the expression is satisfied.
>
>
>If anyone can help with the above problem I would be very grateful.
>
>Thanks,
>Brian Coffey
>
>
>
------------------------------
Date: 9 Jul 1998 00:19:44 GMT
From: Tom.Grydeland@phys.uit.no (Tom Grydeland)
Subject: Resize windows (was: Re: Pod::Text -- Unix only?)
Message-Id: <slrn6q834v.gst.Tom.Grydeland@mitra.phys.uit.no>
> In article <6mi5r4$hga$1@srv38s4u.cas.org>,
> lvirden@cas.org writes:
> > Wouldn't it be nice if xterm/rxvt/dtterm and so forth had an escape
> > sequence to report it's size....
On 22 Jun 1998 22:46:17 GMT,
Martien Verbruggen <mgjv@comdyn.com.au> wrote:
> I don't know how they do it, but it works fine. On my xterm:
SIGWINCH
> Again: I don't know where this information comes from, but it's
> probably documented somewhere.
signal(4) on my system
> Martien Verbruggen |
--
//Tom Grydeland <Tom.Grydeland@phys.uit.no>
- Do radioactive cats have 18 half-lives? -
------------------------------
Date: 8 Jul 1998 23:56:51 GMT
From: cberry@cinenet.net (Craig Berry)
Subject: Re: Searching a file
Message-Id: <6o1103$a38$2@marina.cinenet.net>
David Hamilton (ozslot@alphalink.com.au) wrote:
: I am having some problems loading a text file into a variable and then
: not writing to the file if an E-mail address is already in the file. I
: have read all the documentation I could find on this. This code writes
: to the file no matter what and there are many occurences of $email
: already in the file.
:
: $email=($INPUT{'email'});
Just a more cluttered way of writing
$email = $INPUT{email};
: open (REMOVED, "removed.txt");
Always always always ALWAYS check the success of open()!
open REMOVED, '< removed.txt' or die $!;
: $remfile = <REMOVED>;
: close (REMOVED);
OK, now you've read just the first line of removed.txt into $remfile.
Perhaps you meant:
{ local $/; $remfile = <REMOVED>; }
: unless ($remfile =~ /$email/)
You almost certainly want
unless ($remfile =~ /\Q$email/)
instead. Otherwise regex metacharacters such as . in the email address
will produce weird results.
: {
: open (REMVD, ">>removed.txt");
Always^N check your opens. Also, you could probably open the file once
for read-write, slurping it in then seeking to the end before writing the
new email.
: print REMVD "$email\n";
: close (REMVD);
: }
HTH...
---------------------------------------------------------------------
| 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: 8 Jul 1998 23:42:24 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: Searching a file
Message-Id: <6o1050$to$1@comdyn.comdyn.com.au>
In article <35A38BED.4FC65DE3@alphalink.com.au>,
David Hamilton <ozslot@alphalink.com.au> writes:
You should consider using -w and use strict.
> $email=($INPUT{'email'});
You should probably check here if $email contains anything useful. I
don't mean 'validate' an email address, just check whether it's at
least defined, and contains at least something.
> open (REMOVED, "removed.txt");
You should always check the return value of an open statement:
open(REMOVED, "removed.txt") || die "Couldn't open removed.txt: $!";
> $remfile = <REMOVED>;
This only gets the first line from the file including the terminating
newline.
> close (REMOVED);
> unless ($remfile =~ /$email/)
This tests to see if the first line of removed.txt contains $email.
Since you don't know whether $email contains anything useful, this
might succeed or fail in circumstances that you don't want. And that
is even if you were doing what you are trying to do.
Consider the following two email addresses:
second_user@blabla.com
first_user@blabla.com
if $email = 'user@blabla.com' it would match both the above email
addresses, but they would not be equal.
> {
> open (REMVD, ">>removed.txt");
Again: you should check.
> print REMVD "$email\n";
> close (REMVD);
> }
Maybe you could do it this way:
#!/usr/local/bin/perl -w
use strict;
my $found = 0;
# We will always use the lower case form of an email address
my $email = lc($_);
# open for read and write
open(RR, '+<removed.txt') || die "Couldn't open removed.txt: $!";
while (defined(my $rmvd = <RR>))
{
chomp $rmvd;
if ($rmvd eq $email)
{
print "$email already exists\n";
$found = 1;
last;
}
}
if (!$found)
{
seek(RR, 0, 2);
print RR "$email\n";
}
close RR;
__END__
Of course, if this is a CGI application, or anything else where there
might be more than one instance running at the same time, you will
need to properly lock the file. See
http://www.stonehenge.com/merlyn/WebTechniques/col04.html
Martien
--
Martien Verbruggen |
Webmaster www.tradingpost.com.au | The world is complex; sendmail.cf
Commercial Dynamics Pty. Ltd. | reflects this.
NSW, Australia |
------------------------------
Date: Wed, 8 Jul 1998 20:35:03 -0500
From: tadmc@flash.net (Tad McClellan)
Subject: Re: Searching a file
Message-Id: <7o61o6.058.ln@localhost>
Jonathan Feinberg (jdf@pobox.com) wrote:
: David Hamilton <ozslot@alphalink.com.au> writes:
: > $email=($INPUT{'email'});
: ^ ^
: These parentheses simply make your code obscure; they don't do
: anything useful.
... and the single quotes don't do anything useful either.
;-)
: > open (REMOVED, "removed.txt");
: How do you know that the open() succeeded? As rootbeer always says,
: even if your code is "just an example" (or maybe *especially* if it
: is) you must always check system calls for failure.
: open(REMOVED, '<removed.txt')
: or die "Can't open removed.txt for write: $!";
s/write/read/; # just a typo, I'm sure
: > unless ($remfile =~ /$email/)
: You probably want to match only those cases where the email address is
: the whole line, and you probably don't want it to be case-sensitive:
: /^$email$/i
... and you probably don't want to have 'oz.lot' match 'ozslot' either:
/^\Q$email\E$/i; # or use the quotemeta() function
--
Tad McClellan SGML Consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: 9 Jul 1998 01:31:56 GMT
From: cberry@cinenet.net (Craig Berry)
Subject: Re: Searching a file
Message-Id: <6o16ic$hn5$1@marina.cinenet.net>
Martien Verbruggen (mgjv@comdyn.com.au) wrote:
: Maybe you could do it this way:
[Good way snipped]
Or this, which borrows a bit from Martien's version; less typing, probably
a bit more runtime space/time overhead, not suitable for truly humongous
email data files.
#!/usr/local/bin/perl -w
use strict;
# Population of %FORM omitted.
my $email = lc $FORM{email};
# Checks that $email is nonblank and 'reasonable' omitted.
# open for read and write
open RR, '+< removed.txt' or die "Couldn't open removed.txt: $!";
chomp(my @known_array = <>);
my %known;
@known{@known_array} = (); # All values undef, since they don't matter.
if (exists $known{$email}) {
print "$email already exists\n";
}
else {
seek(RR, 0, 2);
print RR "$email\n";
}
close RR;
---------------------------------------------------------------------
| 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 Jul 1998 01:53:36 GMT
From: "Matthew Giles" <mgiles@mindspring.com>
Subject: Splitting a difficult CSV file
Message-Id: <01bdaadc$3f7d3860$342456d1@aubie>
I am totally stumped on how to split this Excel exported CSV file that is
being delivered to me each day. I'm trying to read the file in and spit
out an HTML document with the three nicely formatted tables. I could read
the entire document in an array and pick out each element.. but that's not
the cleanest way. I also need the date and day of week fields which change
from the data file. But these fields are identical for each of the three
tables so I can not use them as a key to being reading in the data. And I
unfortunately don't have the luxury of changing the format the file is
delivered.
Any ideas on how to approach it? I'm sure someone else has tackled this
type of a data file problem before..
Matthew Giles
mgiles@mindspring.com
--- Start CSV file ---
1999070202707028N30524 0052,,,,,,
000252427 REL,,,,,,
0000,,,,,,
0000,,,,,,
0000,,,,,,
Table 1: Daily Price Change Leaders,,,,,,
,,,,,,
[Ranked by Greatest Percentage Gains],,,,,,
,,,,,,
,Closing Price,,,,Percent Change,
,,7/2,7/1,6/25,Prev,Week
Name,Symbol,Thur,Wed,Thur,Day,Ago
SEC CAP PAC,PTR,22.38,0.00,21.88,-,2.3
EQK RELTY I,EQKR,0.81,0.62,0.00,30.6,-
CORP OFFICE PR,OFC,9.13,8.63,8.94,5.8,2.1
GLIMCHER RLT,GRT,20.00,18.94,20.94,5.6,-4.5
WELLINGTON,WLPT,9.72,9.25,9.88,5.1,-1.6
MILLS CORP,MLS,25.75,24.56,24.44,4.8,5.4
APEX MTG,AXM,10.88,10.44,11.25,4.2,-3.3
BANYAN STRAT,BSRTS,6.75,6.50,6.13,3.8,10.2
RESOURCE AST,RAS,17.00,16.38,15.56,3.8,9.2
USP REAL EST,USPTS,4.77,4.63,4.75,3.0,0.3
,,,,,,
Table 2: Daily Price Change Laggards,,,,,,
,,,,,,
[Ranked by Greatest Percentage Loss],,,,,,
,,,,,,
,,Closing Price,,,,Percent Change
,,7/2,7/1,6/25,Prev,Week
Name,Symbol,Thur,Wed,Thur,Day,Ago
VININGS,VIPIS,4.25,4.75,4.75,-10.5,-10.5
PROPERTY CAP,PCT,0.94,1.00,1.00,-6.2,-6.2
NTL HLTH RLTY,NHR,14.69,15.25,15.75,-3.7,-6.7
BANDO MCGLOC,BMCC,11.63,12.00,12.00,-3.1,-3.1
INDYMAC MTG,NDE,22.56,23.25,21.75,-3.0,3.7
HOST FDG,HFD,4.25,4.38,4.56,-2.9,-6.9
GREAT LAKES,GL,17.13,17.63,16.69,-2.8,2.6
LASALLE HOTEL,LHO,16.44,16.88,16.94,-2.6,-3.0
MONMOUTH,MNRTA,6.56,6.72,6.67,-2.3,-1.6
FIRST UNION,FUR,8.81,9.00,9.38,-2.1,-6.0
Table 3: Activity Leaders,,,,,,
,,,,,,
[Ranked by Greatest Daily Volume],,,,,,
,,,,,,
,,Daily Volume,,,,Percent Change
,,7/2,7/1,6/25,Prev,Week
Name,Symbol,Thur,Wed,Thur,Day,Ago
CAPSTEAD MTG,CMO,8.06,7.88,12.94,2.4,-37.7
STARWOOD LDG,HOT,48.06,47.50,47.50,1.2,1.2
CRESCENT RE,CEI,34.13,33.50,32.31,1.9,5.6
EQUITY OFFIC,EOP,27.75,27.13,26.75,2.3,3.7
MEDITRUST,MT,26.44,26.81,25.94,-1.4,1.9
IMPERIAL CR COM,ICMI,13.06,13.03,13.00,0.2,0.5
PUB STORAGE,PSA,28.25,27.88,26.75,1.3,5.6
AVALON BAY,AVB,37.63,37.19,36.88,1.2,2.0
DUKE RLTY,DRE,23.19,23.31,22.38,-0.5,3.6
LIBERTY PROP,LRY,25.38,25.00,24.50,1.5,3.6
,,,,,,
,,,,,,
,,,,,,
,,,,,,
,,,,,,
,,,,,,
--- End CSV file ---
------------------------------
Date: 9 Jul 1998 00:29:22 GMT
From: cberry@cinenet.net (Craig Berry)
Subject: Re: tough regexp - help needed
Message-Id: <6o12t2$a38$3@marina.cinenet.net>
otis@my-dejanews.com wrote:
: sounds like nobody knows the right regexp :(
Nobody knows it 'cause there ain't none. Such a regex does not exist in
the same sense that a geometric method to square the circle or trisect the
angle does not exist. It is formally, rigorously *proveable* that such a
regex does not exist. If someone presents a regex to you which is alleged
to solve the general HTML parsing problem, the presenter is lying or
misinformed.
---------------------------------------------------------------------
| 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: 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 3101
**************************************