[10754] in Perl-Users-Digest
Perl-Users Digest, Issue: 4353 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Dec 3 16:07:25 1998
Date: Thu, 3 Dec 98 13:00:20 -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 Thu, 3 Dec 1998 Volume: 8 Number: 4353
Today's topics:
Creating Directories with Perl <r2-d2@REMOVEbigfoot.com>
Re: Creating Directories with Perl <Tony.Curtis+usenet@vcpc.univie.ac.at>
Directory permission. <webmaster@bluegalaxy.hypermart.net>
Re: Directory permission. <Tony.Curtis+usenet@vcpc.univie.ac.at>
Re: Embedded ?: operators (Mark-Jason Dominus)
Re: Keys,Values(Associative Arrays) <newsposter@cthulhu.demon.nl>
Re: Memory in Perl (Ilya Zakharevich)
Net::IRC <joe@j9.net>
oraperl webboss@freenet.co.uk
Re: PC to Unix Problem <jc@eddie.mit.edu>
Re: PC to Unix Problem <r28629@email.sps.mot.com>
Re: PC to Unix Problem <r28629@email.sps.mot.com>
Perl learning and a host for running ()
Re: Perl learning and a host for running <Tony.Curtis+usenet@vcpc.univie.ac.at>
Re: Promote a TIEREF to hash.... lordvorp@my-dejanews.com
Re: Promote a TIEREF to hash.... (Mark-Jason Dominus)
Re: Regex question (Tad McClellan)
Re: Sorting VERY large files effeciently (R L Samuell)
system call <rsingh@polymail.calpoly.edu>
Re: system call (David Formosa)
Re: usage of $_ within nested loops <r28629@email.sps.mot.com>
Re: variable inside variable (Tad McClellan)
Variable modification in module without "return"? <jdavis@osprey.arc.nasa.gov>
Re: Variable modification in module without "return"? <Alex.Davies@tiuk.ti.com>
Re: Variable modification in module without "return"? (Sean McAfee)
Re: Variable modification in module without "return"? <r28629@email.sps.mot.com>
Re: Why is "... @foo ..." occasionally a syntax error? (Erik)
Re: Why is "... @foo ..." occasionally a syntax error? (Mark-Jason Dominus)
Re: Why is "... @foo ..." occasionally a syntax error? (Gary E. Ansok)
Re: Win32::FileSecurity::Set (Tye McQueen)
Re: wwwboard question - file locking dturley@pobox.com
Special: Digest Administrivia (Last modified: 12 Mar 98 (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Thu, 3 Dec 1998 18:55:53 -0000
From: "Artoo" <r2-d2@REMOVEbigfoot.com>
Subject: Creating Directories with Perl
Message-Id: <746msi$8oj$1@plug.news.pipex.net>
Hi
How can you use Perl to create new directories?
The following can be used to make a new file:
open(ADD,">$root/test.txt");
But how can you make a new directory?
Thanks
------------------------------
Date: 03 Dec 1998 20:04:23 +0100
From: Tony Curtis <Tony.Curtis+usenet@vcpc.univie.ac.at>
Subject: Re: Creating Directories with Perl
Message-Id: <834srdcaiw.fsf@vcpc.univie.ac.at>
Re: Creating Directories with Perl, Artoo
<r2-d2@REMOVEbigfoot.com> said:
Artoo> Hi How can you use Perl to create new directories?
The same way you do in C or from your shell
perldoc -f mkdir
Artoo> The following can be used to make a new file:
Artoo> open(ADD,">$root/test.txt");
Always check the return status:
open(...) or die "blah blah...";
Artoo> But how can you make a new directory?
If you don't know that the entire path exists, you can use
`mkpath' from
perldoc File::Path
hth
tony
--
Tony Curtis, Systems Manager, VCPC, | Tel +43 1 310 93 96 - 12; Fax - 13
Liechtensteinstrasse 22, A-1090 Wien, | <URI:http://www.vcpc.univie.ac.at/>
"You see? You see? Your stupid minds! | private email:
Stupid! Stupid!" ~ Eros, Plan9 fOS.| <URI:mailto:tony_curtis32@hotmail.com>
------------------------------
Date: Thu, 03 Dec 1998 19:56:12 GMT
From: "Christian H. Knudsen" <webmaster@bluegalaxy.hypermart.net>
Subject: Directory permission.
Message-Id: <3666EDDF.AD7161EE@bluegalaxy.hypermart.net>
I have a directory with a 700 permission. I would like a script
to be able to change the permission to 777 (for example),
write some files in the dir and the chmod back to 700. The
reason for this is that I would like the files in the dir to be
hidden from any users, as it will contain secret info like
passwords and user names.
My problem is that the script (naturally) isn't able to chmod
the dir to 777 because of the 700 permission!
Any ideas?
-- Christian H. Knudsen
------------------------------
Date: 03 Dec 1998 21:05:25 +0100
From: Tony Curtis <Tony.Curtis+usenet@vcpc.univie.ac.at>
Subject: Re: Directory permission.
Message-Id: <83g1axt2ii.fsf@vcpc.univie.ac.at>
Re: Directory permission., Christian
<webmaster@bluegalaxy.hypermart.net> said:
Christian> I have a directory with a 700
Christian> permission. I would like a script to be
Christian> able to change the permission to 777 (for
Christian> example), write some files in the dir and
Christian> the chmod back to 700. The reason for
Christian> this is that I would like the files in
Christian> the dir to be hidden from any users, as
Christian> it will contain secret info like
Christian> passwords and user names.
Christian> My problem is that the script (naturally)
Christian> isn't able to chmod the dir to 777
Christian> because of the 700 permission!
Why ever not?
% mkdir foo
% chmod 700 foo
% ls -ld foo
drwx------ ... foo
% chmod 777 foo
% ls -ld foo
drwxrwxrwx ... foo
% rmdir foo
Invoking my psychic powers I surmise this is a CGI
problem, so you should look at
http://www.perl.com/CPAN/doc/FAQs/cgi/idiots-guide.html
especially questions 5 and 6...
hth
tony
--
Tony Curtis, Systems Manager, VCPC, | Tel +43 1 310 93 96 - 12; Fax - 13
Liechtensteinstrasse 22, A-1090 Wien, | <URI:http://www.vcpc.univie.ac.at/>
"You see? You see? Your stupid minds! | private email:
Stupid! Stupid!" ~ Eros, Plan9 fOS.| <URI:mailto:tony_curtis32@hotmail.com>
------------------------------
Date: 3 Dec 1998 15:12:22 -0500
From: mjd@op.net (Mark-Jason Dominus)
Subject: Re: Embedded ?: operators
Message-Id: <746rb6$21d$1@monet.op.net>
In article <3666BEC8.4588AEE4@obfuscated.net>,
Michael Conlen <mike@obfuscated.net> wrote:
>I do not recall ever seeing a definition for embedded ?: operators. I
>have an example of what appears to work on my system, but I'm curious as
>to whether or not it's defined to work, so that I can count on being
>able to use it in future obfuscated perl code contests.
Well, I'm not really sure what you mean by `embedded', but what you
wrote will almost certainly work forever.
In fact, the only unusual thing about it is that you reversed the
sense of one of the tests. If instead of this:
$i != 0 ? $i == 1 ? $bottle : $bottles : $nobeer
you had written this:
$i == 0 ? $nobeer : $i == 1 ? $bottle : $bottles
then you would have been doing something very ordinary.
The ?: operator was designed with this idiom in mind.
>You should also check this out if you are interested
>in a new way to do a switch statment.
I hope I don't disappoint you, but I notice that the `perlsyn' man
page already includes this example:
print do {
($flags & O_WRONLY) ? "write-only" :
($flags & O_RDWR) ? "read-write" :
"read-only";
};
so I doubt that it is going to win you any obfuscated awards.
------------------------------
Date: Thu, 03 Dec 1998 13:24:09 -0500
From: Erik van Roode <newsposter@cthulhu.demon.nl>
Subject: Re: Keys,Values(Associative Arrays)
Message-Id: <3666D747.4A92C8F@cthulhu.demon.nl>
Ashwini Nagaraj wrote:
> I am using DBI in my perl script and when I do a query as shown below,
> how can I save the results in an associative array as keys and values.
The 'shown below' does not seem to use DBI to access a database ...
> For ex if my query looks like:
> "Select ex.server, ex.metric, ex.value from db.table ex
> where ex.metric = xxxxxxxxxx or ex.metric = aaaaaaaaaaaaa
> group by ex.server"
> I am farely new to this subject, please help me out here. I would
> appreciate if anyone could post me any example of the same type.
I currently don't have access to the DBI documentation, but as far as
I can remember there indeed is a way to fetch a row into a hash, the
field names being the keys, the values being the values ;)
Check out the documentation that comes with the DBI module.
Erik
------------------------------
Date: 3 Dec 1998 19:50:32 GMT
From: ilya@math.ohio-state.edu (Ilya Zakharevich)
Subject: Re: Memory in Perl
Message-Id: <746q28$8vg$1@mathserv.mps.ohio-state.edu>
[A complimentary Cc of this posting was sent to Zenin
<zenin@bawdycaste.org>],
who wrote in article <912556665.988364@thrush.omix.com>:
> Example:
>
> sub foo {
> my $foo = "stuff";
> my @bar = qw(foo bar baz);
> }
>
> Here the memory for $foo and @bar is never reclaimed. Perl expects
> you're likely to call foo() again and so need that memory again.
> For efficiency it just reuses the memory it used the first time.
In fact the memory is kept *twice*. Once for constant initializers,
once per runtime-item of &foo. And if foo is entered 10-levels deep
due to recursion, you get 11 copies.
Ilya
------------------------------
Date: Thu, 3 Dec 1998 18:20:46 +0300
From: "Joe Walnes" <joe@j9.net>
Subject: Net::IRC
Message-Id: <746kp5$rr9$1@starburst.uk.insnet.net>
Hi. I'm trying to write a tiny irc-client using Net::IRC put I am fairly new
to the world of Perl modules.
When I define $irc = new Net::IRC and call $irc->start the program seems to
go into a loop and wait for events from the IRC session. However I can't
figure out how to get input from STDIN while it is in this loop and handle
it appropriately with subroutines.
Can anyone help or can anyone point me to any examples (other than irctest).
Thanks
-Joe Walnes
------------------------------
Date: Thu, 03 Dec 1998 18:51:22 GMT
From: webboss@freenet.co.uk
Subject: oraperl
Message-Id: <746mj8$ccl$1@nnrp1.dejanews.com>
Anyone using Oraperl on Linux to talk to an oracle database on a remote box
(AIX)??
We need some advice on how well it works, especially as a cgi driven web-dbms
link... and any other info you think helps the learning curve!
Cheers!
--
Christopher J Williams - Internet Administrator TCAT
Work : webboss@tcat.ac.uk
Home : webboss@freenet.co.uk
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
------------------------------
Date: Thu, 03 Dec 1998 15:12:32 -0500
From: John Chambers <jc@eddie.mit.edu>
Subject: Re: PC to Unix Problem
Message-Id: <3666F0B0.A368EFEC@eddie.mit.edu>
Allan M. Due wrote:
>
> Steven Morlock wrote in message
> <91w92.73$dF2.160539@lwnws01.ne.mediaone.net>...
> >
> >Don't forget to make the scripts executable when they
> >get to the UNIX box.
> >
> >Now if FTP could only do that too...
> >
> >--
>
> Actually, most Windoz FTP clients will let you change the protection
> of files being uploaded. WS_FTP and AbsoluteFTP just to name two.
It sounded like he was copying W -> U, but it's also true that some
Unix ftp commands will (attempt to) restore file permissions on the
receiving end. I modified one of the ftp programs (on a Digital Unix
box) a couple years back to do this.
One warning: While I was working on the above, a curious "upgrade"
was installed on some nearby NT systems. The FTP server on these
machines then started sending out file listings that mimicked the
format of a Unix listing, including permissions. But all the
permission bits were off. This "broke" the Unix FTP clients that
copied file permissions; when copying from an NT system, they
produced files on the Unix system with 000 permissions. I added
a little kludge that checked for 000 permissions (and an NT FTP
server), and changed them to 644. But the NT server definitely
had been upgraded to throw a monkey wrench into the works of the
Unix FTP clients. There's a good chance that, if your FTP program
copies file permissions, files downloaded from an NT system will
be unusable until you make them readable.
------------------------------
Date: Thu, 03 Dec 1998 14:18:58 -0600
From: Tk Soh <r28629@email.sps.mot.com>
To: dzuy@my-dejanews.com
Subject: Re: PC to Unix Problem
Message-Id: <3666F232.A1A24FFC@email.sps.mot.com>
[posted to c.l.p.m and copy emailed]
dzuy@my-dejanews.com wrote:
[...]
> or in your perl script:
>
> s/^M//g;
>
> To type the actual ^M, hold down the <Ctrl> key and type v then m.
this makes the regex a bit confusing, beside not all edit allow
<ctrl>-key combination. Perhaps you want to do this:
s/\cM//; # tr/// might be faster
Also, since there should be only one CR per line, the /g modifier can be
left out.
-TK
------------------------------
Date: Thu, 03 Dec 1998 14:12:17 -0600
From: Tk Soh <r28629@email.sps.mot.com>
To: dave@mag-sol.com
Subject: Re: PC to Unix Problem
Message-Id: <3666F0A1.2E332AC2@email.sps.mot.com>
[posted to c.l.p.m and copy emailed]
dave@mag-sol.com wrote:
>
> Probably best to transfer the files between DOS and Unix using FTP in ASCII
> mode, it will then do the conversion for you. If you'r forced to use some
Some people, like me, live in the NT-Unix world where the user data
reside on a file server, and ftp to localhost isn't a good idea most of
the time.
> other method then you Unix may well have a dos2unix filter that you can use
> like:
>
> dos2unix < ugly_dos_file.text > nice_unix_file.txt
can't find this command on my HP-UX, guess the sys admin is hiding it
from me again ;-)
> Only if all these easy methods fail should you take on the massive task of
> writing dos2unix yourself. It may well look a little like this
>
> #!/usr/bin/perl -w
> use strict;
>
> while (<STDIN>)
> {
> s/\r\n/\n;
> print;
> }
this one-liner may be more convenient:
perl -i -pe 's/\r//' file.txt
-TK
------------------------------
Date: 3 Dec 1998 18:22:13 GMT
From: vy@ultra.multiweb.net ()
Subject: Perl learning and a host for running
Message-Id: <slrn76dlo2.c3b.vy@ultra.multiweb.net>
Hi all,
I started to learn Perl, I'm now starting to find a webhost to run my scripts.
I want a host without banners.
TNX
VIet Yen , Nguyen
------------------------------
Date: 03 Dec 1998 19:55:42 +0100
From: Tony Curtis <Tony.Curtis+usenet@vcpc.univie.ac.at>
Subject: Re: Perl learning and a host for running
Message-Id: <8367btcaxd.fsf@vcpc.univie.ac.at>
Re: Perl learning and a host for running, Nguyen
<vy@ultra.multiweb.net> said:
Nguyen> Hi all, I started to learn Perl, I'm now starting to
Nguyen> find a webhost to run my scripts. I want a host
Nguyen> without banners.
Install perl locally http://www.perl.com/
Install a WWW Server locally http://www.apache.org/
A server without banners is thus "localhost" :-)
hth
tony
--
Tony Curtis, Systems Manager, VCPC, | Tel +43 1 310 93 96 - 12; Fax - 13
Liechtensteinstrasse 22, A-1090 Wien, | <URI:http://www.vcpc.univie.ac.at/>
"You see? You see? Your stupid minds! | private email:
Stupid! Stupid!" ~ Eros, Plan9 fOS.| <URI:mailto:tony_curtis32@hotmail.com>
------------------------------
Date: Thu, 03 Dec 1998 18:49:56 GMT
From: lordvorp@my-dejanews.com
Subject: Re: Promote a TIEREF to hash....
Message-Id: <746mgj$c51$1@nnrp1.dejanews.com>
In article <73793j$mjf$1@picasso.op.net>,
mjd@plover.com (Mark-Jason Dominus) wrote:
> In article <3654C00D.3553@usa.net>, Lord Vorp <lordvorp@usa.net> wrote:
> >or even better, suppose I wanted to pass my tied %hash by ref to a
> >function:
> >
> >&my_func(\%hash)
> >
> >Is there a way to promote it back to a tied hash?
>
> When the function gets the reference, it still refers to the tied hash.
>
> >
> >sub my_func {
> > my $ref = shift;
> > print ref $ref, "\n";
> >
> > my %hash = %$ref;
>
> Here you have copied the contents of the tied hash into a new,
> untied hash. Of course %hash is untied.
This was the actual purpose I was trying to achieve. Now I have to try:
my %hash;
tie %hash, 'Tie::IxHash', %$ref;
This should presumably copy the contents of the tied hash in $ref (ordered, in
this case) into the new tied %hash (*retaining* the order, in this case).
> But if you use $ref->{foo}, you will be going through the tied hash
> and you will get the usual special tied hash behavior.
YES! Duh...this was what I was looking for...(pretty much :-) I was trying
to think of a syntax that would allow me to refer to the tied data when the
object was passed by reference.
> If you don't want to write arrows, do this:
>
> local *hash = $ref;
>
> Now %hash is an alias for the tied hash that you passed by reference.
I've DONE this...but have you ever tried this while under "use strict;"? :-)
With all of the warnings about keeping symbol tables clean, this solution is
workable but not necessarily subclassable.
Thx for the reply.
L8r,
L V
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
------------------------------
Date: 3 Dec 1998 14:54:09 -0500
From: mjd@op.net (Mark-Jason Dominus)
Subject: Re: Promote a TIEREF to hash....
Message-Id: <746q91$1qk$1@monet.op.net>
In article <746mgj$c51$1@nnrp1.dejanews.com>,
<lordvorp@my-dejanews.com> wrote:
>> If you don't want to write arrows, do this:
>>
>> local *hash = $ref;
>>
>> Now %hash is an alias for the tied hash that you passed by reference.
>
>I've DONE this...but have you ever tried this while under "use strict;"? :-)
Probably. It's been two weeks since I wrote that,so I forget if this
is appropriate, but why not just
use vars '%hash';
...
local *LordVorp::hash = $ref;
...
$hash{x} = y;
>With all of the warnings about keeping symbol tables clean, this solution is
>workable but not necessarily subclassable.
Could be. If your function calls some other function that is
expecting to access `%LordVorp::hash' (or $LordVorp::hash etc.) then
that function will get the wrong thing. But either
a. That function would have failed under `use strict' anyway, or
b. That function is in another package, explicitly getting
LordVorp::hash, which voilates the encapsulation boundary, or
c. That function is in your package and should be easy to fix.
>Thx for the reply.
My pleasure.
------------------------------
Date: Thu, 3 Dec 1998 12:45:24 -0600
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Regex question
Message-Id: <48m647.t12.ln@metronet.com>
Duncan Martin (dmarti81@ford.com) wrote:
: I've tried to work this out, but it's starting to make my head hurt...
So just do it the way suggested in the Perl FAQ...
: I'm reading in a plain text file where each line needs to be split into
: fields. Each field is either alphanumeric and has " around it or
: numeric without the quotes.
: e.g, possible lines are
: 1,2,"camel",4,"book"
: "a","b",4,"c"
: If anyone can suggest a way of doing this without (Sharp intake of
: breath) having to scan left->right counting quotes, I'd be very
: grateful.
Perl FAQ, part 4:
"How can I split a [character] delimited string except when inside
[character]? (Comma-separated files)"
Where you want 'comma' for the first [character], and
'double quote' for the second [character], which is
is exactly what the code given there does...
--
Tad McClellan SGML Consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Thu, 3 Dec 1998 19:06:33 GMT
From: samuell@cis.uab.edu (R L Samuell)
Subject: Re: Sorting VERY large files effeciently
Message-Id: <912711993.31@138.26.65.69>
In article <366baa34.171436064@news.ford.com> dated Thu, 03 Dec 1998 15:31:13 GMT,
cpierce1@mail.ford.com (Clinton Pierce) wrote:
> Divide the file up into N-chunks, where the size of a chunk will fit
> comfortably in core. While the chunk is in core, do a traditional
> q-sort on the chunk. (Or whichever kind of sort best fits your data).
> Write the chunk out, and do the next one. When all of the individual
> chunks are sorted--merge them back together into a large sorted file.
In commercial disk sort software I wrote for a non-IBM mainframe about
20 years ago, I discovered that in a similar design using
insertion-selection table techniques if the number of records known to
be sorted is 'n' that making the number of initial 'chunks' N as close
to sqrt(n) as possible with each chunk containing as close to sqrt(n)
records produced the smallest sort/merge times for various test files.
------------------------------
Date: Thu, 3 Dec 1998 11:34:49 -0800
From: "Raj Singh" <rsingh@polymail.calpoly.edu>
Subject: system call
Message-Id: <746p0n$dlb$1@cscnews.csc.calpoly.edu>
When I make the following system call from within a Perl application:
`echo the`
I get no output. However, I can do the follwing:
$value=`echo the`;
print $value;
In this case it works, how can I get it to work without having to store the
output to a variable. When I do the following:
system("echo the");
It works, but I don't understand what is the difference between using system
or backward single quotes.
Thanks, Raj
------------------------------
Date: 3 Dec 1998 20:07:52 GMT
From: dformosa@zeta.org.au (David Formosa)
Subject: Re: system call
Message-Id: <slrn76drso.dlr.dformosa@godzilla.zeta.org.au>
In article <746p0n$dlb$1@cscnews.csc.calpoly.edu>, Raj Singh wrote:
[...]
>It works, but I don't understand what is the difference between using system
>or backward single quotes.
Backward quotes capture outpput, system dosn't.
--
Please excuse my spelling as I suffer from agraphia. See
http://www.zeta.org.au/~dformosa/Spelling.html to find out more.
------------------------------
Date: Thu, 03 Dec 1998 13:07:22 -0600
From: Tk Soh <r28629@email.sps.mot.com>
Subject: Re: usage of $_ within nested loops
Message-Id: <3666E16A.22C41BF3@email.sps.mot.com>
dave@mag-sol.com wrote:
>
> > How will Perl handle the usage of "$_" within nested loops.
> The example you give will work fine. You would, however, have a problem if you
> tried to do this:
>
> while (<FILE>)
> {
> foreach (@array)
> {
> # Value for $_ from while loop has been lost.
> }
> }
>
To be more picky, I guess the word 'lost' isn't very accurate here, the
$_ inside foreach loop simply get localized, hence the 'lost' value will
be restored upon exiting the foreach loop.
-TK
------------------------------
Date: Thu, 3 Dec 1998 12:40:26 -0600
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: variable inside variable
Message-Id: <qul647.t12.ln@metronet.com>
quinn coldiron (qcoldiro@unlinfo.unl.edu) wrote:
: $field[0] =~ s/\$(\w+)/${$1}/g;
: I don't understand why it works, just that it does.
The pattern matches references to scalar variables,
and saves the variable's name in the $1 variable.
The replacement uses Symbolic References to replace
the variable reference with the referenced variable's
value.
Symbolic References are described in the 'perlref' man page.
--
Tad McClellan SGML Consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Thu, 03 Dec 1998 10:02:52 -0800
From: Jennifer Davis <jdavis@osprey.arc.nasa.gov>
Subject: Variable modification in module without "return"?
Message-Id: <3666D24C.A1F919A9@osprey.arc.nasa.gov>
I want to have a module modify a non-global variable.
I don't want the variable to be returned via "return"
because I am using return for my success/failure codes
(and eventually I might want to modify more than one
non-global variable). (I'm trying to use pass-by-
reference as I do in C. Perhaps I can't do this in
Perl?)
Here is the jist of what I'm doing:
local $x = "";
$result = b::a(\$x);
print "$x"; # this results in the null string
b.pm has:
a()
{
$pkg = shift;
$x = shift;
$x = "bubba";
print "$x"; # this results in "bubba"
return 1;
# normally, the value would be returned here as
# return \$x; ...but I don't wanna!
}
(These are extremely simplified names; I assure you
that I don't use one-letter names in my real code.
I am using use strict; and -w.)
Thanks much for any help. I've been digging through
"Programming Perl," "Advanced Perl Programming," and
various web sites but still can't figure this out.
- Jennifer
--
Jennifer L. Davis Raytheon STX jdavis@osprey.arc.nasa.gov
CTAS Project, NASA Ames Research Center http://ctas.arc.nasa.gov
------------------------------
Date: Thu, 03 Dec 1998 19:49:46 +0000
From: Alex Davies <Alex.Davies@tiuk.ti.com>
To: Jennifer Davis <jdavis@osprey.arc.nasa.gov>
Subject: Re: Variable modification in module without "return"?
Message-Id: <3666EB5A.9002CE6E@tiuk.ti.com>
Jennifer Davis wrote:
> I want to have a module modify a non-global variable.
> I don't want the variable to be returned via "return"
> because I am using return for my success/failure codes
> (and eventually I might want to modify more than one
> non-global variable). (I'm trying to use pass-by-
> reference as I do in C. Perhaps I can't do this in
> Perl?)
>
> Here is the jist of what I'm doing:
>
> local $x = "";
Are you sure local is what you want...? "my" is usually what you want...
>
> $result = b::a(\$x);
> print "$x"; # this results in the null string
>
> b.pm has:
>
> a()
> {
> $pkg = shift;
> $x = shift;
Both these should probably be my'ed...
>
>
> $x = "bubba";
Now if $x is a reference to your global $x, you should use $$x to
assign to it...
>
>
> print "$x"; # this results in "bubba"
>
> return 1;
> # normally, the value would be returned here as
> # return \$x; ...but I don't wanna!
> }
>
> (These are extremely simplified names; I assure you
> that I don't use one-letter names in my real code.
> I am using use strict; and -w.)
>
> Thanks much for any help. I've been digging through
> "Programming Perl," "Advanced Perl Programming," and
> various web sites but still can't figure this out.
>
> - Jennifer
>
> --
> Jennifer L. Davis Raytheon STX jdavis@osprey.arc.nasa.gov
> CTAS Project, NASA Ames Research Center http://ctas.arc.nasa.gov
It basically looks like you've forgotten to dereference a reference....
Good luck!
alex.
_________________________________________________________________________
Alex Davies, MOS Design, Email: Alex.Davies@tiuk.ti.com
Texas Instruments Limited,
800 Pavillion Drive, Tel (work): 01604 663450
Brackmills Industrial Estate, (home): 01604 764961
Northampton, NN4 7YL.
U.K.
------------------------------
Date: Thu, 03 Dec 1998 19:56:32 GMT
From: mcafee@waits.facilities.med.umich.edu (Sean McAfee)
Subject: Re: Variable modification in module without "return"?
Message-Id: <Q1C92.2486$CY1.9928432@news.itd.umich.edu>
In article <3666D24C.A1F919A9@osprey.arc.nasa.gov>,
Jennifer Davis <jdavis@osprey.arc.nasa.gov> wrote:
>I want to have a module modify a non-global variable.
>I don't want the variable to be returned via "return"
>because I am using return for my success/failure codes
>(and eventually I might want to modify more than one
>non-global variable). (I'm trying to use pass-by-
>reference as I do in C. Perhaps I can't do this in
>Perl?)
Sure you can, and it's easier in Perl than in C, because there's no special
syntax involved. From perlsub:
Any arguments passed to the routine come in as the array @_.
Thus if you called a function with two arguments, those
would be stored in $_[0] and $_[1]. The array @_ is a local
array, but its elements are aliases for the actual scalar
parameters. In particular, if an element $_[0] is updated,
the corresponding argument is updated (or an error occurs if
it is not updatable).
Example:
sub assign {
$_[0] = $_[1];
}
assign($x, 10); # $x is now 10
assign($y, "foo"); # $y is now "foo"
--
Sean McAfee | GS d->-- s+++: a26 C++ US+++$ P+++ L++ E- W+ N++ |
| K w--- O? M V-- PS+ PE Y+ PGP?>++ t+() 5++ X+ R+ | mcafee@
| tv+ b++ DI++ D+ G e++>++++ h- r y+>++** | umich.edu
------------------------------
Date: Thu, 03 Dec 1998 13:39:44 -0600
From: Tk Soh <r28629@email.sps.mot.com>
To: Jennifer Davis <jdavis@osprey.arc.nasa.gov>
Subject: Re: Variable modification in module without "return"?
Message-Id: <3666E900.BABDC800@email.sps.mot.com>
[posted to c.l.p.m and copy emailed]
Jennifer Davis wrote:
>
> I want to have a module modify a non-global variable.
> I don't want the variable to be returned via "return"
> because I am using return for my success/failure codes
> (and eventually I might want to modify more than one
> non-global variable). (I'm trying to use pass-by-
> reference as I do in C. Perhaps I can't do this in
> Perl?)
why not?
> Here is the jist of what I'm doing:
>
> local $x = "";
> $result = b::a(\$x);
> print "$x"; # this results in the null string
^ ^
don't need quotes here.
>
> b.pm has:
>
> a()
> {
> $pkg = shift;
> $x = shift;
^^^^^^^^^^
only one argv is passed in, why shift again? into $x?
>
> $x = "bubba";
>
> print "$x"; # this results in "bubba"
again, no quotes.
>
> return 1;
> # normally, the value would be returned here as
> # return \$x; ...but I don't wanna!
> }
>
> (These are extremely simplified names; I assure you
> that I don't use one-letter names in my real code.
> I am using use strict; and -w.)
>
that's good. But how come $pkg and $x are not local'ed or my'ed?
> Thanks much for any help. I've been digging through
> "Programming Perl," "Advanced Perl Programming," and
> various web sites but still can't figure this out.
I think you should start with Learning Perl ;-)
I don't see why you need to use a class method to modify a local, but
this will do it:
$$pkg = "bubba";
HTH.
-TK
------------------------------
Date: 3 Dec 1998 18:12:18 GMT
From: eln@cyberhighway.net (Erik)
Subject: Re: Why is "... @foo ..." occasionally a syntax error?
Message-Id: <746ka2$s8o$1@news.cyberhighway.net>
In article <x3y3e6yce9i.fsf@tigre.matrox.com>,
Ala Qumsieh <aqumsieh@matrox.com> writes:
> Maybe you didn't mean it, but your above statement gave me the
> impression that Perl assumes that @ is literal and continues running
> the program. It doesn't.
I guess my terminology was a little off. Re-reading my original statement,
I can see where you would have gotten this impression. But, yes, I did
intend it to mean that this error is in fact fatal. The error
being described as a "fatal syntax error" in the post I was replying to,
I didn't take a lot of care distinguishing it as a fatal error, as it had
already been stated.
When in doubt, always assume I meant the right thing ;)
--
Erik Nielsen, Cyberhighway Internet Services NOC
...which gives the server a futuristic, serverish, 'Don't touch me, or
I will put a printer up your ass!', kind of look.
-- Nir Soffer in a.s.r.
------------------------------
Date: 3 Dec 1998 14:37:05 -0500
From: mjd@op.net (Mark-Jason Dominus)
Subject: Re: Why is "... @foo ..." occasionally a syntax error?
Message-Id: <746p91$1kl$1@monet.op.net>
In article <3666A343.27A52936@eddie.mit.edu>,
John Chambers <jc@eddie.mit.edu> wrote:
>Mark Dominus wrote:
>>
>> >As far as I can tell, this bug/feature isn't documented in the man pages.
>>
>> What, other than the detailed explanation of the error message that's
>> listed in `perldiag' that other people already quoted?
>
>Um, Here's the relevant passage in its entirety:
>
> In string, @%s now must be written as \@%s
> (F) It used to be that Perl would try to guess whether you wanted an
> array interpolated or a literal @. It did this when the string was
> first used at runtime. Now strings are parsed at compile time, and
> ambiguous instances of @ must be disambiguated, either by prepending a
> backslash to indicate a literal, or by declaring (or using) the array
> within the program before the string (lexically). (Someday it will
> simply assume that an unbackslashed @ interpolates an array.)
>
>This doesn't contain the slightest hint as to what constitutes an
>"ambiguous instances".
The instruction for fixing the error covers the circumstances exactly.
@ in a string must be disambiguated, either by X or by Y. The error
occurs in precisely those circumstances where neither X or Y was done.
What else do you want it to say? It says you must do either X or Y;
you did neither X nor Y, and therefore you got the error. There
really isn't any more to the story than that.
So when I ask `what else did you want it to say?' I'm not being a
smart mouth; I'm really puzzled, because I have no idea what else you
wanted it to say.
> Nor does it contain any sort of clue that
>the compiler wants some (physically) earlier instance of the array.
It says `before ... (lexically)' and you want it to say `(physically) earlier'.
And in fact, `lexically before' is a more correct way to say that.
`Earlier' suggests a time relationship, which is incorrect, and
`physically' in the context of a computer program is a head-scratcher.
But `lexically before' is exactly right.
Is part of the problem that you don't know what `lexically' means?
(I'm not trying to put you down or insult you; I'm making a good-faith
effort to identify your problem.)
>There is nothing here that can be used to understand why one case
>of "... @foo ..." gets this error when a zillion others don't.
A zillion other times, you didn't get the error, and that's because in
each case you did either X or Y, probably Y. This is a description of
an error message. It describes the circumstances under which you get
the error message. It says `you must'. I think most people would see
`you must' and conclude `I guess I didn't.' But for some reason you
didn't come to that conclusion, and I find that very strange.
There's a problem here, which is that you didn't understand the
manual. That could be construed as a fault with the manual, or with
you, or both, and regardless, it is unfortunate, and it means that the
manual failed.
I think there really isn't any point in arguing this any further. We
could go round all week arguing about whether the manual was clear or
not, and that's a matter of opinion. But you haven't said that the
explanation was unclear; you said repeatedly that there was no
explanation at all, and that is not true.
>I asked in the newsgroup. Maybe I should have known better,
>considering how nasty c.l.p.m has become in recent years, but I was
>curious.
I hope you don't take this the wrong way, because I do agree that
there is too much nastiness in the group, but it also seems to me that
you are determined to look for trouble. In this article, for example,
you said
> I suppose you're going to tell me what an idiot I am for drawing
> such a stupid conclusion,
but I don't think I did do anything like that. I'd like to suggest
that a less defensive approach might be more fruitful.
----------------------------------------------------------------
>> Consider:
>>
>> $string =~ /$foo[0-9]/;
>
>I've always loved that one. Isn't that why \d was invented?
No; \d was for convenience and readability. It certainly doesn't
solve the problem of disambiguating that regular expression, because
[0-9] is still allowed, and anyway it could just have easily been
>> $string =~ /$foo[13-8]/;
But it's hard to come up with a really plausibly ambiguous example
here, which is actually why the heuristic works so well in practice.
------------------------------
Date: 3 Dec 1998 19:41:51 GMT
From: ansok@alumni.caltech.edu (Gary E. Ansok)
Subject: Re: Why is "... @foo ..." occasionally a syntax error?
Message-Id: <746phv$7rq@gap.cco.caltech.edu>
In article <dK_82.41$Fn3.104@nsw.nnrp.telstra.net>,
Martien Verbruggen <mgjv@comdyn.com.au> wrote:
>
>The following fails:
>
>> perl
>"@resource"
>In string, @resource now must be written as \@resource at - line 1,
> near "@resource"
>
>All the following succeed without any other code:
>
>@resource = ();
>"@resource";
>
[other examples snipped]
Indeed. The following will cause the error message in question, and
I suspect it might be related to the original poster's problem:
sub foo {
"@resource";
}
@resource = ();
foo();
While @resource will be defined in the program flow before foo() is called,
there is no `definition' of @resource seen by the Perl parser before it
processes the "@resource".
In addition to the other examples of initializing/defining the array,
in this case a workaround is to move the definition of the subroutine foo()
to the end of the source file (or any point after @resource is seen
outside double-quotes). (I didn't say that would be my preferred
solution -- I would probably use "my" or "use vars", depending on
whether @resource needs to be a global variable or not, and "use strict".)
-- Gary Ansok
------------------------------
Date: 3 Dec 1998 14:09:13 -0600
From: tye@fohnix.metronet.com (Tye McQueen)
Subject: Re: Win32::FileSecurity::Set
Message-Id: <746r59$jpp@fohnix.metronet.com>
Casey Feskens <feskencj@plu.edu> writes:
) It seems that the
) Win32::FileSecurity::Set function is destroying my ACL hashes,
) making recursion a problem.
Nitpick: I think you mean iteration, not recursion.
) Set($file, \%dir_RX) || die "Could not set the DACL
Try:
Set($file, {%dir_RX}) || die "Could not set the DACL
It is less efficient but it will prevent Set() from messing
with your %dir_RX.
This is probably a bug in the Win32::FileSecurity module; which
isn't much of a surprise since the vast majority of the Win32::
modules I've tried to use are nearly horrible things.
Try to get the author to fix it.
--
Tye McQueen Nothing is obvious unless you are overlooking something
http://www.metronet.com/~tye/ (scripts, links, nothing fancy)
------------------------------
Date: Thu, 03 Dec 1998 17:45:20 GMT
From: dturley@pobox.com
Subject: Re: wwwboard question - file locking
Message-Id: <746inf$93k$1@nnrp1.dejanews.com>
In article <3666B309.1B1@geocities.com>,
nospam23_skidoo@geocities.com wrote:
> i'm editing my scripts on bbedit on a mac + uploading them to a
> webserver, any ideas how i'd get hold of that documentation?
If you can't telnet to your ISP, check out:
http://language.perl.com/info/documentation.html
then get a new ISP
--
David Turley
dturley@pobox.com
http://www.binary.net/dturley/
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
------------------------------
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 4353
**************************************