[18901] in Perl-Users-Digest
Perl-Users Digest, Issue: 1069 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Jun 6 00:11:17 2001
Date: Tue, 5 Jun 2001 21:05:09 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <991800309-v10-i1069@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Tue, 5 Jun 2001 Volume: 10 Number: 1069
Today's topics:
Re: $^O value for PERL on a Macintiosh <comdog@panix.com>
delimiter? <timster@worldnet.att.net>
Re: delimiter? (Damian James)
Re: Easier access to system call output - maybe output (Tad McClellan)
Re: FAQ 5.5: How can I manipulate fixed-record-length <goldbb2@earthlink.net>
Re: FAQ 6.19: What good is "\G" in a regular expressi <johnlin@chttl.com.tw>
Help on CPAN shell <timster@worldnet.att.net>
help w.r.t perlembed in multi-threaded env (Alex Wold)
interpolate (syntax help understand) (X3)
Re: mailing from perl <goldbb2@earthlink.net>
Re: perl debugging questions <mystill@yahoo.com>
Re: Recursing a directory tree (Martien Verbruggen)
Re: Recursing a directory tree <goldbb2@earthlink.net>
Re: Recursing a directory tree <goldbb2@earthlink.net>
Re: releasing array memory <der.prinz@gmx.net>
Re: use Module (if it exists) <johnlin@chttl.com.tw>
Re: using output of server program (Joe Smith)
Re: who is authentic? $hash_ref->{'key'} or $hash_ref{k <dontuspamme@nospammers.com>
Re: who is authentic? $hash_ref->{'key'} or $hash_ref{k (Greg Bacon)
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Tue, 05 Jun 2001 23:22:09 -0400
From: brian d foy <comdog@panix.com>
Subject: Re: $^O value for PERL on a Macintiosh
Message-Id: <comdog-BC043A.23220905062001@news.panix.com>
In article <9fjrqj$2uf4$1@nntp1.ba.best.com>, inwap@best.com (Joe
Smith) wrote:
> In article <1eu83fh.1no41vr9yvxs0N%g.durr@free.fr>,
> Guillaume DURR <g.durr@free.fr> wrote:
> >$0 print the name of the script that is being executed
>
> Looks like you need to change the font used by your news reader; it
> has caused you to confuse a zero (0) with a capital-o (O).
perhaps you should read the documentation or learn to program
in the shell.
from perlvar:
$PROGRAM_NAME
$0 Contains the name of the file containing the Perl
script being executed. On some operating systems
assigning to "`$0'" modifies the argument area
that the ps(1) program sees.
yes Virgina, there is a zero. you might notice the lack of a
speical variable $O as well.
--
brian d foy <comdog@panix.com>
CGI Meta FAQ - http://www.perl.org/CGI_MetaFAQ.html
Troubleshooting CGI scripts - http://www.perl.org/troubleshooting_CGI.html
------------------------------
Date: Wed, 06 Jun 2001 03:38:27 GMT
From: Tim <timster@worldnet.att.net>
Subject: delimiter?
Message-Id: <3B1DA595.9C2F00C6@worldnet.att.net>
perl -e "@INC" shows:
D:/Perl/libD:/Perl/site/lib.
I don't see a delimiter between "D:/Perl/lib" and "D:/Perl/site/lib".
How does it know that this is really two directories instead of one?
------------------------------
Date: 6 Jun 2001 04:03:27 GMT
From: damian@qimr.edu.au (Damian James)
Subject: Re: delimiter?
Message-Id: <slrn9hras6.p8m.damian@puma.qimr.edu.au>
Tim chose Wed, 06 Jun 2001 03:38:27 GMT to say this:
>perl -e "@INC" shows:
>D:/Perl/libD:/Perl/site/lib.
>
>I don't see a delimiter between "D:/Perl/lib" and "D:/Perl/site/lib".
>How does it know that this is really two directories instead of one?
>
Try
perl -e '$" = "\n" ; print "@INC\n"'
or
perl -e 'print join("\n", @INC), "\n"'
HTH
Cheers,
Damian
--
@:=grep!($;+=m!$/|#!),split//,<DATA>;@;=0..$#:;while(@;){for($;=@;;--$;;)
{@;[$;,$:]=@;[$:,$;]if($:=rand$;+$|)!=$;}push@|,shift@;if$;[0]==@|;select
$,,$,,$,,1/80;print qq x\bxx((@;+@|)*$|++),@:[@|,@;],!@;&&$/} __END__
Just another Perl Hacker # rev 3.1 -- a JAPH in progress, I guess...
------------------------------
Date: Tue, 5 Jun 2001 22:25:06 -0400
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Easier access to system call output - maybe output to a scaler?
Message-Id: <slrn9hr542.3pg.tadmc@tadmc26.august.net>
Will Cardwell <wellhaven@worldnet.att.net> wrote:
>
>In VMS (sorry), I would like to do system commands and operate on the output
>from the call in the simplest way, say output to a scaler instead of a file.
[snip]
>Any help is appreciated.
Help can be had by reading the documentation for the software
that you are using:
perldoc -f system
"... This is I<not> what you want to use to capture the output
from a command, for that you should use merely ..."
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Tue, 05 Jun 2001 23:20:13 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: FAQ 5.5: How can I manipulate fixed-record-length files?
Message-Id: <3B1DA16D.48972079@earthlink.net>
Eli the Bearded wrote:
>
> In comp.lang.perl.misc, Benjamin Goldberg <goldbb2@earthlink.net> wrote:
> > Not only doesn't it scale well, but it's a bad habit to get into -- you
> > should almost never use symbolic references, when there are other ways
> > to do what you want.
>
> Agreed.
>
> > our ($PS_T) = 'A6 A4 A7 A5 A*';
> > our (@PS_N) = qw!pid tt stat time command!;
> ...
> > Here I've eliminated the variables ($pid, $tt, $stat, $time, $command)
> > which were never really needed in the first place, and changed
> > everything which was global, but didn't need to be, into a lexical.
>
> Huh? Do I misunderstand 'our'? Your variables, since not 'my'ed or
> 'local'ed are global variables.
>
> $ perldoc -f our
> our EXPR
> An "our" declares the listed variables to be valid
> globals within the enclosing block, file, or
> ^^^^^^^
>
> Elijah
> ------
> would use 'my' since he does not like to gratuitously break compatibility
Well, you could use use vars, if you want, but then you wouldn't be able
to declare and assign things in the same line.
use vars qw($PS_T @PS_N);
$PS_T = 'A6 A4 A7 A5 A*';
@PS_N = qw!pid tt stat time command!;
It's not as pretty, though.
--
The longer a man is wrong, the surer he is that he's right.
------------------------------
Date: Wed, 6 Jun 2001 09:55:21 +0800
From: "John Lin" <johnlin@chttl.com.tw>
Subject: Re: FAQ 6.19: What good is "\G" in a regular expression?
Message-Id: <9fk2dg$ion@netnews.hinet.net>
"PerlFAQ Server" wrote
> For example, suppose you had a line of text quoted in standard mail and
> Usenet notation, (that is, with leading ">" characters), and you want
> change each leading ">" into a corresponding ":". You could do so in
> this way:
>
> s/^(>+)/':' x length($1)/gem;
>
> Or, using "\G", the much simpler (and faster):
>
> s/\G>/:/g;
I noticed the /m option and found that they are not equivalent:
$_ = ">>> line one\n>>> line two\n";
s/^(>+)/':' x length($1)/gem;
print;
__END__
::: line one
::: line two
But
s/\G>/:/g;
gets the result of
::: line one
>>> line two
Hmm... to correct this, we should... add an /m here?
s/\G>/:/gm;
result is still
::: line one
>>> line two
Nope? Or this (multiline case) is not achievable by \G + /g ?
Thank you.
John Lin
------------------------------
Date: Wed, 06 Jun 2001 03:56:26 GMT
From: Tim <timster@worldnet.att.net>
Subject: Help on CPAN shell
Message-Id: <3B1DA9CC.9E668B38@worldnet.att.net>
Can someone please tell me why I am unable to successfully do:
force install XML::DOM
within 'perl -MCPAN -e shell' ? As it is trying to install XML::DOM, it
realizes it needs XML::Parser, so it attempts to get it. But I get:
CPAN.pm: Going to build T/TJ/TJMATHER/libxml-enno-1.05.tar.gz
Checking if your kit is complete...
Looks good
Warning: prerequisite XML::Parser 2.30 not found at
D:/Perl/lib/ExtUtils/MakeMa
er.pm line 343.
Writing Makefile for XML::XQL::Parser
Writing Makefile for libxml-enno
Microsoft (R) Program Maintenance Utility Version 1.50
Copyright (c) Microsoft Corp 1988-94. All rights reserved.
makefile(545) : fatal error U1035: syntax error : expected ':' or '='
separator
Stop.
C:\GNU\bin\nmake.exe -- NOT OK
Running make test
Can't test without successful make
Running make install
make had returned bad status, install seems impossible
Why does the make fail? What's with the syntax error??? All I want to
do is run XSLint, but since it needs XML::DOM and XML::Parser (per the
notes), I am trying to get those modules, but I have not been successful
at all so far. Any suggestions?
------------------------------
Date: 5 Jun 2001 19:42:04 -0700
From: zeelium@my-deja.com (Alex Wold)
Subject: help w.r.t perlembed in multi-threaded env
Message-Id: <3615d6bb.0106051842.20e78a23@posting.google.com>
Hi Perl Gurus,
i'm using perlembed that comes with 5.6.1 in a multi-threaded
environment and following is the problem:
In a C program, i spawn off 4 threads and each thread
allocates an instance of perl interpreter and will try
to execute a perl subroutine. The perl subroutine uses
the Net.Telnet module to telnet into a host and executes
some commands like "uname -a" and "who".
Finally the subroutine prints the results.
When i serially execute the threads the results comeback fine.
but when i execute them concurrently the telnet fails.
looks like although there are four interpreter instances,
they seem to share some global data that gets overwritten
when the threads are interleaved.
So, can multiple instances of perl interpreters be
executed concurrently in its own thread ?
i've tried with both hand built perl 5.6.1 and
perbuilt active-perl 5.6.1 and the results are the same.
any help/suggestions/experiences would be *Greatly Appreciated*.
additional info:
------
OS is Redhat Linux 2.2.14
Compiler is gcc: egcs-2.91.66
perl version: 5.6.1 compiled with options: MULTIPLICITY USE_ITHREADS
USE_LARGE_FILES PERL_IMPLICIT_CONTEXT
run the executable with the perl script name as argument.
following is the C code, followed by the the perl code:
thanx !
Alex
-- C code --
#include ?stdio.h?
#include ?EXTERN.h?
#include ?perl.h?
#include ?pthread.h?
// for dynaloader
EXTERN_C void xs_init (pTHXo);
EXTERN_C void boot_DynaLoader (pTHXo_ CV* cv);
EXTERN_C void
xs_init(pTHXo)
{
char *file = __FILE__;
dXSUB_SYS;
/* DynaLoader is a special case */
newXS("DynaLoader::boot_DynaLoader", boot_DynaLoader, file);
}
// thread entry function
void* prl_thr_1(void *arg);
// structure to pass argc and argv to the thread entry function
typedef struct argc_v
{
int *acptr;
char **avptr;
} prl_thr_arg;
prl_thr_arg ex_arg;
int main(int argc, char **argv, char **env)
{
pthread_t thr[10];
int thr_cnt = 4;
// subroutines in the perl script each script executes
char *subs[] = { "prl_sub1", "prl_sub2", "prl_sub3", "prl_sub4" };
int i, thr_status;
// needed to pass the argc and argv to perl_call_argv
ex_arg.acptr = ?argc;
ex_arg.avptr = argv;
for (i = 0; i ? thr_cnt; i++)
{
thr_status = pthread_create(thr+i, NULL, prl_thr_1, subs[i]);
}
for (i = 0; i ? thr_cnt; i++)
{
pthread_join(thr[i], 0);
}
return 0;
}
void* prl_thr_1(void *arg)
{
char *sub = (char *)arg;
PerlInterpreter *one_perl = perl_alloc();
char *args[] = { NULL };
printf("\n--Thread %d\n", pthread_self());
PERL_SET_CONTEXT(one_perl);
perl_construct(one_perl);
PERL_SET_CONTEXT(one_perl);
perl_parse(one_perl, xs_init, *(ex_arg.acptr), ex_arg.avptr,
NULL);
PERL_SET_CONTEXT(one_perl);
Perl_call_argv(one_perl, sub, G_DISCARD | G_NOARGS, args);
PERL_SET_CONTEXT(one_perl);
perl_destruct(one_perl);
PERL_SET_CONTEXT(one_perl);
perl_free(one_perl);
}
----- perl code ----
# different hosts but the same code.
# also the uid/password pair is valid
sub prl_sub1 {
use Net::Telnet ();
my ($hostname) = "penguin1";
my ($uid) = "root";
my ($passwd) = "abcd1234";
my ($timeout) = 100;
my ($login_prompt) = '/\w*# $/';
my ($execute) =
"echo \"\"; uname -a; echo \"\"; uptime; echo \"\"; who; echo
\"\"";
my ($t) = new Net::Telnet(Timeout =? $timeout, Prompt =?
$login_prompt);
$t-?open($hostname);
$t-?login($uid, $passwd);
my (@lines) = $t-?cmd($execute);
print @lines;
}
sub prl_sub2 {
use Net::Telnet ();
my ($hostname) = "penguin2";
my ($uid) = "root";
my ($passwd) = "abcd1234";
my ($timeout) = 100;
my ($login_prompt) = '/\w*# $/';
my ($execute) =
"echo \"\"; uname -a; echo \"\"; uptime; echo \"\"; who; echo
\"\"";
my ($t) = new Net::Telnet(Timeout =? $timeout, Prompt =?
$login_prompt);
$t-?open($hostname);
$t-?login($uid, $passwd);
my (@lines) = $t-?cmd($execute);
print @lines;
}
sub prl_sub3 {
use Net::Telnet ();
my ($hostname) = "sumit-lab";
my ($uid) = "root";
my ($passwd) = "abcd";
my ($timeout) = 100;
my ($login_prompt) = '/\w*# $/';
my ($execute) =
"echo \"\"; uname -a; echo \"\"; uptime; echo \"\"; who; echo
\"\"";
my ($t) = new Net::Telnet(Timeout =? $timeout, Prompt =?
$login_prompt);
$t-?open($hostname);
$t-?login($uid, $passwd);
my (@lines) = $t-?cmd($execute);
print @lines;
}
sub prl_sub4 {
use Net::Telnet ();
my ($hostname) = "template";
my ($uid) = "root";
my ($passwd) = "abcd";
my ($timeout) = 100;
my ($login_prompt) = '/\w*# $/';
my ($execute) =
"echo \"\"; uname -a; echo \"\"; uptime; echo \"\"; who; echo
\"\"";
my ($t) = new Net::Telnet(Timeout =? $timeout, Prompt =?
$login_prompt);
$t-?open($hostname);
$t-?login($uid, $passwd);
my (@lines) = $t-?cmd($execute);
print @lines;
}
------------------------------
Date: 5 Jun 2001 20:38:55 -0700
From: imiten@yahoo.com (X3)
Subject: interpolate (syntax help understand)
Message-Id: <461d4acb.0106051938.5c1cab7@posting.google.com>
hello....I am looking at code snippet from perl cookbook and would
appreciate if one could help on whats interpolation...snippet goes
like this: push (@{$ttys{$user}}, $tty). its on page 141 under
discussion of hashtes with multiple values per key. similar thing I
see also under objects where in they try to explain how to write
generic objects ready for inheritence.
snippet:
%ttys = ();
open(WHO, "who|") or die "can't open who: $!";
while(<WHO>) {
($user, $tty) = split;
push(@{$ttys{$user}}, $tty);
}
foreach $user (sort keys %ttys) {
print "$user: @{$ttys{$user}}\n";
}
Please reply cc to:
imiten@yahoo.com
------------------------------
Date: Wed, 06 Jun 2001 00:04:21 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: mailing from perl
Message-Id: <3B1DABC5.1B6AB4EC@earthlink.net>
terminalsplash wrote:
>
> For emails..rather than using system calls
> u should use Mail::Send module
(1) Don't top-post. (2) Snip the parts of the post you're responding to
which aren't directly relevant. (3) Sure, using a module would probably
be better, but you ought to explain why.
--
The longer a man is wrong, the surer he is that he's right.
------------------------------
Date: Tue, 05 Jun 2001 20:16:09 -0700
From: Michael Still <mystill@yahoo.com>
Subject: Re: perl debugging questions
Message-Id: <3B1DA079.6F525007@yahoo.com>
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
please see my comments under yours below. i have some further questions
and much appreciate your time.
<p>"Clinton A. Pierce" wrote:
<blockquote TYPE=CITE>[Posted and mailed]
<p>In article <53abaf0f.0106051441.4d3d6a7@posting.google.com>,
<br> mystill@yahoo.com (Michael
Still) writes:
<br>> can someone take a look at this code and its associated error messages
<br>> and let me know how i can debug this?
<p>By reading the error messages and comparing that against what's in diagnostics.
<br>perldoc diagnostics.
<p>Your system and mine seem to be counting lines differently too.
Ah well.
<p>> here's the errors:
<br>> %> perl -w e2000.pl # invoke the script from command
line
<br>> Useless use of concatenation in void context at news.pm line 39.
<br>> Useless use of concatenation in void context at news.pm line 39.
<p>We don't have news.pm to know what's going wrong here. But diagnostics
<br>say that:
<p> (W void) You did something without a side effect in a context
that does nothing
<br> with the return value, such as a statement that
doesn't return a value
<br> from a block, or the left side of a scalar comma
operator. Very often
<br> this points not to stupidity on your part, but a
failure of Perl to parse
<br> your program the way you thought it would....[omitted,
use diagnostics
<br> in your program for more details]
<p>You probably said something like:
$foo . 'bar';
<p>As a bare statement somewhere in news.pm near line 39.</blockquote>
----------------------------------------------------------------
<br>would this satisfy your hypothesis (its from news.pm around line 39)?
<br><tt>23 sub headlines($) {</tt>
<br><tt>24 my ($category) = @_;</tt>
<br><tt>25 my $lines;</tt>
<br><tt>26 my $text = '<ul>';</tt>
<br><tt>27</tt>
<br><tt>28 open(INDEX, "$apwire_path/$category/index.htm")
|| die "Can't open file for $category: $!\n";</tt>
<br><tt>29 while ( <INDEX>
)</tt>
<br><tt>30 {</tt>
<br><tt>31
if ( m|<A HREF="<A HREF="http://web.home.net:2000/[^">http://web.home.net:2000/[^</A>"]*">([^<]+)| )</tt>
<br><tt>32
{</tt>
<br><tt>33
$text .= "<img src=/e2000/images/bullet.gif>$1<br><img src=<A HREF="http://www/global/image/blank.gif">http://www/global/image/blank.gif</A>
height=6><br>\n";</tt>
<br><tt>34 last if ++$lines >= 4;</tt>
<br><tt>35 }</tt>
<br><tt>36 }</tt>
<br><tt>37 close(INDEX);</tt>
<br><tt>38</tt>
<br><tt>39 $text . '</ul>';</tt>
<br><tt>40 return $text;</tt>
<br><tt>41 }</tt>
<p>so how SHOULD this be done so as to not get errors?
<br>
<br>
<br>
<br>
<blockquote TYPE=CITE>Is this program called e2000.pl? Your line
numbers and mine don't match
<br>up, so I have to guess.</blockquote>
yes the program is called e2000.pl. I can send you the src if that would
help..and if you have the time :)
<br>
<br>
<blockquote TYPE=CITE>> Global symbol "screen" requires explicit package
name at e2000.pl line
<br>> 152.
<p>You have "strict" in effect (use strict) and @screen hasn't been declared
with
<br>my in that scope. (I think that's line 152...)
<p>> Too many arguments for culture::dining at e2000.pl line 205, near
"})
<br>> "
<br>> Too many arguments for culture::film at e2000.pl line 206, near "})
"
<br>> Too many arguments for culture::music at e2000.pl line 207, near
"}) "
<br>> Too many arguments for culture::tv at e2000.pl line 208, near "})
"
<br>> Execution of e2000.pl aborted due to compilation errors.
<p>We don't have these modules to tell, but from the look of it someone
used
<br>a prototype and then lied about the argument count later. Most
likely
<br>someone said something like:
<p> sub foo () {
<br> }</blockquote>
Which modules dont you have to be able to tell. i believe this problem
is within the primary module (e2000.pl)
<br>the lines that seem screwed up are like this:
<br><tt> elsif ( $page eq 'dining' ) {
return culture::dining($fields{screen}) }</tt>
<br><tt> elsif ( $page eq 'chartsfilms' ) { return
culture::film($fields{screen}) }</tt>
<br><tt> elsif ( $page eq 'chartsmusic' ) {
return culture::music($fields{screen}) }</tt>
<br><tt> elsif ( $page eq 'chartstv' )
{ return culture::tv($fields{screen})
}</tt>
<p>where in each line, $fields is the array, and screen is the index we
want in that array
<blockquote TYPE=CITE>
<p>Not knowing what those parens do (perl-style prototypes) and suffering
from too
<br>much JavaScript programming. See the perlsub manpage for details.</blockquote>
thanks for this bit of direction and the time you spent on it.
<br>if you could take one more look at the questions left on this page,
it would be awesome.
<p>\michael
<blockquote TYPE=CITE>
<p>--
<br> Clinton A. Pierce
Teach Yourself Perl in 24 Hours *and*
<br> clintp@geeksalad.org
Perl Developer's Dictionary -- May 2001
<br>"If you rush a Miracle Man, for details, see
<a href="http://geeksalad.org">http://geeksalad.org</a>
<br> you get rotten Miracles."
--Miracle Max, The Princess Bride</blockquote>
</html>
------------------------------
Date: Wed, 06 Jun 2001 02:27:33 GMT
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: Recursing a directory tree
Message-Id: <slrn9hr58o.f15.mgjv@verbruggen.comdyn.com.au>
On Mon, 04 Jun 2001 19:58:41 GMT,
Nan Wang <nwang@shell3.shore.net> wrote:
> Eric Bohlman <ebohlman@omsdev.com> wrote:
>> Nan Wang <nwang@shell3.shore.net> wrote:
>>> I don't know why you think I was being defensive, I have nothing to be
>>> ashamed off. Like I said I write scripts to get things done, not for
>>> people to frame it and stick it on the wall and boggle at how few lines it
>>> took. I was rather pissed off at his nitpicking, anal retentiveness and
>>> his holier-than-thou attitude. Can I improve my code? Definitely, but
>>> I'll improve it the way I want, not as Martien mandates.
>
>> He wasn't *mandating* anything, just *suggesting* things based on his own
>> experience and that of a lot of other very experienced programmers.
>
> What makes you think I wanted his suggestions in the first place?
You posted your code here. The code didn't work, and couldn't work in
the way you said it should. Posting crap to this newsgroup gets your
free code reviews.
Rest assured, you won't get any more from me. You state you write code
to get the job done, which is obviously not true, judging by the
sample you posted. You are obviously not interested in improving your
code, or your attitude towards coding, so..
see ya. or rather, won't.
Martien
--
Martien Verbruggen |
Interactive Media Division | "In a world without fences,
Commercial Dynamics Pty. Ltd. | who needs Gates?"
NSW, Australia |
------------------------------
Date: Tue, 05 Jun 2001 23:57:40 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Recursing a directory tree
Message-Id: <3B1DAA34.2C76EF17@earthlink.net>
Martien Verbruggen wrote:
>
> On Mon, 04 Jun 2001 02:45:03 GMT,
> Nan Wang <nwang@shell3.shore.net> wrote:
> > Benjamin Goldberg <goldbb2@earthlink.net> wrote:
> >> Nan Wang wrote:
> >>>
> >>> sub traverse {
> >>> no strict 'refs';
> >>> my ($startdir,$i)=@_;
> >>> $i++;
> >>> my $FH="FH"."$i";
> >>> opendir ("$FH",$startdir) or die "blah";
>
> [I will try not to repeat what the previous poster already said.]
[snip]
> >>> foreach $file (@allfiles) {
>
> Why didn't you just do
>
> foreach my $file (@allfiles)
>
> or even leave out the whole temporary array?
There are advantages and disadvantages to storing readdir's output in a
list, versus using readdir to iterate over the directory handle.
If we have deeply nested directories, your method [iterating over $dh]
will have a lot of directory handles open -- but it uses less memory.
Mine, OTOH, never has more than one handle open at a time, and then only
briefly, but might use alot of memory.
Keeping in mind that some OSs limit the number of open handles, throwing
memory at the problem to make it go away seems to be the perlish thing
to do.
[snip]
> If I had to come up with a subroutine that does this, I'd probably
> write it more like:
>
> sub traverse
> {
> my $dir = shift;
>
> opendir (my $dh, $dir) or
> warn("Couldn't opendir '$dir': $!\n"), return;
> while (my $file = readdir($dh))
> {
> next if $file eq '.' || $file eq '..';
> if (-d "$dir/$file")
> {
> print "DIR: $dir/$file\n";
> traverse("$dir/$file", @_);
> }
> else
> {
> print "NONDIR: $dir/$file\n";
> }
> }
> }
>
> But I wouldn't actually use this in production code.
> You see, it doesn't take any symbolic links into account, and it
> doesn't atke care of circularities in the file systems in any way.
Fortunately, solving one solves the other, since unix file systems don't
allow circularities other than ".", ".." or symbolic links. Except for
"." and "..", there are not allowed to be *any* hard links to
directories.
The solution? Replace:
if (-d "$dir/$file")
with:
if (-d "$dir/$file" and !-l _)
> A set of symlinks pointing in the wrong direction could set up an
> infinite loop.
>
> File::Find takes better care of that. While it isn't perfect, it is
> generally much better than anything you quickly can write yourself.
True. Not that a roll-your-own can't be made better with effort, but it
will probably take longer to code, and is likely to be less maintainable
[and portable] than using a module.
--
The longer a man is wrong, the surer he is that he's right.
------------------------------
Date: Tue, 05 Jun 2001 23:34:56 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Recursing a directory tree
Message-Id: <3B1DA4E0.4D112B02@earthlink.net>
Nan Wang wrote:
>
> Martien Verbruggen <mgjv@tradingpost.com.au> wrote:
[snip]
> > If I had to come up with a subroutine that does this, I'd probably
> > write it more like:
>
> > sub traverse
> > {
> > my $dir = shift;
> >
> > opendir (my $dh, $dir) or
> > warn("Couldn't opendir '$dir': $!\n"), return;
> > while (my $file = readdir($dh))
> > {
> > next if $file eq '.' || $file eq '..';
> > if (-d "$dir/$file")
> > {
> > print "DIR: $dir/$file\n";
> > traverse("$dir/$file", @_);
> > }
> > else
> > {
> > print "NONDIR: $dir/$file\n";
> > }
> > }
> > }
>
> I don't think your code ever worked, where did you get $dh from? I
> advise you to review your code first before sumbitting to this group
> again.
The $dh is created where it says opendir (my $dh, $dir). Need your
vision checked?
--
The longer a man is wrong, the surer he is that he's right.
------------------------------
Date: Wed, 6 Jun 2001 03:31:42 +0200
From: "Stefan Weiss" <der.prinz@gmx.net>
Subject: Re: releasing array memory
Message-Id: <3b1d87c2$1@e-post.inode.at>
Michael Carman <mjcarman@home.com> wrote:
> > these variables are localized, and the will go out of scope at
> > some time.
>
> You're getting lost in the semantics here. In Perl-speak, "local" means
> a localized copy of a global variable, via the local() keyword. This is
> not the same as a lexical variable declared using my(). When Ilya said
> that local variables release their memory, he was talking about
> localized globals.
Your're right, Michael, thanks for setting me straight. I did not mean
"localized" in the sense of "a global variable given a local value by
using local()", but a variable which is not supposed to be available
outside the block where it was used. So I expected (wrongly) that since
that value would not be needed anymore once the block was finished
(except for closures, maybe), the memory could be returned to the pool.
Keeping the memory allocated in case the block will be entered again
is fine with me, as long as I know how to avoid it if I really need to.
BTW, my using the word "localized" was partly based on your original
posting, where you wrote
| Don't make anything global that doesn't have to be. Use my()
| prodigously to localize variables to the smallest possible scope.
> In general, it's not very Perlish to worry about saving memory. It's a
> lot more trouble than it's worth. Just try to avoid wasting it.
I'm not really worried about memory, I just want to *understand* how
it is used. And sometimes memory does matter - like in a mod_perl
environment with some 50-100 processes, where you want to tune
performance vs memory usage.
cheers,
stefan
------------------------------
Date: Wed, 6 Jun 2001 10:31:55 +0800
From: "John Lin" <johnlin@chttl.com.tw>
Subject: Re: use Module (if it exists)
Message-Id: <9fk4i3$o5b@netnews.hinet.net>
<nobull> wrote
> If you don't like using undef to represent false then put '!!' in front
> of the calls to eval() (or '|| 0' after).
You mean:
my $false = !! undef;
print $false; # prints empty string, thus no warning of 'undef'
Great!!! I learned something here. Thank you.
By the way, do you also happen to have some trick like ||0 to convert
everything to numbers so that arithmatics won't cause warnings 'numeric'?
my $number = (undef ||0) + ('' ||0); # converted to 0 + 0
||0 is good for converting undef and empty-string to zeros,
but not 'non-false' strings.
my $number = ('non-false' ||0) + ('non-numeric' ||0); # 0 + 0 is wanted
Argument "non-numeric" isn't numeric in addition (+) at line 1.
Argument "non-false" isn't numeric in addition (+) at line 1.
My clumzy way is
my $x = 'This should be converted to zero';
my $number = ($x? $x=~/^\d+$/? $x: 0: 0) + 3; # converted to 0 + 3
which is neither proper nor general because the regex is too simplified.
(see the FAQ: How do I determine whether a scalar is a number)
I know no warnings 'numeric'; would do:
sub num { no warnings 'numeric'; shift() + 0 }
my $number = num(undef) + num('') + num('true') + num('-1.25') + num('1E+3');
But I still look forward to seeing some tricky converter like '!!' because I am
looking for the way to convert, not the way to shut up. (Think of that, '!!' can
even be applied to other languages [C/C++/Java])
Do you have any ideas? Thank you.
John Lin
------------------------------
Date: Wed, 6 Jun 2001 02:04:57 +0000 (UTC)
From: inwap@best.com (Joe Smith)
Subject: Re: using output of server program
Message-Id: <9fk349$2uri$1@nntp1.ba.best.com>
In article <9fcntl$7q3ca$1@reader02.wxs.nl>,
Daniel van den Oord <daniel304@planet.nl> wrote:
>I want to be able to open the output of this server sided program into a
>variable http://213.10.212.105:4800/getplaylisttitle?p=angel304
>anybody has any idea on this ?!?
>I tried LWP and socket and just plain simple opening it as a file.
>-LWP couldn't download it
>-socket only got errors (couldn't open socket......)
>-file returned no error but didn't do anything !!!
It's not a file, so don't try that.
Using socket is not the way to go.
Use LWP.
I tried the above URL modified to point to my server and it works.
But if Netscape can't download that URL, then don't be suprised that
LWP also cannot download that URL. It appears that the problem is
that the server is offline, not a problem with LWP.
-Joe
--
See http://www.inwap.com/ for PDP-10 and "ReBoot" pages.
------------------------------
Date: Tue, 5 Jun 2001 19:11:26 -0700
From: "kalasend at YAHOO dot COM" <dontuspamme@nospammers.com>
Subject: Re: who is authentic? $hash_ref->{'key'} or $hash_ref{key}?
Message-Id: <lggT6.60$DB3.7855@chrome-fe.eng.netapp.com>
oh no, i was asking, for the key, should I quote it or not?
seems like both are syntactically ok to me...
"Greg Bacon" <gbacon@HiWAAY.net> wrote in message
news:thqi0sbt4jt4ae@corp.supernews.com...
> That depends on what's in $hash_ref and %hash_ref. So it could be
> both, either, or neither. :-)
>
> Have you read the perlref manpage?
>
> Greg
> --
> Neither a lofty degree of intelligence nor imagination nor both together
go
> to the making of genius. Love, love, love, that is the soul of genius.
> -- Mozart
------------------------------
Date: Wed, 06 Jun 2001 02:31:51 -0000
From: gbacon@HiWAAY.net (Greg Bacon)
Subject: Re: who is authentic? $hash_ref->{'key'} or $hash_ref{key}?
Message-Id: <thr5gng2b8p46b@corp.supernews.com>
In article <lggT6.60$DB3.7855@chrome-fe.eng.netapp.com>,
kalasend at YAHOO dot COM <dontuspamme@nospammers.com> wrote:
: oh no, i was asking, for the key, should I quote it or not?
: seems like both are syntactically ok to me...
Here's what the perldata manpage has to say:
As in some shells, you can enclose the variable name in braces to
disambiguate it from following alphanumerics. You must also do this
when interpolating a variable into a string to separate the variable
name from a following double-colon or an apostrophe, since these
would be otherwise treated as a package separator:
$who = "Larry";
print PASSWD "${who}::0:0:Superuser:/:/bin/perl\n";
print "We use ${who}speak when ${who}'s here.\n";
Without the braces, Perl would have looked for a $whospeak, a
`$who::0', and a `$who's' variable. The last two would be the $0 and
the $s variables in the (presumably) non-existent package `who'.
In fact, an identifier within such curlies is forced to be a string,
as is any simple identifier within a hash subscript. Neither need
quoting. Our earlier example, `$days{'Feb'}' can be written as
`$days{Feb}' and the quotes will be assumed automatically. But
anything more complicated in the subscript will be interpreted as an
expression.
ObDamianWorship: I've been using Text::Autoformat lately, and it's a
wonderful piece of code that's always been on my wish list.
Greg
--
Proof by importance:
A large body of useful consequences all follow from the proposition in
question.
------------------------------
Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>
Administrivia:
The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc. For subscription or unsubscription requests, send
the single line:
subscribe perl-users
or:
unsubscribe perl-users
to almanac@ruby.oce.orst.edu.
To submit articles to comp.lang.perl.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 1069
***************************************