[8310] in Perl-Users-Digest
Perl-Users Digest, Issue: 1927 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Feb 18 23:07:22 1998
Date: Wed, 18 Feb 98 20:00:39 -0800
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Wed, 18 Feb 1998 Volume: 8 Number: 1927
Today's topics:
Re: ANNOUNCE: IndexMaker 4.1: an index.html maker from (Martien Verbruggen)
attach file to mailmessage using sendmail (Penta_internEtional)
Re: books or anything <Chatjack@earthling.net>
Re: Building PERL message board (Bob Weissman)
Re: Content-type Question (Martien Verbruggen)
Re: Displaying Integers <dean@tbone.biol.sc.edu>
Re: Displaying Integers (John Klassa)
Re: Displaying Integers <webmaster@fccj.cc.fl.us>
Re: Displaying Integers <shimpei+usenet+.mil+.gov@BOFH.patnet.caltech.edu>
Re: FS:CDs (Martien Verbruggen)
Re: Handlers (Martien Verbruggen)
Re: hash data access (Martien Verbruggen)
Help for Hashes !! <tthomas@chubb.com>
Re: Help using MacPerl please. (John Moreno)
Re: HELP! My ISP claims that Perl access is a serious <rjk@coos.dartmouth.edu>
Re: HTTP header control references (Martien Verbruggen)
Re: HTTP_USER_AGENT List? <webmaster@fccj.cc.fl.us>
Re: Is there a GOOD Perl Tutorial Online? <cybercom@pacific.net.sg>
keys and out of memory problems with large associative <rpb@genesis.co.nz>
modulus (again!) <franzen@pmel.noaa.gov>
Re: Newbie question: script directory (Martien Verbruggen)
Re: Newbie question: script directory (Martien Verbruggen)
Re: Opinions about SWIG? <ldanna@hotmail.com>
padding a format line? <prl2@lehigh.edu>
Re: padding a format line? (Andrew M. Langmead)
Re: Perl on Win95 - "system" not working (Jonathan Feinberg)
Re: Perl <mishra.aditya@emeryworld.com>
Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 18 Feb 1998 23:39:05 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: ANNOUNCE: IndexMaker 4.1: an index.html maker from PDF,HTML,VRML and other files
Message-Id: <6cfrep$kk0$5@comdyn.comdyn.com.au>
In article <admin1-ya02408000R1802980103330001@news.winternet.com>,
admin1@ShadowMAC.org (ShadowMAC Administrator) writes:
> Learn from Microsloth, people who say military intelligence is a
> contridiction in terms obviously have never dealt with Microsloth. But
err.. How does dealing with Microsoft alter the meaning or content of
the statement 'Military intelligence is a contradiction in terms'?
> Not saying that Netscape doesn't need to learn some elementary lessons
> either, but to use MS as an example is really low!
I think you missed the intent of the statement.
Abigail said:
>> I'd rather go to Microsoft to learn about Perl and Unix than
>> to Netscape to learn about HTML.
I think that she meant it to be equivalent to something like:
"I'd rather stick a hot poker in my eye than shake Bill's hand."
In other words: Both are bad. One is slightly less bad, possibly.
Martien
--
Martien Verbruggen |
Webmaster www.tradingpost.com.au | If it isn't broken, it doesn't have
Commercial Dynamics Pty. Ltd. | enough features yet.
NSW, Australia |
------------------------------
Date: Wed, 18 Feb 1998 23:00:52 GMT
From: penta@knoware.nl (Penta_internEtional)
Subject: attach file to mailmessage using sendmail
Message-Id: <887842872.322825@news.knoware.nl>
Hi,
I want to send an email message using PERL, using the function
sendmail. This I can do. But, I want to attach a message within the
mail message. This I can't do. Can someone help me?
Here's the script I have. This one does not attach a file. How to
attach a file?
#!/usr/bin/perl -w
$debug = 0; # set to 1 fo rdebug
$sendmsg = 1; # set to 0 to print instead of mail
#
# attmail.pl - Attach file to email script
#
# copyright 1996,7 by $Bill Luebkert; dbe@wgn.net
# you may use/modify freely with this header intact
# no guarantees are made as to the efficacy of this code and user
accepts
# responsibility for an damage caused by his/her use of this code
#
#----main----------------------------------------------------------------------
&initialize_variables ();
&acquire_the_attachment ();
&encode_the_attachment ();
&build_final_message ();
&send_the_email ();
#------------------------------------------------------------------------------
sub initialize_variables () {
$from = $mailto = 'penta\@knoware.nl';
$subject = "That JPEG you wanted";
$mailer = '/usr/lib/sendmail';
$boundary = "<-UnIqUe bOuNdArY->";
# the image
$imageconttype = "image/jpeg";
# $imagepath = "../../jpg";
$imagename = "test.jpg";
# the optional pre message
$premsg = "";
# the message
$msg = <<EOD;
Here is that JPEG you wanted Jane, just save it from
your mail reader by right clicking on the image.
EOD
}
#------------------------------------------------------------------------------
sub acquire_the_attachment () {
# get the image
print "Getting image $imagename\n" if $debug;
open (IMAGE, "$imagename") or die "Error opening $imagename: $!\n";
binmode (IMAGE);
undef $/; $rawimage = <IMAGE>; $/ = "\n";
close IMAGE;
}
#------------------------------------------------------------------------------
sub encode_the_attachment () {
# encode the image
print "Encoding image\n" if $debug;
$b64image = &encode_base64 ($rawimage);
chomp $b64image;
}
#------------------------------------------------------------------------------
sub build_final_message () {
# the full mime message
print "Building mime message\n" if $debug;
$mime_msg = <<EOD; # keep the blank lines after content headers
To: $mailto
From: $from
Subject: $subject
Cc: penta\@knoware.nl
Bcc: penta\@knoware.nl
Content-Type: multipart/mixed; boundary="$boundary"
$premsg
--$boundary
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
$msg
--$boundary
Content-Type: $imageconttype; name="$imagename"
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="$imagename"
$b64image
--$boundary--
EOD
}
#------------------------------------------------------------------------------
sub send_the_email () {
# send the email
if ($sendmsg) {
print "Sending mime message\n" if $debug;
open (MAIL, "|$mailer -t -oi") or die "Error mailing email:
\$!\n";
select MAIL;
print $mime_msg;
close (MAIL);
select STDOUT;
} else {
print "Printing mime message:\n\n" if $debug;
print $mime_msg;
}
}
#------------------------------------------------------------------------------
sub encode_base64 ($;$) {
my $res = "";
my $eol = $_[1];
$eol = "\n" unless defined $eol;
while ($_[0] =~ /(.{1,45})/gs) {
$res .= substr (pack ('u', $1), 1);
chomp ($res);
}
$res =~ tr|` -_|AA-Za-z0-9+/|; # `# help emacs
my $padding = (3 - length($_[0]) % 3) % 3;
$res =~ s/.{$padding}$/'=' x $padding/e if $padding;
if (length $eol) {
$res =~ s/(.{1,76})/$1$eol/g;
}
$res;
}
#------------------------------------------------------------------------------
__END__
------------------------------
Date: Thu, 19 Feb 1998 10:06:11 +1100
From: "ChatJack" <Chatjack@earthling.net>
Subject: Re: books or anything
Message-Id: <6cfpdl$dpf$1@arachne.labyrinth.net.au>
G'day mates,
You guys are unreal.!! Thank you very much for all your help/s as I do
appreciate it.
Happy Netting!
Best regards
Joe
------------------------------
Date: Thu, 19 Feb 1998 00:27:03 GMT
From: weissman@netcom.com (Bob Weissman)
Subject: Re: Building PERL message board
Message-Id: <weissmanEoLnx4.It6@netcom.com>
For a small internal organization, news can be overkill.
On a public site where you either don't have privileges (e.g., on an
ISP) or you just don't want system administration hassles, having users
log in to read news is not an option.
There's a very nice free Perl-based message board called HyperNews
already written and debugged. Visit www.hypernews.org for info.
== Bob
In article <34E6680C.389B9FD3@fccj.cc.fl.us> you write:
>I have to agree with Tom this time - scary, huh?
>
>News Servers and newsfeeds are cheap - storing a longterm feed is where it
>gets expensive. But, in the long term, better than trying to do it/maintain
>it yourself.
>
>Tom Christiansen wrote:
>
>> In comp.lang.perl.misc, junk@spanky.tamu.edu writes:
>> :I am creating a message board and I am looking for any help I can get on
>> :the code. If anyone has any suggestions or warnings any help would be
>> :appreeciated.
>>
>> I suggest you install a newsserver, and keep a local spool. Anything else
>> is too much work, and fairly silly. The Internet has catupulted even
>> the Wintel victims past the days of BBS toys.
>>
------------------------------
Date: 18 Feb 1998 23:43:16 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: Content-type Question
Message-Id: <6cfrmk$kk0$6@comdyn.comdyn.com.au>
In article <6ce4c0$at2@ecuador.earthlink.net>,
"Bill White" <pixndix@earthlink.net> writes:
> I'm reading a good book by Selena Sol and others, and trying to learn Perl,
> but something doesn't seem to be right and I was wondering if it's because
> I'm testing the scripts out with Microsoft's Personal Web Server, instead of
> a unix-type server, or even IIS. Here it is:
Probably. But that is not a perl question, it's a question about that
server.
> On all the book's scripts there's this:
> --------------------------------------------------------------
>
> # Print the header required for all CGI scripts that output dynamic text
> data
>
> print "Content-type: text/plain\n\n";
The book is right. CGI scripts have to output a Content-type header.
But that is not a perl question, but a CGI question.
> And, if I delete the command from the script, the script still apears to
> work perfectly, even though the comment above states "header 'required' for
> all CGI scripts that output dynamic text data". So, I'm getting the
> impression that it's not really required.
That is the wrong impression. CGI scripts have to output a
Content-type header. But that is not a perl question, but a CGI question.
You should send this post to one of the comp.infosystems.www.* groups,
where they talk about things that have to do with the WWW, CGI, HTTP,
HTTP servers, JavaScript, HTML, XML, and all that stuff.
We talk about perl, and about the demise of this group. Oh, and some
people talk about growing cucumbers.
Martien
--
Martien Verbruggen |
Webmaster www.tradingpost.com.au | A Freudian slip is when you say one
Commercial Dynamics Pty. Ltd. | thing but mean your mother.
NSW, Australia |
------------------------------
Date: 18 Feb 1998 17:50:17 -0500
From: Dean Pentcheff <dean@tbone.biol.sc.edu>
Subject: Re: Displaying Integers
Message-Id: <87lnv8mst2.fsf@tbone.biol.sc.edu>
As the saying goes... I am not believing this (see quotes below). The
suggested solutions are badly inelegant. In this case, elegance (to
me) would come from using a built-in language function that achieves
the desired goal, and will not break when stressed. Stress could
include negative numbers, numbers with more than two digits, or reals.
Check the printf function. To whit, play with the following:
perl -e 'printf "%02d\n", $_ while (<>)'
-Dean
--
N. Dean Pentcheff <help@biol.sc.edu>
Biological Sciences, Univ. of South Carolina, Columbia SC 29208 (803-777-3936)
Holly Sommer <SNIPhsommer@micro.ti.comSNIP> writes:
Ovanes Manucharyan wrote:
: I have a quick question. How can I force an integer to print with 2
: digits, instead of one.
: Lets say I have numbers 0, 1, 3, 14.. How can I make them print
: 00, 01, 03, 14
if ($number < 10) {
print "0$number";
} else {
print $number;
}
This works if you KNOW the number isn't a string with a 0 in front
of it... if it is a string with a zero, just change the if statement:
if ($number < 10 && $number !~ /^0/ )
-Holly
James Ludlow <ludlow@us.ibm.com> writes:
...
#!/usr/bin/perl -w
$integer = 5; # or whatever
print &add_zero($integer); # Either prints "0" or ""
print $integer; # prints your integer
sub add_zero {
my($number) = @_;
if ($number < 10) {
return "0";
}
else {
return "";
}
}
------------------------------
Date: 18 Feb 1998 21:07:43 GMT
From: klassa@aursgh.aur.alcatel.com (John Klassa)
Subject: Re: Displaying Integers
Message-Id: <6cfiiv$5c7$1@aurwww.aur.alcatel.com>
On Wed, 18 Feb 1998, Ovanes Manucharyan <olm@mail1.csun.edu> wrote:
->Lets say I have numbers 0, 1, 3, 14.. How can I make them print 00,
->01, 03, 14 Any reference would be appreciated.
How about "perldoc -f printf".
--
John Klassa / Alcatel Telecom / Raleigh, NC, USA <><
------------------------------
Date: Wed, 18 Feb 1998 18:53:10 -0500
From: Bill Jones <webmaster@fccj.cc.fl.us>
To: olm@mail1.csun.edu
Subject: Re: Displaying Integers
Message-Id: <34EB7465.4C1E7331@fccj.cc.fl.us>
[Mailed and posted...]
See perldoc -f format (requires Perl 5.004...)
=item format
Declare a picture format with use by the write() function. For
example:
format Something =
Test: @<<<<<<<< @||||| @>>>>>
$str, $%, '$' . int($num)
.
$str = "widget";
$num = $cost/$quantity;
$~ = 'Something';
write;
See 'perlform' for many details and examples.
Or, more to the point -
(length($x) > 1) ? print $x : print "0$x";
A freebie by,
Sneex :-)
Ovanes Manucharyan wrote:
> I have a quick question. How can I force an integer to print with 2
> digits, instead of one.
> Lets say I have numbers 0, 1, 3, 14.. How can I make them print 00,
> 01, 03, 14
>
> Any reference would be appreciated.
>
> --
> ----------------------------------------------------
> Ovanes Manucharyan olm@csun.edu
> California State University, Northridge
> ----------------------------------------------------
------------------------------
Date: 19 Feb 1998 00:37:43 GMT
From: Shimpei Yamashita <shimpei+usenet+.mil+.gov@BOFH.patnet.caltech.edu>
Subject: Re: Displaying Integers
Message-Id: <6cfusn$8bo@gap.cco.caltech.edu>
Holly Sommer <SNIPhsommer@micro.ti.comSNIP> writes:
>
>Ovanes Manucharyan wrote:
>
>: I have a quick question. How can I force an integer to print with 2
>: digits, instead of one.
>: Lets say I have numbers 0, 1, 3, 14.. How can I make them print
>: 00, 01, 03, 14
>
>if ($number < 10) {
> print "0$number";
>} else {
> print $number;
>}
>
>This works if you KNOW the number isn't a string with a 0 in front
>of it... if it is a string with a zero, just change the if statement:
>
>if ($number < 10 && $number !~ /^0/ )
Of course, as long as you are being paranoid, you should also worry
about whether the number is negative, too. '0-34' is not a very pretty
output.
I'm surprised no one has suggested the easiest solution yet.
printf "%02d\n", $number;
If you don't like the fact that it prints -3 instead of -03, then
use
printf "%.02d\n", $number;
instead.
--
Shimpei Yamashita <http://www.patnet.caltech.edu/%7Eshimpei/>
perl -w -e '$_="not a perl hacker\n"; $q=qq;(.);x9;$qq=qq;345123h896789,;;
$s=pack"H6","6a7573";$qq=qq;s,^$q,$s$qq;;$qq=~s;(\d);\$$1;g;eval$qq;print;'
------------------------------
Date: 18 Feb 1998 23:22:57 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: FS:CDs
Message-Id: <6cfqgh$kk0$3@comdyn.comdyn.com.au>
In article <6cdcbe$sig$1@nnrp2.dejanews.com>,
unreal@goplay.com writes:
> Hi,I have for sale much cracked CDs for PC.So let
> me know if you interested...
I doubt very much that they would work here in Australia. Since the
Coriolis force works the other way around than on the Northern
Hemispere, We run into these problems all the time. Someone once
suggested that covering them in Vegemite would solve the problem, but
I never tried that myself. I have heard some good results with that
though.
Another advantage of covering them with Vegemite would be that it
would fill the cracks, which would increase the quality of your CDs.
So, unless you can also provide me with a jar of Vegemite, I'd prefer
it if you took your post, and put it somewhere nice and safe and dark.
Martien
PS. Where did you get the idea to crosspost this message to a
bunch of groups where programmers tend to hang out. The same
programmers that you are robbing. I am genuinely interested
in the warped way of thinking that you display.
--
Martien Verbruggen |
Webmaster www.tradingpost.com.au | Make it idiot proof and someone will
Commercial Dynamics Pty. Ltd. | make a better idiot.
NSW, Australia |
------------------------------
Date: 18 Feb 1998 23:58:00 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: Handlers
Message-Id: <6cfsi8$kk0$9@comdyn.comdyn.com.au>
In article <34EAFF54.85F0F49E@abbott.com>,
Doug Brown <Doug.Brown@abbott.com> writes:
> This message is directed to tchrist. Do you set up a handler
> immediately before executing code? Why did you include a reference to
> the handler inside the REAPER function as well as inside the
> service_clients function?
If you have a question for Tom Christiansen, you should email him
directly. You would most likely get an automatic amswer informing you
of a few things.
It's very rude to post to a newsgroup if you only want to talk to one
person.
Martien
--
Martien Verbruggen |
Webmaster www.tradingpost.com.au | For heaven's sake, don't TRY to be
Commercial Dynamics Pty. Ltd. | cynical. It's perfectly easy to be
NSW, Australia | cynical.
------------------------------
Date: 18 Feb 1998 23:14:36 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: hash data access
Message-Id: <6cfq0s$kk0$2@comdyn.comdyn.com.au>
In article <34EB08AD.3FF21909@shopcfn.com>,
Dan Boorstein <dboorstein@shopcfn.com> writes:
> did you try it without the quotes? it compiles for me without
> warning. try 'print $xyz{a}' and see what you get. "a => a"
> compiles with a warning.
Not with
use strict;
which is a very, very, very recommendable part of any perl program.
Martien
--
Martien Verbruggen |
Webmaster www.tradingpost.com.au | You can't have everything, where would
Commercial Dynamics Pty. Ltd. | you put it?
NSW, Australia |
------------------------------
Date: Wed, 18 Feb 1998 17:45:06 -0500
From: Tod Thomas <tthomas@chubb.com>
Subject: Help for Hashes !!
Message-Id: <34EB6472.BAF870F7@chubb.com>
I have two ascii files both of which have a userid that I can use as a
key. In two separate subroutines I load each of the files into an
associative array with the userid as the key value. After loading each
hash I then run a foreach loop getting the $key and $value from the
first hash and then do a lookup in the second hash with $key - it
doesn't work. I have tried using exist and it doesn't work either.
Can I use the key valued with - foreach $userid (key %AssociativeArray)
- to determine if an entry in another hash exists; like if
(exists($AssociativeArray{$userid})) ?? If anybody has used a key from
one hash to search another or can otherwise help I would really
appreciate it.
Thanks - Tod Thomas
------------------------------
Date: Wed, 18 Feb 1998 00:30:16 -0500
From: phenix@interpath.com (John Moreno)
Subject: Re: Help using MacPerl please.
Message-Id: <3B700A99A69D29CC.C9F92B11635DCB84.EF81934A218430A0@library-proxy.airnews.net>
d shahin <dshahin@bayarea.net> wrote:
> Where is a good place to look for help using Mac Perl?
>
> Just a couple bonehead questions:
>
> 1 how do I access the file structure of my mac?
What do you mean - do you mean how do you move around the directory
tree? If so - in the same manner as on unix boxes.
> 2 What is the root directory called?
The root directory will be the directory MacPerl is in.
> 3 Can I test my scripts written on the SUNs at my work and vice-versa?
Assuming that you know about the difference in path names ":" instead of
"/" and don't use any mac specific commands, yeah.
--
John Moreno
------------------------------
Date: Wed, 18 Feb 1998 00:32:06 -0500
From: Chipmunk <rjk@coos.dartmouth.edu>
Subject: Re: HELP! My ISP claims that Perl access is a serious security risk!
Message-Id: <34EA7257.E57D37A8@coos.dartmouth.edu>
Troy Denkinger wrote:
>
> Do you guys really think the ISP in this case was
> over-the-top in requesting that those with access to the
> Perl interpreter (or other cool tools) pay attention to the
> security of their accounts? I'm of the opinion that
> everyone should be required to exercise some basic security
> procedures on their accounts, but that's probably out of the
> question.
In your first response, you quoted part of the ISP sysadmin's response out of
context in order to defend him. If you go back and read the original message,
you will notice that the sysadmin does *not* offer to give Perl access if the
user will be responsible for his account. The sysadmin says that such a
policy "seems possible". Earlier in the message, the admin clearly states,
"At the moment, we only allow perl/compiler access to our webserver accounts,
and then only if they ask for it."
Note that the original poster is trying get Perl access for his shell account,
not for a webserver account. So, he is currently being denied access to Perl entirely.
I agree with those who suggested a change of ISP.
--
_ / ' _ / rjk@coos.dartmouth.edu
( /)//)//)(//)/( chipmunk@m-net.arbornet.org
/ http://www.ziplink.net/~rjk/
------------------------------
Date: 19 Feb 1998 00:12:25 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: HTTP header control references
Message-Id: <6cftd9$kk0$12@comdyn.comdyn.com.au>
In article <34eb384e.0@poobah.olywa.net>,
chigh@vallier.com (Cliff High) writes:
> see hethmon's book on http at
> http://www.manning.com/hethmon/311.html
Why? I don't think he can tell me anything new about it. Besides, what
does it have to do with perl?
--
Martien Verbruggen |
Webmaster www.tradingpost.com.au | You can't have everything, where would
Commercial Dynamics Pty. Ltd. | you put it?
NSW, Australia |
------------------------------
Date: Wed, 18 Feb 1998 18:43:47 -0500
From: Bill Jones <webmaster@fccj.cc.fl.us>
Subject: Re: HTTP_USER_AGENT List?
Message-Id: <34EB7232.2B0D3548@fccj.cc.fl.us>
Using CGI.pm you could write your own and log the results...
Heck, I've even seen the 'Sony Playstation' User_Agent...
HTH,
Bill
Chester Bullock wrote:
> Some time back I recall seeing a list of all possibilities (or at least
> the majority of possibilities) for HTTP_USER_AGENT values. Does anyone
> know if such a list still exists?
>
> TIA
> --
------------------------------
Date: Thu, 19 Feb 1998 07:41:36 +0800
From: "Ho Seng Yip" <cybercom@pacific.net.sg>
Subject: Re: Is there a GOOD Perl Tutorial Online?
Message-Id: <6cfs5d$cd0$1@newton.pacific.net.sg>
Hi Heng Wah,
You can try http://reference.perl.com . Lots of goodies over there. ;-)
Regards,
Seng Yip
Heng Wah wrote in message <01bd3bb1$95219c60$1d13bcca@heng7.tm.net.my>...
>I am new to Perl.
>Is there a GOOD Perl tutorial Online ?
------------------------------
Date: Thu, 19 Feb 1998 12:26:46 +1300
From: "Paul Bickerstaff" <rpb@genesis.co.nz>
Subject: keys and out of memory problems with large associative arrays
Message-Id: <6cfqni$get$1@aknews1.netlink.net.nz>
I have encountered a problem with large associative arrays that I don't
understand. I am appending a script which illustrates the behaviour in
question.
Basically, I create a large associative array with of the order of 200,000
entries which I then want to sort and print. (In my real world application,
an associative array is a neat way of eliminating duplicates but the script
below just generates a simple case.) The
keys in this array are quite large but the associative array is NOT
tied to a dbm database so I don't see any problem with that.
There is no problem in constructing this array on my machine,
and printing it out shows that its size is of the order of 30MB.
However, the problem occurs when I try and do something like
keys %assoc_array. Naively I would expect this to (roughly)
duplicate the storage needed. However, it bombs with an
"Out of memory!" message. Now I know this is a big array but
my machine has 1 GB of RAM and 5 GB of swap so I expect
it to be able to cope. Not so.
Why does the keys function behave in this way? What is happening
to cause this failure? (I'm by no means convinced that it really is running
out of memory, unless it's just memory that it thinks it may need, as
monitoring indicates memory is still available.) Pre-extending the keys
array didn't seem to change things much.
Note that the script works fine if the array size is reduced a little. On
the machine referred to above it fails somewhere between 212,000
and 213,000 keys for the test script below. The failure point is less
on lesser machines and is related to the size of the key values but
the real problem seems not to be with the machines but with the way
Perl handles the keys function.
I'm not really interested in a workaround (unless it's particularly
brilliant) as I can invent one myself. What I want to understand is,
why is Perl apparently so limited on this point? What am I missing
here? Can Perl be made more robust?
I'm using Perl5.004_4 though the problem occurs also in earlier
versions (and versions of 5.004_4 built with different malloc and
optimization selections). I've tested the script under OSF1 v 4.0C
and Solaris 2.5.1.
Paul Bickerstaff (rpb@genesis.co.nz)
--------------------save file below as
test-big.pl ----------------------------
#!/usr/local/bin/perl -w
#
# Script to test perl's handling of large associative arrays.
#
# The script prints a line to standard output indicating
# completion of each stage of the testing.
#
# Usage:
# test-big.pl [big_number]
#
# (big_number is optional; it is the number of keys in the array;
# if big_number is not supplied the script defaults to 250000.)
#
# Warning:
# The script also prints a file called bigfile in the
# working directory. This file is appropriately named.
# (Its size depends on what you choose for the big_number
# on the command line, see above. The default size will be
# about 33.9 MB.)
#
# History:
# 19/02/98 -- written by Paul Bickerstaff (rpb@genesis.co.nz)
#
use diagnostics;
use strict;
# Initialization: choose size of associative array
my $size = 250000; # default size
if ($ARGV[0]) {
$size = $ARGV[0];
}
# Step 1) Create a big associative array with $size keys
my $pad = "*abcdefghijklmnopqrstuvwxyz" x 5;
my($longkey, %bigassoc);
for (my $i=0; $i < $size; $i++) {
$longkey = join('', $i, $pad);
$bigassoc{substr($longkey, 0, 128)} = $i;
}
print "Step 1: Associative array with $size keys has been constructed.\n";
sub dumpfile {
open(FILE, ">bigfile");
while (my ($key, $val) = each %bigassoc)
print FILE "$key $val\n";
}
}
# Uncomment next line if you want to check on what is going on.
# Be warned though that the file produced may be 10s of MB in size.
#&dumpfile;
# Now test ability to manipulate associative array.
# Step 2) See if keys function works:
my @keysarray = keys %bigassoc;
print "Step 2: Keys array with last index $#keysarray has been
constructed.\n";
undef @keysarray; # get rid of it so as to recover memory
# Step 3) Now see if it can be sorted:
# Note that the extraction of elements from an associative array
# does not yield them in any particular order so we do real work
# here.
open(FILE, ">bigfile");
foreach $longkey (sort byval keys %bigassoc) {
print FILE "$longkey\n";
}
sub byval {
$bigassoc{$a} <=> $bigassoc{$b} ;
}
sub bykey {
# not same order as byval routine!
$a cmp $b;
}
print "Step 3: Array sorted. Hurray! (Check results in bigfile.)\n";
------------------------------
Date: Wed, 18 Feb 1998 14:58:29 -0800
From: Nathan Franzen <franzen@pmel.noaa.gov>
Subject: modulus (again!)
Message-Id: <Pine.SOL.3.96.980218144636.6397C-100000@corona.pmel.noaa.gov>
A couple weeks ago I asked some questions here regarding modulus and got
some very useful replies from Chip Salzenberg, among others, and
discovered that some important fixes were made in the latest release of
Perl.
I have, to my misfortune, still been puttering around with with %, and
discovered that even under 5.004 it behaves differently with and without
'use integer'.
It's not clear to me why this would be intended, but if you can assure me
that it is meant to be so, I can accept it. After all, there's more than
one way &c.
Here are perl -e examples (quoted for VMS):
-------
franzen> perl -e "$x=-400;$x %= 1000; print qq{$x \n};"
600
franzen> perl -e "use integer;$x=-400;$x %= 1000; print qq{$x \n};"
-400
franzen> perl -V
This is perl, version 5.004_04 built for VMS_AXP /**/
Copyright 1987-1997, Larry Wall
Perl may be copied only under the terms of either the Artistic License or
the GNU General Public License, which may be found in the Perl 5.0 source
kit.
--------
------------------------------
Date: 19 Feb 1998 00:09:14 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: Newbie question: script directory
Message-Id: <6cft7a$kk0$11@comdyn.comdyn.com.au>
Another place to look:
perldoc perlfaq
/How do I add the directory my program lives in
Martien
--
Martien Verbruggen |
Webmaster www.tradingpost.com.au | Very funny Scotty, now beam down my
Commercial Dynamics Pty. Ltd. | clothes.
NSW, Australia |
------------------------------
Date: 19 Feb 1998 00:06:28 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: Newbie question: script directory
Message-Id: <6cft24$kk0$10@comdyn.comdyn.com.au>
In article <34EB680B.49BF@world.std.com>,
John O'Brien <jobrien@world.std.com> writes:
> Almost. If the script is an executable someplace on my $PATH, I want
> to know the directory it is executing out of, not the current directory.
>
> John
I think you're confused about some terminology here. Your script is
executing in the current working directory. What you seem to want to
know is in which directory the sources of your script are stored,
right?
This question has come up not too long ago, on this very group. A
dejanews search
http://www.dejanews.com
(~g comp.lang.perl.misc) & current & directory
Would have provided you with a few answers, and cautions.
Try it now.
Martien
--
Martien Verbruggen |
Webmaster www.tradingpost.com.au | We are born naked, wet and hungry. Then
Commercial Dynamics Pty. Ltd. | things get worse.
NSW, Australia |
------------------------------
Date: Wed, 18 Feb 1998 18:18:40 -0500
From: Larry D'Anna <ldanna@hotmail.com>
Subject: Re: Opinions about SWIG?
Message-Id: <34EB6C50.CE07761F@hotmail.com>
Stuart McDow wrote:
>
> Howdy!!
>
> I downloaded SWIG after reading about it in TPJ. I like it. The
> interface is really clean and I like the fact that you can use legacy
> code (provided that it's well-behaved). In fact, I've already used
> SWIG to make a module that twiddles bits on a DSP board. (HP-UX.9).
>
> Question: Is there any advantages or disadvantages to using SWIG over
> plain old XSUBs? I find SWIG much, much cleaner to use.
>
> Opinions, please.
>
some perl specific stuff is more difficult to do in SWIG, because
it was designed to work with various other languages as well.
--
Larry D'Anna ldanna@hotmail.com
"eschew obfuscation"
Democracy is the worst system of government.
Except for all the others
-Winston Churchill
------------------------------
Date: Wed, 18 Feb 1998 17:27:01 -0500
From: "Phil R Lawrence" <prl2@lehigh.edu>
Subject: padding a format line?
Message-Id: <6cfn7n$ies@fidoii.cc.Lehigh.EDU>
I am using a format statement to output a space delimited text file.
However, some of the final variables are null and thus the \n ocurs way
before I want it to. How may I pad the format-ed line with spaces? Or must
I individually pad each variable based on its assigned size?
TIA,
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Phil R Lawrence phone: 610-758-3051
Programmer / Analyst e-mail: prl2@lehigh.edu
194 Lehigh University Computing Center
E.W. Fairchild - Martindale, Bldg. 8B
Bethlehem, PA 18018
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
------------------------------
Date: Thu, 19 Feb 1998 00:08:17 GMT
From: aml@world.std.com (Andrew M. Langmead)
Subject: Re: padding a format line?
Message-Id: <EoLn1t.Eww@world.std.com>
"Phil R Lawrence" <prl2@lehigh.edu> writes:
>I am using a format statement to output a space delimited text file.
>However, some of the final variables are null and thus the \n ocurs way
>before I want it to. How may I pad the format-ed line with spaces? Or must
>I individually pad each variable based on its assigned size?
Maybe you would be better of using unpack() with an "A" format
template or s?printf() to format your output.
--
Andrew Langmead
------------------------------
Date: Tue, 17 Feb 1998 22:29:14 -0500
From: jdf@pobox.com (Jonathan Feinberg)
Subject: Re: Perl on Win95 - "system" not working
Message-Id: <MPG.f541f97ab26b82d9896ee@news.concentric.net>
[courtesy cc of this posting sent to cited author via email]
sb67@dial.pipex.com said...
: Can anyone help me.
Yes? I can?
: I've downloaded the latest kit which is at release PERL 5.003_7 (build
: 315).
I'd recommend that you instead fetch Gurusamy Sarathy's Win32 Perl port, which
is much more up to date than what I'm assuming is the Activethingy port that
you've got. It also comes with a well-stocked module library.
(forgive my line-wrap--the following URL should be one line:)
http://www.perl.com/CPAN-local//authors/Gurusamy_Sarathy/perl5.00402-
bindist04-bc.tar.gz
: I have to run some dos commands and when I pass any switches the process
: hang my Pc. It looks like a bug but I cannot see any notes that suggest
: this does not work.
:
: Can anyone offer any workarounds or confirm that it does not work .
Contrary to what appears to be common belief, the "m" in "c.l.p.m" does not
stand for "mind-readers." Please grace us with brief but complete code
samples that don't work as expected. But first try GSAR's bindist.
--
#!/usr/bin/perl -w -- Just another Perl hacker,
(open 0),$_=<0>,s,.*-+ ,,,chop;for(split?@*?){($$_++or$}=$_,y,
y \,y,<STDIN>,,eval"sub $_ {print'$}'}"),y,} \,},>STDOUT,,&$_}
# Jonathan Feinberg jdf@pobox.com Sunny Brooklyn, NY
------------------------------
Date: Wed, 18 Feb 1998 15:34:05 -0800
From: "Mishra, Aditya" <mishra.aditya@emeryworld.com>
Subject: Re: Perl
Message-Id: <6cfp78$19hk@ljcqs003.cnf.com>
>The DSNs using SQL drivers were not displayed but all other DSNs using MS
Not all DBD's implement the data_sources method
To check this , try the following
perl -MDBI -e "print DBI->data_sources(ODBC);"
The resulting message should be self explanatory
Also try the following..
Assumptions
SQL SERVER client drivers installed on ur M$ box
Make sure you are using 32 bit drivers for SQL Server
DBD::ODBC is installed on your ur M$ box.
DBI is installed
A data source to a SQL server databse is setup on M$
......
Say the datasource is called JUNK, password is JUNK,user is JUNK
Try this
use DBI;
$dbh=DBI->connect('dbi:ODBC:JUNK','JUNK','JUNK','ODBC') || die "Could Not
connect bcos:".$DBI::errstr;
print STDOUT "You Should Be ok now\n";
Hope this helps
Adi
------------------------------
Date: 8 Mar 97 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 8 Mar 97)
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.misc (and this Digest), send your
article to perl-users@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.
The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq". The real FAQ, as it
appeared last in the newsgroup, can be retrieved with the request "send
perl-users FAQ". Due to their sizes, neither the Meta-FAQ nor the FAQ
are included in the digest.
The "mini-FAQ", which is an updated version of the Meta-FAQ, is
available by requesting "send perl-users mini-faq". It appears twice
weekly in the group, but is not distributed in the digest.
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 V8 Issue 1927
**************************************