[10807] in Perl-Users-Digest
Perl-Users Digest, Issue: 4408 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Dec 12 08:07:23 1998
Date: Sat, 12 Dec 98 05:00:39 -0800
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Sat, 12 Dec 1998 Volume: 8 Number: 4408
Today's topics:
a simple puzzle (I suspect) <ddvddv@earthlink.net>
Re: a simple puzzle (I suspect) <uri@sysarch.com>
Re: Accessing MS SQL db from unix <jjn@sanger.ac.uk>
Re: Beginner Book? gwynne@utkux.utk.edu
Re: Change Directory (terry hinds)
Event reminder script? <nurdan@usa.net>
Functions in a template file. <ava@softclub.net>
Re: ip to name lookup (reverse name lookup) (Charles DeRykus)
Re: ls -l in perl? (Mark-Jason Dominus)
LWP problem/question <chobbs@silvervalley.k12.ca.us>
Re: mail attachment <preble@ipass.net>
Re: mail Attachments in Perl <preble@ipass.net>
Re: Making O'Reilly phone script do html <gellyfish@btinternet.com>
no UnderScore (was: Re: usage of $_ within nested loops (Bart Lateur)
OLE referencing problem: PerlScript, ASP and CDONTS.New bdavis@mediaphex.com
Re: rounding numbers (Richard J. Rauenzahn)
Re: rounding numbers (Andre L.)
Re: rounding numbers (Tad McClellan)
Re: Sending file attachments in email <preble@ipass.net>
socket question: to wait or not to wait <kos@tdd.hbo.nec.com>
Re: Splitting a string at a certain point (Bart Lateur)
Re: typeglob (*) VS (\%) direct pass-by-ref (Mark-Jason Dominus)
Re: Writing to filehandles and STDOUT (terry hinds)
Re: Y2K potential problem in localtime() (Larry Rosler)
Special: Digest Administrivia (Last modified: 12 Dec 98 (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Fri, 11 Dec 1998 21:01:25 -0800
From: Dan DeVries <ddvddv@earthlink.net>
Subject: a simple puzzle (I suspect)
Message-Id: <3671F8A5.4319F73C@earthlink.net>
I need to do something that looks pretty simple, but simple me, I
am having some trouble:
I need to downcase a string that WILL be quoted by () and MAY be quoted
by ""
if it follows a particular string. For example, if that string is CELL:
CELL(XYZ) => CELL(xyz)
CELL("XYZ") => CELL("xyz")
nothing else changes.
I'm not much of a perl expert, appreciate some help from you gurus.
Email
to ddevries@pdx.mentorg.com would be nice, but I'll watch the groups.
Thanks,
Dan.
------------------------------
Date: 12 Dec 1998 01:57:52 -0500
From: Uri Guttman <uri@sysarch.com>
Subject: Re: a simple puzzle (I suspect)
Message-Id: <x7u2z1u9sf.fsf@sysarch.com>
>>>>> "DD" == Dan DeVries <ddvddv@earthlink.net> writes:
BTW comp.lang.perl is no longer a real group. i dropped it from the
followups
DD> I need to downcase a string that WILL be quoted by () and MAY be
DD> quoted by "" if it follows a particular string. For example, if
DD> that string is CELL:
DD> CELL(XYZ) => CELL(xyz)
DD> CELL("XYZ") => CELL("xyz")
i would normally first ask you for what code you have tried and failed
but i am feeling generous tonight.
this works fine. it doesn't check for the "" at all. it uses the
required () to find the upper case string. if the prefix is fixed you
can use it instead of $pre in both parts.
s/$pre\((.+?)\)/$pre(\L$1)/;
hth,
uri
--
Uri Guttman ----------------- SYStems ARCHitecture and Software Engineering
Perl Hacker for Hire ---------------------- Perl, Internet, UNIX Consulting
uri@sysarch.com ------------------------------------ http://www.sysarch.com
The Best Search Engine on the Net ------------- http://www.northernlight.com
------------------------------
Date: Sat, 12 Dec 1998 10:15:58 +0000
From: Jonathan Nicholson <jjn@sanger.ac.uk>
Subject: Re: Accessing MS SQL db from unix
Message-Id: <3672425E.A1952FD0@sanger.ac.uk>
dturley@pobox.com wrote:
>
> In article <74r8kq$jlu$3@zware.space.ru>,
> vitus@brass.fe.msk.ru (Victor B Wagner) wrote:
> > Jonathan Nicholson (jjn@sanger.ac.uk) wrote:
> >
> > : Is there a perl module out there that will allow me to access a NT MS SQL
> > : database from UNIX.
> >
> > DBD::Sybase?
>
> DBD::ODBC
Thanks for all the replies. I've got it to work using DBD::Sybase. Is it
possible to use ODBC? If so how (I'm not familiar with ODBC) as I
understand that SQL7 is no longer based on Sybase...
Regards,
Jonathan
------------------------------
Date: Sat, 12 Dec 1998 06:15:09 GMT
From: gwynne@utkux.utk.edu
Subject: Re: Beginner Book?
Message-Id: <74t1ld$49b$1@nnrp1.dejanews.com>
In article <rdm-1711980047340001@140.174.42.30>,
rdm@cfcl.com (Rich Morin) wrote:
> In article <36512724.396404058@news.online.no>, tore@forumnett.no wrote:
>
> > On Mon, 16 Nov 1998 19:12:10 GMT, jeff.kennedy@natdecsys.com (Jeff
> > Kennedy) wrote:
> > > I need a book geared to an ABSOLUTE BEGINNER! No perl experience, no
> > > programming experience, no real shell scripting experience.
> >
> > "Learning Perl, 2nd Edition" should work out just fine. When
> > finished reading it, proceed with "Programming Perl, 2nd Edition".
>
> "Learning Perl" is a bit ungentle for a real beginner. Although it's
> geared towards MacPerl, you might try "MacPerl: Power and Ease". An
> HTML copy is available at http://www.ptf.com/macperl/ptf_book/HTML/
>
MacPerl:Power and Ease does not have enough exercises and is not basic
enough. I suggest Perl 5 Interactive Course by Jon Orwant. It is basic and
has many exercises. Learning Perl is aimed at people who already know C,
Python, etc. I also suggest that you try C How to Program or C++ How to
Program by Deitel and Deitel. They are college-type texts and have many
exercises. One cannot learn a computer language well without working with the
language--in this case: completing many exercises and altering and
experimenting with them. Knowledge of C should be a prerequisite to learning
Perl. Only then would Learning Perl or MacPerl: Power and Ease be useful.
Bob Gwynne, Ph.D.
Speech Communication
University of Tennessee, Knoxville
gwynne@utkux.utk.edu
How 'bout them Vols?
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
------------------------------
Date: Sat, 12 Dec 1998 20:16:02 +0900
From: terry577@aol.com (terry hinds)
Subject: Re: Change Directory
Message-Id: <terry577-1212982016030001@cs11j31.ppp.infoweb.ne.jp>
Rollo Chan Ka Chun <kcchan@csis.hku.hk> wrote:
".....what can I do???.....should
> I record the initial path of the working directory???...if Yes...how can I
> do that???...thanks for all of your help....thanks a lot....
>From the embedded POD in CWD.PM part of the standard dist.:
use Cwd;
$dir = cwd;
use Cwd;
$dir = getcwd;
use Cwd;
$dir = fastgetcwd;
use Cwd 'chdir';
chdir "/tmp";
print $ENV{'PWD'};
DESCRIPTION
The getcwd() function re-implements the getcwd(3) (or getwd(3)) functions
in Perl.
The fastcwd() function looks the same as getcwd(), but runs faster. It's
also more dangerous because you might conceivably chdir() out of a
directory that you can't chdir() back into.
The cwd() function looks the same as getcwd and fastgetcwd but is
implemented using the most natural and safe form for the current
architecture. For most systems it is identical to `pwd` (but without the
trailing line terminator). It is recommended that cwd (or another *cwd()
function) is used in all code to ensure portability.
If you ask to override your chdir() built-in function, then your PWD
environment variable will be kept up to date. (See Overriding Builtin
Functions in the perlsub manpage.) Note that it will only be kept up to
date if all packages which use chdir import it from Cwd.
------------------------------
Date: Sat, 12 Dec 1998 03:01:24 +0200
From: "Natalia" <nurdan@usa.net>
Subject: Event reminder script?
Message-Id: <74sfcg$ndc$1@medousa.forthnet.gr>
I'm looking for an event reminder script that I can use on my site to be =
able to send visitors emails at the dates they enter. Could you please =
help?
Thanks in advance,
Natalia
------------------------------
Date: Sat, 12 Dec 1998 15:04:43 +0300
From: Alexei Alexandrov <ava@softclub.net>
Subject: Functions in a template file.
Message-Id: <36725BDB.33C68A93@softclub.net>
Hello,
I have a question to ask:
For my CGI i use template files to parse them and insert variable
values.
The question is can i use in a template file perl functions like this:
<html>
bla-bla
<%
if ($i > 0) { print "Ok" } else { print "No" }
%>
</html>
and the the script would analyze my template file and interpret this
function.
Thanks for your help.
------------------------------
Date: Sat, 12 Dec 1998 01:28:36 GMT
From: ced@bcstec.ca.boeing.com (Charles DeRykus)
Subject: Re: ip to name lookup (reverse name lookup)
Message-Id: <F3tw3o.JnI@news.boeing.com>
In article <74r5vo$jim$1@news.megsinet.net>,
Al Degutis <adegutis@isi-info.com> wrote:
>Is it possible to do a reverse name lookup of an IP address using perl? I'd
>like to writing a firewall log analyzer and want to display the IP address
>and host.domain where available.
>
perldoc -f gethostbyaddr
e.g,
use Socket;
$hostname = gethostbyaddr(inet_aton($ip),AF_INET);
hth,
--
Charles DeRykus
------------------------------
Date: 11 Dec 1998 22:34:36 -0500
From: mjd@op.net (Mark-Jason Dominus)
Subject: Re: ls -l in perl?
Message-Id: <74so8c$3r5$1@monet.op.net>
In article <uiufi21vv.fsf@server3.symmetrycomm.com>,
Kin Cho <kin@symmetrycomm.com> wrote:
>Does someone has some handy code sniplets to emulate a "ls -l"
>listing purely in Perl?
Stat::lsMode will format the `mode' part in the way that `ls -l' does.
See http://www.plover.com/~mjd/perl/lsMode/.
The rest of it is pretty simple.
------------------------------
Date: Fri, 11 Dec 1998 17:46:33 -0800
From: Chris Hobbs <chobbs@silvervalley.k12.ca.us>
Subject: LWP problem/question
Message-Id: <3671CAF9.ADCD4337@silvervalley.k12.ca.us>
[ Apologies if this shows up twice - my first post from work didn't
appear to make it ]
[ previously posted to perl-win32-www and libwww-perl lists ]
Hello Everyone!
I'm writing a little script for our purchasing department (and
myself,
of course) to find the best pricing on books from the big three
online
vendors, Amazon, Borders, and Barnes and Noble.
The script takes an ISBN and hits each vendor's site for that book,
parses out the pricing info, and sends it back to the user's
browser.
I've used a script that Randall Schwartz has on his website for
pulling
Dilbert strips from unitedmedia.com as a model.
It works splendidly with Amazon and Borders; however, I'm having
problems with B&N. In order to discover whether the problem was with
my
RegEx or not, I modified the code so that it looks like the
following
(lots removed for clarity...)
1: use strict;
2: use LWP::Simple qw/get/;
3: use CGI qw/:form :html param header/;
4:
5: my $b_and_n_top =
"http://shop.barnesandnoble.com/bookSearch/isbnInquiry.asp?isbn=";
6: my $isbn = param("isbn");
7:
8: my $b_and_n_page = get ($b_and_n_top . $isbn);
9: print p("B & N Page should begin here...");
10: print $b_and_n_page; # TEST TO MAKE SURE PAGE IS RETRIEVED!
11: print p("...and it should stop here!");
The problem is that line 10 prints only half the time
(approximately...), and thus I can't parse the price. However,
whenever
I click the link I create, it works perfectly. You may try the
script at
http://www.silvervalley.k12.ca.us/autopilot/books.pl?isbn=1565922433
The complete listing is at:
http://www.silvervalley.k12.ca.us/autopilot/books.pl.txt
I know it's sort of ugly (I'm new, OK? :-), but I am impressed that
it
works so well for what I've learned so far. If I can just figure out
why
I can't load in that B & N page, it'll be wonderful.
Thanks for your help,
Chris Hobbs
------------------------------
Date: Fri, 11 Dec 1998 20:48:45 -0500
From: "E. Preble" <preble@ipass.net>
Subject: Re: mail attachment
Message-Id: <Q%jc2.982$kx1.1441@news.ipass.net>
Michael Renshaw wrote in message
<366FFEFD.AE7@lndn.tensor.pgs.com>...
does anyone know how to send a file as an attachment in perl.
<-snip->
I've made a PERL file attaching script publically available at:
http://www.datatrendsoftware.com/automail_lite.html
It uses MIME::ENTITY to send attachments (binary or otherwise)
from Formmail (Matt Wrights script) inputs.
If you disect that code, you can see how it works quite easily.
E. Preble
------------------------------
Date: Fri, 11 Dec 1998 20:58:19 -0500
From: "E. Preble" <preble@ipass.net>
Subject: Re: mail Attachments in Perl
Message-Id: <V5kc2.984$kx1.1446@news.ipass.net>
I have a script called Automail Lite, written in PERL that can do
binary attachments. See:
http://www.datatrendsoftware.com/automail_lite.html
for more details.
------------------------------
Murali wrote in message <367157DE.D55229A6@hotmail.com>...
Hi,
Is there a way to send mail attachments in Perl...when sending
mail..I
tried using Send.pm..it doesn't seem to supprt attachments...any
ideas
...?????
Thanks in advance..
Murali
email: mmbaddela@hotmail.com
------------------------------
Date: 11 Dec 1998 19:44:45 -0000
From: Jonathan Stowe <gellyfish@btinternet.com>
Subject: Re: Making O'Reilly phone script do html
Message-Id: <74rsnd$av$1@gellyfish.btinternet.com>
In comp.lang.perl.misc Damon K. Haley <dhaley@infobeat.com> wrote:
> Hello,
>
> I've been using the phone script I got from the
> O'Reilly Unix Power tools book. It works nicely
> as a command-line address book. I have attatched it
> for those who have not seen it.
>
> Does anyone have a script that will convert its address
> files to html or have an example of something similar preferably
> using perl or sh? This is the current phone system I use, but
> it there is one that works better with the web (prebuilt)
> please let me know.
>
> Thanks in advance
>
> Damon Haley
>
> #!/bin/sh
> #
> # phone, address - look a phone or address in a file.
> # LINK BOTH THE phone AND address SCRIPTS TOGETHER; BOTH USE THIS FILE!
>
> myname="`basename $0`" # NAME OF THIS SCRIPT (USUALLY address OR phone)
> case "$myname" in
> phone|address)
> sysfile=~dhaley/contacts/system/phone # SYSTEM FILE
> persfile=${HOME?}/contacts/personal/phone # PERSONAL FILE
> ;;
> *) echo "$0: HELP! I don't know how to run myself." 1>&2; exit 1 ;;
> esac
>
> if test ! -f $persfile
> then touch $persfile
> fi
>
> case $# in
> 0) echo "Usage: $myname searchfor [...searchfor]
> (You didn't tell me what you want to search for.)" 1>&2
> exit 1
> ;;
> *) # BUILD egrep EXPRESSION LIKE (arg1|arg2|...) FROM NAME(S) USER TYPES:
> for arg
> do
> case "$expr" in
> "") expr="($arg" ;;
> *) expr="$expr|$arg" ;;
> esac
> done
> expr="$expr)"
> esac
>
> # SEARCH WITH egrep, USE sed TO ADD sys> TO START OF FILENAMES FROM
> # SYSTEM FILE AND pers> TO START OF FILENAMES FROM HOME LIST:
> egrep -i "$expr" $persfile $sysfile |
> sed -e "s@^$sysfile:@sys>@" -e "s@^$persfile:@pers>@"
> exit
>
Except of course that isnt a Perl program.
You could make this into a CGI program directly if you want by inserting
the appropriate 'echo' statements ...
I did post a similar script in Perl just the other day if you search DejaNews
for a thread entitled "Easily searchable database format" you will find the
script. This is markedly not CGI however (I deliberately removed that) but
I'm sure asking some questions of the appropriate resource (and this is not
the place to ask about CGI) will probably help.
/J\
--
Jonathan Stowe <jns@btinternet.com>
Some of your questions answered:
<URL:http://www.btinternet.com/~gellyfish/resources/wwwfaq.htm>
Hastings: <URL:http://www.newhoo.com/Regional/UK/England/East_Sussex/Hastings>
------------------------------
Date: Sat, 12 Dec 1998 08:53:09 GMT
From: bart.lateur@skynet.be (Bart Lateur)
Subject: no UnderScore (was: Re: usage of $_ within nested loops)
Message-Id: <36772ebb.3723805@news.skynet.be>
[posted and mailed]
There was a follow-up post by Tom Christiansen to my post. I got a cc in
my mail. I waited several days for it to show up in the newsgroup, but
it didn't appear. I've just checked DejaNews, and it hasn't appeared
there either. Therefore, I'm quoting more than I ordinarily would have
done, because you people probably missed the original. I think it was
quite interesting.
On Wed, 9 Dec 1998 06:22:37 -0700, Tom Christiansen wrote:
>Perhaps you don't understand what the no underscore thingie
>is about. All it really does is forbid access to the global version.
>Local()ized ones are fine. Check it out.
That would be nice. You're right about that: previous posts in clp.misc
suggested that it forbids each and every use of $_.
I can imagine a few more difficult test cases, let's see if it works...
>For example, here's an example test suite that shows
>what is and is not permitted. The why should be self-evident.
> #!/usr/bin/perl
>
> no UnderScore;
>
> @tests = (
> "Assignment" => sub { $_ = "Bad" },
> "Reading" => sub { print },
> "Matching" => sub { $x = /badness/ },
> "Chop" => sub { chop },
> "Filetest" => sub { -x },
> "Nesting" => sub { for (1..3) { print } },
# These are mine:
"Localized" => sub { local($_) = 'ok?'; print },
"Once more" => sub { local($_) = 'ok?'; print },
"Nested while"=> sub { my(@ary) = ('outer');
for (@ary) { while(<DATA>) { print; last; } }
print @ary },
> );
>
> while ( ($name, $code) = splice(@tests, 0, 2) ) {
> print "Testing $name: ";
> eval { &$code };
> print $@ ? "detected" : "missed!";
> print "\n";
> }
# this is mine, too:
__DATA__
testing 1,2
>And here is the Underscore.pm module itself:
>
> package UnderScore;
>
> use Carp;
>
> sub TIESCALAR {
> my $class = shift;
> my $dummy;
> return bless \$dummy => $class;
> }
>
> sub FETCH { croak "Read access to \$_ forbidden" }
> sub STORE { croak "Write access to \$_ forbidden" }
>
> sub unimport { tie($_, __PACKAGE__) }
> sub import { untie $_ }
>
> tie($_, __PACKAGE__) unless tied $_;
>
> 1;
Something is fishy. These are the results:
Testing Assignment: detected
Testing Reading: detected
Testing Matching: detected
Testing Chop: detected
Testing Filetest: detected
Testing Nesting: 123missed!
Testing Localized: detected
Testing Once more: ok?missed!
Testing Nested while: testing 1,2
testing 1,2
missed!
First: "Nested while" is missed. This is a case that is relevant to the
original subject of the thread.
>In comp.lang.perl.misc,
> Randal Schwartz <merlyn@stonehenge.com> writes:
>:foreach does (if that's the variable you're using to walk through the
>:list). grep does. map does. The others use the outer $_.
>
>:Yup. $_ got clobbered.
>
>That's what "no underscore" is for.
Well, it doesn't seem to be working.
Second: for "Localized" and "Once more" (same sub!) I get different
results. That is disturbing.
Here it is a gain, in a script of it's own:
#! perl
no UnderScore;
{
local($_) = "Hello, world!\n";
}
Result:
Read access to $_ forbidden at underscore.t2 line 5
Hmm... localizing $_ appears to fail.
Bart.
------------------------------
Date: Sat, 12 Dec 1998 04:10:37 GMT
From: bdavis@mediaphex.com
Subject: OLE referencing problem: PerlScript, ASP and CDONTS.NewMail object
Message-Id: <74sqbt$uqv$1@nnrp1.dejanews.com>
I'm trying to use the CDONTS.NewMail object from the SMTP server component of
IIS 4 from a PerlScript driven ASP page. I've gotten the basic functionality
of the object mapped over to PerlScript. I can set the standard headers and
send the mail message. I have not however been able to set arbitrary headers.
A method named Value is used to set arbitrary message headers. Its VBScript
syntax is:
<object ref>.Value(header) = strHdrValue.
I have tried every syntax I can think of under PerlScript to access this to no
avail.
Here is the OLEViewer output for the method in question:
[id(00000000), propput, helpstring("Arbitrary mail header value")]
void Value(
BSTR bstrHeader,
[in] BSTR rhs);
The signature for this method doesn't match any other that I have seen. The
strange thing about this to me is the lack of an [in] specifier on the
bstrHeader value. This is the part in parens in the VBScript call.
Any help would be appreciated.
Bryan Davis
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
------------------------------
Date: 12 Dec 1998 02:14:24 GMT
From: nospam@hairball.cup.hp.com (Richard J. Rauenzahn)
Subject: Re: rounding numbers
Message-Id: <913428856.467354@hpvablab.cup.hp.com>
Jeff Hill <jhill@shamrockmedia.com> writes:
>Here is my dilemna;
>
>This algorithm is supposed to convert seconds into Minutes, Seconds.
> here is what I have so far.
[perl script that converts the time to fractional number of minutes,
splits at the decimal point, and attempts to convert the fractional
minute back into a integer, representing seconds.]
I suspect your problem is that you aren't aware of the % (or modulus)
operator available in most languages. Read up on it in the perlop man
page.
>differ from %s or %d) but I am guessing they are the answer. I can't
>find anything useful in the Camel Book. Help please.
That's because you're thinking about the problem the wrong way -- you're
stuck in a floating point mindset.
Rich
--
Rich Rauenzahn ----------+xrrauenza@cup.hp.comx+ Hewlett-Packard Company
Technical Consultant | I speak for me, | 19055 Pruneridge Ave.
Development Alliances Lab| *not* HP | MS 46TU2
IASD / Enterprise Systems Group +--------------+---- Cupertino, CA 95014
------------------------------
Date: Fri, 11 Dec 1998 21:38:41 -0500
From: alecler@cam.org (Andre L.)
Subject: Re: rounding numbers
Message-Id: <alecler-1112982138410001@dialup-436.hip.cam.org>
In article <3671ACEF.159B7FE2@shamrockmedia.com>, Jeff Hill
<jhill@shamrockmedia.com> wrote:
> Here is my dilemna;
>
> This algorithm is supposed to convert seconds into Minutes, Seconds.
> here is what I have so far.
>
> #!/usr/bin/perl -w
>
> $total_seconds = 125; #obviously its 2:05
> $raw = $total_seconds / 60;
> ($min,$sec) = split(/\./, $raw); #splits the left side of the decimal
> into minutes, but the
> $sec = $sec * .60; #right side gets a "percentage of
> a minute". Multiply that
> #by .60 and you get the
> number of seconds.
>
> print "$min:$sec";
>
> The problem lies in the fact that I need it to print "2:05", instead of
> 2:4999999999999.8
> I can't seem to find any info on "sprintf" or "printf", (How does %i
> differ from %s or %d) but I am guessing they are the answer. I can't
> find anything useful in the Camel Book. Help please.
Maybe this will help:
$secs = 125;
$timestring = sprintf "%d:%02d", $secs/60, $secs%60;
# '2:05'
You want "h:mm:ss" ?
$secs = 3725;
$timestring = sprintf "%d:%02d:%02d",
$secs/3600, $secs%3600/60, $secs%60;
# '1:02:05'
%d : an integer, any length
%02d : an integer, zero-padded to 2 positions
(See sprintf in perlfunc.)
Also take a look at int() in perfunc. You will like it. :-)
HTH,
Andre
------------------------------
Date: Fri, 11 Dec 1998 21:39:07 -0600
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: rounding numbers
Message-Id: <rgos47.dd9.ln@magna.metronet.com>
Jeff Hill (jhill@shamrockmedia.com) wrote:
: The problem lies in the fact that I need it to print "2:05", instead of
: 2:4999999999999.8
: I can't seem to find any info on "sprintf" or "printf", (How does %i
: differ from %s or %d) but I am guessing they are the answer. I can't
: find anything useful in the Camel Book. Help please.
There is info in the newer 'perlfunc' man page.
Here's mine from 5.00502
----------------------------------
=item sprintf FORMAT, LIST
Returns a string formatted by the usual C<printf()> conventions of the
C library function C<sprintf()>. See L<sprintf(3)> or L<printf(3)>
on your system for an explanation of the general principles.
Perl does its own C<sprintf()> formatting -- it emulates the C
function C<sprintf()>, but it doesn't use it (except for floating-point
numbers, and even then only the standard modifiers are allowed). As a
result, any non-standard extensions in your local C<sprintf()> are not
available from Perl.
Perl's C<sprintf()> permits the following universally-known conversions:
%% a percent sign
%c a character with the given number
%s a string
%d a signed integer, in decimal
%u an unsigned integer, in decimal
%o an unsigned integer, in octal
%x an unsigned integer, in hexadecimal
%e a floating-point number, in scientific notation
%f a floating-point number, in fixed decimal notation
%g a floating-point number, in %e or %f notation
In addition, Perl permits the following widely-supported conversions:
%X like %x, but using upper-case letters
%E like %e, but using an upper-case "E"
%G like %g, but with an upper-case "E" (if applicable)
%p a pointer (outputs the Perl value's address in hexadecimal)
%n special: *stores* the number of characters output so far
into the next variable in the parameter list
Finally, for backward (and we do mean "backward") compatibility, Perl
permits these unnecessary but widely-supported conversions:
%i a synonym for %d
%D a synonym for %ld
%U a synonym for %lu
%O a synonym for %lo
%F a synonym for %f
Perl permits the following universally-known flags between the C<%>
and the conversion letter:
space prefix positive number with a space
+ prefix positive number with a plus sign
- left-justify within the field
0 use zeros, not spaces, to right-justify
# prefix non-zero octal with "0", non-zero hex with "0x"
number minimum field width
.number "precision": digits after decimal point for
floating-point, max length for string, minimum length
for integer
l interpret integer as C type "long" or "unsigned long"
h interpret integer as C type "short" or "unsigned short"
There is also one Perl-specific flag:
V interpret integer as Perl's standard integer type
Where a number would appear in the flags, an asterisk ("C<*>") may be
used instead, in which case Perl uses the next item in the parameter
list as the given number (that is, as the field width or precision).
If a field width obtained through "C<*>" is negative, it has the same
effect as the "C<->" flag: left-justification.
If C<use locale> is in effect, the character used for the decimal
point in formatted real numbers is affected by the LC_NUMERIC locale.
See L<perllocale>.
--
Tad McClellan SGML Consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Fri, 11 Dec 1998 20:55:35 -0500
From: "E. Preble" <preble@ipass.net>
Subject: Re: Sending file attachments in email
Message-Id: <_3kc2.983$kx1.1452@news.ipass.net>
David Capredoni wrote in message
<36713E02.FEA8552A@nabu.isg.mot.com>...
Hi
I was just wondering if anyone knows how to send a word document
attachment in an email. I can send text document. However, when
I try
to send a word document as an attachment, a zero size file is sent
through the mail.
--------------------
I've written a script called Automail_Lite that is free to the
public. It attaches any file (binaries included) to an email. It
requires MIME::ENTITY which is available on most systems as part
of the MIME modules. It also requires sendmail.
Although this script is designed to work using formmail, you could
check it out to see -how- it works.
See:
http://www.datatrendsoftware.com/automail_lite.html
E. Preble
Datatrend Software
------------------------------
Date: Wed, 9 Dec 1998 15:26:59 -0800
From: "Shang Ko" <kos@tdd.hbo.nec.com>
Subject: socket question: to wait or not to wait
Message-Id: <74n19o$3e51@jpgate.inoc.sj.nec.com>
We are trying to have two processes talking to each other. It seems that
socket is the choice that first come to our mind. However, we couldn't
figure out how the client process can check, without pending for input, if
there is anything in the input socket. If there is something in the socket,
the client process reads it. If not, the client process continues its
execution.
Of course, we don't have to use socket. What I am looking for is the the
ability of receiving a semaphore or message with a user-specified timeout
(including "no wait").
Our current platform is NT. In the future, we would like to have the same
program also running on Solaris. We use ActivePerl.
Any suggestion? Thanks in advance.
Shang Ko
Eluminant Technologies
------------------------------
Date: Sat, 12 Dec 1998 08:55:47 GMT
From: bart.lateur@skynet.be (Bart Lateur)
Subject: Re: Splitting a string at a certain point
Message-Id: <36782f6b.3899400@news.skynet.be>
Craig Berry wrote:
> @pieces = $longstring =~ /.{1,20}/g;
I think you forgot the parentheses.
@pieces = $longstring =~ /(.{1,20})/g;
Bart.
------------------------------
Date: 11 Dec 1998 20:14:38 -0500
From: mjd@op.net (Mark-Jason Dominus)
Subject: Re: typeglob (*) VS (\%) direct pass-by-ref
Message-Id: <74sg1u$qbb$1@monet.op.net>
In article <74s90s$767$1@nntp.smartdna.com>,
Chris Reickenbacker <chrisre@ecpi.com> wrote:
>But that aint why the glob is losing scope. Any ideas ?
When you pass an argument to a function, the function has to receive
the arguments, and the two have to match. You showed us the code that
passes, but not the code that receives.
That makes it difficult to explain why the arguments are not being
properly received.
------------------------------
Date: Sat, 12 Dec 1998 20:09:30 +0900
From: terry577@aol.com (terry hinds)
Subject: Re: Writing to filehandles and STDOUT
Message-Id: <terry577-1212982009300001@cs11j31.ppp.infoweb.ne.jp>
In article <74qpbm$6rs$1@nnrp1.dejanews.com>, charlie66@my-dejanews.com wrote:
> I had a Perl problem yesterday which I have resolved, but I am still not sure
> how it works exactly.
> print <<End_of_HTML;
> Content-type: text/html
insert blank line here*
> <HTML><HEAD><TITLE>Bla Bla</TITLE></HEAD>
> ...
> End_of_HTML
>
> I got the same problem even if I added STDOUT after that last "print". Any
> clues?
>
------------------------------
Date: Fri, 11 Dec 1998 17:08:57 -0800
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Y2K potential problem in localtime()
Message-Id: <MPG.10db6205ae0856189898c0@nntp.hpl.hp.com>
In article <MPG.10db159874fd66699898be@nntp.hpl.hp.com> on Fri, 11 Dec
1998 11:42:50 -0800, Larry Rosler <lr@hpl.hp.com> says...
> ... This discussion reveals a gratuitous difference
> in semantics between C and Perl.
...
> "If the quotient a/b is representable, the
> expression (a/b)*b + a%b shall equal a.
...
> ... the result of int(-1/100) is 0, and the result of -1%100 is 99,
> so the equation is not satisfied.
In the 5.005_02 documentation, this behavior is explicit, and the use of
'use integer;' is presented as the way to get C-conforming behavior.
> This anomaly is not documented in the "C Traps" section of perltrap. I
> am filing a bug report.
The C portability trap exists and should be documented. I have
submitted the bug report (my very first, BTW).
--
(Just Another Larry) Rosler
Hewlett-Packard Company
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: 12 Dec 98 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Special: Digest Administrivia (Last modified: 12 Dec 98)
Message-Id: <null>
Administrivia:
Well, after 6 months, here's the answer to the quiz: what do we do about
comp.lang.perl.moderated. Answer: nothing.
]From: Russ Allbery <rra@stanford.edu>
]Date: 21 Sep 1998 19:53:43 -0700
]Subject: comp.lang.perl.moderated available via e-mail
]
]It is possible to subscribe to comp.lang.perl.moderated as a mailing list.
]To do so, send mail to majordomo@eyrie.org with "subscribe clpm" in the
]body. Majordomo will then send you instructions on how to confirm your
]subscription. This is provided as a general service for those people who
]cannot receive the newsgroup for whatever reason or who just prefer to
]receive messages via e-mail.
The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc. For subscription or unsubscription requests, send
the single line:
subscribe perl-users
or:
unsubscribe perl-users
to almanac@ruby.oce.orst.edu.
To submit articles to comp.lang.perl.misc (and this Digest), send your
article to perl-users@ruby.oce.orst.edu.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.
The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq". The real FAQ, as it
appeared last in the newsgroup, can be retrieved with the request "send
perl-users FAQ". Due to their sizes, neither the Meta-FAQ nor the FAQ
are included in the digest.
The "mini-FAQ", which is an updated version of the Meta-FAQ, is
available by requesting "send perl-users mini-faq". It appears twice
weekly in the group, but is not distributed in the digest.
For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V8 Issue 4408
**************************************