[17099] in Perl-Users-Digest
Perl-Users Digest, Issue: 4511 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Oct 3 21:05:44 2000
Date: Tue, 3 Oct 2000 18:05:17 -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: <970621517-v9-i4511@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Tue, 3 Oct 2000 Volume: 9 Number: 4511
Today's topics:
again a sort problem (help me please: newbie) jaur@mp3-search.nl
Re: again a sort problem (help me please: newbie) (Clay Irving)
Re: again a sort problem (help me please: newbie) <elephant@squirrelgroup.com>
Re: Automatically creating new virtual hosts using this <elephant@squirrelgroup.com>
check double words <george@aigiocity.gr>
Re: check double words <jeff@vpservices.com>
Re: check double words <lr@hpl.hp.com>
Re: converting \codes <lr@hpl.hp.com>
Re: converting \codes <Lloyd_Lim@mail.limunltd.com>
Re: converting \codes <lr@hpl.hp.com>
Re: converting \codes <lr@hpl.hp.com>
Re: converting \codes <Lloyd_Lim@mail.limunltd.com>
Converting to thumbnails apacheproblems@my-deja.com
Re: Converting to thumbnails (Martien Verbruggen)
Re: die() ignores tied STDERR? (Daniel Chetlin)
Re: die() ignores tied STDERR? (Ilya Zakharevich)
Re: die() ignores tied STDERR? (Martien Verbruggen)
Re: die() ignores tied STDERR? (Martien Verbruggen)
Re: Easy installation of modules <anmcguire@ce.mediaone.net>
Re: Hash of Arrays oddness? (Martien Verbruggen)
Re: Hash of Arrays oddness? (Martien Verbruggen)
Re: help: FORCE perl to evaluate arithmetic string <godzilla@stomp.stomp.tokyo>
MATH problem <felix.gourdeau@videotron.ca>
Re: MATH problem <lr@hpl.hp.com>
Re: MATH problem (Martien Verbruggen)
Re: multiple word command line arg <elephant@squirrelgroup.com>
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Tue, 03 Oct 2000 22:37:53 GMT
From: jaur@mp3-search.nl
Subject: again a sort problem (help me please: newbie)
Message-Id: <39da5ecf.98379989@news.freeler.nl>
Hi,
Can someone help me please.
I have a textfile with the following data:
file: main.txt
< a href="http://www.site53.com>">site 53</a><br>
< a href="http://www.new.com>">site 23>/a><br>
< a href="http://www.perl.com>">site 253</a><br>
< a href="http://www.etc.com>">site 453</a><br>
I've tried to use the following lines to sort this file:
open(INPUT, "main.txt" ) || die "error opening file";
while(<INPUT>)
{
( $field1, $field2 ) = split( /">/, $_ );
print sort $field2;
}
close(INPUT);
When I run this, it won't sort the lines.
How can I sort the the lines and add field1 before field2 (sorted!)
Thanks, Patrick.
------------------------------
Date: 3 Oct 2000 23:30:32 GMT
From: clay@panix.com (Clay Irving)
Subject: Re: again a sort problem (help me please: newbie)
Message-Id: <slrn8tkr0o.181.clay@panix3.panix.com>
On Tue, 03 Oct 2000 22:37:53 GMT, jaur@mp3-search.nl <jaur@mp3-search.nl> wrote:
>Can someone help me please.
>I have a textfile with the following data:
>
>file: main.txt
>< a href="http://www.site53.com>">site 53</a><br>
>< a href="http://www.new.com>">site 23>/a><br>
>< a href="http://www.perl.com>">site 253</a><br>
>< a href="http://www.etc.com>">site 453</a><br>
>
>I've tried to use the following lines to sort this file:
>
>open(INPUT, "main.txt" ) || die "error opening file";
>while(<INPUT>)
>{
> ( $field1, $field2 ) = split( /">/, $_ );
> print sort $field2;
>}
>close(INPUT);
>
>When I run this, it won't sort the lines.
>How can I sort the the lines and add field1 before field2 (sorted!)
perldoc -f sort
sort LIST
Sorts the LIST and returns the sorted list value.
[...]
Is $field2 a list?
Look at the examples provided in the documentation.
--
Clay Irving <clay@panix.com>
Whenever you find that you are on the side of the majority, it is time to
reform.
- Mark Twain
------------------------------
Date: Wed, 4 Oct 2000 10:39:01 +1000
From: jason <elephant@squirrelgroup.com>
Subject: Re: again a sort problem (help me please: newbie)
Message-Id: <MPG.14452732491b92f29897ea@localhost>
jaur@mp3-search.nl wrote ..
>Can someone help me please.
>I have a textfile with the following data:
>
>file: main.txt
>< a href="http://www.site53.com>">site 53</a><br>
>< a href="http://www.new.com>">site 23>/a><br>
>< a href="http://www.perl.com>">site 253</a><br>
>< a href="http://www.etc.com>">site 453</a><br>
>
>I've tried to use the following lines to sort this file:
>
>open(INPUT, "main.txt" ) || die "error opening file";
>while(<INPUT>)
>{
> ( $field1, $field2 ) = split( /">/, $_ );
> print sort $field2;
>}
>close(INPUT);
>
>When I run this, it won't sort the lines.
eh ? .. Perl may be amazing .. but it's not magic
check out the documentation for the 'sort' function
perldoc -f sort
you will see that it needs to take a LIST as (one of) it's argument(s)
.. you're looping through each line of text .. doing a crazy split and
then trying to sort a single field on each iteration through the loop
within the first loop - Perl isn't even aware that there *are* any more
lines in the file .. how could it possibly sort them all
you should first read all the lines into memory (a hash would be perfect
for holding these lines - it will make it very easy to sort them)
>How can I sort the the lines and add field1 before field2 (sorted!)
your question is not really one of Perl - it's one of programming .. so
the help that can be given to you is fairly limited (ie. this won't get
you very far considering the mess that your code is in) .. also - I'm
not sure what you mean by "add field1 before field2" .. but anyway
#!/usr/bin/perl -w
use strict;
open INPUT, 'main.txt' or die "Bad open: $!";
my %lines = ();
while(<INPUT>)
{
# assuming your data spec is accurate
my($numeric_field) = /site (\d+)/;
# assuming you want the newline left on
$lines{$numeric_field} = $_;
}
print "$lines{$_}" for sort { $a <=> $b } keys %lines;
__END__
--
jason -- elephant@squirrelgroup.com --
------------------------------
Date: Wed, 4 Oct 2000 09:27:42 +1000
From: jason <elephant@squirrelgroup.com>
Subject: Re: Automatically creating new virtual hosts using this script?
Message-Id: <MPG.14451675928152719897e6@localhost>
suzbik@btinternet.com wrote ..
>I have set up Apache and all the rest on my computer and it is working
>fine. I decided I would try and write a script that would enable me to
>automatically add new virtual domains. However it doesnt work. If i
>check the error log it says: [Mon Oct 02 18:52:05 2000] [error] [client
>127.0.0.1] (2)No such file or directory: couldn't spawn child process:
>c:/phpdev/www/cgi-bin/virtual.pl
excuse this reply - because I'm not sure at all what's wrong .. but you
haven't received any other replies - so I thought I'd take a stab
I think this is caused by an Apache mis-configuration .. ie. I don't
think that there's anything wrong with your script - just that Apache
isn't able to find it properly
perhaps you're missing a ScriptAlias or something .. I don't really
remember .. BUT .. to confirm that this is the problem try writing a
very small script .. consisting of a single print .. something like this
#!c:/phpdev/perl/perl.exe
print <<__EOI;
Content-type: text/html
<html>
<head>
<title>test</title>
</head>
<body>
<p>Test paragraph</p>
</body>
</html>
__EOI
__END__
if that throws the same error - then it's something to do with your
setup - and not a Perl issue .. perhaps that shebang line is incorrect
.. or perhaps you've some Apache configuration error
in any case - you'll be better off in the Apache docs or an Apache
related newsgroup
--
jason -- elephant@squirrelgroup.com --
------------------------------
Date: Wed, 4 Oct 2000 01:09:57 +0300
From: "gbouris" <george@aigiocity.gr>
Subject: check double words
Message-Id: <970610978.915977@athnrd02.forthnet.gr>
I need some help please because i am litle bit confused.
Let's say that I have this array
@array=('dog,','cat','bird',dog');
How can I eliminate double words (dog) so only one left at the end?
Thanks for your time!
------------------------------
Date: Tue, 03 Oct 2000 15:47:25 -0700
From: Jeff Zucker <jeff@vpservices.com>
Subject: Re: check double words
Message-Id: <39DA61FD.38BB1D46@vpservices.com>
gbouris wrote:
>
> I need some help please because i am litle bit confused.
No problem there, happens to me all the time.
> Let's say that I have this array
> @array=('dog,','cat','bird',dog');
>
> How can I eliminate double words (dog) so only one left at the end?
This topic has been discussed on this list numerous times in the past
few weeks alone. You could have discovered that fact by searching the
archives of the group at http://www.dejanews.com/ for the word
"duplicate".
The answer given in that discussion was that this is a Frequently Asked
Question (is that really a surprise that this question would have been
asked frequently?) that is fully discussed in the perlfaq4 section
titled "How can I remove duplicate elements from a list or array?". You
could have found out that fact by typing "perldoc -q duplicate" at the
command prompt of any system that runs perl or by looking up "array" and
then "duplicate" at
http://www.perl.com/pub/doc/manual/html/pod/perlfaq.html.
If you have questions after reading the FAQ, please come back and ask
again.
--
Jeff
------------------------------
Date: Tue, 3 Oct 2000 15:54:29 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: check double words
Message-Id: <MPG.1444037cf818884998adfe@nntp.hpl.hp.com>
In article <970610978.915977@athnrd02.forthnet.gr> on Wed, 4 Oct 2000
01:09:57 +0300, gbouris <george@aigiocity.gr> says...
> I need some help please because i am litle bit confused.
>
> Let's say that I have this array
> @array=('dog,','cat','bird',dog');
>
> How can I eliminate double words (dog) so only one left at the end?
Would you believe that this Question has been Asked before, Frequently,
in fact?
perlfaq4: "How can I remove duplicate elements from a list or array?"
> Thanks for your time!
You would do better to use your own time, by scanning the voluminous
Perl FAQ once, reading the questions at least, to get some idea of all
that is in there.
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Tue, 3 Oct 2000 15:44:18 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: converting \codes
Message-Id: <MPG.1444011aa437509b98adfc@nntp.hpl.hp.com>
In article <VcsC5.5615$O5.120571@news.itd.umich.edu> on Tue, 03 Oct 2000
21:29:25 GMT, Sean McAfee <mcafee@waits.facilities.med.umich.edu>
says...
> In article <MPG.1443de294b069d1998adfb@nntp.hpl.hp.com>,
> Larry Rosler <lr@hpl.hp.com> wrote:
> > my %escapes = map { $_ => eval qq("\\$_") } qw( a b e f n r t );
> >
> > s{\\( ([0-7]{1,3}) | x([\da-fA-F]{1,2}) | c(.) | [abefnrt] ) }
> > { defined $2 ? chr oct $2 :
> > defined $3 ? chr hex $3 :
> > defined $4 ? chr ord $4 & "\x1F" :
> > $escapes{$1} }egx;
>
> This can actually be tightened up a bit more, since oct() can handle
> hexadecimal notation as well:
>
> s{\\( ([0-7]{1,3} | x[\da-fA-F]{1,2}) | c(.) | [abefnrt] ) }
> { defined $2 ? chr oct $2 :
> defined $3 ? chr ord $3 & "\x1F" :
> $escapes{$1} }egx;
>
> Although perlfunc claims oct only treats its argument as hexadecimal if it
> begins with "0x", it seems that a single "x" works as well.
It seems that relying on something that is expressly against what the
documentation says is a bad idea, whether it works or not. The behavior
you observe may well be that of the One True Perl today. But who knows
about tomorrow?
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: 3 Oct 2000 23:01:16 GMT
From: Lloyd Lim <Lloyd_Lim@mail.limunltd.com>
Subject: Re: converting \codes
Message-Id: <8rdofs$865$1@samba.rahul.net>
In article <MPG.144437d9d6b504f49897e5@localhost>,
jason <elephant@squirrelgroup.com> wrote:
>Lloyd Lim wrote ..
>>
>>I'd like to be able to process \t, \n, \r, ..., \033, \x1B, \c[
>>in a string and substitute the appropriate characters just like
>>Perl does. I'd also prefer avoiding eval, if possible.
>
>I'm not sure why you want to avoid eval .. but if it's for safety
>(because you're unsure of your inputs here) then the following are safe
>(although they still use a type of eval)
>
>[examples deleted]
Yes, I just want to be safe because the input can be anything.
After further thought, I came up with the following using eval:
$str = quotemeta($str);
$str =~ s/\\\\(?=[tnrfae01xc])/\\/g;
$str = eval("qq($str)");
I think this should be safe, but you never know what someone will
come up with. Can anyone think of any obvious holes?
Thanks to everyone for all the examples and code. I learned
a great deal. My non-eval code would have been much longer.
+++
Lloyd Lim <Lloyd_Lim@mail.limunltd.com>
------------------------------
Date: Tue, 3 Oct 2000 15:58:40 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: converting \codes
Message-Id: <MPG.1444047f4cf396b298adff@nntp.hpl.hp.com>
In article <MPG.1444011aa437509b98adfc@nntp.hpl.hp.com> on Tue, 3 Oct
2000 15:44:18 -0700, Larry Rosler <lr@hpl.hp.com> says...
> In article <VcsC5.5615$O5.120571@news.itd.umich.edu> on Tue, 03 Oct 2000
> 21:29:25 GMT, Sean McAfee <mcafee@waits.facilities.med.umich.edu>
> says...
...
> > s{\\( ([0-7]{1,3} | x[\da-fA-F]{1,2}) | c(.) | [abefnrt] ) }
> > { defined $2 ? chr oct $2 :
> > defined $3 ? chr ord $3 & "\x1F" :
> > $escapes{$1} }egx;
> >
> > Although perlfunc claims oct only treats its argument as hexadecimal if it
> > begins with "0x", it seems that a single "x" works as well.
>
> It seems that relying on something that is expressly against what the
> documentation says is a bad idea, whether it works or not. The behavior
> you observe may well be that of the One True Perl today. But who knows
> about tomorrow?
But I would accept this simple change:
s{\\( ([0-7]{1,3} | x[\da-fA-F]{1,2}) | c(.) | [abefnrt] ) }
{ defined $2 ? chr oct "0$2" : # prefix '0' to either one!
defined $3 ? chr ord $3 & "\x1F" :
$escapes{$1} }egx;
In no event is this the "tons of code" the OP said he required.
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Tue, 3 Oct 2000 16:25:04 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: converting \codes
Message-Id: <MPG.14440aac54ad449c98ae01@nntp.hpl.hp.com>
In article <8rdofs$865$1@samba.rahul.net> on 3 Oct 2000 23:01:16 GMT,
Lloyd Lim <Lloyd_Lim@mail.limunltd.com> says...
...
> Yes, I just want to be safe because the input can be anything.
> After further thought, I came up with the following using eval:
>
> $str = quotemeta($str);
> $str =~ s/\\\\(?=[tnrfae01xc])/\\/g;
That is missing 'b', and the '01' should be '0-7'.
> $str = eval("qq($str)");
>
> I think this should be safe, but you never know what someone will
> come up with. Can anyone think of any obvious holes?
I think the quotemeta with the doubled quoting makes it safe. I haven't
been able to interpolate a damaging command into the string using
'${\...}" or '@{[...]}'. But maybe someone else is smarter.
> Thanks to everyone for all the examples and code. I learned
> a great deal. My non-eval code would have been much longer.
But the eval code is likely to be much slower, because it must crank up
the compiling mechanism.
Anyhow, minimizing the code was a fun midnight project, still going on
today.
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: 3 Oct 2000 23:37:55 GMT
From: Lloyd Lim <Lloyd_Lim@mail.limunltd.com>
Subject: Re: converting \codes
Message-Id: <8rdqkj$8ip$1@samba.rahul.net>
In article <MPG.1444047f4cf396b298adff@nntp.hpl.hp.com>,
Larry Rosler <lr@hpl.hp.com> wrote:
>
> s{\\( ([0-7]{1,3} | x[\da-fA-F]{1,2}) | c(.) | [abefnrt] ) }
> { defined $2 ? chr oct "0$2" : # prefix '0' to either one!
> defined $3 ? chr ord $3 & "\x1F" :
> $escapes{$1} }egx;
>
>In no event is this the "tons of code" the OP said he required.
Are ya done beating me up over my "tons of code"? :)
FWIW, I didn't know about the s///e option and wouldn't have
been that clever to think of using it that way anyway. So I
probably would've just pattern matched with several if/elsif's
inside of a while. But it wouldn't have worked quite right
because it would be doing multiple passes, as another poster
pointed out. (And I wouldn't have caught that bug either!)
<puts his Perl dunce cap back on and crawls back to the lurking corner> :)
+++
Lloyd Lim <Lloyd_Lim@mail.limunltd.com>
------------------------------
Date: Tue, 03 Oct 2000 23:19:46 GMT
From: apacheproblems@my-deja.com
Subject: Converting to thumbnails
Message-Id: <8rdpib$ljb$1@nnrp1.deja.com>
We would like a simple perl script that will take a gif or jpeg and
will reduce the size of the picture by N%. The code will be used both
in real time and batch process. The script should be able to read the
original size of the picture. Any such scripts or libraries we can use?
Thank you,
-a
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Tue, 03 Oct 2000 23:36:51 GMT
From: mgjv@verbruggen.comdyn.com.au (Martien Verbruggen)
Subject: Re: Converting to thumbnails
Message-Id: <slrn8tkrci.b9n.mgjv@verbruggen.comdyn.com.au>
On Tue, 03 Oct 2000 23:19:46 GMT,
apacheproblems@my-deja.com <apacheproblems@my-deja.com> wrote:
> We would like a simple perl script that will take a gif or jpeg and
> will reduce the size of the picture by N%. The code will be used both
> in real time and batch process. The script should be able to read the
> original size of the picture. Any such scripts or libraries we can use?
use Image::Magick;
# http://www.imagemagick.org/
my $im = Image::Magick->new();
my $rc = $im->Read($image_name);
die $rc if $rc;
$rc = $im->Scale("50%");
die $rc if $rc;
$rc = $im->Write($other_image_name);
die $rc if $rc;
Apart from Scale, there are also Zoom, Sample, Transform, Minify and
Maxify (IIRC).
Martien
--
Martien Verbruggen |
Interactive Media Division | We are born naked, wet and hungry.
Commercial Dynamics Pty. Ltd. | Then things get worse.
NSW, Australia |
------------------------------
Date: 3 Oct 2000 21:45:12 GMT
From: daniel@chetlin.com (Daniel Chetlin)
Subject: Re: die() ignores tied STDERR?
Message-Id: <8rdk180du6@news1.newsguy.com>
On Tue, 3 Oct 2000 09:21:23 +1100,
Martien Verbruggen <mgjv@tradingpost.com.au> wrote:
>Ok, apart from pointer abuse with unpack and passing bad stuff to
>syscall, can anyone think of other things one can do from Perl (not XS
>or using the Inline stuff) that causes perl to segfault?
Off the top of my head...
[~] $ perl -e'use overload q/""/,sub{"$_[0]"};$r=bless{};print$r'
Segmentation fault (core dumped)
[~] $ perl -e'sub TIEHASH{bless$_[1]}sub FETCH{shift->{$_[0]}}
tie%h,"main",\%h;$h{a}'
Segmentation fault (core dumped)
Lots of fun games you can play with the new REx features as well.
-dlc
------------------------------
Date: 3 Oct 2000 22:39:54 GMT
From: ilya@math.ohio-state.edu (Ilya Zakharevich)
Subject: Re: die() ignores tied STDERR?
Message-Id: <8rdn7q$kmg$1@charm.magnus.acs.ohio-state.edu>
[A complimentary Cc of this posting was sent to Daniel Chetlin
<daniel@chetlin.com>],
who wrote in article <8rdk180du6@news1.newsguy.com>:
> [~] $ perl -e'use overload q/""/,sub{"$_[0]"};$r=bless{};print$r'
> Segmentation fault (core dumped)
Why so hairy? This should be more or less equivalent to
perl -we 'sub a {my $x=shift; a($x)} a(1)'
If it is not, something is buggy...
> [~] $ perl -e'sub TIEHASH{bless$_[1]}sub FETCH{shift->{$_[0]}}
> tie%h,"main",\%h;$h{a}'
> Segmentation fault (core dumped)
Similar.
Ilya
------------------------------
Date: Tue, 03 Oct 2000 22:57:59 GMT
From: mgjv@verbruggen.comdyn.com.au (Martien Verbruggen)
Subject: Re: die() ignores tied STDERR?
Message-Id: <slrn8tkp3l.64u.mgjv@verbruggen.comdyn.com.au>
[Next time you send a Cc, please state so in the body of your message.
I almost replied to your email instead of this post, thinking that
there was no post. Also inform the authors of your newsreader that
they should insert a line like that, and that they should honour the
'Mail-Copies-To:' header]
On Tue, 3 Oct 2000 10:14:24 -0400,
David Coppit <newspost@coppit.org> wrote:
> On Mon, 2 Oct 2000, Martien Verbruggen wrote:
>
> > > I tied STDERR to a module in order to detect when something goes wrong
> >
> > why?
>
> Because I'm now maintaining CGI::Cache, which caches output from CGI
> scripts to speed up execution on subsequent runs. The problem is that
> I don't want to cache output if an error occurred. This means that I'd
> like to determine when the script writes to STDERR, and dump the
> captured STDOUT instead of caching it.
Aha.. well... that's a valid reason I guess.. And I guess you want to
capture warn, die, and print STDERR output, alltogether? (carp,
croak, cluck and confess just use die and warn).
You could do a combination of things, maybe. Apart from tie-ing
STDERR, you could also override warn and die (like CGI::Carp does, for
example). It's hardly elegant, but it may be the only way to get about
it.
If the perl developers agree with you that warn and die should use
STDERR, you wouldn't need to, but your module will have to deal with
the fact that that won't ever happen retrospectively :)
Martien
--
Martien Verbruggen |
Interactive Media Division | Failure is not an option. It comes
Commercial Dynamics Pty. Ltd. | bundled with your Microsoft product.
NSW, Australia |
------------------------------
Date: Tue, 03 Oct 2000 23:05:20 GMT
From: mgjv@verbruggen.comdyn.com.au (Martien Verbruggen)
Subject: Re: die() ignores tied STDERR?
Message-Id: <slrn8tkphe.64u.mgjv@verbruggen.comdyn.com.au>
On 3 Oct 2000 21:45:12 GMT,
Daniel Chetlin <daniel@chetlin.com> wrote:
> On Tue, 3 Oct 2000 09:21:23 +1100,
> Martien Verbruggen <mgjv@tradingpost.com.au> wrote:
> >Ok, apart from pointer abuse with unpack and passing bad stuff to
> >syscall, can anyone think of other things one can do from Perl (not XS
> >or using the Inline stuff) that causes perl to segfault?
>
> Off the top of my head...
>
> [~] $ perl -e'use overload q/""/,sub{"$_[0]"};$r=bless{};print$r'
> Segmentation fault (core dumped)
> [~] $ perl -e'sub TIEHASH{bless$_[1]}sub FETCH{shift->{$_[0]}}
> tie%h,"main",\%h;$h{a}'
> Segmentation fault (core dumped)
Neither of the two segfault for me (perl 5.005_03 and 5.6.0). They do
emit warnings when run with -w though.
Martien
--
Martien Verbruggen |
Interactive Media Division | Never hire a poor lawyer. Never buy
Commercial Dynamics Pty. Ltd. | from a rich salesperson.
NSW, Australia |
------------------------------
Date: Tue, 3 Oct 2000 18:36:56 -0500
From: "Andrew N. McGuire " <anmcguire@ce.mediaone.net>
Subject: Re: Easy installation of modules
Message-Id: <Pine.LNX.4.21.0010031834550.7834-100000@hawk.ce.mediaone.net>
On Tue, 3 Oct 2000, zoo.tv@btinternet.com quoth:
> HI,
>
> Can you put any module as the script you are calling from, or do they have
> to be installed properly?
>
> The module in question is DBI.pm. The hosting company of a site I'm working
> on doesn't have it but I need it to connect to a mySQL database on another
> server. I guess I'd have to put the mysql.pm (DBD) module in there too.
I guess I am a bit unclear on the concept of what you are asking, can you
clarify your question?
anm
--
perl -wMstrict -e '
$a=[[qw[J u s t]],[qw[A n o t h e r]],[qw[P e r l]],[qw[H a c k e r]]];$.++
;$@=$#$a;$$=[reverse sort map$#$_=>@$a]->[$|];for$](--$...$$){for$}($|..$@)
{$$[$]][$}]=$a->[$}][$]]}}$,=$";$\=$/;print map defined()?$_:$,,@$_ for @$'
------------------------------
Date: Tue, 03 Oct 2000 22:17:51 GMT
From: mgjv@verbruggen.comdyn.com.au (Martien Verbruggen)
Subject: Re: Hash of Arrays oddness?
Message-Id: <slrn8tkmod.64u.mgjv@verbruggen.comdyn.com.au>
On Tue, 03 Oct 2000 12:57:59 -0400, Andrew Pearce <pearce@aw.sgi.com>
wrote:
> Martien Verbruggen wrote:
>
> > > I have a hash and one element is to be an array. As I construct
> > > it, I'm using the push() call as recommended;
> >
> > Recommended by whom?
>
> By "Perl 5 Complete", by O'Reilly's "Perl Cookbook", by O'Reilly's
> "Learning Perl", by Osborne's "Perl Programmer's Reference" ...
Not all of these are good books.
They discuss push, but they don't recommend it in the way that you
were using it. For the example code that you gave push is unnecessary.
Using push to create an array reference is probably hardly advocated
by anyone, although many programmers will rely on it. I tend to
explicitly create one myself.
> > Why not just
> >
> > my @array = makeArrayFunc();
> > $hash{$key} = \@array;
>
> This is a simplified version of the file. There is other processing
> happening on the individual array elements in the real code.
You didn't mention that in the original post.
> > # perl
> > @a = qw (foo bar baz banana);
> > foreach $ae (@a)
> > {
> > push @{$hash{bleb}}, $ae;
> > }
> > print "@{$hash{bleb}}\n";
> > __END__
> > foo bar baz banana
>
> Change this slightly and it will not work on your Perl too:
>
> @a = qw (foo bar baz banana);
> dbmopen( %hash, "test", 0666);
> foreach $ae (@a)
> {
> push @{$hash{bleb}}, $ae;
> }
> print "@{$hash{bleb}}\n";
> __END__
> bar baz banana
You didn't mention dbmopen in the original post. And yes, a regular
hash and one tied by dbmopen are not the same thing. It is much more
likely for things to go wrong with tied hashes than with the builtins.
This is a vital piece of information. Why didn't you say so in the
first place?
Adding this line just after the dbmopen() fixes it:
$hash{bleb} = [];
> Please, no need to educate me about the ability to store array
> references in a dbm or anything like that, just thought you might
> like to know that I was not trying to waste anyone's time, or blame
> Perl without investigating it. I know, I know, "why are you trying
> to do this?" - existing code, prototype project, trying not to
> change arguments to calls, and a myriad of other bad reasons.
I wasn't going to educate you :) And yes, I see that problem with
5.6.0 and dbmopen as well. It may be a 'bug' with the dbm stuff. On
the other hand, dbm is documented, as you mentione yourself, not to
store references. I don't think it's fair to expect it to handle it
any way, even though it is documented not to work.
In C they call behaviour like this undefined: Anything might happen,
including the behaviour you expect. In this case it almost does what
you want, but not entirely.
But then, perl isn't a defined language anyway. I'd still not rely on
things that are documented not to work, however. Even if you can make
them work with some acrobatics. Who knows what will happen on the next
release of the code.
> perl -v
> This is perl, version 5.004_04 built for irix-n32
> Copyright 1987-1997, Larry Wall
>
> (ah, no bugs in main-stream software, like, um, Windows?)
oooh.. them's fightin' words. Perl is developed in a very different
way from Windows. An OS which is pushed out to distribution by
marketing is different from a programming language interpreter which
(until recently) got released for very different reasons.
Besides, I didn't say Perl has _no_ bugs. I said it was unlikely to
have bugs in an area that is used by so many people.
> I thank you for your help and I'm glad I gave you the oportunity to
> be a jerk.
A jerk? My.. You do have thin skin, don't you? You probably need to
get some more Usenet experience before you can take posts for what
they're worth, instead of reading things into them that are not even
there.
You posted a question that had no bearing to your real problem. You
stated that the code you presented displayed certain behaviour, and
you asked whether that was a bug in perl. I demonstrated that it did
not have that behaviour, and therefore couldn't be a bug in perl.
I'm not that sure why you considered it to be a jerky response, but I
assure you, it's all in your perception.
Martien
--
Martien Verbruggen |
Interactive Media Division | Begin at the beginning and go on till
Commercial Dynamics Pty. Ltd. | you come to the end; then stop.
NSW, Australia |
------------------------------
Date: Tue, 03 Oct 2000 22:32:42 GMT
From: mgjv@verbruggen.comdyn.com.au (Martien Verbruggen)
Subject: Re: Hash of Arrays oddness?
Message-Id: <slrn8tknk8.64u.mgjv@verbruggen.comdyn.com.au>
On Tue, 03 Oct 2000 12:57:59 -0400,
Andrew Pearce <pearce@aw.sgi.com> wrote:
> Martien Verbruggen wrote:
>
> > # perl
> > @a = qw (foo bar baz banana);
> > foreach $ae (@a)
> > {
> > push @{$hash{bleb}}, $ae;
> > }
> > print "@{$hash{bleb}}\n";
> > __END__
> > foo bar baz banana
>
> Change this slightly and it will not work on your Perl too:
>
> @a = qw (foo bar baz banana);
> dbmopen( %hash, "test", 0666);
> foreach $ae (@a)
> {
> push @{$hash{bleb}}, $ae;
> }
> print "@{$hash{bleb}}\n";
> __END__
> bar baz banana
Just to show you that it isn't inherent in all tied modes, but
probably just the dbmopen stuff:
# cat foo
#!/usr/local/bin/perl -w
use Tie::Hash;
@a = qw (foo bar baz banana);
tie %hash, "Tie::StdHash";
foreach $ae (@a)
{
push @{$hash{bleb}}, $ae;
}
print "@{$hash{bleb}}\n";
# ./foo
foo bar baz banana
#
Martien
--
Martien Verbruggen |
Interactive Media Division | If at first you don't succeed, try
Commercial Dynamics Pty. Ltd. | again. Then quit; there's no use
NSW, Australia | being a damn fool about it.
------------------------------
Date: Tue, 03 Oct 2000 16:30:32 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: help: FORCE perl to evaluate arithmetic string
Message-Id: <39DA6C18.5154D3B1@stomp.stomp.tokyo>
ruzbehgonda@my-deja.com wrote:
> after building an arithmetic expression dynamically
> eg. $arith = ( (1 * 0) + 1) + 1
> i need perl to evaluate for the results...
> perl treats this as another string
> because of the operators and parenthesis and does
> not cast the string...
> how can i do this?
I have read some articles within this thread,
with humored interest. I also posted a clear
answer. Still, I am most curious. Why would
you "force" perl core to evaluate a mathematical
expression which is self-evaluating?
"Arithmetical" expressions automatically evaluate.
Godzilla!
------------------------------
Date: Tue, 03 Oct 2000 18:49:29 -0400
From: =?iso-8859-1?Q?F=E9lix?= Gourdeau <felix.gourdeau@videotron.ca>
Subject: MATH problem
Message-Id: <39DA6279.C92D1599@videotron.ca>
Hello
I need a subroutine or a module that accept a long mathematical
operation like this:
$input =3D '3+4**5-6*7+(4-5)/4-2';
and output the result. I know its possible to do this using complicated
regex but i don't how !
I you know how please send me the source by email at:
felix.gourdeau@videotron.ca
Thanx in advance.
F=E9lix Gourdeau
------------------------------
Date: Tue, 3 Oct 2000 16:03:00 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: MATH problem
Message-Id: <MPG.1444058446c8558a98ae00@nntp.hpl.hp.com>
[Posted and a courtesy copy mailed.]
In article <39DA6279.C92D1599@videotron.ca> on Tue, 03 Oct 2000 18:49:29
-0400, =?iso-8859-1?Q?F=E9lix?= Gourdeau <felix.gourdeau@videotron.ca>
says...
> Hello
>
> I need a subroutine or a module that accept a long mathematical
> operation like this:
> $input =3D '3+4**5-6*7+(4-5)/4-2';
>
> and output the result. I know its possible to do this using complicated
> regex but i don't how !
How odd. That is the second time this question has been asked today. I
guess you didn't follow netiquette by reading even one day's worth of
this newsgroup before posting.
Subject: force arithmetic interpretation
From: ruzbehgonda@my-deja.com
Newsgroups: comp.lang.perl.misc
after dynamically building an arithmetic
expression
such as
$arith = ( (1 * 0) + 1) + 1
how can i force perl to evaulate the results??
assigning it to another variable :
$results = $arith + 1;
does not work
thanks,
ruzbeh
> I you know how please send me the source by email at:
> felix.gourdeau@videotron.ca
I'll mail you this. Look up the thread yourself, to find the answer,
which is a word of four letters (no, not THAT one! :-).
> Thanx in advance.
> F=E9lix Gourdeau
Yeah, yeah.
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Tue, 03 Oct 2000 23:08:08 GMT
From: mgjv@verbruggen.comdyn.com.au (Martien Verbruggen)
Subject: Re: MATH problem
Message-Id: <slrn8tkpmm.64u.mgjv@verbruggen.comdyn.com.au>
On Tue, 03 Oct 2000 18:49:29 -0400,
Félix Gourdeau <felix.gourdeau@videotron.ca> wrote:
> Hello
>
> I need a subroutine or a module that accept a long mathematical
> operation like this:
> $input = '3+4**5-6*7+(4-5)/4-2';
>
> and output the result.
# perl
$input = '3+4**5-6*7+(4-5)/4-2';
$output = eval $input;
print "$input => $output\n";
__END__
3+4**5-6*7+(4-5)/4-2 => 982.75
# perldoc -f eval
Martien
--
Martien Verbruggen |
Interactive Media Division | If at first you don't succeed,
Commercial Dynamics Pty. Ltd. | destroy all evidence that you tried.
NSW, Australia |
------------------------------
Date: Wed, 4 Oct 2000 09:49:37 +1000
From: jason <elephant@squirrelgroup.com>
Subject: Re: multiple word command line arg
Message-Id: <MPG.14451b98b5602b339897e7@localhost>
rathi_sk wrote ..
>i am new to perl. I was parsing command line args with GetOptions()
>(use Getopt:Long;).
>
>GetOptions("instType=s" => \$instType,
> "euro" => \$euro,
> "country:s" => \$country);
>
>now when i call the script
>
>perl /export/home/dd/bin/refresh.pl --instType "dummy one" --euro --
>country US
>
>It treates the instType as "dummy.
>
>When i tried
>perl /export/home/dd/bin/refresh.pl --instType 'dummy one' --euro --
>country US
>
>It gives instType as 'dummy.
it would seem that for some reason neither ' or " are being treated as
delimiters by your shell .. judging by the delimiters you're on UNIX of
some sort - and yet you're not using a shebang line - what shell are you
using ?
try running it under Bash if that's available to you - and see if that
solves your problem .. if Bash fixes it - then you're asking the
question to the wrong people - read your shell documentation
--
jason -- elephant@squirrelgroup.com --
------------------------------
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 4511
**************************************