[12248] in Perl-Users-Digest
Perl-Users Digest, Issue: 5848 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Jun 1 11:07:17 1999
Date: Tue, 1 Jun 99 08:00:19 -0700
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Tue, 1 Jun 1999 Volume: 8 Number: 5848
Today's topics:
An Efficient Split Function <rael@see.sig>
anyone want to help a beginner? <mattfree@hardlink.com>
Re: anyone want to help a beginner? <rootbeer@redcat.com>
Re: Artistic License (Matthew Bafford)
Re: Artistic License (Tad McClellan)
Creating HTML Table from file?? <robert.meppelink@ict.nl>
Re: Creating HTML Table from file?? <rootbeer@redcat.com>
Re: m// in list context - can't tell if match succeeded <rootbeer@redcat.com>
Packing a raw IP..... bennycc@pacific.net.sg
perl application help needed (VROOMZR)
Re: perl application help needed <rootbeer@redcat.com>
Re: Perl/CGI/MIME attachments difficulty <rootbeer@redcat.com>
Re: Perl/CGI/MIME attachments difficulty <fruffet@kaptech.com>
Re: Perl/CGI/MIME attachments difficulty (I.J. Garlick)
PFR: Convert engineering notation to arbitrary fixed-po <jdiscenza@carletoninc.com>
Re: Secure join? <rootbeer@redcat.com>
Re: Serial port question... (Bbirthisel)
Re: User Authentication using .htaccess and perl <rootbeer@redcat.com>
Re: User Authentication using .htaccess and perl <yasser@x-unity-x.demon.co.uk>
Re: User Authentication using .htaccess and perl <rootbeer@redcat.com>
Win32::ODBC LIMITS??? (16,377 bytes) and not one more. <kangas@anlon.com>
Re: Y2K infected Perl code ()
Re: You can earn $50,000 40686 (Jochem Huhmann)
Special: Digest Administrivia (Last modified: 12 Dec 98 (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 01 Jun 1999 08:58:19 -0500
From: "William S. Lear" <rael@see.sig>
Subject: An Efficient Split Function
Message-Id: <8790a4rpj8.fsf@lisa.zopyra.com>
I am reposting this to comp.lang.perl.misc since there seems to be
some confusion (and, I must say, some surprising anger) over the
contents of this post.
Let me outline my motivation for this posting to try to avert any
flame wars: we have a Perl program that processes log files that are
fairly regular --- they have lines split by a field separator
character; the fields are fixed in number; the fields are of a
predictable length. This Perl program is taking nearly 20 hours to
run, so I decided to conduct a somewhat generalized investigation, and
compare one very small part of the basic process to a C++ version in
order to get a very crude estimate of the type of speedup I might
expect. I compared the Python version as well because I simply wanted
another data point (I fully expected the Python version to run more
slowly than the Perl version). Note also that I was not trying to
write a *generalized* split function in C++ that mimics that of Perl;
I'm simply trying to write one that will handle the particular data
set that we have need of processing. I'm fully aware of the power of
Perl, how flexible it is, etc., and that the C++ version that I have
written is specialized, intended to solve a particular problem, has
thereby a variety of limitations, etc., etc.
Let me be clear: I am not, it should be needless to say, waging an
"anti-Perl" war here. I code in Perl, Python, and C++ a great deal,
and am not interested in why one language is better, broadly
considered, than another. I am simply interested in a very narrow
comparison, that is intended to provide a starting point for a broader
inquiry. I was hoping to devise a C++ version that ran in under 10%
of the time of the fasted interpreted version --- an arbitrarily
chosen goal.
The original post is very heavily slanted to the C++ algorithms that I
devised for the comparison. The Perl code in question is up front for
those not interested in scanning further.
Now, here is my original post:
I have made an effort to write an efficient split function in C++,
comparing it to similar versions written in Python and Perl. I'm
posting this to the three language communities because I would like
help in answering two questions: Is my approach in general valid?
and, Are the particular solutions I've come up with in each language
reasonable? Those who would like to reply to me directly can do so at
the address in my .sig.
An efficient split function is part of the foundation of many programs
--- especially those that, e.g, summarize information in log files of
various sorts. The other part that is quite important for performance
issues, as I have discovered, is the routine used to read in the "raw"
information. The idiom used here, quite common I'm sure, might be
thought of as "Read a line; Split on a separator character; Process
the fields" (we might call this the "RSP" idiom). My focus below is
on the first two parts of this idiom.
I have been testing a set of functions I have written to split
character strings (both NULL-terminated character arrays and C++
strings). I needed to see what sort of performance improvement I
could get over two interpreted languages I use quite frequently,
Python (version 1.5.2) and Perl (version 5.004_04).
For comparison, I used the following Perl program:
my $count = 0;
my @v;
while (<STDIN>) {
@v = split(/\|/);
$count++;
}
print "$count\n";
and the following Python program:
import sys, string
def main():
readline = sys.stdin.readline
split = string.split
count = 0
while 1:
line = readline()
if not line: break
l = split(line, '|')
count = count + 1
print count
main()
As can be seen, to substitute for the third part of the RSP idiom I
simply coded a count of the number of lines processed.
Surprisingly, to me, the Python version far outperformed the Perl
version. Running on 1 million lines of input of 9 fields each, the
Python version ran in just under 16 seconds, the Perl version in just
under 40 seconds (this on a 400Mhz Pentium Linux box). [Author's note:
this is a ratio of 2.5 to 1.]
For the C++ split function, the first time through I tried a very
straightforward approach using the C++ string and vector classes (I'm
using the egcs compiler, version 1.1b). The split function prototype
is
int split(vector<string>&, const string&, char);
(I've posted the implementation of the split functions below) and the
main function is:
main() {
string line;
vector<string> v;
int count = 0;
while (getline(cin, line)) {
split(v, line, '|');
++count;
}
cout << count << endl;
}
This ran in about 8.5 seconds, (21% of Perl, 54% of Python). But, this
wasn't the sort of speedup I had in mind, so I kept plowing ahead.
Previous tests of mine comparing the getline() version that works
with C++ strings and that which works with character arrays showed me
that the latter was much faster, albeit less flexible. So, keeping
the general split algorithm intact, I recoded the split function:
int split(vector<string>&, const char*, char);
and the main routine:
main() {
char line[1024];
vector<string> v;
int count = 0;
while (cin.getline(line, 1024)) {
split(v, line, '|');
++count;
}
cout << count << endl;
}
This ran in about 4.75 seconds (12% of Perl, 30% of Python). Better, but
I still wanted more. So I devised a split routine to operate on character
arrays, but to create a vector of "spans" instead of strings:
typedef pair<const char*, const char*> span;
int split(vector<span>&, const char*, char);
and a new main routine:
main() {
char line[1024];
vector<span> v(30);
int count = 0;
while (cin.getline(line, 1024)) {
split(v, line, '|');
++count;
}
cout << count << endl;
}
This ran in 1.2 seconds (3% of Perl, 7.5% of Python), which sounded about
where I wanted the performance to be.
For comparison purposes, here are the three split routines:
// Split a string on a given character into a vector of strings
// The vector is passed by reference and cleared each time
// The number of strings split out is returned
int split(vector<string>& v, const string& str, char c)
{
v.clear();
string::const_iterator s = str.begin();
while (true) {
string::const_iterator begin = s;
while (*s != c && s != str.end()) { ++s; }
v.push_back(string(begin, s));
if (s == str.end()) {
break;
}
if (++s == str.end()) {
v.push_back("");
break;
}
}
return v.size();
}
// Split a NULL-terminated character array on a given character into
// a vector of strings
// The vector is passed by reference and cleared each time
// The number of strings split out is returned
int split(vector<string>& v, const char* s, char c)
{
v.clear();
while (true) {
const char* begin = s;
while (*s != c && *s) { ++s; }
v.push_back(string(begin, s));
if (!*s) {
break;
}
if (!*++s) {
v.push_back("");
break;
}
}
return v.size();
}
// Represents a span of a character array
typedef pair<const char*, const char*> span;
// Convenience function to set a span
inline void set_span(span& s, const char* b, const char* e)
{
s.first = b;
s.second = e;
}
// Split a NULL-terminated character array on a given character into
// a vector of spans
// The vector is of constant size is not cleared each time
// The number of spans split out is returned
int split(vector<span>& v, const char* s, char c)
{
int i = 0;
while (true) {
const char* begin = s;
while (*s != c && *s) { ++s; }
set_span(v[i++], begin, s);
if (!*s) {
break;
}
if (!*++s) {
set_span(v[i++], 0, 0);
break;
}
}
return i;
}
Each of these routines will split the following string:
<field0>|<field1>|<field2>| ... |<fieldN>
where any of the N fields can be empty, into N+1 fields.
So, what do folks think of this? Obviously, the particular span
approach above has the drawback that is relies both on a fixed-length
input buffer and a fixed-length vector of spans. However, for my
purposes, this is safe enough and speed is paramount at this time.
I'm sure there are better ways to approach this, issues I haven't
thought of, speed gains to be found here and there, etc. I'd be glad
to hear of them.
Bill
--
William S. Lear | Who is there that sees not that this inextricable labyrinth
r a e l @ | of reasons of state was artfully invented, lest the people
z o p y r a . | should understand their own affairs, and, understanding,
c o m | become inclined to conduct them? ---William Godwin, 1793
------------------------------
Date: Tue, 1 Jun 1999 07:37:02 -0700
From: "Matt" <mattfree@hardlink.com>
Subject: anyone want to help a beginner?
Message-Id: <7j0qvp$d8o$1@newssvr04-int.news.prodigy.com>
i'm fairly new to perl, and i've written a simple CGI script that does
madlibs. now i realize that usually when someone posts a request it's
because they have a problem. well, my script seems to work fine, but like i
said i'm a beginner. i'm sure i made a mistake someplace
i wouldn't ask people to look at it, except it's very short. the meat of it
is only about 6 lines. i'd just like to know if i'm doing anything stupid.
any feedback is greatly appreciated.
the source of it is on my web page, so rather than post it here and waste
space i'll just give the link
http://www.hardlink.com/~mattfree/madlibs/source.html
i realize you guys don't have time to run around the web looking at
everybody's stuff, but if you can help then i'm grateful
-Matt
------------------------------
Date: Tue, 1 Jun 1999 07:50:21 -0700
From: Tom Phoenix <rootbeer@redcat.com>
Subject: Re: anyone want to help a beginner?
Message-Id: <Pine.GSO.4.02A.9906010742370.13086-100000@user2.teleport.com>
On Tue, 1 Jun 1999, Matt wrote:
> Subject: anyone want to help a beginner?
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
> well, my script seems to work fine, but like i
> said i'm a beginner. i'm sure i made a mistake someplace
Probably. What does your code do that you didn't expect? That information
would be a big clue.
When you're having trouble with a CGI program in Perl, you should first
look at the please-don't-be-offended-by-the-name Idiot's Guide to solving
such problems. It's available on CPAN.
http://www.perl.com/CPAN/
http://www.perl.org/CPAN/
http://www.perl.org/CPAN/doc/FAQs/cgi/idiots-guide.html
http://www.perl.org/CPAN/doc/manual/html/pod/
The following quotes come from the code.
> my(%data) = &parseURL($ENV{QUERY_STRING});
Why aren't you using a thoroughly-debugged module to deal with your CGI
parameters? That looks to be your first mistake. It's a touch tricky to
get it right, and this subroutine doesn't.
> open (TEMPLATE, "$data{template}") ||
Does this mean that you'll let remote users read your /etc/passwd file
over the web? I'd recommend that you plug this security hole!
Well, that's enough to get you started. Good luck!
--
Tom Phoenix Perl Training and Hacking Esperanto
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: Tue, 01 Jun 1999 13:07:17 GMT
From: dragons@dragons.duesouth.net (Matthew Bafford)
Subject: Re: Artistic License
Message-Id: <slrn7l7kuo.28m.dragons@dragons.duesouth.net>
On Tue, 1 Jun 1999 00:00:37 -0700, David Christensen <dchrist@dnai.com>
held some poor sysadmin at gun point while typing in the following:
: I am researching confidential disclosure and intellectual property
: agreements. An "Artistic License" is mentioned in the documentation for
: Perl, and indicates that it can be found with the source files. I don't
: think I have this file and can't seem to find it separate from a the whole
: tarball on CPAN. Can someone please post a link or send it to me?
http://www.activestate.com/corporate/artistic_license.htm
: TIA,
--Matthew
------------------------------
Date: Tue, 1 Jun 1999 05:42:00 -0400
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Artistic License
Message-Id: <8t90j7.d64.ln@magna.metronet.com>
David Christensen (dchrist@dnai.com) wrote:
: An "Artistic License" is mentioned in the documentation for
: Perl, and indicates that it can be found with the source files. I don't
: think I have this file and can't seem to find it separate from a the whole
: tarball on CPAN.
Hmmm.
I have 2 unpacked perl tarballs here.
They both have a file named 'Artistic' at the top level.
The tarball you looked at doesn't have that file?
--
Tad McClellan SGML Consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Tue, 1 Jun 1999 15:34:22 +0200
From: "Robert Meppelink" <robert.meppelink@ict.nl>
Subject: Creating HTML Table from file??
Message-Id: <7j0nch$q4u$1@tasmania.dev.ict.nl>
Hello PERL guru's over there!
I'm a newbee at the PERL scene, but I must say it's a rather nice script
language.
But now I have got a question. The following is the matter:
I'm having a file like this:
Archive: P:\VDO_WETZ\csi_platform\product\01-contents\TOC
product.dvc
Workfile: TOC product.doc
Archive created: 06 Apr 1999 13:13:12
Owner: schroeg
Last trunk rev: 1.16
Locks:
Groups: Draft : 1.16
Rev count: 17
Attributes:
WRITEPROTECT
CHECKLOCK
NOEXCLUSIVELOCK
NOEXPANDKEYWORDS
NOTRANSLATE
NOCOMPRESSDELTA
NOCOMPRESSWORKIMAGE
NOGENERATEDELTA
COMMENTPREFIX = ""
NEWLINE = "\r\n"
Version labels:
"ICT1999-05-0226.2.1-1" = 1.*
Description:
Empty Table of Contents Product
This is repeated about 30 times or so. But now I want this info displayed in
a HTML page in a TABLE.
Like this(but with the lines and stuff:
Workfile: Owner: Version Labels:
TOC product.doc schroeg ICT1999-05-0226.2.1-1 =1.*
.... .... ......
.... .... ......
The main question is? Can this be done easiliy with PERL ??
(sub)questions are:
How can I use PERL for reading the Attributes from the file, I can read one
line from a file, and split it, but I don't know how to use PERL for reading
more than one line ?? like the Attributes: ???
How can I split up a line like Workfile
So I get the 'keyword' Workfile and the 'data' TOC product.doc.
Now I use split function e.g. ($header,$data) = split(/Workfile:/,$_);
But when I want to display $header it's empty ??
And when I use $&, $' and $` for match prematch and aftermatch it read's
everything after the $match till the end of the file and that's not what I
want, it must read till the end of the line !
Can I create my HTML File when reading the inputfile in a while loop?
Because now I do this, and it looks for all matches in the file, not just
one match, I read something about changing the greedines with using ? but I
tried this And it doesn't work like this: if($Archive{1}?/) What's wrong
about this??
Well enough questions right now or else I will be banned :-)
Hope somebody is willing to help me!
greetz from Mark !!
------------------------------
Date: Tue, 1 Jun 1999 07:17:26 -0700
From: Tom Phoenix <rootbeer@redcat.com>
Subject: Re: Creating HTML Table from file??
Message-Id: <Pine.GSO.4.02A.9906010709340.13086-100000@user2.teleport.com>
On Tue, 1 Jun 1999, Robert Meppelink wrote:
> The main question is? Can this be done easiliy with PERL ??
Yep.
> How can I use PERL for reading the Attributes from the file, I can
> read one line from a file, and split it, but I don't know how to use
> PERL for reading more than one line ?? like the Attributes: ???
If you can read one line, maybe you want to use a loop to read and process
multiple lines.
> How can I split up a line like Workfile
> So I get the 'keyword' Workfile and the 'data' TOC product.doc.
> Now I use split function e.g. ($header,$data) = split(/Workfile:/,$_);
> But when I want to display $header it's empty ??
Maybe you want to use a pattern match, more or less like this.
($header, $data) = /^(\w+):\s*(.*)/;
> And when I use $&, $' and $` for match prematch and aftermatch it
> read's everything after the $match till the end of the file and that's
> not what I want, it must read till the end of the line !
Maybe you're reading multiple lines into a single string, perhaps?
> Can I create my HTML File when reading the inputfile in a while loop?
Yes.
> Because now I do this, and it looks for all matches in the file, not just
> one match, I read something about changing the greedines with using ? but I
> tried this And it doesn't work like this: if($Archive{1}?/) What's wrong
> about this??
It's syntactically invalid. But if you want just the first match in the
file when you're reading line-by-line, non-greedy matching isn't the tool
you need. You probably want to set a flag to know when you've found the
match.
I recommend that you concentrate on solving one problem at a time, rather
than trying to tackle all of these at once. Maybe you should first see
that you can read your input data one line at a time and identify the
headers. Good luck!
--
Tom Phoenix Perl Training and Hacking Esperanto
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: Tue, 1 Jun 1999 07:35:07 -0700
From: Tom Phoenix <rootbeer@redcat.com>
Subject: Re: m// in list context - can't tell if match succeeded or failed
Message-Id: <Pine.GSO.4.02A.9906010732310.13086-100000@user2.teleport.com>
On Tue, 1 Jun 1999, Joey Hess wrote:
> According to the man page:
>
> If used in a context that requires a list value, a pattern match
> returns a list consisting of the subexpressions matched by the
> parentheses in the pattern, i.e., ($1, $2, $3...). (Note that here $1
> etc. are also set, and that this differs from Perl 4's behavior.) If
> the match fails, a null array is returned. If the match succeeds, but
> there were no parentheses, a list value of (1) is returned.
>
> This seems badly designed to me. There's no way to differentiate
> between a successful match with one set of parens that didn't trap
> anything, and a failed match with no parens.
Sure there is: In one case you used parens. :-)
The list context value of m// was designed with memory parens in mind. If
you're not using parens, is there a reason to use list context?
--
Tom Phoenix Perl Training and Hacking Esperanto
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: Tue, 01 Jun 1999 10:47:39 +0800
From: bennycc@pacific.net.sg
Subject: Packing a raw IP.....
Message-Id: <375349CB.15D2EC53@pacific.net.sg>
Hi,
Been trying out how to pack a IP header + data. (UDP + TCP)
And also, how to calulate the checksum.
Saw someone use the pack (TEMPLATE, LIST) command. But was wondering
about the
template part of it.
Benny
bennycc@pacific.net.sg
------------------------------
Date: 1 Jun 1999 14:22:19 GMT
From: vroomzr@aol.com (VROOMZR)
Subject: perl application help needed
Message-Id: <19990601102219.01107.00002930@ng-cq1.aol.com>
Hello,
I'm trying to create a cgi application that will take input from my own htm
form and then send it off to another person's cgi application, take the return
output and use that along with some other stuff as input for another cgi
application. Can this be done using perl and cgi, or should I use java
servlets. The rest of this site has been written with perl and I would like to
keep it that way. Any help or urls with help on this subject would be greatly
appreciated. Thank you, ryan.
------------------------------
Date: Tue, 1 Jun 1999 07:27:16 -0700
From: Tom Phoenix <rootbeer@redcat.com>
Subject: Re: perl application help needed
Message-Id: <Pine.GSO.4.02A.9906010726440.13086-100000@user2.teleport.com>
On 1 Jun 1999, VROOMZR wrote:
> I'm trying to create a cgi application that will take input from my
> own htm form and then send it off to another person's cgi application,
> take the return output and use that along with some other stuff as
> input for another cgi application. Can this be done using perl and
> cgi, or should I use java servlets.
It sure sounds as if Perl can do this. Good luck!
--
Tom Phoenix Perl Training and Hacking Esperanto
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: Tue, 1 Jun 1999 06:45:32 -0700
From: Tom Phoenix <rootbeer@redcat.com>
Subject: Re: Perl/CGI/MIME attachments difficulty
Message-Id: <Pine.GSO.4.02A.9906010644030.13086-100000@user2.teleport.com>
On Tue, 1 Jun 1999, Max Pinton wrote:
> This almost works - Outlook Express 4.5 Mac shows an attachment and the
> "part one" text fine, and it all looks fine when I Show Source. But
> when I save the attachment, OE assumes that it's base64 encoded, and
> "decodes" into an mangled mess. Is this an Outlook problem, or am I
> doing something wrong?
Well, if you're using the proper protocol in the proper way, it sounds
like an Outlook problem. If you're not, it's a bug in your code. If you're
not sure, you should check the protocol specification again, or check with
a newsgroup about the protocol. Good luck!
--
Tom Phoenix Perl Training and Hacking Esperanto
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: Tue, 1 Jun 1999 15:05:05 +0200
From: "Fred Ruffet" <fruffet@kaptech.com>
Subject: Re: Perl/CGI/MIME attachments difficulty
Message-Id: <7j0lqt$vu$1@gatekeeper.ornano.kapt.com>
Max,
I don't see anything wrong with the structure you made, but I'm not a
specialist. All I know is that I had problems like this, and I use the
MIME::Lite module, which works fine. It's not too hard to understand, and is
quiet simple to use.
Regards,
Fred
------------------------------
Date: Tue, 1 Jun 1999 14:17:17 GMT
From: ijg@csc.liv.ac.uk (I.J. Garlick)
Subject: Re: Perl/CGI/MIME attachments difficulty
Message-Id: <FCnJot.LzF@csc.liv.ac.uk>
In article <010619990451089942%max@maxgraphic.com>,
Max Pinton <max@maxgraphic.com> writes:
> To: blah
> ...
> Content-type: multipart-mixed;
> boundary="MIME_Part"
>
> --MIME_Part
> Content-type: text/plain; charset="US-ASCII"
> Content-transfer-encoding: 7bit
>
> part one
>
> --MIME_Part
> Content-type: text/plain; name="results.txt"
> Content-disposition: attachment
> Content-transfer-encoding: 7bit
>
> part two
>
> --MIME_Part
^^
>
> This almost works - Outlook Express 4.5 Mac shows an attachment and the
> "part one" text fine, and it all looks fine when I Show Source. But
> when I save the attachment, OE assumes that it's base64 encoded, and
> "decodes" into an mangled mess. Is this an Outlook problem, or am I
> doing something wrong?
Yep you are. Go read the MIME spec again you missed something (see above).
Come to think of it this has nothing to do with Perl either as you would
get it equally wrong in C, C++ etc.... doing it this way.
--
Ian J. Garlick
ijg@csc.liv.ac.uk
Falling in love is a lot like dying. You never get to do it enough to
become good at it.
------------------------------
Date: Tue, 1 Jun 1999 09:49:28 -0400
From: "Joe Discenza" <jdiscenza@carletoninc.com>
Subject: PFR: Convert engineering notation to arbitrary fixed-point format
Message-Id: <3753e4d0@news-out2.newsnerds.com>
This may come in handy for other programmers. I was running into
a problem: I had to read a file that (possibly) contained numbers in
engineering notation (1e4, 2.36e-9, etc.), and the next tool in the
pipe could not understand this, but had to have fixed-point numbers
(10000, .00000000236, etc.). s?printf springs instantly to mind, but
you need to know ahead of time how many places you want to show
(i.e., "%.11f" for the 2.36e-9 example) or you will lose precision
(especially for negative exponents). It's terribly wasteful to use
"%.42f" everywhere (I could have a 10-digit mantissa w/an exponent
of -33) since *most* of the time I have 1e-2 and such. Figuring out
the precision and then using s?printf turned out to be less efficient
than the following.
Credit for the basic idea goes to $Bill Luebkert.
Note that the next tool in my pipe does not require a leading 0 before
the decimal point in the fixed-point format, so the last line strips all
leading zeros. You could change that if you need them.
__BEGIN__
# first, make sure I have a leading digit for the real match below
# (it's more efficient than an alternation in the real match)
$line =~ s/(\D)(\.\d+e[-+]?\d+)/${1}0$2/gi;
$line =~ s/(\d+)\.?(\d*)e([-+]?)(\d+)/&conv_eng($1, $2, $3, $4)/egi;
sub conv_eng {
my ($intpart, $fracpart, $expsign, $exponent) = @_;
my $num = $intpart . $fracpart; # digits only: insert decimal point later
if ($expsign eq '-') {
$num = '0' x $exponent . $num; # pad w/leading 0's
$num = substr($num, 0, length($intpart)) . '.'
. substr($num, length($intpart));
}
else {
$num .= '0' x $exponent; # pad w/trailing 0's
$num = substr($num, 0, length($intpart) + $exponent) . '.'
. substr($num, length($intpart) + $exponent);
}
# now we may have leading/trailing 0's to get rid of to make it pretty
$num =~ s/^0*(.*?)\.?0*$/$1/;
# you should change to
#$num =~ s/\.?0*$//;
# (or skip entirely) if you need a leading 0 before a fraction
return $num;
}
__END__
------------------------------
Date: Tue, 1 Jun 1999 06:39:33 -0700
From: Tom Phoenix <rootbeer@redcat.com>
Subject: Re: Secure join?
Message-Id: <Pine.GSO.4.02A.9906010633240.13086-100000@user2.teleport.com>
On Tue, 1 Jun 1999, Pavel Kotala wrote:
> I use DBD - oracle. Sometimes I receive rows with NULL (in Perl
> undefined) values.
>
> Then in this line:
>
> print RR join( ",", @$row) . "\n";
>
> I receive message:
>
> Use of uninitialized value at ...
> Where is an error? I using join bad (then exists any secure join
> function, that replaces undefined to "")?
One way would be to use map to prepare the arguments to join:
map defined($_) ? $_ : 'NULL', @$row
The use of the ?: operator can be confusing. This says that if the value
(temporarily in $_) is defined, use it as itself. Otherwise, use the
string 'NULL'. Of course, you could replace that NULL with text of your
choice.
Cheers!
--
Tom Phoenix Perl Training and Hacking Esperanto
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: 1 Jun 1999 14:37:42 GMT
From: bbirthisel@aol.com (Bbirthisel)
Subject: Re: Serial port question...
Message-Id: <19990601103742.13051.00007006@ng-fh1.aol.com>
Hi Mitch:
>I'm writing a script right now, that should allow the user to change the
>baud rate on the serial port, how do I do this?
Depends on which Operating System you are running.
Is baud rate the only parameter of interest? There are
usually others you need as well. If you provide a few
details it will be easier to give useful answers.
-bill
Making computers work in Manufacturing for over 25 years (inquiries welcome)
------------------------------
Date: Tue, 1 Jun 1999 06:52:29 -0700
From: Tom Phoenix <rootbeer@redcat.com>
Subject: Re: User Authentication using .htaccess and perl
Message-Id: <Pine.GSO.4.02A.9906010649540.13086-100000@user2.teleport.com>
On Tue, 1 Jun 1999, Yasser Nabi wrote:
> A friend has a web page which is protected with .htacces and he asked
> me if i could write a perl script which basicaly replaced the dialog
> box which is produced. So what I would like to know is how can I read
> and verify users from the .htpasswd and then say to the server that
> the users have been authenticated.
You can open files for reading with the open() function. You may use the
crypt() function to verify the password. Is that what you needed to know?
If you have questions about how your program can interact with the server
or browser, check the docs, FAQs, and newsgroups about servers, browsers,
and the protocols they use.
Good luck!
--
Tom Phoenix Perl Training and Hacking Esperanto
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: Tue, 1 Jun 1999 15:18:25 +0100
From: "Yasser Nabi" <yasser@x-unity-x.demon.co.uk>
Subject: Re: User Authentication using .htaccess and perl
Message-Id: <928246628.25253.0.nnrp-04.c1edd835@news.demon.co.uk>
Tom Phoenix <rootbeer@redcat.com> wrote in message
news:Pine.GSO.4.02A.9906010649540.13086-100000@user2.teleport.com...
> On Tue, 1 Jun 1999, Yasser Nabi wrote:
>
> > A friend has a web page which is protected with .htacces and he asked
> > me if i could write a perl script which basicaly replaced the dialog
> > box which is produced. So what I would like to know is how can I read
> > and verify users from the .htpasswd and then say to the server that
> > the users have been authenticated.
>
> You can open files for reading with the open() function. You may use the
> crypt() function to verify the password. Is that what you needed to know?
Thanks,
but how would the webserver know that the authentication ha gone through,
what I mean is...
placing .htacces in a dir, prevents any of the documents from being viewed
untill the user has been authenticated. Now if i was to use a perl script,
i may be able to authenticate the user but then how would i bypass the
.htaccess file?
I hope that explains it abit better
>
> If you have questions about how your program can interact with the server
> or browser, check the docs, FAQs, and newsgroups about servers, browsers,
> and the protocols they use.
>
> Good luck!
>
> --
> Tom Phoenix Perl Training and Hacking Esperanto
> Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
>
Any thing specific you could recommend i read?
Thanks again
------------------------------
Date: Tue, 1 Jun 1999 07:26:24 -0700
From: Tom Phoenix <rootbeer@redcat.com>
Subject: Re: User Authentication using .htaccess and perl
Message-Id: <Pine.GSO.4.02A.9906010723160.13086-100000@user2.teleport.com>
On Tue, 1 Jun 1999, Yasser Nabi wrote:
> but how would the webserver know that the authentication ha gone
> through,
You communicate with a webserver by means of a protocol, such as the CGI
protocol.
> placing .htacces in a dir, prevents any of the documents from being
> viewed untill the user has been authenticated. Now if i was to use a
> perl script, i may be able to authenticate the user but then how would
> i bypass the .htaccess file?
You'll have to see what methods your server provides for this. See the
docs, FAQs, and newsgroups about your server and servers in general for
more information.
> > If you have questions about how your program can interact with the server
> > or browser, check the docs, FAQs, and newsgroups about servers, browsers,
> > and the protocols they use.
> Any thing specific you could recommend i read?
In addition to your server's docs, see the CGI specification.
http://hoohoo.ncsa.uiuc.edu/cgi/
Cheers!
--
Tom Phoenix Perl Training and Hacking Esperanto
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: Tue, 01 Jun 1999 09:41:09 -0500
From: Mike <kangas@anlon.com>
Subject: Win32::ODBC LIMITS??? (16,377 bytes) and not one more.
Message-Id: <3753F105.F5CDEBBA@anlon.com>
I can only get my INSERT statements to insert 16,377 bytes
into a memo field in Microsoft Access. Is this an Access issue
or a Win32::ODBC issue??
If I can change this number, does anyone have an idea for how
to change this number??
Thanx.
Mike Kangas
Mankato, MN.
kangas@anlon.com
------------------------------
Date: Tue, 01 Jun 1999 14:19:07 GMT
From: docdwarf@clark.net ()
Subject: Re: Y2K infected Perl code
Message-Id: <vZR43.319$K2.12310@iad-read.news.verio.net>
In article <3757b388.7478603@news.insnet.net>,
David Cantrell <NukeEmUp@ThePentagon.com> wrote:
>On Fri, 28 May 1999 18:41:46 GMT, docdwarf@clark.net () said:
>
>>Please be so kind, then, as to address the situation posed and not my
>>responses to it... what happens if a person writing code is not a 'retard'
>>but the specs demand the adherance to certain standards?
>
>If standards say "thou shalt write buggy code" then anyone who is
>still working to those standards is a "retard". If they knew better
>they would either have got the standards changed or gone elsewhere.
>It's not as if there is an unemployment problem for perl programmers.
It is not as though my statement was restricted to perl programmers,
either... if you wish to think that this particular subset of the
code-slinging trade is the Alpha and Omega of work-environments then
perhaps you might learn to post within a newsgroup limited to such coders.
Before there was perl there were... other languages, these have left their
imprints in a small supply of what is quaintly referred to as 'legacy
code'.
DD
------------------------------
Date: 1 Jun 1999 14:53:42 GMT
From: joh@gmx.net (Jochem Huhmann)
Subject: Re: You can earn $50,000 40686
Message-Id: <7j0s5m$hi8$2@nova.revier.com>
In article <7iuvt0$qb1$1@kopp.stud.ntnu.no>,
"Kent Dahl" <MenThal@bigfoot.com> writes:
> Gah! I hate it when they don't have a valid reply adress... So much FUN to
> send a reply, filling their e-mail-boxes as they do with ours.... Now, where
> is that virtual memory file and how do I attach it to outgoing e-mail? ;-))
mail money@moneymaker.com < /dev/mem
(I don't recommend mail bombing, it does more harm to others than to
it's target)
--
Hi! I'm a .signature virus! Copy me into your ~/.signature to help me spread!
------------------------------
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 5848
**************************************