[18256] in Perl-Users-Digest
Perl-Users Digest, Issue: 424 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Mar 6 03:05:45 2001
Date: Tue, 6 Mar 2001 00:05:11 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <983865910-v10-i424@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Tue, 6 Mar 2001 Volume: 10 Number: 424
Today's topics:
creating dos exectable from perl script <cj@sinha.cncdsl.com>
Re: creating dos exectable from perl script <wyzelli@yahoo.com>
Crypt::CBC and DES - Starting Variable Problems. <david-news@trumpet.com.au>
Re: different $/ for different filehandle? (Gwyn Judd)
Re: flock and close with empty read strangeness (H. Merijn Brand)
Re: flock and close with empty read strangeness <groovyt@erols.com>
Re: flock and close with empty read strangeness <groovyt@erols.com>
Re: flock and close with empty read strangeness <groovyt@erols.com>
Re: flock and close with empty read strangeness <groovyt@erols.com>
Re: flock and close with empty read strangeness <groovyt@erols.com>
Re: HELP!!!! perl script that writes to a text database <webmaster@webdragon.munge.net>
Re: Is Perl right for me? (Gwyn Judd)
Net::FTP <hilda@invopower.com>
Re: Opening files on other Windows machines <john@particlewave.com>
Re: pi day (Gwyn Judd)
Regex problem with array ul141@victoria.tc.ca
Re: Regex problem with array <nouser@emailunwelcome.com>
Re: Regex problem with array <joe+usenet@sunstarsys.com>
Re: Regex question (newbie) <godzilla@stomp.stomp.tokyo>
Re: Small problem: dup'ing DATA and $. <skuo@mtwhitney.nsc.com>
Re: use strict (vars, etc.) <Jonathan.L.Ericson@jpl.nasa.gov>
Re: use strict (vars, etc.) <Jonathan.L.Ericson@jpl.nasa.gov>
Re: why won't "format FILEHANDLE" work?? <c_clarkson@hotmail.com>
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 06 Mar 2001 04:07:07 GMT
From: C J Sinha <cj@sinha.cncdsl.com>
Subject: creating dos exectable from perl script
Message-Id: <B6C9DAAA.578E%cj@sinha.cncdsl.com>
Greetings,
I have written a small perl program which is very useful to my colleagues.
When someone wants it, I have go over and install perl on their NT machines,
so that they can run this script.
I understand that it is possible to convert a perl script to a self
contained .exe file that will run in windows/dos. That way I just pass
along the .exe file and the do not have to install perl on their machine.
Don't have a clue how to get started. How would I go about doing it? Any
pointers or examples appreciated.
TIA
Sanjay
p.s. My skill set of perl is very limited, but I will learn enough to get
the job done. :-)
------------------------------
Date: Tue, 6 Mar 2001 14:07:42 +0930
From: "Wyzelli" <wyzelli@yahoo.com>
Subject: Re: creating dos exectable from perl script
Message-Id: <qFZo6.28$6d2.4932@vic.nntp.telstra.net>
"C J Sinha" <cj@sinha.cncdsl.com> wrote in message
news:B6C9DAAA.578E%cj@sinha.cncdsl.com...
>
> Greetings,
> I have written a small perl program which is very useful to my
colleagues.
> When someone wants it, I have go over and install perl on their NT
machines,
> so that they can run this script.
>
> I understand that it is possible to convert a perl script to a self
> contained .exe file that will run in windows/dos. That way I just
pass
> along the .exe file and the do not have to install perl on their
machine.
>
> Don't have a clue how to get started. How would I go about doing it?
Any
> pointers or examples appreciated.
>
perl2exe www.dynamicstate.com
Wyzelli
--
($a,$b,$w,$t)=(' bottle',' of beer',' on the wall','Take one down, pass
it around');
for(reverse(1..100)){$s=($_!=1)?'s':'';$c.="$_$a$s$b$w\n$_$a$s$b\n$t\n";
$_--;$s=($_!=1)?'s':'';$c.="$_$a$s$b$w\n\n";}print"$c*hic*";
------------------------------
Date: Tue, 6 Mar 2001 15:57:32 +1100
From: "Dave Lacey" <david-news@trumpet.com.au>
Subject: Crypt::CBC and DES - Starting Variable Problems.
Message-Id: <981qt1$lp7$1@jazz-1.trumpet.com.au>
Hi there,
I am having real trouble with the Crypt::CBC and Crypt::DES modules.
I want to be able to encrypt something in an email using DES/CBC, but
then I want to decrypt it at the other end, using standard DES/CBC
decrypting. However it seems that the encryptioin process uses random
starting variables, so it is impossible to reconstruct the same encryption/
decryption later on (since you don't know the starting variable).
Is there any way to SPECIFY a SV, rather than let it be generated? Or
is there any way you can actually find out what the SV was that was used?
I am looking at the test cases given out in some EFTPOS documents, and
they are using the strings "Now is the time for all", and they give outputs
that
are desired (SV=1234567890ABCDEF).
Could anyone please tell me how to get these results somehow. I would
very much appreciate it - thanks. (Even some example code would be
great).
Dave
------------------------------
Date: Tue, 06 Mar 2001 06:07:03 GMT
From: tjla@guvfybir.qlaqaf.bet (Gwyn Judd)
Subject: Re: different $/ for different filehandle?
Message-Id: <slrn9a8vuo.17t.tjla@thislove.dyndns.org>
I was shocked! How could Daniel Heiserer <daniel.heiserer@bmw.de>
say such a terrible thing:
>This is a multi-part message in MIME format.
This is an single-part joke in ASCII format. Your sense of humour does not
support this format.
_____________
/ /|
+------------+ |
|man in a box|/
+------------+
>Hi,
>is there away to have different Input-record-separators
>for different Filehandles.
>
>e.g.
>
>open(ip1,"<gf1");
>open(ip2,"<gf2");
>
>$/="\n"; #for gf1
>$/="prompt>"; #for gf2
That would be one way. Then all you need to do is make sure you keep
them straight. Do you have an actual question?
--
Gwyn Judd (print `echo 'tjla@guvfybir.qlaqaf.bet' | rot13`)
He has half the deed done who has made a beginning.
-Horace
------------------------------
Date: Mon, 05 Mar 2001 19:50:09 +0100
From: h.m.brand@hccnet.nl (H. Merijn Brand)
To: comp.lang.perl.misc
Subject: Re: flock and close with empty read strangeness
Message-Id: <Xns905BC9C7E42E9Merijn@192.0.1.90>
abigail@foad.org (Abigail) wrote in
>So, while I'm reading /etc/passwd, the system administrator cannot
>add new accounts?
>
>I don't think so.
Would be a neat feature to keep it a pseudo single-user system though ...
;-)
--
H.Merijn Brand Amsterdam Perl Mongers
(http://www.amsterdam.pm.org/)
using perl-5.005.03, 5.6.0, 5.6.1, 5.7.1 & 623 on HP-UX 10.20 & 11.00, AIX
4.2
AIX 4.3, WinNT 4, Win2K pro & WinCE 2.11 often with Tk800.022 &/| DBD-
Unify
ftp://ftp.funet.fi/pub/languages/perl/CPAN/authors/id/H/HM/HMBRAND/
------------------------------
Date: Tue, 06 Mar 2001 01:20:53 -0500
From: ZepHead <groovyt@erols.com>
Subject: Re: flock and close with empty read strangeness
Message-Id: <groovyt-755034.01205306032001@virt-reader.news.rcn.net>
In article <90j6atcl9berv4rd0sg6dqr7pbqgtrh4eq@4ax.com>,
Bart Lateur <bart.lateur@skynet.be> wrote:
>
> What's the purpose of creating a file that you can't write to? No, sis,
> creating of and writing to a file are connected. No create without
> write.
opps i meant write lol
i want a simple way to tell open
to open for write but and create but not truncate
sinec
<
>
+>
+<
>>
are all used night as well use
<<
; )
------------------------------
Date: Tue, 06 Mar 2001 01:29:52 -0500
From: ZepHead <groovyt@erols.com>
Subject: Re: flock and close with empty read strangeness
Message-Id: <groovyt-944258.01295206032001@virt-reader.news.rcn.net>
>
> Mandatory LOCK_EX is a bad thing, because it would prevent anyone from
> even reading the file (which would happen with a LOCK_SH, if locking
> always happened).
well all writes should be LOCK_EX IMHO
and this thread is about writing and race conditions
the open > causes when another process reads the truncated
file before the write which happens in overloaded
servers a lot and why I'm here. ; )
>
> +<< could be used for O_CREAT|O_RDWR, but I can't think of anything
> logical for the other one.
i said << but that looks to much like a read and so much so
i called it a read by mistake a post back
I guess +<< is the way to go and with +<
it makes sense.
>
> > as always just my opinion : P
>
> Understood.
>
> Martien
same here. I like talking about this stuff ; )
------------------------------
Date: Tue, 06 Mar 2001 01:42:52 -0500
From: ZepHead <groovyt@erols.com>
Subject: Re: flock and close with empty read strangeness
Message-Id: <groovyt-1B0B61.01425206032001@virt-reader.news.rcn.net>
In article <980uh3$820$1@orpheus.gellyfish.com>,
Jonathan Stowe <gellyfish@gellyfish.com> wrote:
>
> Get a grip. If I am creating a private temporary file for the use of
> my process then if locking was to become an issue then someone would
> really be in need of treatment - either me or the OS designer :)
>
> /J\
we are NOT talking about a private process we are talking
about a SHARED system that can have race condidtions.
of course if it is a closed system with no file sharing
you do not need the locks ; )
------------------------------
Date: Tue, 06 Mar 2001 01:43:45 -0500
From: ZepHead <groovyt@erols.com>
Subject: Re: flock and close with empty read strangeness
Message-Id: <groovyt-395F4F.01434506032001@virt-reader.news.rcn.net>
In article <ta7kc8i69qr452@corp.supernews.com>,
Chris Stith <mischief@velma.motion.net> wrote:
>
> Especially since create and write require similar privs on the OS level.
> Can you imagine the headache of implementing "if the user has write
> permissions on the directory, they can read a file that doesn't exist"?
>
> Chris
grrr i meant write
+<< is better anyway
------------------------------
Date: Tue, 06 Mar 2001 02:02:44 -0500
From: ZepHead <groovyt@erols.com>
Subject: Re: flock and close with empty read strangeness
Message-Id: <groovyt-21A9FE.02024406032001@virt-reader.news.rcn.net>
In article <slrn9a7btj.8a8.abigail@tsathoggua.rlyeh.net>,
abigail@foad.org (Abigail) wrote:
>
>
> So, while I'm reading /etc/passwd, the system administrator cannot
> add new accounts?
>
> I don't think so.
>
>
> Abigail
there is no reason new accounts can't be added at the same time.
it just means the cache flush would have to wait until
it can get a lock then flush.
if the OS is written well, a write will have higher priority
than a read anyway so you will never get a backup of shared locked reads
staling a write.
------------------------------
Date: 6 Mar 2001 07:48:30 GMT
From: "Scott R. Godin" <webmaster@webdragon.munge.net>
Subject: Re: HELP!!!! perl script that writes to a text database question.
Message-Id: <9824oe$eab$0@216.155.32.141>
In article <TYVo6.28684$W05.6105347@news1.rdc1.mi.home.com>, "alan
scanlon" <alan@afdsolutions.com> wrote:
| my perl script below writes to a text database that reads each entry
| by a new line. the problem is that whenever a user enters data
| useing a multiline-text box input form, where ever they push enter
| to go to the next line in the textbox it also jumps down to the next
| line in my text database file making only the first line of the
| entry available. what i need is for whenever they push enter in the
| input text box to switch it to a <br> in the database file and keep
| the entire entry on one line in my database file.
|
| please let me know of the best solution to fix my existing code.
|
| thank you in advance, alan (aka: perl_newbie)
[snip of code sample]
I ran into something similar recently and here's what I wound up doing
with it:
sub fix_paragraphs () {
my $fixee = shift;
# contributed by Brad Baxter, c.l.p.m
$fixee =~ s/(?:[\r\n]{2})+/<br><br>/g;
$fixee =~ s/[\r\n]/<br>/g;
# my original regexes
# $fixee =~ s|\n\n|<br><br>|g;
# $fixee =~ s|\r\r|<br><br>|g;
# $fixee =~ s/\n|\r/<br>/g;
# $fixee =~ s/<br><br><br><br>/<br><br>/g;
return $fixee;
}
and I have them in my output sections as something like
...
td({-valign=>'top'}, fix_paragraphs( escapeHTML("$UT::mod_description")
) ),
...
Note that I use CGI.pm's escapeHTML() to prevent any nasties the users
might insert from being processed AS html. (:
(note also that I'm using the other nice feature
import_names('UT');
to bring all the param() items into the $UT::* namespace, making my life
easier... not that this has anything to do with your question :o)
try the sub on your params and see how that affects the results.
As always, Caveat Emptor.
HTH, though! :)
--
unmunge e-mail here:
#!perl -w
print map {chr(ord($_)-3)} split //, "zhepdvwhuCzhegudjrq1qhw";
# ( damn spammers. *shakes fist* take a hint. =:P )
------------------------------
Date: Tue, 06 Mar 2001 06:15:06 GMT
From: tjla@guvfybir.qlaqaf.bet (Gwyn Judd)
Subject: Re: Is Perl right for me?
Message-Id: <slrn9a90dr.17t.tjla@thislove.dyndns.org>
I was shocked! How could Jonathan Stowe <gellyfish@gellyfish.com>
say such a terrible thing:
>On 4 Mar 2001 19:13:00 -0000 Jonathan Stowe wrote:
>> On Sun, 04 Mar 2001 13:19:21 GMT Bart Lateur wrote:
>>> Holly Bortfeld wrote:
>>>
>>>>I can write HTML
>>>>from scratch without an editor.
>>>
>>> Wow, that is strong. So how do you write HTML? Using a speech
>>> recognition system?
>>>
>>
>> copy CON: somefile.html
>>
>> or
>>
>> cp /dev/tty somefile.html
>>
>
>or of course the editor of champions :
>
> dd if=/dev/tty of=somefile.html
|
cat /dev/random | sed -e $SOME_SCRIPT > somefile.html
I'm still working on it though
--
Gwyn Judd (print `echo 'tjla@guvfybir.qlaqaf.bet' | rot13`)
NOBODY EXPECTS THE SPANISH INQUISITION!
------------------------------
Date: Tue, 6 Mar 2001 11:40:18 +0800
From: "Hilda" <hilda@invopower.com>
Subject: Net::FTP
Message-Id: <3aa455ff$0$21785@wodc7nh7.news.uu.net>
Hi,
I am not sure whether my question is out of topic or not. Anyway, hope that
someone can answer me.
I use Net::FTP to ftp some files to the ftp server, using:
put_unique('C:/uploads/abc.txt') function, but when i use it, it always
return " 'STOU abc.txt': Invalid number of parameters". And the transfer of
file is unsuccessful. I already checked the remote path which didn't have
the abc.txt file in it. So, just wonder anybody know what's matter of it.
THanks very much!!!
Hilda
------------------------------
Date: Mon, 05 Mar 2001 18:59:35 -0800
From: John Lockwood <john@particlewave.com>
Subject: Re: Opening files on other Windows machines
Message-Id: <cik8at83n3q848hs3rp8pv8ndbknse0fhs@4ax.com>
On Tue, 6 Mar 2001 12:27:17 +1100, "Iain Hosking"
<iain_hosking@hotmail.com> wrote:
>How do I open a file on another Windows machine?
>
>I can't use a drive mapping as this is a CGI script and it's running in the
>system account.
>
>Microsoft's \\machine\drive\foo\bar syntax doesn't work.
>
Yes it does, just tried it.
open(OUTPUT, ">>\\\\machine_name\\sharename\\foo.txt");
print(OUTPUT "Hello there, this works");
close(OUTPUT);
>I'm using ActiveState Perl 5.6.0 (build 623).
>
>Thanks
>
>Iain
>
------------------------------
Date: Tue, 06 Mar 2001 06:54:11 GMT
From: tjla@guvfybir.qlaqaf.bet (Gwyn Judd)
Subject: Re: pi day
Message-Id: <slrn9a92n3.17t.tjla@thislove.dyndns.org>
I was shocked! How could Russ Jones <russ_jones@rac.ray.com>
say such a terrible thing:
>Coincidence? None of these has anything to do with Perl or pi, but I
>really would like to get some Perl versions of pi calculations, the
>more screwy the better. Anno's already suggested the "dropping
>buckshot onto a circle" method.
Can I just say, that method sucks. I remember doing that for a class in
Numerical Analysis once. I seem to recall having to do 1000000
iterations to get something like 3dp. This makes me think of a worse
method just now. You all know that it requires "only" 10dp or so of pi
to be able to accurately measure the diameter of the universe. Well then
why not turn this method around? Imagine drawing a large circle, measure
it's circumference (in pixels) and then divide this by the diameter.
Keep expanding the circle till you get sufficient accuracy.
This doesn't seem to converge though. Anyone have any idea why?
#!/usr/bin/perl -w
# calculates pi (poorly) using bresenham's circle algorithm
use strict;
sub pi
{
my $radius = shift;
my $d = 3 - (2 * $radius);
my $x = 0;
my $y = $radius;
my $pixels = 0;
while ($x < $y)
{
if ($d < 0)
{
$d += 4 * $x + 6;
}
else
{
$d += 4 * ($x - $y) + 10;
$y = $y - 1;
$pixels += 0.5;
}
$x = $x + 1;
$pixels++;
}
my $circ = $pixels * 8;
my $pi = $circ / (2 * $radius);
$pi;
}
print pi shift;
--
Gwyn Judd (print `echo 'tjla@guvfybir.qlaqaf.bet' | rot13`)
The art of simplicity is a puzzle of complexity.
-- Doug Horton
------------------------------
Date: Mon, 05 Mar 2001 21:41:50 -0800
From: ul141@victoria.tc.ca
Subject: Regex problem with array
Message-Id: <ul141-0503012142060001@10.10.10.2>
I'm fairly new to Perl so forgive me if this is pathetically simple, but
I'm having a problem with the following and could do with some help.
I have an array full of text, @thatArray. Basically, whenever the code
below tries to grep @thatArray, I get an unmatched () error. The second
member of @thisArray has a forward bracket as part of the string, which is
causing the problem I know, but how to get around it? Backslashing the
bracket in the string doesn't seem to help . . .
@thisArray = ('string1', '(string2', 'string3');
for ($n = 0; $n < @thisArray; $n++)
{
$count = grep /$thisArray[$n]/, @thatArray;
print " I saw $thisArray[$n] exactly $count times.\n";
}
It's driving me nuts. Please someone save my sanity . . .
Glenn
------------------------------
Date: Tue, 06 Mar 2001 01:37:05 -0500
From: Jay Tilton <nouser@emailunwelcome.com>
Subject: Re: Regex problem with array
Message-Id: <c919at4u1lhijj43fk47ljsgt44judfeq1@4ax.com>
ul141@victoria.tc.ca wrote:
>below tries to grep @thatArray, I get an unmatched () error. The second
>member of @thisArray has a forward bracket as part of the string, which is
>causing the problem I know, but how to get around it?
The easy way is to use metaquote, \Q, in the regex.
>@thisArray = ('string1', '(string2', 'string3');
>
>for ($n = 0; $n < @thisArray; $n++)
> {
> $count = grep /\Q$thisArray[$n]\E/, @thatArray;
# added ^^ added ^^
> print " I saw $thisArray[$n] exactly $count times.\n";
> }
Briefly, after variable interpolation, all characters including metas
between \Q and \E are taken literally.
------------------------------
Date: 06 Mar 2001 01:45:15 -0500
From: Joe Schaefer <joe+usenet@sunstarsys.com>
Subject: Re: Regex problem with array
Message-Id: <%G%o6.484$642.27140@news2.atl>
ul141@victoria.tc.ca writes:
> I have an array full of text, @thatArray. Basically, whenever the code
> below tries to grep @thatArray, I get an unmatched () error. The second
> member of @thisArray has a forward bracket as part of the string,
> which is causing the problem I know, but how to get around it?
I think you want to quote the metacharacters in a string
that winds up in a regexp. Did you check
% perldoc -q quote
already?
> Backslashing the bracket in the string doesn't seem to help . . .
Why not? It should work fine with single quoted strings. Double
quotes need double slashes.
> @thisArray = ('string1', '(string2', 'string3');
>
> for ($n = 0; $n < @thisArray; $n++)
> {
> $count = grep /$thisArray[$n]/, @thatArray;
my $count = grep /\Q$thisArray[$n]/, @thatArray;
^^
This is a better fix, and the FAQ recommends this approach
as well. See the documentation in
% man perlre
for details on \Q.
> print " I saw $thisArray[$n] exactly $count times.\n";
> }
However, since you're just checking for a substring match,
why not just use index ( perldoc -f index ) and avoid the
escaping issue?
for my $substr (@thisArray) {
my $count = grep { index($_, $substr) >= 0 } @thatArray;
print " I saw $substr exactly $count times.\n";
}
HTH
--
Joe Schaefer "I hate a country witout a derrick."
--Mark Twain
------------------------------
Date: Mon, 05 Mar 2001 18:24:40 -0800
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: Regex question (newbie)
Message-Id: <3AA44A68.6CB7DC9@stomp.stomp.tokyo>
Adam Warner wrote:
> Thanks Tad,
> > Perl can easily act like a not-grep as you describe:
> > my $a = $1 if /(.*,)/;
> >>(and later work out how to make
> >>the match non-greedy).
> > my $a = $1 if /(.*?,)/;
> That's great! Sorry I was confusing the way matches are found using
> regular expressions and what grep outputs. That's why the newbie alert
> was there :-)
> Full steam ahead now though.
Hmmm, maybe one-third ahead full. This regex method
displayed is quite slow and inefficient. Consider
using a substring method when possible.
$_ = "this, is a test";
$a = substr ($_, 0, index ($_, ",") + 1);
I am guesstimating this substring method to be
three times as fast and uses less memory to
an extent greater than it is faster.
Using a regex, using a regex match, both are ok
but most often prove to be a bad choice for
Perl programming.
Godzilla!
------------------------------
Date: Mon, 5 Mar 2001 19:28:55 -0800
From: Steven Kuo x7914 <skuo@mtwhitney.nsc.com>
Subject: Re: Small problem: dup'ing DATA and $.
Message-Id: <Pine.GSO.4.21.0103051926040.17265-100000@mtwhitney.nsc.com>
On Tue, 6 Mar 2001, Clinton A. Pierce wrote:
> I was tinkering with $. and the DATA filehandle, and ran into this small
> problem. Look at the code:
>
> # Not work
> open(FOO, "<&DATA") || die;
> $_=<DATA>;
> if ($a=<FOO>) {
> print "read ok\n";
> } else {
> print "not ok: $!\n";
> }
> __END__
> BLAH
> HLAG
> NARF
> POIT
>
> What SHOULD happen (IMHO) is that I dup DATA, read a line from DATA into
> $_ ("BLAH\n") and then read a line from FOO into $a (I'd take either "HLAG\n"
> or "BLAH\n" at this point :)
>
> But $a=<FOO> fails, and the "not ok" branch is taken. Worse, $! isn't
> set to anything useful. Did these tired eyes miss something obvious?
Is this what you wanted?
#! /usr/local/bin/perl
use strict;
use warnings;
my $begin = tell DATA;
open (FOO,"<&DATA") or die ("Could not dup DATA: $!");
$_ = <DATA>;
print $_;
seek FOO, $begin, 0;
if (defined($a=<FOO>)) {
print "$. $a";
} else {
print "Not okay: $!";
}
__DATA__
BLAH
HLAG
NARF
POIT
--
Steven Kuo
perl -MFile::Basename=basename -e 'printf "Just Another %s Hacker",
ucfirst(basename($^X))'
------------------------------
Date: 06 Mar 2001 02:10:29 +0000
From: Jon Ericson <Jonathan.L.Ericson@jpl.nasa.gov>
Subject: Re: use strict (vars, etc.)
Message-Id: <863dcrr6ju.fsf@jon_ericson.jpl.nasa.gov>
David Bakhash <cadet@alum.mit.edu> writes:
> I have the simple situation. I want to define a function which, when
> called, will be done in an environment where some dynamic variables
> will be defined (i.e. with local()). But I do want to make Perl
> require me to declare these as such in my function. Can someone tell
> me if this is right:
>
> sub function_1 {
> local $arg_1 = shift();
> function_2();
> }
>
> sub function_2 {
> our($arg_1); # since this executes in that dynamic extent
> my $arg_2 = shift();
> print "arg 1 and arg 2 are $arg_1 and $arg_2.\n";
> }
$ perldoc -f our
our EXPR
An "our" declares the listed variables to be valid globals
within the enclosing block, file, or "eval". That is, it has
the same scoping rules as a "my" declaration, but does not
create a local variable. If more than one value is listed,
the list must be placed in parentheses. The "our" declaration
has no semantic effect unless "use strict vars" is in effect,
in which case it lets you use the declared global variable
without qualifying it with a package name. (But only within
the lexical scope of the "our" declaration. In this it
differs from "use vars", which is package scoped.)
...
$ perldoc -f local
local EXPR
You really probably want to be using "my" instead, because
"local" isn't what most people think of as "local". See the
Private Variables via my() entry in the perlsub manpage for
details.
...
Were you looking for something like:
#!/usr/bin/perl -w
use strict;
sub function_1 {
our $arg_1 = shift();
function_2("'nother test");
}
sub function_2 {
our($arg_1); # since this executes in that dynamic extent
my $arg_2 = shift();
print "arg 1 and arg 2 are $arg_1 and $arg_2.\n";
}
function_1('test');
Jon
------------------------------
Date: 06 Mar 2001 02:26:35 +0000
From: Jon Ericson <Jonathan.L.Ericson@jpl.nasa.gov>
Subject: Re: use strict (vars, etc.)
Message-Id: <86y9ujpr8k.fsf@jon_ericson.jpl.nasa.gov>
"Dave Brondsema" <brondsema@my-deja.com> writes:
> I recall reading in some perl docs that local doesn't do what is expected.
> Use 'my' instead; for more info look for the documentation on local (sorry,
> i'm too lazy right now to point you to it)
I would consider this to be the bad kind of lazy. There is a FAQ that
addresses this issue, an item "local" in perlfunc, and extensive
discussion in perlsub. Location of other documents left as an
exercise for the reader. :)
Jon
------------------------------
Date: Mon, 5 Mar 2001 20:30:51 -0600
From: "Charles K. Clarkson" <c_clarkson@hotmail.com>
Subject: Re: why won't "format FILEHANDLE" work??
Message-Id: <778BD127A519EDEE.DFC3A3442DB72C2B.C8D2C1707F84E7A9@lp.airnews.net>
David Charles <administrator@playauction.com> wrote
: --==START OF CODE SNIPPET==--
[SNIP]
: sort keys %dat;
BTW, What do you think this line does?
[MORE SNIPPAGE]
: $^ = REPORT_TOP;
: $~ = REPORT;
: write;
Change this line to
write REPORT;
: close outREPORT;
: --==END OF CODE SNIPPET==--
HTH,
Charles K. Clarkson
------------------------------
Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 16 Sep 99)
Message-Id: <null>
Administrivia:
The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc. For subscription or unsubscription requests, send
the single line:
subscribe perl-users
or:
unsubscribe perl-users
to almanac@ruby.oce.orst.edu.
| NOTE: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.
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.
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 V10 Issue 424
**************************************