[8956] in Perl-Users-Digest
Perl-Users Digest, Issue: 2574 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue May 12 20:07:35 1998
Date: Tue, 12 May 98 17: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 Tue, 12 May 1998 Volume: 8 Number: 2574
Today's topics:
[Serdar Argic Alert] Re: Nuclear bombing of NEW YORK! (Alexander Viro)
Re: A bug in localtime() <lr@hpl.hp.com>
Re: chdir in Win NT <acannon@sr.hp.com>
Re: converting non-printable characters (TomH)
difficulty calling anonymous sub with params <lanier@shell6.ba.best.com>
Re: Does Perl have a IDE?I don't like command line. (Michael J Gebis)
extracting version resources from ntfs <acannon@sr.hp.com>
Re: flock is not (Martien Verbruggen)
Re: Grieving our dying community (brian d foy)
Re: Is if ($a="something") a bad style? <rootbeer@teleport.com>
Re: memory efficiency question (Martien Verbruggen)
Re: Newbie needs help! <rootbeer@teleport.com>
Re: Randomly sorting an array <tchrist@mox.perl.com>
Re: Randomly sorting an array (Abigail)
Re: Randomly sorting an array (Tom Rokicki)
Re: Set Difference Problem! <lr@hpl.hp.com>
Re: Significant digit? (brian d foy)
Re: Significant digit? (brian d foy)
Re: Significant digit? (Abigail)
Re: Significant digit? <lr@hpl.hp.com>
Re: Small Perl quick-reference? (Colin Kuskie)
sorry bout the long sig <lanier@shell6.ba.best.com>
Re: Tip: Filehandles (Martien Verbruggen)
Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 12 May 1998 19:04:03 -0400
From: viro@riemann.math.psu.edu (Alexander Viro)
Subject: [Serdar Argic Alert] Re: Nuclear bombing of NEW YORK!
Message-Id: <6jakh3$phh@riemann.math.psu.edu>
#Path: ...!Supernews60!supernews.com!Supernews69!not-for-mail
#From: gdw <gdw@yahoo.com>
#Newsgroups: comp.os.linux.misc,comp.lang.perl.misc,\
# comp.databases.sybase,comp.databases.informix
#Subject: Nuclear bombing of NEW YORK! Small countries can target with nukes!
#Date: Tue, 12 May 1998 17:28:57 -0500
#Organization: gdw
#Lines: 82
#Message-ID: <3558CD29.12CB@yahoo.com>
#Reply-To: gdw@yahoo.com
#NNTP-Posting-Host: 198.64.253.250
#Mime-Version: 1.0
#Content-Type: text/plain; charset=us-ascii
#Content-Transfer-Encoding: 7bit
#X-Trace: 895012103 2YNFDRPCBFDFAC640C usenet76.supernews.com
#X-Complaints-To: newsabuse@supernews.com
#X-Mailer: Mozilla 3.04 (Win95; I)
[Serdar Argic type drivel snipped]
Yet another posting from our spamming friend gold_bag@yahoo.com aka
nuketest@yahoo.com aka gdw@yahoo.com.
198.64.253.250 == dresden.bmc.com.
Note: yahoo.com has nothing with this guy. Complaining to them is useless.
Shit was injected from dresden.bmc.com via supernews.com servers.
This guy spammed a lot of newsgroups in March-April (BI>50)
Let's help him to lose his account, folks.
--
My theory is that someone's Emacs crashed on a very early version of Linux
while reading alt.flame and the resulting unholy combination of Elisp and
Minix code somehow managed to bootstrap itself and take on an independent
existence. -- James Raynard in c.u.b.f.m on nature of Albert Cahalan
------------------------------
Date: Tue, 12 May 1998 16:04:52 -0700
From: "Larry Rosler" <lr@hpl.hp.com>
Subject: Re: A bug in localtime()
Message-Id: <6jakia$eg7@hplntx.hpl.hp.com>
[posted and emailed]
Stephen P Potter wrote in message <35589786.4A65FF52@ds.net>...
>Alex Dong Li wrote:
>
>> Secondly, yes, I got 4 for May. I am just curious: if 0 is for
January, but
>> why not 0 for the first day of a month too? Why the second day is 2?,
not
>> offset to 1?
>
>Perl implements localtime() and such as calls to the underlying C
>routine.
>The C routine is based on a structure that defines some things (such as
>month)
>as "since" (months since January, hence January is 0), and other things
>(day) as
>"of the" (day of the month, 1-31). This is mostly because of arrays
>(and enums)
>being 0 based in C, and things like month often being used in a list
>context for
>conversion purposes ($month[0] = Jan ... $month[11] = Dec). You'll
note
>that
>days are rarely used in such a context.
>
>-spp
True, but don't be led astray by overgeneralization. As a recent thread
showed, the day_of_the_year variable (localtime)[7] counts from 0 (i.e.,
days since January 1). No rationale given for this, or expected!
BTW: Fix your news software so the lines aren't so long.
--
Larry Rosler
Hewlett-Packard Laboratories
lr@hpl.hp.com
------------------------------
Date: Tue, 12 May 1998 16:00:18 -0700
From: Andrew Cannon <acannon@sr.hp.com>
Subject: Re: chdir in Win NT
Message-Id: <3558D482.2568F77C@sr.hp.com>
scott@softbase.com wrote:
> Oren Levine (olevine@clalit.co.il) wrote:
> > I adapted a search engine script to work with NT.
> > I have a problem with the following:
> > sub get_files {
>
> > chdir ($basedir);
> > However, chdir won't work.
>
> It works for me. I use it all the time. The thing to
> look for is path problems. Try not using \ as the
> path separator.
1) Make sure you substitute all "\" with "\\" using y/// or tr///.
2) If you must support spaces in directory or file names, use:
chdir "\"$dir\"";
--
acannon@sr.hp.com (internal)
http://web.sr.hp.com/~acannon/
Software Design Engineer, Hewlett-Packard (Santa Rosa Systems Division)
------------------------------
Date: Tue, 12 May 1998 20:11:05 GMT
From: beans@bedford.net (TomH)
Subject: Re: converting non-printable characters
Message-Id: <3558ac09.12140043@news.bedford.net>
Substitute where you find the hex value of the offending character.
Use "ord" function if in doubt as to what's out there. I couldn't
figure out how to specify a range of hex values.
-Tom
###############
$\ = "\n";
$ans = "A";
print ord $ans;
$ans =~ s/\x41//g;
print $ans;
##############
On Tue, 12 May 1998 13:50:47 -0400, Matthew Glogowski
<matthewg@bu.edu> wrote:
>hi,
>
>i've got a quick question.
...
>
>how do i tell perl to get rid of the non-printable characters--the ones
>other than the 7-bit ascii chars that are compatible between OS's?
>
>
...
------------------------------
Date: Tue, 12 May 1998 16:30:10 -0700
From: "matthew d. p. k. lanier" <lanier@shell6.ba.best.com>
Subject: difficulty calling anonymous sub with params
Message-Id: <Pine.BSF.3.96.980512162618.16394J-100000@shell6.ba.best.com>
hello all-
i'm having difficulty calling an anonymous subroutine with parameters.
i see from the camel book that
&$subref(list)
is valid, but what about when $subref is a more complex expression?
$self->{'FOO'} is a reference to an anonymous subroutine that takes
parameters.
when i call it as &{$self->{'FOO'}}, $self is the first parameter, as it
should be. when i try something like &{$self->{'FOO'}}($param1, $param2),
param1 is the first parameter.
what am i doing incorrectly? any references to the answer are very
welcome.
matt =)
matthew d. p. k. lanier / professional hugger and empath / matt@lanier.org - i web, therefore i am / matt@saturn5.com - i read too many mailing lists / +1-415-505-4450 - i cell way too much / +1-415-863-2932 - i'm never home, but try it anyway /
_______
/ \
/ o o \
| ^ |
| |
___ \ \_/ / ___
__(___\ \__ __/ /___)__
(______ \________\ /_________/ ______)
(_______ ____________________ _______)
(______ / \ ______)
(_____/ \_____)
------------------------------
Date: 12 May 1998 23:42:32 GMT
From: gebis@albrecht.ecn.purdue.edu (Michael J Gebis)
Subject: Re: Does Perl have a IDE?I don't like command line.
Message-Id: <6jamp8$9pv@mozo.cc.purdue.edu>
Tom Christiansen <tchrist@mox.perl.com> writes:
}In comp.lang.perl.misc,
} gebis@albrecht.ecn.purdue.edu (Michael J Gebis) writes:
}:Programming languages are not an everyday thing, but help systems
}:should be. Perldoc is an oddity for non-unix programmers. They can
}:understand it, but it clashes, and will continue to be ignored
}:forever.
}Then so too shall they.
I wish. But what you really meant is, "They shall continue to post
dumbass questions and they shall continue to receive answers which are
at worst rude and insulting, and at best are redundant and a waste of
bandwidth."
--
Mike Gebis gebis@ecn.purdue.edu mgebis@eternal.net
------------------------------
Date: Tue, 12 May 1998 16:04:49 -0700
From: Andrew Cannon <acannon@sr.hp.com>
Subject: extracting version resources from ntfs
Message-Id: <3558D591.E8A40DD5@sr.hp.com>
Is there a package available that will extract ntfs version resources
from
binaries, dlls, ocx, ...?
--
acannon@sr.hp.com (internal)
http://web.sr.hp.com/~acannon/
Software Design Engineer, Hewlett-Packard (Santa Rosa Systems Division)
------------------------------
Date: 12 May 1998 23:18:51 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: flock is not
Message-Id: <6jalcr$5km$3@comdyn.comdyn.com.au>
In article <894940267.458165@thrush.omix.com>,
Zenin <zenin@bawdycaste.org> writes:
> Martien Verbruggen <mgjv@comdyn.com.au> wrote:
> >snip<
>: You can't get an exclusive lock on a file that you didn't open for write.
>
> This is incorrect. Exclusive flock()s are available on any open
> file descriptor and under SysV are available on socket descriptors
> as well. The options the descriptor was opened with are not
> important.
# uname -a
SunOS timber 5.6 Generic_105181-04 sun4u sparc SUNW,Ultra-2
# perl -v
This is perl, version 5.004_04 built for sun4-solaris
# cat tt.pl
#!/usr/local/bin/perl -w
use strict;
my $fn = 'tt';
open(ZZZ, $fn) || die "Cannot open $fn for reading: $!";
flock(ZZZ, 2) || warn "Cannot flock $fn (read): $!";
close(ZZZ);
open(ZZZ, ">$fn") || die "Cannot open $fn for writing: $!";
flock(ZZZ, 2) || warn "Cannot flock $fn (write): $!";
close(ZZZ);
# ./tt.pl
Cannot flock tt (read): Bad file number at ./tt.pl line 5.
#
Oh, wait...
# perldoc -f flock
[snip]
Note that the emulation built with lockf(3) doesn't provide shared
locks, and it requires that FILEHANDLE be open with write intent. These
are the semantics that lockf(3) implements. Most (all?) systems
implement lockf(3) in terms of fcntl(2) locking, though, so the
differing semantics shouldn't bite too many people.
[snip]
That probably is the problem. I guess I'll have to see if I can build
perl with fcntl support on Solaris.
To the original poster: That might also be your problem.
Martien
--
Martien Verbruggen |
Webmaster www.tradingpost.com.au | I'm just very selective about what I
Commercial Dynamics Pty. Ltd. | accept as reality - Calvin
NSW, Australia |
------------------------------
Date: Tue, 12 May 1998 19:02:03 -0400
From: comdog@computerdog.com (brian d foy)
Subject: Re: Grieving our dying community
Message-Id: <comdog-ya02408000R1205981902030001@news.panix.com>
Keywords: from just another new york perl hacker
In article <3558C041.CAAD465E@order.booktraders.com>, Birgitt Funk <birgitt@order.booktraders.com> posted:
>> : You should not forget that we can't go to school to learn Perl. We are
>>
>> You're kidding, right?
>I don't think so. In the whole Washington D.C. metropolitan area
>there is not one university who teaches Perl in their curriculum or
>uses Linux for teaching unix system administration, shell programming,
>network administration etc. Why ?
New York University has a very reasonable Perl course. it's even
available to non-matriculated students. perhaps the DC Perl Mongers
can fix the problem down there though :)
>So, why don't you change it to a school with low cost tuition to
>teach programming using the Perl language ? The demand is so
>obviously there.
when you talk to schools about adding courses, you end up talking
to a curriculum committee more interested in adding an intro English
course for the hordes of incoming students than figuring out what
Perl is. Computer Science departments tend to laugh at anyone
suggesting such a course.
the demand is not "obviously" there. you might see it because you
know what the language is and how useful it is, but that means
nothing to a university budget committee which thinks in terms of
the number of students who would take the course and balances that
against all the other demands on the budget.
you're never going to get a Perl course in a university based on
the merits of Perl. you have to think like a university committee
and pander to their concerns - none of which deal with Perl. show
them favorable numbers, and you might have your foot in the door.
otherwise, they'll move on to another crisis.
at least, that's my personal experience from dealing with area
universities on the same issue.
--
brian d foy <comdog@computerdog.com>
CGI Meta FAQ <URL:http://computerdog.com/CGI_MetaFAQ.html>
Comprehensive Perl Archive Network (CPAN) <URL:http://www.perl.com>
Perl Mongers <URL:http://www.pm.org>
------------------------------
Date: Tue, 12 May 1998 23:23:47 GMT
From: Tom Phoenix <rootbeer@teleport.com>
To: Yong Huang <yong@shell.com>
Subject: Re: Is if ($a="something") a bad style?
Message-Id: <Pine.GSO.3.96.980512162308.21974c-100000@user2.teleport.com>
On Tue, 12 May 1998, Yong Huang wrote:
> That's why I want to know if this is thought of as neat in Perl too.
Why do you care whether _we_ think it's neat? What matters more is whether
_you_ think it's neat! :-)
--
Tom Phoenix Perl Training and Hacking Esperanto
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: 12 May 1998 22:53:57 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: memory efficiency question
Message-Id: <6jaju5$5km$2@comdyn.comdyn.com.au>
In article <35571EC6.429EB51F@matrox.com>,
Ala Qumsieh <aqumsieh@matrox.com> writes:
> This reads your file one line at a time. The end of a line is defined by
> the $\ variable.
Do you mean the $/ variable?
# perldoc perlvar
[snip]
$\ The output record separator for the print operator.
[snip]
$/ The input record separator, newline by default.
[snip]
Martien
--
Martien Verbruggen |
Webmaster www.tradingpost.com.au | If it isn't broken, it doesn't have
Commercial Dynamics Pty. Ltd. | enough features yet.
NSW, Australia |
------------------------------
Date: Tue, 12 May 1998 22:58:43 GMT
From: Tom Phoenix <rootbeer@teleport.com>
To: Mitch O'Brien <vincent@psnw.com>
Subject: Re: Newbie needs help!
Message-Id: <Pine.GSO.3.96.980512155015.21974a-100000@user2.teleport.com>
On Tue, 12 May 1998, Mitch O'Brien wrote:
> Subject: Newbie needs help!
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
> Unfortunately I don't have the time to figure out the script that
> I need
[ description of task snipped ]
> I'm running out of time for this
> script to be ready and so I'm asking if anyone can help?
I didn't see where you said what help you needed. Here are some
possibilities:
Are you trying to learn more about Perl? If so, we can probably help you
to find more information. What are you needing to learn?
Are you needing someone to do some programming for you? How much are you
willing to pay?
Is it something else? Maybe you could post again with a specific request.
Cheers!
--
Tom Phoenix Perl Training and Hacking Esperanto
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: 12 May 1998 23:01:16 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: Randomly sorting an array
Message-Id: <6jakbs$7da$1@csnews.cs.colorado.edu>
[courtesy cc of this posting sent to cited author via email]
In comp.lang.perl.misc, Dan Boorstein <danboo@negia.net> writes:
:and if i want the function to return... maybe a 'splice' would be
:appropriate.
That's an O(N**2) kind of approach.
--tom
--
Now I surely will not plague you
With such words as plaque and ague.
------------------------------
Date: 12 May 1998 23:15:32 GMT
From: abigail@fnx.com (Abigail)
Subject: Re: Randomly sorting an array
Message-Id: <6jal6k$pei$1@client2.news.psi.net>
Chip Salzenberg (chip@mail.atlantic.net) wrote on MDCCXV September
MCMXCIII in <URL: news:6jaclq$u6s$1@cyprus.atlantic.net>:
++
++ A simpler approach:
++
++ sub shuffle {
++ my @new;
++ push @new, $_[rand @_] while @_;
++ @new;
++ }
Which of course doesn't terminate.
package Algorithms::Numerical::Shuffle;
################################################################################
#
# $Author: abigail $
#
# $Date: 1998/04/23 17:58:07 $
#
# $Id: Shuffle.pm,v 1.1 1998/04/23 17:58:07 abigail Exp abigail $
#
# $Log: Shuffle.pm,v $
# Revision 1.1 1998/04/23 17:58:07 abigail
# Initial revision
#
#
#
################################################################################
use strict;
use Exporter;
use vars qw /$VERSION @ISA @EXPORT @EXPORT_OK/;
@ISA = qw /Exporter/;
@EXPORT = qw //;
@EXPORT_OK = qw /shuffle/;
($VERSION) = '$Revision: 1.1 $' =~ /(\d+\.\d+)/;
sub shuffle {
my $array = @_ == 1 && ref $_ [0] eq 'ARRAY' ? shift : [@_];
for (my $i = @$array; -- $i;) {
my $r = int rand ($i + 1);
($array -> [$i], $array -> [$r]) = ($array -> [$r], $array -> [$i]);
}
wantarray ? @$array : $array;
}
__END__
=head1 NAME
Algorithms::Numerical::Shuffle - Shuffle a list.
=head1 SYNOPSIS
use Algorithms::Numerical::Shuffle qw /shuffle/;
@shuffled = shuffle (1, 2, 3, 4, 5, 6, 7);
$in_situ = [qw /one two three four five six/];
shuffle $in_situ;
=head1 DESCRIPTION
C<shuffle> performs a one pass, fair shuffle on a list. If the list is
passed as a reference to an array, the shuffle is done in situ.
The subroutine returns the list in list context, and a reference to
the list in scalar context.
=head1 COMPLEXITY
The running time of the algorithm is linear in the size of the list.
For an in situ shuffle, the memory overhead is constant; otherwise,
linear extra memory is used.
=head1 LITERATURE
The algorithm used is discussed by Knuth [3]. It was first published
by Fisher and Yates [2], and later by Durstenfeld [1].
=head1 CAVEAT
Salfi [4] points to a big caveat. If the outcome of a random generator
is solely based on the value of the previous outcome, like a linear
congruential method, then the outcome of a shuffle depends on exactly
three things: the shuffling algorithm, the input and the seed of the
random generator. Hence, for a given list and a given algorithm, the
outcome of the shuffle is purely based on the seed. Many modern computers
have 32 bit random numbers, hence a 32 bit seed. Hence, there are at
most 2^32 possible shuffles of a list, foreach of the possible algorithms.
But for a list of n elements, there are n! possible permutations.
Which means that a shuffle of a list of 13 elements will not generate
certain permutations, as 13! > 2^32.
=head1 REFERENCES
=over
=item [1]
R. Durstenfeld: I<CACM>, B<7>, 1964. pp 420.
=item [2]
R. A. Fisher and F. Yates: I<Statistical Tables>. London, 1938.
Example 12.
=item [3]
D. E. Knuth: I<The Art of Computer Programming>, Volume 2, Third edition.
Section 3.4.2, Algorithm P, pp 145. Reading: Addison-Wesley, 1997.
ISBN: 0-201-89684-2.
=item [4]
R. Salfi: I<COMPSTAT 1974>. Vienna: 1974, pp 28 - 35.
=back
=head1 HISTORY
$Date: 1998/04/23 17:58:07 $
$Log: Shuffle.pm,v $
Revision 1.1 1998/04/23 17:58:07 abigail
Initial revision
=head1 AUTHOR
This package was written by Abigail.
=head1 COPYRIGHT
Copyright 1998 by Abigail.
You may use, distribute and modify this package under the same
terms as Perl.
=cut
--
perl -MLWP::UserAgent -MHTML::TreeBuilder -MHTML::FormatText -wle'print +(HTML::FormatText -> new -> format (HTML::TreeBuilder -> new -> parse (LWP::UserAgent -> new -> request (HTTP::Request -> new ("GET", "http://work.ucsd.edu:5141/cgi-bin/http_webster?isindex=perl")) -> content)) =~ /(.*\))[-\s]+Additional/s) [0]'
------------------------------
Date: 12 May 1998 16:21:13 -0700
From: rokicki@cello.hpl.hp.com (Tom Rokicki)
Subject: Re: Randomly sorting an array
Message-Id: <6jalh9$40m@cello.hpl.hp.com>
Of course, us happy folks just use
@b = map{$_->[1]}sort{$a->[0]<=>$b->[0]}map{[rand,$_]} @a ;
And if you're still using random numbers with only 32 bits of state, well,
I guess there's not much we can do to help you.
-tom
------------------------------
Date: Tue, 12 May 1998 16:19:43 -0700
From: "Larry Rosler" <lr@hpl.hp.com>
Subject: Re: Set Difference Problem!
Message-Id: <6jale8$f1i@hplntx.hpl.hp.com>
[posted and emailed]
Allan M. Due wrote in message <6jadpj$9ia$0@206.165.146.138>...
> I think we have a definition of terms problem here. By your
definition
>(and I have no problem with it) the code in the PerlFAQ for a
difference is
>incorrect as it will never produce a result consistent with the stated
>definition. In my post I accepted the definition of difference implied
(but
>not explicitly stated) by the FAQ and was trying to point out that by
such a
>definition one would not see the results that Walid expected.
>
>The set
>X - Y = { x | x in X and x not in Y }
>is called the difference (or relative complement). The
>difference X - Y consists of all elements in X that are
>not in Y.
>
>@X=(1,2,3,4,5);
>@Y=(1,3,6);
>X-Y =2,4,5;
>Y-X = 6;
>
>Result from FAQ code: 2,4,5,6;
>
> As I see it, by your definition, the PerlFAQ code is in error. By
the
>FAQ's definition, Walid's expectation is wrong. Either way, he does
not
>have code that does what he wants. He originally introduced the
analogy to
>sets (which is implied in the FAQ) and so I was trying (inarticulately
it
>seems) to explain continuing with the analogy. Even though the FAQ
actually
>refers to arrays. I shall endevor to be more percise in the future. I
do
>appreciate the reference.
>
> AmD
In set theory, the result from the FAQ is called "symmetric difference"
(because it's symmetric :-). The result is
( x | x in X and x not in Y or x in Y and x not in X }
--
Larry Rosler
Hewlett-Packard Laboratories
lr@hpl.hp.com
------------------------------
Date: Tue, 12 May 1998 19:09:41 -0400
From: comdog@computerdog.com (brian d foy)
Subject: Re: Significant digit?
Message-Id: <comdog-ya02408000R1205981909410001@news.panix.com>
Keywords: from just another new york perl hacker
In article <6jafep$dou$1@marina.cinenet.net>, cberry@cinenet.net (Craig Berry) posted:
> my $trunc = (int ($mantissa * $figFactor + 0.5)) / $figFactor;
that division is going to mess everything up for certain values of
$mantissa and $figFactor.
--
brian d foy <comdog@computerdog.com>
CGI Meta FAQ <URL:http://computerdog.com/CGI_MetaFAQ.html>
Comprehensive Perl Archive Network (CPAN) <URL:http://www.perl.com>
Perl Mongers <URL:http://www.pm.org>
------------------------------
Date: Tue, 12 May 1998 19:24:45 -0400
From: comdog@computerdog.com (brian d foy)
Subject: Re: Significant digit?
Message-Id: <comdog-ya02408000R1205981924450001@news.panix.com>
Keywords: from just another new york perl hacker
In article <6jafep$dou$1@marina.cinenet.net>, cberry@cinenet.net (Craig Berry) posted:
>John Stanley (stanley@skyking.OCE.ORST.EDU) wrote:
>: I can't get it to run, since:
>:
>: > my $trunc = sprintf "%.*f", $figs, $abcissa;
>:
>: Use of * in printf format not supported at s2 line 25, <> chunk 1.
>Hrm. I thought Perl's s?printf formatting was handled via C's s?printf
>formatting (with some argument jiggering first, of course), and I'm
>fairly certain that width/precision indirection (the .* trick) is part of
>the ANSI C standard. Alas, my copy of same is elsewhere. Anybody have
>one handy to check?
well, i don't know about the printf() thingy, but what about an end
run while we figure it out? :)
#!/usr/bin/perl
my $number = 1/3;
foreach my $decimal_places ( 1..6 )
{
printf("%.${decimal_places}f\n", $number);
}
__END__
0.3
0.33
0.333
0.3333
0.33333
0.333333
--
brian d foy <comdog@computerdog.com>
CGI Meta FAQ <URL:http://computerdog.com/CGI_MetaFAQ.html>
Comprehensive Perl Archive Network (CPAN) <URL:http://www.perl.com>
Perl Mongers <URL:http://www.pm.org>
------------------------------
Date: 12 May 1998 23:25:30 GMT
From: abigail@fnx.com (Abigail)
Subject: Re: Significant digit?
Message-Id: <6jalpa$pei$2@client2.news.psi.net>
brian d foy (comdog@computerdog.com) wrote on MDCCXV September MCMXCIII
in <URL: news:comdog-ya02408000R1205981405590001@news.panix.com>:
++ In article <Pine.GSO.3.96.980511164241.21974b-100000@user2.teleport.com>, Tom Phoenix <rootbeer@teleport.com> posted:
++
++ >On Mon, 11 May 1998, Yong Huang wrote:
++ >
++ >> Did somebody write code to extract significant digits out of a number?
++ >
++ >The FAQ talks about this. Hope this helps!
++
++ actually, i think the problem is a different one than printing a number
++ with the appropriate number of digits. for instance, the number 1234 to
++ two significant digits is 1200. the conventional use of sprintf and
++ friends won't help this. it looks like it's a problem in rounding, but
++ it's a bit more involved.
1200 is 4 significant digits. Try:
$ perl -we 'printf "%.2g\n", 1234'
1.2e+03
2 significant digits.
Abigail
--
perl -MLWP::UserAgent -MHTML::TreeBuilder -MHTML::FormatText -wle'print +(HTML::FormatText -> new -> format (HTML::TreeBuilder -> new -> parse (LWP::UserAgent -> new -> request (HTTP::Request -> new ("GET", "http://work.ucsd.edu:5141/cgi-bin/http_webster?isindex=perl")) -> content)) =~ /(.*\))[-\s]+Additional/s) [0]'
------------------------------
Date: Tue, 12 May 1998 16:31:54 -0700
From: "Larry Rosler" <lr@hpl.hp.com>
Subject: Re: Significant digit?
Message-Id: <6jam4v$f60@hplntx.hpl.hp.com>
[posted and emailed]
Craig Berry wrote in message <6jafep$dou$1@marina.cinenet.net>...
>John Stanley (stanley@skyking.OCE.ORST.EDU) wrote:
>: In article <6ja8ab$8p7$1@marina.cinenet.net>,
>: Craig Berry <cberry@cinenet.net> wrote:
>: >How about this, only tested in a casual way, but seems to do the
job:
>:
>: I can't get it to run, since:
>:
>: > my $trunc = sprintf "%.*f", $figs, $abcissa;
>:
>: Use of * in printf format not supported at s2 line 25, <> chunk 1.
>
>Hrm. I thought Perl's s?printf formatting was handled via C's s?printf
>formatting (with some argument jiggering first, of course), and I'm
>fairly certain that width/precision indirection (the .* trick) is part
of
>the ANSI C standard. Alas, my copy of same is elsewhere. Anybody have
>one handy to check?
"...[A] field width, or precision, or both, may be indicated by an
asterisk. In this case, an *int* argument supplies the field width or
precision..."
The problem lies not in the underlying C library, but in the version of
perl. The full diagnostic in perl 5.002 reads:
(F) You attempted to use a feature of printf that is accessible only
from C. This usually means there's a better way to do it in Perl.
And the "better" (Perlish) way is simply to concatenate the width into
the format string (harder to do in C):
sprintf "%.${figs}f", ...
--
Larry Rosler
Hewlett-Packard Laboratories
lr@hpl.hp.com
------------------------------
Date: 12 May 1998 15:32:01 -0700
From: colink@latticesemi.com (Colin Kuskie)
Subject: Re: Small Perl quick-reference?
Message-Id: <6jail1$s58@sarek.latticesemi.com>
In article <1d8x34q.7tbnvcp7mjysN@slip166-72-108-231.ny.us.ibm.net>,
Kevin Reid <kpreid@ibm.net> wrote:
> "Programming Perl" is a great book - with one problem: it is large and
> heavy. Does anybody know of a small (paperback-novel size) "quick
> reference" book?
There is a great "quick reference" called the
Perl5 Desktop Reference by John Vromans. You can find it at
CPAN at www.perl.org. You'll need to dig around to find the exact
links. Or, you could use the search engine at www.perl.org to
help you find the link. I believe the exact name is
perlref-5.004.1.tar.gz
Hope this helps,
Colin Kuskie
------------------------------
Date: Tue, 12 May 1998 16:31:37 -0700
From: "matthew d. p. k. lanier" <lanier@shell6.ba.best.com>
Subject: sorry bout the long sig
Message-Id: <Pine.BSF.3.96.980512163102.16394L-100000@shell6.ba.best.com>
hello all-
sorry bout the long signature, i forgot to switch sigs.
flame me privately, ok?
matt =)
------------------------------
Date: 12 May 1998 22:48:08 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
To: tchrist@mox.perl.com (Tom Christiansen)
Subject: Re: Tip: Filehandles
Message-Id: <6jajj8$5km$1@comdyn.comdyn.com.au>
[Posted and Mailed]
In article <6jaaja$lpr$1@csnews.cs.colorado.edu>,
Tom Christiansen <tchrist@mox.perl.com> writes:
>:You do realise that there is very likely a very good reason why perlfaq5
>:states the following?
>
> It was written that way because Nate didn't understand filehandles very
> well yet. He's been upgraded since.
I just assumed that the documentation, in this case the FAQ, would be
the correct source of information. If there has been a change since
5.004_04, then I am just not aware of that.
I might just change my local copy of the documentation.
> Stop making things hard that should be easier. These C++ craving is
> the antiperl speaking to you. Get it behind thee.
Heh, I really don't have a C++ craving, thank you. :)
Martien
--
Martien Verbruggen |
Webmaster www.tradingpost.com.au | If it isn't broken, it doesn't have
Commercial Dynamics Pty. Ltd. | enough features yet.
NSW, Australia |
------------------------------
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 2574
**************************************