[12756] in Perl-Users-Digest
Perl-Users Digest, Issue: 166 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Jul 16 13:17:15 1999
Date: Fri, 16 Jul 1999 10:05:20 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Fri, 16 Jul 1999 Volume: 9 Number: 166
Today's topics:
bogus "used only once" message? <mwood@mhw.ULib.IUPUI.Edu>
Re: checking if variable is already a memeber of an arr <flash@pobox.com>
Re: checking if variable is already a memeber of an arr <flash@pobox.com>
Re: checking if variable is already a memeber of an arr <flash@pobox.com>
Re: checking if variable is already a memeber of an arr <tchrist@mox.perl.com>
Re: checking if variable is already a memeber of an arr <tchrist@mox.perl.com>
Re: Date conversions between Perl & Access <dmb197@ecs.soton.ac.uk>
dbase 4 <travis.cox@itron.com>
Re: die ? <uri@sysarch.com>
Re: Every morning at 6.00 am on a NT-box... (Henri Schomäcker)
Re: Help!: trying to compile my scripts <camerond@mail.uca.edu>
Re: how do i convert a integer to string. <dhenders@cpsgroup.com>
Re: How do I find the current line-number while the scr (M.J.T. Guy)
Re: How do you get rid of a remainder in a number <chris@inta.net.uk>
Re: How do you get rid of a remainder in a number <jcreed@cyclone.jprc.com>
Re: How do you get rid of a remainder in a number <chris@inta.net.uk>
Re: How do you get rid of a remainder in a number <anonymous@web.remarq.com>
Re: How do you get rid of a remainder in a number <chris@inta.net.uk>
Re: How do you get rid of a remainder in a number (Larry Rosler)
Re: How do you get rid of a remainder in a number <tchrist@mox.perl.com>
Re: How to output derived value as float <chris@inta.net.uk>
Re: I hate to do this <gt7202e@prism.gatech.edu>
Re: I hate to do this <uri@sysarch.com>
Re: I hate to do this <hove@ido.phys.ntnu.no>
Digest Administrivia (Last modified: 1 Jul 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 16 Jul 1999 16:28:48 GMT
From: "Mark H. Wood" <mwood@mhw.ULib.IUPUI.Edu>
Subject: bogus "used only once" message?
Message-Id: <7mnmk0$66r$1@hercules.iupui.edu>
I've got a lookup table in a (pardon the expression) DOS batch file
used by another application, and I now want to load that table into a
hash. I thought I'd do this cheaply by writing a tiny script to turn
that foreign format into Perl code to assign all the values thus:
%jacks=(
"key1","value1",
"keyN","valueN",
);
and then, in my main script:
do 'blah.pl' || die;
The hash gets loaded just fine, but there's only one other occurrence
of the name "jacks":
dosomething($jacks{$somekey});
and the compiler doesn't like it:
Name "main::jacks" used only once: possible typo at myscript.pl line 42.
Since the assignment worked, and I do get the values out when I
subscript the thing, I think I used main::jacks twice: once to load
it, once to retrieve from it. What gives?
Here's a 1-liner example:
mhw:~$ head netset.pl
# data converted from NETSET.BAT
%jacks = (
"00:C0:4F:C5:F9:BE","ITGXMT",
"00:A0:24:29:AC:9C","0106-C2",
"00:A0:24:26:97:58","0106-D2",
"00:A0:24:29:B6:3D","0106-E1",
"00:A0:24:29:B6:45","0106-H2",
"00:A0:24:29:B0:A9","0106-I1",
"00:A0:24:29:B6:B8","0106-I2",
"00:A0:24:26:99:A9","0106-L1",
mhw:~$ perl -e 'do "netset.pl"; print $jacks{"00:C0:4F:B3:95:16"};'
Name "main::jacks" used only once: possible typo at -e line 1.
mhw:~$ perl --version
This is perl, version 5.005_03 built for i686-linux
--
Mark H. Wood, Lead System Programmer mwood@IUPUI.Edu
A Brazil-nut is neatly packaged and tightly integrated. To turn it into
food, you must crack and remove the shell. I find that I feel the same
way about an increasing number of software products. *sigh*
------------------------------
Date: 16 Jul 1999 16:15:43 GMT
From: Flash Sheridan <flash@pobox.com>
Subject: Re: checking if variable is already a memeber of an array?
Message-Id: <7mnlrf$lq9$1@samba.rahul.net>
In article <slrn7oncuj.q2r.sitaram@diac.com>,
Sitaram Chamarty <sitaram@diac.com> wrote:
>On 13 Jul 1999 16:12:18 GMT, Flash Sheridan <flash@pobox.com> wrote:
>
>>purposes. A high-level language is supposed to make such questionable
>>decisions unnecessary, in favor of a standard, safe, and acceptably-
>
>No. Most of us prefer TMTOWTDI over one-size fits all, which - if
>you come right down to it - is what you are describing (even if
>you didn't realise it)
Wrong. I wasn't saying that people who enjoy re-inventing the wheel should
be prevented from doing their own membership function. I was pointing out
that programmers who want to avoid reinventing the wheel should have that
option as well. That is, in fact, one of the key points to a flexible
high-level programming language, and the analogy with being forced to
re-implement multiplication stands. But I'm certainly not saying that
anyone should be _prevented_ from doing multiplication or membership with
a loop if she chooses to; indeed, it's hard to see how I could prevent it.
--
<LI><a href="http://pobox.com/~flash">Flash Sheridan</a>
<LI><a href="http://pobox.com/~spug">Stanford PalmPilot User Group</a>
------------------------------
Date: 16 Jul 1999 16:27:35 GMT
From: Flash Sheridan <flash@pobox.com>
Subject: Re: checking if variable is already a memeber of an array?
Message-Id: <7mnmhn$luo$1@samba.rahul.net>
In article <xkfvhbol8tj.fsf@valdemar.col.hp.com>,
Eric The Read <emschwar@rmi.net> wrote:
>Flash Sheridan <flash@pobox.com> writes:
>> Disclaimer: I used to be a set theorist, so I'm obviously biased about
>> whether membership is primitive.
>
>Yes, but an array is not a set-- an important distinction which you, as a
>former set theorist, ought to be aware of.
Correct; the terms "ordered set" and "multiset" are each something of a
misnomer, but they're similar enough to unordered sets be useful as well.
(And in fact, in set theory, they're represented as sets, as is everything
else.)
>
>For more "set-like" behaviour, use a hash. exists() is a "primitive"
>(predefined function, more like, but close enough), it doesn't burden you
>with annoying things like ordering your set elements for you,
For the cases in which I've had to implement my own membership function,
the objects have generally been presented in a linear order. Whether
this is significant or just a coincidence depends, e.g., on how you feel
about the Axiom of Choice. But in such cases, good programming practice
(unless there's a good reason to do otherwise) would be to use a language
primitive for array membership. Everything should be done at the highest
practical level of abstraction, but no higher.
--
<LI><a href="http://pobox.com/~flash">Flash Sheridan</a>
<LI><a href="http://pobox.com/~spug">Stanford PalmPilot User Group</a>
------------------------------
Date: 16 Jul 1999 16:36:36 GMT
From: Flash Sheridan <flash@pobox.com>
Subject: Re: checking if variable is already a memeber of an array?
Message-Id: <7mnn2k$m16$1@samba.rahul.net>
In article <slrn7ongtm.h7.abigail@alexandra.delanet.com>,
Abigail <abigail@delanet.com> wrote:
>Flash Sheridan (flash@pobox.com) wrote on MMCXLII September MCMXCIII in
><URL:news:7mfoh2$sqv$1@samba.rahul.net>:
><> In article <slrn7omg2s.h7.abigail@alexandra.delanet.com>,
><> Abigail <abigail@delanet.com> wrote:
><> >Artoo (r2-d2@REMOVEbigfoot.com) wrote on MMCXLII September MCMXCIII in
><> ><URL:news:378b14d7.0@london.netkonect.net>:
><> >**
><> >** How can you check whether a variable is already a member of an array with
><> >** out using any form of loop?
><> >...
><> >The answer is 'of course not'. What do you have against
><> >loops anyway?
><>
><> They're unnecessarily complicated, and prone to programmer error,
><> when used for what ought to be a language primitive. Or do you also
><> eschew multiplication, in favor of addition in a loop?
>
>Silly analogon.
You're free to call it silly, of course, but do you have any actual evidence
that it doesn't apply?
>You can call things a primitive all you want, fact is, you still need
>to loop.
No, the machine code may need to loop, _I_ don't. I was discussing Perl,
not machine code. In a high-level language, unless there's a good reason
to the contrary, I shouldn't have to worry about how multiplication or
membership is implemented.
--
<LI><a href="http://pobox.com/~flash">Flash Sheridan</a>
<LI><a href="http://pobox.com/~spug">Stanford PalmPilot User Group</a>
------------------------------
Date: 16 Jul 1999 10:50:25 -0700
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: checking if variable is already a memeber of an array?
Message-Id: <378f62d1@cs.colorado.edu>
In comp.lang.perl.misc, Flash@pobox.com writes:
:But in such cases, good programming practice
:(unless there's a good reason to do otherwise) would be to use a language
:primitive for array membership.
C doesn't have this either, and for the same reason. "Array membership"
makes little sense. Are you sure you know what an array is? Why do you
want to encourage linear searches?
--tom
--
Hartley's Second Law:
Never sleep with anyone crazier than yourself.
------------------------------
Date: 16 Jul 1999 10:54:03 -0700
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: checking if variable is already a memeber of an array?
Message-Id: <378f63ab@cs.colorado.edu>
In comp.lang.perl.misc, Flash@pobox.com writes:
:Wrong. I wasn't saying that people who enjoy re-inventing the wheel should
:be prevented from doing their own membership function.
You're using a very weird definition for membership. I suppose that
the notion of dynamic sets comprise both perl arrays and perl hashes,
and that membership being a property of a set datatype must consequently
apply here, but I think you're barking up the wrong search tree.
--tom
--
Won't it make you lose your wits,
Writing groats and saying grits?
------------------------------
Date: Fri, 16 Jul 1999 16:49:41 +0100
From: Dylan Beattie <dmb197@ecs.soton.ac.uk>
Subject: Re: Date conversions between Perl & Access
Message-Id: <Pine.LNX.3.96.990716164827.6291B-100000@soolin.ecs.soton.ac.uk>
On 13 Jul 1999, Steffen Beyer wrote:
> In article <Pine.LNX.3.96.990712171734.27292C-100000@soolin.ecs.soton.ac.uk>, Dylan Beattie <dmb197@ecs.soton.ac.uk> wrote:
>
> > I'm writing some Perl CGI stuff to talk to an Access database via the
> > Win32::ODBC package - it's all working real nicely, except Access and Perl
> > use different date formats and it looks like it could be a bit tricky
> > converting between the two. Before I dive in and do all the hard work
> > myself, anyone know if there's a module that handles it or even just
> > script fragment?
>
> There's a recipe in the documentation of Date::Calc which deals with
Yep, that'd be the one... Found Date::Calc the other day, solves most of
the tricky stuff for me, but thanks for the tip anyway!
Cheers,
D.
===========================================
Dylan Beattie dmb197@zepler.org
Computer Science, University of Southampton
ICQ:34865704 http://www.zepler.org/~dmb197/
===========================================
------------------------------
Date: Fri, 16 Jul 1999 08:47:17 -0700
From: "TravisC" <travis.cox@itron.com>
Subject: dbase 4
Message-Id: <7mnjrt$cpc$1@bayer.itron.com>
I am looking for a module to convert text files to dbase (.dbf) format
so far I haven't found anything. Any help would be greatly appreciated.
------------------------------
Date: 16 Jul 1999 11:33:31 -0400
From: Uri Guttman <uri@sysarch.com>
Subject: Re: die ?
Message-Id: <x7lncglid0.fsf@home.sysarch.com>
>>>>> "BP" == Brian Pontz <pontz@channel1.com> writes:
BP> sub Error {
BP> my ($mesg)=@_;
BP> print "Content-type: text/html\n\n";
BP> print <<"end_print";
BP> <HTML><HEAD><TITLE> Error </TITLE></HEAD>
BP> <BODY BGCOLOR="#000000">
BP> Error:$mesg
BP> </BODY>
BP> </HTML>
BP> end_print
BP> exit 0;
BP> }
now here is an interesting situation. the correct answer was posted
several times and then we get this roll your own version which doesn't
show the line number, and possibly prints out an extra header. so will
this poster read the other solutions and learn or will he think his is
reply is good so he doesn't need to see what others say.
well, i am cc'ing this so i can say to him:
read the other posts in this thread so you learn a better way to do
this.
uri
--
Uri Guttman ----------------- SYStems ARCHitecture and Software Engineering
uri@sysarch.com --------------------------- Perl, Internet, UNIX Consulting
Have Perl, Will Travel ----------------------------- http://www.sysarch.com
The Best Search Engine on the Net ------------- http://www.northernlight.com
"F**king Windows 98", said the general in South Park before shooting Bill.
------------------------------
Date: Fri, 16 Jul 1999 16:04:52 GMT
From: hschomae@rz-online.de (Henri Schomäcker)
Subject: Re: Every morning at 6.00 am on a NT-box...
Message-Id: <378f56d4.11365586@news.rhein-zeitung.de>
On Wed, 14 Jul 1999 13:33:19 GMT, hschomae@rz-online.de (Henri
Schomäcker) wrote:
>Hi folks,
>
>I`ve got a pretty complex problem:
>
>A customer gets info-requests by a form on his webpage on a NT-Box,
>which are stored into a textfile.
>Right now, he can download the Textfile which is copied to a public
>directory for this purpose and deleted after the download and renamed
>in the secure directory to request_actual_date.txt .
>
>Now he wants to get the file every morning at 6.00am mailed as an
>attachment to his email account.
>
>O.K. mailing the file as an attachment is no problem, Im doing this
>with Blatmail, wich works great!
>
>My problem is how to do this job best on the NT-I-Net Server.
>
>I thought of starting a script which mails the actual textfile as
>attachment, and renames it afterwoods.
>
>But how to start the script the best way?
>- Setting up a service on the NT-box wich starts the script every
> morning?
> And if this is the best way, how should the script be called
> (Sorry, but I dont have the possibility to try this out on NT
> because I just have Win 98 set up and have to deal with the admins
> of the webspace provider) "perl.exe path to my script"?
> Is there something special I have to take care of when coding the
> script? I normally use Blatmail by a system() call.
>
>- Is there a possibility to let the perl-script do the control of time
> and starting the actions every morning without any NT-Services?
> Eg by a Win32::? Module?
>
>
>Any ideas?
>
>
>Thanks very much in advance for every little suggestion and help,
>
>yours Henri
>
>+---------------------------------------+
Hi folks,
Thanks, I`ve done it now this way and it works very well:
Wrote the script that does all the recommendet work,
dosbox: pl2bat c:\path_to_script\send_info_requests.pl
-> send_info_requests.bat
via ftp to server,
called the admin and let him set up the service to start it every day
at 6.00 am.
That was it.
CU Henri
+---------------------------------------+
| Henri Schomäcker - VIRTUAL HOMES |
| Datendesign für Internet und Intranet |
| http://www.virtual-homes.de/ |
| henri.schomaecker@virtual-homes.de |
+---------------------------------------+
------------------------------
Date: Fri, 16 Jul 1999 11:20:45 -0500
From: Cameron Dorey <camerond@mail.uca.edu>
Subject: Re: Help!: trying to compile my scripts
Message-Id: <378F5BDD.6CE5793@mail.uca.edu>
The Thing of Rock 'N Roll wrote:
>
> In a similar vein, I am trying to find a method of hiding myself from
> the public. Can anyone offer any suggestions?
1. Make a whole lot of money.
2. Purchase the penthouse floor in a Las Vegas hotel and move there.
3. Order pizza in every night.
A variation of this (because I can't remember the details) worked quite
well for Howard Hughes.
Cameron
--
Cameron Dorey
Associate Professor of Chemistry
University of Central Arkansas
Phone: 501-450-5938
camerond@mail.uca.edu
------------------------------
Date: 16 Jul 1999 10:17:17 -0500
From: Dale Henderson <dhenders@cpsgroup.com>
Subject: Re: how do i convert a integer to string.
Message-Id: <874sj4zksi.fsf@camel.cpsgroup.com>
[Posted and a courtesy copy mailed.]
In article <7mljd7$s1r$1@nnrp1.deja.com> on Thu, 15 Jul 1999 21:21:56
GMT, Dale Henderson <dhenders@cpsgroup.com> says...
> In article <7mg4kg$scg$1@nnrp1.deja.com>,
> cramey@my-deja.com wrote:
> > i want to convert an integer
> >
> > specifically
> >
> > 1111111 to a string with
> >
> > str[0] == 1
> > .
> > .
> > .
> > str[6] == 1
> >
> > is there an easy way to do this ?
> (newsfeed is on the fritz, posting from dejanews)
> you might try this. It does almost exactly what you ask.
Larry> <SNIP> of C-ish code reproduced more legibly in the
Larry> benchmark below.
Very C-ish that is what was asked for. :)
Larry> It's hard to know what to make of this submission, other
Larry> than to take it at face value. TMTOWTDI, isn't there? So
Larry> here's a benchmark.
Actually it was a joke.
Larry> #!/usr/local/bin/perl -w
Larry> use strict;
Larry> use Benchmark;
Larry>
Larry> my $x = 1_111_111;
Larry>
Larry> timethese(1 << (shift || 0), {
Larry> Loop => sub {
Larry> my $num = $x;
Larry> my $len = int(log($num)/log(10));
Larry> my $str = " " x $len;
Larry> while ($num > 0) {
Larry> my $digit = $num%10;
Larry> substr($str, $len, 1) = sprintf("%d", $digit);
Larry> $num = int($num/10);
Larry> $len--;
Larry> }
Larry> "|$str|\n"
Larry> },
Larry> String => sub { "|$x|\n" },
Larry> });
Larry> __END__
Larry> Benchmark: timing 65536 iterations of Loop, String...
Larry> Loop: 14 wallclock secs (14.20 usr + 0.00 sys = 14.20 CPU)
Larry> String: 1 wallclock secs ( 0.39 usr + 0.00 sys = 0.39 CPU)
Larry> (warning: too few iterations for a reliable count)
I knew that log trick would slow it down.
Larry> Maybe we need an award for The Least Appropriate Way To Do
Larry> It.
Cool. That's exactly what I was going for. And my code is less
appropriate than yours because by your own admission mine was
less legable. Plus I didn't use strict or -w. :p
> --
> Dale Henderson <mailto:dhenders@cpsgroup.com>
...
Larry> If you put a magic invisible trailing space after the two
Larry> dashes, proper newsreaders will snip your signature
Larry> automatically.
Yet another reason not to use deja news.
------------------------------
Date: 16 Jul 1999 15:07:51 GMT
From: mjtg@cus.cam.ac.uk (M.J.T. Guy)
Subject: Re: How do I find the current line-number while the script is running?
Message-Id: <7mnhs7$koh$1@pegasus.csx.cam.ac.uk>
In article <q3Dj3.101$nz6.349@news1.online.no>,
Trond Michelsen <mike@crusaders.no> wrote:
>
>Trond Michelsen <mike@crusaders.no> wrote in message
>news:NdCj3.67$nz6.124@news1.online.no...
>> I have a small problem. I have to make a small wrapper for the die()
>> function, so that instead of just dying, the program closes a database,
>> writes to a logfile, then removes a lockfile and finally just dies.
>
>Just typical isn't it... I've obviously looked through all the wring parts
>of the docs. Anyway - the first thing I read after posting my question is
>chapter 10.4 of the Perl Cookbook.
>
>Well, well - at least I know how to use the caller() function now :-)
Also, the built-in Carp module may provide a pre-packaged solution
to your problem.
Mike Guy
------------------------------
Date: Fri, 16 Jul 1999 16:07:09 +0100
From: "Chris Denman" <chris@inta.net.uk>
Subject: Re: How do you get rid of a remainder in a number
Message-Id: <7mni0t$2oda$1@news2.vas-net.net>
$number=split(/\./,$float);
You never know!
Chris Denman
Ronald J Kimball wrote in message
<1dustk3.18liwbw1llsid8N@p53.block1.tc4.state.ma.tiac.com>...
>Warren McCoy <perl@dfwplaza.com> wrote:
>
>> I am creating a formula for going through an array,
>> and I want to use the whole number from the result
>> of a division statement.
>>
>> i.e. 14 divided by 5 = 2.7999999999999998224
>> I just want the 2!
>>
>> I have tried the remainder function (%) but that does
>> not work like the book states; (I am on a UNIX server)
>
>The remainder here is 4, not 2. I think you must be misunderstanding
>what the book says.
>
>What you want is the integer portion of the quotient. That is
>ridiculously easy: int(14/5).
>
>--
> _ / ' _ / - aka -
>( /)//)//)(//)/( Ronald J Kimball rjk@linguist.dartmouth.edu
> / http://www.tiac.net/users/chipmunk/
> "It's funny 'cause it's true ... and vice versa."
------------------------------
Date: 16 Jul 1999 11:18:36 -0400
From: Jason Reed <jcreed@cyclone.jprc.com>
Subject: Re: How do you get rid of a remainder in a number
Message-Id: <a1n1wwhbcj.fsf@cyclone.jprc.com>
"Chris Denman" <chris@inta.net.uk> writes:
> $number=split(/\./,$float);
Doesn't work.
#!/usr/bin/perl
$float = "4.3";
$number1=split(/\./,$float);
($number2)=split(/\./,$float);
print "scalar context: $number1 (wrong)\nlist context: $number2 (right)\n";
yields
scalar context: 2 (wrong)
list context: 4 (right)
(
Not that I'd recommend using
($number)=split(/\./,$float);
over
$number = int($float);
)
---Jason
------------------------------
Date: Fri, 16 Jul 1999 17:29:43 +0100
From: "Chris Denman" <chris@inta.net.uk>
Subject: Re: How do you get rid of a remainder in a number
Message-Id: <7mnmrn$2ql5$1@news2.vas-net.net>
My mistake, $number should have been in brackets.
You are wrong about INT though, it rounds the number up or down.
Chris Denman
Jason Reed wrote in message ...
>"Chris Denman" <chris@inta.net.uk> writes:
>
>> $number=split(/\./,$float);
>Doesn't work.
>
>#!/usr/bin/perl
>$float = "4.3";
>$number1=split(/\./,$float);
>($number2)=split(/\./,$float);
>print "scalar context: $number1 (wrong)\nlist context: $number2 (right)\n";
>
>yields
>
>scalar context: 2 (wrong)
>list context: 4 (right)
>
>(
>Not that I'd recommend using
>($number)=split(/\./,$float);
>over
>$number = int($float);
>)
>
>---Jason
------------------------------
Date: Fri, 16 Jul 1999 08:38:39 -0800
From: Ashish Kadakia <anonymous@web.remarq.com>
Subject: Re: How do you get rid of a remainder in a number
Message-Id: <932143122.5451@www.remarq.com>
int (14/5) always gives the answer 2.
It dosen't round up, it just cuts every thing after decimal
point.
**** Posted from RemarQ - http://www.remarq.com - Discussions Start Here (tm) ****
------------------------------
Date: Fri, 16 Jul 1999 17:43:53 +0100
From: "Chris Denman" <chris@inta.net.uk>
Subject: Re: How do you get rid of a remainder in a number
Message-Id: <7mnnm7$2qt5$1@news2.vas-net.net>
I am a fool. Ignore me. I posted without testing, and presumed it would
happen that way. I must have used this command in a different language
where it indeed rounded up or down the number. I could also be talking out
of my arse.
Chris Denman
Ashish Kadakia wrote in message <932143122.5451@www.remarq.com>...
>int (14/5) always gives the answer 2.
>It dosen't round up, it just cuts every thing after decimal
>point.
>
>
>
>**** Posted from RemarQ - http://www.remarq.com - Discussions Start Here
(tm) ****
------------------------------
Date: Fri, 16 Jul 1999 09:52:09 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: How do you get rid of a remainder in a number
Message-Id: <MPG.11f903138d8c2911989ce3@nntp.hpl.hp.com>
In article <7mnmrn$2ql5$1@news2.vas-net.net> on Fri, 16 Jul 1999
17:29:43 +0100, Chris Denman <chris@inta.net.uk> says...
> My mistake, $number should have been in brackets.
>
> You are wrong about INT though, it rounds the number up or down.
You are wrong about int() though. It truncates the number toward zero.
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: 16 Jul 1999 10:58:12 -0700
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: How do you get rid of a remainder in a number
Message-Id: <378f64a4@cs.colorado.edu>
In comp.lang.perl.misc, Ashish Kadakia <anonymous@web.remarq.com> writes:
:int (14/5) always gives the answer 2.
:It dosen't round up, it just cuts every thing after decimal
:point.
I don't think I'm happy with the "round up" terminology, but I'm
not entirely sure why, although floor and ceiling I can handle.
DB<1> printf "%.0f\n", 0.5
0
DB<2> printf "%.0f\n", 1.5
2
DB<3> printf "%.0f\n", 2.5
2
DB<4> printf "%.0f\n", 3.5
4
DB<5> printf "%.0f\n", 4.5
4
DB<6> printf "%.0f\n", 5.5
6
--tom
--
: 1. What is the possibility of this being added in the future?
In the near future, the probability is close to zero. In the distant
future, I'll be dead, and posterity can do whatever they like... :-) --lwall
------------------------------
Date: Fri, 16 Jul 1999 16:13:04 +0100
From: "Chris Denman" <chris@inta.net.uk>
Subject: Re: How to output derived value as float
Message-Id: <7mnic0$2oks$1@news2.vas-net.net>
($left)=split(/\./,$number);
$newnumber="$left.0";
It's *A* solution.
Chris Denman
Tom Kralidis wrote in message <378DFF8D.9855CC2F@ccrs.nrcanDOTgc.ca>...
>I am writing a script to extract given values from a text file and print
>them to another file. One of the derived values involves some
>calculations, assigning this value to a variable. The values involve
>floats.
>
>eg. $value = 5464085.0 + ((400 -1) * 5);
> print "$value";
>
>..gives me 5466080
>
>whereas if I alter the equation to:
>
>eg. $value = 5464085.1 + (400 -1) * 5);
> print "$value";
>
>..gives me 5466080.1, picking up the decimal place if not a zero value.
>
>How can I print out the first example as 5466080.0, to show one decimal
>place when 0?
>
>Any advice is appreciated.
>
>Thanks
>
>..Tom
>
>---------------------------------------------------------------------------
--------------
>Tom Kralidis Geo-Spatial Technologist
>Canada Centre for Remote Sensing Tel: (613) 947-1828
>588 Booth Street , Room 241 Fax: (613) 947-1408
>Ottawa , Ontario K1A 0Y7
>http://www.ccrs.nrcan.gc.ca
>---------------------------------------------------------------------------
--------------
------------------------------
Date: Fri, 16 Jul 1999 11:15:33 -0400
From: andy barfoot <gt7202e@prism.gatech.edu>
Subject: Re: I hate to do this
Message-Id: <378F4C95.48EFD1CF@prism.gatech.edu>
Ion Pro wrote:
>
> I'm a "newbie" to Perl, and I'm trying to write a script to randomly change
> wallpaper (on a *nix system). I got it randomly changing-- but it cannot
> repeat any image until all are used. Now, it does repeat any image-- it just
> stops working when all of them are used, and I cannot figure out why. There
> is no error output-- it just sits there spinning away until I manually end
> task. Also, did I mention I was coding this in Windoze? a little hard to
> test....
> Anyway, most of this is Perl4-- I've read the infamous Llama book, but
> nothing else, really.
my @gfx = grep /\.(gif|jpe?g|etc)$/i, <directory/*>;
# Use of @gfx in scalar context.
my $random_number = time % @gfx;
# exec does not return (if it works), unlike system.
exec "blah blah $gfx[$random_number]" or die "$0 couldn't exec xv:
$!\n";
--
andy barfoot
------------------------------
Date: 16 Jul 1999 12:05:30 -0400
From: Uri Guttman <uri@sysarch.com>
Subject: Re: I hate to do this
Message-Id: <x7emi8lgvp.fsf@home.sysarch.com>
>>>>> "IP" == Ion Pro <ion@preferred.com> writes:
why did you use such a poor subject? you are asking a legitimate
question and posted real code. that is better than %99 of the newbies here.
IP> I'm a "newbie" to Perl, and I'm trying to write a script to
IP> randomly change wallpaper (on a *nix system). I got it randomly
IP> changing-- but it cannot repeat any image until all are used. Now,
IP> it does repeat any image-- it just stops working when all of them
IP> are used, and I cannot figure out why. There is no error output--
IP> it just sits there spinning away until I manually end task. Also,
IP> did I mention I was coding this in Windoze? a little hard to
IP> test.... Anyway, most of this is Perl4-- I've read the infamous
IP> Llama book, but nothing else, really.
that is "famous" llama. and you are using perl5 stuff like map here.
IP> #!/usr/bin/perl -w
good for -w.
bad for no use strict ;
IP> #Script to randomly change wallpaper. Very nice indeed.
IP> #xv syntax: xv -root -quit -maxpect filename
IP> #open directory, get listing of files
IP> opendir CWD, "." || die "Can't open current directory $!";
good for testing output of opendir (and open below)
good for printing $!
bad for wrong precedence. either wrap the oper args in () or use 'or'
instead of ||. same for other opens.
IP> @files = readdir CWD;
IP> close CWD;
IP> #start logfile section
IP> &init; #initalize logfile vars and filehandles
in perl5 you can say init() which looks nicer.
IP> if ($numFiles==$count) {
IP> unlink "logfile";
no check if unlink worked.
IP> &init;
IP> my %h = map { $_ => 1 } @log;
IP> @unused = grep { !$h{$_} } @files;
IP> $numFiles=(scalar @unused);
unneeded use of scalar. assigning an array to a scalar does that for you.
IP> }
IP> &pick_wallpaper;
IP> print LOGFILE "$wallpaper\n"; #send wallpaper name to logfile
IP> #start subroutine defs
IP> sub pick_wallpaper {
IP> $fnumber=0;
IP> $wallpaper="";
IP> srand(time()^($$+($$<<15))); #initalize random number generator
current versions of perl don't need to call srand.
IP> while ( ($fnumber<2) or ($fnumber >= $numFiles) or
how can $fnumber be >= $numFiles when you are using rand to create it?
and with my comment below you can delete the < 2 clause.
IP> $wallpaper=~/change/ or
IP> $files[$fnumber]=~m[\.(pl|log|sh)$]) {
why filter out the bad suffixes here? why not do it when you do the
readdir and then all your random choices will be good. and it wouldbe
better to use a positive filter like
@wall_files = grep /\.wp$/, readdir DIR
IP> #We can't use the first or second directory entry, as they're ./
IP> and ../
same comment.
IP> $fnumber=(int(rand $numFiles));
IP> $wallpaper=$unused[$fnumber];
a simple splice to remove the entry would make life easier.
IP> }
IP> }
the reason you never repeat is that you never repeat. after you use up
all the files, you have to exit this loop and iterate in an outer loop.
IP> sub init {
IP> $logentries=0; #initalize vars used later on
IP> open LOGFILE,">>logfile" || die "Can't open a file for writing $!"; #open a
IP> file for writing
IP> open READLOG,"logfile" || die "Can't open logfile for reading $!"; #open a
IP> file for reading
IP> chomp(@log=<READLOG>); #read the logfile into an array
IP> #this'll determine how long the array is (how many entries...)
IP> $logentries=(scalar @log);
same as before. no need for scalar.
IP> #make @unused = @files-@log
IP> my %h = map { $_ => 1 } @log;
IP> $count = 0;
IP> @unused = grep { !$h{$_} } @files;
IP> $numFiles=(scalar @unused);
IP> foreach (@files) {
IP> $count++ if (m[\.(pl|log|sh)$]);
IP> }
IP> }
i don't feel like analyzing the above code. it is making my head hurt.
here is a simple version of your program. assume wallpaper file have a
wp suffix.
opendir(CWD, "." ) || die "Can't open current directory $!";
@wp_files = grep /\.wp$/, readdir CWD ;
close CWD
while( 1 ) {
@wp_left = @wp_files ;
while( @wp_left ) {
$wp_file = splice( @wp_left, int rand @wp_left, 1 ) ;
system("/usr/X11R6/bin/xv -root -quit -maxpect $wp_file");
sleep 300 ; # 5 minutes per wallpaper
}
}
no logging (what are you trying to log?) but clean and neat.
uri
--
Uri Guttman ----------------- SYStems ARCHitecture and Software Engineering
uri@sysarch.com --------------------------- Perl, Internet, UNIX Consulting
Have Perl, Will Travel ----------------------------- http://www.sysarch.com
The Best Search Engine on the Net ------------- http://www.northernlight.com
"F**king Windows 98", said the general in South Park before shooting Bill.
------------------------------
Date: 16 Jul 1999 18:39:57 +0200
From: Joakim Hove <hove@ido.phys.ntnu.no>
Subject: Re: I hate to do this
Message-Id: <k0nr9m8mtuq.fsf@ido.phys.ntnu.no>
"Ion Pro" <ion@preferred.com> writes:
> I'm a "newbie" to Perl, and I'm trying to write a script to randomly change
> wallpaper (on a *nix system). I got it randomly changing-- but it cannot
> repeat any image until all are used. Now, it does repeat any image-- it just
> stops working when all of them are used, and I cannot figure out why. There
> is no error output-- it just sits there spinning away until I manually end
Hello,
maybe I did not quite understand what you wanted to accomplish. How I
understood it was that every time the program is run a new random
wallpaper should be assigned, not repeating before they had all been
tried out. I though I had an elegant solution to this, but as things
turned out I'm not particulary satisfied with it, but here it comes
...
#!/store/bin/perl -w
$logfile = "/path/LogFile";
$image_dir = "/path/to/images";
opendir(CWD , $image_dir) || die("Could not read directory $!\n");
@file_list = grep { /\w+\.(jpe?g|gif)/i } readdir CWD;
closedir(CWD);
# OK - now @file_list contains a list of all the files with extensions
# .jpg, .jpeg and .gif (case insensitive - that is the final "i" in
# the grep).
if (-e $logfile) {
open(LOGFILE , $logfile) || die("Could not open $logfile for reading $!\n");
while (<LOGFILE>) {
chomp;
$used_image{$_} = 1;
}
close(LOGFILE);
} else {
%used_image = ();
}
# We build up a hash with all the images we have used previously. If
# we can not find the log over previously used images we start afresh.
@image_list = ();
foreach $image (@file_list) {
if (! defined $used_image{$image}) {
push @image_list , $image;
}
}
# Now we have looped through all the avilable images in the
# @file_list, and the ones which were not also in the logfile have
# been appended into @image_list, which now contains the list of
# available images.
if (! @image_list) {
unlink($logfile) || die("Could not unlink $logfile $!\n");
@image_list = @file_list;
}
# If there are now images in @image_list - meaning we have gone
# through all the images at our disposal we start afresh.
$image_number = int rand @image_list;
$image = $image_list[$image_number];
# Pick a random number and a corresponding image.
open (LOGFILE , ">>$logfile") || die("Could not open $logfile for appending $! \n");
print (LOGFILE $image , "\n");
close (LOGFILE);
# Append the last chosen image to the log-file.
system($xv_cmd $image)
If this is of any use to you I'm happy :-), anyway I enjoyed writing
it.
Joakim
--
=== Joakim Hove www.phys.ntnu.no/~hove/ ======================
# Institutt for fysikk (735) 93637 / 352 GF | Skøyensgate 10D #
# N - 7034 Trondheim hove@phys.ntnu.no | N - 7030 Trondheim #
=====================================================================
------------------------------
Date: 1 Jul 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 1 Jul 99)
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 V9 Issue 166
*************************************