[21970] in Perl-Users-Digest
Perl-Users Digest, Issue: 4192 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Nov 28 03:05:50 2002
Date: Thu, 28 Nov 2002 00:05:08 -0800 (PST)
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, 28 Nov 2002 Volume: 10 Number: 4192
Today's topics:
Re: 'Burning' memory in perl <mb@uq.not.au>
a scope question (derek chen)
Re: a scope question <derek@wedgetail.com>
Re: a scope question <jurgenex@hotmail.com>
Free Classified Ads: Job listings , Real Estates, Event webinfoboard.com
Free Classified Ads: Resume, Job listings , Real Estate webinfoboard.com
Re: help: multi-dimensional hash from flat array (Damian James)
Re: Modules Hurting My Head, Help Please. <wksmith@optonline.net>
Re: Modules Hurting My Head, Help Please. (Alan Barclay)
Re: Modules Hurting My Head, Help Please. (Tad McClellan)
Need help in using ftp. <pengtaoli@hotmail.com>
Re: perl module path problem (Damian James)
Re: Please take my two-minute software engineering surv <vm.mayer@comcast.net>
Re: Please take my two-minute software engineering surv (Malcolm Dew-Jones)
Re: Regular expression question <stevenm@blackwater-pacific.com>
Re: Sending NumKeys with Win32::GuiTest <goldbb2@earthlink.net>
Teaching Perl complex data structures <derek@wedgetail.com>
What is $a,$b (derek chen)
Re: What is $a,$b <sunderc@directvinternet.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Thu, 28 Nov 2002 14:07:33 +1000
From: MB <mb@uq.not.au>
Subject: Re: 'Burning' memory in perl
Message-Id: <3DE59685.7060806@uq.not.au>
Greetings,
Ilya Zakharevich wrote:
<snip>
> Yes, it would overwrite the current contents of $passwd (unless it was
> in utf-8) with the current implementations. However,
>
>
>> my $passwd = get_passwd();
>
>
> Now the contents password is not only in $passwd, but possibly in many
> other locations (return value of get_passwd(), the variables and
> temporaries used by get_passwd(), the STDIO buffers etc). There is no
> way to overwrite all *these* locations...
I was afraid of that. I guess I could use references to the string
instead of the string itself...
Thanks,
MB (net not not)
------------------------------
Date: 27 Nov 2002 21:56:08 -0800
From: u8526505@ms27.hinet.net (derek chen)
Subject: a scope question
Message-Id: <85789064.0211272156.60fd8f04@posting.google.com>
I can't understand why this would not work. $i is visible to test but
why test is not aware of $i's chnage?
my $i=0;
for $i (1 .. 10){
test();
}
sub test
{
print "$i\n"; # always print 0
}
------------------------------
Date: Thu, 28 Nov 2002 06:49:25 GMT
From: Derek Thomson <derek@wedgetail.com>
Subject: Re: a scope question
Message-Id: <V%iF9.30$_27.780@news.optus.net.au>
Hi Derek,
derek chen wrote:
> I can't understand why this would not work. $i is visible to test but
> why test is not aware of $i's chnage?
>
> my $i=0;
>
> for $i (1 .. 10){
> test();
> }
>
> sub test
> {
> print "$i\n"; # always print 0
> }
That's a good one. It had me stumped. Here's what the perlsyn man page
says about it:
Foreach Loops
The "foreach" loop iterates over a normal list value and
sets the variable VAR to be each element of the list in
turn. If the variable is preceded with the keyword "my",
then it is lexically scoped, and is therefore visible only
within the loop. Otherwise, the variable is implicitly
local to the loop and regains its former value upon exit
ing the loop. If the variable was previously declared
with "my", it uses that variable instead of the global
one, but it's still localized to the loop.
This must be related to the loop variable reverting back to it's old value.
So, I guess the variable $i gets a new local variable created for it
while it's acting as the loop iterator, and therefore the "$i" in the
subroutine is still looking at the "other" value. I'd recommend you
don't use globals for this sort of thing anyway, but use arguments
instead if possible, as I show in my revised example below.
I'm not sure whether this is good or bad behaviour at the moment, but
that's your answer. If we're lucky, someone else will come along who
actually understands why it works this way!
#!/usr/bin/perl
use warnings;
use strict;
for my $i (1..10) {
test($i);
}
sub test
{
my $i = shift @_;
print "$i\n";
}
--
D.
------------------------------
Date: Thu, 28 Nov 2002 07:04:55 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: a scope question
Message-Id: <rejF9.39200$hi6.30911@nwrddc02.gnilink.net>
derek chen wrote:
> I can't understand why this would not work. $i is visible to test but
> why test is not aware of $i's chnage?
>
> my $i=0;
> for $i (1 .. 10){
> test();
> }
>
> sub test
> {
> print "$i\n"; # always print 0
> }
The answer can be found in the man page for 'for' (perldoc perlsyn):
The `foreach' loop iterates over a normal list value and sets the
variable VAR [...]. If the variable was previously declared with `my',
it uses
that variable instead of the global one, but it's still localized to the
loop.
jue
------------------------------
Date: 27 Nov 2002 20:24:40 -0800
From: webinfoboard.com
Subject: Free Classified Ads: Job listings , Real Estates, Events, Services, Personal and more!
Message-Id: <3de59a88_1@nopics.sjc>
Hi,
Are you looking for jobs? Selling your home? Moving to new areas?
It is free to post and search classified ads on
http://www.webinfoboard.com
Web Marketing
www.webinfoboard.com
------------------------------
Date: 27 Nov 2002 23:57:14 -0800
From: webinfoboard.com
Subject: Free Classified Ads: Resume, Job listings , Real Estates, Events, Services, Personal and more!
Message-Id: <3de5cc5a$1_4@nopics.sjc>
Hi,
Are you looking for jobs? Selling your home? Moving to new areas?
It is free to post and search classified ads on
http://www.webinfoboard.com
Web Marketing
www.webinfoboard.com
------------------------------
Date: 28 Nov 2002 04:22:37 GMT
From: damian@qimr.edu.au (Damian James)
Subject: Re: help: multi-dimensional hash from flat array
Message-Id: <slrnaub6gd.7dj.damian@puma.qimr.edu.au>
On Wed, 27 Nov 2002 04:10:38 -0500, Chef Tako said:
>evil yes; but necessary. i found myself in a hole where
>i need to create flat variable names (through a cgi- web page form) and
>need to get it uniquely back into my session hash.
>...
>What do you percieve and suggest as an elegant solution?
I think this works in more cases than the other response in this
thread, which doesn't respect existing values. Naive maybe, but
no modules came to my mind and this was a good exercise.
#!/usr/bin/perl
use strict;
use warnings;
use Data::Dumper;
my %h = ();
while ( my $line = <DATA> ) {
chomp $line;
my ($keys, $path) = split /=/, $line;
$path = { $_ => $path } for reverse split /-/, $keys;
merge( \%h, %$path );
}
sub merge {
my ( $h, $key, $val ) = @_;
merge ( $h->{$key}, %$val ), return if exists $h->{$key};
$h->{ $key } = $val;
}
print Dumper( \%h );
__DATA__
a-b-c-d-e=test1
f-g-h-i-j=test2
a-g-h-i-j=test3
a-b-h-i-j=test4
f-g-c-d-e=test5
__END__
There you go -- you too can avoid that nasty old string eval.
Probably needs some error checking and such. Maybe some guru
will delurk and show us a way that avoids the separate loop
and recursion :-).
HTH
--damian
------------------------------
Date: Thu, 28 Nov 2002 02:16:29 GMT
From: "Bill Smith" <wksmith@optonline.net>
Subject: Re: Modules Hurting My Head, Help Please.
Message-Id: <10fF9.6742$Kk2.2446@news4.srv.hcvlny.cv.net>
"Bryon Black" <bryon@blacklambrocks.com> wrote in message
news:1de7ee90.0211271702.16f861ae@posting.google.com...
> Hi,
>
> Well, I'm trying my hand at building modules and getting very
> confused. I could use some help with answering these questions: A.)
> True or not true; a module need not be in the @INC array if the module
> is in either the same directory or sub-directories of the script using
You may find a module in the working directory, but don't depend on it.
The module should be in @INC.
--sniped example--
> If anyone can help to explain what I'm doing wrong I would sincerely
> appreciate it.
refer to FAQ
perldoc -q module/library
perldoc -q runtime
If you prefer books, check out the "Perl Cookbook". Recipe 12.7
(Keeping Your Own Module Directory) has a lengthy discussion of your
options.
Bill
------------------------------
Date: 28 Nov 2002 03:05:50 GMT
From: gorilla@elaine.furryape.com (Alan Barclay)
Subject: Re: Modules Hurting My Head, Help Please.
Message-Id: <1038452751.173640@elaine.furryape.com>
In article <1de7ee90.0211271702.16f861ae@posting.google.com>,
Bryon Black <bryon@blacklambrocks.com> wrote:
>confused. I could use some help with answering these questions: A.)
>True or not true; a module need not be in the @INC array if the module
>is in either the same directory or sub-directories of the script using
>them. For instance, if in my script I have:
False.
If a program is run with -T, then it won't implictly include '.'
in @INC.
elaine ~% echo 'print "hello"' > test.pm
elaine ~% perl -Mtest -e 'print "\n"'
hello
elaine ~% perl -T -Mtest -e 'print "\n"'
Can't locate test.pm in @INC (@INC contains: [list of @INC trimmed for usenet])
------------------------------
Date: Wed, 27 Nov 2002 22:43:06 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Modules Hurting My Head, Help Please.
Message-Id: <slrnaub7mq.56u.tadmc@magna.augustmail.com>
Bryon Black <bryon@blacklambrocks.com> wrote:
> Well, I'm trying my hand at building modules and getting very
> confused.
Did you use h2xs to start building your modules?
> True or not true; a module need not be in the @INC array if the module
> is in either the same directory or sub-directories of the script using
> them.
Not true.
The directory that your program is stored in is completely
irrelevant to finding a module.
What might matter is your _current working directory_.
The cwd is often compiled into @INC.
It might happen that the cwd is the same as the directory
where your program is stored, but it might be
something else, so you can't rely on it.
> My problem is that from my windows machine this structure seems to
> work fine. When I upload this structure to a UNIX machine,
Why are you uploading to a Unix machine?
Is this a stealth CGI question?
> it works
> fine but only assuming that I execute the the script from the
> directory of the script.
Looks like the web server is set up so that the cwd _is_
set to the CGI program's directory. That was fortunate.
> If I try to execute the script from another
> directory (or from the web, which is really where the script will be
> used) I get an error stating:
Oh, not so stealthy. Sorry.
> BEGIN failed--compilation aborted at ../cgi-bin/email_list_join.pl
> line 3.
>
> which is where the statement use ShowTime::ShowTimeDB... occurs, or
> from the web I simply get a 500 error.
>
> If anyone can help to explain what I'm doing wrong I would sincerely
> appreciate it.
1) Making assumptions about what your cwd is.
2) Apparently not checking the Perl FAQ before posting to
the Perl newsgroup.
perldoc -q module
How do I create a module?
How do I keep my own module/library directory?
How do I add the directory my program lives in to the
module/library search path?
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Thu, 28 Nov 2002 14:59:31 +0800
From: "Franklin Lee" <pengtaoli@hotmail.com>
Subject: Need help in using ftp.
Message-Id: <as4esp$boi@netnews.proxy.lucent.com>
Hello,
I want to use ftp in my Perl program.
In Ksh, I can write:
ftp -vin <<EOF
open aaa
user user1 aaa
put bbb
bye
EOF
But in Perl, I don't know how to do it.
I didn't have Net::Ftp and don't want to interaction.
Thank you very much!
------------------------------
Date: 28 Nov 2002 05:08:02 GMT
From: damian@qimr.edu.au (Damian James)
Subject: Re: perl module path problem
Message-Id: <slrnaub95i.7dj.damian@puma.qimr.edu.au>
On 27 Nov 2002 15:09:40 -0800, Urmi said:
>...
>The contents of test are as follow:
>********************************
>#!/usr/bin/perl -w
>use strict;
>use NetGeoClient;
>
>my $recordRef = $netgeo->getRecord("192.172.226.30");
>print "$recordRef\n";
>*********************************************************
>
>But when I run the test file, it doesn't seem to be able to locate
>NetGeoClient.pm . It keeps giving me the error message:
>
>Global symbol "$netgeo" requires explicit package name at ./test line 5.
>Execution of ./test aborted due to compilation errors.
You are trying to call the method "getRecord" on an object in $netgeo,
but you haven't created that object yet. The error message is telling
you that you haven't declared $netgeo yet. Perhaps you need to do
something like:
my $netgeo = new NetGeoClient;
You *do *need to refer to the documentation for your module to find
out how to create the object.
>I figure something is wrong with the path variable.
??? How do you get that?
HTH
--damian
------------------------------
Date: Wed, 27 Nov 2002 23:44:32 -0500
From: Mike Mayer <vm.mayer@comcast.net>
Subject: Re: Please take my two-minute software engineering survey!
Message-Id: <vm.mayer-56F8DA.23443127112002@news-east.giganews.com>
In article <BA0A671A.14C10%jnleipzi@unity.ncsu.edu>,
Jeremy Leipzig <jnleipzi@unity.ncsu.edu> wrote:
> http://zigster.com/survey.html
Will you be making the results available?
I took the survey and am curious how others answered.
mike
------------------------------
Date: 27 Nov 2002 22:10:31 -0800
From: yf110@vtn1.victoria.tc.ca (Malcolm Dew-Jones)
Subject: Re: Please take my two-minute software engineering survey!
Message-Id: <3de5b357@news.victoria.tc.ca>
Jeremy Leipzig (jnleipzi@unity.ncsu.edu) wrote:
: http://zigster.com/survey.html
perl -S get. zigster.com/survey.html | grep -i perl
=> no output from grep <=
Why is this in a perl group?
------------------------------
Date: Wed, 27 Nov 2002 20:23:27 -0800
From: Steven May <stevenm@blackwater-pacific.com>
Subject: Re: Regular expression question
Message-Id: <as45eg$e35$1@quark.scn.rain.com>
North Lilly wrote:
>
>
> Can a regular expression be used to take a string and add a character to
> it (ie 1234 -> 12:34)? If so what is the syntax?
>
given the above:
#! /usr/bin/perl -w
use strict;
my $string = '1234';
$string =~ s/(\d\d)(\d\d)/\1:\2/;
print "string is $string\n";
exit 0;
results:
string is 12:34
------------------------------
Date: Wed, 27 Nov 2002 21:32:45 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Sending NumKeys with Win32::GuiTest
Message-Id: <3DE5804D.883765A1@earthlink.net>
Just in wrote:
[snip]
> Is there anything available that would allow me to
> write the contents of the VAX output screen to the
> screen and a variable that I could run a m/// on?
It would probably depend on whether it's a graphic that changes, or
text. If it's text, you might be able to use GetWindowText.
Since it may not be the window itself, but rather a textarea/whatever
within it, that contains text, you may need to do something like:
my $child = FindWindowLike( $parent, q/pattern1/, q/pattern2/ );
To find out which window contains the text, and then use GetWindowText
on that panel.
(Umm, I may be confusing Win32's concept "child windows" with X11's
concept of "child windows" ... they might not be the same thing).
--
my $n = 2; print +(split //, 'e,4c3H r ktulrnsJ2tPaeh'
."\n1oa! er")[map $n = ($n * 24 + 30) % 31, (42) x 26]
------------------------------
Date: Thu, 28 Nov 2002 07:09:59 GMT
From: Derek Thomson <derek@wedgetail.com>
Subject: Teaching Perl complex data structures
Message-Id: <bjjF9.31$_27.782@news.optus.net.au>
Hi,
I was wondering if anyone could advise me on how best to explain the
concept of arrays of references to arrays to someone learning Perl.
Let's say that the person in question is already familiar with Python.
In that language, everything is pretty much just a reference, so you can
simply say:
list = [ 'one', 'two', 'three', 'four']
list[2] = [ 'first', 'second', 'third' ]
... to end up with [ 'one', 'two', [ 'first', 'second', 'third' ], four'].
Because of Perl's behaviour, I can't just do this:
@list = ( 'one', 'two', 'three', 'four' );
$list[2] = ( 'first', 'second', 'third' );
... because I end up with ( 'one', 'two', 'first', 'four').
Now, I understand why that happens, but as you can imagine this causes
some confusion.
Obviously, I need to do this
@list = ( 'one', 'two', 'three', 'four' );
$list[2] = [ 'first', 'second', 'third' ];
... but all this expilicit screwing about with references just leaves
people confused, and "not liking Perl". Is there a good reason, apart
from historical, why the behaviour isn't more like Python's ie. lists
can just be nested? I guess I've always seen using references in arrays
to achieve nesting like this as a bit of a hack, so perhaps I'm just not
seeing the obvious benefits ...
How can I convince people that this is sensible?
--
D.
------------------------------
Date: 27 Nov 2002 23:39:08 -0800
From: u8526505@ms27.hinet.net (derek chen)
Subject: What is $a,$b
Message-Id: <85789064.0211272339.d2a55b2@posting.google.com>
I tried the snippets below and the interpreter said it ok. But error
message will show if I use variable names other than $a,$b. Does this
mean $a, $b are default global variables in main:: ? For what reason ?
Thanks.
use strict vars;
local $a;
local $b;
------------------------------
Date: Wed, 27 Nov 2002 23:55:48 -0800
From: Sunder Chakravarty <sunderc@directvinternet.com>
Subject: Re: What is $a,$b
Message-Id: <3de5cab4$1_1@nopics.sjc>
derek chen wrote:
> I tried the snippets below and the interpreter said it ok. But error
> message will show if I use variable names other than $a,$b. Does this
> mean $a, $b are default global variables in main:: ? For what reason ?
> Thanks.
>
> use strict vars;
>
> local $a;
> local $b;
Here is a snippet from "perldoc -f sort" that will help explain $a and $b
If you're using strict, you *must not* declare $a and $b as
lexicals. They are package globals. That means if you're in the
"main" package and type
@articles = sort {$b <=> $a} @files;
then "$a" and "$b" are "$main::a" and "$main::b" (or "$::a" and
"$::b"), but if you're in the "FooPack" package, it's the same
as typing
@articles = sort {$FooPack::b <=> $FooPack::a} @files;
Regards
Sunder
------------------------------
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 4192
***************************************