[7485] in Perl-Users-Digest
Perl-Users Digest, Issue: 1111 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Oct 1 19:17:13 1997
Date: Wed, 1 Oct 97 16:00:27 -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 Wed, 1 Oct 1997 Volume: 8 Number: 1111
Today's topics:
Re: a2p and redirection <rootbeer@teleport.com>
Bases Class Constructor Invokation <sgermain@nortel.ca>
Re: Bases Class Constructor Invokation <sgermain@nortel.ca>
Bigtime Newbie needs a teeny bit of help . . . (Rama Polefka)
Re: Can't debug a perl script. (Ilya Zakharevich)
convert ms word document to plain text (RHS Linux User)
Credit Card Number Validation <nmuller@ddx.com>
Re: Credit Card Number Validation (brian d foy)
fflush... <gerberc@cs.uregina.ca>
Re: fflush... (Jot Powers)
Re: Generating bit patterns "00000000" .. "11111111" <Matthew.Rice@ftlsol.com>
Re: Generating bit patterns "00000000" .. "11111111" (Lozano Mosterin, Jesus)
Re: Help: reformat variable <rootbeer@teleport.com>
Re: how to write HTML form data to a text file??? (M.J.T. Guy)
HTML->RTF ? (Chris Nandor)
Re: Is it EBCDIC ? <rootbeer@teleport.com>
line-by-line add to HTML-output <matthias.hellmund@nienburg-weser.de>
Re: MIME Header "Location:" <russ@mail.org.uk>
New CGI Web Site <landrews@telechoiceonline.com>
Re: operator expected. <rootbeer@teleport.com>
Parsing compressed text (Doug Roberts)
Re: perl and HTTP (Abigail)
Perl pack templates ARE crippled (Was: Perl <=> C Serve uwe@ptc.spbu.ru
Re: Reading Excel <rootbeer@teleport.com>
simple <rswanson@sarnoff.com>
Re: simple (Pete Ratzlaff)
Re: simple <rootbeer@teleport.com>
Re: splitting a tab delimited line (Ken Gaugler)
Traceroute, a perl version <jaydee@worsdall.demon.co.uk>
Re: unlink & rename <gnadan@channell.com>
Wanted: Wall/Schwartz book (1st ed) (Gregory Glockner)
Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 1 Oct 1997 15:23:24 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: Nathan Franzen <franzen@pmel.noaa.gov>
Subject: Re: a2p and redirection
Message-Id: <Pine.GSO.3.96.971001152135.236H-100000@usertest.teleport.com>
On Wed, 1 Oct 1997, Nathan Franzen wrote about an awk construct not
understood by the a2p program, which converts awk to perl:
> I've been very impressed with a2p, but am surprised that it can't handle
> this. Any comments or suggestions?
You should modify a2p to handle that construct, then run 'perlbug' to send
in a patch. :-) Thanks!
--
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: Wed, 01 Oct 1997 15:41:29 -0400
From: "Sylvain St.Germain" <sgermain@nortel.ca>
Subject: Bases Class Constructor Invokation
Message-Id: <3432A769.34A7@nortel.ca>
I am posting this question
as well as a reply I got from Jim Stern.
How does the two base classes (B and C) of a class (A) have
their "new" functions invoked in the A's constructor?
package A;
@ISA = (qw/B C/);
sub new {
...
my $self = B->SUPER::new(@_);
"???? What goes here for class C ????"
...
}
Sylvain.
------------------------------
Date: Wed, 01 Oct 1997 15:43:43 -0400
From: "Sylvain St.Germain" <sgermain@nortel.ca>
Subject: Re: Bases Class Constructor Invokation
Message-Id: <3432A7EF.69A2@nortel.ca>
Here is Jim Stern reply.
Let's start with some key facts. I mentioned some of these in my
earlier reply but they bear repeating:
1. Unlike C++, Perl does not automatically call 'new'
for the base classes in a derived class's 'new'. (In fact,
Perl doesn't even require you to name the constructor 'new'.
Hence it can't even be sure which function _is_ the base
class's constructor. You could have called B's constructor
'build' instead of 'new', for example. Of course, sticking
to a standard name like 'new' is a good idea. It helps you
and others understand your code.)
2. Unlike C++, Perl classes don't automatically inherit data.
Just because 'A' is derived from 'B' and 'C' that doesn't
mean 'A' inherits their fields.
3. As a consequence of 1 and 2, it's totally up to you to
ensure that the proper constructor calls are made in the
proper sequence and that the resulting bless-ed object
contains all the data that 'A', 'B' and 'C' need.
Point 3 is especially worrisome. Suppose that B::new and C::new
both return blessed references to hashes. Suppose that B
requires the hash to have a field named 'xxx' set to 'Bxxx' and
that C requires the hash to have the same field set to 'Cxxx'.
I don't think you can do multiple inheritance in that case so
I will assume you don't have this problem.
Now, a new point:
4. Beware of 'SUPER' when there are multiple base classes.
For example, which 'new' does SUPER::new call? I don't
think B->SUPER::new buys you much over B::new in this
case either. Both have the effect of hardcoding class 'B'.
So much for the background. Here is some sample code:
#!/usr/local/bin/perl -w
# File test.pl
use strict;
require A;
my $A = new A key1 => 'value1', key2 => 'value2';
for (sort keys %$A) {
print "$_\t$A->{$_}\n";
}
# File A.pm
use strict;
package A;
use vars qw(@ISA);
require B;
require C;
@ISA = qw(B C);
sub new {
my($class, %data) = @_;
my $b = new B (%data);
my $c = new C (%data);
bless my $this = { %$b, %$c }, $class;
}
1;
# File B.pm
use strict;
package B;
use vars qw(@ISA);
sub new {
my($class, %data) = @_;
bless my $this = { %data, B_ran => 1 }, $class;
}
1;
# File C.pm
use strict;
package C;
use vars qw(@ISA);
sub new {
my($class, %data) = @_;
bless my $this = { %data, C_ran => 1, }, $class;
}
1;
==============================================================
A::new is the hardest to understand. Notice that I had to store
B::new and C::new in separate variables and then combine them.
Contrast that with:
my $this = new B (%data);
$this = new C (%data);
The second statement reassigns $this. It undoes all of B::new's
work.
I hope my code helps but it will help more if you also read the
following:
* The perlobj and perltoot man pages
* At least the OO-related sections of Programming Perl
(although the rest of the book is great too)
Good luck.
--
Jim Stern -- Views here are my own, not Northrop Grumman's. (El
Segundo, CA)
------------------------------
Date: Wed, 01 Oct 1997 18:06:19 GMT
From: rama@rely.com (Rama Polefka)
Subject: Bigtime Newbie needs a teeny bit of help . . .
Message-Id: <3432815a.3413784@news.internex.net>
i have a simple problem -
i need to run a series of commands at specified intervals to trigger a
mail flush. the series of commands is as follows:
telnet secondary-mx.xxx.net 25
etrn#mydomain.com
quit
this needs to run on a NT box that is receiving mail from another mail
server. i am madly flipping pages in a Perl 5 book but need to have
this done as soon as possible. if this is trivial (which i think it
is) i would greatly appreciate someone sending me the script. if it
is not super easy, could you at least tell me so i can plan
accordingly? i will return the favor in any way i can.
thanks a bunch
------------------------------
Date: 1 Oct 1997 22:42:10 GMT
From: ilya@math.ohio-state.edu (Ilya Zakharevich)
Subject: Re: Can't debug a perl script.
Message-Id: <60ujk2$3pu@agate.berkeley.edu>
In article <343284F3.4312@NOSPAM.instinet.com>,
Michael Shael O'Neill Selden <selden@NOSPAM.instinet.com> wrote:
> Pierre BERGDOLT wrote:
> >
> > But if I run:
> >
> > "perl -d cc_upvw"
> >
> > I get the following message:
> >
> > Got SEGV!
> > Signal SEGV: No such file or directory
> > Resources lost
> >
>
> Pierre,
> Did you specifically compile Perl with Debug support enabled?
> If not, do so and your problem will go away. If you are not in a
> position to recompile Perl, or you did not compile it yourself in the
> first place, you can check to see whether or not Debug support is
> available by executing `perl -v` and looking at the output.
Wrong.
But upgrading your Perl may work. Try fetching 5.004m4t2
(CPAN/authors/id/TIMB), it should have several new debugger bugs
cleaned up.
Ilya
------------------------------
Date: 1 Oct 1997 12:58:44 -0700
From: jwilliam@jwilliams.mayo.edu (RHS Linux User)
Subject: convert ms word document to plain text
Message-Id: <60ua1k$1uh$1@jwilliams.mayo.edu>
would like to convert some ms word documents to plain text on my linux
box. Would appreciate any pointers to utilities,modules,etc. thanks.
jim
------------------------------
Date: Tue, 30 Sep 1997 22:28:17 -0700
From: "Nathan J. Muller" <nmuller@ddx.com>
Subject: Credit Card Number Validation
Message-Id: <3431DF71.154C@ddx.com>
Hi,
I would like to add a statement to my Perl script that processes credit
card orders which will do a simple online card number verification such
that a Visa card number, for example, must start with the number 4 and
be followed by 15 random digits. Can anyone suggest a line of code to
start me off? Thanks in advance.
------------------------------
Date: Wed, 01 Oct 1997 15:06:29 -0400
From: comdog@computerdog.com (brian d foy)
Subject: Re: Credit Card Number Validation
Message-Id: <comdog-ya02408000R0110971506290001@news.panix.com>
In article <3431DF71.154C@ddx.com>, nmuller@ddx.com wrote:
>Hi,
>
>I would like to add a statement to my Perl script that processes credit
>card orders which will do a simple online card number verification such
>that a Visa card number, for example, must start with the number 4 and
>be followed by 15 random digits. Can anyone suggest a line of code to
>start me off?
better than that even (why settle for less?)! check out the
Business::CreditCard module at CPAN [1].
good luck :)
[1]
Comprehensive Perl Archive Network
find one near you at <URL:http://www.perl.com>
--
brian d foy <comdog@computerdog.com>
NY.pm - New York Perl M((o|u)ngers|aniacs)* <URL:http://ny.pm.org/>
CGI Meta FAQ <URL:http://computerdog.com/CGI_MetaFAQ.html>
------------------------------
Date: Wed, 1 Oct 1997 13:56:43 -0600
From: Chris Gerber <gerberc@cs.uregina.ca>
Subject: fflush...
Message-Id: <Pine.SGI.3.91.971001135318.22228A-100000@HERCULES.CS.UREGINA.CA>
Hi, I was wondering if anyone knows a way to flush a file buffer from
within perl. There doesn't appear to be any built-in function that does
this, and neither fcntl or ioctl will let me do a flush either. If
anyone can tell me how this can be done w/o a lot of hassle, or tell me
that it can't be done without a lot of hassle I'd be rather
appreciative.
Please email and post a response, cause my newsreader (yay pine!)
sometimes loses posts. Thanks very much,
-chris
------------------------------
Date: 1 Oct 1997 20:30:22 GMT
From: news@bofh.com (Jot Powers)
Subject: Re: fflush...
Message-Id: <60ubsu$lh0$1@gazette.corp.medtronic.com>
In article <Pine.SGI.3.91.971001135318.22228A-100000@HERCULES.CS.UREGINA.CA>,
Chris Gerber wrote:
>
>Hi, I was wondering if anyone knows a way to flush a file buffer from
>within perl. There doesn't appear to be any built-in function that does
>this, and neither fcntl or ioctl will let me do a flush either. If
>anyone can tell me how this can be done w/o a lot of hassle, or tell me
>that it can't be done without a lot of hassle I'd be rather
>appreciative.
>
>Please email and post a response, cause my newsreader (yay pine!)
>sometimes loses posts. Thanks very much,
>-chris
It would be faster, and easier to look in the documentation that comes
with perl.
node127% cd /usr/local/man/man1
node127% grep flush perl*.1 | wc -l
59
node127% perldoc perlfaq5
...
How do I flush/unbuffer a filehandle? Why must I do this?
The C standard I/O library (stdio) normally buffers
characters sent to devices. This is done for efficiency
...
You can use select() and the $| variable to control
autoflushing (see the section on $| in the perlvar manpage
and the select entry in the perlfunc manpage):
$oldh = select(DEV);
$| = 1;
select($oldh);
...
--
Jot Powers news@bofh.com
Unix System Administrator
"Sometimes you just have to grab the bull by the tail and face the situation."
------------------------------
Date: 01 Oct 1997 14:38:34 -0400
From: Matthew Rice <Matthew.Rice@ftlsol.com>
Subject: Re: Generating bit patterns "00000000" .. "11111111"
Message-Id: <m3hgb1jplh.fsf@hudson.ftlsol.com>
Jan Krynicky <Jan.Krynicky@st.mff.cuni.cz> writes:
> Ricky Roque wrote:
> >
> > I'm trying to generate pattern like the following
> > "00000000"
> > "00000001"
> > :
> > :
> > "11111110"
> > "11111111"
>
> for($i=0;$i<=255;$i++){
> print unpack('B8',pack('C1',$i)),"\n";
> }
you can also remove the for statement with:
print map { unpack('B8', pack('C1', $_)), "\n" } (0..255)
--
Matthew Rice e-mail: matthew.rice@ftlsol.com
------------------------------
Date: 1 Oct 97 20:54:53 +0200
From: lozano@polar.etsiig.uniovi.es (Lozano Mosterin, Jesus)
Subject: Re: Generating bit patterns "00000000" .. "11111111"
Message-Id: <1997Oct1.205453.6@polar.etsiig.uniovi.es>
In article <3430B6B6.66894D5B@bigfoot.com>, Ricky Roque <ricky.roque@bigfoot.com> writes:
> Any other method of doing the task?
> Thanks.
I like this, but in perl seems to run too slow
#!/usr/bin/perl
for (1..$ARGV[0]){ $b[$_]=0; }
do{
for ($c=1;$c<=$lastb+1;$c++){
if ($b[$c]==0){
$b[$c]=1;
last;
}else{ $b[$c]=0; }
}
if ($c>$lastb) { $lastb=$c; }
for ($c=$ARGV[0];$c>=1;$c--){ print $b[$c]; }
print "\n";
}until ($lastb>$ARGV[0]);
i.e.
perl_land:~$ binar 90
Plonk! ... extraplonk!
perl_land:~$ binar 4
0001
0010
0011
0100
0101
0110
0111
1000
1001
1010
1011
1100
1101
1110
1111
0000
Cheers
---
perl -e 'print pack "B77",
"00111001001110000010110100110101001100010011100000110010001100010011000000111";'
------------------------------
Date: Wed, 1 Oct 1997 15:26:00 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: Peter Losin <losinp@wam.umd.edu>
Subject: Re: Help: reformat variable
Message-Id: <Pine.GSO.3.96.971001152534.236J-100000@usertest.teleport.com>
On 1 Oct 1997, Peter Losin wrote:
> I need to take the input from an HTML <TEXTAREA>, which may be hundreds
> of characters including \n, etc., and pass it through some routine that
> will format it so it's no more than (say) 50 characters wide.
Check out Text::Wrap. Hope this helps!
--
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: 1 Oct 1997 20:59:17 GMT
From: mjtg@cus.cam.ac.uk (M.J.T. Guy)
Subject: Re: how to write HTML form data to a text file???
Message-Id: <60udj5$f9b$1@lyra.csx.cam.ac.uk>
Tom Phoenix <rootbeer@teleport.com> wrote:
>On Thu, 25 Sep 1997, Ed.Q.Bridges wrote:
>
>> &UnLock( DATAFILE );
>> close DATAFILE;
>
>Don't release a lock before closing the file unless you're an expert.
And if you were an expert, you wouldn't anyway.
Mike Guy
------------------------------
Date: Wed, 01 Oct 1997 17:03:13 -0400
From: pudge@pobox.com (Chris Nandor)
Subject: HTML->RTF ?
Message-Id: <pudge-ya02408000R0110971703130001@news.idt.net>
Anyone got something to convert HTML to RTF or Word or something? Can't
seem to find anything ...
Thanks much,
--
Chris Nandor pudge@pobox.com http://pudge.net/
%PGPKey=('B76E72AD',[1024,'0824 090B CE73 CA10 1FF7 7F13 8180 B6B6'])
------------------------------
Date: Wed, 1 Oct 1997 15:20:04 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: Vasanth Shenoy <k3dk@maristb.marist.edu>
Subject: Re: Is it EBCDIC ?
Message-Id: <Pine.GSO.3.96.971001151351.236G-100000@usertest.teleport.com>
On Mon, 29 Sep 1997, Vasanth Shenoy wrote:
> I have script that gets some input from a form and does something
> with the input(sends a mail). The script runs perfectly in Linux.
> But when I try to use it in MVS/OS-390, it just does not work.
There are many (many!) ways in which something "just does not work". Does
it do nothing? Does it make an error message which you don't understand?
Does it make an error message which you do understand? Does it produce the
wrong output? Does it produce too much output? Does it produce too little
output? Does it make smoke come out of the back of your computer? Does it
get stuck in an infinite loop? :-) If you can be more specific, that
would be helpful.
> I know why it does not work! it does not work because we have to
> interpret the escape sequenced letters properly. eg: : / , ~ ( ) etc.
I don't know what you mean by "escape sequenced letters". To Perl, those
characters can be used in data without any problems. But maybe some other
program is escaping them somehow, and you want to undo the escaping,
perhaps?
> I get a ^3A for a : ^2C for a , ...
> I guess its not a EBSIC character becuase, even from a ASCII machine,
> I get the same codes for these characters. So, what is the problem ?
I don't know. :-) But if you can make a small example script (say, about
ten lines) and show us some sample input, that would be a start. If you
tell us what you want the code to do that it's not doing, we might be able
to point you in the right direction. Thanks!
--
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: 1 Oct 1997 22:07:04 GMT
From: "Matthias Hellmund" <matthias.hellmund@nienburg-weser.de>
Subject: line-by-line add to HTML-output
Message-Id: <01bccebe$bd71ef40$0100a8c0@o63hutef>
How can I program a script that outputs a frame (line by line) and after
e.g. 20 lines erases the frame and then prints out some more lines?
I captured the enclosed file from a German chat (at www.west.de). It should
display only the last messages after the last "--pagestop", but when I
reopen it in my browser all messages are shown.
I know, that this is not a perl-specific problem but I hope you can
nevertheless help me!
Shouldn't this perl-script-part display only "Hello!" in a browser?
#!/usr/bin/perl
print "Content-Type: text/html\n\n";
print "Don't show this<br>\n";
print "Content-Type: text/html\n\n";
print "Hello!<br>\n";
What is wrong with it?
e-mail-replies (but NO advertisements!!!) very appreciated.
CU
Matthias
--
Matthias Hellmund
E-Mail: matthias.hellmund@nienburg-weser.de
Homepage (NEW!): http://www.nienburg-weser.de/~hellmund
------------------------------
Date: Wed, 01 Oct 1997 16:46:36 +0100
From: Russell Odom <russ@mail.org.uk>
Subject: Re: MIME Header "Location:"
Message-Id: <3432705C.9F87651E@mail.org.uk>
S. Steven Maese wrote:
>
> I'm new to PERL, sorry if this is a more than obvious question, but....
>
> sub redir {
> print "Location: http://www.csolutions.net/index.html\n\n";
> }
>
> The above code is intended to redirect a browser to the above listed web
> page. This works with IE 3.02, but with Navigator 4.01 I get "Document
> contains no data." Any ideas?
I think it this may be because some browsers don't recognise the
'Location:' header, they need 'URI:' (which is apparently the official
header). Use the CGI module, it now produces both.
For more info, use 'perldoc cgi', and look for 'GENERATING A REDIRECTION
INSTRUCTION'
HTH,
Russ
---------------------------------------------------------------------
--[ R u s s e l l O d o m ]---[ *NEW:* mailto:russ@mail.org.uk ]--
--[ University of York, UK ]---[ http://www.york.ac.uk/~rjo100/ ]--
---------------------------------------------------------------------
--[ FAQ maintainer, news:comp.os.ms-windows.win95.moderated ]--
---------------------------------------------------------------------
------------------------------
Date: Mon, 29 Sep 1997 11:53:18 -0500
From: Lynn Andrews <landrews@telechoiceonline.com>
Subject: New CGI Web Site
Message-Id: <342FDCFE.4B95@telechoiceonline.com>
Please take a look at The Complete Webmaster, the new site for
webmasters, by webmasters. Read articles about HTML, CGI, Java,
JavaScript, and more.ters. Read articles about HTML, CGI, Java,
http://www.abiglime.com/webmaster/ticles about HTML, CGI, Java,
We welcome any feedback to feedback@abiglime.com. Thanks very ,
much.lcome any feedback to feedback@abiglime.com. Thanks very ,
-Josh Andrewsy feedback to feedback@abiglime.com. Thanks very ,
------------------------------
Date: Wed, 1 Oct 1997 15:32:29 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: Benarson Behajaina <Benarson.Behajaina@swh.sk>
Subject: Re: operator expected.
Message-Id: <Pine.GSO.3.96.971001152910.236L-100000@usertest.teleport.com>
On Wed, 1 Oct 1997, Benarson Behajaina wrote:
> When running a perl script (cache-compare.pl) I've got the following
> error message:
> ===============================================
> Number found where operator expected at (eval 175) line 1, near ") 0"
> (Missing operator before 0?)
> ===============================================
> Is there someone who knows what does the message mean ?
Yes: Anyone who can find it in the perldiag(1) manpage. :-)
Note that the error didn't occur on line 1 of your script, but instead on
line 1 of the 175th eval STRING which your script did. Hope this helps!
--
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: Wed, 01 Oct 1997 12:36:57 -0800
From: zz---dougr--zz@headspace.com (Doug Roberts)
Subject: Parsing compressed text
Message-Id: <zz---dougr--zz-ya02408000R0110971236570001@news1.alterdial.uu.net>
Is there a relatively easy (for a Perl tourist, not purist) way to parse
gigantic (40+ meg) files that have been conveniently gzip'ed to <4 megs?
I need to parse our HTTP server logs that are automagically compressed on
the ISP side, downloaded and processed on a Mac. We may move log processing
to a WinNT box, but as far as I know neither of those two platforms has a
command similar to zcat, which is what I was using on Linux, piping it into
the perl script.
If there is a Perl specific command to do something similar, I'd love to
know what it is for use either in MacPerl, NT or Linux Perl versions.
Ideally, all the log processing would take place on one platform.
--
Doug Roberts
to reduce spam, reply to me at dougr at headspace.com
============
The views I express do not reflect those of my employer or the other voices
I hear in my head.
(Do too!) (Do not!)
(Do too!) (Do not!)
(Too!) (Not!)
------------------------------
Date: 1 Oct 1997 19:15:37 GMT
From: abigail@fnx.com (Abigail)
Subject: Re: perl and HTTP
Message-Id: <slrn6358es.565.abigail@betelgeuse.rel.fnx.com>
Matteo Pelati (pelatimtt@poboxes.com) wrote on 1485 September 1993 in
<URL: news:60bs1f$6re@server-b.cs.interbusiness.it>:
++ I do have a problem like this: when I got a reply from my perl script the
++ text sent to the browser isn't interpreted as text/html but just as plain
++ text. Anyone of you know wht could be the problem?
Yes. You aren't asking in the right group. The people in
comp.infosystems.www.authoring.cgi will happily slap you
for asking a FAQ.
Abigail
------------------------------
Date: 1 Oct 1997 20:00:07 GMT
From: uwe@ptc.spbu.ru
Subject: Perl pack templates ARE crippled (Was: Perl <=> C Server)
Message-Id: <60ua47$1lt@svx1.ptc.spbu.ru>
I'm sorry to intrude.
Perl template language is crippled, period. I've spent some time
making people understand why, but to no avail. At the end of this
message you will find my old letter to the perl patch pumpking holder
(as of mid of June) that left unanswered. I don't have time to lobby
for my patch, but please read it carefully, examine the problem
described in this thread, think about it -- and you will agree with
me.
Doug Seay <seay@absyss.fr> wrote:
> dave wrote:
> >
> > >Andrew M. Langmead wrote:
> > >> struct foo {
> > >> char name[32];
> > >> int id;
> > >> };
> > >>
> > >> could be converted like this:
> > >>
> > >> ($name, $id) = unpack 'A32I', $data;
> > >
> >
> > I'm surprised that this works for you. Exactly how does Perl know the
> > last valid character in the name?
> The programmer specified "A32I" which means 32 bytes of ascii text
> padded with spaces (more interesting for the pack than the unpack)
> followed by an unsigned integer (endian is system specific). Perl grabs
> 32 bytes, calls it a string and puts that in $name. The next
> sizeof(int) bytes are grabbed, called an integer and stuffed into $id.
> Perl doesn't know anything about the "last valid character in the name",
> it just knows to get 32 characters.
Now, given this C structure definition, write a template that will do
*BOTH* packing and unpacking, i.e. writing data for and reading data
from a C program. Please, note well that a trailing space is valid
character in a C null-delimited string.
I have raised this question in c.l.p.m and posted enhancment request
(with implementation) to p5p in June but got no response.
I'm overwhelmed with work and I don't have time to engage in long
e-mail conversation. I've spent a lot of time trying to explain
people where the problem is -- and I'm fed with it. This thread gives
a good exmple: try to *TALK* (both ways) to a C program. And remember
that a trailing space is a valid part of C string. May be then the
case will be clear.
Below I include one of my old e-mails with complete rationale and an
actual patch. I still belive that my proposal must be included in
perl. Please, think again about this example of talking to a C
program. You will see why I'm so confidently saying 'must be
included'.
PS: I think I had hard time explaining people that there's a problem,
because perl is usually used to only read or to only write data.
Try to go both ways and you'll see.
PPS: Please Cc your follow-ups by e-mail as my news feed is terrible.
----8<--------8<--------8<--------8<--------8<--------8<--------8<----
>From uwe@ptc.spbu.ru Mon Jun 16 03:00:32 1997
Date: Mon, 16 Jun 1997 03:00:31 +0400 (MSD)
From: "Valeriy E. Ushakov" <uwe@ptc.spbu.ru>
To: Malcolm Beattie <mbeattie@sable.ox.ac.uk>
Subject: lack of pack/unpack letter with useful symmetry
for C null delimited strings
Message-ID: <%lOHpzIuGV@snark.ptc.spbu.ru>
Hi, Malcolm.
Recently, after discussion with Tom Phoenix in clpm and in private
emails, I posted a bug report and a patch with perlbug. Tom advised
me to send the patch to you, current pumpking holder, along with some
rationale. I apologize for sending you may be overly long and wordy
explanations, but I took me some time and effort to convince Tom that
there's a problem and explain where it is, so this experience urge me
to go in some details in my rationale.
Included are source patch and a pod patch attempt. I don't include
patch for t/op/pack.t, I put some exapmles at the end of my rationale
though.
Thanks for your time.
* Summary
There's no format letter which is pack/unpack symmetric for C style
null delimited strings.
* Rationale
Most common use of (un)packing is interfacing with other programs,
written in C usually, that use data structures represented with C
`struct' or, perhaps, similar language constructs if other languages
are concerned. A good perl idiom is:
# Defining struct foobar layout
$struct_foobar = <template for C struct foobar>;
$sizeof_foobar = <size of struct foobar in bytes>;
# Reading struct foobar
read FOOBAR, $foobar, $sizeof_foobar;
@foobar = unpack $struct_foobar, $foobar;
# ... hack away ...
# Writing struct foobar
$foobar = pack $struct_foobar, @foobar;
print FOOBAR $foobar;
This idiom is based on the symmetry of packing and unapcking using the
same template. And indeed as perlfunc(1) says ``The same template may
generally also be used in the unpack function''. Thus symmetry is
desired property for templates since it supports the above idiom.
Using different formats or doing some additional posprocessing is
cumbersome and error-prone. Unfortunately perl currently lacks
symmetric format for a very common case, when C null delimited string
is stored in a fixed size field of a C struct: struct utmp is one good
example of such structure.
Currently, when such field is packed one have to use 'a' format, that
packs the string padding it with null bytes. When such field is
unpacked one have to use 'A' format that strips trailing nulls and
spaces. Thus for this common situation symmetry is broken. More
over, if C string has trailing spaces (followed by a null byte
terminator and ofted padded with more nulls to fill available field
width), unpacking it with 'A' will strip away not only nulls but those
trailing spaces that are part of C string as well.
To clarify my point a bit I will point out that otherwise 'a' and 'A'
both exhibit symmetric behavior in their own domains:
'a' - I prefer mnemonic of "any" - is symmetric for arbitrary binary
data. It does not modify data when unpacking. It pads with
null bytes when packing which is almost certainly what one
needs.
'A' - I prefer mnemonic of "ASCII" - is symmetric for printable
text.
What I think perl obviously lacks is herein proposed new format letter
'Z' with mnemonic of "ASCIZ" (like in many assemblers) for symmetric
packing and unpacking of C null delimited strings.
pack - 'Z' will pad the string with null bytes.
unpack - 'Z' will strip away trailing null bytes but (unlike 'A') not spaces.
To reiterate, proposed format letter 'Z' is symmetric for a common case
of C null delimited strings and will support the idomatic coding cited
at the beginnig of my message.
Stripping only nulls when unpacking is required to support desired
symmetry, since trailing spaces are valid part of C string. Also it may
be noted that stripping those spaces, if required, is semantically related
to the interpretation of the content of C string in some other context.
The following example demonstrates the lack of symmetry:
$struct_utmp_A = "A8 A8 A16 L"; # can only unpack witgh this one
$struct_utmp_a = "a8 a8 a16 L"; # can only pack with this one
$sizeof_utmp = 36;
$_PATH_WTMP = "/var/log/wtmp";
open WTMP, "$_PATH_WTMP" or die "$_PATH_WTMP:$!\n";
read WTMP, $wtmp, $sizeof_utmp or die "read: $!\n";
@wtmp_A = unpack $struct_utmp_A, $wtmp;
@wtmp_a = unpack $struct_utmp_a, $wtmp;
# I don't want trailing nulls in user, line and host names!
# My login name is 'uwe', not 'uwe\0\0\0\0\0'
print "'a' doesn't strip nulls\n" if $wtmp_a[1] =~ /\0/;
# I can't pack with 'A' if C program is to read these record, for it
# expects null, not space. My login name is 'uwe' not 'uwe '
$wtmp_A_prim = pack $struct_utmp_A, @wtmp_A;
print "'A' is not reversible\n" if $wtmp_A ne $wtmp_A_prim;
Exaple usage of proposed format is (symmetrically) defining BSD style
struct utmp as:
$struct_utmp = "Z8 Z8 Z16 L";
Example test (more contorted cases are welcome):
$string = "1234 ";
$format = "Z8"
$packed = pack $format, $string;
($unpacked) = unpack $format, $packed;
print "not " if $string ne $unpacked;
print "ok NN\n";
* Source patch
The following patch add proposed 'Z' format letter to pp_pack and
pp_unpack.
--- pp.c.dist Fri Apr 25 05:56:28 1997
+++ pp.c Thu Jun 5 10:13:00 1997
@@ -2724,6 +2724,7 @@
s += len;
break;
case 'A':
+ case 'Z':
case 'a':
if (len > strend - s)
len = strend - s;
@@ -2732,11 +2733,15 @@
sv = NEWSV(35, len);
sv_setpvn(sv, s, len);
s += len;
- if (datumtype == 'A') {
+ if (datumtype == 'A' || datumtype == 'Z') {
aptr = s; /* borrow register */
s = SvPVX(sv) + len - 1;
- while (s >= SvPVX(sv) && (!*s || isSPACE(*s)))
- s--;
+ if (datumtype == 'Z') /* 'Z' strips only nulls */
+ while (s >= SvPVX(sv) && (!*s))
+ s--;
+ else /* 'A' strips both nulls and spaces */
+ while (s >= SvPVX(sv) && (!*s || isSPACE(*s)))
+ s--;
*++s = '\0';
SvCUR_set(sv, s - SvPVX(sv));
s = aptr; /* unborrow register */
@@ -3500,6 +3505,7 @@
sv_catpvn(cat, null10, len);
break;
case 'A':
+ case 'Z':
case 'a':
fromstr = NEXTFROM;
aptr = SvPV(fromstr, fromlen);
* POD patch
Following is a POD patch attempt. But I'd like to see the notion of
pack/unpack symmetry more thoroughly explained in the POD. Not a
native speaker of English, I didn't ventured into these more radical
changes. I hope my long rationale can be converted to a terser and
cleaner summary suitable for inclusion in the POD.
--- pod/perlfunc.pod~ Thu May 8 19:43:18 1997
+++ pod/perlfunc.pod Mon Jun 16 02:50:55 1997
@@ -2092,8 +2092,10 @@
sequence of characters that give the order and type of values, as
follows:
+ a A string with arbitrary binary data, will be null padded.
A An ascii string, will be space padded.
- a An ascii string, will be null padded.
+ Z A null terminated (asciz) string, will be null padded.
+
b A bit string (ascending bit order, like vec()).
B A bit string (descending bit order).
h A hex string (low nybble first).
@@ -2143,20 +2145,21 @@
@ Null fill to absolute position.
Each letter may optionally be followed by a number which gives a repeat
-count. With all types except "a", "A", "b", "B", "h", "H", and "P" the
-pack function will gobble up that many values from the LIST. A * for the
-repeat count means to use however many items are left. The "a" and "A"
-types gobble just one value, but pack it as a string of length count,
-padding with nulls or spaces as necessary. (When unpacking, "A" strips
-trailing spaces and nulls, but "a" does not.) Likewise, the "b" and "B"
-fields pack a string that many bits long. The "h" and "H" fields pack a
-string that many nybbles long. The "P" packs a pointer to a structure of
-the size indicated by the length. Real numbers (floats and doubles) are
-in the native machine format only; due to the multiplicity of floating
-formats around, and the lack of a standard "network" representation, no
-facility for interchange has been made. This means that packed floating
-point data written on one machine may not be readable on another - even if
-both use IEEE floating point arithmetic (as the endian-ness of the memory
+count. With all types except "a", "A", "Z", "b", "B", "h", "H", and "P"
+the pack function will gobble up that many values from the LIST. A * for
+the repeat count means to use however many items are left. The "a", "A"
+and "Z" types gobble just one value, but pack it as a string of length
+count, padding with nulls or spaces as necessary. (When unpacking, "A"
+strips trailing spaces and nulls, "Z" strips trailing nulls and "a"
+returns data verbatim.) Likewise, the "b" and "B" fields pack a string
+that many bits long. The "h" and "H" fields pack a string that many
+nybbles long. The "P" packs a pointer to a structure of the size
+indicated by the length. Real numbers (floats and doubles) are in the
+native machine format only; due to the multiplicity of floating formats
+around, and the lack of a standard "network" representation, no facility
+for interchange has been made. This means that packed floating point data
+written on one machine may not be readable on another - even if both use
+IEEE floating point arithmetic (as the endian-ness of the memory
representation is not part of the IEEE spec). Note that Perl uses doubles
internally for all numeric calculation, and converting from double into
float and thence back to double again will lose precision (i.e.,
----8<--------8<--------8<--------8<--------8<--------8<--------8<----
SY, Uwe
--
uwe@ptc.spbu.ru | Zu Grunde kommen
http://www.ptc.spbu.ru/~uwe/ | Ist zu Grunde gehen
------------------------------
Date: Wed, 1 Oct 1997 15:25:17 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: dsstevens@ingrDOT.com
Subject: Re: Reading Excel
Message-Id: <Pine.GSO.3.96.971001152452.236I-100000@usertest.teleport.com>
On Wed, 1 Oct 1997 dsstevens@ingrDOT.com wrote:
> I am looking for the code to open existing MS Excel files and read the
> specific cells.
If there's a module which does what you want, it should be listed in
the module list on CPAN. If you don't find one to your liking, you're
welcome and encouraged to submit one! :-) Hope this helps!
http://www.perl.org/CPAN/
http://www.perl.com/CPAN/
--
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: Wed, 01 Oct 1997 15:09:18 -0400
From: Ross Swanson <rswanson@sarnoff.com>
Subject: simple
Message-Id: <34329FDD.32BEC7A3@sarnoff.com>
# if
$memory {
asram =>[ qw(96x12 256x8 380x8 384x8 384x16 1152x16 2048x18)],
ram =>[ qw(64x8 64x10 64x16 64x32 96x18
128x8 128x16 128x20 256x20 256x32 384x8 384x16 1024x20)],
rom => [ qw( 1024x17 1024x20)]
};
$p = \*STDOUT;
# then how do I get the values in the 'array' ?
print $p @($memory->{test})[1],"\n";
# and what does the for loop look like?
# Ross
------------------------------
Date: 1 Oct 97 20:07:30 GMT
From: rpete@ascda3.harvard.edu (Pete Ratzlaff)
To: rswanson@sarnoff.com
Subject: Re: simple
Message-Id: <3432ad82.0@cfanews.harvard.edu>
Ross Swanson (rswanson@sarnoff.com) wrote:
> # if
> $memory {
> asram =>[ qw(96x12 256x8 380x8 384x8 384x16 1152x16 2048x18)],
> ram =>[ qw(64x8 64x10 64x16 64x32 96x18
> 128x8 128x16 128x20 256x20 256x32 384x8 384x16 1024x20)],
> rom => [ qw( 1024x17 1024x20)]
> };
> $p = \*STDOUT;
> # then how do I get the values in the 'array' ?
> print $p @($memory->{test})[1],"\n";
> # and what does the for loop look like?
> # Ross
To get an entire array,
@{$memory->{ram}}; # or
@{$$memory{ram}};
To get just an element,
${$memory->{ram}}[0];
This reference stuff gets easier as you do it more often.
-------------
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: Wed, 1 Oct 1997 15:28:14 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: Ross Swanson <rswanson@sarnoff.com>
Subject: Re: simple
Message-Id: <Pine.GSO.3.96.971001152623.236K-100000@usertest.teleport.com>
On Wed, 1 Oct 1997, Ross Swanson wrote:
> Subject: simple
Please check out this helpful information on choosing good subject
lines. It will be a big help to you in making it more likely that your
requests will be answered.
http://www.perl.com/CPAN/authors/Dean_Roehrich/subjects.post
> # if
>
> $memory {
> asram =>[ qw(96x12 256x8 380x8 384x8 384x16 1152x16 2048x18)],
> ram =>[ qw(64x8 64x10 64x16 64x32 96x18
> 128x8 128x16 128x20 256x20 256x32 384x8 384x16 1024x20)],
> rom => [ qw( 1024x17 1024x20)]
> };
> # then how do I get the values in the 'array' ?
See the manpages perlref(1), perllol(1), and perldsc(1). If you've still
got questions that aren't answered in the docs, please post again. Thanks!
--
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: Wed, 01 Oct 1997 18:25:32 GMT
From: keng@nospam.hybrid.com (Ken Gaugler)
Subject: Re: splitting a tab delimited line
Message-Id: <34339540.100851751@dracula.hybrid.com>
How about
@fields=split(/\t/,$line) # split $line, using tab (\t) as a separator
On Tue, 30 Sep 1997 15:46:13 -0700, "Ernie Johnson" <tcm@tcmd.com>
wrote:
> Anyone have some thoughts on what I need to do to be able to split a tab
>delimited text file?
>
>It has a format of
>
>partnumber<tab>part description<tab>category<tab>stock<tab>price
>
>I'd have no problem using split( ) but don't know what to tell split() to
>split on.
>
>please cc replies to tcm@tcmd.com
>
>ernie johnson
>
>
---
To reply to this post, remove the 'nospam.' from my address.
Ken Gaugler N6OSK Systems Engineer, Hybrid Networks, Inc.
(personal: keng @wco.com URL: http://www.wco.com/~keng)
------------------------------
Date: Wed, 1 Oct 1997 23:41:45 +0100
From: Mark Worsdall <jaydee@worsdall.demon.co.uk>
Subject: Traceroute, a perl version
Message-Id: <PAePnbApGtM0EwZH@worsdall.demon.co.uk>
Hi,
Now I have a perl script that takes an IP number and DNS's it. If this
fails to come up with a domain name then the script initiates a
traceroute with the IP number. All of this is piped to the body of the
mail program so I get the results. At the moment I am working on 2 more
improvements to the script.
1) Currently I am trying to get it to also check fo a web page at the IP
number DNS'ed, which entails my program taking the domain name and
trying to read an html page from this address, if it fails then subtract
the first part of the address from it and try again until we run out of
domain name, in which case there is no webpage. If a webpage is read
then I extract the title of the page and write the URL along with the
page title to the mail program. THIS I am not asking for advice on as it
is nearly done (Hopefully, though hard to test on a win95 system and
off-line). How you would have done it would be interesting though.
2) I would like to implement my own version of traceroute in perl so I
can get the last domain name (text address as oppose to Number) seen.
Then I can feed this into what I am doing in point 1.
Any ideas? Like nope, no way:-)
--
Mark Worsdall - Oh no, I've run out of underpants :(
Home:- jaydee@worsdall.demon.co.uk WEB site:- http://www.worsdall.demon.co.uk
Shadow:- webmaster@shadow.org.uk WEB site:- http://www.shadow.org.uk
------------------------------
Date: Wed, 01 Oct 1997 15:01:21 +0100
From: Greg Nadan <gnadan@channell.com>
Subject: Re: unlink & rename
Message-Id: <343257B1.86A387A1@channell.com>
I am willing to bet the your web server does not have the correct
permission to do the unlink or rename on those files!!! Check what
account(user) your web server is running as, then make sure that user has
permission to read/write those file.
Omar zalouq wrote:
> Hi,
>
> part of my script is as follows:
>
> unlink ("man.txt");
> rename ("temp.txt", "man.txt");
>
> when it is executed from xterm everything goes fine,
> but when the script is executed from netscape, It fails to do the above
> actions,but does not give any errors, hhmmmmm.....
>
> thanx for your help!!
> pls mailto: no@earthling.net
------------------------------
Date: 1 Oct 1997 17:55:07 GMT
From: glockner@shell. (Gregory Glockner)
Subject: Wanted: Wall/Schwartz book (1st ed)
Message-Id: <60u2pr$gds$1@news.wco.com>
I am looking for a copy of the old version of the book "Programming perl"
by Wall and Schwartz that covers Perl 4.0. I can only seem to find the
newer version that covers Perl 5.0. If you have an extra copy of this
book (ISBN 0-937175-64-1), please contact me by email. TIA.
--
Gregory Glockner, Ph.D. http://www.wco.com/~glockner/
415-474-0169 glockner@wco.com
------------------------------
Date: 8 Mar 97 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 8 Mar 97)
Message-Id: <null>
Administrivia:
The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc. For subscription or unsubscription requests, send
the single line:
subscribe perl-users
or:
unsubscribe perl-users
to almanac@ruby.oce.orst.edu.
To submit articles to comp.lang.perl.misc (and this Digest), send your
article to perl-users@ruby.oce.orst.edu.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.
The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq". The real FAQ, as it
appeared last in the newsgroup, can be retrieved with the request "send
perl-users FAQ". Due to their sizes, neither the Meta-FAQ nor the FAQ
are included in the digest.
The "mini-FAQ", which is an updated version of the Meta-FAQ, is
available by requesting "send perl-users mini-faq". It appears twice
weekly in the group, but is not distributed in the digest.
For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V8 Issue 1111
**************************************