[7908] in Perl-Users-Digest
Perl-Users Digest, Issue: 1533 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Dec 24 16:07:34 1997
Date: Wed, 24 Dec 97 13:00:21 -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 Wed, 24 Dec 1997 Volume: 8 Number: 1533
Today's topics:
Re: Annoying rounding problem... (Nihon)
Re: Annoying rounding problem... (Gabor)
Re: book on perl (David Jacoby)
Good HTTPd logfile analysis script? (Chris Charman)
Hashes and reverse-lookup (Josh Kortbein)
How to pad a variable to make the output look pretty ;p (Nihon)
Re: How to pad a variable to make the output look prett (Mike Stok)
Re: How to pad a variable to make the output look prett (Gabor)
Re: How to pad a variable to make the output look prett (Andrew M. Langmead)
Nesting Arrays question (David Jacoby)
Re: Nesting Arrays question (Andrew M. Langmead)
Newbie frustration (Don)
Re: Newbie frustration (Mike Stok)
Re: Perl Implementation of Checksum? (Nihon)
problem working with XS <sayuj@sycon-design.com>
Re: Removing Spaces <bryan@eai.com>
Re: Review of CGI/Perl book (Tushar Samant)
Re: Teen Perl Programmers Mailing List <merlyn@stonehenge.com>
Re: Which language pays most 17457 -- C++ vs. Java? <jdporter@min.net>
Re: Which language pays most 17457 -- C++ vs. Java? <jdporter@min.net>
Re: Which language pays most 17457 -- C++ vs. Java? (Kaz Kylheku)
Re: Which language pays most 17457 -- C++ vs. Java? <jdporter@min.net>
Re: y2k compliant perl <#@qz.to>
Re: y2k compliant perl <merlyn@stonehenge.com>
Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 24 Dec 1997 18:22:02 GMT
From: Xnihon@Yjapan-mail.Zcom (Nihon)
Subject: Re: Annoying rounding problem...
Message-Id: <34a85267.6272850@news.itsnet.com>
On Wed, 24 Dec 1997 17:26:24 GMT, Xnihon@Yjapan-mail.Zcom (Nihon) tirelessly authored:
>In writing the script for an online store, I've run into this problem. Here's the variable:
>
>$Tax = ($Subtotal * 0.06125)
>
>
>If $Subtotal is 100, then the resulting tax is $6.125. How do I round
>that UP to $6.13 in perl so their total is $106.13, NOT $106.125?
>
I did look in the latest Perl FAQ at http://www.perl.com/CPAN-local/doc/FAQs/FAQ/PerlFAQ.html#Does_perl_have_a_round_function_ but I'm not sure how to
implement the commands. Any suggestions would be helpful!
Thanks!
To reply to this posting, remove the X, Y, and Z from my address.
Want to contact me? http://users.itsnet.com/~nihon/contact.html
----------------/----------------/----------------/----------------\
Avoid Microsoft like the plague? They ARE the plague!
------------------------------
Date: 24 Dec 1997 20:21:16 GMT
From: gabor@vinyl.quickweb.com (Gabor)
Subject: Re: Annoying rounding problem...
Message-Id: <slrn6a2rb2.blv.gabor@vinyl.quickweb.com>
In comp.lang.perl.misc, Nihon <Xnihon@Yjapan-mail.Zcom> wrote:
# On Wed, 24 Dec 1997 17:26:24 GMT, Xnihon@Yjapan-mail.Zcom (Nihon) tirelessly authored:
#
# >In writing the script for an online store, I've run into this problem. Here's the variable:
# >
# >$Tax = ($Subtotal * 0.06125)
# >
# >
# >If $Subtotal is 100, then the resulting tax is $6.125. How do I round
# >that UP to $6.13 in perl so their total is $106.13, NOT $106.125?
simple
$tax=(int( (($subtotal * 0.06125) * 100) + 0.5 )) / 100;
$total = $subtotal + $tax;
gabor.
--
Perl is designed to give you several ways to do anything, so
consider picking the most readable one.
-- Larry Wall in the perl man page
------------------------------
Date: 24 Dec 1997 18:37:25 GMT
From: jacoby@freighter.ecn.purdue.edu (David Jacoby)
Subject: Re: book on perl
Message-Id: <67rkp5$nr6@mozo.cc.purdue.edu>
In article <Pine.GSO.3.96.971222200508.6935A-100000@daftary-ultra.cisco.com>,
Kuntal M. Daftary <daftary@cisco.com> wrote:
>i have "programming perl" book which describes perl 4. so is there a "bible" on
>perl 5 like "programming perl" ?
>
>basically i would like to get familiar with the new features in perl 5 like
>extended regexes and the new commands and OOPs.
The blue-backed camel book covers Perl 5.
--
David Jacoby mailto:jacoby@ecn.purdue.edu
Web Technician and Librarian http://harbor.ecn.purdue.edu/~jacoby/
Engineering Computer Network What do you want? Perl can do that!
---------------------------------------------------------------------
------------------------------
Date: Wed, 24 Dec 97 18:20:36 GMT
From: chris.charman@inference.com (Chris Charman)
Subject: Good HTTPd logfile analysis script?
Message-Id: <67rk2g$k2r$1@nntp2.ba.best.com>
Has anyone managed to put together a decent script to do logfile analysis of
HTTPd traffic? Using Logfile:: or not?
If you'd be willing to share, I'd appreciate it...
Thanks!
-Chris
------------------------------
Date: 24 Dec 1997 17:51:25 GMT
From: kortbein@iastate.edu (Josh Kortbein)
Subject: Hashes and reverse-lookup
Message-Id: <67ri2t$jst$1@news.iastate.edu>
I'm writing an LZW encoder, and I've encountered a problem: the
basic encoding algorithm is
set w = NIL
loop
read a character K
if wK exists in the dictionary
w = wK
else
output the code for w
add wK to the string table
w = K
endloop
I've tried both a normal array and an associative array for my
dictionary/string table, but neither seems to do what I want. The
problem I've encountered is that I need to be able to lookup elements
both by key and by value, and I suspect my code is slowing down
immensely because of it - when I do the reverse-lookup, to get the
code (key to the hash) for a given string (value to the hash), I
have to do either
create a reverse hash:
%by_val = reverse %by_key;
$key = $by_val{$value};
or
walk the hash myself:
foreach $key (sort keys(%table)) {
if ($table{$key} eq $val) {
return $key
}
}
return $key
I've tried the former, and now that I've found the latter in the FAQ and
had it described as not-as-good as walking the hash yourself, I don't
think the latter will help.
Is there a better way for me to go about storing my string table?
Is there perhaps a way to do a binary search on the string table,
while it's still a hash, that I'm not seeing?
Email replies appreciated.
TIA,
Josh
____________________________________________
Karma police arrest this man
He talks in maths, he buzzes like a fridge
He's like a detuned radio
- Radiohead, "Karma Police," _OK Computer_
------------------------------
Date: Wed, 24 Dec 1997 19:21:58 GMT
From: Xnihon@Yjapan-mail.Zcom (Nihon)
Subject: How to pad a variable to make the output look pretty ;p
Message-Id: <34aa602c.9798263@news.itsnet.com>
Here's my question:
How do I read how many characters are in a variable and make sure that I pad the variable with spaces at the end to make the total amount of
characters equal 25 if the amount of characters is less than 25? Otherwise, the table in the email looks awful.
I scanned thru the FAQ index, but I didn't see anything that seemed to address this problem. Of course, the FAQ is _rather_ large.... ;p
Thanks for the help!
To reply to this posting, remove the X, Y, and Z from my address.
Want to contact me? http://users.itsnet.com/~nihon/contact.html
----------------/----------------/----------------/----------------\
Avoid Microsoft like the plague? They ARE the plague!
------------------------------
Date: 24 Dec 1997 14:43:55 -0500
From: mike@stok.co.uk (Mike Stok)
Subject: Re: How to pad a variable to make the output look pretty ;p
Message-Id: <67rolr$1i2$1@stok.co.uk>
In article <34aa602c.9798263@news.itsnet.com>,
Nihon <Xnihon@Yjapan-mail.Zcom> wrote:
>Here's my question:
>How do I read how many characters are in a variable and make sure that I
>pad the variable with spaces at the end to make the total amount of
>characters equal 25 if the amount of characters is less than 25?
>Otherwise, the table in the email looks awful.
>I scanned thru the FAQ index, but I didn't see anything that seemed to
>address this problem. Of course, the FAQ is _rather_ large.... ;p
You might consider (s)printf and say something like
$var = sprintf '%25.25s', $var;
using printf in the debugger:
DB<1> printf '>%5.5s<', '123'
> 123<
DB<2> printf '>%5.5s<', '123456'
>12345<
The format characters used by perl's sprintf are documented in the
perlfunc page - printf uses the same characters & conventions.
Hope this helps,
Mike
--
mike@stok.co.uk | The "`Stok' disclaimers" apply.
http://www.stok.co.uk/~mike/ | PGP fingerprint FE 56 4D 7D 42 1A 4A 9C
http://www.tiac.net/users/stok/ | 65 F3 3F 1D 27 22 B7 41
stok@colltech.com | Collective Technologies (work)
------------------------------
Date: 24 Dec 1997 20:07:00 GMT
From: gabor@vinyl.quickweb.com (Gabor)
Subject: Re: How to pad a variable to make the output look pretty ;p
Message-Id: <slrn6a2qga.blv.gabor@vinyl.quickweb.com>
In comp.lang.perl.misc, Nihon <Xnihon@Yjapan-mail.Zcom> wrote:
# Here's my question:
#
# How do I read how many characters are in a variable and make sure that I pad the variable with spaces at the end to make the total amount of
# characters equal 25 if the amount of characters is less than 25? Otherwise, the table in the email looks awful.
#
# I scanned thru the FAQ index, but I didn't see anything that seemed to address this problem. Of course, the FAQ is _rather_ large.... ;p
Hmm, did you look at sprintf?
the number before the dot means field width, the number after is
maximum field width, the - means left justify
$foo = sprintf "%-25.25s",$foo;
or
$foo = sprintf "%25.25s",$foo;
or
$foo = sprintf "%-25s",$foo;
or
$foo = sprintf "%25s",$foo;
you can also do, but it's just maximum field is 25 but no padding is
done
$foo = sprintf "%.25s",$foo;
#
# Thanks for the help!
#
#
# To reply to this posting, remove the X, Y, and Z from my address.
# Want to contact me? http://users.itsnet.com/~nihon/contact.html
# ----------------/----------------/----------------/----------------\
# Avoid Microsoft like the plague? They ARE the plague!
gabor.
--
str->str_pok |= SP_FBM; /* deep magic */
s = (unsigned char*)(str->str_ptr); /* deeper magic */
-- Larry Wall in util.c from the perl source code
------------------------------
Date: Wed, 24 Dec 1997 20:15:02 GMT
From: aml@world.std.com (Andrew M. Langmead)
Subject: Re: How to pad a variable to make the output look pretty ;p
Message-Id: <ELpMx2.JFt@world.std.com>
Xnihon@Yjapan-mail.Zcom (Nihon) writes:
>How do I read how many characters are in a variable and make sure that I pad the variable with spaces at the end to make the total amount of
>characters equal 25 if the amount of characters is less than 25? Otherwise, the table in the email looks awful.
Probably the best thing to do would be to use the printf() function to
print the string out with the appropriate padding.
printf '%25.25s', $variable;
--
Andrew Langmead
------------------------------
Date: 24 Dec 1997 18:34:47 GMT
From: jacoby@freighter.ecn.purdue.edu (David Jacoby)
Subject: Nesting Arrays question
Message-Id: <67rkk7$nln@mozo.cc.purdue.edu>
I'm working on a library system, and I'm trying to learn to nest an array
within another array. The codelet below (along with the loop I pulled it
out of) parses a data set where there exist multiple instances of $book
with the same $subj and multiple instances of $subj with the same $book.
Right now, it counts the number of subjects per book and books per subject,
but I would like to add a list of the subjects per book and books per subject.
My best attempt has been integrated into the parse for @book, and that doesn't
work.
($book,$subj) = split /:/;
if ($s_num{$subj})
{ $s_num{$subj}++; }
else
{
@subject = ($subj, 1);
$s_num{@subject[0]} = @subject[1];
}
if ($b_num{$book})
{ $b_num{$book}++;
@var{@book[0]} = $subj;
}
else
{
@book = ($book, 1);
$b_num{@book[0]} = @book[1];
@var{@book[0]} = $subj;
}
Thank you.
--
David Jacoby mailto:jacoby@ecn.purdue.edu
Web Technician and Librarian http://harbor.ecn.purdue.edu/~jacoby/
Engineering Computer Network What do you want? Perl can do that!
---------------------------------------------------------------------
------------------------------
Date: Wed, 24 Dec 1997 20:08:58 GMT
From: aml@world.std.com (Andrew M. Langmead)
Subject: Re: Nesting Arrays question
Message-Id: <ELpMMy.HAE@world.std.com>
jacoby@freighter.ecn.purdue.edu (David Jacoby) writes:
> $s_num{@subject[0]} = @subject[1];
Statements like this make me assume that you aren't using perl's
optional warnings switch. You might want to put:
#!/usr/bin/perl -w
as the first line in your script to enable them.
>I'm working on a library system, and I'm trying to learn to nest an array
>within another array.
Have you taken a look at the perldsc man page? If if you have and
still have questions, you may want to describe where the documentation
was misleading.
I think what you are looking for is something like this:
($book,$subj) = split /:/;
push @{$subjects{$subj}}, $book; # add this book to the list of matching $subj
push @{$books{$book}}, $subj; #add subject to the list of matching $books
and now $subject{$subj}[0] will be the first book with the subject
contained in "$subj", $subject{$subj}[1] will be the second, and so
on.
The key concept is that each value of the hash %subjects and %books
contains a reference to an array. You can use $subjects{$subj} to
retrieve that array reference, and then use @{} to dereference it and
access the array itself.
and when you want to print them all out:
foreach $subj (sort keys %subjects) { # for each subject.
foreach $book (@$subj) { # the value is a ref to an array containing
print "$book\n"; # the titles to the books.
}
}
--
Andrew Langmead
------------------------------
Date: Wed, 24 Dec 1997 18:43:02 GMT
From: dongood@ibm.net (Don)
Subject: Newbie frustration
Message-Id: <34a25654.7567381@news3.ibm.net>
Well, thanx to this ng I now know that I can use ctrl-z as an EOF in
win 95. Problem is when I use ctrl-z, it ignores the next command!
Checked the FAQ's but found nothing about this. So I'm thinking that
maybe I should just run a unix OS.
Can I run a unix OS(linux) on my win 95 box without removing win 95?
(This would allow me to code according to the book and make learning
PERL much easier)
Happy Holidays!
Thanx in advance,
Don
------------------------------
Date: 24 Dec 1997 14:15:24 -0500
From: mike@stok.co.uk (Mike Stok)
Subject: Re: Newbie frustration
Message-Id: <67rn0c$1gc$1@stok.co.uk>
In article <34a25654.7567381@news3.ibm.net>, Don <dongood@ibm.net> wrote:
>Can I run a unix OS(linux) on my win 95 box without removing win 95?
>(This would allow me to code according to the book and make learning
>PERL much easier)
Yes you can. If you haven't got a full disc then it's possible to defrag
your C: drive and use something like fips as mentioned in
http://www.linuxhq.com/HOWTO/mini/Linux+Win95.html
and if you get a distribution like the RedHat 5.0 (http://www.redhat.com/)
then their Before You Begin section of the manual discusses some options
and they provide some utilities on their CD-ROMs
One nice thing about linus is that you get a whole development environment
for free and a pre-built perl (albeit 5.004_01 in RH 5.0) to boot *and*
you can mount your Win 95 partitions from Linux too...
Do take the warnings about backups seriously, I have repartitioned a disc
using fips OK but it would be a bummer if you lost data. In the end I
bought a second hard disc and use one for linux and one for Win 95.
Hope this helps,
Mike
--
mike@stok.co.uk | The "`Stok' disclaimers" apply.
http://www.stok.co.uk/~mike/ | PGP fingerprint FE 56 4D 7D 42 1A 4A 9C
http://www.tiac.net/users/stok/ | 65 F3 3F 1D 27 22 B7 41
stok@colltech.com | Collective Technologies (work)
------------------------------
Date: Wed, 24 Dec 1997 19:09:18 GMT
From: Xnihon@Yjapan-mail.Zcom (Nihon)
Subject: Re: Perl Implementation of Checksum?
Message-Id: <34a95ce0.8954268@news.itsnet.com>
On 17 Dec 1997 00:10:24 GMT, mgjv@comdyn.com.au (Martien Verbruggen) tirelessly authored:
>In article <6771c4$squ$1@shell3.ba.best.com>,
> rsr@best.com (Roy S. Rapoport) writes:
>>
>> I'm looking for an implementation of checksum in perl, or possibly an
>> idea on how I could implement it myself. A search on 'sum' on both
>> the FAQ and the CPAN module listing has come up with no relevant
>> matches ...
>>
>
>I think CPAN uses the MD5 algorithm to do checksum like things. There's
>a module out there (on CPAN) that takes care of this.
Yep, and here's where to find it on the web:
http://theory.uwinnipeg.ca:8042/mod_perl/cpan-search.pl?search=Business%3A%3ACreditCard&Search=Search&filetype=%20module%20name&case=clike&age=&download=auto&site=ftp.funet.fi&add=ftp%3A%2F%2Fftp.utilis.com%2Fpublic%2FCPAN&add=ftp%3A%2F%2Fftp.utilis.com%2Fpublic%2FCPAN&add=ftp://ftp.utilis.com/public/CPAN&dir=authors/id/JONO/Business-CreditCard-0.1.tar.gz
How's that for a long URL?
To reply to this posting, remove the X, Y, and Z from my address.
Want to contact me? http://users.itsnet.com/~nihon/contact.html
----------------/----------------/----------------/----------------\
Avoid Microsoft like the plague? They ARE the plague!
------------------------------
Date: Wed, 24 Dec 1997 10:32:51 -0800
From: Sayuj Nadhan <sayuj@sycon-design.com>
Subject: problem working with XS
Message-Id: <34A15553.2A48930F@sycon-design.com>
Hi,
I'm trying out the Example4 of the on-line perl manual (perlxstut: Perl
XS tutorial)
and when I do a make test, I get the following error msg :
Can't load './blib/arch/auto/Test4/Test4.so' for module Test4: ld.so.1:
/sycon/bin/perl: fatal: relocation error: file
./blib/arch/auto/Test4/Test4.so: symbol test4: referenced symbol not
found at /sycon/lib/perl5/DynaLoader.pm line 140.
at blib/lib/Test4.pm line 41
BEGIN failed--compilation aborted at test.pl line 11.
not ok 1
*** Error code 2
make: Fatal error: Command failed for target `test_dynamic'
I'm running this on a Solaris 2.6 m/c and I've used gcc with '-fpic'
option inorder to generate
position independent code for the C part of the program.
Any help on what went wrong and how can I get around this problem ?
(BTW, I do have the same problem on my real program, that's why I tried
this example).
Thanks
Sayuj
------------------------------
Date: Wed, 24 Dec 1997 13:24:19 -0600
From: Bryan Hart <bryan@eai.com>
Subject: Re: Removing Spaces
Message-Id: <34A16163.15FB@eai.com>
brian d foy wrote:
>
> In article <01bd0ee9$cf27c1e0$LocalHost@oasis>, "Ho Seng Yip" <cybercom@pacific.net.sg> wrote:
>
> >I will like to ask how is it possible for me to remove spaces in the
> >comment section of my mailform. I got some light on searching for spaces
> >using Perl patterns, but the problem comes in on how I can delete the
> >spaces after I have located them.
>
> the substitute operator is your friend:
>
> s/\s+/ /g; #collapse multiple whitespace.
>
or s/\s+$//g; # strip trailing whitespace
You get the idea...
Bryan
--
------------------------------------------------------------
| Bryan Hart | Phone: (515) 296-5979 |
| Network Products Engineer | Fax: (515) 296-7025 |
| Engineering Animation Inc. | Email: bryan@eai.com |
| | Web: http://www.eai.com/
|
------------------------------------------------------------
DOGBERT: "Hmm...Let's see if it's on the free speech
checklist...Okay, you didn't advocate overthrowing the
government...You were not obscene...You did not generalize
about a disadvantaged group...You did not teach children
anything useful or practical...You didn't refer to anybody
who can afford a lawyer to sue us...and there's nobody
within hearing distance who can harm us financially...You're
clear."
-- from "It's Obvious You Won't Survive By Your Wits Alone"
------------------------------
Date: 24 Dec 1997 14:35:12 -0600
From: scribble@tekka.wwa.com (Tushar Samant)
Subject: Re: Review of CGI/Perl book
Message-Id: <67rrm0$bgg@tekka.wwa.com>
craig@cgi-perl.com writes:
>Hmmm...I wrote the book (half the scripts and all the text) and would
>never claim that a love of the book is a hacker prerequisite.
I am not sure why I feel I should respond, but I will, without getting
into details: Yes, I understand the import and the intent of the book.
I am not part of any Perl elite by any definition, but I know that even
a little knowledge makes it very difficult to resist making smart-ass,
even scornful, remarks. If I made any, I apologise. I don't know if
I can add much more -- it's kind of lame to criticize when someone's
already agreed to disagree so magnanimously. Let me just repeat what
my feelings were -- that the instant popularity of a book cannot
possibly be evidence for its merit, and that it's dishonest not to
mention the marketing exigencies driving the decisions. The latter
is an old, discreditable habit -- it's as if "Cliff's Notes" claimed
they were democratizing knowledge -- and anyone even slightly attuned
to the market's workings has developed a distaste for it. It's not a
matter of belonging to the "Perl elite". Just to give an example --
so suppose it were of the greatest importance to have the quickest,
dirtiest, least labour-intensive CGI program installation imaginable,
and scripts which were extremely easy to tinker with in minor aspects
of behaviour. I still can't see what *theoretical* reason there was
not to use Perl5 and say CGI.pm. How much slower and harder is that?
It looks to me like the decision was "practical" -- to put it crassly,
it was a "let's cash in" kind of decision.
This is a summary of what I feel. I don't want to go on any more about
this. BTW I have still not looked at the book, I based everything on
the web site.
------------------------------
Date: 24 Dec 1997 11:37:03 -0700
From: Randal Schwartz <merlyn@stonehenge.com>
To: techie@continuum.eu.org
Subject: Re: Teen Perl Programmers Mailing List
Message-Id: <8cafdqlh9s.fsf@gadget.cscaper.com>
[comp.lang.perl is dead. Almost as dead as Perl4. Please stop
posting there.]
>>>>> "TechMaster" == TechMaster Pinyan <jefpin@bergen.org> writes:
TechMaster> Ok... I am sure many of you are teenagers programming (I
TechMaster> hope), like myself. I think that a teen programmer
TechMaster> mailing list should be started, or even a newsgroup. I
TechMaster> would like to host the mailing list... if you are
TechMaster> interested, please email me at techie@continuum.eu.org.
I'm now intensely curious about the parts of Perl Programming that are
especially troublesome to teens that would require a separate forum.
"Geez, Biff... the use of the chomp operator is really bad on my
complexion...."
"Dude, you should use the way-rad map for that."
:-)
print "Just another Perl hacker," # but not what the media calls "hacker!" :-)
## legal fund: $20,990.69 collected, $186,159.85 spent; just 250 more days
## before I go to *prison* for 90 days; email fund@stonehenge.com for details
--
Name: Randal L. Schwartz / Stonehenge Consulting Services (503)777-0095
Keywords: Perl training, UNIX[tm] consulting, video production, skiing, flying
Email: <merlyn@stonehenge.com> Snail: (Call) PGP-Key: (finger merlyn@ora.com)
Web: <A HREF="http://www.stonehenge.com/merlyn/">My Home Page!</A>
Quote: "I'm telling you, if I could have five lines in my .sig, I would!" -- me
------------------------------
Date: Wed, 24 Dec 1997 12:53:43 -0500
From: John Porter <jdporter@min.net>
Subject: Re: Which language pays most 17457 -- C++ vs. Java?
Message-Id: <34A14C27.57C0@min.net>
Lawrence Kirby wrote:
>
> Aren't the standard library identifiers with external linkage reserved
> even in a freestandinhg environment?
With the possible exception of environments for embedded development,
the identifiers defined in the standard or any other library are not
reserved words. If I don't include string.h, I am free to use the
id 'memcpy' for my own purposes. Even if I do link with a library which
defines memcpy, my definition overrides it. I'm not sure how you can
construe this to mean that 'memcpy' is in any way "reserved".
John Porter
jporter@logicon.com
------------------------------
Date: Wed, 24 Dec 1997 13:19:34 -0500
From: John Porter <jdporter@min.net>
Subject: Re: Which language pays most 17457 -- C++ vs. Java?
Message-Id: <34A15236.607F@min.net>
Lawrence Kirby wrote:
>
> Your opinion is wrong because it contradicts fact.
Ooh, "You have an opinion, by *I* know the *truth*!"
> The standard library is an integral part of the
> language *definition*.
Well, if this is your definition of "language definition".
I think the more traditional definition is the syntax and grammar
specifications, along with indications as to the semantics. Thus,
'if', 'switch', braces and commas are part of the C language definition,
but 'main' and '#include' are not.
> The standard library
> cannot be constructed from the language because there is no way in the
> language to construct, say, a time() function beyond a trivial one that
> returns (time_t)-1 on every call. There is no way to write setjmp() and
> longjmp() in the language.
I think we'll all agree that certain functions in the standard library
--
and other arbitrary libraries, without distinction -- may need to have
some
functions written in assembly language. But the ANSI C spec does not
state
that these functions MUST be written in asm; it only specifies the
interface
(the function signatures) and the behavioral semantics of the functions.
The implementation of the functions is really up to the implementors,
and
therefore is not (by your definition) part of the language
specification.
Maybe you're thinking of Pascal, where 'writeln' etc. are reserved
words,
mentioned explicitly in the grammar.
> I can't remember ever having the need to replace standard library functions,
> at least not with an ANSI C compiler.
So therefore no one will ever need to do it, and therefore suggestions
that
it is a useful feature are groundless?
I suspect everyone who has ever used a third-party (or home-grown)
drop-in
replacement for malloc() might strongly disagree with you.
> I accept that there are cases where
> this might be useful, mainly where you are stuck with a 3rd party library
> without the source code.
Why should this be any different from being "stuck" with a library from
the
compiler vendor? In fact, it's not.
> However in that case if the code was compiled
> in such a way that functions were inlined there will be very little you
> can do about it.
This is true for code you're linking in which was compiled with the
inlined
function definitions, but not for any source code you are compiling
a-fresh.
> You're fighting
> a losing battle here and I'm still not clear about what you hope to gain.
It is my studied opinion that you are the one who is fighting, and that
the
battle was decided in your opponent's favor long before you took up the
fight.
John Porter
jporter@logicon.com
------------------------------
Date: 24 Dec 1997 18:12:51 GMT
From: bill@cafe.net (Kaz Kylheku)
Subject: Re: Which language pays most 17457 -- C++ vs. Java?
Message-Id: <67rjb3$pfb$1@brie.direct.ca>
In article <34A14C27.57C0@min.net>, John Porter <jdporter@min.net> wrote:
>Lawrence Kirby wrote:
>>
>> Aren't the standard library identifiers with external linkage reserved
>> even in a freestandinhg environment?
>
>With the possible exception of environments for embedded development,
>the identifiers defined in the standard or any other library are not
>reserved words. If I don't include string.h, I am free to use the
>id 'memcpy' for my own purposes. Even if I do link with a library which
False. Although 'memcpy' is not a reserved keyword by any means,
it is a reserved 'external name'. External names defined by the C library are
reserved as external names regardless of what header you include.
(An external name is an identifier with external linkage).
Not only are those names reserved, but certain external name SPACES are
reserved! A strictly conforming program may not define any external
name that begins with 'mem' followed by any combination of letters,
digits or underscores. This is true even though the library doesn't
currently define anything else in that category other than 'memcpy'
or 'memmove'. However, 'mem' itself is not reserved because it's
not followed by any letters, digits or underscores. Similarly,
identifiers beginning with 'to' and 'is' are reserved for future
extensions to <ctype.h>, and identifiers starting 'str' are reserved
for future extensions to <string.h>.
I have set up my Vim 5.0 editor to colorize any occurence of an identifier
that belongs to the forbidden name spaces. :)
>defines memcpy, my definition overrides it. I'm not sure how you can
>construe this to mean that 'memcpy' is in any way "reserved".
You are sadly mistaken. In fact your overriding definition must have static
linkage, otherwise your program invokes undefined behavior. Moreover, if you
write such a static function, you must not include the <string.h> header in
the same translation unit, else undefined behavior results.
There is no such thing as ``overriding'' in C. Each external name must
have exactly one definition if it is used anywhere in the program.
Additionally, an external name that is declared but never referenced, is
permitted to be without an external definition.
Overriding of library functions (via ``weak symbols'' or some other such
resolution mechanism) is possible as a system-specific extension.
How I can construe all this is by interpreting the fine words written
in a document entitled _American National Standard for Programming
Languages---C_, ANSI/ISO 9899:1990.
------------------------------
Date: Wed, 24 Dec 1997 13:24:27 -0500
From: John Porter <jdporter@min.net>
Subject: Re: Which language pays most 17457 -- C++ vs. Java?
Message-Id: <34A1535B.339D@min.net>
Klaus-Georg Adams wrote:
> ...
> Speaking for C. In ANSI C++ there is a datatype set.
>
> > Strings are also a high level construct. C and C++ do not have string
> > data types, instead they use Zero terminated character arrays. *That*
> > is the primitive.
>
> Speaking for C. In ANSI C++ there is a datatype string.
>
May I gently point out that the discussion is whether the language
features
under discussion are *primitives* within the language, or are
constructed
features, built up from other features.
Set and String are in no way primitives -- at least not at the present
time,
and I personally doubt they will ever be.
John Porter
jporter@logicon.com
------------------------------
Date: 24 Dec 1997 18:27:23 GMT
From: Eli the Bearded <#@qz.to>
Subject: Re: y2k compliant perl
Message-Id: <eli$9712241318@qz.little-neck.ny.us>
Keywords: just another New York perl hacker
Posted and mailed.
Ian Kallen <spidaman@well.com> wrote:
> anybody have a more elegant way to be y2kosher?
Yes.
> sub right_now {
> # rely on the system clock's accuracy to
> # make a y2k'able SQL DATETIME string: 0000-00-00 00:00:00
> # don't bug me about the 22nd century
Why not?
> my $century;
> my $time=shift;
> my($se,$mi,$ho,$md,$mo,$ye)=(localtime($time))[0,1,2,3,4,5];
^^^
This value is defined to be the year minus 1900.
> $mo++;
> if ($time >= 946713600) {
^^^^^^^^^^^^^^^^^^
This relies on a fixed epoch. That's ugly to me.
> $century='20';
> $ye=~s/^1/$century/;
This is just stupid. If you want to be clever and obfuscatory you
should have done this:
$century='20';
$ye=~s/^(\d)/$century+$1-1/e;
Which will work for later centuries.
> ...seems to work but as with all things perly, I bet there's a neater way to
> do it.
$ye+=1900;
Elijah
------
should have entered code into the best obfuscated perl y2k bug contest
------------------------------
Date: 24 Dec 1997 11:43:47 -0700
From: Randal Schwartz <merlyn@stonehenge.com>
To: spidaman@well.com (Ian Kallen)
Subject: Re: y2k compliant perl
Message-Id: <8c67oelgyk.fsf@gadget.cscaper.com>
>>>>> "Ian" == Ian Kallen <spidaman@well.com> writes:
Ian> if ($time >= 946713600) {
Mixing localtime with a Unix epoch value (measured relative to GMT)
is dangerous at best, and completely unnecessary.
See the other response in this thread for proper coding.
print "Just another Perl hacker," # but not what the media calls "hacker!" :-)
## legal fund: $20,990.69 collected, $186,159.85 spent; just 250 more days
## before I go to *prison* for 90 days; email fund@stonehenge.com for details
--
Name: Randal L. Schwartz / Stonehenge Consulting Services (503)777-0095
Keywords: Perl training, UNIX[tm] consulting, video production, skiing, flying
Email: <merlyn@stonehenge.com> Snail: (Call) PGP-Key: (finger merlyn@ora.com)
Web: <A HREF="http://www.stonehenge.com/merlyn/">My Home Page!</A>
Quote: "I'm telling you, if I could have five lines in my .sig, I would!" -- me
------------------------------
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 1533
**************************************