[17412] in Perl-Users-Digest
Perl-Users Digest, Issue: 4832 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Nov 7 14:10:32 2000
Date: Tue, 7 Nov 2000 11:10:17 -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: <973624217-v9-i4832@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Tue, 7 Nov 2000 Volume: 9 Number: 4832
Today's topics:
Re: Q: Getting program line number? - Thanks nospam@our.site
Re: Q: Getting program line number? <james@NOSPAM.demon.co.uk>
references (one element of an array to an array) <soeder@ai-lab.fh-furtwangen.de>
Re: references (one element of an array to an array) (Chris Fedde)
Re: references (one element of an array to an array) nobull@mail.com
Re: references (one element of an array to an array) <ren.maddox@tivoli.com>
references <soeder@ai-lab.fh-furtwangen.de>
Re: references (Chris Fedde)
Re: references nobull@mail.com
Re: returning a true value is FUN! (was Re: Log.pm did (Logan Shaw)
Re: returning a true value is FUN! (was Re: Log.pm did <jeffp@crusoe.net>
Re: Sorting hash of hashes by value dhartsough@my-deja.com
Re: Sorting hash of hashes by value <jeff@vpservices.com>
Re: Sorting hash of hashes by value <ren.maddox@tivoli.com>
SSLeay - compiles but Autosplit has problem! <none@none.ca>
Re: system call return <ren.maddox@tivoli.com>
Win32::OLE excel.application <pd@psps.com>
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Tue, 07 Nov 2000 16:09:49 +0000
From: nospam@our.site
Subject: Re: Q: Getting program line number? - Thanks
Message-Id: <8u99ge$c3f$1@icrf.news>
This message has been posted by: Aengus Stewart <aengus.stewart@REMOVE-THIS-TO-SENDicrf.icnet.uk>
nospam@our.site wrote:
>
> This message has been posted by: Aengus Stewart <aengus.stewart@REMOVE-THIS-TO-SENDicrf.icnet.uk>
>
> In my program I want to do
>
> "Error at line number XXX"
>
> However I cant find a PERL global variable for this.
>
Thanks to all those who replied, and yes rereading it, it is ambiguous,
but it was indeed __LINE__ that I wanted.
To the one pedant, you are a genius and I stand in awe of your god like
ability.
Cheers
Aengus
--
----------------------------------------------------------------------
Aengus Stewart aengus.stewart@icrf.icnet.uk
Computational Genome Analysis Laboratory Tel: +44 (0)171 269 3679
Imperial Cancer Research Fund
Lincoln's Inn Fields, Holborn, London, WC2A 3PX, UK
----------------------------------------------------------------------
------------------------------
Date: Tue, 7 Nov 2000 18:10:27 +0000
From: James Taylor <james@NOSPAM.demon.co.uk>
Subject: Re: Q: Getting program line number?
Message-Id: <ant071827b49fNdQ@oakseed.demon.co.uk>
In article <slrn90g3l3.boe.mgjv@martien.heliotrope.home>, Martien Verbruggen
<URL:mailto:mgjv@tradingpost.com.au> wrote:
>
> Perl. Perl. Perl. Perl. Perl. Perl. Perl.
> or perl if you talk about the program. If you want to program in it,
> please get used to spelling the name correctly.
I agree that this oft repeated mistake is irritating, but given
that the name Perl is supposed to be an acronym I can also see
some validity in spelling it PERL.
--
James Taylor <james (at) oakseed demon co uk>
PGP key available ID: 3FBE1BF9
Fingerprint: F19D803624ED6FE8 370045159F66FD02
------------------------------
Date: Tue, 07 Nov 2000 17:46:04 +0100
From: Oliver =?iso-8859-1?Q?S=F6der?= <soeder@ai-lab.fh-furtwangen.de>
Subject: references (one element of an array to an array)
Message-Id: <3A0831CC.7A4CB23E@ai-lab.fh-furtwangen.de>
I have got to build a list, but I have one problem.
How can I create a reference from one element of an array (which is an
scalar) to an whole array?
#!/usr/bin/perl
@arra=3Dqw(Hi du dummer Depp);@arra2=3Dqw(und noch ein dummer depp);
$test=3D\@arra;
$test->[0]=3D\@arra2; #HOW CAN I SOLVE THIS PROBLEM?
print $test->[0],"\n";
foreach (@arra){
s/$test//g;
}
print @arra,"\n";
That doesn=B4t work.
Thanks =
Oliver S=F6der
------------------------------
Date: Tue, 07 Nov 2000 17:36:55 GMT
From: cfedde@fedde.littleton.co.us (Chris Fedde)
Subject: Re: references (one element of an array to an array)
Message-Id: <X4XN5.224$Bf7.189810688@news.frii.net>
In article <3A0831CC.7A4CB23E@ai-lab.fh-furtwangen.de>,
Oliver Söder <soeder@ai-lab.fh-furtwangen.de> wrote:
>I have got to build a list, but I have one problem.
>
>How can I create a reference from one element of an array (which is an
>scalar) to an whole array?
>
>#!/usr/bin/perl
>@arra=qw(Hi du dummer Depp);@arra2=qw(und noch ein dummer depp);
>$test=\@arra;
>$test->[0]=\@arra2; #HOW CAN I SOLVE THIS PROBLEM?
>print $test->[0],"\n";
>foreach (@arra){
>s/$test//g;
>}
>print @arra,"\n";
>
>That doesn´t work.
>
Do you want to merge the two lists?
my @arra3 = (@arra, @arra2)
Replace element 0 of @arra with @arra2?
splice (@arra, 0, 1, @arra2);
Make element 0 of @arra into a reference to @arra2?
$arra[0] = \@arra2;
Or maybe I've missed the point completely.
chris
--
This space intentionally left blank
------------------------------
Date: 07 Nov 2000 17:50:51 +0000
From: nobull@mail.com
Subject: Re: references (one element of an array to an array)
Message-Id: <u91ywnisck.fsf@wcl-l.bham.ac.uk>
Oliver Söder <soeder@ai-lab.fh-furtwangen.de> writes:
> I have got to build a list, but I have one problem.
>
> How can I create a reference from one element of an array (which is an
> scalar) to an whole array?
The only sensible interpretation I can think of for that sentence is
"given a reference to an array element how can I get a reference to
the array?". The answer to that question is you can't.
I do not think that is actually what you meant.
> #!/usr/bin/perl
> @arra=qw(Hi du dummer Depp);@arra2=qw(und noch ein dummer depp);
> $test=\@arra;
> $test->[0]=\@arra2; #HOW CAN I SOLVE THIS PROBLEM?
What problem? I works fine the 'Hi' in $arra[0] is replaced by a
reference to @arra2. Can you please explain what you were hoping to
do?
> print $test->[0],"\n";
What are you expecting this to do? What it _will_ do is print out the
stringified representation of a reference to @arra2.
> foreach (@arra){
> s/$test//g;
> }
This makes no sense at all. You are interpolating the stringified
representation of a reference to @arra into a regular expression.
Can you please explain what you were hoping to do?
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: 07 Nov 2000 11:15:19 -0600
From: Ren Maddox <ren.maddox@tivoli.com>
Subject: Re: references (one element of an array to an array)
Message-Id: <m33dh3snyw.fsf@dhcp11-177.support.tivoli.com>
Oliver Söder <soeder@ai-lab.fh-furtwangen.de> writes:
> How can I create a reference from one element of an array (which is an
> scalar) to an whole array?
>
> #!/usr/bin/perl
> @arra=qw(Hi du dummer Depp);@arra2=qw(und noch ein dummer depp);
> $test=\@arra;
> $test->[0]=\@arra2; #HOW CAN I SOLVE THIS PROBLEM?
This replaces "Hi" in @arra with a reference to @arra2.
> print $test->[0],"\n";
And this prints that reference (something like ARRAY(0x8107c60)).
> foreach (@arra){
> s/$test//g;
$test is a reference. This stringifies it (as above) and then tries
to remove such a string from each element of @arra. None of them
contain such a string, so nothing happens.
> }
> print @arra,"\n";
This prints the contents of @arra all run together. The first element
is an array reference and the next three are unchanged, so you get
something like:
ARRAY(0x8107c60)dudummerDepp
> That doesn´t work.
What is it that you want it to do?
Taking a wild guess at what you want, it looks like you might want to
remove from @arra2 any elements that are in @arra. If so, you can
use:
#!/usr/bin/perl -w
use strict;
my @arra = qw(Hi du dummer Depp);
my @arra2 = qw(und noch ein dummer depp);
my %arra_elements;
@arra_elements{@arra} = ();
@arra2 = grep { ! exists $arra_elements{$_} } @arra2;
print "@arra2\n";
__END__
Note that this is case sensitive but can be changed by changing two
lines. The initialization of %arra_elements would change to:
$arra_elements{uc $_}++ for @arra;
and the grep would change to:
@arra2 = grep { ! $arra_elements{uc $_} } @arra2;
HTH,
--
Ren Maddox
ren@tivoli.com
------------------------------
Date: Tue, 07 Nov 2000 18:19:19 +0100
From: Oliver =?iso-8859-1?Q?S=F6der?= <soeder@ai-lab.fh-furtwangen.de>
Subject: references
Message-Id: <3A083996.9074E17B@ai-lab.fh-furtwangen.de>
How can I refere from one element of an array to an array?
I have to build a linked list. =
$list->[0}=3D\@array; #doesn=B4t work and i don=B4t know how to solute it=
Thanks a lot
Oliver S=F6der
------------------------------
Date: Tue, 07 Nov 2000 17:40:08 GMT
From: cfedde@fedde.littleton.co.us (Chris Fedde)
Subject: Re: references
Message-Id: <Y7XN5.225$Bf7.171105792@news.frii.net>
In article <3A083996.9074E17B@ai-lab.fh-furtwangen.de>,
Oliver Söder <soeder@ai-lab.fh-furtwangen.de> wrote:
>How can I refere from one element of an array to an array?
>
>I have to build a linked list.
>
Perl has dynamic array allocation. Most of the places where you might use a
linked list in C you can use an array in Perl.
--
This space intentionally left blank
------------------------------
Date: 07 Nov 2000 17:51:42 +0000
From: nobull@mail.com
Subject: Re: references
Message-Id: <u9zojbhdqp.fsf@wcl-l.bham.ac.uk>
Oliver Söder <soeder@ai-lab.fh-furtwangen.de> writes:
> How can I refere from one element of an array to an array?
Can you elaborate on that?
> I have to build a linked list.
Why do you say you have to build a linked list?
> $list->[0}=\@array; #doesn't work and i don't know how to solute it
Change the } to ] and it works just fine.
Sets the first element of the referenced by $list to be a reference to
@array.
You need to show us more code so we can work out what you are really
trying to do.
Oh, and please stop uning MIME.
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: 7 Nov 2000 10:56:30 -0600
From: logan@cs.utexas.edu (Logan Shaw)
Subject: Re: returning a true value is FUN! (was Re: Log.pm did not return a true value)
Message-Id: <8u9c7u$an$1@cheshire.cs.utexas.edu>
In article <Pine.GSO.4.21.0011070826300.25313-100000@crusoe.crusoe.net>,
Jeff Pinyan <japhy@pobox.com> wrote:
>On Nov 7, Anno Siegel said:
>>Jeff Zucker <jeff@vpservices.com> wrote in comp.lang.perl.misc:
>>As it happens, it even works with the quotes.
>
>As does:
>
> ()=0;
>
>at the end of a file... sigh, what wicked webs we weave.
Other things that work:
!();
[];
$];
$$;
- Logan
------------------------------
Date: Tue, 7 Nov 2000 12:20:40 -0500
From: Jeff Pinyan <jeffp@crusoe.net>
Subject: Re: returning a true value is FUN! (was Re: Log.pm did not return a true value)
Message-Id: <Pine.GSO.4.21.0011071220120.25313-100000@crusoe.crusoe.net>
On Nov 7, Logan Shaw said:
>> ()=0;
>
>Other things that work:
>
> !();
> [];
> $];
> $$;
Ah, but those are somewhat more intuitive. Why would assigning 0 to an
empty list return a true value?
--
Jeff "japhy" Pinyan japhy@pobox.com http://www.pobox.com/~japhy/
PerlMonth - An Online Perl Magazine http://www.perlmonth.com/
The Perl Archive - Articles, Forums, etc. http://www.perlarchive.com/
CPAN - #1 Perl Resource (my id: PINYAN) http://search.cpan.org/
------------------------------
Date: Tue, 07 Nov 2000 17:03:02 GMT
From: dhartsough@my-deja.com
Subject: Re: Sorting hash of hashes by value
Message-Id: <8u9cjv$ma7$1@nnrp1.deja.com>
In article <8u7bjf$2pn$1@nnrp1.deja.com>,
dhartsough@my-deja.com wrote:
> Hi,
> The subject line sort of says it all. I know how to sort a hash by
> value and get the ordered list of keys. However, I do not see how to
> sort a hash of hashes (or hash of hash of hashes...) by value
returning
> an ordered list of pairs of keys. Any help greatly appreciated...
>
> dave
>
> Sent via Deja.com http://www.deja.com/
> Before you buy.
>
I apologize for the cross posting of a response to my own message, but
I want to make sure that anyone with a good idea sees this. OK, I can
see from the replies that I did an incredibly poor job of explaining
the problem. Let me try again with an example (I apologize for the
brevity of the earlier question, it is obvious to me what I wanted so
it must be obvious to everybody else...). Anyway, if I have the hash
of hashes shown below:
my %hash = (
france => {
red => "12.72",
blue => "1.65",
green => "3.94",
},
germany => {
red => "6.47",
blue => "3.65",
green => "9.45",
},
italy => {
red => "2.22",
blue => "19.5",
green => "0.63",
},
);
I want to sort the keys by value and get back a list of hash keys in
pairs sorted by the order of the values they reference (e.g. italy,
green, france, blue, italy, red, germany, blue, france, green,... the
first pair of keys "italy", "green" references the value 0.63, the next
pair "france", "blue" references the value 1.65 ...). I can accomplish
this by creating a one-dimensional hash using a compound key formed by
a join on the original keys and then a split on the result:
foreach $key_1(keys %hash){
foreach $key_2(keys %{$hash{$key_1}}){
$cmpd_key = join ':',$key_1,$key_2;
$cmpd_hash{$cmpd_key} = $hash{$key_1}{$key_2};
}
}
@ord_list = sort{$cmpd_hash{$a} <=> $cmpd_hash{$b}} keys %cmpd_hash;
foreach $key (@ord_list){
($key_1,$key_2) = split(/:/,$key);
...now do other stuff I really want to do with $key_1 and $key_2...
}
The above works and gives me what I want, but seems to be a very non-
Perlish and inefficient solution. I am looking for something that will
sort by value by acting directly on the multi-dimensional hash, rather
than compressing it down to a one-dimensional hash and then splitting
the resulting keys. As always, any help greatly appreciated...
dave
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Tue, 07 Nov 2000 10:05:20 -0800
From: Jeff Zucker <jeff@vpservices.com>
Subject: Re: Sorting hash of hashes by value
Message-Id: <3A084460.E73336A3@vpservices.com>
dhartsough@my-deja.com wrote:
>
>
> my %hash = (
> france => {
> red => "12.72",
> blue => "1.65",
> green => "3.94",
> },
> germany => {
> red => "6.47",
> blue => "3.65",
> green => "9.45",
> },
> italy => {
> red => "2.22",
> blue => "19.5",
> green => "0.63",
> },
> );
>
> ...
>
> foreach $key_1(keys %hash){
> foreach $key_2(keys %{$hash{$key_1}}){
> $cmpd_key = join ':',$key_1,$key_2;
> $cmpd_hash{$cmpd_key} = $hash{$key_1}{$key_2};
> }
> }
>
> @ord_list = sort{$cmpd_hash{$a} <=> $cmpd_hash{$b}} keys %cmpd_hash;
>
> foreach $key (@ord_list){
> ($key_1,$key_2) = split(/:/,$key);
> ...now do other stuff I really want to do with $key_1 and $key_2...
> }
How about:
my %cmpd_hash;
while (my($country,$vals)=each %hash) {
while (my($color,$num)=each %{$vals}) {
$cmpd_hash{$num} = {country=>$country,color=>$color};
}
}
for my $num( sort {$a <=> $b} keys %cmpd_hash ) {
print "$num ", $cmpd_hash{$num}->{country},
' ' , $cmpd_hash{$num}->{color}, "\n";
}
--
Jeff
------------------------------
Date: 07 Nov 2000 10:13:48 -0600
From: Ren Maddox <ren.maddox@tivoli.com>
Subject: Re: Sorting hash of hashes by value
Message-Id: <m3g0l3sqtf.fsf@dhcp11-177.support.tivoli.com>
dhartsough@my-deja.com writes:
> The above works and gives me what I want, but seems to be a very non-
> Perlish and inefficient solution. I am looking for something that will
> sort by value acting directly on the multi-dimensional hash, rather
> than compressing it down to a one-dimensional version. As always, any
> help greatly appreciated...
The problem is that sort is a one-dimensional operation. Because of
that, it will need one-dimensional data on which to operate. I've
thought about it for a few minutes, and no significant improvements
come to mind.
--
Ren Maddox
ren@tivoli.com
------------------------------
Date: Tue, 7 Nov 2000 12:07:15 -0400
From: "k" <none@none.ca>
Subject: SSLeay - compiles but Autosplit has problem!
Message-Id: <lOVN5.89886$YG5.68917@tor-nn1.netcom.ca>
I've installed OpenSSL and Net::SSLeay to a local directory with no
problems:
OpenSSL Directory /home3/ssl/OpenSSL/
Net::SSLeay /home/ssl/HTML/cgi/lib/(auto and Net
directories)
Using a test script, I can "use Net::SSLeay" with no problems, but when I
try to call some routines as with the following code which POSTs to an SSL
website:
use Net::SSLeay qw(get_https post_https sslcat make_headers make_form);
my ($page, $response, %reply_headers) = &Net::SSLeay::post_https(
'www.bacus.pt', 443, '/foo.cgi', '', &Net::SSLeay::make_form('OK'=>
'1', 'name' => 'Sampo')
);
I get an error saying "GoTo undefined subroutine &Net::SSLeay::make_form at
/usr/lib/perl5/AutoLoader/pm line 51 ".
When I installed Net::SSLeay it split any AutoSplit routines into their
separate files, so they definitely exist and are in the right place
(lib/auto/Net/SSLeay/*.al).
Is there a way to get aroud this?
Much appreciated,
kh
------------------------------
Date: 07 Nov 2000 10:40:26 -0600
From: Ren Maddox <ren.maddox@tivoli.com>
Subject: Re: system call return
Message-Id: <m3bsvrspl1.fsf@dhcp11-177.support.tivoli.com>
Lars Oeschey <oeschey@media-saturn.com> writes:
> the second system call first returns some error message (which I could
> ignore) and
> afterwards the "SUCCESS" message. But i do get $EP{$_}=1, so I guess,
> the
> grep returns after getting the first message. When I do the systemcall
> at
> the prompt, I just get the "SUCCESS" line back, as it should be.
> Any ideas?
What is the error message? That might indicate what the problem is.
Also, it could be useful to check what the actual return value is in
the case that it isn't 0. That could also give a clue to the problem.
--
Ren Maddox
ren@tivoli.com
------------------------------
Date: Tue, 7 Nov 2000 14:51:56 -0400
From: "pd" <pd@psps.com>
Subject: Win32::OLE excel.application
Message-Id: <r3YN5.57386$Z2.807558@nnrp1.uunet.ca>
Hi
First off let me say that I am not experienced in the use of Win32::OLE, or
with Objects in Perl
What I am trying to create is an automation script to convert a comma
seperated variable file (*.csv) into a MS Excel 97 Workbook (*.xls)
I have searched the web and all of the reference material I can find, but
this seems to be undocumented territory. everything I have found is either
outdated (excel 95) or doesn't cover file formats
here is a code snippit
use Win32::OLE;
$excel = new Win32::OLE('Excel.Application')
|| die "Excel did not start $! \n";
$excel->{'Visible'}=1;
my $Workbook = $excel->Workbooks->Open("$csvfile") || print" file not found
\n";
my $Worksheet = $Workbook->Worksheets(1);
#select the worksheet and autofit the columns
$Worksheet->Cells->Select();
$Worksheet->Cells->EntireColumn->AutoFit();
$Worksheet->SaveAs("$path$xlfile") || print "didnt save the $path$xlfile
file $!\n";
____ end snippit ______
this does load the .csv file, and saves it as a .xls file, but it does not
save in the .xls file format
any suggestions as to how to set the file format attribute before or during
the save?
------------------------------
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 V9 Issue 4832
**************************************