[11946] in Perl-Users-Digest
Perl-Users Digest, Issue: 5546 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon May 3 00:07:34 1999
Date: Sun, 2 May 99 21:00:20 -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 Sun, 2 May 1999 Volume: 8 Number: 5546
Today's topics:
Re: An attempt to compare the performance of perl vs co (Ilya Zakharevich)
Re: An attempt to compare the performance of perl vs co <tchrist@mox.perl.com>
Re: An attempt to compare the performance of perl vs co <tchrist@mox.perl.com>
Re: An attempt to compare the performance of perl vs co <ebohlman@netcom.com>
ANNOUNCE: Experienced perl programmer needed! (Richard Elliot)
Re: Apache mod_perl script won't exit on Apache::exit() <steveb@web.co.nz>
calling with strings <joeyandsherry@mindspring.com>
Can I output contents of multiple subdirectories? <portboy@home.com>
embed cgi in HTML (Scruffles)
Re: embed cgi in HTML <memberjh@yahoo.com>
Re: Filtering a file (Larry Rosler)
Re: for ($i = 0, $i <= 29470, $i++} -- 29470 too high? (Rob Sweet)
Re: for ($i = 0, $i <= 29470, $i++} -- 29470 too high? (Tad McClellan)
Re: global var disappearing, reappearing <otis@my-dejanews.com>
Re: global var disappearing, reappearing <tchrist@mox.perl.com>
How could I use the typeglobs in a hash? <Bauli_Yang@via.com.tw>
Re: is o'reilly auctioning off llama books? <bowman@montana.com>
Re: Need help creating Date arrays (Ronald J Kimball)
Re: Newsfeed and Local Weather (Kai Henningsen)
Re: RegEx for matching Mbx "From " delimeter (Ronald J Kimball)
stuctured data object for export <ryandav@u.washington.edu>
Re: stuctured data object for export (Tad McClellan)
Re: stuctured data object for export <ebohlman@netcom.com>
Re: unos problemitas (Tad McClellan)
Whats wrong? esalmon@packet.net
writing binary data to a file <frankhale@worldnet.att.net>
Re: writing binary file (Tad McClellan)
Re: writing binary file (Larry Rosler)
Re: writing binary files in Perl (Rob Sweet)
Re: writing binary files in Perl (Ronald J Kimball)
Special: Digest Administrivia (Last modified: 12 Dec 98 (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 3 May 1999 00:19:39 GMT
From: ilya@math.ohio-state.edu (Ilya Zakharevich)
Subject: Re: An attempt to compare the performance of perl vs compiled perl vs C
Message-Id: <7giq2r$ggj$1@mathserv.mps.ohio-state.edu>
[A complimentary Cc of this posting was sent to David Cassell
<cassell@mail.cor.epa.gov>],
who wrote in article <372CDEA5.3A2D740D@mail.cor.epa.gov>:
> But these times suggest that there might be some non-optimal
> elements in your Perl code.
>
> Tom Christiansen's [possibly mythological] Perl vs. C bet with
> Rob Kolstad makes me wonder if a factor of 29 [or so] is a little
> high to expect, even for something like this. The rumor I heard
> said that Tom never had to pay off on his bet.
As demonstrated many times, a typicaly slowdown C-->Perl of a program
which does not map into powerful Perl primitives is 200x. The idea of
Tom is that typical problems for a system administrator map *well*
into Perl primitives, thus a lot of time is spent inside highly
optimized C code of perl executable.
Numerical-intensive problems are an absolutely different topic.
> > # perl uncompiled (sum_array.pl) -> 58 sec:
>
> > # perl compiled to bytecode (from sum_array.pl) -> 58 sec:
>
> > # perl compiled to an executable (from sum_array.pl) -> 22 sec:
>
> I really didn't expect to see this large of a change here.
AFAIK, there should be no change (but I may be mixing C backend with
CC backend), This makes 27x figure quite suspicious (I would expect
something closer to 200x).
Ilya
------------------------------
Date: 2 May 1999 18:26:22 -0700
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: An attempt to compare the performance of perl vs compiled perl vs C
Message-Id: <372ced2e@cs.colorado.edu>
Oh joy of joy. More bullshit Fear Uncertainty and Doubt.
--tom
--
"And I don't like doing silly things (except on purpose)."
--Larry Wall in <1992Jul3.191825.14435@netlabs.com>
------------------------------
Date: 2 May 1999 18:32:31 -0700
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: An attempt to compare the performance of perl vs compiled perl vs C
Message-Id: <372cee9f@cs.colorado.edu>
[Excerpted for purposes of review from p79-80 of _The Practice of
Programming_, 1999, by Brian Kernighan and Rob Pike.]
PLATFORM 250mhz Irix 400mhx pII MS line count
C 0.36 sec 0.30 sec 150
Java 4.9 9.2 105
C++/STL/deque 2.6 11.2 70
C++/STL/list 1.7 1.5 70
Awk 2.2 2.1 20
Perl 1.8 1.0 18
The Perl version is similar [to the Awk version], but uses an anonymous
array instead of a third subscript to keep track of suffixes; it also uses
multiple assignment to update the prefix. Perl uses special characters to
indicate the types of variables: $ marks a scalar and @ an indexes array,
while brackets [] are used to index arrays and braces {} to index hashes.
# markov.pl: markov chain algorithm for 2-word prefixes
$MAXGEN = 10000;
$NONWORD = "\n";
$w1 = $w2 = $NONWORD; # initial state
while (<>) { # read each line of input
foreach (split) {
push(@{$statetab{$w1}{$w2}}, $_);
($w1, $w2) = ($w1, $_); # multiple assignment
}
}
push(@{$statetab{$w1}{$w2}}, $NONWORD); # add tail
$w1 = $w2 = $NONWORD;
for ($i = 0; $i < $MAXGEN; $i++) {
$suf = $statetab{$w1}{$w2}; # array reference
$r = int(rand @$suf); # @$suf is number of elems
exit if (($t = $suf->[$r]) eq $NONWORD);
print "$t\n";
($w1, $w2) = ($w1, $t); # advance chain
}
As in the previous programs, the map is stored using the variable
statetab. The heard of the program is the line
push(@{$statetab{$w1}{$w2}}, $_);
which pushes a new suffix onto the end of the (anonymous) array stored at
$statetab{$w1}{$w2}. In the generation phase, $statetab{$w1}{$w2} is a
reference to an array of suffixes, and $suf->[$r] points to the r-th
suffix.
Both the Perl and Awk programs are short compared to the three earlier
versions, but the are harder to adapt to handle prefixes that are not
exactly two words. The core of the C++ STL implementation (the add and
generate functions) is of comparable length and seems clearer.
Nevertheless, scripting languages are often a good choice for experimental
programming, for making prototypes, and even for production use if run-time
is not a major issue.
--
s = (unsigned char*)(SvPVX(sv)); /* deeper magic */
--Larry Wall, from util.c in the v5.0 perl distribution
------------------------------
Date: Mon, 3 May 1999 02:26:53 GMT
From: Eric Bohlman <ebohlman@netcom.com>
Subject: Re: An attempt to compare the performance of perl vs compiled perl vs C
Message-Id: <ebohlmanFB4xGu.3ns@netcom.com>
Tom Christiansen <tchrist@mox.perl.com> wrote:
: [Excerpted for purposes of review from p79-80 of _The Practice of
: Programming_, 1999, by Brian Kernighan and Rob Pike.]
[snip]
: : # markov.pl: markov chain algorithm for 2-word prefixes
: $MAXGEN = 10000;
: $NONWORD = "\n";
: $w1 = $w2 = $NONWORD; # initial state
: while (<>) { # read each line of input
: foreach (split) {
: push(@{$statetab{$w1}{$w2}}, $_);
: ($w1, $w2) = ($w1, $_); # multiple assignment
Is there a typo here? I don't see how $w1 ever gets set to anything but
$NONWORD anywhere in the program.
: }
: }
: push(@{$statetab{$w1}{$w2}}, $NONWORD); # add tail
: $w1 = $w2 = $NONWORD;
: for ($i = 0; $i < $MAXGEN; $i++) {
: $suf = $statetab{$w1}{$w2}; # array reference
: $r = int(rand @$suf); # @$suf is number of elems
: exit if (($t = $suf->[$r]) eq $NONWORD);
: print "$t\n";
: ($w1, $w2) = ($w1, $t); # advance chain
Similarly here.
: }
------------------------------
Date: Mon, 03 May 1999 03:40:06 GMT
From: relliot@pacificnet.net (Richard Elliot)
Subject: ANNOUNCE: Experienced perl programmer needed!
Message-Id: <372d1a73.3118800@news.supernews.com>
High level perl programmer sought for employment with Los Angeles
based ISP headquartered at Universal Studios. Stimulating projects,
excellent wage, benefits and profit sharing program available to
talented and motivated team players.
Requirements:
Extensive experience with UNIX based perl programming.
Solaris background preferred.
Linux experience a plus.
Extensive experience with CGI
sendmail and Qmail experience a plus.
SQL experience a plus
Previous ISP employment preferred.
Please Email resume or inquiry to:
Richard Elliot
relliot@pacificnet.net
PacificNet
www.pacificnet.net
------------------------------
Date: Mon, 03 May 1999 15:18:19 +1200
From: Steve Baker <steveb@web.co.nz>
Subject: Re: Apache mod_perl script won't exit on Apache::exit();
Message-Id: <372D157B.D64F7B4F@web.co.nz>
> Sounds like a problem for a newsgroup with cgi in its name
not really, mod_perl is not cgi. its mod_perl
thanks for being no help at all
------------------------------
Date: Sun, 2 May 1999 23:52:43 -0400
From: <joeyandsherry@mindspring.com>
Subject: calling with strings
Message-Id: <7gj6s2$pln$1@nntp2.atl.mindspring.net>
Thanks for your assistance:
I wish to write a script that I can link to with somewhat this format:
http://mydomain.com/cgi-bin/thescript.pl
But, I'd also like to include a string value with the link
some what like this:
http://mydomain.com/cgi-bin/thescript.pluserid=1234
and have the ability to recognize the strings value.
Any assistance would be greatly appreciated.
THANKS!
--
Joey Cutchins
President
Trading Post.Com, L.L.C.
http://internettradingpost.com
ceo@internettradingpost.com
------------------------------
Date: Mon, 03 May 1999 03:35:27 GMT
From: Mitch <portboy@home.com>
Subject: Can I output contents of multiple subdirectories?
Message-Id: <372D19EF.5DA9C07C@home.com>
Let me lay the groun work for my question first:
Currently my script is using a "base" directory say /foo/bar. In that
directory are stored sub directories and files, e.g.
/foo/bar/1234/foo.pem and bar.pem, or /foo/bar/5678/foo.pem and
bar.pem. These files are strictly ascii text. Now, my question is -
How can I output the contents of all directories under /foo/bar? At the
same time, how can I also provide a header containing the subdirectory
name, and filenames of everything being printed out?
Any and all help is apprecited,
Mitch
------------------------------
Date: Mon, 03 May 1999 00:55:09 GMT
From: scruffles*nospam*@geocities.com (Scruffles)
Subject: embed cgi in HTML
Message-Id: <372cf2cb.515071193@news.inlink.com>
I want to inclued a CGI generated peice of HTML into a web page. I
would like to be able to load the web page into an HTML editor when
needed, so making the hole thing a Here document is out of the
question (unless I am missing something).
What I want to do is something like
<!--#exec cgi="/path/to/script.cgi"-->
to embed the script's output (I got this from
http://www.inlink.com/support/web/personal/cgi.html )
or
as geocities uses it: <!--#geoguide-->
How do these work? Are they web server specific? Where can I get
more information?
------------------------------
Date: Sun, 2 May 1999 21:32:07 -0400
From: "Jane H." <memberjh@yahoo.com>
Subject: Re: embed cgi in HTML
Message-Id: <7giu7n$did@dfw-ixnews12.ix.netcom.com>
The proper term is "server side include".
Try one of the search engines for further documentation. I did a search on
http://www.alingo.com and it yielded:
http://conan.itc.virginia.edu/ssi.html
seems thorough enough.
Scruffles wrote in message <372cf2cb.515071193@news.inlink.com>...
>I want to inclued a CGI generated peice of HTML into a web page. I
>would like to be able to load the web page into an HTML editor when
>needed, so making the hole thing a Here document is out of the
>question (unless I am missing something).
>
>What I want to do is something like
><!--#exec cgi="/path/to/script.cgi"-->
>to embed the script's output (I got this from
>http://www.inlink.com/support/web/personal/cgi.html )
>
>or
>
>as geocities uses it: <!--#geoguide-->
>
>How do these work? Are they web server specific? Where can I get
>more information?
------------------------------
Date: Sun, 2 May 1999 19:56:26 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Filtering a file
Message-Id: <MPG.1196b03956ba26e3989999@nntp.hpl.hp.com>
In article <l0hhg7.s21.ln@magna.metronet.com> on Sun, 2 May 1999
08:38:45 -0400, Tad McClellan <tadmc@metronet.com> says...
+ Larry Rosler (lr@hpl.hp.com) wrote:
...
+ : my $re = join '|', map quotemeta, @trigger_strings;
+ : /$re/o and print while <>;
...
+ This program gives different output if you swap the commented lines:
+
+ ----------
+ #!/usr/bin/perl -w
+ use strict;
+
+ #my @trigger_strings = qw(catalog cat);
+ my @trigger_strings = qw(cat catalog);
+
+ my $re = join '|', map quotemeta, @trigger_strings;
+
+ /($re)/o and print "'$1'\n" while <DATA>;
+
+ __DATA__
+ i have a catalog
+ no Catalog here
+ i have another catalog here
+ ----------
I felt that adding a suggestion to bracket the regex with /\b($re)\b/o
to deal with this problem of partial-word matches was beyond the needs
or capabilities of the submitter.
--
(Just Another Larry) Rosler
Hewlett-Packard Company
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Mon, 03 May 1999 00:03:46 GMT
From: sweet@enterpriseusa.com (Rob Sweet)
Subject: Re: for ($i = 0, $i <= 29470, $i++} -- 29470 too high?
Message-Id: <372ce7a6.18812981@news.msen.com>
You should be using a semicolon not a comma as a delimiter. The
commas are creating a list with three elements, which you are then
iterating.
Rob Sweet
----
On Sun, 02 May 1999 15:10:46 -0700, Daniel <dbohling@earthlink.net>
wrote:
> Hi all, I am having a strange problem with the following for loop:
> <...snip...>
>for ($i = 0, $i <= 29470, $i++) {
------------------------------
Date: Sun, 2 May 1999 16:38:55 -0400
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: for ($i = 0, $i <= 29470, $i++} -- 29470 too high?
Message-Id: <v4dig7.hj1.ln@magna.metronet.com>
Rob Sweet (sweet@enterpriseusa.com) wrote:
: You should be using a semicolon not a comma as a delimiter.
s/delimiter/separator/;
A "delimiter" marks both "limits", the start and end, like
"double quotes".
A separator marks the end of one "thing" and the beginning
of the next thing, like the space characters in this sentence.
Precise terminology is important when discussing technical topics :-)
: The
: commas are creating a list with three elements, which you are then
: iterating.
: On Sun, 02 May 1999 15:10:46 -0700, Daniel <dbohling@earthlink.net>
: wrote:
: > Hi all, I am having a strange problem with the following for loop:
: >for ($i = 0, $i <= 29470, $i++) {
--
Tad McClellan SGML Consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Mon, 03 May 1999 00:53:44 GMT
From: Otis Gospodnetic <otis@my-dejanews.com>
Subject: Re: global var disappearing, reappearing
Message-Id: <7gis2o$phs$1@nnrp1.dejanews.com>
In article <372c68e1@cs.colorado.edu>,
tchrist@mox.perl.com (Tom Christiansen) wrote:
> [courtesy cc of this posting sent to cited author via email]
>
> In comp.lang.perl.misc, Otis Gospodnetic <otis@my-dejanews.com> writes:
> :I knew somebody would say that :)
> :True, I should use 'use vars' to make it global, I guess.
> :However, how come that a my-ed variable declared right at the beginning of
> :script (outside any blocks) is sometimes seen properly from within
subroutines
> :and sometimes it is not?
> :Why the inconsistency?
>
> There is no inconsistency. But perhaps you have some mistaken
> notion that lexical variable are shared amongst threads.
>
> They aren't.
But have you checked the output of the script I provided in the original post?
Here is what I get:
.......
Adding Thread 1
Adding Thread 2
tMax: 2
Thread 1 of 2 working on 1
Use of uninitialized value at /tmp/dn.pl line 32.
tMax:
Use of uninitialized value at /tmp/dn.pl line 33.
Thread 2 of working on 2
Free Thread Slot 1
tMax: 2
.......
tMax above is first visible (has value 2), then it is not visible (undefined
val warning), and then in stays seen. One thread sees it, the other one
doesn't and then both start seeing it.
weird, no?
Otis
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
------------------------------
Date: 2 May 1999 20:05:48 -0700
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: global var disappearing, reappearing
Message-Id: <372d047c@cs.colorado.edu>
[courtesy cc of this posting sent to cited author via email]
In comp.lang.perl.misc,
Otis Gospodnetic <otis@my-dejanews.com> writes:
:weird, no?
yes. i haven't gotten to playing with it more, though.
--tom
--
s = (char*)(long)retval; /* ouch */
--Larry Wall in doio.c from the perl source code
------------------------------
Date: Mon, 03 May 1999 11:47:42 +0800
From: Bauli Yang <Bauli_Yang@via.com.tw>
Subject: How could I use the typeglobs in a hash?
Message-Id: <372D1C5E.B41E4EAA@via.com.tw>
I know I can pass the parameters by the following way:
*b = *a;
But the syntax *foo{THING} returns a reference to the THING slot in
*foo.
Is it the native restrict that the typeglobs can not be specified for
the values of the hash table in Perl script?
such as *HASH{$key} = *array;
------------------------------
Date: Sun, 2 May 1999 19:30:06 -0600
From: "bowman" <bowman@montana.com>
Subject: Re: is o'reilly auctioning off llama books?
Message-Id: <k%6X2.2695$Ny1.15624@newsfeed.slurp.net>
Uri Guttman <uri@sysarch.com> wrote in message
news:x7k8ur4cxj.fsf_-_@home.sysarch.com...
>
> this article intrigued me. it says "llamas start at $500"!! what could
> make them charge so much? special editions? autographed by every major
> perl hacker? special deodorants? a personal tuturial session with randal?
If you want a less expensive llama, I can get you one real cheap. Too damn
many of the things in Montana, a few won't be missed. How about some sheep
so they won't get lonely?
--
Bear Technology -- making Montana safe for grizzlies
http://people.montana.com/~bowman
------------------------------
Date: Sun, 2 May 1999 23:02:18 -0400
From: rjk@linguist.dartmouth.edu (Ronald J Kimball)
Subject: Re: Need help creating Date arrays
Message-Id: <1dr78xl.ga053j9beqnyN@p54.tc1.state.ma.tiac.com>
Lyndon F. Bartels <lbartels@pressenter.com> wrote:
> Is there a way to do two dimensional arrays? I'd like to build columns on each
> page, reading left to right. I need to
> keep track which column, or table field, I'm currently writing to in each
> file.
You want to look at the perllol, perldsc, perlreftut, and perlref
manpages. They all deal with references and multi-dimensional data
structures.
--
chipmunk (Ronald J Kimball) <rjk@linguist.dartmouth.edu>
perl -e 'print map chop, sort split shift, reverse shift
' 'j_' 'e._jP;_jr/_je=_jk{_jn*_j &_j :_j @_jr}_ja)_js$_j
~_jh]_jt,_jo+_jJ"_jr>_ju#_jt%_jl?_ja^_jc`_jh-_je|' -rjk-
------------------------------
Date: 02 May 1999 21:47:00 +0200
From: kaih=7G5oWCd1w-B@khms.westfalen.de (Kai Henningsen)
Subject: Re: Newsfeed and Local Weather
Message-Id: <7G5oWCd1w-B@khms.westfalen.de>
rra@stanford.edu (Russ Allbery) wrote on 01.05.99 in <ylvhedb5qj.fsf@windlord.stanford.edu>:
> I don't think TIMTOWTDI is just a theoretical concept to Larry.
But 19$Year is *not* a way to do it.
In fact, it never was.
>The
> script works. :)
For 8 months, counting from yesterday.
> The fact you can use barewords in Perl is still a feature. :)
Yep.
A *mis*feature.
Kai
--
http://www.westfalen.de/private/khms/
"... by God I *KNOW* what this network is for, and you can't have it."
- Russ Allbery (rra@stanford.edu)
------------------------------
Date: Sun, 2 May 1999 23:02:19 -0400
From: rjk@linguist.dartmouth.edu (Ronald J Kimball)
Subject: Re: RegEx for matching Mbx "From " delimeter
Message-Id: <1dr791e.l075pb4fuim8N@p54.tc1.state.ma.tiac.com>
Ronald J Kimball <rjk@linguist.dartmouth.edu> wrote:
> while (<>) {
> if (/^From /) { # new mail message
> ($email, $date) = split(' ', $_, 2);
> # do other stuff
> }
> }
P.S. I should have written this instead:
(undef, $email, $date) = split(' ', $_, 3);
because the first column is the word 'From', of course. :)
--
_ / ' _ / - aka -
( /)//)//)(//)/( Ronald J Kimball rjk@linguist.dartmouth.edu
/ http://www.tiac.net/users/chipmunk/
"Remember, Perl doesn't write bad programs; programmers do."
------------------------------
Date: Sun, 2 May 1999 17:51:47 -0700
From: "R. David Whitlock" <ryandav@u.washington.edu>
Subject: stuctured data object for export
Message-Id: <Pine.A41.4.10.9905021727070.17422-100000@dante35.u.washington.edu>
I'm having some troubles with my move down the path of perl tao, namely my
comprehension of the construction techniques sometimes used to create
happy little structured data objects suitable for returning to other
programs to be accessed in nice readable ways....
I would like to ask the collective assistance of a perl guru or two to
help me get past this minor setback, fully acknowledging the ever present
tenet of all perly knowledge, There's More Than One Way To Do It...
I have a subroutine which calls other subroutines to generate several
data objects and which needs to then return some sort of data structure
which contains all of the data it has collected. I have three arrays of
variable length and a long string that I need to give back to any program
calling my function, and I need to return a single item ( a hash I guess)
so that someone could easily extract the info they seek from the object.
I am visualizing something like the following:
my @Array1 = &Func1(...);
my @Array2 = &Func2(...);
my @Array3 = &Func3(...);
my $String = &Func4(...);
foreach $foo (@Array1) {
assignment into my hash or whatnot
}
# repeat addition to hash or whatnot until I have a final %hash
# and then...
return %hash
So that someone can then call the program, receive the %hash from the
return, and then look at the elements, like say, all the $foo's in
@Array1.
The part I am unable to comprehend would seem to be the heart of this
function, spooling all of this data into some nice object to ship off to
elsewhere.
I appreciate all relevant comment, and am willing to learn more in my path
to enlightenment. This is, in case anyone is interested, a program to get
a set of MAC addresses behind some layer2 device as well as the associated
IP's that are in use currently by consulting a number of automatically
generated files, and then supplying the contact info for the layer2 device
in question. This is so that if a hub or whatnot loses management, we can
ping hosts behind the hub to see if it has indeed lost management or if
something like a power loss has taken down a building's connectivity. Not
that that has any relevance to the question above, but in case anyone's
doing something similar with perl (which seems eminently qualified for the
task...)
Thanks.
David (aKa, "Slave of the layer2 devices")
------------------------------
Date: Sun, 2 May 1999 17:12:55 -0400
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: stuctured data object for export
Message-Id: <n4fig7.hj1.ln@magna.metronet.com>
R. David Whitlock (ryandav@u.washington.edu) wrote:
: I'm having some troubles with my move down the path of perl tao, namely my
: comprehension of the construction techniques sometimes used to create
: happy little structured data objects
So then you have had a look at perldsc.pod
(Perl Data Structures Cookbook) that came with your
perl distribution?
: suitable for returning to other
: programs to be accessed in nice readable ways....
I'm not too clear on what is needed.
Do you need to pass the data to some non-Perl program?
Perl FAQ, part 4:
"How do I print out or copy a recursive data structure?"
points to a couple of modules that can be used for persistence.
Do you need to pass them to other Perl code?
perldoc perlref
might be helpful.
: I have a subroutine which calls other subroutines to generate several
: data objects and which needs to then return some sort of data structure
: which contains all of the data it has collected.
: I am visualizing something like the following:
[snip]
You can use a hash of (mostly) references to arrays for that.
: The part I am unable to comprehend would seem to be the heart of this
: function, spooling all of this data into some nice object to ship off to
: elsewhere.
: I appreciate all relevant comment, and am willing to learn more in my path
: to enlightenment.
Get thee to perlref.pod and perldsc.pod Grasshopper!
---------------------
#!/usr/bin/perl -w
use strict;
my %Hash = %{&build_struct};
foreach (@{$Hash{array1}}) { print "$_, "; } print "\n";
foreach (@{$Hash{array2}}) { print "$_, "; } print "\n";
print ${$Hash{string}}, "\n";
sub build_struct {
my %hash;
$hash{array1} = [ Func1() ];
$hash{array2} = [ Func2() ];
$hash{string} = Func4() ;
return \%hash;
}
sub Func1 { return (1, 2, 3, 4) }
sub Func2 { return qw(1 2 3 4) }
sub Func4 { return \'four score and seven years ago' }
---------------------
You might just use code refs to Func[1234] rather than carting
their output all around instead...
--
Tad McClellan SGML Consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Mon, 3 May 1999 02:37:44 GMT
From: Eric Bohlman <ebohlman@netcom.com>
Subject: Re: stuctured data object for export
Message-Id: <ebohlmanFB4xyw.4F0@netcom.com>
R. David Whitlock <ryandav@u.washington.edu> wrote:
: I'm having some troubles with my move down the path of perl tao, namely my
: comprehension of the construction techniques sometimes used to create
: happy little structured data objects suitable for returning to other
: programs to be accessed in nice readable ways....
Have you checked out the following (man pages | HTML documents | POD
files) that came with your installation?
perllol (Lists of lists)
perldsc (Data Structures Cookbook)
perlref (References, just about all data structures depend on them)
You might also find the first two chapters of Sriram Srinivasan's
_Advanced Perl Programming_ (the "panther" book) helpful; IMHO the
explanation is cleaner than the one in the Camel.
: I have a subroutine which calls other subroutines to generate several
: data objects and which needs to then return some sort of data structure
: which contains all of the data it has collected. I have three arrays of
: variable length and a long string that I need to give back to any program
: calling my function, and I need to return a single item ( a hash I guess)
: so that someone could easily extract the info they seek from the object.
Yes, a hash sounds like a good choice.
: I am visualizing something like the following:
: my @Array1 = &Func1(...);
: my @Array2 = &Func2(...);
:
: my @Array3 = &Func3(...);
:
: my $String = &Func4(...);
: foreach $foo (@Array1) {
:
: assignment into my hash or whatnot
:
: }
:
: # repeat addition to hash or whatnot until I have a final %hash
: # and then...
: return %hash
Better yet, have Func1, Func2 and Func3 return array *references* rather
than actual arrays. Then you can fill up the hash in one swell foop:
my %hash=(Array1=>Func1(...), Array2=>Func2(...), Array3=>Func3(...),
string=>Func4(...));
Then, thanks to some syntactic sugar, you can write things like:
$hash{Array1}[2] #the third element of the first array
Whether to return the actual hash, or a reference to it, is up to you.
------------------------------
Date: Sun, 2 May 1999 16:28:45 -0400
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: unos problemitas
Message-Id: <thcig7.hj1.ln@magna.metronet.com>
Tom Christiansen (tchrist@mox.perl.com) wrote:
: [courtesy cc of this posting sent to cited author via email]
: In comp.lang.perl.misc,
: David Cassell <cassell@mail.cor.epa.gov> writes:
: :As well as Ahnold-speak [from Terminator 2], and probably half a
: :dozen other pop-culture refs [and/or riffs].
: When my pop grows a culture, I throw it away undrunk.
When my pop grows a culture, I ask him to take a shower.
--
Tad McClellan SGML Consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Sun, 02 May 1999 23:23:22 -0400
From: esalmon@packet.net
Subject: Whats wrong?
Message-Id: <372D16AA.6389@packet.net>
How do I make the following systen command work? And possibly return the
results?
$userid = 'whoami';
------------------------------
Date: Mon, 03 May 1999 00:01:55 -0400
From: Frank Hale <frankhale@worldnet.att.net>
Subject: writing binary data to a file
Message-Id: <372D1FB3.E1ED6788@worldnet.att.net>
I didn't know this was such a funny subject. Please I am not a perl guru
as most of you here.
I'm on RedHat Linux 5.2. The man pages says that binmode has no effect
on Unix systems since it doesn't distinguish between binary and text
files.
I tried the following script
#!/usr/bin/perl
$a = 0x01;
$b = 0x02;
$c = 0x03;
open (BIN, ">bin.dat");
print BIN $a,$b,$c;
close (BIN);
This produces a normal text file with the following data
123
When in fact I want the data in binary for the numbers 1,2,3.
--
From: Frank Hale
Email: frankhale@worldnet.att.net
------------------------------
Date: Sun, 2 May 1999 16:46:05 -0400
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: writing binary file
Message-Id: <didig7.hj1.ln@magna.metronet.com>
Frank Hale (frankhale@worldnet.att.net) wrote:
: How do you write a binary file in Perl?
Perl FAQ, part 4:
"How do I handle binary data correctly?"
Perl FAQ, part 5:
"How do I randomly update a binary file?"
Neither answer your question directly, but both show
things that would be of interest to binary file
manipulations using Perl.
--
Tad McClellan SGML Consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Sun, 2 May 1999 20:32:00 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: writing binary file
Message-Id: <MPG.1196b885b8d1134798999a@nntp.hpl.hp.com>
[Posted and a courtesy copy sent.]
In article <372ce07f@cs.colorado.edu> on 2 May 1999 17:32:15 -0700, Tom
Christiansen <tchrist@mox.perl.com> says...
> In comp.lang.perl.misc,
> Frank Hale <frankhale@worldnet.att.net> writes:
> :How do you write a binary file in Perl?
>
> 1. Install an operating system.
> 2. Open the file.
> 3. Write.
Tad McLellan wrote (several times today):
Precise terminology is important when discussing technical topics :-)
So we need a precise definition of 'an operating system'. Let me try:
An 'operating system' is a set of software that supports writing and
reading binary files without having to use binmode() on them.
So we need an alternate algorithm for writing a binary file in Perl:
1. Install a non-operating system.
2. Open the file.
3. binmode() the filehandle.
4. Write.
That should do it.
--
(Just Another Larry) Rosler
Hewlett-Packard Company
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Mon, 03 May 1999 02:39:49 GMT
From: sweet@enterpriseusa.com (Rob Sweet)
Subject: Re: writing binary files in Perl
Message-Id: <372d0c58.28207637@news.msen.com>
You Probably want to lookup binmode in the perlfunc docs.
---
On Sun, 02 May 1999 19:55:14 -0400, Frank Hale
<frankhale@worldnet.att.net> wrote:
>Okay since my last question wasn't clear.
>
>I want to write data to a file in binary using Perl. I don't want to
>produce a text file but have a binary file, like how an executable file
>would be stored.
>
>I am writing an assembler in Perl so this should clarify the type of
>file I need to write.
>
>This method produces a text file.
>
>open (BIN, ">binary.dat");
>print BIN @binary_data;
>close BIN;
>
>--
>From: Frank Hale
>Email: frankhale@worldnet.att.net
------------------------------
Date: Sun, 2 May 1999 23:02:20 -0400
From: rjk@linguist.dartmouth.edu (Ronald J Kimball)
Subject: Re: writing binary files in Perl
Message-Id: <1dr798z.rv09cfkd8qlaN@p54.tc1.state.ma.tiac.com>
Frank Hale <frankhale@worldnet.att.net> wrote:
> This method produces a text file.
>
> open (BIN, ">binary.dat");
binmode(BIN);
> print BIN @binary_data;
> close BIN;
On operating systems which distinguish between text and binary files,
binmode() will prevent line endings from being translated on input and
output.
Enjoy!
--
_ / ' _ / - aka -
( /)//)//)(//)/( Ronald J Kimball rjk@linguist.dartmouth.edu
/ http://www.tiac.net/users/chipmunk/
perl -e '$_="\012534`!./4(%2`\cp%2,`(!#+%2j";s/./"\"\\c$&\""/gees;print'
------------------------------
Date: 12 Dec 98 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Special: Digest Administrivia (Last modified: 12 Dec 98)
Message-Id: <null>
Administrivia:
Well, after 6 months, here's the answer to the quiz: what do we do about
comp.lang.perl.moderated. Answer: nothing.
]From: Russ Allbery <rra@stanford.edu>
]Date: 21 Sep 1998 19:53:43 -0700
]Subject: comp.lang.perl.moderated available via e-mail
]
]It is possible to subscribe to comp.lang.perl.moderated as a mailing list.
]To do so, send mail to majordomo@eyrie.org with "subscribe clpm" in the
]body. Majordomo will then send you instructions on how to confirm your
]subscription. This is provided as a general service for those people who
]cannot receive the newsgroup for whatever reason or who just prefer to
]receive messages via e-mail.
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 5546
**************************************