[17132] in Perl-Users-Digest
Perl-Users Digest, Issue: 4544 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Oct 6 21:10:39 2000
Date: Fri, 6 Oct 2000 18:10:10 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <970881010-v9-i4544@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Fri, 6 Oct 2000 Volume: 9 Number: 4544
Today's topics:
Re: passing parameter to subroutine <matt.stoker@motorola.com>
Re: Perl vs Pegasus Mail (strange things happens) (Martien Verbruggen)
PP, 3rd ed.??? <kj0@mailcity.com>
Re: reading in file as uneven multi-dimensional array <bmb@ginger.libs.uga.edu>
Re: Rounding Integers <matt.stoker@motorola.com>
Script sends mail, only get header!! <dean_j_pompilio@yahoo.com>
Re: Search an array <anmcguire@my-deja.com>
Re: Splitting data <lincmad001@telecom-digest.zzn.com>
Re: Testing for numeric integer <gdaniell@wt.com.au>
Re: Variable names enclosed within curly braces <bart.lateur@skynet.be>
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Fri, 06 Oct 2000 16:32:22 -0700
From: Matthew Stoker <matt.stoker@motorola.com>
Subject: Re: passing parameter to subroutine
Message-Id: <39DE6106.5C77566A@motorola.com>
Kris Gonzalez wrote:
>
> Can anyone tell me why the following code will not print the value of
> the parameter passed to the subroutine "make_page"?
>
> -----------BEGIN-INSERTED-CODE-------------
>
> &make_page(3);
> exit(0);
>
> sub make_page {
>
> print <<EOF;
>
> <html><head></head>
> <body>
> <input type=text value=$_>
> </body
> </html>
>
> -------------END-INSERTED-CODE--------------
>
You mean $_[0] instead of $_, since the values are passed using @_. This
worked in the code I tested.
> I've tried this as well as the following:
>
> -----------BEGIN-INSERTED-CODE-------------
>
> &make_page(3);
> exit(0);
>
> sub make_page {
>
> $param = shift;
>
> print <<EOF;
>
> <html><head></head>
> <body>
> <input type=text value=$param>
> </body>
> </html>
>
> -------------END-INSERTED-CODE--------------
>
I don't know why this didn't work for you. I tried what I believe to be
the exact same code (I just added the EOF and } and
#!/usr/local/bin/perl at the start) and it worked for me.
--
/------------------------------------------------------------------\
| Matt Stoker | email: matt.stoker@motorola.com |
| Unit Process Modeling | Mail Drop: M360 |
| DigitalDNA(TM) Laboratories| Phone: (480)655-3301 |
| Motorola, SPS | Fax: (480)655-5013 |
| 2200 W Broadway Road | Pager: (888)699-8803 |
| Mesa, AZ 85202 | |
\------------------------------------------------------------------/
------------------------------
Date: Sat, 7 Oct 2000 10:28:25 +1100
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: Perl vs Pegasus Mail (strange things happens)
Message-Id: <slrn8tso0p.jr6.mgjv@martien.heliotrope.home>
On Fri, 06 Oct 2000 10:33:30 +0200, Christian Rüggeberg
<news@sinus-medien.de> wrote:
> Hi,
>
> my Script sends a Mail with an Attachment. If i only send this mail
> with an uuencoded File (without any header information) Pegasus
> recieves a correct Mail with a correct (readable) Attachment. Other
> Mail-Progs don´t rcognize the Attachment because there is no true
> header in this mail. If I send a correct mail with header and base64
> encoded attachment all the other mail-progs like netscape, outlook, or
> also webmail-progs like gmx recognize the mail correct, the
> attachement is readable. Pegasus also recieves a correct Mail (...it
> looks so) BUT the attachment is not readable. I compared my
> Script-output with the orig. header inside a correct (from Pegasus)
> sent message, but i don't find any difference....
In your article, you don't present any code. You do not even mention
whether you use Perl modules to create and send this email, or whether
you cooked up something yourself. You don't present any example
input/output. How the fsck are we supposed to give you any sensible
advice?
Besides that, the above story is hardly a clear description of the
problem, is it? Read it again.
Anyway, just in the hope that not all of this is wasted:
If you cooked up something yourself, then consider switching to the use
of one of the modules available from CPAN. They're more likely to have
it right than you.
If you don't want to switch, but want to keep doing things yourself,
then don't come here to discuss the format of email messages. Do that
somewhere else. It has nothing to do with Perl.
If you use a module, and the problem persists, and you really believe
this to be a bug in the module, and not in the mail programs,
then contact the module's author. Otherwise contact the authors of the
mail programs you think are flawed.
But please, if you post here again, make sure you want to talk about
Perl, ok? Oh, BTW, for discussions about modules the group
comp.lang.perl.modules was created, in case you come back asking which
module to use. Look on CPAN: http://www.cpan.org/. Or
http://search.cpan.org/. Lots of modules with mail and mime in their
name.
Martien
--
Martien Verbruggen |
Interactive Media Division |
Commercial Dynamics Pty. Ltd. | Curiouser and curiouser, said Alice.
NSW, Australia |
------------------------------
Date: 6 Oct 2000 20:38:43 -0400
From: kj0 <kj0@mailcity.com>
Subject: PP, 3rd ed.???
Message-Id: <8rlraj$iee$1@panix3.panix.com>
I read the 1st and 2nd editions of "Programming Perl" pretty much
cover-to-cover when they came out. Therefore, I would like to read
only those parts of the new 3rd edition that are substantially new
relative to the first two editions. What would those be?
Thank you,
KJ
------------------------------
Date: Fri, 6 Oct 2000 20:41:48 -0400
From: Brad Baxter <bmb@ginger.libs.uga.edu>
Subject: Re: reading in file as uneven multi-dimensional array
Message-Id: <Pine.A41.4.21.0010062034090.16526-100000@ginger.libs.uga.edu>
On 6 Oct 2000, Logan Shaw wrote:
>
> Oh, and I forgot to mention an even simpler (or at least shorter) way:
>
> @file = map ([ split ], <>);
>
> Note, however, that this only works because I used split() in a way
> that makes it not matter that I didn't chomp the newline.
Why am I only just now consciously realizing that split(' ') loses
newlines? I know I've relied on this behavior for years, but I found
myself saying, "No, the last word on each line will have a newline," to
Logan's comment above. YLSNED.
Brad
------------------------------
Date: Fri, 06 Oct 2000 16:53:14 -0700
From: Matthew Stoker <matt.stoker@motorola.com>
Subject: Re: Rounding Integers
Message-Id: <39DE65EA.F6C575A3@motorola.com>
vivi16@my-deja.com wrote:
>
> Can you use sprintf(); to round integers? I want to round something
> like 4568 to 4600. I suppose if I knew a number was always going to be
> in the thousands, I could divide by 100, use the CEIL function and then
> multiply by 100. But is there an easier way or built in command?
>
> Sent via Deja.com http://www.deja.com/
> Before you buy.
Yes, in some cases sprintf() can be used to round integers. But you
should be a little more specific about what you mean by rounding? Do you
want to always round to the hundreds place or do you just want 2
significant figures? Also, which specific rounding rules do you wish to
use? The following are some common rules:
1. Always round down. (i.e. 4568 -> 4500, 3850 -> 3800, 3750 -> 3700)
2. Round up if x=>0.5 else round down (i.e. 4568 -> 4600, 3850 -> 3900,
3750 -> 3800, 2448 -> 2400)
3. Round up if x>0.5, round down if x < 0.5 and round to even number if
x = 0.5 (i.e. 4568 -> 4600, 3850 -> 3800, 3750 -> 3800, 2448 -> 2400)
--
/------------------------------------------------------------------\
| Matt Stoker | email: matt.stoker@motorola.com |
| Unit Process Modeling | Mail Drop: M360 |
| DigitalDNA(TM) Laboratories| Phone: (480)655-3301 |
| Motorola, SPS | Fax: (480)655-5013 |
| 2200 W Broadway Road | Pager: (888)699-8803 |
| Mesa, AZ 85202 | |
\------------------------------------------------------------------/
------------------------------
Date: Fri, 06 Oct 2000 23:35:03 GMT
From: Dean J. Pompilio <dean_j_pompilio@yahoo.com>
Subject: Script sends mail, only get header!!
Message-Id: <8rlnj7$3na$1@nnrp1.deja.com>
I have a perl script which mails an output file to my account on
another Unix box. Here are the two commands I have tried:
`cat $outfile | mailx -s $outfile me\@unix.com`;
system("cat $outfile | mailx -s $outfile me\@unix.com");
Both commands give me the same problem. When I read my mail on
unix.com, I only get the header of the message... there is no body.
If I run the command from the shell, everything works just fine. Any
ideas Perl/Unix gurus????
-Dean
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Fri, 06 Oct 2000 22:07:57 GMT
From: Andrew N McGuire <anmcguire@my-deja.com>
Subject: Re: Search an array
Message-Id: <8rlifo$vhc$1@nnrp1.deja.com>
In article <MPG.144530654fd6bee498ae07@nntp.hpl.hp.com>,
Larry Rosler <lr@hpl.hp.com> wrote:
> In article <39DB36B7.FFD2DE53@texas.net> on Wed, 04 Oct 2000 13:55:03
> GMT, Tom Briles <sariq@texas.net> says...
> > "Andrew N. McGuire" wrote:
>
> ...
>
> > > if (grep /^foo$/ => @array) {
> > > print "we have foo!\n";
> > > }
>
> <SNIP> correction on efficiency from FAQ
>
> And the test should be equality:
>
> $_ eq 'foo'
>
> --
> (Just Another Larry) Rosler
> Hewlett-Packard Laboratories
> http://www.hpl.hp.com/personal/Larry_Rosler/
> lr@hpl.hp.com
>
You are both absolutely correct, thank you for your follow-ups,
and sorry for contradicting the FAQ. I know better than that,
but for some reason 'grep' just popped into my head.
[ aside: I had to follow up via deja-news becuase my news server
is awful. I did not even see your follow-ups until now. :-( ]
anm
--
$ENV{PAGER} = 'perl -wpe0';
system perldoc => '-t', '-F', $0;
=head1 Just Another Perl Hacker
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Fri, 06 Oct 2000 17:38:38 -0700
From: Linc Madison <lincmad001@telecom-digest.zzn.com>
Subject: Re: Splitting data
Message-Id: <061020001738382907%lincmad001@telecom-digest.zzn.com>
In article <slrn8trhtp.f8v.bernard.el-hagin@gdndev25.lido-tech>,
Bernard El-Hagin <bernard.el-hagin@lido-tech.net> wrote:
> On Fri, 06 Oct 2000 12:06:15 GMT, vivekvp <vivekvp@spliced.com> wrote:
> > Hello,
> >
> >I have a list of delimited data like this:
> >
> >BILL|$10000|555-5555|4|HOUSE|NEW YORK
> >CHRIS|$4000|666-6666|7|APT|BOSTON
> >LIU|$120000|777-7777|12|MANSION|SHANGHAI|CHINA
> >etx.
> >
> >I want to search through the list for people in New York. If they are
> >found - print the value the phone number and rent.
> >
> >How do I just extract the phone number and rent. Right now - I do a
> >split like this ($a,$b,$c,$d,$e,$f,$g)=split(/|/,$line). But what if I
> >had 200 fields?
>
> As I understand it the first four fields in each line are always
> name|value|number|rent and the last is the city. Since you're not interested
> in everything that's in between you can try:
>
> (split '|', $line)[-1] to get the city name,
> (split '|', $line)[0] to get the first name,
> (split '|', $line)[1] to get the value,
> (split '|', $line)[2] to get the phone number, and, last but not least,
> (split '|', $line)[3] to get the rent.
>
> This way you don't have to worry about how many fields are in each line.
Close but not quite. As posted, there is an optional additional field
at the end for the country if it's not USA (extrapolating from what's
shown). However, the basic concept is correct.
Why are you bothered about assigning to variables you don't use? It
shouldn't be an issue, even with 200 fields. If it's cleaner, you can
index the split array directly, or, if you're using 14 of the 200
fields, you might do something like
@temp = split '|', $line;
$phone = $temp[2];
$city = $temp[5];
etc.
to avoid repeating the split operation unnecessarily.
------------------------------
Date: Sat, 07 Oct 2000 07:11:25 +0800
From: Graham Daniell <gdaniell@wt.com.au>
Subject: Re: Testing for numeric integer
Message-Id: <39DE5C1D.CD5DAF43@wt.com.au>
My thanks to all who have replied to my original query for the wonderful
variety of approaches to this problem. It proves that there is indeed
more than one way to skin a cat (apologies to all cat lovers). I now
just need to decide which to use :-)
Regards,
Graham Daniell
---------------------------------------------------------------
Graham Daniell wrote:
>
> Can anyone tell me how I test that a field contains ONLY a number,
> without any decimal point in it? ie: a number like 1 or 2 or 199? Or
> where to look to find the answer?
>
> It is for a web product ordering application and I want to ensure that
> the user has entered a valid number of products, so I can multiply by
> the unit price to get the total price.
>
> Any help appreciated,
> Graham Daniell
> Perth, Western Australia
> gdaniell@wt.com.au
------------------------------
Date: Fri, 06 Oct 2000 23:25:09 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Variable names enclosed within curly braces
Message-Id: <fanstsojbhjqtton0u4es19a28b1qp79lo@4ax.com>
evanharrington@my-deja.com wrote:
>I encountered problems with variable substitutions in perl and found
>that the one sure way of coping with the issue was to always refer to
>variable names between curly braces. So, wherever a variable name was
>used (whether a list, hash, or scalar) I would refer to it as follows:
>
> ${scalar}
> @{list}
> %{hash}
>
>This is because it seemed a clear way to avoid confusion about where
>the beginning of the name started and ended. But, then, lots of people
>became vocal about my divergence from "established perl style".
> $cmd = "ctmcontb -add $ctmFileName_FILE-OK $odat";
> $cmd = "ctmcontb -add ${ctmFileName}_FILE-OK $odat";
>or, to be more consistent:
>
> ${cmd} = "ctmcontb -add ${ctmFileName}_FILE-OK ${odat}";
My rule: use the curlies to separate the varaible's name from the rest
from the string, when there's no other way to separate them. Otherwise,
it's useless.
So, to me, the "more consistent" is silly. I'd go with version #2.
> while ( <${fh}> ) # WRONG!
> while ( <$fh> ) # GOOD!
>Do you know why the curly
>braces do not work within the angled brackets, when reading from a file
>handle? Must it be this way?
Hmmm... I don't care, really. But filehandles often must be bare
scalars. Hashes won't work:
print $fh @list; # good
print $fh{there} @list; # wrong
COuld this be similar?
print ${fh} @list;
...
No... this one works.
Your
while(<${fh}>) {
print
}
returns a GLOB. So there's a clash between the <$fh> and the <*.txt>
globbing syntax.
--
Bart.
------------------------------
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 V9 Issue 4544
**************************************