[7000] in Perl-Users-Digest
Perl-Users Digest, Issue: 625 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Jun 17 18:17:27 1997
Date: Tue, 17 Jun 97 15:00:21 -0700
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Tue, 17 Jun 1997 Volume: 8 Number: 625
Today's topics:
Controlling "printf" Formatting from the Command Line (Kevin M Simonson)
Re: Debugging tutorial? <coke@adrenalin.com>
Re: dereferecing variables in another variable name (Tim Smith)
Re: elapsed time? (M.J.T. Guy)
File Permissions - 'nobody' can't open file <mha@dunraven.com>
Re: Help w/ Data Structures (Eric Finley)
HTML Doc Tags Missing? (Parillo)
Re: justa question... (Faust Gertz)
Re: justa question... (Faust Gertz)
Re: justa question... (Jason Costomiris)
Linux,glibc-2,perl-5.004_1: make test fails (Andreas Steffan)
Re: mod_perl or fastcgi install, liberl.so help.. (Michael Parson)
MS-DOS port of the Perl programming language @jumbo.com
Re: not printing (Lack Mr G M)
Re: Perl Reg Exp <usenet-tag@qz.little-neck.ny.us>
Re: PERL to Oracle <coke@adrenalin.com>
programming question <msda+@andrew.cmu.edu>
Re: Running out of memory in recursive subroutine (Ilya Zakharevich)
Re: Running out of memory in recursive subroutine (Tim Smith)
Re: Sockets (Henry Salvia)
Re: Sorting Associative Array? (Urgent) <jbokma@caiw.nl>
Re: TIMING EXPERIMENT <merlyn@stonehenge.com>
US- NC, GA, TX Permanent Positions (Kgikaren)
Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 17 Jun 1997 21:48:51 GMT
From: simonson@skopen.dseg.ti.com (Kevin M Simonson)
Subject: Controlling "printf" Formatting from the Command Line
Message-Id: <5o70o3$gdp@sf18.dseg.ti.com>
Keywords: printf format variable
What I would like to do is write a "perl" script that varies the for-
mat floating points are printed in, depending on what is entered on the
command line.
In C I can write a program that contains "printf" statements like the
following:
printf ("[%*d]\n", Length, Number);
This would cause <Number> to be printed out in a field that is <Length>
long (assuming, of course, that there is enough room for <Number> in that
field. Leading zeroes in that field would be filled with blanks.
This is kind of what I want in "perl" except that I would also like to
be able to control the number of decimal places that get printed. In par-
ticular, what I would like is a "perl" script written such that if I were
to execute "Space <length> <decimals> <float>", then what I would get would
be a line with square brackets around the number field in which <float>
would be displayed, have the number field be <length> long, have leading
zeroes replaced by blanks, and have <decimals> decimals be displayed.
For example, "Space 11 5 3.1415926535897932" would need to result in
[ 3.14159]
and "Space 17 14 3.1415926535897932" would need to result in
[ 3.14159265358979]
I tried to get this working with
,---Space-------------------------------------------------------------.
|#!/usr/local/bin/perl |
| |
|if ($#ARGV == 2) |
|{ $DecimalLine = sprintf ("[%*.*f]", $ARGV[0], $ARGV[1], $ARGV[2]); |
| print "$DecimalLine\n"; |
|} |
|else |
|{ print STDERR "Usage is\n Space <length> <decimals> <float>\n"; |
|} |
`---------------------------------------------------------------------'
but all I got when I executed it was
re^simonson/Pr} Space 17 14 3.1415926535897932
[.*f]
re^simonson/Pr}
Does anybody have any idea how I would go about doing this? Thanks in ad-
vance.
---Kevin Simonson
------------------------------
Date: 17 Jun 1997 17:24:56 GMT
From: "Chris Oke" <coke@adrenalin.com>
Subject: Re: Debugging tutorial?
Message-Id: <01bc7b43$8e62dbc0$371c9bcf@pc10.adrenalin.com>
http://www.panix.com/clay/perl/ has a section on debugging.
Chris
Michael Schuerig <uzs90z@uni-bonn.de> wrote in article
<199706170048551642226@rhrz-ts2-p4.rhrz.uni-bonn.de>...
>
> When debugging my scripts I usually resort to using print statements.
> Now, this has to change. Can anyone point me to a tutorial on using the
> debugger? The offerings of _Programming in Perl_ and perldebug are a bit
> too terse for me.
------------------------------
Date: 17 Jun 1997 13:38:06 -0700
From: trs@azstarnet.com (Tim Smith)
Subject: Re: dereferecing variables in another variable name
Message-Id: <5o6sje$81s@web.azstarnet.com>
In article <33A62AE0.12A4126F@cornell.edu>, <jknight@iname.com> wrote:
>I am trying to use a counter variable inside another var name to keep
>track of which vars belong with which section of a form.
John,
You're looking for symbolic references. Read the perlref man page, look
at the section on Symbolic references. It has several excellent examples
of what you're trying to do.
Tim
------------------------------
Date: 17 Jun 1997 17:55:35 GMT
From: mjtg@cus.cam.ac.uk (M.J.T. Guy)
Subject: Re: elapsed time?
Message-Id: <5o6j2n$cvn@lyra.csx.cam.ac.uk>
In article <33A6C60F.60A@nortel.ca>, Bob Lockie <bjlockie@nortel.ca> wrote:
>I want to find the elapsed time of my program.
>
>Why doesn't this work?
>
>It returned "20.11.40", there is no way it took 20 hours. :-)
>
>
>$tstart = time();
>
>&Process();
>
>$tend = time();
>
>$t = $tend - $tstart;
>@ct = localtime( $t );
>$t = $ct[2] . "." . $ct[1] . "." . $ct[0];
>print "It took $t\n";
I think you've been bitten by timezones. Your trick might work if you
used gmtime instead of localtime, but I'm not particularly confident.
Mike Guy
------------------------------
Date: Sat, 14 Jun 1997 15:04:54 -0700
From: Mission Hills Association <mha@dunraven.com>
Subject: File Permissions - 'nobody' can't open file
Message-Id: <33A31586.23AE@dunraven.com>
Hi -
I'm running a CGI script that needs to open a file and append data.
It works fine from the shell, but not when it's invoked from a
browser.
I think the problem must be that 'nobody' doesn't have permission
to create a file in the cgi-bin directory, or in my own (I've tried
both.)
Can someone let me know a good workaround?
-Puzzled in San Diego
------------------------------
Date: 17 Jun 1997 17:30:06 GMT
From: ez041407@boris.ucdavis.edu (Eric Finley)
Subject: Re: Help w/ Data Structures
Message-Id: <5o6hiu$340$1@mark.ucdavis.edu>
Thanks for all the help. I think I figured out what I need to do now and
how I can simplify my code.
Thanks,
Eric Finley
------------------------------
Date: 17 Jun 1997 21:33:14 GMT
From: lparillo@newshost.li.net (Parillo)
Subject: HTML Doc Tags Missing?
Message-Id: <5o6vqq$756@linet06.li.net>
I just downloaded the latest Perl from Activeware.
The HTML formatted docs no longer seem to have links from the perl.html
page. Is that the case in all docs? If not, can I download documentation
from another release without stepping on my Win32-specific docs?
------------------------------
Date: Tue, 17 Jun 1997 18:48:33 GMT
From: faust@wwa.com (Faust Gertz)
Subject: Re: justa question...
Message-Id: <33a8da27.981235@news.wwa.com>
On Mon, 16 Jun 1997 21:14:17 GMT, faust@wwa.com (Faust Gertz) wrote:
>if ($DATA{'Name'}=~ /[;><&\*`\|]/) {
> &return_error (500,'CGI Program Alert', "Value supplied for
>$DATA{'Name'} contains suspicious meta-characters. Please use your
>browsers' <CITE>back</CITE> function to return to the <A
>HREF=\"$ENV{'HTTP_REFERER'}\">form</A> and try again.");
But probably should have wrote something like:
if $value=~ /[;><&\*`\|]/) {
&return_error (500,'CGI Program Alert', "Value supplied for
$name contains suspicious meta-characters. Please use your
browsers' <CITE>back</CITE> function to return to the <A
HREF=\"$ENV{'HTTP_REFERER'}\">form</A> and try again.");
}
instead. Opps. Sorry. :-(
Streben nach Wahrheit
Faust Gertz
Philosopher at Large
"There are no honorable bargains involving the exchange of qualitative
merchandize like souls for quantitative merchandize like time or
money." - William S. Burroughs, `Words of Advice for Young People'
------------------------------
Date: Tue, 17 Jun 1997 19:28:03 GMT
From: faust@wwa.com (Faust Gertz)
Subject: Re: justa question...
Message-Id: <33a9de57.2047549@news.wwa.com>
heron> Will this bit of code utilize "GET" Methods?
jcostom> No. Please pick a better subject next time. It looks like
jcostom> you don't understand the difference between GET and
jcostom> POST either.
heron> And if this ISN'T the beginning of a "GET" Perl
heron> program, I would appreciate it if you would show me
heron> where one might be.
jcostom> #!/usr/bin/perl
jcostom>
jcostom> use CGI;
jcostom> $query = new CGI;
jcostom>
jcostom> There, that's the beginning. It will work, GET or POST.
If he doesn't understand the difference between GET and POST, what
makes you think he will be able to understand how to use the CGI
module? We don't even know if he has it installed. And if you were
going to bother to include the shebang line for him, why didn't you
include the "-w" and then "use strict;" for him as well? This kind of
help seems more likely to frustrate than aid.
Streben nach Wahrheit
Faust Gertz
Philosopher at Large
"Don't be mean. There's no need to be mean. Remember, no matter
where you go, there you are." - Buckaroo Banzai
------------------------------
Date: 17 Jun 1997 19:33:09 GMT
From: jcostom@shaft.sjis.com (Jason Costomiris)
Subject: Re: justa question...
Message-Id: <slrn5qdpjm.gmc.jcostom@dogbert.sjis.com>
On Tue, 17 Jun 1997 19:28:03 GMT, Faust Gertz <faust@wwa.com> wrote:
: If he doesn't understand the difference between GET and POST, what
: makes you think he will be able to understand how to use the CGI
: module? We don't even know if he has it installed. And if you were
: going to bother to include the shebang line for him, why didn't you
: include the "-w" and then "use strict;" for him as well? This kind of
: help seems more likely to frustrate than aid.
Frustrate? I told him to go read how to find out what the difference
between GET and POST is. Once he reads aobut the difference between
reading a stream from STDIN, and reading $ENV{QUERY_STRING}, he'll
understand...
Personally, I only use -w when I'm having trouble with something working.
As for your comment about CGI.pm being installed, consider that he
already has GD.pm installed, so he already knows something about
installing modules, most likely, at least how to use them. Perl
5.004 comes with CGI.pm, in case you haven't noticed.
Why are you bitching at me anyhow? I didn't see a posting from you
offerring help.....
--
Jason Costomiris | Finger for PGP 2.6.2 Public Key
jcostom@sjis.com | "There is a fine line between idiocy
My employers like me, but not | and genius. We aim to erase that line"
enough to let me speak for them. | --Unknown
http://www.jasons.org/~jcostom
------------------------------
Date: 17 Jun 1997 23:16:37 +0200
From: deas@rrz.uni-hamburg.de (Andreas Steffan)
Subject: Linux,glibc-2,perl-5.004_1: make test fails
Message-Id: <5o6url$hgf$1@mortimer.deas.org>
Hi
I wonder if anyone succeeded in building perl-5.004(_1) with glibc-2
on Linux.
"make" finshed without errors, but "make test" yielded the following
errors:
pragma/locale.....FAILED on test 0
lib/anydbm........FAILED on test 0
lib/db-btree......FAILED on test 0
lib/db-hash.......FAILED on test 0
lib/db-recno......FAILED on test 0
lib/filecopy......FAILED on test 6
lib/filehand......FAILED on test 0
lib/gdbm..........FAILED on test 0
lib/io_dup........FAILED on test 0
lib/io_pipe.......FAILED on test 0
lib/io_sock.......FAILED on test 0
lib/io_taint......FAILED on test 0
lib/io_tell.......FAILED on test 0
lib/io_udp........FAILED on test 0
lib/io_xs.........FAILED on test 0
lib/ndbm..........FAILED on test 0
lib/odbm..........FAILED on test 0
lib/opcode........FAILED on test 0
lib/open2.........FAILED on test 0
lib/open3.........FAILED on test 0
lib/ops...........FAILED on test 0
lib/posix.........FAILED on test 0
lib/safe1.........FAILED on test 0
lib/safe2.........FAILED on test 0
lib/sdbm..........FAILED on test 0
lib/socket........FAILED on test 0
Failed 26 test scripts out of 152, 82.89% okay.
"perl harness" died with a segfault.
Any ideas ?
--
Thanks Andreas
PS: Linux-2.0.29,glibc-2.0.3,perl-5.004_1,gcc-2.7.2.2-glibc
PPS: Please also reply via email.
+-----------------------------------------------------------------+
| Andreas Steffan email: deas@rrz.uni-hamburg.de|
| Hamburg, Germany |
+-----------------------------------------------------------------+
finger p25a003@server2.rrz.uni-hamburg.de for PGP-public-key.
------------------------------
Date: 17 Jun 1997 12:49:13 -0500
From: mparson@roloc.bl.org (Michael Parson)
Subject: Re: mod_perl or fastcgi install, liberl.so help..
Message-Id: <5o6imp$303$1@roloc.bl.org>
In article <33A33959.32C1@hotmail.com>,
perl guy <perlprogrammer@hotmail.com> wrote:
. Hi..
. I am looking to do a few things, but I'm not sure how much I can
. do remotely. Needless to say, I'm hoping for a little direction
. in where to tell my server tech to look, and to do with some things
. he's having trouble with.
. I'm trying to get either mod_perl or fastcgi to work on this system
. so I won't chew up the CPU, etc.. Right now I have a chat site,
. and it's getting so much traffic, that it's much too slow, and
. doing a number on the machine it's run on.
. The chat scripts are in Perl and I want to keep them that way for
. portability, etc... so please don't post to me about how I should
. do this in C, etc.
. Also, I am looking into building a shared libperl.so library to link my
. script to. I want to link my main perl binary with this, as I
. understand is will make my 500BK+ /usr/bin/perl file run as small as
. only 11k to 30K in size! I could really use that feature at this point
. as well, or at least untill we get the mod_perl working. But he's having
. trouble installing it.
You may want to not use the libperl.so, according to the perl INSTALL docs,
using libperl may be slower:
--
The disadvantages are that there may be a significant
performance penalty associated with the shared libperl.so,
and that the overall mechanism is still rather fragile
with respect to different versions and upgrades.
In terms of performance, on my test system (Solaris
2.5_x86) the perl test suite took roughly 15% longer to
run with the shared libperl.so. Your system and typical
applications may well give quite different results.
--
. I need to do something, but my access is somewhat limited, because I'm
. not the tech at my server, and although I do have root access, I can
. only do things remotely via telnet. I think they might get annoyed wth
. me going to the server and tweaking the Linux box. So, what exactly can
. I do from remote access via Telnet?
That is the beauty of unix systems, you can do everything but
power-cycle the machine over telnet... =)
Really... I manage several unix based web servers remotely... Both
from my workstation at work, or logged in from home. (hey, sometimes
you can just code better in your underwear ;). There is very little
that you can get done at the console that you can't do over the
net.
. Is there anyone that can advise me about how to get the mod_perl going,
. and what and *if* I need to change in my scripts usually. I am a plain
. perl hacker (not an expert), in other words, I do scripts.. I don't have
. knowledge of how everythign workds, let alone, .pm, etc files and mods..
. and I surely know very little about the actual Linux box and how to go
. about installing a plugin such as mod_perl. I'm looking and learning as
. much as I can, but this needs to be done soon, and I would appreciate
. any advice, etc.. I hope that I don't have to change much in my scripts,
. but I am more concerned with getting this working. My tech hs read
. through all the fiels wth information about the mod_perl install, but
. yet, he's having trouble wth it. *cringe* For now, I'm stuck. Any ideas,
. advice, or pointers? Maybe I need to send him to a mod_perl site for
. dummies?. maybe I should look there too :0
mod_perl is rather easy to install. Just untar the apache 1.2
sources and the mod_perl sources into the same dir (ie, you have
/usr/local/src/mod_perl and /usr/local/src/apache1.2). Change into
the mod_perl dir, run 'perl Makefile.PL', answer a couple of
questions, and run 'make' in the mod_perl dir. Just make sure you
are running the latest version of mod_perl (ver .99 is the latest
on CPAN and on the mod_perl guy's ftp site).
Web docs for mod_perl can be found at:
http://www.osf.org/~dougm/apache/src/mod_perl.html
. BTW, I'm running Linux, with Ret Hat 4, Apache 1.2 (not beta), perl
. 5.003, Kernel is 2.0.18 .. Thanks for any advice. This is all new to
. me, and all the info is vague it seems. Thanks again for any help.
If you want to use fcgi, you will need to have AT&T's sfio installed.
You need a special compile of perl5.003pl23 or newer (5.004 has
sfio and perlio support), compiled to use sfio and perlio, read
the INSTALL file for info on this part.
I don't know of an RPM for sfio, but it does compile with little
coaxing, though there are some things to take into consideration
before putting it into production.
It is easy enough to modify the .spec file from the perl5.004 SRPM
to produce a binary release of perl5.004 (or 4.003pl23+) compiled
with sfio and perlio.
Feel free to mail me if you have any questions about what I've
covered here. Just pay attention to my .sig, or the mail will
find itself in /dev/null
--
Michael Parson
Mail sent to this posting host will not make it to me, to reply,
send to just the domain.
------------------------------
Date: 17 Jun 1997 16:03:31 -0400
From: @jumbo.com
Subject: MS-DOS port of the Perl programming language
Message-Id: <5o6qij$d3a@orion.jumbo.com>
Get NEW MS-DOS port of the Perl programming language Shareware As It's Written!
The latest and greatest MS-DOS port of the Perl programming language shareware and
freeware as soon as it's created! We download new programs DAILY
(10 a.m. EST) from more than 300 sites all over the world.
Check out the new programs everyday in the "TODAY'S FREE COMPUTER
PROGRAMS" section on the all new JUMBO! --- bigger and faster
than ever with over 200,000 files and programs --- more than 1.8 million
links --- including a HUGE multimedia section with sounds, graphics, videos,
streaming music, VRML, animations, clip art, icons,
schockwave, screen savers --everything! --- http://www.jumbo.com.
Get the latest at:
http://www.jumbo.com/pages/programming/dos/perl/
http://www.jumbo.com/pages/programming/mac/languages/
------------------------------
Date: Tue, 17 Jun 1997 18:37:52 BST
From: gml4410@ggr.co.uk (Lack Mr G M)
Subject: Re: not printing
Message-Id: <1997Jun17.183752@ukwit01>
In article <33a50cf3.1394996@news.interserv.com>, rroberts@gowebway.com writes:
|> I have reposted this after reading the artical "getting the most out
|> of CLPM" so if your reading this twice sorry.
|>
|> This program is not printing at line 6. In all other ways it is
|> working just fine.
It's line buffered, and you don't have a newline at the end.
Add:
use IO::File;
STDOUT->autoflush(1);
|> ########################---- begin code
|> #!/usr/bin/perl -w
|> print "Give me a list of words and press^z when done.\n";
|> @a=<stdin>;
|> $b = @a;
|> print "Now give me a number between 1 and $b.";
|> $c = <stdin>;
|> chop($c);
|> print $a[$c-1];
|> ########################------- end code
Also, the ^z is specifc to MS systems. On Unix you would want ^D. Or
even better woudl be to keep reading from stdin until you got a blank
line, which is portable.
And you should put a trailing space on the failing print....
--
----------- Gordon Lack ----------------- gml4410@ggr.co.uk ------------
The contents of this message *may* reflect my personal opinion. They are
*not* intended to reflect those of my employer, or anyone else.
------------------------------
Date: 17 Jun 1997 17:41:54 GMT
From: Eli the Bearded <usenet-tag@qz.little-neck.ny.us>
Subject: Re: Perl Reg Exp
Message-Id: <5o6i92$40r$1@news.netusa.net>
Brett Borger <bxb121@psu.edu> wrote:
> In my continuing battle against a mangled version of 4.??? perl for
> Novell:
> isNew(60,"somedatehere")
to
> isNew(60, "newdate")
> where newdate is what you would expect. The line I'm using is:
> $temp=~s/isNew\(+\)/isNew(60,"$date")/o;
$temp=~s/isNew\([^)]+\)/isNew(60,"$date")/;
The /o is only useful (I am reasonably sure) if the variable is in
the RE part, not the substitution part.
Elijah
------
the RE part takes some time to compile, the sub part does not
------------------------------
Date: 17 Jun 1997 17:35:30 GMT
From: "Chris Oke" <coke@adrenalin.com>
Subject: Re: PERL to Oracle
Message-Id: <01bc7b45$079079c0$371c9bcf@pc10.adrenalin.com>
Win32::ODBC should do the trick. You can find it in CPAN and at
http://www.roth.net/odbc/
Chris
C. Duncan Hudson <duncan.hudson@us.gases.boc.com> wrote in article
<01bc7b2d$8f08e1c0$8add76a2@unity-94.us.gases.boc.com>...
> I have a need to read a file off a Windows NT machine and update an
Oracle
> 7 (also NT) database from the records contained in the file. Is this
> something that I can do with PERL, without having to buy canned software?
> If so, how would I go about doing it? Thanks in advance,
------------------------------
Date: Tue, 17 Jun 1997 17:23:38 -0400
From: Michael D Sohn <msda+@andrew.cmu.edu>
Subject: programming question
Message-Id: <0ndk1O200YUf02ENk0@andrew.cmu.edu>
I appologize if this is an inappropriate question but I want to use perl
to do the following:
Say I have a cartesion coordinate system.
Within the coordiante system, I have a rectangle drawn.
I would like to know each of the squares(nodes) that are enclosed or in
contact with the rectangle.
Does anyone have a program to do the following:
This seems like something someone might have common use for but can be a
programming nightmare if not a competent programmer.
thanks,
Mike
again my sincere apologies if this is not an appropriate forum. Could
you suggest an alternative?
------------------------------
Date: 17 Jun 1997 18:44:24 GMT
From: ilya@math.ohio-state.edu (Ilya Zakharevich)
Subject: Re: Running out of memory in recursive subroutine
Message-Id: <5o6lu8$rfe@agate.berkeley.edu>
In article <33A5FE63.48A4@unikix.com>, Steve Hart <s.hart@unikix.com> wrote:
> I have written a perl subroutine that reads a text file, and whenever
> a file name is encountered in the text file, appends the file's
> contents to the text file.
..
> My problem is that memory allocated for the string that is used to
> store the text file does not seem to be released each time the
> subroutine finishes.
>
> Here is part of my program showing the recursive subroutine:
> sub expand {
> my ($text) = @_;
> foreach $line (split (/\n/, $text)) {
> if ($line =~ /^EXPAND:(.+?)\s/) {
> $expfile = $1;
> open (EXPFILE, "<$expfile");
> $text .= &expand (<EXPFILE>); # Recursive call
> close EXPFILE;
> }
> }
> return ($text);
> }
Perl never frees any intermediate values in a hope that you when you
*reenter* the subroutine, you will need approximately the same amount
of space again, and the overhead of reallocing the space will be
avoided.
Here *reenter* is not related to recursive call, the lexicals and
temporaries are reallocated for each "entry" of a recursive subroutine.
I myself consider this decision with mixed feelings, but at least for
the code like you have (where $text grows) it looks reasonable.
I can see two possible temporaries/lexicals: $text and (possibly) the
SV into which the result of recursive call to "expand" is written.
Though "leavesub" opcode is marked as using a temporary (see
opcode.pl), I cannot find the use of this temporary in the code of
pp_leavesub. (Well, and you use an explicit "return" which is not
even marked as using a temporary.)
So the only culprit must be $text, and this may be alleviated by doing
undef $text;
if you could do it before returning. Maybe something like (horrible)
my %t = ('' => $text);
$t{''} = $text;
undef $text;
return delete $t{''};
would work? Probably "delete" is extraneous, since %t should be
cleaned up.
Ilya
------------------------------
Date: 17 Jun 1997 13:17:24 -0700
From: trs@azstarnet.com (Tim Smith)
Subject: Re: Running out of memory in recursive subroutine
Message-Id: <5o6rck$ofd@web.azstarnet.com>
[ CC'd to poster ]
In article <33A5FE63.48A4@unikix.com>, Steve Hart <s.hart@unikix.com> wrote:
>My problem is that memory allocated for the string that is used to
>store the text file does not seem to be released each time the
>subroutine finishes.
You can avoid using those temporary text strings. One way would be to
use an array that holds the sections. Here's one way to do it. I also
modified it a bit so you're processing one line at a time, instead of
slurping in whole files at once. Whatever works for you, but I hope
this helps.
Tim
#!/usr/bin/perl -w
use strict;
use IO::File; # don't have to worry about clobbering FILEHANDLES
my @chunks;
my $arg;
foreach $arg (@ARGV) {
@chunks = ();
open TEXTFILE, "< $arg" or warn("can't open < $arg: $!\n"), next;
expand(\*TEXTFILE);
print "---TOP OF FILE '$arg'---\n";
foreach (@chunks) { print; }
print "---BOT OF FILE '$arg'---\n";
close TEXTFILE;
}
sub expand {
my ($fh) = @_;
push @chunks, ''; # we're expanding a new file
my $index = $#chunks; # remember which chunk we're working on
while (<$fh>) {
$chunks[$index] .= $_; # append to our current file's chunk
if (/^EXPAND:(\S+)/) {
my $subfh = new IO::File $1, '<'
or warn("can't open < $1: $!\n"), next;
expand($subfh); # Recursive call
$subfh->close;
}
}
}
__END__
>undef $/;
>
>foreach $arg (@ARGV) {
> open (TEXTFILE, "<$arg");
> $expanded_file = &expand (<TEXTFILE>);
>}
>
>sub expand {
> my ($text) = @_;
> foreach $line (split (/\n/, $text)) {
> if ($line =~ /^EXPAND:(.+?)\s/) {
> $expfile = $1;
> open (EXPFILE, "<$expfile");
> $text .= &expand (<EXPFILE>); # Recursive call
> close EXPFILE;
> }
> }
> return ($text);
>}
>
>What happens is that every time the program expands a text file,
>more memory is used up, which will eventually casuse my machine to
>run out of memory.
>
>Is there any way I can free up the memory used for $text in this
>example.
>
>Or should this not cause a problem (meaning I'm doing something
>wrong elsewhere)?
>
>
>Steve Hart
>s.hart@unikix.com
------------------------------
Date: 17 Jun 1997 19:39:30 GMT
From: hjs@Cadence.COM (Henry Salvia)
Subject: Re: Sockets
Message-Id: <5o6p5i$ohf$1@cds8604.Cadence.COM>
In article 5D7D@inta.net.au, Anil Gupta <anil@inta.net.au> () writes:
> Hello there..
>
> Does anyone know where I can find a good socket tutorial?
> I tried perlipc but it was a bit advanced
>
>
> Thanks.
>
> Anil Gupta
Try http://www.usenix.org/publications/perl/perl14.html
This is part 1 of a 3-part series on Network programming with perl5,
by Hal Pomeranz. The example code has worked quite well for me.
------------------------------
Date: 17 Jun 1997 20:09:52 GMT
From: "John Bokma" <jbokma@caiw.nl>
Subject: Re: Sorting Associative Array? (Urgent)
Message-Id: <01bc7b5a$90f54f00$d50ab2c2@tschai>
Ng Chin Kiong <ckng@global.com.my> wrote in article
<33A4D734.1C3A@global.com.my>...
> Does anyone know how to sort an associative array by the key value?
> Example data is %array=("name","id",.....) and I need to sort by
the key
> name. Anyone?
> I've look into
http://www.perl.com/perl/everything_to_know/sort.html,
> but couldn't find anything.
> Thanks in advance.
>
>
You can't sort an associative array. However you can walk trough all
the values in sorted
order e.g. to print the key-values:
foreach $key (sort keys %array)
{
print "$key containts $array{$key}\n";
}
or assign the keys in sorted order to an array:
@sorted = sort keys %array;
Regards,
John
--
----------------------------------------------------------------------
Need a Freelance Software Developer (MSc)? (CGI, Perl, Java, C, C++)
http://www.caiw.nl/~jbokma [Java demo's, Curriculum Vitae and
more...]
email: jbokma@caiw.nl phone: +31 10 4291827
------------------------------
Date: 17 Jun 1997 13:42:00 -0700
From: Randal Schwartz <merlyn@stonehenge.com>
To: johnm@non.net
Subject: Re: TIMING EXPERIMENT
Message-Id: <8coh95ynaf.fsf@gadget.cscaper.com>
>>>>> "John" == John D Mitchell <johnm@non.net> writes:
John> In article <EBtG27.uM@statcan.ca>, Mike Jeays wrote:
>> -------------------------------------------------------T
>> TIMING EXPERIMENT - C, JAVA, Visual Basic, PERL and TCL
>> -------------------------------------------------------
>>
>> I tried a timing experiment to compare C, Java, Visual Basic, Perl and Tcl
>> for a simple calculation-intensive task - generating the first n primes
>> using the well-known Sieve of Eratosthenes.
>>
>> The timings (in seconds) were as follows :
>>
>> Number of primes | C Java VBasic Perl Tcl
>> 2,000 | 0.2 0.9 2.0 4.0 41
>> 10,000 | 1.6 6.8 14.0 33.0 355
>> 20,000 | 3.7 16.7 34.0 85.0 885
>> 100,000 | 25.0 139.5 # 786.0 5319*
John> [...]
Good. Next time I need some prime numbers, I'll know not to do it in
Perl. Big deal. It probably wasn't even a fair algorithm (hint: if
it used subscripts into an array, it wasn't fair).
Now, here's a real-world task:
Create a web page that allows people to search the Internet Movie
Database for movies by a particular director, and then get details on
each movie. The data itself is stored in a Sybase server. Oh, yeah,
and you have about 3 hours to finish.
Go!
In summary, it doesn't matter how fast a computer gets an answer, if
it gets the answer *later* (because of development time).
John> Of course, if you're wanting to write "applets" your only choices out of
John> that list are Java & Tcl.
Not at all. Penguin allows the Perl-TK browser to run digitally
signed "perl-applets" in a "safe" area. And unlike Java, it's all
free (as in, unencumbered by costs or licensing restrictions). And
unlike TCL, Perl has *real* datatypes.
Just another datapoint,
--
Name: Randal L. Schwartz / Stonehenge Consulting Services (503)777-0095
Keywords: Perl training, UNIX[tm] consulting, video production, skiing, flying
Email: <merlyn@stonehenge.com> Snail: (Call) PGP-Key: (finger merlyn@ora.com)
Web: <A HREF="http://www.stonehenge.com/merlyn/">My Home Page!</A>
Quote: "I'm telling you, if I could have five lines in my .sig, I would!" -- me
------------------------------
Date: 17 Jun 1997 19:24:59 GMT
From: kgikaren@aol.com (Kgikaren)
Subject: US- NC, GA, TX Permanent Positions
Message-Id: <19970617192400.PAA15726@ladder02.news.aol.com>
Quote of the Week----
"Job security is no longer a given. Neither are the generous benefits that
a previous generation of workers enjoyed. These qualities are not worthy
indicators of the value of a job. Rather, the individual should evaluate a
job offer from the perspective of its contribution to the attainment of
long-term goals."
The Kelton Group offers technical services ranging from computer
information services to technical documentation and training. To keep up
with the championship standards set by our clients, we seek out the best
programmers, analysts, technical writers, editors, and more.
We are seeking qualified professionals with a minimum 3+ yrs of industry
experience in one or more of the following:
Database Analyst - use data modeling techniques to analyze and specify
data usage within an application area. Define both logical views and
physical data structures. In the client/server environments, define the
back-end. (Oracle, Sybase, Informix and SAP)
Database Administrator - administer and control an organizations data
resources. Use data dictionary software packages to ensure data integrity
and security, recover corrupted data and eliminate data redundancy. Also
use tuning tools to improve database performance. (Oracle, Sybase,
Informix and SAP)
Data Modeler - design data models to support system requirements. Provide
input to DBA to assist in physical database layout, including space
estimations, index utilization and table locations. Implement logical
data models into physical form in a relations database management system.
UNIX Systems Administrator - Install and maintain UNIX operating systems.
Configure UNIX boxes, establish standards and evaluates hardware and
software products.
Software Engineer - responsible for design, development and implementation
of computer software in Windows or UNIX using C, C++, Assembly and other
low-level operating system software. Also responsible for development of
GUI-based applications, systems, software and embedded software.
Windows System Developer - develop and support graphical user interface
applications. Program in Visual Basic, C++, Powerbuilder. Know how to
access relational databases like Access, Oracle or Sybase. Skilled in
OLE, SDK, MFL, DLL and DDE.
UNIX Systems Developer - develop software for distributed or centralized
systems. Analyze, design, and code with definitive understanding of
application. Expertise in UNIX and C. Familiar with C++, X-Windows,
Motif, and Interprocess Communications. Capable of integrating systems in
two- or three tiers architecture.
Salary ranges -- (dependent upon experience) Mid 40's -- Low 100's
Think you have what it takes to join us? We invite you to learn more about
The Kelton Group. Contact:
Karen Servance, Technical Recruiter kgikaren@aol.com
The Kelton Group 919-851-4064
phone 919-859-3561 fax
5540 Centerview Drive, Suite 412 Raleigh, NC
27606
P.S. ASK ABOUT THE TALKING FROG ! ! ! !
Karen Servance, Corporate Recruiter
The Kelton Group
www.keltongroup.com
919-851-4064 phone 919-859-3561 fax
kgikaren@aol.com
------------------------------
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 625
*************************************