[8261] in Perl-Users-Digest
Perl-Users Digest, Issue: 1878 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Feb 12 17:07:47 1998
Date: Thu, 12 Feb 98 14:00:31 -0800
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Thu, 12 Feb 1998 Volume: 8 Number: 1878
Today's topics:
(deep breath first...) Understanding "pack" <franzen@pmel.noaa.gov>
Re: (deep breath first...) Understanding "pack" <doug@tc.net>
**Perl/CGI Developers Needed - FLORIDA** <jmorris@silcoinc.com>
Re: assigning variable names (Ian Kallen)
Re: Can you flush a print statement to the browser imme <dgoddard@us.oracle.com>
CGI, PERL help needed in South Florida <mhensley@silcoinc.com>
Re: Code Example Needed <jdporter@min.net>
Re: Converting ISO-8859-1 to IBM DOS-ASCII (PC8) <pinard@iro.umontreal.ca>
CRs in scripts - ARGH! <dhardy@beagle.colorado.edu>
Re: CRs in scripts - ARGH! <jim.michael@gecm.com>
Re: Date validation (I R A Aggie)
Elements in a hash <SNIPhsommer@micro.ti.comSNIP>
Re: FAQless Forays (was: Code Example Needed) <jdporter@min.net>
Re: Fork/Threads <msackett@shn.net>
Free CGI hosting <Johncarryl@Sprintmail.com>
FTP as filehandle (Reilly Shea)
Re: garbage collection in perl (Ilya Zakharevich)
getting strings ("Rick Bauman")
Re: Help installing Text::NWrap (Gabor)
Re: How generate counter? <John.Adams@BentonvilleAR.ncr.com>
Re: How the Hell do I...? (Martin Vorlaender)
Re: Matt's Script Archive <jdporter@min.net>
Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Thu, 12 Feb 1998 11:55:22 -0800
From: Nathan Franzen <franzen@pmel.noaa.gov>
Subject: (deep breath first...) Understanding "pack"
Message-Id: <Pine.SOL.3.96.980212112635.21911C-100000@corona.pmel.noaa.gov>
With fear and trepidation in my heart I venture forth to ask a dumb
question. I guess my basic problem is that I am not yet a programmer,
merely someone whose been trying to become one for the past few months
through using Perl.
I have a couple specific problems, but rather than post the code
fragments, I'm going to first ask if there's some doumentation out there
that will allow me to fundamentally understand what I'm doing. I'd be
happy to post some code if that's a better way to get help.
I've been writing some programs that process text data files, and
everything has worked just fine. In the future, however, the data files
are going to come at me in a binary format. I have a preliminary file in
this format, and I'm trying to figure out how to read it in. Although I
have figured out one way to make it work, I do still like to understand
everything that I'm using. I don't quite get "pack".
The documentation reads:
pack TEMPLATE,LIST
Takes an array or list of values and packs it into a
binary structure, returning the string containing
the structure.
Now, I read that once and I understand it. But I read it a second time,
and realize that I don't. I don't know what the word "structure" means,
or "string", or "contains". This description is a little too terse for
me.
I need some documentation, but it may not in fact be Perl documentation I
want. Perhaps it is some primer on binary file storage. Any hints?
I've delayed posting this question for a few hours this morning. I would
very much appreciate any answer that is not (1) patronizing or (2) rude.
Please, I've spent some hours considering whether I should ask any
question at all - pause a minute or two to consider whether you should
"answer" it. And avoid being patronizing. I'm no fool.
-Nathan
------------------------------
Date: 12 Feb 1998 16:13:55 -0500
From: Douglas McNaught <doug@tc.net>
Subject: Re: (deep breath first...) Understanding "pack"
Message-Id: <m2k9b0bk6k.fsf@ono.tc.net>
Nathan Franzen <franzen@pmel.noaa.gov> writes:
> I've been writing some programs that process text data files, and
> everything has worked just fine. In the future, however, the data files
> are going to come at me in a binary format. I have a preliminary file in
> this format, and I'm trying to figure out how to read it in. Although I
> have figured out one way to make it work, I do still like to understand
> everything that I'm using. I don't quite get "pack".
Actually, what you'll more likely be using is 'unpack'. In general,
'pack' creates binary structures; 'unpack' decodes them.
> The documentation reads:
>
> pack TEMPLATE,LIST
> Takes an array or list of values and packs it into a
> binary structure, returning the string containing
> the structure.
>
> Now, I read that once and I understand it. But I read it a second time,
> and realize that I don't. I don't know what the word "structure" means,
> or "string", or "contains". This description is a little too terse for
> me.
The documentation is written from the point of view of the C-savvy
programmer (arguably Perl's original target audience). C gives you
the ability to define 'structures' using the following syntax:
struct rec {
int field1;
short field2;
char field3[42];
};
If I declare a 'rec' variable with the line
struct rec rec1;
then 'rec1' refers to a chunk of memory subdivided into three
'sub-chunks' (usually called 'members' or 'fields'). The first field
is a binary integer (usually 4 bytes on modern machines), the second
is a short int (almost always 2 bytes), and the third is an array of
42 characters (bytes).
This structure might be represented in memory as follows:
<----------------------48 bytes total size--------------------------->
+----------------------------------------------- ----------------+
|1|1|1|1|2|2|3|3|3|3|3|3|3|3|3|3|3|3|3|3|3|3|3|3\ ...\3|3|3|3|3|3|3|3|
+------------------------------------------------- ---------------+
It could also be written out to a data file, which could then be read
into a Perl string (which is nothing more than a contiguous sequence
of bytes of arbitrary length). The Perl code might look something
like this (UNTESTED):
open(FH, "binaryfile.dat") or die "Open failed: $!\n";
(read(FH, $rec1, 48) == 48) or die "Read failed: $!\n"
($field1, $field2, $field3) = unpack("isA42", $rec1);
# assumes field3 in the C struct is a normal null-terminated string
Hopefully that'll help get you started.
Now, for the caveats (mostly portability-related):
1) Format of C structures depends on the compiler.
The C compiler is free to insert arbitrary padding bytes in the
structure definition. In the example above, it might be very common
on 32-bit machines to see an extra 2 bytes inserted either before or
after the second field, in order to preserve alignment and/or improve
performance. This action by the compiler, invisible to you, will
*break* the Perl code above. It might work fine on one system but
break upon moving to a different machine, or even just a compiler
upgrade.
2) Byte ordering.
Binary integers are stored as a small sequence of bytes. There are
two commonly-used ways to arrange these bytes--either the MSB (most
significant byte) can come first in memory, or the LSB (least). The
32-bit integer 32768, expressed in hex (with C notation) as 0x8000,
would stored on my Linux Intel machine as
00 80 00 00 (in ascending order of memory address)
while on a Sparc it would be
00 00 80 00 (also in ascending order)
The first format is called "little-endian" and is used by the Intel
family, the VAX and other DEC systems (it's often called "VAX
ordering"). The second, "big-endian", is used by Motorola processors,
the Sparc, SGI's MIPS and others. Big-endian is also known as
"network byte order" because it's the standard ordering for binary
integers passed over network connections.
The 'pack' and 'unpack' template format provides ways to handle all
byte orderings. If the integer in question is in your machine's
native format, the 'i' specifier (as I've used above) will interpret
it correctly. If it's in big-endian format, 'N' will do the trick.
For little-endian, 'V' for VAX is the ticket.
For your task, you'll need a specification of the exact binary format
that your files will have. It should include record length, field
sizes and types, and any padding bytes that may be present. Make sure
that byte ordering is specified for all integer fields. You should be
able to make a "box-chain" diagram like the one above for your record
format, with all fields and padding bytes marked.
Once you have the spec and a sample file, work up an 'unpack' template
that will parse a record. It'll probably take some trial and error,
but that's what Perl is good for ;)
> I need some documentation, but it may not in fact be Perl documentation I
> want. Perhaps it is some primer on binary file storage. Any hints?
I don't know if there's any such primer. I got a lot of what I know
by reading Usenet, and a lot more by solving real-world problems. A
bit of assembly-language hacking in my younger days didn't hurt,
either.
-Doug
--
sub g{my$i=index$t,$_[0];($i%5,int$i/5)}sub h{substr$t,5*$_[1]+$_[0],1}sub n{(
$_[0]+4)%5}$t='encryptabdfghjklmoqsuvwxz';$c='fxmdwbcmagnyubnyquohyhny';while(
$c=~s/(.)(.)//){($w,$x)=g$1;($y,$z)=g$2;$w==$y&&($p.=h($w,n$x).h($y,n$z))or$x==
$z&&($p.=h(n$w,$x).h(n$y,$z))or($p.=h($y,$x).h($w,$z))}$p=~y/x/ /;print$p,"\n";
------------------------------
Date: Thu, 12 Feb 1998 16:24:26 -0500
From: "Jim L. Morris" <jmorris@silcoinc.com>
Subject: **Perl/CGI Developers Needed - FLORIDA**
Message-Id: <34e3683c.0@207.49.135.12>
I apologize if this is the wrong place to post this
message. I am a newsgroup rookie.
One of our clients located in sunny/warm Boca Raton, Florida
has several permanent developer openings for Perl and CGI
programmers. Positions are permanent and inlcude excellent
benefits and salary with one of the fastest growing Internet Web
hosting companies in the USA.
Come to Florida and enjoy warm weather
year around, a low cost of living, some of the best
beaches in the U.S., and no State Income Tax!!!!!!!!!!!
Due to the immediate needs of our client we cannot
consider H-1 candidates at this time. No 3rd party calls please.
For more info. contact: (Prefer E-mail)
Jim Morris
SILCO Software Technology, Inc.
jmorris@silcoinc.com
888-745-2646 ext. 11(toll free)
813-939-0703 (Fax)
------------------------------
Date: 12 Feb 1998 20:22:02 GMT
From: spidaman@well.com (Ian Kallen)
Subject: Re: assigning variable names
Message-Id: <6bvlla$oji$1@was.hooked.net>
: server. I am having trouble assigning the parameters names though. Could
: anyone provide me with some insight?? I can be reached at jfontaine2@aol.com
No code example, no insights offered.
--
Ian Kallen <spidaman@well.com>
"Like so many Americans, she was trying to construct a life that made
sense from things she found in gift shops."
-- Kurt Vonnegut, Jr.
------------------------------
Date: Thu, 12 Feb 1998 12:15:49 -0800
From: Denis Goddard <dgoddard@us.oracle.com>
Subject: Re: Can you flush a print statement to the browser immediately?
Message-Id: <34E35875.166DA0E4@us.oracle.com>
Rick Ryan wrote:
>
> Is there any way to "flush" the print commands to the screen
> immediately so that the user can see that something's going on?
>
See perlfaq5, 'How do I flush/unbuffer a filehandle? Why must I do this?'
HTH,
-Denis
--
__ __ _ __ __
~~~~(__)|-< /-\(__ |__(-_ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Denis Goddard, Senior Member, Tech. Staff |"I see the heads of men arise
email: dgoddard@us.oracle.com |with hungry minds and open eyes!"
ourworld.compuserve.com/homepages/d_goddard| -Rush, from 2112: _The Oracle_
------------------------------
Date: Thu, 12 Feb 1998 15:04:01 -0500
From: "Mike Hensley" <mhensley@silcoinc.com>
Subject: CGI, PERL help needed in South Florida
Message-Id: <34e35591.0@207.49.135.12>
Pardon the intrusion, but do you know of anybody that is looking for a new
job in the South Florida area?
If you do, then please have them contact me. I have requirements for
CGI , PERL programmers in South Florida.
Mike Hensley
e-mail: mhensley@silcoinc.com
------------------------------
Date: Thu, 12 Feb 1998 08:48:54 -0500
From: John Porter <jdporter@min.net>
Subject: Re: Code Example Needed
Message-Id: <34E2FDC5.31D@min.net>
Eileen Kortright wrote:
>
> I just finished perusing the 217 messages in this group to see if
> anyone has asked my question recently. I see no one has, so, at the
> risk of getting jumped on by Mr. Christiansen:
>
> 1) Yes, I've read the FAQ.
> 2) I'm not a programmer, okay? I'm
> *trying* to learn Perl for my own personal web site, not get a job as
> a programmer. 3) I have BOTH the camel and the lama open in from of
> me, as well as various OTHER texts. 4) I have a headache and I really
> would not appreciate getting one of your typical "read the FAQ" "go
> back to programming school" responses.
[Snip]
What I appreciate is the fact the Ms. Kortright is making a real
effort to Do The Right Thing before posting to the group.
For the benefit of other newbies who may be doing the right thing
by reading the group before posting to it, I would add two more
things, in addition to reading the FAQ (which, as everyone should
know, comes with every installation of Perl):
1. Check CPAN (the Comprehensive Perl Archive Network) for
modules which may applicable to your problem.
CPAN is reachable through the Perl Software Page:
(http://language.perl.com/info/software.html)
2. Search the archive of comp.lang.perl.misc at DejaNews:
http://x4.dejanews.com/filter.xp?groups=comp.lang.perl.misc
What I don't appreciate about Ms. Kortright's post is the
implication that one needn't "be a programmer" to write
correct, useful programs. Yes, Perl is easy to learn and
very easy to use, but -- unlike Visual Basic, supposedly --
it does not program itself; it does not obviate the need
to think in terms of algorithms and data structures.
Programming is expressing algorithms and data structures in
the language of your choice. If you try to write perl programs,
then you're trying to be a programmer, so you'd better be up to
the task.
John Porter
------------------------------
Date: Thu, 12 Feb 1998 20:17:08 GMT
From: =?ISO-8859-1?Q?Fran=E7ois_Pinard?= <pinard@iro.umontreal.ca>
Subject: Re: Converting ISO-8859-1 to IBM DOS-ASCII (PC8)
Message-Id: <vrpvks8toc.fsf@raptor.IRO.UMontreal.CA>
[I wonder if this reply will get posted. Much fighting with the tools :-)]
Russell Schulz <Russell_Schulz@locutus.ofB.ORG> writes:
> Kari Marttila <Kari.Marttila.@tietogroup.com> writes:
>
> > Does anybody know if there is a script or a module that knows how to
> > convert ISO-8859-1 text (I believe this is the character set used in
> > Windows) to IBM DOS-ASCII (PC8)?
>
> I assume GNU recode will do this. but if you're desperate for a pure
> perl solution, it's just one big ugly tr.
The next release of `recode' (as the current pretests) should be able
to generate tables for Perl. I did not thought about generating tr's,
maybe these would indeed be ugly :-). Could tables, like below, be
efficiently drive the translation of an in-memory block? Since I suspect
this is would be common application, and if an array is not a good way
to make the information available, I would like to receive suggestions.
$ recode -v l1..pc/ -hPerl/
# Conversion table generated mechanically by GNU recode 3.4g
# for sequence ISO_8859-1..IBM-PC/ (mono-`-mono).
@ISO_8859_1_IBM_PC =
(
0, 1, 2, 3, 4, 5, 6, 7, # 0 - 7
8, 9, 10, 11, 12, 13, 14, 15, # 8 - 15
16, 17, 18, 19, 182, 186, 22, 23, # 16 - 23
24, 25, 26, 27, 28, 29, 30, 31, # 24 - 31
32, 33, 34, 35, 36, 37, 38, 39, # 32 - 39
40, 41, 42, 43, 44, 45, 46, 47, # 40 - 47
48, 49, 50, 51, 52, 53, 54, 55, # 48 - 55
56, 57, 58, 59, 60, 61, 62, 63, # 56 - 63
64, 65, 66, 67, 68, 69, 70, 71, # 64 - 71
72, 73, 74, 75, 76, 77, 78, 79, # 72 - 79
80, 81, 82, 83, 84, 85, 86, 87, # 80 - 87
88, 89, 90, 91, 92, 93, 94, 95, # 88 - 95
96, 97, 98, 99, 100, 101, 102, 103, # 96 - 103
104, 105, 106, 107, 108, 109, 110, 111, # 104 - 111
112, 113, 114, 115, 116, 117, 118, 119, # 112 - 119
120, 121, 122, 123, 124, 125, 126, 127, # 120 - 127
199, 252, 233, 226, 228, 224, 229, 231, # 128 - 135
234, 235, 232, 239, 238, 236, 196, 197, # 136 - 143
201, 181, 198, 244, 247, 242, 251, 249, # 144 - 151
223, 214, 220, 243, 183, 209, 158, 159, # 152 - 159
255, 173, 155, 156, 177, 157, 188, 21, # 160 - 167
191, 169, 166, 174, 170, 237, 189, 187, # 168 - 175
248, 241, 253, 179, 180, 230, 20, 250, # 176 - 183
184, 185, 167, 175, 172, 171, 190, 168, # 184 - 191
192, 193, 194, 195, 142, 143, 146, 128, # 192 - 199
200, 144, 202, 203, 204, 205, 206, 207, # 200 - 207
208, 165, 210, 211, 212, 213, 153, 215, # 208 - 215
216, 217, 218, 219, 154, 221, 222, 225, # 216 - 223
133, 160, 131, 227, 132, 134, 145, 135, # 224 - 231
138, 130, 136, 137, 141, 161, 140, 139, # 232 - 239
240, 164, 149, 162, 147, 245, 148, 246, # 240 - 247
176, 151, 163, 150, 129, 178, 254, 152, # 248 - 255
);
If you are curious, let me explain the call. "recode -v l1..pc/ -hPerl/"
asks for the Perl table, and not the actual recoding, so says the -h
option. If the / was not there, Perl would be the name of the generated
C table, as the syntax is:
-h[LANGUAGE/]TABLENAME
and C is implied by default for the language. The wanted table should go
from Latin-1 to IBM-PC, and l1 and pc are short abbreviations for those.
The / after pc says that the usual surface transformations which goes with
IBM-PC (here, CR-LF for end of lines) should not considered. The syntax
is a bit more difficult to fully explain. l1..pc clause is in fact a
request, which is briefly summarised this way in the --help output:
REQUEST is SUBREQUEST[,SUBREQUEST]...; SUBREQUEST is ENCODING[..ENCODING]...
ENCODING is [CHARSET][/[SURFACE]]...; REQUEST often looks like BEFORE..AFTER,
with BEFORE and AFTER being charsets. An omitted CHARSET implies the usual
charset; an omitted [/SURFACE]... means the usual surfaces for CHARSET; a /
with an empty surface name means no surfaces at all. See the manual.
--
Frangois Pinard mailto:pinard@iro.umontreal.ca
Join the free Translation Project! http://www.iro.umontreal.ca/~pinard
------------------------------
Date: Thu, 12 Feb 1998 12:17:07 -0700
From: David Hardy <dhardy@beagle.colorado.edu>
Subject: CRs in scripts - ARGH!
Message-Id: <34E34AB2.7818C87B@beagle.colorado.edu>
Does anyone know of an easy way to make perl accept CR/LFs as well as
just LFs in scripts? It's a pain in the neck to have to convert when I
write scripts on my PC.
-David
--
..........................................................................
: David C. Hardy
: MCDB Computing and Network Services
: University of Colorado, Boulder
: dhardy@colorado.edu
: ph(303)492-4535 fx(303)492-7744
:.........................................................................
------------------------------
Date: Thu, 12 Feb 1998 16:02:14 -0500
From: Jim Michael <jim.michael@gecm.com>
Subject: Re: CRs in scripts - ARGH!
Message-Id: <34E36356.5B95@gecm.com>
David Hardy wrote:
> Does anyone know of an easy way to make perl accept CR/LFs as well as
> just LFs in scripts? It's a pain in the neck to have to convert when I
> write scripts on my PC.
If you ftp in ascii (text) mode your problem will disappear.
--
------------------------------
Date: Thu, 12 Feb 1998 14:50:44 -0500
From: fl_aggie@thepentagon.com (I R A Aggie)
Subject: Re: Date validation
Message-Id: <fl_aggie-1202981450440001@aggie.coaps.fsu.edu>
In article <6bv9j2$s1s$1@cronkite.ocis.temple.edu>,
stan@thunder.temple.edu (Stan Horwitz) wrote:
This is a good question. Perhaps a bit clueless, but you tried something
and posted the code, and explained what you wanted.
+ date is to be entered on a terminal in response to a prompt. The date is
+ stored as a string in the format mm/dd/yyyy. When I try to make sure that
+ "mm" is in the range 01 to 12, I run into a problem, perhaps the result of
+ my being somewhat inexperienced at Perl programming.
Ok...
+ if (substr($start_date, 0, 2) ne "01 .. 12")
No, but I can see what you're thinking...the "N..M" operator only
works in loops. How about this:
$input=<STDIN>; # reads mm/dd/yyyy from STDIN
($mon,$day,$year)=split #/#, $input; # split apart the input string
if ($mon>1 && $mon<12) { #hopefully, I have the logic doing the same as you
#did... :)
+ {
[hmmm...you where a C programmer? ;]
+ $date_okay = "N"; print "\n Invalid date ".$start_date;
+ }
If you're expecting just numeric data, you may also want to validate
that $mon contains only digits:
if ($mon=~/\d*/) { #contains numbers only...presuming I got the regex right
if ($mon>1 && $mon<12) {
James
--
Consulting Minister for Consultants, DNRC
The Bill of Rights is paid in Responsibilities - Jean McGuire
To cure your perl CGI problems, please look at:
<url:http://www.perl.com/CPAN-local/doc/FAQs/cgi/idiots-guide.html>
------------------------------
Date: Thu, 12 Feb 1998 13:54:13 -0600
From: Holly Sommer <SNIPhsommer@micro.ti.comSNIP>
Subject: Elements in a hash
Message-Id: <34E35365.FBEFE711@micro.ti.comSNIP>
OK, here's the pertinent code snippet, for a script I'm writing
which will eventually be the middle of a basic search "engine".
Right now, however, only the first "description" is being read,
and it is being read into the "description" field of each record
in the array of hashes I am populating, from the data in DBTEXT.
Specs:
The contents of the file which has a filehandle of DBTEXT are
formatted like this:
---------- Begin Sample Record ------------
+++++++++
Course Name: COURSE NAME HERE
Classes: 980212 980213 980214
Description:
First line of course description.
Second line.
Fourth line.
Last line of course description.
URL: www.somewhere.net/dir1/file.html
Vendor: VENDOR NAME
Groups: GRP1 GRP2 GRP3
Keywords: keyword1 keyword2 keyword3
++++++++++++
--------- End Sample Record --------------
...
$count = 0;
while(<DBTXT>) {
chop;
if ( $_ =~ /:/ ) { # colons at end of fieldname
($fieldname, $fieldcontents) = split( /:/, $_, 2);
&format_field;
} elsif ( $_ =~ /\+/ ) {
# record separator (a plus sign)
$count++;
} elsif ($_ eq "" ) {
$records[$count]{description} .= "\n";
} else {
# Only descriptions go over one line
$records[$count]{description} .= "\n".$_;
}
}
$total = $count;
for ( $total =0; $total<$count; $total++ ) {
print STDOUT "Record Number: $total\n";
print STDOUT "Course: $records[$total]{course_name}\n";
print STDOUT "Classes: $records[$total]{classes}\n";
print STDOUT "Description: $records[$rtotal]{description}\n";
print STDOUT "URL: $records[$total]{url}\n";
print STDOUT "Groups: $records[$total]{groups}\n";
print STDOUT "Keywords: $records[$total]{keywords}\n";
print STDOUT "\n==========================================\n\n";
}
print STDOUT "\nNumber of courses listed: $total\n";
...
So, I run the script, and it lists the {description} for $records[0]
on all records. I'm sure it's something simple, but I haven't found
yet what's causing it to only display the first record's description
for all records.
Ideas?
Thanks,
Holly
------------------------------
Date: Thu, 12 Feb 1998 09:11:45 -0500
From: John Porter <jdporter@min.net>
Subject: Re: FAQless Forays (was: Code Example Needed)
Message-Id: <34E30321.6E70@min.net>
Phil Jach - who sends from an unrepliable address - wrote:
>
> . . . Those 3 times I posted, I didn't bother to read
> the FAQ or check to see if someone else had already posted the question and
> received an answer.
>
> The reason I didn't, is because sometimes I have way to many things going
> on. As most IT professionals know, there is always something to be learned
> and never enough time to read it all.
>
> I do read the ng's and I do post replies to some of the easy questions, I
> spend a lot of time searching the Net for my own answers to my Perl
> problems. That's the best way I've found to learn. Occasionally I do need
> an answer and I don't have 16 hours to spend researching and testing to
> discover a solution to my Perl problems.
If you would spend just one hour reading the FAQ, you'd save
FAR more than 16 hours doing "research and testing" and other
wheel reinventing, I guarantee you.
> . .. my primary job responsibilities
> are to engineer solutions for managing hundreds of servers connected to a
> WAN. So as you can see, the vast amounts of information I need to keep
> abreast of can be overwhelming.
Whereas Tom, Martien, Chip, Andrew, Eli, Joseph, and the rest
have nothing better to do all day than to read usenet news?
John Porter
(Sorry about the bad formatting. It's not my fault. Some
people read the newsgroup and still don't get the message.)
------------------------------
Date: Thu, 12 Feb 1998 21:29:04 +0000
From: Morgan Sackett - SHN <msackett@shn.net>
Subject: Re: Fork/Threads
Message-Id: <34E369A0.4DA5DEAC@shn.net>
patrick@cre8tivegroup.com wrote:
> I've tried fork() from the Camel book, but it forks the entire script, and not
> just the code I want it to (I get the intro message multiple times). I know
> threads are going to be part of 5.005, but I want to "fake" implementation
> now.
>
> Hints, pointers, and sample code would be greatly appreciated :)
I too am trying to understand how fork() works exactly in perl. Here is my
example script.
#!/usr/bin/perl
#############################################################################
#
# script to demonstrate how perl handles forks, and the pid
associated
# with each process.
#
#############################################################################
$pid = $$ ; # pid of "parent process"
fork; # call a fork to spawn child process
if ($ppid == $$ ) { # check if my pid is the same as the
shell
print "$ppid\n" ; # if not, then something is funny and we
should
print "$$\n" ; # give proof of this by printing the
associated
# pids of the shell (read us) and the
current
# pid, these should match
print "This must be the parent\n" ;
}
if (fork) { # test to see if we have forked.
$ppid = getppid; # pid of parent
print "This is the child process\n" ;
print "My PID is $$\n" ;
print "My Parent's PID is $ppid\n" ;
exit 0 ;
}
system("ps aux |grep perl ") ;
exit ;
when I run this I get two answers back. One from the parent process,
and one from the child. Just as one would expect.
EXAMPLE OUTPUT:
[zogg /home/httpd/cgi-bin]# ./forktest.pl
This is the child process
This is the child process
My PID is 744
My Parent's PID is 445
My PID is 745
My Parent's PID is 744
root 746 0.0 1.6 1592 792 p0 S 21:35 0:00 perl
./forktest.pl
root 747 0.0 1.6 1592 792 p0 S 21:35 0:00 perl
./forktest.pl
root 751 0.0 0.7 836 348 p0 S 21:35 0:00 grep perl
root 753 0.0 0.7 836 348 p0 S 21:35 0:00 grep perl
root 746 0.0 1.6 1592 792 p0 S 21:35 0:00 perl
./forktest.pl
root 747 0.0 1.6 1592 792 p0 S 21:35 0:00 perl
./forktest.pl
root 751 0.0 0.7 836 348 p0 S 21:35 0:00 grep perl
root 753 0.0 0.7 836 348 p0 S 21:35 0:00 grep perl
This script works and it doesn't. It works in that it demonstrates
exactly what I wanted to do, which was show the pid's associated with
each process, both the parent(s) and the child. What I was going for
however is this: I wanted to find a way so that the parent perl process
is is the "true" parent, and not my shell, and fork the process so that
only the child gives output. Very important as I would like to use this
in a CGI script that queries a database. I want to use the parent
process to send a holding page to keep the user entertained until the
child process has finished retrieving the data and can send it on it's
way.
I read M.J.T. Guy's post about using select() to communicate between the parent
and the child. But there was no clear example on how to do this....
--
-------------------------------------------------------------------------------
S A P I E N T H E A L T H N E T W O R K
Morgan Sackett Phone: (503) 299-9944
Systems Administration Fax: (503) 299-9917
msackett@shn.net
HTTP://WWW.SHN.NET
------------------------------
Date: 12 Feb 1998 21:13:23 GMT
From: "John Karr" <Johncarryl@Sprintmail.com>
Subject: Free CGI hosting
Message-Id: <01bd37fb$37b57600$5a0e85ce@default>
Hello:
I have just completed learning the fundamentals of the Perl language. For
practice, I am now looking for a few companies that are currently hosting
CGI scripts (designed by me) for FREE. If you know any Internet sites that
are offering this service, please give me a shout.
Thanks,
John.
------------------------------
Date: Thu, 12 Feb 1998 20:37:39 GMT
From: traveler@rust.net (Reilly Shea)
Subject: FTP as filehandle
Message-Id: <6bvms5$3v3$1@news4.ispnews.com>
Keywords: ftp,filehandle
I've been pulling my hair out on this one, reading pg 191-194 of the Camel
book over and over, and still no luck. The answer is probably simple but....
I open an ftp process as a filehandle doing the following..
open(FTP,|ftp somemachine");
I've got a .netrc file in my home directory that has the correct info & format
and everything works just fine.
What I want to know is how can I tell if the open fails (i.e. from an
incorrect login, etc.)
I've tried looking at $? but it comes back 0 successful or not. This
actually makes sense since I'm technically not doing a system call (am I?).
The script that uses the open is run in the background with all output
redirected to /dev/null (somescript > /dev/null 2>&1 &) so just watching the
output isn't an option.
Can someone help?
Thanks,
Reilly
Going bald looking for a return code
------------------------------
Date: 12 Feb 1998 20:31:04 GMT
From: ilya@math.ohio-state.edu (Ilya Zakharevich)
Subject: Re: garbage collection in perl
Message-Id: <6bvm68$mrr$1@mathserv.mps.ohio-state.edu>
[A complimentary Cc of this posting was sent to Malcolm Beattie
<mbeattie@sable.ox.ac.uk>],
who wrote in article <6buli6$crg$1@news.ox.ac.uk>:
> If I ever get around to putting a slab allocator into perl then any
> O/S which uses an mmap-based malloc for large chunk allocation (such
> as GNU libc, the default libc for recent Linux distributions) can have
> unused slabs returned to the O/S. Maybe 5.006.
Similar plans exist for Perl's malloc (note that the advantage of slab
allocator over the newest Perl's malloc are debatable).
Ilya
------------------------------
Date: Thu, 12 Feb 1998 13:49:26 +0000
From: rick@internetx.net ("Rick Bauman")
Subject: getting strings
Message-Id: <19980212184108.AAA11298@rick.internetx.net>
I am trying to get info from a text file . . . the format is as
follows
antjenn 1998/02/03 22:20:09 1998/02/03 22:22:51
antjenn 1998/02/04 20:52:39 1998/02/04 21:13:40
antjenn 1998/02/05 17:24:15 1998/02/05 17:26:07
ajr 1998/02/09 18:28:19 1998/02/09 18:29:03
ajr 1998/02/09 18:51:34 1998/02/09 19:20:00
there is a blank line following each users entry
the script is as follows:
$query_string = "$ENV{'QUERY_STRING'}";
# Open logs and get the info you need
open(SESSIONIX, "/etc/local/logscripts/userdata/sessionlog.ix");
while(<SESSIONIX>) {
($userid, $therest) = split(//,$Line,2);
if($query_string eq $userid) {
print $_;
print "\<br\>"
}
}
next;
close(SESSIONIX);
the script always returns no data . . . can anyone help me with this?
tia
r
Rick Bauman
System Administrator/Internet Express
rick@internetx.net www.internetx.net
finger rick@internetx.net for pgp public key
http://www.lowcountry.net/
Where the truth NEVER gets in the way!!
------------------------------
Date: 12 Feb 1998 21:31:14 GMT
From: gabor@vmunix.com (Gabor)
Subject: Re: Help installing Text::NWrap
Message-Id: <slrn6e6qcu.8if.gabor@vnode.vmunix.com>
In comp.lang.perl.misc, jase@cadence.com <jase@cadence.com> wrote :
# I'm attempting to install the Text-Format+NWrap0.11 package which includes
# the Text::NWrap routine. It compiles fine with 'make', but 'make test'
# produces this output:
#
# PERL_DL_NONLAZY=1 /usr/local/bin/perl -I./blib/arch -I./blib/lib -
# I/usr/local/lib/perl5/sun4-solaris/5.003 -I/usr/local/lib/perl5 -e 'use
# Test::Harness qw(&runtests $verbose); $verbose=0; runtests @ARGV;' t/*.t
# t/*.................Can't open perl script "t/*.t": No such file or
# directory
# FAILED before any test output arrived
# Test returned status 2 (wstat 512)
# FAILED--1 test script could be run, alas -- no output ever seen
# *** Error code 29
# make: Fatal error: Command failed for target `test_dynamic'
Yes, unfortunately I called the test script test.pl and it should be
test.t. :-(
#
#
# And if I try to use Text::NWrap in a script, I get these errors:
#
# Bareword "_text" not allowed while "strict subs" in use at
# /usr/local/lib/perl5/site_perl/Text/Format.pm line 305.
# Bareword "_findent" not allowed while "strict subs" in use at
# /usr/local/lib/perl5/site_perl/Text/Format.pm line 308.
# [etc.]
Hmm, it doesn't happen for me.
the lines in question are
@wrap = @{$this->{_text}} # unquoted hash key
if @wrap < 1;
my $findent = ' ' x $this->{_findent};
Unfortunately I wrote this using perl5.004 and I guess 5.003 doesn't
like barewords as hash keys.
All I can say is that I can fix it up and quote the hash keys.
I'll have it on CPAN as soon as I can, I'll fix it right now, and
upload it as soon as I am done.
:-(
gabor.
--
I don't know if it's what you want, but it's what you get. :-)
-- Larry Wall in <10502@jpl-devvax.JPL.NASA.GOV>
------------------------------
Date: Thu, 12 Feb 1998 15:26:11 -0600
From: John Adams <John.Adams@BentonvilleAR.ncr.com>
Subject: Re: How generate counter?
Message-Id: <34E368F3.79C0@BentonvilleAR.ncr.com>
chris+usenet@netmonger.net wrote:
> Tom, is it possible for you to mark your useful and informative posts
> to separate them from the one-line quips? I used to read everything
> you write (I even have a perl program that e-mails posts by you,
> Randal, etc. to me), but lately I'm drowning in this sea of
> "you are satanspawn" posts.
My suggestion is that such posts be indicated by "discourtesy copy"
rather than "courtesy copy". I realize that, in fact, discouraging the
sorts of posts that are usually thus responded to is actually a courtesy
to the rest of us (and to those who make such posts then learn better),
but...well, think of it as "dis courtesy" as opposed to "dat courtesy".
And speaking of dat, I've got a tape to load.
John A
...who doesn't speak for his employer on this issue
...or on most other non-technical topics
...but does appreciate the work Tom does
...even if he won't see this post because I'm using Netscape
------------------------------
Date: Thu, 12 Feb 1998 21:12:59 +0100
From: martin@RADIOGAGA.HARZ.DE (Martin Vorlaender)
Subject: Re: How the Hell do I...?
Message-Id: <34e357cb.524144494f47414741@radiogaga.harz.de>
Dave Power (dave.power@adpdesign.com) wrote:
: Tom Christiansen <tchrist@mox.perl.com> wrote:
: > % man perlfunc | grep -i delete
: > [amongst other things ...]
: > XXXXXX Deletes a list of files. Returns the number
: > of files successfully deleted.
: >
: >The XXXXXX is left for you to lookup on your now. Although
: >if you read the FAQ, there's a way to do that (see the POSIX
: >module or the IO::File module) in which it's not even needed.
: I've picked up the FAQ now - thanx (much better than the docs which
: came with my W95 version 4 of Perl) but I'm still confused.
: Maybe I've not had enough time to do a proper read thro'
You're not supposed to read thro'. Y'know, even in W95 you can "grep":
C:\> find /i /n "delete" c:/perl/lib/pod/perlfunc.pod
[amongst other things ...]
[3656]Deletes a list of files. Returns the number of files successfully
[3657]deleted.
Note1: I only tried this in the DOS box of my OS/2 system at home.
Note2: The path to perlfunc.pod must be adjusted to match your installation.
Note3: You still have to look up the name of the function yourself.
Hint: It's near line 3656 in perlfunc.pod.
: but pls tell
: me how - in simple terms - do I delete a file? I don't want a full
: course in the language - just one answer to one question.
The point is not that we're not trying to be helpful here. We're trying
to help you to help yourself, so that the next time you are lost at some
function's name, you can go and find it yourself.
cu,
Martin
--
| Martin Vorlaender | VMS & WNT programmer
Ceterum censeo | work: mv@pdv-systeme.de
Redmondem delendam esse. | http://www.pdv-systeme.de/users/martinv/
| home: martin@radiogaga.harz.de
------------------------------
Date: Thu, 12 Feb 1998 09:42:33 -0500
From: John Porter <jdporter@min.net>
Subject: Re: Matt's Script Archive
Message-Id: <34E30A59.5A6C@min.net>
I R A Aggie wrote:
>
> Last I looked, Matt was _not_ using CGI.pm in his scripts.
Speaking of which, Why isn't Matt taking part in our lovely
newsgroup? Matt, are you here? clpm to Matt! Come in!
John Porter
------------------------------
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 1878
**************************************