[7378] in Perl-Users-Digest
Perl-Users Digest, Issue: 1003 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Sep 9 21:07:38 1997
Date: Tue, 9 Sep 97 18:00:29 -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, 9 Sep 1997 Volume: 8 Number: 1003
Today's topics:
"C/C++" Data Dictionary/Cxref tool? <elias@telcontar.tc.cornell.edu>
Re: A simpler perl question. <w.stanton@auckland.ac.nz>
Re: Access and Perl <charles.engelke@cloverleaf.net>
Re: Book: Dynamic HTML Primer <jhoskins@ichips.intel.com>
Building dynamically named arrays <mgn00@eng.amdahl.com>
Re: Calling a Perl Script... (brian d foy)
Re: Calling a Perl Script... <rootbeer@teleport.com>
Re: Can you escape from the debugger ? (Ilya Zakharevich)
Re: Clearing screen in CGI (Jeremy Brinkley)
Re: Converting strings to numbers <rootbeer@teleport.com>
Finally! Something Perl can't do well! (Pete Ratzlaff)
Re: Finally! Something Perl can't do well! (Will Morse)
Re: Finally! Something Perl can't do well! (Brian Wheeler)
Re: Finally! Something Perl can't do well! <rootbeer@teleport.com>
Re: Finally! Something Perl can't do well! <rootbeer@teleport.com>
getlogin, getpwuid on Win95 (dmouse)
hash of objects vs array of objects <tech-support@valueclick.com>
Re: Help in search script (Eric Bohlman)
Re: how do I redirect the output of an existing perl sc (DR TE$TH & THE ELECTRIC MAYHEM)
Re: How to open a file for both read and write (Tad McClellan)
Re: How to open a file for both read and write (Eric Bohlman)
Re: How to rename /etc/passwd ? <rpsavage@ozemail.com.au>
Re: I think this is a simple question (Faust Gertz)
Re: Is it a module, or what? (Ken Williams)
Migrating to Berkeley db 2 using DB_File? (Ken Williams)
Re: Minimizing Memory Needed for Numbers Read from Bina (Ilya Zakharevich)
Re: Q: bitwise operators and perl <Philip.Abercrombie@MCS.VUW.AC.NZ>
Re: removing shell comments from ksh scripts (Dan Nelson)
Server Push problem...I think (Matt Weber)
SQL Server, ODBC and problems (Dirge )
Re: sumcheck generator wanted (Jim Michael)
system() use in forked server process ? <rjm2@cornell.edu>
Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 09 Sep 1997 14:54:12 -0400
From: Doug Elias <elias@telcontar.tc.cornell.edu>
Subject: "C/C++" Data Dictionary/Cxref tool?
Message-Id: <s9plo16nwrv.fsf@telcontar.tc.cornell.edu>
G'day ...
i'm about to start building a Perl tool to assist in constructing a
"data dictionary"/cross-referencer for C/C++ packages: the tool would
take a set of source files, and return a listing of all declared
variables and defined symbols, the location of the their
declaration/define, and the locations of all of their uses.
i just wanted to check again to see if someone has already done this --
i didn't see anything suitable in CPAN, so if you've got one that you
wouldn't mind sharing, i'll try yours out first before going ahead
with my own.
Thanks,
doug
--
__|_ Internet: elias@tc.cornell.edu
dr _|_)oug USmail: Sci.Comp.Support/Cornell Theory Center
(_| 737 Rhodes Hall/C.U./Ithaca/N.Y./14853-3801
(_|__ MaBelle: 607-254-8686 Fax: 607-254-8888
| MOOs: doug/DougE/Strider/Dun'a'dan
------------------------------
Date: 10 Sep 1997 11:44:46 +1300
From: Worik Macky Stanton <w.stanton@auckland.ac.nz>
Subject: Re: A simpler perl question.
Message-Id: <wken6ygl9d.fsf@auckland.ac.nz>
"OrdwayNet Webmaster" <ordway@iwshost.net> writes:
>
> I have a question that I need answered-
>
> I have a directory full of files. Lets say that I want to add something to
> each one of those files. How would I do it?
>
> I think it would be something like this, but it isn't enough-
>
> foreach $file
# Page 202 camel
opendir THISDIR;
@file = readdir THISDIR;
closedir THISDIR;
foreach (@file) {
open OUT ">>$_"; # '>>' indicates apend page 191 camel
print OUT "bla bla"\n";
close OUT;
}
>
> How do I make $file mean every file in the dir. Thanks for any help!
> Email me at ordway@iwshost.net or post it on this newsgroup.
>
camel 2nd ed. Sept. 1996
------------------------------
Date: Tue, 09 Sep 1997 16:17:27 -0400
From: Charles Engelke <charles.engelke@cloverleaf.net>
Subject: Re: Access and Perl
Message-Id: <3415AED7.271F@cloverleaf.net>
Derick A. Jackson wrote:
>
> I am a microsoft database programmer that is attempting to use perl to
> access data in a .mdb file. Does anyone out there know of any perl
> scripts for MS access?
Use ODBC. Set up an ODBC DSN pointing to your Access database with the
Control Panel first. Say you call it "demo". Then you can use the
following code to fetch the results of an SQL query, such as getting all
fields of all records from table XYZ:
use Win32::ODBC;
$db = new Win32::ODBC("demo") or die "Can't create db\n";
$db->Sql("SELECT * from XYZ;")
and die "Can't run SQL Statement\n";
# Believe it or not, the "and" is right!
while ($db->FetchRow())
{
undef %Data;
%Data = $db->DataHash();
foreach $FieldName (sort keys %Data)
{
print "$FieldName => $Data{$FieldName}\n";
}
}
------------------------------
Date: Tue, 9 Sep 1997 12:32:30 -0700
From: "Kevin Hoskins" <jhoskins@ichips.intel.com>
Subject: Re: Book: Dynamic HTML Primer
Message-Id: <5v486o$nok@news.or.intel.com>
Try both http://www.insidedhtml.com where Scott Isaacs is working on a book
and putting his code online. Try also the long awaited book by Nick Heinle
"Designing with JavaScript" which was due to be published in July, but
hasn't made its appearance yet. Information about the book can be found at
http://www.oreilly.com/catalog/designjs/
Kevin
http://www.thatplace.com
John Ratzan wrote in message <341567A7.278B@us.ibm.com>...
>John Burke wrote:
{snip]
>Do you know of any additional books or resources on Dynamic HTML?
>Thanks in advance.
>John Ratzan
>ratzan@us.ibm.com
------------------------------
Date: Tue, 9 Sep 1997 23:02:41 GMT
From: Matt Noel <mgn00@eng.amdahl.com>
Subject: Building dynamically named arrays
Message-Id: <3415D591.41C67EA6@eng.amdahl.com>
I would like to read some data into multiple associative arrays, where
the array names are based on the data in the file.
Specifically, a trivial example would be a set of data like this:
---------------------------------------------------
ArrayOne:one:I
ArrayOne:two:II
ArrayOne:three:III
ArrayTwo:one:1
ArrayTwo:two:2
ArrayTwo:three:3
-----------------------------------
I would like to treat the first thing ('ArrayOne' and 'ArrayTwo' in this
case) as the name of an associative array. I would treat the other two
values as an index into the array, and a value to store at that index.
I was trying to figure out how to do this with type globbing, reading
the description of it in the original camel book (pages 101-102) but I
can't get anything to work.
Can anyone help out? I'd really like to get by with a solution which
works with perl 4.* as I need to port this to a system where the latest
level of perl is 4.36.
--
Matt Noel mgn00@eng.amdahl.com
Amdahl Corporation Phone (408) 746-6283
------------------------------
Date: Tue, 09 Sep 1997 16:06:46 -0400
From: comdog@computerdog.com (brian d foy)
Subject: Re: Calling a Perl Script...
Message-Id: <comdog-ya02408000R0909971606460001@news.panix.com>
In article <3415975E.3DF34B61@ait.acl.ca>, Guy Doucet <gdoucet@ait.acl.ca> wrote:
>(1) I want to know how to call a Perl script from an HTML/JavaScript
>document, other than the <form method="post"... or "get"... What I'm
>getting at is I'd like to know if a JavaScript can call the Perl script
>directly.
i haven't looked at JavaScript in awhile, but isn't that what
document.location is for? the folks in comp.lang.javascript would know.
>(2) I am running on a Novell Web Server and I was wondering how to call
>a Perl script that doesn't return anything to the web page. When I try,
>I get Document contains no data.
use the HTTP status 204 [1], which is designed for that. however, some
clients treat this as an error. i vacillate on the human interface
implications of this though - people expect something to happen (usually),
and seem to keep clicking, pointing, or whatever they do until something
does.
--
brian d foy <comdog@computerdog.com>
------------------------------
Date: Tue, 9 Sep 1997 14:49:52 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: Guy Doucet <gdoucet@ait.acl.ca>
Subject: Re: Calling a Perl Script...
Message-Id: <Pine.GSO.3.96.970909144636.27604a-100000@julie.teleport.com>
On Tue, 9 Sep 1997, Guy Doucet wrote:
> (1) I want to know how to call a Perl script from an HTML/JavaScript
> document, other than the <form method="post"... or "get"... What I'm
> getting at is I'd like to know if a JavaScript can call the Perl script
> directly.
If it can be done, you do it the same way you call a script written in any
other language. To find out how to do that (and whether it's possible)
check the docs and FAQs for the language making the call.
> (2) I am running on a Novell Web Server and I was wondering how to call
> a Perl script that doesn't return anything to the web page. When I try,
> I get Document contains no data.
If it's not supposed to return anything, aren't you _supposed_ to get no
data? :-)
--
Tom Phoenix http://www.teleport.com/~rootbeer/
rootbeer@teleport.com PGP Skribu al mi per Esperanto!
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
Ask me about Perl trainings!
------------------------------
Date: 9 Sep 1997 20:40:57 GMT
From: ilya@math.ohio-state.edu (Ilya Zakharevich)
Subject: Re: Can you escape from the debugger ?
Message-Id: <5v4c8p$i3f@agate.berkeley.edu>
In article <5v35v3$lug$1@news.rwth-aachen.de>,
Helmut Jarausch <jarausch@numa1.igpm.rwth-aachen.de> wrote:
> Hi,
>
> for a quick test I very much like to use the debugger,
> but this time it caught me and wouldn't let me go, again.
> In both variants below I had to 'kill' it!
Control-Break works here (probably some kind of ^\ or ^Y on *nix, I
never use them).
>
> perl -de 0 #Variant I)
>
> format STDERR =
> @#@#
> 1,2
> .
> q
You do not need a debugger to demostrate this, just
perl -e "eval 'format STDERR =' or die"
will go.
Ilya
------------------------------
Date: 9 Sep 1997 23:01:38 GMT
From: jeremy@wishbone.stanford.edu (Jeremy Brinkley)
Subject: Re: Clearing screen in CGI
Message-Id: <5v4kgi$si5$2@nntp.Stanford.EDU>
On Wed, 03 Sep 1997 16:34:19 -0600, kchadha@hotmail.com put forth:
> How would I clear the screen from the GCI script
> after printing a couple of lines ?
As was mentioned, you want to look up the concept of "server push"
in a CGI reference to get the impression of printing & waiting.
You may also want to look at "client pull." This should allow you
to send a doc, then have the client (browser) request it again (by
specifying the Refresh: HTTP header), at which point you can print
something else, thereby "clearing" the "screen."
I liked Shishar Gundavaram's book "CGI Programming on the World Wide
Web" from O'Reilly, ISBN 1-56592-168-2.
> Please e-mail your replies to kchadha@hotmail.com
It's generally considered impolite to request that people who are
giving you help for free e-mail you the answers. If you can't be
bothered hang around a newsgroup for the responses, then who
cares about you?
--
Jeremy Brinkley
System Administrator
Stanford Blood Center
jeremy@wishbone.stanford.edu
finger for PGP key (2.6.2) or
http://wishbone.stanford.edu/~jeremy
------------------------------
Date: Tue, 9 Sep 1997 14:45:24 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: John J Holden <swrholdj@met.rdg.ac.uk>
Subject: Re: Converting strings to numbers
Message-Id: <Pine.GSO.3.96.970909143325.27604Z-100000@julie.teleport.com>
On 8 Sep 1997, John J Holden wrote:
> I'm using a form on a web page to read some numbers into a perl program.
> These numbers then need to be written to a file for a Fortran program to
> subsequently read. It is vital that these numbers are valid and do not
> contain non-numeric characters.
What's a non-numeric character? A hyphen? The letter E? A period? A comma?
:-) Do any of these have non-numeric characters? (They're all "valid
numbers" to me! :-)
$18,267.43 +1.6e-43 127.0.0.1 3+7i 0377
(212) 555-1212 216-48-3990 pi -inf 0
Find out what format the Fortran prog needs, then check that that's what
you're giving it. (This is the only true way to do what you request.) You
may be able to check with a regexp.
> Is it possilbe to convert the string into a numeric variable in perl?
Yes; Perl will do that automatically when you use it as a number. For
example:
$foo = 0+ $foo; # numeric conversion
In this case, $foo will have to become a number. (But maybe Fortran's idea
of what's a number isn't exactly the same as Perl's. In fact, they're
likely different, so beware.) Of course, Perl will warn you (if asked)
when you use this technique on something which isn't a number - in the
opinion of Perl, of course!
Good luck!
--
Tom Phoenix http://www.teleport.com/~rootbeer/
rootbeer@teleport.com PGP Skribu al mi per Esperanto!
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
Ask me about Perl trainings!
------------------------------
Date: 9 Sep 97 19:27:06 GMT
From: rpete@ascda3.harvard.edu (Pete Ratzlaff)
Subject: Finally! Something Perl can't do well!
Message-Id: <3415a30a.0@cfanews.harvard.edu>
I'm trying to read data from a file (a FITS binary table extension,
for those that care). This data is in the form of short integers.
The problem is that there are a large number to read ( > 1e6), and
Perl's scalars are *much* too large for these integers. Reading
2MB worth of file data turns into a 60MB Perl process!
Anyone know of a solution to this problem?
-------------
Peter Ratzlaff Harvard-Smithsonian Center for Astrophysics
Office B102 60 Garden St, MS 21, Cambridge MA 02138 USA
<pratzlaff@cfa.harvard.edu> phone: 617 496 7714
------------------------------
Date: 9 Sep 1997 14:59:07 -0500
From: will@Starbase.NeoSoft.COM (Will Morse)
Subject: Re: Finally! Something Perl can't do well!
Message-Id: <5v49qb$mu2$1@Starbase.NeoSoft.COM>
pack/unpack
store the data as characters in a string and just unpack them
into interger scalers when you need that specific number.
Its been a long time since I saw a system that considered
60MB to be terribly large. Is this really a problem? Maybe
a simpler answer is a larger box?
Will
In article <3415a30a.0@cfanews.harvard.edu>,
Pete Ratzlaff <rpete@ascda3.harvard.edu> wrote:
>I'm trying to read data from a file (a FITS binary table extension,
>for those that care). This data is in the form of short integers.
>The problem is that there are a large number to read ( > 1e6), and
>Perl's scalars are *much* too large for these integers. Reading
>2MB worth of file data turns into a 60MB Perl process!
>
>Anyone know of a solution to this problem?
>
>-------------
>Peter Ratzlaff Harvard-Smithsonian Center for Astrophysics
>Office B102 60 Garden St, MS 21, Cambridge MA 02138 USA
><pratzlaff@cfa.harvard.edu> phone: 617 496 7714
--
# Copyright 1997 Will Morse. Internet repost/archive freely permitted.
# Hardcopy newspaper, magazine, etc. quoting requires permission.
#
# Gravity, # Will Morse
# not just a good idea, # Houston, Texas
# it's the law. # will@starbase.neosoft.com
#
# These are my views and do not necessarly reflect anyone else/
=========================================================================
By US Code Title 47, Sec.227(a)(2)(B), a computer/modem/printer
meets the definition of a telephone fax machine. By Sec.227(b)
(1)(C), it is unlawful to send any unsolicited advertisement to
such equipment, punishable by action to recover actual monetary
loss, or $500, whichever is greater, for EACH violation.
=========================================================================
------------------------------
Date: 9 Sep 1997 20:00:44 GMT
From: bdwheele@indiana.edu (Brian Wheeler)
Subject: Re: Finally! Something Perl can't do well!
Message-Id: <5v49tc$cpg$5@dismay.ucs.indiana.edu>
In article <3415a30a.0@cfanews.harvard.edu>,
rpete@ascda3.harvard.edu (Pete Ratzlaff) writes:
>I'm trying to read data from a file (a FITS binary table extension,
>for those that care). This data is in the form of short integers.
>The problem is that there are a large number to read ( > 1e6), and
>Perl's scalars are *much* too large for these integers. Reading
>2MB worth of file data turns into a 60MB Perl process!
>
>Anyone know of a solution to this problem?
Since you've not even told us what the problem is (other than massive
memory usage), it'd be really hard to help you.
If you don't need to access all of these numbers at the same time,
don't convert the shorts to scalars. Just do one at a time and add them up, if
you're wanting a sum. Or, perhaps write a function that goes and gets the
nth data point and returns it, and only work with the set that you need to
deal with.
>
>-------------
>Peter Ratzlaff Harvard-Smithsonian Center for Astrophysics
>Office B102 60 Garden St, MS 21, Cambridge MA 02138 USA
><pratzlaff@cfa.harvard.edu> phone: 617 496 7714
--
Brian Wheeler
bdwheele@indiana.edu
------------------------------
Date: Tue, 9 Sep 1997 14:57:15 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: Pete Ratzlaff <rpete@ascda3.harvard.edu>
Subject: Re: Finally! Something Perl can't do well!
Message-Id: <Pine.GSO.3.96.970909145621.27604c-100000@julie.teleport.com>
On 9 Sep 1997, Pete Ratzlaff wrote:
> The problem is that there are a large number to read ( > 1e6), and
> Perl's scalars are *much* too large for these integers. Reading
> 2MB worth of file data turns into a 60MB Perl process!
Maybe you want the PDL package, from CPAN? Good luck!
--
Tom Phoenix http://www.teleport.com/~rootbeer/
rootbeer@teleport.com PGP Skribu al mi per Esperanto!
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
Ask me about Perl trainings!
------------------------------
Date: Tue, 9 Sep 1997 14:53:10 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: Will Morse <will@Starbase.NeoSoft.COM>
Subject: Re: Finally! Something Perl can't do well!
Message-Id: <Pine.GSO.3.96.970909145128.27604b-100000@julie.teleport.com>
On 9 Sep 1997, Will Morse wrote:
> Subject: Re: Finally! Something Perl can't do well!
> store the data as characters in a string and just unpack them
> into interger scalers when you need that specific number.
That's one way. Or, use PDL. (Maybe with PDL, this will be another failed
attempt to find something that Perl doesn't do well. :-)
--
Tom Phoenix http://www.teleport.com/~rootbeer/
rootbeer@teleport.com PGP Skribu al mi per Esperanto!
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
Ask me about Perl trainings!
------------------------------
Date: 9 Sep 1997 19:26:20 GMT
From: gt1535b@acmey.gatech.edu (dmouse)
Subject: getlogin, getpwuid on Win95
Message-Id: <5v47ss$php@catapult.gatech.edu>
Hey there,
I just installed GS's Win32 port on my Win95 machine and I'm having
problems. My script used getlogin and getpwuid without problems
using the Activeware port(307), but when I use 402, I get an error
saying that they're not implemented. Is this a bug?
But wait there's more. That wasn't even the reason that I switched
to 402 in the first place. I was getting a 'permission denied'
error when I tried to opendir() in one of my subroutines. I've read
about people having problems opening the root directory, but that's
not the case here. Here's the code:
sub rm {
local($file, $arg, @names, @flist, $tmp);
$file = $_[0];
if ($file =~ /-r\s*(\S*)/) {
$tmp = $1;
if (-f $tmp) {
unlink($tmp) || die "rm1: couldn't unlink $tmp - $!.\n";
} else {
$DB::single = 1;
local(*DIR);
$tmp = $1;
#It dies with the next statement
open(DIR, "$tmp") || die "rm: couldn't open DIR: $tmp - $!\n";
@names = readdir(DIR);
chdir(DIR);
foreach $file (@names) {
if (-f $file) {
push(@flist, $file);
} elsif (($file eq '.')||($file eq '..')) {
next;
} elsif (-d $file) {
rm("-r $file");
}
}
@cannot = grep(!unlink($_), @flist);
die "rm: could not unlink @cannot.\n" if @cannot;
undef @cannot;
chdir '..';
closedir(DIR);
rmdir($tmp);
}
} elsif ($file =~ /^(\S*)\s*2>>(\S*)/) {
$tmp = $1;
unlink($tmp) || die "rm3: couldn't unlink $tmp - $!.\n";
} elsif (-f $file) {
unlink($file) || die "rm2: couldn't unlink $file.\n";
}
}
Has anyone seen this before?
thanks,
Daryl
--
<>< Daryl Bowen <><
Georgia Institute of Technology
E-mail: gt1535b@prism.gatech.edu
Siemens Stromberg-Carlson Co-op
------------------------------
Date: Tue, 09 Sep 1997 17:03:21 -0700
From: Michael Bueno <tech-support@valueclick.com>
Subject: hash of objects vs array of objects
Message-Id: <3415E3C9.EBE8F68E@valueclick.com>
here's a bit 'o code to look at before i explain
my problem:
### create a bunch of AdEntry objects and store
### their addresses in both an array and hash
my(%score);
my($ad_entry);
foreach $file (@files) {
$ad_entry = AdEntry->new();
push(@add_entries, $ad_entry);
$score{$ad_entry} = ${ $ad_entry->{fields} }[19]{value};
# yes, the scores are getting assigned properly.
}
### array section
foreach $ad_entry (@add_entries) {
$ad_entry->hi;
}
### hash section
foreach $ad_entry (sort { $score{$a} <=> $score{$b} } keys %score) {
print "$ad_entry ";
$ad_entry->hi();
}
1) i loop thru a bunch of files, creating an object to represent
what's in each with the AdEntry->new() method.
while i do this, i store the reference to the new object
in @add_entries and the %score hash.
2) when i try to invoke the $ad_entry->hi() method in the
"array section" above, it works fine. (this method just
prints "hi").
3) when i try to invoke the $ad_entry->hi() method in the
"hash section" above, it complains:
Can't locate object method "hi" via package "AdEntry=HASH(0x135430)"
in the hash section, $ad_entry is given as the type:
AdEntry=HASH(0x135430) which i believe indicates it
is indeed an object of type AdEntry.
what am i missing? i suspect it may have to do with the
sort by value of the hash.
thanks for your replies.
-michael bueno
------------------------------
Date: Wed, 10 Sep 1997 00:07:51 GMT
From: ebohlman@netcom.com (Eric Bohlman)
Subject: Re: Help in search script
Message-Id: <ebohlmanEG9n13.MCK@netcom.com>
Marcantonio Fabra (fabra@ax.apc.org) wrote:
: Hello,
: I have a script that searches words received via STDIN in files of a directory.
: I separate the words I want to search by blank.
: The script is functioning well.
: Someone can help me in order to change the script, giving to it the capacity of
: search composed words ?
: For instance, "american theatre" (using the " in order to determine a composed
: word).
: I thing the part that need to be changed is the parse_form routine on my script.
: Here you have it :
: sub parse_form {
[snip familiar re-invented wheel]
I think you want to use CGI.pm and get rid of that code. That should
make your problem go away.
------------------------------
Date: 9 Sep 97 14:24:41 MDT
From: ronb.removethis@removethis.cc.usu.edu (DR TE$TH & THE ELECTRIC MAYHEM)
Subject: Re: how do I redirect the output of an existing perl script
Message-Id: <4hpWyQJJ4i6R@cc.usu.edu>
In article <5upg2n$ro6$1@ha1.rdc1.sdca.home.com>, "Peter Tiemann" <peter@preview.org> writes:
> I'd like to redirect the standard output of a perl function that I call.
> (Right now it writes on the screen = in a web page in my particular case)
> I would like to have that function write to a file to be able to process the
> output.
It has been a long time since I pearled, but I think I can answer that one:
You'll need to open a filehandle. Look up OPEN in whatever reference you have
available for this one. From there, I believe that you just do:
print FILEHANDLE $string;
note: do NOT put a comma after the filehandle.
HTH
rOn
--
Fone:801-787-8525 Page: 801-755-3746 - punch in your phone number and hit '#'
DISCLAIMER - These opoi^H^H "dang", ^H, [esc :q :qq !q "NYRGH!" :Q! "Whaddya
mean, Not an editor command?" :wq! ^C^C^C !STOP ^bye ^quit :quit! !halt ...
^w^q :!w :wq! ^D :qq!! ^STOP [HALT! HALT!!! "Why's it doing this?" :stopit!
:wwqq!! ^Z ^L ^ESC STOP :bye bye bye! M-X-DOCTOR "HELP! I can't get out of
this stupid editor!!!" And how does this make you feel?
------------------------------
Date: Tue, 9 Sep 1997 15:07:59 -0500
From: tadmc@flash.net (Tad McClellan)
Subject: Re: How to open a file for both read and write
Message-Id: <vaa4v5.3v1.ln@localhost>
Charlie (charlie@flychina.com) wrote:
: Songtao Chen <songtao@nortel.ca> wrote
: > Could anyone tell me how to open a file for both
: > read and write ?
: open(FH,"+>filename") || die "Cannot open filename\n";
^
^
Say goodbye to the contents of the file...
--
Tad McClellan SGML Consulting
tadmc@flash.net Perl programming
Fort Worth, Texas
------------------------------
Date: Tue, 9 Sep 1997 23:54:18 GMT
From: ebohlman@netcom.com (Eric Bohlman)
Subject: Re: How to open a file for both read and write
Message-Id: <ebohlmanEG9MEI.Kpu@netcom.com>
Charlie (charlie@flychina.com) wrote:
: Songtao Chen <songtao@nortel.ca> wrote
: > Could anyone tell me how to open a file for both
: > read and write ?
: open(FH,"+>filename") || die "Cannot open filename\n";
For some reason, reading this bit of advice has caused an early 1960's
instrumental by the Surfaris to start playing in my head...
------------------------------
Date: Wed, 10 Sep 1997 08:32:03 +1100
From: Ron Savage <rpsavage@ozemail.com.au>
Subject: Re: How to rename /etc/passwd ?
Message-Id: <3415C053.2A9C@ozemail.com.au>
Robert J Migliore wrote:
[snip]
> Not to avoid your question, but how do people go about copying files in
> general.. ? I've been using shell commands and to my knowledge there is
> no copy function (at least in any of the perl books I own).
>
> -Rob
Some versions of Perl 5 come with File::Copy(.pm).
------------------------------
Date: Tue, 09 Sep 1997 18:38:49 GMT
From: faust@wwa.com (Faust Gertz)
Subject: Re: I think this is a simple question
Message-Id: <34159624.648719@news.wwa.com>
On 9 Sep 1997 15:01:13 GMT, "Scott" <haleysco@imsports.msu.edu> wrote:
>Folks,
> Here's the deal: I'm working on a web-based mortgage ammortization
>applet. My Perl script receives the necessary input from the first form
>and I've got all the calculations down but I can't figure out how the print
>the output.
>
>I would like it to look something like this:
>
>Beginning Balance Interest Paid Payment Ending Balance
>100,000 1000 1500 98,500
>98,500 9850 1500 etc.
>
>My problem is that I don't understand how to keep calculating and printing
>at the same time. For example how can I set the beginning balance in the
>2nd line equal the the ending balance in the first line?
I am sure that this cannot be the answer to your question, but I will
try anyway.
Beginning Balance Interest Paid Payment Ending Balance
$BB1 $IP1 $P1 $EB1
$BB2 $IP2 $P2 $EB2
etc . . . .
$EB1 = $BB1 - $IP1 - $P1
$BB2 = $EB1
etc . . . .
Perhaps you could use a for loop to save on some typing.
Like I said. This kind of answer just seems too simple to be te one
you seek.
HTH
Faust Gertz
Philosopher at Large
------------------------------
Date: Tue, 09 Sep 1997 16:39:18 -0400
From: ken@forum.swarthmore.edu (Ken Williams)
Subject: Re: Is it a module, or what?
Message-Id: <ken-0909971639180001@news.swarthmore.edu>
In article <Pine.GSO.3.96.970905163639.24123X-100000@julie.teleport.com>,
Tom Phoenix <rootbeer@teleport.com> wrote:
>
>I don't know; are you doing what it says in the perlmod(1) manpage? (Be
>sure that you start with h2xs, since that's really the only way to make
>modules.)
What? Is this true? Haven't I made modules before that don't use C code
and don't use h2xs? In fact, the Camel book says how to make modules but
doesn't seem to mention h2xs.
Perhaps you mean this is the only _good_ way to make _precompiled_
modules, provided you know C and you don't mind hiding/obscuring your
source code.
I'm no expert on this, so correct any misconceptions I have.
-Ken Williams
The Math Forum
ken@forum.swarthmore.edu
------------------------------
Date: Tue, 09 Sep 1997 16:13:20 -0400
From: ken@forum.swarthmore.edu (Ken Williams)
Subject: Migrating to Berkeley db 2 using DB_File?
Message-Id: <ken-0909971613200001@news.swarthmore.edu>
Hi-
I rely on Berkeley DB files for some very mission-critical applications.
I've experienced some unstable behavior with them, and I've read that the
Berkeley folks want people to move to version 2. I'm happy to do so.
However, I can't figure out how to do so gracefully using DB_File.
If I build DB_File with DB version 2, then won't all my programs that rely
on DB_File be broken until I switch their databases to the new file
format? If true, this seems not-so-good. I can't do this all in one fell
swoop, and people rely on these programs all the time.
I'd much rather that the new DB_File (which will fully support version 2
DB) not be called DB_File anymore. Then I could switch each program to
version 2 as I build my confidence in the new products. Doesn't it make
sense to give a new module a new name?
Of course, if someone can tell me a gentle, gradual way to migrate to DB
version 2, I'd sure appreciate it.
Thanks.
-Ken Williams
The Math Forum
ken@forum.swarthmore.edu
------------------------------
Date: 9 Sep 1997 23:30:35 GMT
From: ilya@math.ohio-state.edu (Ilya Zakharevich)
Subject: Re: Minimizing Memory Needed for Numbers Read from Binary Files
Message-Id: <5v4m6r$mr4@agate.berkeley.edu>
In article <5v2182$j3r@agate.berkeley.edu> I wrote:
> > $array[$j][$i] = '3.1415927'; # 234 Mb
> > $array[$j][$i] = 1; # 80 Mb
> > $array[$j][$i] = $PI; # 184 Mb
> > $array[$j][$i] = unpack "f", $string; # 96 Mb
>
> Doing it here with a 400x200 array gives
> '3.1415927' => 3.37M # scaled 270M
> 1 => 1.76M # scaled 88M
> 3.1415927 => 2.09M # scaled 104M
> unpack 'f', "\332\cOI\@" => 2.09M # scaled 104M
>
> Let us count: 2000 arrays of length 2000, approx 4M words. 4M perl
> variables, 12M words.
> Integers: 4M words, total 20M words => 80M. Perl OK.
> Floats: 8M words, total 24M words => 96M. Perl OK.
> Strings: 4M pointers + 4M 3-words => 128M. Perl could be better.
Sorry, momentary brain damage. It is as expected. Perl is OK.
Count again: 2000 arrays of length 2000, approx 4M words. 4M 3-word
perl variables, 12M words. 4M perl 3-word string descriptors, 12M
words. 4M 3-word strings, 12M words.
40M words total, 160M taken. I checked a 10x scaled down example, and
it takes 17M (quite reasonable counting memory overhead and array variables
which I did not count above):
env PERL_DEBUG_MSTATS=2 perl -e \
"while ($i<2000) {$j=0;$a[$i][$j++]='3.1415926' while $j<200;$i++}"
Memory allocation statistics after compilation: (buckets 4(4)..8188(8192)
13968 free: 138 121 1 6 10 1 1 1 1 0 0
430 58 39 37 4
59116 used: 117 133 188 56 6 7 3 15 2 0 1
81 112 301 89 21
Total sbrk(): 73728/20:118. Odd ends: pad+heads+chain+tail: 0+644+0+0.
Memory allocation statistics after execution: (buckets 4(4)..8188(8192)
15768 free: 138 121 64 6 10 9 5 0 0 0 0
430 68 36 11 4
16835156 used: 117 133 188 56 6 7 3 11654 2 0 2
81 400112 304 2089 21
Total sbrk(): 17129472/191:289. Odd ends: pad+heads+chain+tail: 0+67604+0+210944.
> And it looks like my malloc() is worse than yours (or statistics with
> PERL_DEBUG_MSTATS=2 is buggy). Need to investigate this.
Just wrong scaling in the previous message. There are other overheads
which are relevant in my example, but negligeable in yours.
Everything is OK in *my* perl. Your "unpack" looks broken indeed, try
to add 0 to the results,
0 + unpack "f", $string;
And your malloc() is very unefficient with 10-byte-long allocations
for '3.1415927'. (Perl's malloc() with jumbo-malloc-patch.)
Ilya
------------------------------
Date: 10 Sep 1997 10:15:43 +1200
From: Phil Abercrombie <Philip.Abercrombie@MCS.VUW.AC.NZ>
Subject: Re: Q: bitwise operators and perl
Message-Id: <6wg1re8774.fsf@bats.mcs.vuw.ac.nz>
Cameron Hart <cam@plain.co.nz> writes:
[...]
> $ARRAY[0] = [
> '3391401472',
> '4294967040'
> ];
>
[...]
> If you perform an & on these numbers, like I tried in the perl debugger
> you should get
>
> (4294967040 & 3391401473) = 3391401472
>
> which would be a match. But for some reason
>
> ($ARRAY[$i][1] & $addr) = 1243917825
>
> What I want to know is why, and how can I get the value I am really
> after?
The _why_ is probably because perl is doing a bitwise and on the bytes of the
string, just as it is supposed to (although your numbers don't pan out).
To get the value you're really after, try saying
$ARRAY[0] = [ 3391401472, 4294967040 ]; # (no quotes)
(and similarly force $addr to be an integer, not a string).
(Having said this, I usually handle network addresses as four-byte
strings by preference, not as 32-bit integers)
-phil
--
Phil Abercrombie
Victoria University of Wellington
+64 4 495 5126
------------------------------
Date: Tue, 09 Sep 1997 21:10:41 GMT
From: dnelson@airmail.net (Dan Nelson)
Subject: Re: removing shell comments from ksh scripts
Message-Id: <6FD0EF29687586FC.B9B00A7A2568E771.62E0951F9A2A9949@library-proxy.airnews.net>
On Tue, 09 Sep 1997 15:51:28 +0100, James Hunt
<jhunt@mltsa.uk.lucent.com> wrote:
>
>k=${j##*/} # comment
>
>...where the program has to know that the 1st hash isn't a comment
>character.
>
If the hash is always enclosed in braces, just keep track of the
braces to see if a comment has started.
Hope this works.
Dan
------------------------------
Date: 10 Sep 1997 00:06:13 GMT
From: mweber@vt.edu (Matt Weber)
Subject: Server Push problem...I think
Message-Id: <5v4o9l$262$1@solaris.cc.vt.edu>
Here is the deal: I have a perl script that is executed from the web. The
problem is that it takes way too long for it to give any output to the user. I
want to do something that gives output to the user right away, while the script
finishes executing. I was thinking of a server push. However, this will not
help me because the web server still waits for the script to finish executing
before it creates any output...even server push.
Any suggestions?
M. Weber
http://www.weberworld.com
------------------------------
Date: 9 Sep 1997 14:52:22 GMT
From: mjw101@york.ac.uk (Dirge )
Subject: SQL Server, ODBC and problems
Message-Id: <5v3nr6$d12$1@netty.york.ac.uk>
Hiya,
We're running MS SQL server on an NT box, and using Win32::ODBC based
scripts to access the server. Now comes the fun script.
These cgi scripts run fine on a '95 box with a system DSN setup to access
the SQL server.
They do *not* run fine when precisely the same scripts are run on the NT
server itself, with precisely the same System DSN set up on the server.
Investigating the SQL log file reveals that the script appears to be
asking for an invalid DSN (it isn't).
Any suggestions? The scripts should eventually be run on the NT box, the
reason we're using the SQL server rather than a normal system dsn is
because other machines need to access the database.
Cheers in advance,
--
/\ Michael /\
< > Only cat lovers know the joy of a fur-covered < >
\/ musical hot-water bottle that never goes cold. \/
------------------------------
Date: Tue, 9 Sep 1997 21:19:29 GMT
From: genepool@netcom.com (Jim Michael)
Subject: Re: sumcheck generator wanted
Message-Id: <genepoolEG9FBt.4E8@netcom.com>
Dennis Kowalski (dennis.kowalski@daytonoh.ncr.com) wrote:
: Does anyone know of a sumcheck generator similar to the UNIX sum command
: that will run in a NT/WIN95 environment ?
What type of checksum do you require. I did extensive searching of
dejanews on this subject so can point you to several items of interest. I
settled on an MD5 solution. I also wrote a table driven CRC in Perl based
on previously posted c code.
Cheers,
Jim
------------------------------
Date: Tue, 9 Sep 1997 15:33:46 -0400
From: "Richard J. Marisa" <rjm2@cornell.edu>
Subject: system() use in forked server process ?
Message-Id: <Pine.OSF.3.96.970909151501.4069H-100000@cupid.cit.cornell.edu>
A few days ago, I wrote the following:
>Wrong status from system() in child process ?
>
>I'm having trouble getting the return status from a system()
>call. It works fine if I create a test script, but in my
>application $? is always -1 after the system call. The only
>difference is that the application calls system from within a
>child (forked) process. Is there anything strange about the
>status returned to child processes?
The key part that I missed was that this was a forked *server* process
modeled after the multithreaded server example in "man perlipc". That
means it includes code like:
my $waitedpid = 0;
my $paddr;
sub REAPER {
$waitedpid = wait;
$SIG{CHLD} = \&REAPER; # loathe sysV
logmsg "reaped $waitedpid" . ($? ? " with exit $?" : '');
}
$SIG{CHLD} = \&REAPER;
Now, the Camel Book section on "wait" notes that system() does a wait and
could harvest the wrong process. Indeed, when I commented out the
installation of the handler, all of my system() calls returned meaningful
results. But... I have the dread accumulation of zombie processes.
The manual says that I need to use waitpid to solve the zombie problem.
But how? If there are several server processes outstanding, how can I
waitpid for more than one at a time? Do I have to poll all of the
outstanding processes with non-blocking flags to catch which ones expired?
I sure could use an example of a server written this way... one that will
let me use system() in the server process and return meaningful status
returns. I would guess this must be a common (if complicated) idiom.
By the way, another problem I have is apparent asynchronous behavior from
system() ... as if the call returns before the operation is finished. Can
this be caused by the wait() called by system() harvesting the wrong
process and returning too soon? Why doesn't system() do a waitpid ?
Configuration: Perl 5.004 on Digital Unix 4.0
Richard Marisa, Special Projects: Electronic Publishing Initiatives
Office of Information Technology, Cornell University
110 Maple Avenue, Room 109, Ithaca, NY 14850
rjm2@cornell.edu (607) 255-7636
------------------------------
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 1003
**************************************