[11781] in Perl-Users-Digest
Perl-Users Digest, Issue: 5381 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Apr 14 12:07:23 1999
Date: Wed, 14 Apr 99 09:00:24 -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, 14 Apr 1999 Volume: 8 Number: 5381
Today's topics:
$variables in <FILES> TimeSpinner@hotmail.com
Re: $variables in <FILES> <tchrist@mox.perl.com>
Re: $variables in <FILES> (Mark-Jason Dominus)
Re: $variables in <FILES> (Tim Herzog)
Re: accessing an array of subroutine references (Larry Rosler)
Re: accessing an array of subroutine references <uri@home.sysarch.com>
Re: Another beginner question (Clinton Pierce)
Re: Best books to use... (Tim Herzog)
Check for NT Groups on 95 Client? <jholmes@nospam.psrw.com>
Current Date <terral@cyberplex.com>
DBI as a Base Module (Sys Adm 89806 Manager of programing development and Intranet Resources)
Directory Renaming on NT? <ptomsic@pop.pitt.edu>
Re: Dummy Question about Perl Licence (Abigail)
Re: Get Info from a file (Tim Herzog)
how to find unused IP addresses on a subnet mjbower@my-dejanews.com
Re: how to find unused IP addresses on a subnet <gellyfish@gellyfish.com>
Re: how to find unused IP addresses on a subnet (Lack Mr G M)
Re: HTML redirection to FTP site (Tim Herzog)
Re: ide advice wanted <c4jgurney@my-dejanews.com>
Re: Looking for Tutoral Referenced in the Perl Cookbook <tchrist@mox.perl.com>
mailer script question andrew338@my-dejanews.com
Re: mailer script question (Tim Herzog)
Re: Newbie Question: String Manipulation (Tim Herzog)
Re: Password encryption (Tim Herzog)
Re: Perl or C? <andrewf@beausys.demon.co.uk>
Re: Q: Convert two newlines to \n<p> (Bart Lateur)
Re: Q: Convert two newlines to \n<p> <gellyfish@gellyfish.com>
Re: Q: Convert two newlines to \n<p> <tchrist@mox.perl.com>
Re: Reading from STDIN, VMSperl + DCL <keithmur@mindspring.com>
regex - meta char's kscurry@my-dejanews.com
Re: regex - meta char's <vvb@ibm.net>
Re: regex - meta char's (Tim Herzog)
sort readdir on NT <c4jgurney@my-dejanews.com>
Re: sort readdir on NT (David Cantrell)
Re: TPJ still shipping? (Tad McClellan)
Re: Unitialized var errors & -w flag (Tim Herzog)
Re: Unitialized var errors & -w flag (Larry Rosler)
Special: Digest Administrivia (Last modified: 12 Dec 98 (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 14 Apr 1999 14:29:35 GMT
From: TimeSpinner@hotmail.com
Subject: $variables in <FILES>
Message-Id: <7f28o4$9cq$1@nnrp1.dejanews.com>
Is it possible to have a file which contains the text:
Hello, my name is $name.
My address is $address.
and have a Perl Script read this file, and print it, automatically
substituting the $name and $address variables in?
I've tried reading in the file, and processing the @array printing each line,
but it didn't do the interpolation, so I am guessing that while it reads in
the file, it's somehow changing the $name into \$name.
Is there anyway around this?
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
------------------------------
Date: 14 Apr 1999 08:47:25 -0700
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: $variables in <FILES>
Message-Id: <3714aa7d@cs.colorado.edu>
[courtesy cc of this posting sent to cited author via email]
In comp.lang.perl.misc,
TimeSpinner@hotmail.com writes:
:Is it possible to have a file which contains the text:
:
:Hello, my name is $name.
:My address is $address.
:
:and have a Perl Script read this file, and print it, automatically
:substituting the $name and $address variables in?
That's wrong. You don't want the file to access your variables.
You think you do, but you're wrong.
=head2 How can I use a variable as a variable name?
Beginners often think they want to have a variable contain the name
of a variable.
$fred = 23;
$varname = "fred";
++$$varname; # $fred now 24
This works I<sometimes>, but it is a very bad idea for two reasons.
The first reason is that they I<only work on global variables>.
That means above that if $fred is a lexical variable created with my(),
that the code won't work at all: you'll accidentally access the global
and skip right over the private lexical altogether. Global variables
are bad because they can easily collide accidentally and in general make
for non-scalable and confusing code.
Symbolic references are forbidden under the C<use strict> pragma.
They are not true references and consequently are not reference counted
or garbage collected.
The other reason why using a variable to hold the name of another
variable a bad idea is that the question often stems from a lack of
understanding of Perl data structures, particularly hashes. By using
symbolic references, you are just using the package's symbol-table hash
(like C<%main::>) instead of a user-defined hash. The solution is to
use your own hash or a real reference instead.
$fred = 23;
$varname = "fred";
$USER_VARS{$varname}++; # not $$varname++
There we're using the %USER_VARS hash instead of symbolic references.
Sometimes this comes up in reading strings from the user with variable
references and wanting to expand them to the values of your perl
program's variables. This is also a bad idea because it conflates the
program-addressable namespace and the user-addressable one. Instead of
reading a string and expanding it to the actual contents of your program's
own variables:
$str = 'this has a $fred and $barney in it';
$str =~ s/(\$\w+)/$1/eeg; # need double eval
Instead, it would be better to keep a hash around like %USER_VARS and have
variable references actually refer to entries in that hash:
$str =~ s/\$(\w+)/$USER_VARS{$1}/g; # no /e here at all
That's faster, cleaner, and safer than the previous approach. Of course,
you don't need to use a dollar sign. You could use your own scheme to
make it less confusing, like bracketed percent symbols, etc.
$str = 'this has a %fred% and %barney% in it';
$str =~ s/%(\w+)%/$USER_VARS{$1}/g; # no /e here at all
Another reason that folks sometimes think they want a variable to contain
the name of a variable is because they don't know how to build proper
data structures using hashes. For example, let's say they wanted two
hashes in their program: %fred and %barney, and to use another scalar
variable to refer to those by name.
$name = "fred";
$$name{WIFE} = "wilma"; # set %fred
$name = "barney";
$$name{WIFE} = "betty"; # set %barney
This is still a symbolic reference, and is still saddled with the
problems enumerated above. It would be far better to write:
$folks{"fred"}{WIFE} = "wilma";
$folks{"barney"}{WIFE} = "betty";
And just use a multilevel hash to start with.
The only times that you absolutely I<must> use symbolic references are
when you really must refer to the symbol table. This may be because it's
something that can't take a real reference to, such as a format name.
Doing so may also be important for method calls, since these always go
through the symbol table for resolution.
In those cases, you would turn off C<strict 'refs'> temporarily so you
can play around with the symbol table. For example:
@colors = qw(red blue green yellow orange purple violet);
for my $name (@colors) {
no strict 'refs'; # renege for the block
*$name = sub { "<FONT COLOR='$name'>@_</FONT>" };
}
All those functions (red(), blue(), green(), etc.) appear to be separate,
but the real code in the closure actually was compiled only once.
So, sometimes you might want to use symbolic references to directly
manipulate the symbol table. This doesn't matter for formats, handles, and
subroutines, because they are always global -- you can't use my() on them.
But for scalars, arrays, and hashes -- and usually for subroutines --
you probably want to use hard references only.
--
"I think I'll side with the pissheads on this one." --Larry Wall
------------------------------
Date: Wed, 14 Apr 1999 15:15:55 GMT
From: mjd@op.net (Mark-Jason Dominus)
Subject: Re: $variables in <FILES>
Message-Id: <7f2bec$pek$1@monet.op.net>
In article <7f28o4$9cq$1@nnrp1.dejanews.com>, <TimeSpinner@hotmail.com> wrote:
>Is it possible to have a file which contains the text:
>
>and have a Perl Script read this file, and print it, automatically
>substituting the $name and $address variables in?
>
>I've tried reading in the file, and processing the @array printing each line,
>but it didn't do the interpolation,
Perl is full of these kinds of bugs. It says in the manual that if a
number begins with `0' it is interpreted as an octal constant. But
look at this:
perl -ne 'print $_ + 1';
If you type `027' that is octal constant, so it should do octal
arithmetic and print 030. But instead it prints 28. So Perl cannot
even do simple arithmetic right.
And even worse, if you have comments in the file, Perl does not ignore
them like it says in the manual that it should. I mean for example
that if the file has
Dr. Jerome Fenchurch # Not a very good doctor
and you read in the line and ask for length($_), it says that the
length is 46 instead of 20---clearly it did NOT ignore the comment!
How stupid is that? How can you depend on a language that does not
even ignore comments properly? Sometimes it seems to ignore them, and
sometimes not, and I am afrait to write anything in a comment because
I do not know what Perl is going to decide to do with it. I was
printing out form letters, and one came out addressed to `Dear
Dr. Fenchurch # Not a very good doctor,' and was mailed out. Then
Dr. Fenchurch got very angry and my client fired me! All because Perl
cannot know a comment when it sees one.
I even submitted a patch for this so that it would be fixed in future
versions of Perl, and instead of using my patch, the Perl maintainers
called me a fool!
>Is there anyway around this?
Try using Text::Template module
from http://www.plover.com/~mjd/perl/Template/
------------------------------
Date: Wed, 14 Apr 1999 10:33:44 -0500
From: therzog@knotech.com (Tim Herzog)
Subject: Re: $variables in <FILES>
Message-Id: <therzog-1404991033440001@therzog-host105.dsl.visi.com>
In article <3714aa7d@cs.colorado.edu>, tchrist@mox.perl.com (Tom
Christiansen) wrote:
> [courtesy cc of this posting sent to cited author via email]
>
>In comp.lang.perl.misc,
> TimeSpinner@hotmail.com writes:
>:Is it possible to have a file which contains the text:
>:
>:Hello, my name is $name.
>:My address is $address.
>:
>:and have a Perl Script read this file, and print it, automatically
>:substituting the $name and $address variables in?
I wrote something like that where the variables to be substituted were
stored in a hash, and I did the substitutions like this:
while(<FILE>) {
foreach $key(%macros) {
s/\$$key/$macros{$key}/g;
}
print "$_";
}
It gets slow for large files and hashes, but it works.
--
Tim Herzog
------------------------------
Date: Wed, 14 Apr 1999 07:23:33 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: accessing an array of subroutine references
Message-Id: <MPG.117e44ba6f449d1e9898aa@nntp.hpl.hp.com>
[Posted and a courtesy copy sent.]
In article <7f1e99$ise$1@nnrp1.dejanews.com> on Wed, 14 Apr 1999
06:57:47 GMT, Ronny <ronald_f@my-dejanews.com> says...
> I have an array of sub references, like this:
>
> @subs=(sub {do_this()}, sub {do_that()});
>
> Given an index $i, I would like to execute the subroutine at $subs[$i]. I
> tried
>
> $result=&$subs[$i]();
$result = &{$subs[$i]}();
--
(Just Another Larry) Rosler
Hewlett-Packard Company
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: 14 Apr 1999 10:36:07 -0400
From: Uri Guttman <uri@home.sysarch.com>
Subject: Re: accessing an array of subroutine references
Message-Id: <x7k8vfnuaw.fsf@home.sysarch.com>
>>>>> "JF" == Jonathan Feinberg <jdf@pobox.com> writes:
JF> Ronny <ronald_f@my-dejanews.com> writes:
>> Given an index $i, I would like to execute the subroutine at
>> $subs[$i].
JF> $subs[$i]->($arg)
JF> &{subs[$i]}($arg)
^
missing $
just a little typo, you meant well!
uri
--
Uri Guttman ----------------- SYStems ARCHitecture and Software Engineering
uri@sysarch.com --------------------------- Perl, Internet, UNIX Consulting
Have Perl, Will Travel ----------------------------- http://www.sysarch.com
The Best Search Engine on the Net ------------- http://www.northernlight.com
------------------------------
Date: Wed, 14 Apr 1999 14:35:07 GMT
From: cpierce1@ford.com (Clinton Pierce)
Subject: Re: Another beginner question
Message-Id: <3718a60e.1210519304@news.ford.com>
[Author cc'd in E-Mail]
On Mon, 12 Apr 1999 21:57:54 -0400, "ibrew" <ibrew@voyager.net> wrote:
>I get an error on the following chunck of code taken directly from the
>"Learning Perl" book, pages 8-9
>
>!#c:/perl/bin/perl
>@words = qw(camel llama alpaca);
>
>I get a compile error on the second statement;
>"Can't modify not in scalar assignment on line two..."
>
>i would be thankful for any help.
Others have pointed out that the first line is the culprit. I'd just like
to add why you got that particular message....
"#!" is significant. It's a magic token that means "run the interpreter
indicated on this line to interpret this script". Comes from a Unix-ism.
"!#" is something different. It's a "not" operator, followed by a
comment-starting character.
Perl (usually) isn't picky about whitespace between statements, so what
your program looks like, after the comment was stripped out, is:
!
@words=qw(camel llama alpaca);
In other words:
! @words=qw(camel llama alpaca);
This is (sort of) nonsensical, and the error message indicates that a
"not" has been applied to a scalar assignment on line two. That's why you
got that particular error message.
------------------------------
Date: Wed, 14 Apr 1999 10:21:05 -0500
From: therzog@knotech.com (Tim Herzog)
Subject: Re: Best books to use...
Message-Id: <therzog-1404991021050001@therzog-host105.dsl.visi.com>
In article <7f1q17$17c$1@camel18.mindspring.com>, "Doug Crabtree"
<not@gonna.tell> wrote:
>I am new to perl, and am wondering where to start. I have bought a book
>called "Perl5 by example (David Medinets)". It seems to be a book that will
>give me a good foundation for basic use. I have heard good things and bad
>things about Randall's "Learning Perl (2nd ed.)".
>
>What is a good secondary book to get to become a more advanced programmer in
>perl? Is it Randall's book?
>
>TIA,
>Dug (no use for redundant lettering)
Once you get through a primer, you have to get "Programming Perl" by Wall,
Christiansen & Schwarz from O'Reilly. Least I think so. It starts with
"In the beginning" and ends with "Amen" if you catch my drift.
--
Tim Herzog
------------------------------
Date: Tue, 13 Apr 1999 15:27:38 -0400
From: "Jim Holmes" <jholmes@nospam.psrw.com>
Subject: Check for NT Groups on 95 Client?
Message-Id: <7f061a$ae0$1@flint.psrw.com>
Can someone tell me how to check for NT group membership when a user logs on
to a NT domain via a Win 95/98 client?
Win32::NetAdmin::GroupIsMember works only under NT, at least according to
the error message I'm getting when trying to use it...
Thanks,
--
Jim Holmes
jholmes@nospam.psrw.com
------------------------------
Date: Wed, 14 Apr 1999 12:47:51 -0300
From: "Terra Landry" <terral@cyberplex.com>
Subject: Current Date
Message-Id: <7f2dfn$45b$1@bignews.fundy.net>
I know this has nothing to do with perl, but I'm hoping someone can help me
anyway...
I want to get the current date in javascript.. but in my books it says that
it will only return a 2 digit value for the year... is there any way I can
get a 4 digit value for the year? The only thing I can find is using the
date object, but that doesn't seem to work!!
Thanks, and sorry that this isn't a perl question..
Terra
------------------------------
Date: Wed, 14 Apr 1999 15:47:34 GMT
From: ruben@llinderman.dental.nyu.edu (Sys Adm 89806 Manager of programing development and Intranet Resources)
Subject: DBI as a Base Module
Message-Id: <qM2R2.25$jD.616@typhoon.nyu.edu>
I'm fairly perplexed at what is happening. I tried to specifiy the path and
diagnostics told me I didn't have permissions??
Without the path, it says it can't find any such module.
This small code, for example:
#!/usr/bin/perl -w
use SQLHANDLE;
use diagnostics;
$ref = new SQLHANDLE('SELECT * FROM patients');
print $ref->statement();
$dbh = $ref->connect("DBI:mysql:ezpages:localhost", 'someuser','somepasswd') or
print "Sorry DB DOWN";
Produces this output:
/home/ruben/myootest.pl
Can't exec "DBI": No such file or directory at /usr/lib/perl5/SQLHANDLE.pm line
2.
Name "main::dbh" used only once: possible typo at /home/ruben/myootest.pl line
6 (#1)
(W) Typographical errors often show up as unique variable names.
If you had a good reason for having a unique name, then just mention
it again somehow to suppress the message. The use vars pragma is
provided for just this purpose.
SELECT * FROM patientsCan't locate object method "connect" via package "SQLHANDL
E" at
/home/ruben/myootest.pl line 6 (#2)
(F) You called a method correctly, and it correctly indicated a package
functioning as a class, but that package doesn't define that particular
method, nor does any of its base classes. See perlobj.
Uncaught exception from user code:
Can't locate object method "connect" via package "SQLHANDLE" at /home/ru
ben/myootest.pl line 6.
Any clues as to what I am doing wrong?
Ruben
------------------------------
Date: Wed, 14 Apr 1999 11:03:53 -0400
From: "Paul Tomsic" <ptomsic@pop.pitt.edu>
Subject: Directory Renaming on NT?
Message-Id: <7f2ap1$cuk$1@usenet01.srv.cis.pitt.edu>
Could someone possibly assist in renaming directories on NT?
I need to rename a directory from x-->y but directory(x) is in about 400
locations on a machine
Any assistance would be much appreciated..
Thanks
Paul
tomsicpj@msx.upmc.edu
------------------------------
Date: 14 Apr 1999 14:40:49 GMT
From: abigail@fnx.com (Abigail)
Subject: Re: Dummy Question about Perl Licence
Message-Id: <7f29dh$6r5$1@client2.news.psi.net>
haytounet@my-dejanews.com (haytounet@my-dejanews.com) wrote on MMLII
September MCMXCIII in <URL:news:7f1sin$uta$1@nnrp1.dejanews.com>:
.. Okay, here is my my question, which i am pretty sure most of people will find
.. stupid.
..
.. Anyway, I would like to know the conditions to use Perl. Can I use for non-
.. commercial and/or commercial use ... ?
The conditions come with Perl. Get the distribution and look up the two
licenses; pick the one you like most.
.. Thank you fo answering.
..
.. p.s: i tried to read the Faq but my browser crashes each time I try.
So? You don't need a browser to read the faq. 'man perlfaq' or
'perldoc perlfaq' will work fine.
Abigail
--
perl -MNet::Dict -we '(Net::Dict -> new (server => "dict.org")
-> define ("foldoc", "perl")) [0] -> print'
------------------------------
Date: Wed, 14 Apr 1999 10:27:49 -0500
From: therzog@knotech.com (Tim Herzog)
Subject: Re: Get Info from a file
Message-Id: <therzog-1404991027490001@therzog-host105.dsl.visi.com>
In article <7f1utf$oi$1@nnrp1.dejanews.com>, haytounet@my-dejanews.com wrote:
>Hello,
>
>i am designing a web site and I have a problem.
>
>I need to create a form with a list of product which comes from a file. This
>file is updated every three or four hours. Therefore i cannot use the classic
><select> tag.
>
>I would like to know if there is a script available that would do the job, as
>i am not a programmer.
Probably not, and this isn't the forum for it, but I'll point you in the
right direction anyway. In Perl, do something like:
if( open FILE, "productlist" ) {
@products = <FILE>;
close FILE;
}
print "Content-type: text/html\n\n";
print "<HTML><BODY><FORM><SELECT name=\"PRODUCTS\"";
foreach $product(@product) {
print "<OPTION>$product\n";
}
print "</SELECT></FORM></BODY></HTML>\n";
Then use the URL of the script in your web site to return the product list.
--
Tim Herzog
------------------------------
Date: Wed, 14 Apr 1999 14:44:11 GMT
From: mjbower@my-dejanews.com
Subject: how to find unused IP addresses on a subnet
Message-Id: <7f29jp$a29$1@nnrp1.dejanews.com>
I'd like to find the unused IP addresses on a subnet, at the moment I use a
script which loops and tests the result from a ping command, which takes 1
second per IP address.
Does anyone know a quick way of doing this ?
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
------------------------------
Date: 14 Apr 1999 16:07:32 -0100
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: how to find unused IP addresses on a subnet
Message-Id: <3714af34.0@newsread3.dircon.co.uk>
mjbower@my-dejanews.com wrote:
>
>
> I'd like to find the unused IP addresses on a subnet, at the moment I use a
> script which loops and tests the result from a ping command, which takes 1
> second per IP address.
>
> Does anyone know a quick way of doing this ?
>
You're still going to have to do the Moral Equivalent Of A Ping on each
machine whatever way you do it.
/J\
--
Jonathan Stowe <jns@gellyfish.com>
------------------------------
Date: Wed, 14 Apr 1999 16:08:51 BST
From: gml4410@ggr.co.uk (Lack Mr G M)
Subject: Re: how to find unused IP addresses on a subnet
Message-Id: <1999Apr14.160851@ukwit01>
In article <7f29jp$a29$1@nnrp1.dejanews.com>, mjbower@my-dejanews.com writes:
|>
|> I'd like to find the unused IP addresses on a subnet, at the moment I use a
|> script which loops and tests the result from a ping command, which takes 1
|> second per IP address.
|>
|> Does anyone know a quick way of doing this ?
You keep a database (a flat-file would do) or assigned IP addresses
and make sure you keep it up to date. You also ensure that nobody uses
addresses without being assigned them.
Just because you do not get an answer from ping does not mean that
the address is unused. The related host may just be offlien at that
point.
Procedural programming is not a substitute for proper procedures.
--
----------- Gordon Lack ----------------- gml4410@ggr.co.uk ------------
The contents of this message *may* reflect my personal opinion. They are
*not* intended to reflect those of my employer, or anyone else.
------------------------------
Date: Wed, 14 Apr 1999 10:18:29 -0500
From: therzog@knotech.com (Tim Herzog)
Subject: Re: HTML redirection to FTP site
Message-Id: <therzog-1404991018290001@therzog-host105.dsl.visi.com>
In article <924094054.10176.1.nnrp-11.c2de8dd8@news.demon.co.uk>,
oliver.buckie@actix.co.uk (Oliver Buckie) wrote:
>I am having difficulty redirecting users from my web page to an FTP
>site. The FTP site does not allow anonymous logins so the users need
>to login using a valid username and password. To do this, I have
>created a perl script which passes a username and password from a form
>on the web page. These are then used to redirect to the FTP site using
>the following syntax:
>
>"Location: ftp://<username>:<password>@FTPsiteIPaddr"
>
>This works but it puts the username & password into the URL display of
>the browser. Any way of avoiding this?
>
>Any help much appreciated.
>
>Oliver
No idea. Nor do I know what this has to do w/Perl. Try another newsgroup
like comp.infosystems.www.authoring.html or
comp.infosystems.www.authoring.cgi
--
Tim Herzog
------------------------------
Date: Wed, 14 Apr 1999 14:11:30 GMT
From: Jeremy Gurney <c4jgurney@my-dejanews.com>
Subject: Re: ide advice wanted
Message-Id: <7f27mb$8e5$1@nnrp1.dejanews.com>
In article <371446CA.DC2D346@ix.netcom.com>,
ranen@ix.netcom.com wrote:
> I just got a new computer with NT 4.0, got Perl installed and
> ready-to-rock. It's been so long since I used windoze i forgot about
> the backwards backslashes!
>
> How can I use my UNIX scripts and keep the fullpath directory names
> intact?
Forward slashes work just fine, in fact they're an awful lot safer to use in
code than having to remember to double backslahes.
I've also noticed that using single quoted backslahes (which is reputed to be
safe) has unpredictable behaviour when used as arguments to module functions
so I'd avoid doing it this way.
HTH,
Jeremy Gurney
SAS Programmer | Proteus Molecular Design Ltd.
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
------------------------------
Date: 14 Apr 1999 08:02:49 -0700
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: Looking for Tutoral Referenced in the Perl Cookbook
Message-Id: <3714a009@cs.colorado.edu>
[courtesy cc of this posting sent to cited author via email]
In comp.lang.perl.misc, danbeck@scott.net (Daniel Beckham) writes:
:Thanks, my linux box didn't have the tutorial in the doc directory
That's because no Linux distribution has anything resembling
tolerable documentation. The situation ranges from an embarrassment
to an atrocity. You can fix that.
http://synack.net/daemonlinux/
--tom
--
[End of diatribe. We now return you to your regularly scheduled
programming...]
--Larry Wall in Configure from the perl distribution
------------------------------
Date: Wed, 14 Apr 1999 14:39:32 GMT
From: andrew338@my-dejanews.com
Subject: mailer script question
Message-Id: <7f29b2$9tg$1@nnrp1.dejanews.com>
First time caller here. :) I have a form that is going to have mailer script
behind it. There is a twist, though. One of the form questions is a 4 pick
pull down menu, and if the user picks 1, I need the form input to be mailed
two two people, if the user picks 2, I need the form input to be mailed to
two different people, etc. This is the kind of thing Perl was created to do,
right? Has this script already been written and can I get it from somewhere?
Any guidance would be appreciated.
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
------------------------------
Date: Wed, 14 Apr 1999 10:36:48 -0500
From: therzog@knotech.com (Tim Herzog)
Subject: Re: mailer script question
Message-Id: <therzog-1404991036480001@therzog-host105.dsl.visi.com>
In article <7f29b2$9tg$1@nnrp1.dejanews.com>, andrew338@my-dejanews.com wrote:
>First time caller here. :) I have a form that is going to have mailer script
>behind it. There is a twist, though. One of the form questions is a 4 pick
>pull down menu, and if the user picks 1, I need the form input to be mailed
>two two people, if the user picks 2, I need the form input to be mailed to
>two different people, etc. This is the kind of thing Perl was created to do,
>right? Has this script already been written and can I get it from somewhere?
>Any guidance would be appreciated.
>
>-----------== Posted via Deja News, The Discussion Network ==----------
>http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
Go to www.worldwidemart.com and look for formmail. It's a Perl/CGI script
that's a front end interface to sendmail, and you can tweak it to do what
you want.
--
Tim Herzog
------------------------------
Date: Wed, 14 Apr 1999 10:10:58 -0500
From: therzog@knotech.com (Tim Herzog)
Subject: Re: Newbie Question: String Manipulation
Message-Id: <therzog-1404991010580001@therzog-host105.dsl.visi.com>
In article <7f25mq$phm$1@clarknet.clark.net>, "Aaron Glahe"
<glahea@wwdsi.com> wrote:
>I am using Perl 5.005
>
>I have a string
>
>$cgi1 = "GET /cgi-bin/test?xxxxx"
>
>I would like to strip out the first and last part and have "test" be left.
>How would I do that. I do not want to depend on looking for "test", but
>would rather
>strip off "GET /cgi-bin/" and "?xxxx"
>
>Thanks in advance.
$cgi1 =~ s/GET \/.*\/.*\?(.*)/$1/;
or to make it more readable:
$cgi1 =~ s|GET /.*/.*\?(.*)|$1|;
Since that first ".*" is greedy, it will match
GET /cgi-bin/test?xxxxx
as well as:
GET /cgi-bin/subdir/subdir/subdir/test?xxxxx
--
Tim Herzog
------------------------------
Date: Wed, 14 Apr 1999 10:38:08 -0500
From: therzog@knotech.com (Tim Herzog)
Subject: Re: Password encryption
Message-Id: <therzog-1404991038080001@therzog-host105.dsl.visi.com>
In article <371499a1@news.uk.ibm.net>, "Vincent Vanbiervliet"
<vvb@ibm.net> wrote:
>Hi,
>
>I need to be able to create .htaccess and .htpasswd files on the fly. To do
>this, I thought I'd use a perl script where you can enter a userid and
>password, and that would then create the needed files.
>Problem is that I don't see any way to create the password file. I know in a
>Unix environment, there's this command 'htpasswd' that you can use, but as
>far as I know, there's no win32 variant of it (I'm using WinNT).
Just reformat your hard drive and install Linux ;)
Sorry. Couldn't resist.
--
Tim Herzog
------------------------------
Date: Wed, 14 Apr 1999 10:22:50 +0100
From: Andrew Fry <andrewf@beausys.demon.co.uk>
Subject: Re: Perl or C?
Message-Id: <UDAKlAAq5FF3Ew+8@beausys.demon.co.uk>
In article <Pine.HPP.3.95a.990411155120.8214B-100000@hpplus01.cern.ch>,
Alan J. Flavell <flavell@mail.cern.ch> writes
>On Sun, 11 Apr 1999 airplanes@altavista.net wrote:
>
>> Which is a better language to lean - C or Perl???
>
>For what?
>
>Programming is a way of thinking about problem-solving. What language
>you do it in is sort-of secondary.
For very simple problems, this is true.
In practice, some languages are better suited to certain situations or
types of problem than others. As others have pointed out, C and Perl are
different, and comparing the two is rather like trying to compare
apples and pears.
>
>Of course, people whose first language was Lisp may be expected to think
>differently. And it's commonly reputed (in our field) that "physicists
>write FORTRAN in any language" (although that's less and less true with
>time). Only last month a colleague showed me a program allegedly written
>in C++: in reality it was perfectly obvious that it was FORTRAN,
>transcribed into a different language, and not really C++ at all, apart
>from the surface syntax. But he's an old-timer - like me only more so.
>
>C provides powerful facilities for shooting yourself in the foot,
>in all sorts of detailed low-level ways that Perl can shield you from.
>Which is not to say that you can't shoot yourself in the foot with
>Perl, if you try...
>
>One respected colleague considers that the best way to start programming
>is with Java, even though you subsequently migrate to something else for
>your "real work". It's the object orientation, you see. I rather
>suspect he's right. But it all depends on what you want to achieve.
>No language is ideal for everything: if there was, then the others would
>all have died out, it stands to reason.
Are we talking about an absolute newcomer to programming ?
If so, I would have thought that Java was quite inappropriate.
Best start with BASIC, or some very simple C or Perl ... move onto
object orientation / abstraction and all the rest later.
Let's not "run before we can walk".
>
>[disclaimer: I wrote my first program in 1958, so I'm too far away from
>the problem to have a clear idea how I would want to start again today.]
>
---
Andrew Fry
"Time flies like an arrow. Fruit flies like a banana". (Groucho Marx).
------------------------------
Date: Wed, 14 Apr 1999 14:30:04 GMT
From: bart.lateur@skynet.be (Bart Lateur)
Subject: Re: Q: Convert two newlines to \n<p>
Message-Id: <3715a63f.18645389@news.skynet.be>
Tom Christiansen wrote:
>n comp.lang.perl.misc, bart.lateur@skynet.be (Bart Lateur) writes:
>:Getting rid of all "\r" may be a safe idea, in any case.
>: tr/\r//d;
>
>Oh good. You're on a Mac, and you've just deleted all the linefeeds.
You've got me there!
/\n/ and tr/\r//d;
Bart.
------------------------------
Date: 14 Apr 1999 15:46:07 -0100
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: Q: Convert two newlines to \n<p>
Message-Id: <3714aa2f.0@newsread3.dircon.co.uk>
Tom Christiansen <tchrist@mox.perl.com> wrote:
> In comp.lang.perl.misc, Jonathan Stowe <gellyfish@gellyfish.com> writes:
> :Are you sure you have \n\n where you think you have and not \r\n\r\n
> :instead?
>
> All systems end text lines in "\n". Are you forgetting the
> transparent conversions?
>
Indeed they do for files created on the same system. But for, say, a file
created in the DOS world and transferred in a binary mode - NFS or samba
say then that is not strictly the case:
fatmog:~$ od -c test.blah
0000000 t h i s \r \n i s \r \n a \r \n t e
0000020 s t \r \n i s n t \r \n i t \r \n
0000036
test.blah was created in DOS and then FTP'd in binary mode.
fatmog:~$ perl -pe 's/\r\n/<P>\n/g' test.blah
this<P>
is <P>
a<P>
test<P>
isnt<P>
it<P>
Yes all lines do end in \n but two empty lines are not necessarily \n\n.
/J\
--
Jonathan Stowe <jns@gellyfish.com>
------------------------------
Date: 14 Apr 1999 09:03:59 -0700
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: Q: Convert two newlines to \n<p>
Message-Id: <3714ae5f@cs.colorado.edu>
[courtesy cc of this posting sent to cited author via email]
In comp.lang.perl.misc,
Jonathan Stowe <gellyfish@gellyfish.com> writes:
:test.blah was created in DOS and then FTP'd in binary mode.
Don't do that. Duh.
--tom
--
"The purpose of most computer languages is to lengthen your resume by
a word and a comma." --Larry Wall
/* dbmrefcnt--; */ /* doesn't work, rats */
--Larry Wall in hash.c from the v4.0 perl source code
------------------------------
Date: Wed, 14 Apr 1999 10:43:02 -0500
From: "Keith G. Murphy" <keithmur@mindspring.com>
Subject: Re: Reading from STDIN, VMSperl + DCL
Message-Id: <3714B786.140CB533@mindspring.com>
Rich Lafferty wrote:
>
> Excuse the crosspost; I'm not sure at this point if my problem
> is more perl-related or DCL-related.
>
> I've run into an unusual situation with perl 5.004_01 under
> OpenVMS/AXP 7.1.
>
> This:
>
> $usrinput = <STDIN>; # asking user a yes-or-no question
>
> works fine when I run the program directly from the DCL prompt,
> i.e.,
>
> $ perl -w editmail.plx
>
> Unfortunately, since this program's going to be called from MAIL
> (it's a wrapper to use a nonstandard editor with MAIL$EDIT), I
> can't call it directly; instead, I call it from a one-line DCL
> script containing the 'perl' line above.
>
> When I do so, STDIN doesn't block; it just cruises right on past
> that line without stopping.
>
[snip]
Thinking *way* back to my VMS days, don't you have to
$ DEFINE/USER SYS$INPUT SYS$COMMAND
in the line directly prior to your Perl invocation? Tells the command
interpreter to temporarily redirect the input (which is otherwise coming
from your command file itself) to be from the keyboard. IIRC, you need
/USER to make sure it's a temporary redirection (so it will keep reading
the command file after the Perl script finishes).
Of course, someone on the VMS group has probably answered this long
ago...
------------------------------
Date: Wed, 14 Apr 1999 14:41:07 GMT
From: kscurry@my-dejanews.com
Subject: regex - meta char's
Message-Id: <7f29e1$a0p$1@nnrp1.dejanews.com>
I am trying to use regex to match query data with wildcards
( *,? ) but I want other special characters ((,),{,},.,^) to
be interpreted literally.
Any help would be appreciated.
monkeyman
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
------------------------------
Date: Wed, 14 Apr 1999 17:14:55 +0200
From: "Vincent Vanbiervliet" <vvb@ibm.net>
Subject: Re: regex - meta char's
Message-Id: <3714b05c@news.uk.ibm.net>
Escape them (use '\' in front of them)
<kscurry@my-dejanews.com> wrote in message
news:7f29e1$a0p$1@nnrp1.dejanews.com...
>
>
>
> I am trying to use regex to match query data with wildcards
> ( *,? ) but I want other special characters ((,),{,},.,^) to
> be interpreted literally.
>
> Any help would be appreciated.
>
> monkeyman
>
>
> -----------== Posted via Deja News, The Discussion Network ==----------
> http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
------------------------------
Date: Wed, 14 Apr 1999 10:13:11 -0500
From: therzog@knotech.com (Tim Herzog)
Subject: Re: regex - meta char's
Message-Id: <therzog-1404991013110001@therzog-host105.dsl.visi.com>
In article <7f29e1$a0p$1@nnrp1.dejanews.com>, kscurry@my-dejanews.com wrote:
>I am trying to use regex to match query data with wildcards
>( *,? ) but I want other special characters ((,),{,},.,^) to
>be interpreted literally.
>
>Any help would be appreciated.
Just precede characters that you want to be interpreted literally with a
"\" For example:
/\*.*/
will match "*hobo" and "*mail" but not "hobo"
--
Tim Herzog
------------------------------
Date: Wed, 14 Apr 1999 14:43:32 GMT
From: Jeremy Gurney <c4jgurney@my-dejanews.com>
Subject: sort readdir on NT
Message-Id: <7f29ij$a23$1@nnrp1.dejanews.com>
I recently noticed some curious behaviour in one of my CGI apps that was
listing the contents of a directory. Most of the files were in alphabetical
order (as I had intended) but the most recent files were tacked on to the end
of the list - so the list was neither sorted cronologically or
alphabetically.
The code I was using is similar to the following;
opendir(LISTDIR,"my\path\") || die "$!";
foreach (sort readdir(LISTDIR)) {
print $_ ."\n";
}
I found that by removing the sort I got what I was after - a nice alphabetical
list of my files.
I originally copied this code snippet from page 143 of the gecko book which
says that it should work. Does anyone have any Ideas what's going on here?
The specifics are NT4 SP3 (NTFS), AP build 509.
Cheers,
Jeremy Gurney
SAS Programmer | Proteus Molecular Design Ltd.
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
------------------------------
Date: Wed, 14 Apr 1999 15:46:54 GMT
From: NukeEmUp@ThePentagon.com (David Cantrell)
Subject: Re: sort readdir on NT
Message-Id: <3714b678.88336170@news.insnet.net>
On Wed, 14 Apr 1999 14:43:32 GMT, Jeremy Gurney
<c4jgurney@my-dejanews.com> enlightened us thusly:
>I recently noticed some curious behaviour in one of my CGI apps that was
>listing the contents of a directory. Most of the files were in alphabetical
>order (as I had intended) but the most recent files were tacked on to the end
>of the list - so the list was neither sorted cronologically or
>alphabetically.
>
>The code I was using is similar to the following;
>
>opendir(LISTDIR,"my\path\") || die "$!";
>foreach (sort readdir(LISTDIR)) {
> print $_ ."\n";
>}
>
>I found that by removing the sort I got what I was after - a nice alphabetical
>list of my files.
The NTFS filesystem returns filenames alphabetically; however, whilst
it does retain case information in filenames (that is, you can have a
file like 'FoObAr'), case is _ignored_ on any file operations - so
that file can also be referred to as 'foobar' and 'FOOBAR'. Sometimes
I think this is a Good Thing and sometimes not ;-)
Removing the 'sort' from your code means that readdir returns files in
the order NT gives them - which is sorted. But when you use perl's
sort function, it applies a _case_sensitive_ sort. An example is
probably more enlightening ;-)
C:\>perl -e "print join',',sort qw(foo BAR FOO bar)"
BAR,FOO,bar,foo
That applies perl's usual case-sensitive sort to the list of words.
C:\>perl -e "print join',',sort{lc($a)cmp lc($b)} qw(foo BAR FOO bar)"
BAR,bar,foo,FOO
That applies a custom case-insensitive search.
I would guess that the recently-added files in your directory all have
lower-case names, so perl sorts them after the upper-case files,
whereas NT mixes them up in case-insensitive order.
[Copying newsgroup posts to me by mail is considered rude]
--
David Cantrell, part-time Unix/perl/SQL/java techie
full-time chef/musician/homebrewer
http://www.ThePentagon.com/NukeEmUp
------------------------------
Date: Wed, 14 Apr 1999 04:22:12 -0400
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: TPJ still shipping?
Message-Id: <k7j1f7.0g6.ln@magna.metronet.com>
Uri Guttman (uri@home.sysarch.com) wrote:
: >>>>> "TM" == Tad McClellan <tadmc@metronet.com> writes:
: TM> Wappinger Mary (revjack@radix.net) wrote:
: TM> : Is The Perl Journal still shipping? I ordered a year's subscription and
: TM> : all the back issues almost a month ago, and I have yet to receive them.
: TM> : Mail to Mr. Orwant doesn't seem to be getting me anywhere.
: TM> : Has anyone else successfully purchased TPJ?
: TM> I ordered all of the back issues on March 31, got them on
: TM> April 9.
: what's with all these orders for back issues? you can't call yourselves
: perl hackers if you haven't been charter subscribers from issue 1?
: what's wrong with you?
I let my subscription lapse for several months.
Easier to just get them all than to get just then ones I missed.
--
Tad McClellan SGML Consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Wed, 14 Apr 1999 10:04:46 -0500
From: therzog@knotech.com (Tim Herzog)
Subject: Re: Unitialized var errors & -w flag
Message-Id: <therzog-1404991004460001@therzog-host105.dsl.visi.com>
In article <37149eb1@cs.colorado.edu>, tchrist@mox.perl.com (Tom
Christiansen) wrote:
> [courtesy cc of this posting sent to cited author via email]
>
>In comp.lang.perl.misc, Gordon Shannon <gordon.shannon@Central.Sun.COM> writes:
>: % perl -we 'my $foo; print "OK\n" if !$foo'
>: It seems inconsistent. Either both should produce the warning
>: or neither should. Obviously Perl is looser with the concept of
>: "truth" than that of actual value.
>
>Perl's notion of truth is much more powerful and flexible than yours.
>Don't write == 0 or == 1 or eq '' or ne '' or m/./ or anything like that.
>There are many valid values of true. There are several valid values
>of false. Let your true be true, your false be false. Leave it at that.
>Don't freak.
I still have a problem with unitialized variable warnings for global
variables declared in one file and referenced in another, e.g.:
------ test1.pl ------
#!/usr/bin/perl
require "test2.pl";
$global_var = "boohoo";
PrintBooHoo();
------ test2.pl ------
sub PrintBooHoo
{
print "$global_var\n";
}
----------------------
Anyone know if there is some trick or workaround to either disable the
"unitialized variable" warning (but not the other warnings), or do the
equivalent of an "extern" declaration (as much as I'd hate having to do
that)?
--
Tim Herzog
------------------------------
Date: Wed, 14 Apr 1999 08:44:03 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Unitialized var errors & -w flag
Message-Id: <MPG.117e579ef8bd14149898ab@nntp.hpl.hp.com>
[Posted and a courtesy copy sent.]
In article <37149722.AECC97E4@Central.Sun.COM> on Wed, 14 Apr 1999
07:24:50 -0600, Gordon Shannon <gordon.shannon@Central.Sun.COM> says...
> A point of philosophy. I disagree with the way Perl acts when
> -w is on, with regard to unitialized variables. Can anyone
> change my mind?
...
> % perl -we 'my $foo; print "OK\n" if $foo != 1'
> Use of uninitialized value at -e line 1.
...
> % perl -we 'my $foo; print "OK\n" if !$foo'
...
> It seems inconsistent. Either both should produce the warning
> or neither should. Obviously Perl is looser with the concept of
> "truth" than that of actual value.
>
> Issue 2: I don't think either should produce a warning! I don't see
> the harm in using unitialized variables.
As Tom Christiansen pointed out, there is no harm in using undefined
variables in direct Boolean tests, as in your second example. So there
is no warning. This is a great convenience.
In your first example, you are using an undefined variable to calculate
the value of an expression, so perl warns you about it. As it should.
(But it should say 'undefined' rather than 'uninitialized'. '$foo =
undef;' initializes $foo, but it is still undefined.)
--
(Just Another Larry) Rosler
Hewlett-Packard Company
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: 12 Dec 98 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Special: Digest Administrivia (Last modified: 12 Dec 98)
Message-Id: <null>
Administrivia:
Well, after 6 months, here's the answer to the quiz: what do we do about
comp.lang.perl.moderated. Answer: nothing.
]From: Russ Allbery <rra@stanford.edu>
]Date: 21 Sep 1998 19:53:43 -0700
]Subject: comp.lang.perl.moderated available via e-mail
]
]It is possible to subscribe to comp.lang.perl.moderated as a mailing list.
]To do so, send mail to majordomo@eyrie.org with "subscribe clpm" in the
]body. Majordomo will then send you instructions on how to confirm your
]subscription. This is provided as a general service for those people who
]cannot receive the newsgroup for whatever reason or who just prefer to
]receive messages via e-mail.
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 5381
**************************************