[23558] in Perl-Users-Digest
Perl-Users Digest, Issue: 5766 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Nov 8 06:05:46 2003
Date: Sat, 8 Nov 2003 03: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 Sat, 8 Nov 2003 Volume: 10 Number: 5766
Today's topics:
Re: binary dist calculation <fJogham@yahoo.com>
Re: bit sequence match (Jay Tilton)
Re: bit sequence match <edady2002@yahoo.com>
Re: bit sequence match <usenet@morrow.me.uk>
Re: bit sequence match <edady2002@yahoo.com>
Re: calling XS(function) from C <nospam-abuse@ilyaz.org>
Re: CGI parameter question <j.g.karssenberg@student.utwente.nl>
Re: Help a non-Perl user update an older program... <me@privacy.net>
max of cardinality <fJogham@yahoo.com>
Re: Perl module for analyzing log files? <ken.blacklist@sewingwitch.com>
Re: Problem with changes to referrenced object rosenthd@yahoo.com
Re: Problem with changes to referrenced object <ebohlman@earthlink.net>
Re: searching for null in pattern <bmb@ginger.libs.uga.edu>
Re: Style question: map versus foreach <tassilo.parseval@rwth-aachen.de>
subroutines return values <bmb@ginger.libs.uga.edu>
Re: subroutines return values <kalinaubears@iinet.net.au>
Re: subroutines return values (Jay Tilton)
Re: subroutines return values <uri@stemsystems.com>
Re: subroutines return values <kalinaubears@iinet.net.au>
Re: subroutines return values <go@away.spam>
Re: subroutines return values <grazz@pobox.com>
Re: Upgrading perl and module use <b_duke@octa4.net.invalid>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sat, 08 Nov 2003 21:38:24 +1100
From: Fred <fJogham@yahoo.com>
Subject: Re: binary dist calculation
Message-Id: <3FACC7A0.7010100@yahoo.com>
Sisyphus wrote:
> Sisyphus wrote:
>
>>
>> As Brian hinted:
>> $x = 0b101; # $x is a number (= 3).
>> $x = "0b101"; # $x is not a number, just a string of chars.
>> $x = oct("0b101"); # $x is a number (= 3)
>>
>
> Ummm ... I wasn't wearing my glasses, and couldn't see my fingers
> properly. I think '101' is actually binary representation of '5', not
> '3'. Time to visit the optometrist .... or maybe the neurosurgeon.
>
> Cheers,
> Rob
>
>
thanks
one more thing,
what is this " $x is a number (= 3) or (= 5) mean?
who is (= number) used and what for?
this is perl, I don't expect an explainatin but maybe a term to google for.
thanks
------------------------------
Date: Sat, 08 Nov 2003 03:37:45 GMT
From: tiltonj@erols.com (Jay Tilton)
Subject: Re: bit sequence match
Message-Id: <3fac61e7.888620891@news.erols.com>
Edo <edady2002@yahoo.com> wrote:
: Jay Tilton wrote:
: > Edo <edady2002@yahoo.com> wrote:
[snip]
: > Are the hash keys really going to be numeric? Using arrays may be a
: > more sensible choice than using hashes.
:
: the hash keys are going to be numeric, in the @a1 above example, the
: real keys are 369 444 885 with irregular incrementation, thats why I
: thought it'd be better to use a hash with 1 2 3 ... keys for ease of
: coding and debugging.
I suspected the (1,2,3) keys could be an artifact of simplifying the
sample code. A hash is indeed a better choice than a sparsely populated
array.
: > : once found place the results in
: > : another %h3 which is then a hoh with the first result taking the number
: > : 1 and the second result 2 ... in that new %h3.
: >
: > That part needs more explanation. With the %h1 and %h2 shown above,
: > what exactly would you like the data structure in %h3 to look like?
:
: %h3 which I think it could be an array @a3 instead, needs to contain the
: list of all matched sequences, therefore it would be array of hash refs
: IF hashs are still the more sensible way from question 1 above.
I asked the question poorly.
After %h3 is created, what would be the output from:
use Data::Dumper;
print Dumper( \%h3 );
As a guess, I expected that you just wanted the relevant chunk of %h2
copied into %h3, e.g.
%h3 = (
3 => '000001',
4 => '000010',
5 => '000100',
);
but your mention of references and %h3 being a hash-of-hashes is
confusing. I can think of a dozen different data structures that would
meet the criteria, and none would probably be what you want.
------------------------------
Date: Sat, 08 Nov 2003 15:42:41 +1100
From: Edo <edady2002@yahoo.com>
Subject: Re: bit sequence match
Message-Id: <3FAC7441.4020601@yahoo.com>
Jay Tilton wrote:
> Edo <edady2002@yahoo.com> wrote:
>
> : Jay Tilton wrote:
> : > Edo <edady2002@yahoo.com> wrote:
>
> [snip]
>
> : > Are the hash keys really going to be numeric? Using arrays may be a
> : > more sensible choice than using hashes.
> :
> : the hash keys are going to be numeric, in the @a1 above example, the
> : real keys are 369 444 885 with irregular incrementation, thats why I
> : thought it'd be better to use a hash with 1 2 3 ... keys for ease of
> : coding and debugging.
>
> I suspected the (1,2,3) keys could be an artifact of simplifying the
> sample code. A hash is indeed a better choice than a sparsely populated
> array.
>
> : > : once found place the results in
> : > : another %h3 which is then a hoh with the first result taking the number
> : > : 1 and the second result 2 ... in that new %h3.
> : >
> : > That part needs more explanation. With the %h1 and %h2 shown above,
> : > what exactly would you like the data structure in %h3 to look like?
> :
> : %h3 which I think it could be an array @a3 instead, needs to contain the
> : list of all matched sequences, therefore it would be array of hash refs
> : IF hashs are still the more sensible way from question 1 above.
>
> I asked the question poorly.
>
> After %h3 is created, what would be the output from:
>
> use Data::Dumper;
> print Dumper( \%h3 );
>
> As a guess, I expected that you just wanted the relevant chunk of %h2
> copied into %h3, e.g.
>
> %h3 = (
> 3 => '000001',
> 4 => '000010',
> 5 => '000100',
> );
>
> but your mention of references and %h3 being a hash-of-hashes is
> confusing. I can think of a dozen different data structures that would
> meet the criteria, and none would probably be what you want.
>
e.g, if the code gets 20 matches from %h2. then those matches are
identical to %h1 in as a sorted-whole so
if %h1 = (1 => '000001', 2 => '000010', 3 => '000100');
and there are in the "key-sorted-%h2"
(20 => '000001', 21 => '000010', 22 => '000100')
(41 => '000001', 42 => '000010', 43 => '000100')
(111 => '000001', 112 => '000010', 113 => '000100')
then I need those above 3 lines in array of hrefs.
thanks
------------------------------
Date: Sat, 8 Nov 2003 07:56:17 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: bit sequence match
Message-Id: <boi7j1$pdc$1@wisteria.csv.warwick.ac.uk>
news@group.com wrote:
> Jay Tilton wrote:
> > After %h3 is created, what would be the output from:
> >
> > use Data::Dumper;
> > print Dumper( \%h3 );
<snip>
> e.g, if the code gets 20 matches from %h2. then those matches are
> identical to %h1 in as a sorted-whole so
> if %h1 = (1 => '000001', 2 => '000010', 3 => '000100');
> and there are in the "key-sorted-%h2"
> (20 => '000001', 21 => '000010', 22 => '000100')
> (41 => '000001', 42 => '000010', 43 => '000100')
> (111 => '000001', 112 => '000010', 113 => '000100')
>
> then I need those above 3 lines in array of hrefs.
Hmm, this still isn't very clear. Is what you want something like:
my %h1 = (1 => '000001', 2 => '000010', 3 => '000100');
my %h2 = (20 => '000001', 21 => '000010', 22 => '000100',
30 => '001000', 31 => '001010', 32 => '001100',
41 => '000001', 42 => '000010', 43 => '000100',
111 => '000001', 112 => '000010', 113 => '000100');
my @lookfor = map { $h1{$_} } sort keys %h1;
my $lookfor = 0;
my (@h3, $tmph);
for (sort keys %h2) {
$tmph = {} unless $lookfor;
if ($h2{$_} eq $lookfor[$lookfor]) {
$tmph->{$_} = $h2{$_};
$lookfor = ($lookfor + 1) % @lookfor;
}
push @h3, $tmph if !$lookfor and keys %$tmph;
}
?
Ben
--
Joy and Woe are woven fine,
A Clothing for the Soul divine William Blake
Under every grief and pine 'Auguries of Innocence'
Runs a joy with silken twine. ben@morrow.me.uk
------------------------------
Date: Sat, 08 Nov 2003 21:22:21 +1100
From: Edo <edady2002@yahoo.com>
Subject: Re: bit sequence match
Message-Id: <3FACC3DD.3040602@yahoo.com>
Ben Morrow wrote:
> news@group.com wrote:
>
>>Jay Tilton wrote:
>>
>>>After %h3 is created, what would be the output from:
>>>
>>> use Data::Dumper;
>>> print Dumper( \%h3 );
>>
> <snip>
>
>>e.g, if the code gets 20 matches from %h2. then those matches are
>>identical to %h1 in as a sorted-whole so
>>if %h1 = (1 => '000001', 2 => '000010', 3 => '000100');
>>and there are in the "key-sorted-%h2"
>>(20 => '000001', 21 => '000010', 22 => '000100')
>>(41 => '000001', 42 => '000010', 43 => '000100')
>>(111 => '000001', 112 => '000010', 113 => '000100')
>>
>>then I need those above 3 lines in array of hrefs.
>
>
> Hmm, this still isn't very clear. Is what you want something like:
>
> my %h1 = (1 => '000001', 2 => '000010', 3 => '000100');
> my %h2 = (20 => '000001', 21 => '000010', 22 => '000100',
> 30 => '001000', 31 => '001010', 32 => '001100',
> 41 => '000001', 42 => '000010', 43 => '000100',
> 111 => '000001', 112 => '000010', 113 => '000100');
>
> my @lookfor = map { $h1{$_} } sort keys %h1;
> my $lookfor = 0;
>
> my (@h3, $tmph);
>
> for (sort keys %h2) {
> $tmph = {} unless $lookfor;
>
> if ($h2{$_} eq $lookfor[$lookfor]) {
> $tmph->{$_} = $h2{$_};
> $lookfor = ($lookfor + 1) % @lookfor;
> }
>
> push @h3, $tmph if !$lookfor and keys %$tmph;
> }
>
> ?
>
> Ben
>
my %h1 = (1 => '000001', 2 => '000010', 3 => '000100');
my %h2 = (20 => '000001', 21 => '000010', 22 => '000100',
30 => '001000', 31 => '001010', 32 => '001100',
41 => '000001', 42 => '000010', 43 => '000100',
111 => '000001', 112 => '000010', 113 => '000100');
seq_mat(\%h1, \%h2);
sub seq_mat {
...
return @AoA;
}
@AoA = (
['20', '21', '22' ],
['111', '112' '113']
)
------------------------------
Date: Sat, 8 Nov 2003 09:28:22 +0000 (UTC)
From: Ilya Zakharevich <nospam-abuse@ilyaz.org>
Subject: Re: calling XS(function) from C
Message-Id: <boicvm$q5h$1@agate.berkeley.edu>
[A complimentary Cc of this posting was sent to
Penguinista
<peter@nospam.calweb.com>], who wrote in article <3fac25e8$0$22655$d368eab@news.calweb.com>:
> I'm embeding perl in a C program and using swig to generate an
> interface. One of the generated functions is XS(boot_module) to
> initialize the extension functions in perl, and intended to be called
> from perl in a module bootstrap operation. In my case I want to call it
> from C code. I've gotten a kludge that to works on my system, but
> breaks on a different system. Is there a 'proper' way to make this call?
Did you look how XSLoader does it?
Yours,
Ilya
------------------------------
Date: Sat, 8 Nov 2003 04:24:27 +0100
From: Jaap Karssenberg <j.g.karssenberg@student.utwente.nl>
Subject: Re: CGI parameter question
Message-Id: <20031108042427.08d1372e.j.g.karssenberg@student.utwente.nl>
: CGI.pm provides the method path_info() which contains the value
: of the environment variable PATH_INFO.
Thanks, thats was the name I needed to know :)
--
) ( Jaap Karssenberg || Pardus [Larus] | |0| |
: : http://pardus-larus.student.utwente.nl/~pardus | | |0|
) \ / ( |0|0|0|
",.*'*.," Proud owner of "Perl6 Essentials" 1st edition :)
------------------------------
Date: Sat, 8 Nov 2003 19:53:55 +1300
From: "Tintin" <me@privacy.net>
Subject: Re: Help a non-Perl user update an older program...
Message-Id: <boi3vk$1dat30$1@ID-172104.news.uni-berlin.de>
"Steve" <gomek@onvoymail.com> wrote in message
news:b1e7c6d6.0311071508.722506b7@posting.google.com...
> Hi - I also use this program and am interested in a fix.
> Unfortunately, I know nothing of Perl...
*this* program being....??? Obviously you know nothing about NG etiquette
as well.
> I was wondering if the suggestion above helped? I may be able to
> enlist some help from some Perl friends...
There is no suggestion above. Are you blind as well as stupid?
------------------------------
Date: Sat, 08 Nov 2003 20:52:47 +1100
From: Fred <fJogham@yahoo.com>
Subject: max of cardinality
Message-Id: <3FACBCEF.1050206@yahoo.com>
this code works good but I think I can be cleaner / faster.
thanks for all input
my @bit1 = qw /01 00 10 11 00 11/;
my @bit2 = qw /01 01 01 01 11/;
print (max(\@bit1,\@bit2),"\n");
sub max {
my ($aref1, $aref2) = (shift, shift);
my $bit1 = card(@{$aref1});
my $bit2 = card(@{$aref2});
if ( $bit1 > $bit2 ) {
return $bit1;
} elsif ( $bit1 > $bit2 ) {
return $bit2;
} else {
return $bit1; #both equal, return any
}
}
sub card {
join("", @_) =~ tr/01//;
}
------------------------------
Date: Sat, 08 Nov 2003 04:25:17 GMT
From: Kenneth Porter <ken.blacklist@sewingwitch.com>
Subject: Re: Perl module for analyzing log files?
Message-Id: <Xns942CCFBD5CF0Cshivawellcom@64.164.98.51>
Massi <massi@NOSPAMmassimilianosini.it> wrote in
news:Xns942C86A868661massi70Massi@195.31.190.132:
> Try using Date::Parse
Thanks. How does that compare to Date::Manip or Time::ParseDate?
--
Kenneth Porter
http://www.sewingwitch.com/ken/
------------------------------
Date: Sat, 08 Nov 2003 04:55:03 GMT
From: rosenthd@yahoo.com
Subject: Re: Problem with changes to referrenced object
Message-Id: <fotoqv0ujanu7rpclh6426a671qdt18e66@4ax.com>
Thanx, This solves my problem!
On Sat, 08 Nov 2003 00:19:18 +0100, Gunnar Hjalmarsson
<noreply@gunnar.cc> wrote:
>rosenthd@yahoo.com wrote:
>> I'd like to use a copy of my "test" object below without it being
>> changed. However, all of my attempts so far to copy it don't
>> seem to succeed. As the example shows below changing newarray
>> affects the test object. How Can I copy values from the test
>> array into a new array without changing the original test array.
>>
>> $test[0]{'A'} = 1;
>> $test[1]{'A'} = 1;
>> $test[2]{'A'} = 2;
>> $test[2]{'C'} = 3;
>> $test[3]{'B'} = 3;
>>
>> @newarray = @test;
>
>@test contains references to anonymous hashes, so @newarray is
>assigned references to just those anonymous hashes.
>
>Instead of
>
> @newarray = @test;
>
>you need to do something like
>
> for my $i (0..$#test) {
> for my $key ( keys %{ $test[$i] } ) {
> $newarray[$i]{$key} = $test[$i]->{$key};
> }
> }
>
>@newarray now contains references to _copies_ of the anonymous hashes
>instead of references to the original ditto.
>
>HTH
------------------------------
Date: 8 Nov 2003 07:05:18 GMT
From: Eric Bohlman <ebohlman@earthlink.net>
Subject: Re: Problem with changes to referrenced object
Message-Id: <Xns942DD3BEA734ebohlmanomsdevcom@130.133.1.4>
rosenthd@yahoo.com wrote in
news:lq4oqvc1hgsm0j73c2q6tnt17qs9tp6mia@4ax.com:
> I'd like to use a copy of my "test" object below without it being
> changed. However, all of my attempts so far to copy it don't seem
> to succeed. As the example shows below changing newarray affects the
> test object. How Can I copy values from the test array into a new
> array without changing the original test array.
>
>
> $test[0]{'A'} = 1;
> $test[1]{'A'} = 1;
> $test[2]{'A'} = 2;
> $test[2]{'C'} = 3;
> $test[3]{'B'} = 3;
>
>
>
> @newarray = @test;
@newarray will be what's known in the business as a "shallow copy" of
@test, which means that the actual array elements will be copied, but the
things they reference won't. In other words, you'll have two arrays of
references to the *same* hashes, giving you the result you experienced.
What you need is a "deep copy" or "clone" of @test. Probably the easiest
way to do it is to get the Clone::Any module from CPAN, which will provide
you with functions that make cloning nested data structures simple.
------------------------------
Date: Fri, 7 Nov 2003 21:15:56 -0500
From: Brad Baxter <bmb@ginger.libs.uga.edu>
Subject: Re: searching for null in pattern
Message-Id: <Pine.A41.4.58.0311072100360.11388@ginger.libs.uga.edu>
On Sat, 8 Nov 2003, Ben Morrow wrote:
> Brad Baxter <bmb@ginger.libs.uga.edu> wrote:
> > \d (including the backslash) means [0-9], i.e., digits
>
> As someone pointed out before wrt [[:lower:]], \d is different from
> [0-9]. Try
>
> % perl -Mcharnames=viacode -le'for(0x0..0xffff) { print \
> charnames::viacode $_ if chr =~ /\d/ }'
>
> with 5.8. (The above should be all on one line.)
:-) I am more than happy to concede that point. I guess I can only plead
that my reply was in the spirit of:
http://www.perldoc.com/perl5.8.0/pod/perlintro.html
which states, to my mind admirably considering its purpose, "This
introductory document does not aim to be complete. It does not even aim to
be entirely accurate."
I agree that 'match a digit' is more accurate.
Regards,
Brad
------------------------------
Date: 8 Nov 2003 06:53:57 GMT
From: "Tassilo v. Parseval" <tassilo.parseval@rwth-aachen.de>
Subject: Re: Style question: map versus foreach
Message-Id: <boi3u5$42l$1@nets3.rz.RWTH-Aachen.DE>
Also sprach Anno Siegel:
> Tassilo v. Parseval <tassilo.parseval@post.rwth-aachen.de> wrote in comp.lang.perl.misc:
>> Also sprach LaDainian Tomlinson:
>>
>> > I wrote a short script the other night to search for C errno definitions by
>> > their integer values. It works fine, but I was originally using map() in
>> > void context and figured that was bad practice. Is this true at all, or are
>> > there any advantages to using map() (speed-wise or otherwise) rather than a
>> > foreach loop even in void context? The script follows:
>>
>> [...]
>>
>> Depends on the version of perl you employ. When you are using 5.8.1
>> map() no longer bothers to return a list in void context which makes it
>> almost (but not quite, as I remember) fast as a foreach-loop.
>>
>> For older perls, there is a measurable difference in speed favouring
>> foreach. If in doubt, use the Benchmark module to get some figures for
>> your machine.
>
> That's efficiency. As for style, that depends very much upon whom
> you ask. Some want to ban map in void context entirely, others say
> there's nothing wrong with it. I tend to avoid it since (namely 5.1.1
> or so) the statement-modifying "for" does the same thing.
I think map() allows for some suggestive notations if one rememebers
that it applies a chunk of code to each element of a list. Someone with
an affinity to functional programming might like idioms such as
local $\ = " " and map print() => qw(Just another Perl hacker,);
On the other hand, this is likely to confuse a rather
imperatively-minded programmer.
Tassilo
--
$_=q#",}])!JAPH!qq(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?<=sub).+q#q!'"qq.\t$&."'!#+sexisexiixesixeseg;y~\n~~dddd;eval
------------------------------
Date: Fri, 7 Nov 2003 21:39:39 -0500
From: Brad Baxter <bmb@ginger.libs.uga.edu>
Subject: subroutines return values
Message-Id: <Pine.A41.4.58.0311072119300.11388@ginger.libs.uga.edu>
Consider the code below. My admittedly superficial understanding makes me
think that line 7 says essentially, "Copy the value of $right to $left."
My intuition, based on statements in documents like `perldoc perlsub`,
makes me wonder if line 10 may, on the other hand, mean something like,
"Copy the value of $right to the holding area where subroutine return
values are processed, and then copy the value from this holding area to
$left."
I ask only to get an idea of what might happen if the value of $right we
very large. I.e., would there not only be a copy of this hypothetical
large value in $right and $left, but also in this "holding area" (which
I'm not sure actually exists).
Thanks,
Brad
1 #!/usr/local/bin/perl
2 use warnings;
3 use strict;
4
5 our( $left, $right ) = ( 'left', 'right' );
6
7 $left = $right;
8 print $left;
9
10 $left = right();
11 print $left;
12
13 sub right{ $right }
------------------------------
Date: Sat, 08 Nov 2003 15:32:21 +1100
From: Sisyphus <kalinaubears@iinet.net.au>
Subject: Re: subroutines return values
Message-Id: <3fac7294$0$1757$5a62ac22@freenews.iinet.net.au>
Brad Baxter wrote:
>
> 1 #!/usr/local/bin/perl
> 2 use warnings;
> 3 use strict;
> 4
> 5 our( $left, $right ) = ( 'left', 'right' );
> 6
> 7 $left = $right;
> 8 print $left;
> 9
> 10 $left = right();
> 11 print $left;
> 12
> 13 sub right{ $right }
Make line 13:
sub right {return $right}
Then, at line 10, $left gets assigned to it the value returned by the
'right()' subroutine. So line 11 should print 'right' because that's the
value that the 'right()' subroutine returned. Right ??
:-)
The way you had line 13 written it wasn't returning anything.
Cheers,
Rob
--
To reply by email u have to take out the u in kalinaubears.
------------------------------
Date: Sat, 08 Nov 2003 04:52:27 GMT
From: tiltonj@erols.com (Jay Tilton)
Subject: Re: subroutines return values
Message-Id: <3fac75df.893733474@news.erols.com>
Sisyphus <kalinaubears@iinet.net.au> wrote:
: Brad Baxter wrote:
:
: > 13 sub right{ $right }
:
: Make line 13:
: sub right {return $right}
[snip]
:
: The way you had line 13 written it wasn't returning anything.
That is incorrect.
From perlsub:
The return value of a subroutine is the value of the
last expression evaluated.
------------------------------
Date: Sat, 08 Nov 2003 04:54:07 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: subroutines return values
Message-Id: <x7brrn4g0g.fsf@mail.sysarch.com>
>>>>> "S" == Sisyphus <kalinaubears@iinet.net.au> writes:
>> 13 sub right{ $right }
S> Make line 13:
S> sub right {return $right}
and how does that change anything? the first version just returns the
last evaluated expression.
S> The way you had line 13 written it wasn't returning anything.
no, he did it correctly. there was something else going on.
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
------------------------------
Date: Sat, 08 Nov 2003 16:20:05 +1100
From: Sisyphus <kalinaubears@iinet.net.au>
Subject: Re: subroutines return values
Message-Id: <3fac7dc4$0$1736$5a62ac22@freenews.iinet.net.au>
Uri Guttman wrote:
>>>>>>"S" == Sisyphus <kalinaubears@iinet.net.au> writes:
>
>
> >> 13 sub right{ $right }
>
> S> Make line 13:
> S> sub right {return $right}
>
> and how does that change anything? the first version just returns the
> last evaluated expression.
>
> S> The way you had line 13 written it wasn't returning anything.
>
> no, he did it correctly. there was something else going on.
>
> uri
>
Oh ... thanks for the correction uri, Jay.
Cheers,
Rob
--
To reply by email u have to take out the u in kalinaubears.
------------------------------
Date: Sat, 08 Nov 2003 05:37:43 GMT
From: "LaDainian Tomlinson" <go@away.spam>
Subject: Re: subroutines return values
Message-Id: <Hi%qb.66182$v82.3700062@twister.southeast.rr.com>
"Brad Baxter" wrote:
> Consider the code below. My admittedly superficial understanding makes me
> think that line 7 says essentially, "Copy the value of $right to $left."
[ line 7: $left = $right; ]
> My intuition, based on statements in documents like `perldoc perlsub`,
> makes me wonder if line 10 may, on the other hand, mean something like,
> "Copy the value of $right to the holding area where subroutine return
> values are processed, and then copy the value from this holding area to
> $left."
[ line 10: $left = right(); ]
> I ask only to get an idea of what might happen if the value of $right we
> very large. I.e., would there not only be a copy of this hypothetical
> large value in $right and $left, but also in this "holding area" (which
> I'm not sure actually exists).
<snip code>
I'm not completely positive about the Perl compiler/interpreter, but I think
I'm safe in assuming that it uses a memory stack to keep up with the data
currently in scope (ignoring static or global data, which may be somewhere
else entirely). Your variables $left and $right are really just spots on
the stack.
When you say '$left = $right;', you're telling the compiler 'look in the
address on the stack (or wherever) pointed to by $right, take that value,
and stick it in the spot on the stack (or wherever) pointed to by $left'.
The exact way that you 'stick it' varies depending on the data type:
sometimes a copy of the data is made, sometimes you get a reference to the
original data.
When you say '$left = right();', the call to right() allocates some more
memory on top of the stack where it's local variables reside (in this case,
it has none). Every subroutine's stack frame has a place on it for the
return value of the subroutine. The _calling_ subroutine knows where to
find this value after the _called_ subroutine exits. In your example, the
return value happens to be $right. So the compiler looks for a spot in the
current stack frame labelled '$right', doesn't see it, backs up one frame,
finds it there, and copies the value to the return value's place in the
current stack frame (i.e., right()'s stack). When the subroutine exits, the
calling code knows where to find that return value and sticks it in $left's
spot on the stack. So your 'holding area' doesn't exist as you mean it, but
there is a short time period where $left does not necessarily contain the
value returned by right() (a few clock cycles at most). After that, the
memory that was occupied by right() is available for allocation again, and
so the slot for the return value is garbage.
I hope this clears things up a little, since it's awfully long-winded.
Brandan L.
--
bclennox AT eos DOT ncsu DOT edu
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.532 / Virus Database: 326 - Release Date: 10/28/2003
------------------------------
Date: Sat, 08 Nov 2003 09:49:59 GMT
From: Steve Grazzini <grazz@pobox.com>
Subject: Re: subroutines return values
Message-Id: <b%2rb.6529$y95.3642@nwrdny01.gnilink.net>
Brad Baxter <bmb@ginger.libs.uga.edu> wrote:
> Consider the code below. My admittedly superficial understanding
> makes me think that line 7 says essentially, "Copy the value of
> $right to $left."
Right.
> My intuition, based on statements in documents like `perldoc
> perlsub`, makes me wonder if line 10 may, on the other hand, mean
> something like, "Copy the value of $right to the holding area where
> subroutine return values are processed, and then copy the value
> from this holding area to $left."
That's partially correct. When you say "return $x" from a normal
(non-lvalue) subroutine, it means "return a temporary copy of $x".
If $x is a string, the actual string will be copied...
> I ask only to get an idea of what might happen if the value of
> $right we very large. I.e., would there not only be a copy of
> this hypothetical large value in $right and $left, but also in
> this "holding area" (which I'm not sure actually exists).
But this won't happen. Perl checks for that (very common) case
in order to avoid copying the temporary string.
--
Steve
------------------------------
Date: Sat, 08 Nov 2003 04:18:06 GMT
From: Brian Salter-Duke <b_duke@octa4.net.invalid>
Subject: Re: Upgrading perl and module use
Message-Id: <28_qb.55$z31.1662@news.optus.net.au>
On Fri, 7 Nov 2003 17:18:50 -0600, Tad McClellan <tadmc@augustmail.com> wrote:
> Brian Salter-Duke <b_duke@octa4.net.invalid> wrote:
>
>> When I upgraded perl,
>
>
> From what version to what version?
The last was 5.6.0 to 5.6.1, but I ought to go to 5.8 soon
>
>> it could not find my installed modules (the ones I
>> had installed). Is there a way to get perl to use modules that are under a
>> different version tree structure,
>
>
> Yes, the way given in the Perl FAQ no less!
>
> perldoc -q module
>
> How do I keep my own module/library directory?
Thanks. I'll look at that.
>
>> or do I have to reinstall the modules?
>
>
> Maybe.
>
> Are they pure Perl modules or do they use XS?
Not sure, but I think most are pure perl.
Brian.
> Some versions of Perl are not binary-compatible with other versions.
>
>
--
Brian Salter-Duke Humpty Doo, Nr Darwin, Australia
My real address is b_duke(AT)octa4(DOT)net(DOT)au
Use this for reply or followup
Perl user for eight years - the way to go.
------------------------------
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 5766
***************************************