[10789] in Perl-Users-Digest
Perl-Users Digest, Issue: 4391 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Dec 9 16:07:31 1998
Date: Wed, 9 Dec 98 13:01:34 -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 Wed, 9 Dec 1998 Volume: 8 Number: 4391
Today's topics:
Re: Is there a 'predeclare subs' module ? (Mark-Jason Dominus)
Left and right halves of s/// parsed differently? chess@watson.ibm.com
Re: Left and right halves of s/// parsed differently? (brian d foy)
Re: Left and right halves of s/// parsed differently? (Larry Rosler)
Re: Perl ARRAYs <gwebb@reedtech.com>
Re: Perl ARRAYs (brian d foy)
Re: Perl ARRAYs <uri@ibnets.com>
Perl code for CM11a X10 interface keatlim@my-dejanews.com
Regular Expression help <gala@sonic.net>
SCO Unix <rob_a@unipharm.com>
Re: SCO Unix <che@debian.org>
scoped vars and nesting subroutines (Bill Moseley)
Re: scoped vars and nesting subroutines <uri@ibnets.com>
Re: Still just a quickie (Greg Ward)
strict bug in CGI.PM? <nospam.eam@starfire.mlb.semi.harris.com>
Re: test for a directory (Jim Matzdorff)
Re: using the command system() in perl cgi (Larry Rosler)
what _is_ shellwords.al? <mhofer@jpmorgan.com>
Special: Digest Administrivia (Last modified: 12 Mar 98 (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 9 Dec 1998 14:35:53 -0500
From: mjd@op.net (Mark-Jason Dominus)
Subject: Re: Is there a 'predeclare subs' module ?
Message-Id: <74mjep$fq5$1@monet.op.net>
In article <39u2z5rzga.fsf@ibnets.com>, Uri Guttman <uri@ibnets.com> wrote:
>>>>>> "MD" == Mark-Jason Dominus <mjd@op.net> writes:
> MD> # Who is the greater pinhead? You decide.
>
>don't ask questions you don't want answered!
I don't. But you never answered!
>definitely a major waste of your neurons.
Thanks! I'm on vacation this week.
>why not add a makefile to build the subs include the way we use make
>to get dependencies in c.
That would be dumb. Who wants to maintain a makefile?
> and what about parsing sub in weirdly formatted files?
I thought I already discussed that. It's a problem and it's always
going to be a problem.
>so your module (if you can call it that :-) is broken.
So is `etags', but that doesn't stop it from being useful.
------------------------------
Date: Wed, 09 Dec 98 14:37:51 est
From: chess@watson.ibm.com
Subject: Left and right halves of s/// parsed differently?
Message-Id: <366ed18f.3e89.chess@watson.ibm.com>
I'm trying to use s/// to substitute one string for another,
where either or both of the strings may contain arbitrary
metacharacters, and I don't understand what's going on. I
would think I would have to use \Q \E or equivalent on both
strings, to avoid wrongness; but in fact it only works if I
use it on the first string, but not the second. As in:
$from = "big\\noses";
$to = "large\\eyes";
$this = "clowns\\have\\big\\noses\\here";
$this =~ s/\Q$from\E/$to/g;
print "$this\n";
It *works* fine this way, but I'd really like to understand why
it fails if I write
$this =~ s/\Q$from\E/\Q$to\E/g;
If I do that, it prints:
clowns\have\large\\eyes\here
Whence that second consecutive backslash? I'm sure I'm missing
something horribly obvious...
- -- -
David M. Chess Which orbital mind control
High Integrity Computing Lab lasers are you referring to?
IBM Watson Research
------------------------------
Date: Wed, 09 Dec 1998 15:07:30 -0500
From: comdog@computerdog.com (brian d foy)
Subject: Re: Left and right halves of s/// parsed differently?
Message-Id: <comdog-ya02408000R0912981507300001@news.panix.com>
In article <366ed18f.3e89.chess@watson.ibm.com>, chess@watson.ibm.com posted:
> $this =~ s/\Q$from\E/$to/g;
>
> print "$this\n";
>
> It *works* fine this way, but I'd really like to understand why
> it fails if I write
>
> $this =~ s/\Q$from\E/\Q$to\E/g;
remember, one side is a regex and one side is a double quotish like
thingy.
> If I do that, it prints:
>
> clowns\have\large\\eyes\here
it does that because that is what \Q is supposed to do. compare:
$\ = "\n";
print "this is a \\slash";
print "\Qthis is a \\slash";
print quotemeta("this is a \\slash");
see the docs on these for more details.
--
brian d foy <brianNOSPAM@NOSPAM.smithrenaud.com>
CGI Meta FAQ <URL:http://computerdog.com/CGI_MetaFAQ.html>
remove NOSPAM or don't. it doesn't matter either way.
------------------------------
Date: Wed, 9 Dec 1998 12:20:00 -0800
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Left and right halves of s/// parsed differently?
Message-Id: <MPG.10d87b4d38fe2f5f9898b4@nntp.hpl.hp.com>
[Posted to comp.lang.perl.misc and a copy mailed.]
In article <366ed18f.3e89.chess@watson.ibm.com> on Wed, 09 Dec 98
14:37:51 est, chess@watson.ibm.com <chess@watson.ibm.com> says...
> I'm trying to use s/// to substitute one string for another,
> where either or both of the strings may contain arbitrary
> metacharacters, and I don't understand what's going on. I
> would think I would have to use \Q \E or equivalent on both
> strings, to avoid wrongness; but in fact it only works if I
> use it on the first string, but not the second. As in:
>
> $from = "big\\noses";
> $to = "large\\eyes";
>
> $this = "clowns\\have\\big\\noses\\here";
>
> $this =~ s/\Q$from\E/$to/g;
>
> print "$this\n";
>
> It *works* fine this way, but I'd really like to understand why
> it fails if I write
>
> $this =~ s/\Q$from\E/\Q$to\E/g;
>
> If I do that, it prints:
>
> clowns\have\large\\eyes\here
>
> Whence that second consecutive backslash? I'm sure I'm missing
> something horribly obvious...
You might understand it more clearly if you replaced your input strings
by these, which are functionally identical:
$from = 'big\noses';
$to = 'large\eyes';
$this = 'clowns\have\big\noses\here';
The statement after interpolation of the variables is:
$this =~ s/\Qbig\noses\E/\Qlarge\eyes\E/g;
Now, the effect of \Q (quotemeta) is to escape (with a leading
backslash) any metacharacters in the string. So after the \Q
processing, the statement becomes:
$this =~ s/big\\noses/large\\eyes/g;
The escaped backslash in the regex portion matches the single backslash
in $this. The two backslashes in the substitution are two backslashes.
Hence that second consecutive backslash!
--
(Just Another Larry) Rosler
Hewlett-Packard Company
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Wed, 09 Dec 1998 14:19:11 -0500
From: Garth Webb <gwebb@reedtech.com>
To: Tad McClellan <tadmc@metronet.com>
Subject: Re: Perl ARRAYs
Message-Id: <366ECD2F.DA32F40@reedtech.com>
Yes, I know the many ways to take a Perl reference, but thats not what
I really meant in my post.
I admit I misued the built in function 'ref'. What I really want to
know is given the STRING value:
'ARRAY(0x2a79ac)'
how can that STRING value be used to access the array at memory location
0x2a79ac?
Tad McClellan wrote:
> Garth Webb (gwebb@reedtech.com) wrote:
> : I have a problem referencing Perl arrays that I used to know the answer
> : to, but now I can't remember or figure out how its done.
>
> And for some reason you are unable to read the documentation
> about references (perlref.pod) that are on your hard disk?
>
> How to take a reference is covered very near the top...
>
> : Say you have an array:
>
> : my @a = ("foo")
> : my $ref = ref(@a);
>
> : The variable $ref now contains the string:
>
> : 'ARRAY(0x2a79ac)'
>
> No it doesn't.
>
> print "'$ref'\n"; # See?
>
> You should look up ref() in the perlfunc.pod man page if
> you want to use ref()...
>
> -----------------
> #!/usr/bin/perl -w
>
> my @a = qw(foo bar);
>
> my $ref = \@a; # take a reference
>
> foreach (@$ref) # derefernece it
> {print "$_\n"}
> -----------------
>
> You don't need to make @a first either:
>
> -----------------
> #!/usr/bin/perl -w
>
> my $ref = [ qw(foo bar) ]; # take a reference to an anonymous array
>
> foreach (@$ref) # derefernece it
> {print "$_\n"}
> -----------------
>
> --
> Tad McClellan SGML Consulting
> tadmc@metronet.com Perl programming
> Fort Worth, Texas
--
--------------------
Garth Webb
Software Developer
Reed Technology and Information Services
gwebbQ@Qreedtech.com
(To reply to me, please remove the 'Q's from my email address. Thanks.)
------------------------------
Date: Wed, 09 Dec 1998 15:24:13 -0500
From: comdog@computerdog.com (brian d foy)
Subject: Re: Perl ARRAYs
Message-Id: <comdog-ya02408000R0912981524130001@news.panix.com>
In article <366ECD2F.DA32F40@reedtech.com>, Garth Webb <gwebb@reedtech.com> posted:
> 'ARRAY(0x2a79ac)'
>
> how can that STRING value be used to access the array at memory location
> 0x2a79ac?
Perl wasn't made to do things with pointers. you shouldn't
have to worry about the low level memory stuff.
--
brian d foy <brianNOSPAM@NOSPAM.smithrenaud.com>
CGI Meta FAQ <URL:http://computerdog.com/CGI_MetaFAQ.html>
remove NOSPAM or don't. it doesn't matter either way.
------------------------------
Date: 09 Dec 1998 15:17:40 -0500
From: Uri Guttman <uri@ibnets.com>
To: Garth Webb <gwebb@reedtech.com>
Subject: Re: Perl ARRAYs
Message-Id: <39n24xrrx7.fsf@ibnets.com>
>>>>> "GW" == Garth Webb <gwebb@reedtech.com> writes:
GW> Yes, I know the many ways to take a Perl reference, but thats not
GW> what I really meant in my post.
GW> I admit I misued the built in function 'ref'. What I really
GW> want to know is given the STRING value:
GW> 'ARRAY(0x2a79ac)'
GW> how can that STRING value be used to access the array at memory
GW> location 0x2a79ac?
you can't. you should never need to use the string form of a reference
value. why do you want to do that?
uri
--
Uri Guttman Hacking Perl for Ironbridge Networks
uri@sysarch.com uri@ibnets.com
------------------------------
Date: Wed, 09 Dec 1998 20:39:44 GMT
From: keatlim@my-dejanews.com
Subject: Perl code for CM11a X10 interface
Message-Id: <74mn6f$nm5$1@nnrp1.dejanews.com>
I was wondering if anyone has made a perl code to interface with the CM11A
and willing to share it with me! I am trying to make a web interface so that
it can be run from any web browser to control the house!
Any help will be greatly appreciated!
Thanks!
-Keat
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
------------------------------
Date: Wed, 9 Dec 1998 12:34:45 -0800
From: "Gala Grant" <gala@sonic.net>
Subject: Regular Expression help
Message-Id: <74mmr1$u7h$1@ultra.sonic.net>
Can anyone tell me why
if ($line =~ /<a href="(.*)"?/i)
isn't stopping at the first " it finds?
Thanks
Gala Grant
gala@sonic.net
------------------------------
Date: Wed, 9 Dec 1998 12:25:02 -0000
From: "Robert Annandale" <rob_a@unipharm.com>
Subject: SCO Unix
Message-Id: <74mmcg$akc$1@fountain.mindlink.net>
I tried to install perl5.003 on SCO 5.04.
I used the command 'sh configure' and a snazzy script ran some checks on my
system.
Then it bombed with the error 'Your C compiler "cc" doesn't seem to be
working!'
''You better start hunting for one and let me know about it.'
Snazzy eh?
Anyways, does this mean I need to splurge 400 greenbacks for a SCO
Development Kit?
Rob Annandale
Vancouver, BC
------------------------------
Date: 09 Dec 1998 12:47:02 -0800
From: Ben Gertzfield <che@debian.org>
Subject: Re: SCO Unix
Message-Id: <yttn24xxcu1.fsf@gilgamesh.cse.ucsc.edu>
>>>>> "Robert" == Robert Annandale <rob_a@unipharm.com> writes:
Robert> I tried to install perl5.003 on SCO 5.04. I used the
Robert> command 'sh configure' and a snazzy script ran some checks
Robert> on my system. Then it bombed with the error 'Your C
Robert> compiler "cc" doesn't seem to be working!' ''You better
Robert> start hunting for one and let me know about it.'
Robert> Snazzy eh?
Robert> Anyways, does this mean I need to splurge 400 greenbacks
Robert> for a SCO Development Kit?
You could always install the free and open source GNU C compiler,
gcc.
There are probably binaries for SCO 5.04 available somewhere on the
web. I'd try a web search.
Alternatively, SCO is supposed to have Linux emulation nowadays, so
you could just download one of the plethora of Linux binaries of
Perl or GCC and use SCO's emulation. However, I don't know how
good SCO's emulation is right now.
Judging from the posts on this newsgroup, SCO is notoriously bad at
supporting software like Perl and GCC (problems with I/O stutters at
high load with Perl were recently discussed on this newsgroup) so you
may wish to consider an alternative x86 operating system like Linux or
BSD.
Ben
--
Brought to you by the letters Z and R and the number 13.
"He's kissing Christian.. and it's making you die." -- that dog.
Debian GNU/Linux -- where do you want to go tomorrow? http://www.debian.org/
I'm on FurryMUCK as Che, and EFNet and YiffNet IRC as Che_Fox.
------------------------------
Date: 09 Dec 1998 19:21:30 GMT
From: moseley@best.com (Bill Moseley)
Subject: scoped vars and nesting subroutines
Message-Id: <366ecdba$0$199@nntp1.ba.best.com>
I've been nesting subroutines. I want "global" vars that are available to a
collection of subroutines, but not elsewhere.
In real life my "helper_sub" gets called recursively (which is why I want
local-global vars - seems like a waste stack space to recursively pass
variables that don't change).
sub main_sub {
my $foo;
...
&helper_sub;
sub helper_sub {
my $bar;
(do something with $foo and $bar)
} # end inner sub
} # end main_sub
Is there a better way to have "local global" vars? Packages would seem to be
the answer, but I want these subroutines to have access the the current
packages globals, too. But I admit that I haven't felt the need to break my
little CGI scripts into packages.
Also, interesting how helper_sub is not hidden outside of main_sub. I would
have expected that helper_sub to be available to main_sub only.
--------------
Bill Moseley
moseley@best.com
------------------------------
Date: 09 Dec 1998 15:25:20 -0500
From: Uri Guttman <uri@ibnets.com>
To: moseley@best.com (Bill Moseley)
Subject: Re: scoped vars and nesting subroutines
Message-Id: <39k901rrkf.fsf@ibnets.com>
>>>>> "BM" == Bill Moseley <moseley@best.com> writes:
BM> I've been nesting subroutines. I want "global" vars that are
BM> available to a collection of subroutines, but not elsewhere.
<code snip>
BM> Is there a better way to have "local global" vars? Packages would
BM> seem to be the answer, but I want these subroutines to have access
BM> the the current packages globals, too. But I admit that I haven't
BM> felt the need to break my little CGI scripts into packages.
packages do not hide anything. they just create a hierarchal names
system for globals.
BM> Also, interesting how helper_sub is not hidden outside of
BM> main_sub. I would have expected that helper_sub to be available
BM> to main_sub only.
perl does not support nested sub ala PL/I. all named subs are
global. you can create anonymous subs and store their refs in local
vars:
(this is file/module level my)
my $private_sub = sub { blah } ;
and if this is a module you can just use my vars to create my level
globals.
but even better is to use a block surrounding the private vars and the
subs that use them:
{
my $private_var ;
sub foo {
my( $bar ) = @_ ;
blah with $private_var and $bar
foo( blah ) ;
}
}
hth,
uri
--
Uri Guttman Hacking Perl for Ironbridge Networks
uri@sysarch.com uri@ironbridgenetworks.com
------------------------------
Date: 9 Dec 1998 20:36:33 GMT
From: gward@thrak.cnri.reston.va.us (Greg Ward)
Subject: Re: Still just a quickie
Message-Id: <74mn0h$2l3$2@news0-alterdial.uu.net>
Antony <amcnulty@nortel.co.uk> wrote:
> My script needs to be run a subroutine every time the timestamp of a certain
> file is altered.
>
> I tried a couple of ideas but most seem to impractical and too memory
> consuming.
Yeah, that sounds pretty hairy. I can't think of anything offhand that
doesn't boil down to a greedy polling operation. If possible, you might
want to replace the file that you want to watch with a FIFO (named
pipe), and attach one end to your script. Then, when it received input
on the pipe (ie. some other process opens and writes to it), it can wake
up and do the appropriate thing. This isn't *exactly* the same as
"running every time the timestamp is altered", but you can probably do
what you wanted to do.
BTW, I have no idea how portable that would be -- named pipes are
definitely a Unix-ism, but they might be supported by other OS's. I
don't know.
> Also, anyone ever come up with many problems in porting UNIX perl scripts
> over to WinNT ?
Sure, replace NT with Linux. Probably save you time in the long run.
(Also, if you run Linux, you could always hack the kernel filesystem
code to watch that file for you, and send a signal to your script when
the file is updated... JUST KIDDING!)
Greg
--
Greg Ward - software developer gward@cnri.reston.va.us
Corporation for National Research Initiatives
1895 Preston White Drive voice: +1-703-620-8990 x287
Reston, Virginia, USA 20191-5434 fax: +1-703-620-0913
------------------------------
Date: Wed, 09 Dec 1998 13:59:29 -0500
From: Software Sciences <nospam.eam@starfire.mlb.semi.harris.com>
Subject: strict bug in CGI.PM?
Message-Id: <366EC891.A3408987@starfire.mlb.semi.harris.com>
I wrote an upload script that uploads files from DOS to unix using
cgi.pm. It works great, but when I enable "use strict;" It quits working
at the read step. When I compile it with -w, I get no warnings
whatsoever. When I take out "use strict" it works perfectly. It's most
vexing.
I researched it on
http://stein.cshl.org/WWW/software/CGI/cgi_docs.html#upload_caveats
and I did find this note:
1.Fixed problem with "use strict" and file uploads (thanks to
Peter Haworth)
Unfortunately, I couldn't find any details on the bug, and a search of
DejaNews for both "upload strict" and "Haworth perl" wasn't helpful
either.
Does anyone know if what I'm seeing is that bug? Second, can anyone tell
me how to determine my system's version of cgi.pm?
Thank-You.
------------------------------
Date: 9 Dec 1998 12:20:50 -0800
From: syran@shell1.ncal.verio.com (Jim Matzdorff)
Subject: Re: test for a directory
Message-Id: <74mm32$r5d$1@shell1.ncal.verio.com>
of course, if you don't care about portability (or if you know where you'll be running this script), and you don't care about making a system
call, then you can simply do this:
my (@content_names) = split (/\n/, `ls -1Fa`);
@dirs = grep(/\//, sort @content_names);
@files = grep(!/\//, sort @content_names);
then, @dirs contains directories (with the .., .) and @files contain only the files. And they are sorted. And to rid yourself of the ..,. --
just change the ls command ls "ls -1FA".
Again, this is only if you know what your system supports :)
--jim
------------------------------
Date: Wed, 9 Dec 1998 12:07:07 -0800
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: using the command system() in perl cgi
Message-Id: <MPG.10d8784a4c963ade9898b3@nntp.hpl.hp.com>
[Posted to comp.lang.perl.misc and a copy mailed.]
In article <d80m47.cl4.ln@magna.metronet.com> on Wed, 9 Dec 1998
08:08:13 -0600, Tad McClellan <tadmc@metronet.com> says...
...
> 1) check the return value of the system call
>
> system("pgp filename") && die "could not run system() $!";
>
>
> 2) use the full path to the executable
>
> system("/usr/local/bin/pgp filename") && die "could not run system() $!";
Surely you mean this instead of $! (quoted from perlvar):
$CHILD_ERROR
$?
The status returned by the last pipe close, backtick (``) command,
or system() operator. ...
--
(Just Another Larry) Rosler
Hewlett-Packard Company
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Wed, 09 Dec 1998 14:58:32 -0500
From: "Michael D. Hofer" <mhofer@jpmorgan.com>
Subject: what _is_ shellwords.al?
Message-Id: <366ED668.2507@jpmorgan.com>
Trying to run a perldoc under perl 5.004_04, I get
"Can't locate auto/Text/ParseWords/shellwords.al in @INC (@INC contains:
/home/mhofer/bin /home/mhofer/lib
/opt/perl5.004_04/lib/sun4-solaris/5.00404 /opt/perl5.004_04/lib
/opt/perl5.004_04/lib/site_perl/sun4-solaris
/opt/perl5.004_04/lib/site_perl .) at /opt/perl5.004_04/bin/perldoc line
74"
So after trying to find shellwords.al _somewhere_ within the
installation, which I did myself, and followed all recommended defaults,
I finally looked at the perldoc script itself and saw at line 74:
"unshift(@ARGV,shellwords($ENV{"PERLDOC"}));"
and I says to myself: I'm not using a PERLDOC environment variable, and
don't think I have to stick any arguments onto the arglist anyway.
So I commented it out.
It works fine now.
So a) what's it supposed to do (perldoc shellwords gives back "not
found") and b) should I make an effort to find it?
--
Michael D. Hofer
Internet Services
212 235 4415
------------------------------
Date: 12 Jul 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 Mar 98)
Message-Id: <null>
Administrivia:
Special notice: in a few days, the new group comp.lang.perl.moderated
should be formed. I would rather not support two different groups, and I
know of no other plans to create a digested moderated group. This leaves
me with two options: 1) keep on with this group 2) change to the
moderated one.
If you have opinions on this, send them to
perl-users-request@ruby.oce.orst.edu.
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 4391
**************************************