[16017] in Perl-Users-Digest
Perl-Users Digest, Issue: 3426 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Jun 20 11:20:28 2000
Date: Tue, 20 Jun 2000 00:05:13 -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: <961484712-v9-i3426@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Tue, 20 Jun 2000 Volume: 9 Number: 3426
Today's topics:
Re: [ Regexp ] Curious Behaviour of " last if /(match)/ <TheEx0rcist@fanclub.org>
Re: [ Regexp ] Curious Behaviour of " last if /(match)/ <TheEx0rcist@fanclub.org>
Re: [ Regexp ] Curious Behaviour of " last if /(match)/ (Steven Smolinski)
Re: [ Regexp ] Curious Behaviour of " last if /(match)/ <tina@streetmail.com>
Re: [ Regexp ] Curious Behaviour of " last if /(match)/ (Tad McClellan)
Re: [ Regexp ] Curious Behaviour of " last if /(match)/ (Tad McClellan)
Re: Crazy enough that it might just work... <altavistaNOalSPAM@agentkhaki.com.invalid>
Getting current working directory in perl script <glchyNOglSPAM@cc21.com.sg.invalid>
Re: Getting current working directory in perl script (Clinton A. Pierce)
Re: Getting current working directory in perl script (Steven Smolinski)
Re: help creating directories with perl (Brandon Metcalf)
Re: logs of BigFloats, binomial density function, large (Paul Rubin)
Re: Messagebox in Win32 <rob13@rock13.com>
Perl DBI Oracle? <taylorr@greendot.net>
Re: Perl DBI Oracle? (Eric Bohlman)
Programming with Perl -melting dowin name, icq into a t <tamtc@hotmail.com>
Reg Expression Question tony_123@my-deja.com
Re: Reg Expression Question (Tad McClellan)
Re: Reg Expression Question <philipg@atl.mediaone.net>
Re: Returning a hash from XS <cching@mqsoftware.com>
simplest e-mail script in the world wanted <info@sansom.net>
Re: Sorting a ':' delimeted file by a field value/surna <jimmy.lantz@ostas.lu.se>
Viewing Multipart/Mixed messages <rvadlapa@cisco.com>
Re: What the... <altavistaNOalSPAM@agentkhaki.com.invalid>
Re: What the... <altavistaNOalSPAM@agentkhaki.com.invalid>
Re: What the... <altavistaNOalSPAM@agentkhaki.com.invalid>
Re: What the... <nnickee@nnickee.com>
Re: What's the difference between a hash and an array? (David Bell)
Re: What's the difference between a hash and an array? (Eric Bohlman)
Where to get CPAN CD? (Paul Rubin)
Re: Where to get CPAN CD? (Eric Bohlman)
Re: Where to get CPAN CD? (Paul Rubin)
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Tue, 20 Jun 2000 03:16:26 +0200
From: "TheEx0rcist" <TheEx0rcist@fanclub.org>
Subject: Re: [ Regexp ] Curious Behaviour of " last if /(match)/ "
Message-Id: <8imgma$2pmr$1@news5.isdnet.net>
> The code below prints "bar". With your suggested global $1,
> it would print "foo":
>
> ---------------------------
> #!/usr/bin/perl -w
> use strict;
>
> $_ = "foo bar baz\n";
>
> if ( /(bar)/ ) {
> my_sub($1);
> print "$1\n";
> }
>
>
> # insert a few thousand lines of code here
>
>
> sub my_sub {
> my($str) = @_;
>
> if ( $str =~ /(foo)/ )
> { return 1 }
> else
> { return 0 }
> }
> ---------------------------
hmmm I don't think so.
Be the variable $1 global or not, since /(bar)/ matches $_, the string $1 =
'bar' is sent to my_sub(). Then we have $str = 'bar'. /(foo)/ never matches
'bar' so the variable $1 is in no way altered. That's why in all case,
after the if() block, $1 will always equal 'bar'. What in the world would
make it equal 'foo' since the pattern /(foo)/ in your my_sub block never
matches anything !
------------------------------
Date: Tue, 20 Jun 2000 03:26:57 +0200
From: "TheEx0rcist" <TheEx0rcist@fanclub.org>
Subject: Re: [ Regexp ] Curious Behaviour of " last if /(match)/ "
Message-Id: <8imha2$6ap$1@news3.isdnet.net>
> Use my(). Don't use local().
The problem with my() is that you get warning messages with perl -w when you
use it inside loops ("my" variable masks earlier declaration in same scope).
For instance the following code produces the error message ::
--
my $a;
while(1) {
my $a = ...
}
--
Instead, Perl would prefer :
--
my $a;
while(1) {
local($a) = ...
};
--
> >so why should $<DIGIT> variables act otherwise? Why
> >should Perl assume "local($<DIGIT>)"? It nothing but obfuscating ...
>
>
> No, it _avoids_ obfuscations.
>
> Global variables can be changed "at a distance", which makes the
> place where they are being changed hard to find.
Well, that is your own opinion.
Personaly, I think that as long as $<digit> variables don't work as "normal"
variables, it is obfuscating
--
TheEx0rcist
------------------------------
Date: Tue, 20 Jun 2000 02:15:22 GMT
From: sjs@yorku.ca (Steven Smolinski)
Subject: Re: [ Regexp ] Curious Behaviour of " last if /(match)/ "
Message-Id: <slrn8ktkta.kon.sjs@john.sympatico.ca>
TheEx0rcist <TheEx0rcist@fanclub.org> wrote:
>> Use my(). Don't use local().
>The problem with my() is that you get warning messages with perl -w when you
>use it inside loops ("my" variable masks earlier declaration in same scope).
>For instance the following code produces the error message ::
>--
>my $a;
>while(1) {
> my $a = ...
>}
>--
Really? What's your perl version?
--------------8<------------------
% uname -sr
Linux 2.2.13-SMP
% perl -Mstrict -we 'my $bob=1; while($bob-- >0) {my $bob="hi\n"; print $bob}'
hi
% perl -v
This is perl, version 5.005_03 built for i586-linux
[...]
------------------------------
Date: 20 Jun 2000 02:48:35 GMT
From: Tina Mueller <tina@streetmail.com>
Subject: Re: [ Regexp ] Curious Behaviour of " last if /(match)/ "
Message-Id: <8imm23$54k6n$1@fu-berlin.de>
hi,
TheEx0rcist <TheEx0rcist@fanclub.org> wrote:
>> The code below prints "bar". With your suggested global $1,
>> it would print "foo":
>>
>> ---------------------------
>> #!/usr/bin/perl -w
>> use strict;
>>
>> $_ = "foo bar baz\n";
>>
>> if ( /(bar)/ ) {
>> my_sub($1);
maybe you wanted to write:
my_sub($_);
then it would print "foo" if there was something
like global $1.
>> print "$1\n";
>> }
> hmmm I don't think so.
> Be the variable $1 global or not, since /(bar)/ matches $_, the string $1 =
> 'bar' is sent to my_sub(). Then we have $str = 'bar'. /(foo)/ never matches
> 'bar' so the variable $1 is in no way altered. That's why in all case,
> after the if() block, $1 will always equal 'bar'. What in the world would
> make it equal 'foo' since the pattern /(foo)/ in your my_sub block never
> matches anything !
with the change of the line above you would agree, right?
tina
--
http://tinita.de \ enter__| |__the___ _ _ ___
tina's moviedatabase \ / _` / _ \/ _ \ '_(_-< of
search & add comments \ \ _,_\ __/\ __/_| /__/ perception
"The Software required Win98 or better, so I installed Linux."
------------------------------
Date: Mon, 19 Jun 2000 22:04:30 -0400
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: [ Regexp ] Curious Behaviour of " last if /(match)/ "
Message-Id: <slrn8ktk9e.e7e.tadmc@magna.metronet.com>
On Tue, 20 Jun 2000 03:16:26 +0200, TheEx0rcist <TheEx0rcist@fanclub.org> wrote:
>> The code below prints "bar". With your suggested global $1,
>> it would print "foo":
>>
>> ---------------------------
>> #!/usr/bin/perl -w
>> use strict;
>>
>> $_ = "foo bar baz\n";
>>
>> if ( /(bar)/ ) {
>> my_sub($1);
>> print "$1\n";
>> }
>>
>>
>> # insert a few thousand lines of code here
>>
>>
>> sub my_sub {
>> my($str) = @_;
>>
>> if ( $str =~ /(foo)/ )
>> { return 1 }
>> else
>> { return 0 }
>> }
>> ---------------------------
>
>hmmm I don't think so.
>Be the variable $1 global or not, since /(bar)/ matches $_, the string $1 =
>'bar' is sent to my_sub(). Then we have $str = 'bar'. /(foo)/ never matches
>'bar' so the variable $1 is in no way altered.
Duh, oh yeah.
Sorry.
>That's why in all case,
^^^
No, just in the broken case that I showed.
So let me show another case (2 cases actually).
if ( $str =~ /(a)/ )
So now $1 is NOT "bar", it is "a".
or
my_sub($_)
In which case, it works as I had originally described, i.e.
$1 equals "foo".
>after the if() block, $1 will always equal 'bar'.
^^^^^^
The point being that $1 was set in code far far away from where
the problem revealed itself (back up in the main procedure).
--
Tad McClellan SGML Consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Mon, 19 Jun 2000 22:38:49 -0400
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: [ Regexp ] Curious Behaviour of " last if /(match)/ "
Message-Id: <slrn8ktm9p.e7e.tadmc@magna.metronet.com>
On Tue, 20 Jun 2000 03:26:57 +0200, TheEx0rcist <TheEx0rcist@fanclub.org> wrote:
>> Use my(). Don't use local().
>
>The problem with my() is that you get warning messages with perl -w when you
>use it inside loops ("my" variable masks earlier declaration in same scope).
>
>For instance the following code produces the error message ::
^^^^^
That is a warning message, not an error message.
>--
>my $a;
>while(1) {
> my $a = ...
>}
>--
>
>Instead, Perl would prefer :
>--
>my $a;
>while(1) {
> local($a) = ...
>};
>--
No, instead Perl (and computer science in general) would prefer
either that the first $a goes out of scope before you get to
the second $a's scope, or that you choose a different name for
the second one because the name you chose is already being used
for something else.
Or you make a package, or some sort of scoping mechanism anyway.
In other words, you should properly control the scope (visibility)
of your variables.
The above is an example of _not_ controlling scope, so you
_should_ be warned that you are doing something that has
been proven to be a Bad Idea (use identically named variables
to mean different things at the same point in your program).
>> >so why should $<DIGIT> variables act otherwise?
Because global variables are bad.
>> >Why
>> >should Perl assume "local($<DIGIT>)"?
Because global variables are bad.
>> >It nothing but obfuscating ...
>>
>>
>> No, it _avoids_ obfuscations.
>>
>> Global variables can be changed "at a distance", which makes the
>> place where they are being changed hard to find.
>
>Well, that is your own opinion.
No, that is a standard Software Engineering principle.
Where have you heard that using global variables is "OK"?
--
Tad McClellan SGML Consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Mon, 19 Jun 2000 22:50:00 -0700
From: Agentkhaki <altavistaNOalSPAM@agentkhaki.com.invalid>
Subject: Re: Crazy enough that it might just work...
Message-Id: <0c991c4d.93addc40@usw-ex0105-035.remarq.com>
<frowns>
I sincerely apologize to Tad McClellan (and everyone else) for
my misuse of the post and for my comments about him, born out of
anger at my own stupidity more than anything else.
After re-reading all the posts, I must agree that HTML isn't a
programming language per se. You're right, you cannot make HTML
do something, such as add two numbers.
My understanding of programming in the sense of writing code in
C, C++, Perl, etc is somewhat limited. I'm just starting to
learn, and I've got a long (and frustrating) way to go.
The reason that I still feel that HTML is a programming language
in some senses is this: If I sit down and write an actual
program in C, I've written something that's pretty much useless
in and of itself. That is to say, that original file, complied
in (G)Notepad doesn't stand up by itself. Just like an HTML
file. However, when I run that little file through a compiler,
poof, I've suddenly got an output that's useable.
HTML doesn't exactly run through a compiler, but it does get
read by a browser. What it contains is interpreted and then a
finished product is spewed forth. Granted the output won't look
the same on every browser, but I think that the argument that
HTML isn't a programming language because of this is fairly
weak. Furthermore, HTML is about 'do this.' Without it, web
browsers are useless. I think it is pretty clear that HTML tells
a browser 'do this' and, after some complaining and perhaps a
little modification, it does pretty much that. The point that
programming languages are not flexible like this is a very good
one. (I have a feeling Kira explained that much better than I
just did...).
So, in short, I am the immature one. Hey, what can I say... my
parent never let me out of the house. I didn't exactly 'grow up'
so to speak. Had I simply said 'writing HTML' instead of
programming, none of this never would have been an issue. Yes,
HTML isn't a programming language in the true sense of the word,
especially when you get down to the nitty-gritty, but it also
shares many parallels. Whatever the case may be, I have a
feeling this post is going to make me look more like a wet dog
come crawling back with his tail between his legs when he knows
he's been bested, but I felt I had to clear my somewhat
tarnished name.
I guess I'm not ready to hang with the big guns yet. Like I
said, still stumbling through most things that have to do with
programming. Again, please access my apologies.
Blair J. Miller
Chief Idiot @ http://www.agentkhaki.com
Got questions? Get answers over the phone at Keen.com.
Up to 100 minutes free!
http://www.keen.com
------------------------------
Date: Mon, 19 Jun 2000 19:12:41 -0700
From: glchy <glchyNOglSPAM@cc21.com.sg.invalid>
Subject: Getting current working directory in perl script
Message-Id: <121d1f18.9981ce59@usw-ex0106-045.remarq.com>
Hi,
this is a simple question. I would like to get the current
working directory in my perl script and unshift it in my @INC.
Was thrown those codes:
eval {
($0 =~ m,(.*)/[^/]+,) && unshift (@INC, "$1");
}
Which does NOT seem to work as $0 contains only the name of the
file.
Im using Perl version 5.005_03 built for i386-linux and am on
Linux.
Thanks,
GC.
Got questions? Get answers over the phone at Keen.com.
Up to 100 minutes free!
http://www.keen.com
------------------------------
Date: Tue, 20 Jun 2000 02:44:35 GMT
From: clintp@geeksalad.org (Clinton A. Pierce)
Subject: Re: Getting current working directory in perl script
Message-Id: <nUA35.5313$fR2.61293@news1.rdc1.mi.home.com>
[Posted and mailed]
In article <121d1f18.9981ce59@usw-ex0106-045.remarq.com>,
glchy <glchyNOglSPAM@cc21.com.sg.invalid> writes:
> this is a simple question. I would like to get the current
> working directory in my perl script and unshift it in my @INC.
Maybe...
use Cwd;
unshift(@INC, cwd);
Now, you probably wanted this at compile time, didn't you? :)
Then why not just:
use lib '.';
This'll probably do what you want anyway. If you want to mess with @INC
extensively at compile time, look into BEGIN blocks.
--
Clinton A. Pierce Teach Yourself Perl in 24 Hours!
clintp@geeksalad.org for details see http://www.geeksalad.org
"If you rush a Miracle Man,
you get rotten Miracles." --Miracle Max, The Princess Bride
------------------------------
Date: Tue, 20 Jun 2000 02:21:13 GMT
From: sjs@yorku.ca (Steven Smolinski)
Subject: Re: Getting current working directory in perl script
Message-Id: <slrn8ktl8c.kon.sjs@john.sympatico.ca>
glchy <glchyNOglSPAM@cc21.com.sg.invalid> wrote:
>Hi,
Hi.
>this is a simple question. I would like to get the current
>working directory in my perl script and unshift it in my @INC.
I would suggest using the Cwd module that ships with Perl.
The docs can be viewed with:
perldoc Cwd
perl -MCwd -we 'unshift @INC, cwd; print join "\n", @INC'
Steve
------------------------------
Date: 20 Jun 2000 01:10:07 GMT
From: bmetcalf@baynetworks.com (Brandon Metcalf)
Subject: Re: help creating directories with perl
Message-Id: <8img9f$bu1$1@bcrkh13.ca.nortel.com>
VincentMurphy@mediaone.net writes:
> >> How can I create directories with perl? I'm on a redhat 6 machine.
>
> Tom> Perl's base functions are documented in the 'perlfunc' page of the
> Tom> manual.
...
> perldoc File::Path
>
> This is a more portable solution, to operating systems like Windows, than
> something like system mkdir ...
Who said anything about making a system call to mkdir.
blueduck (bmetcalf_leg) bmetcalf $ perldoc -tf mkdir
mkdir FILENAME,MODE
Creates the directory specified by FILENAME, with
permissions specified by MODE (as modified by `umask').
If it succeeds it returns TRUE, otherwise it returns
FALSE and sets `$!' (errno).
In general, it is better to create directories with
permissive MODEs, and let the user modify that with
their `umask', than it is to supply a restrictive MODE
and give the user no way to be more permissive. The
exceptions to this rule are when the file or directory
should be kept private (mail files, for instance). The
perlfunc(1) entry on `umask' discusses the choice of
MODE in more detail.
Brandon
------------------------------
Date: 20 Jun 2000 05:00:04 GMT
From: phr@netcom.com (Paul Rubin)
Subject: Re: logs of BigFloats, binomial density function, large factorials
Message-Id: <8imtok$rc9$1@slb2.atl.mindspring.net>
In article <8im6b3$5un$1@nnrp1.deja.com>, <mnanao@my-deja.com> wrote:
>
>
> I'm trying to compute NON-cumulative binomial density functions
>of rather large N (>1000). In other words, for a set of N trials,
>I want to know the probabilty of getting *exactly* n "positives" of
>probability p. As a result, I need to calculate factorials
>of these large N which easily overflow perls ~1x10^308 limit.
>So far I've tried:
Calculate the logs of the factorials by adding up the logs of 1....N.
Or, use Stirling's approximation
n! ~ (n/e)**n * sqrt(2*pi*n) * (1 + 1/(12n) + O(n** -2))
which should be quite accurate for the n > 1000 you're talking about.
Again, you can find the log of n! very easily that way.
Really though, ask yourself if what you're doing is sensible.
For large n, the binomial distribution is very close to the normal
distribution and you should be able to use standard tables.
You probably ought to talk to a statistics whiz (I don't qualify!)
for more help. Your question is a math/stat question, not a perl question.
------------------------------
Date: Tue, 20 Jun 2000 00:59:39 -0400
From: "Rob - Rock13.com" <rob13@rock13.com>
Subject: Re: Messagebox in Win32
Message-Id: <394EFA3B.3798F103@rock13.com>
Jan van Mansum wrote:
>
> Where do I get that module?
Probably here:
http://search.cpan.org/
--
Rob
http://rock13.com/webhelp/
Fight Spam - http://www.cauce.org/
------------------------------
Date: Mon, 19 Jun 2000 21:21:08 -0700
From: Robert <taylorr@greendot.net>
Subject: Perl DBI Oracle?
Message-Id: <394EF134.58A79B22@greendot.net>
Is perl the preferred method for pulling data out of an oracle
database into text files? Can resident "bot" programs be written in
perl for unix that would generate files on a schedule? Perl is
generally available on unix boxes installed with the OS?
Sorry for the general questions. I'm a VB-Database programmer and I'm
going to have to do some database work on a unix machine and I'm trying
to figure out the best way to do it.
Is the Perl DBI O-riley book the only one available that would cover
databasing with perl?
Thanks
Robert
------------------------------
Date: 20 Jun 2000 05:58:45 GMT
From: ebohlman@netcom.com (Eric Bohlman)
Subject: Re: Perl DBI Oracle?
Message-Id: <8in16l$gnf$5@nntp9.atl.mindspring.net>
Robert (taylorr@greendot.net) wrote:
: Is perl the preferred method for pulling data out of an oracle
: database into text files?
Depends on who's doing the preferring, but it's certainly a viable and
well-supported method.
: Can resident "bot" programs be written in
: perl for unix that would generate files on a schedule?
Unix systems have an excellent task scheduler, cron, that can fire up a
program at intervals you specify.
: Perl is
: generally available on unix boxes installed with the OS?
Yes, though sometimes it's an old version. If it's too old (most people
would say that anything before 5.004_04 is too old), you can obtain a
newer version from CPAN, the Comprehensive Perl Archive Network.
: Sorry for the general questions. I'm a VB-Database programmer and I'm
: going to have to do some database work on a unix machine and I'm trying
: to figure out the best way to do it.
Once you get used to Perl, you might resent having to go back to VB
(though Perl is available for Win32 systems as well...).
: Is the Perl DBI O-riley book the only one available that would cover
: databasing with perl?
Not the only one, but probably the most definitive reference.
------------------------------
Date: Tue, 20 Jun 2000 14:50:33 +0800
From: "karen" <tamtc@hotmail.com>
Subject: Programming with Perl -melting dowin name, icq into a template and password to access directory
Message-Id: <8in47a$2sh$1@news.ctimail.com>
I. 1. name card program for kids that can have a choice of 50 (pictures)
for examples;
2. email the name card to kids
3. edit the name card with field name, address, phone, ( icq)
4. edit the background of the card
Questions:
1. How to create template in HTML and so that kids can fill in point #3 in
the background picture ?
2. How to melt down the point # 3 into a a picture.
3. How to write a perl to control access of designate directory. Where can
store the password so the logic is: if the password is correct then kids can
access the specified directory.
All of these can be edited interactively via web for the global access
tamtc@hotmail.com
------------------------------
Date: Tue, 20 Jun 2000 02:37:40 GMT
From: tony_123@my-deja.com
Subject: Reg Expression Question
Message-Id: <8imldk$f61$1@nnrp1.deja.com>
Hi Folks
I have the string
$MyString='<img src="http://www.myhouse.com.au/house.gif">';
Can someone please tell me how I can extract the house.gif part of this
string.
Cheers
Tony
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Mon, 19 Jun 2000 22:54:36 -0400
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Reg Expression Question
Message-Id: <slrn8ktn7c.e9l.tadmc@magna.metronet.com>
On Tue, 20 Jun 2000 02:37:40 GMT, tony_123@my-deja.com <tony_123@my-deja.com> wrote:
>Hi Folks
Hi.
>I have the string
>
>$MyString='<img src="http://www.myhouse.com.au/house.gif">';
>
>Can someone please tell me how I can extract the house.gif part of this
>string.
Here's one way:
my $img_name = substr($MyString, 36, 9);
You forgot to show us the code you have so far.
Post it, and we will help you fix it.
Typing:
perldoc perlre
may prove helpful.
--
Tad McClellan SGML Consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Tue, 20 Jun 2000 06:32:20 GMT
From: "Philip Garrett" <philipg@atl.mediaone.net>
Subject: Re: Reg Expression Question
Message-Id: <UdE35.1010$Vf7.33474@typhoon.southeast.rr.com>
<tony_123@my-deja.com> wrote in message news:8imldk$f61$1@nnrp1.deja.com...
> $MyString='<img src="http://www.myhouse.com.au/house.gif">';
($MyGif) = $MyString =~ /src="[^"]*\/(\w+(\.\w*)?)"/;
print "$MyGif\n";
could be simpler, e.g. /(\w+\.gif)/, but not as flexible
------------------------------
Date: Mon, 19 Jun 2000 15:57:59 -0500
From: "Craig L. Ching" <cching@mqsoftware.com>
Subject: Re: Returning a hash from XS
Message-Id: <8im23g$lfl$1@paxfeed.eni.net>
Ok, thanks much for the info, this is great stuff (I'm still a bit green
with Perl)!
Cheers,
Craig
Dan Sugalski <dan@tuatha.sidhe.org> wrote in message
news:3Js35.4050$Zg4.17910@news1.rdc1.ct.home.com...
> Craig L. Ching <cching@mqsoftware.com> wrote:
> > Excellent! Thanks for the answer to my question!
>
> >> Returning a ref is the only way to return a hash. You can always return
a
> >> list of key/value pairs, but that's less efficient.
>
> > Now, I really would like my data to be returned in a normal hash.
>
> You can't--there's no way in perl to return a hash. You either return a
> list of key/value pairs:
>
> %hash = some_func();
>
> or a ref to a hash:
>
> $hashref = some_other_func();
>
> There's no way to return a hash per se. (Remember, return returns either a
> single scalar or a list of scalars, with hashes and arrays getting
> flattened) If you want the first style, just return a list of key/value
> pairs. If you've got a lot of pairs it's not paticularly efficient, though
> if you've only got a few it's fine.
>
> If you're feeling clever you can check the context your function was
> called in and return either a list of scalars or a hash ref, though that
> can be a bit confusing.
>
> Dan
------------------------------
Date: Tue, 20 Jun 2000 05:26:23 GMT
From: Kirk Sansom <info@sansom.net>
Subject: simplest e-mail script in the world wanted
Message-Id: <394F0018.231BF60E@sansom.net>
I am a totally programming novice and urgently need a simple
script to send a prewriting e-mail to one pre-determined recipient
by cron on Redhat 6.2. I've created a gawk script and simply need
cron to run this script to let me know that it has completed
running the gawk script.
------
The e-mail recipient, subject and body will stay the same such as:
To: administrator@mydomain.com
Subject: the updates have been completed
Body: The updates have been completed.
------
That's it! I can't seem to find such a simple script anywhere!
--
Kirk Sansom
info@sansom.net
------------------------------
Date: Mon, 19 Jun 2000 15:58:06 +0200
From: Jimmy Lantz <jimmy.lantz@ostas.lu.se>
Subject: Re: Sorting a ':' delimeted file by a field value/surname. #2
Message-Id: <394E26EE.E38A6A06@ostas.lu.se>
Hi,
I'm still working with sorting the file alphabetically.
I got the code below from Michel Dalle, Thanks BTW!
################################### START MAP/SORT #########
# Hint : read the comments from bottom to top
print map {$_->[0]} # keep only the line itself for printing
sort { # sort on the two fields you selected below
$a->[1] cmp $b->[1] ||
$a->[2] cmp $b->[2]
}
map { [ $_, (split(/:/))[3,2] ] } # keep the line itself
# + fields 3 and 2 for sorting
# (field numbers start at 0)
<DATA>; # your data - replace with STDIN or FILE
###################################
I've now been looking for a good Manual for the function MAP, cause I
don't really get
how the above code works. But it is working for me as desired!! Even
handles the swedish chars (thanks to the fact that i work on Macintosh I believe).
My next Question is how can I combine the subroutine do_content below
with the code above,
so that I can decide how I want to treat each line after it has been
sorted in the sort above.
Can I assign the output from the code above to an array? then do an
"foreach" like the sub below ?
I know these Questions might steem from not understanding the MAP
function good enough.
So if you have some good pointers/links for tutorials which deals with
the Map function in depth I would be very gratefull.
Or if someone could write some pseude-code for the code above, I would
appreciate that as well.
Yours sincerely
Jimmy Lantz
##################################~ START SUB ~#############
sub do_content
{
foreach $line (@lines) # @lines contains the lines from the filehandle <DATA>
{
print qq!<tr class="tddata">!;
@arrayline = split(/:/,$line);
print "<td>$arrayline[1]</td>\n";
print "<td>$arrayline[3]</td>\n";
print "<td>$arrayline[2]</td>\n";
print qq!</tr>!;
}
}
################################################
############# Exampleline from file. ##############
KIN231:111111-1111:John:Burnes:jburnes@hotmail.com:555121212:greenway
21:PO 251:Bournesporth:Scolarship:YES
------------------------------
Date: Mon, 19 Jun 2000 19:46:22 -0700
From: Ramesh Vadlapatla <rvadlapa@cisco.com>
Subject: Viewing Multipart/Mixed messages
Message-Id: <394EDAFE.E9D2B57E@cisco.com>
Hello!
Let's say I have a multipart/mixed message that contains:
Content-Type: TEXT/PLAIN; charset=US-ASCII
and
Content-Type: APPLICATION/octet-stream; name="test.JPG"
How would I display this file(message) in a browser and display both
Text as well as the jpg?
I have the ability to pass it through a script(perl) before I display it
on the browser.
So what header information should I pass?
Any pointers(modules) to implement this would be helpful.
Thanks,
Ramesh
------------------------------
Date: Mon, 19 Jun 2000 22:58:46 -0700
From: Agentkhaki <altavistaNOalSPAM@agentkhaki.com.invalid>
Subject: Re: What the...
Message-Id: <17b01a3f.95f7453a@usw-ex0105-035.remarq.com>
Okay.
This is becoming more of a journal of my progress than anything
else. I guess that's what I deserve for letting my anger at
failure get the best of me in "Topic: Crazy enough that it might
just work..."
Anyway, I fixed the above mentioned error, and now here's what's
happening. I logged into a unix machine, ran my code, generated
the dbm files using another script, which also set their file
permissions. Now the script pretty much works when it finds
errors in the information entered through the form, but when the
info is correct, and it should be written to file, it isn't. The
file permissions for all of the files in my CGI-BIN having to do
with this script are as follows:
-rwxr-xr-x (create_user.pl)
-rwxr-xr-x (datahandler_cu.pl)
-rw-r--r-- (members.dir)
-rw-r--r-- (members.pag)
Are those permissions correct? It looks to me like I am the only
one who has... wait a minute... I don't know enough to be able
to read that, but I think it's saying that I am the only one
with permission to write to the files, which would explain why
it works when I run it on my computer, but not when it's run on
the web server... I guess my question is how to I reset the file
permissions so that everyone can read and write to the last two
files... I'll try and figure it out, but in case I don't, can
someone post the command I'll need to use here? Thanks.
Got questions? Get answers over the phone at Keen.com.
Up to 100 minutes free!
http://www.keen.com
------------------------------
Date: Mon, 19 Jun 2000 23:30:35 -0700
From: Agentkhaki <altavistaNOalSPAM@agentkhaki.com.invalid>
Subject: Re: What the...
Message-Id: <00eea8a1.9e44089c@usw-ex0105-035.remarq.com>
Okay, so I think I managed to fix the permissions problem
locally, so that the files had the permissions
-rw-rw-rw-
But when I uploaded them they went back to the same... Any ideas?
Got questions? Get answers over the phone at Keen.com.
Up to 100 minutes free!
http://www.keen.com
------------------------------
Date: Mon, 19 Jun 2000 23:33:52 -0700
From: Agentkhaki <altavistaNOalSPAM@agentkhaki.com.invalid>
Subject: Re: What the...
Message-Id: <00abf3e2.9f1fbadf@usw-ex0105-035.remarq.com>
Right clicking on the file and selecting 'Properties' in Crystal
FTP 2000 was the way to go. Right there 'Set File Permissions.'
Duh! See, I'm figureing it out myself... Newbies just sitting
around and waiting for the answer... Bah! I'm too impatient for
that... At least he got the impatient part right...
Got questions? Get answers over the phone at Keen.com.
Up to 100 minutes free!
http://www.keen.com
------------------------------
Date: Tue, 20 Jun 2000 01:56:12 -0500
From: Nnickee <nnickee@nnickee.com>
Subject: Re: What the...
Message-Id: <CE6D1922C70BD4BF.B2DB973F00697B9E.ADB70DB7C16DE22D@lp.airnews.net>
On Mon, 19 Jun 2000 22:58:46 -0700, someone claiming to be Agentkhaki
<altavistaNOalSPAM@agentkhaki.com.invalid> said:
>Okay.
>This is becoming more of a journal of my progress than anything
>else. I guess that's what I deserve for letting my anger at
>failure get the best of me in "Topic: Crazy enough that it might
>just work..."
No... I think it's more a case of you haven't actually asked a perl
related question yet.
Since I haven't noticed Tom pointing you to this (he might've done it,
but I didn't notice it :) please take a look at (please don't be
offended by the name) The Idiot's Guide to Solving Perl CGI Problems:
http://www.cpan.org/doc/FAQs/cgi/idiots-guide.html
After you've worked your way through that, if you believe that your
problem is perl related (as opposed to cgi or web server permissions
related) then you should post your .pl here -- snip it down to the
section that isn't working -- if your problem really is perl related,
there's no way the Gurus can solve it for you without actually seeing
the code.
HTH,
Nnickee
------------------------------
Date: 20 Jun 2000 02:38:54 GMT
From: db7654321@aol.comspamsux (David Bell)
Subject: Re: What's the difference between a hash and an array?
Message-Id: <20000619223854.02926.00002300@ng-cg1.aol.com>
>Perl comes with a plethora of documentation (which admittedly can be
>overwhelming for newbies). Familiarize yourself with perldoc: type
>'perldoc perldoc' on your command line. You won't regret it.
Yup, It's well documented if you know what to search for. As flock doesn't do
quite what'd I'd like (I think...), I need another solution. How do I lock the
entire program so only one copy of it can be run at a time? I've searched
quite a bit, but couldn't find the answer to that one. I figured the only way
would be to make another script to call the original ( Can flock lock
system()?), and lock it in the process. ...But if this is even possible, it
sounds very inefficient. Any ideas? Thanks!
-------------------------
David Bell - Otherwise known as DB7654321
Remember to remove nospam, notrash or anything odd looking from my email
address. :)
------------------------------
Date: 20 Jun 2000 05:45:04 GMT
From: ebohlman@netcom.com (Eric Bohlman)
Subject: Re: What's the difference between a hash and an array?
Message-Id: <8in0d0$gnf$4@nntp9.atl.mindspring.net>
David Bell (db7654321@aol.comspamsux) wrote:
: Yup, It's well documented if you know what to search for. As flock doesn't do
: quite what'd I'd like (I think...), I need another solution. How do I lock the
: entire program so only one copy of it can be run at a time? I've searched
: quite a bit, but couldn't find the answer to that one. I figured the only way
: would be to make another script to call the original ( Can flock lock
: system()?), and lock it in the process. ...But if this is even possible, it
: sounds very inefficient. Any ideas? Thanks!
The usual way is to use a mutex; check CPAN to see if there are modules
for dealing with them. If not, you can construct one using a shared file.
------------------------------
Date: 20 Jun 2000 05:02:07 GMT
From: phr@netcom.com (Paul Rubin)
Subject: Where to get CPAN CD?
Message-Id: <8imtsf$ntp$1@slb7.atl.mindspring.net>
Anyone know of a cheap place where I can get a cd-rom with a snapshot
of the CPAN archive, so I don't have to keep downloading stuff?
I know of the CPAN CD included with the O'Reilly perl bundle and the
Red Hat Professional bundle, but these are quite expensive.
I suggested www.cheapbytes.com make a perl cd, and they said they'd
consider it, but it's not currently on their website.
I have DSL at home so I guess I could make my own cpan mirror in a day
or so of ftp'ing, but it seems like overkill and an unnecessary waste
of bandwidth.
Thanks
Paul
------------------------------
Date: 20 Jun 2000 06:04:38 GMT
From: ebohlman@netcom.com (Eric Bohlman)
Subject: Re: Where to get CPAN CD?
Message-Id: <8in1hm$gnf$6@nntp9.atl.mindspring.net>
Paul Rubin (phr@netcom.com) wrote:
: Anyone know of a cheap place where I can get a cd-rom with a snapshot
: of the CPAN archive, so I don't have to keep downloading stuff?
The problem is that such CD-roms (which can be found in some Perl books)
become outdated *very* quickly. Take a look at the "by recentness" list
on CPAN over a period of a couple weeks. By the time you get a CD ready
for distribution, the most popular modules on CPAN will be several
versions ahead of those on the CD.
Some enterprising soul could consider running a CPAN mirror and, upon
request, burning a CD-R of it and FedExing it to the customer, but it
would probably be too expensive for most people to use.
------------------------------
Date: 20 Jun 2000 06:15:34 GMT
From: phr@netcom.com (Paul Rubin)
Subject: Re: Where to get CPAN CD?
Message-Id: <8in266$cki$1@slb3.atl.mindspring.net>
Eric Bohlman <ebohlman@netcom.com> wrote:
>The problem is that such CD-roms (which can be found in some Perl books)
>become outdated *very* quickly. Take a look at the "by recentness" list
>on CPAN over a period of a couple weeks. By the time you get a CD ready
>for distribution, the most popular modules on CPAN will be several
>versions ahead of those on the CD.
>
>Some enterprising soul could consider running a CPAN mirror and, upon
>request, burning a CD-R of it and FedExing it to the customer, but it
>would probably be too expensive for most people to use.
I don't mind if the CD is a few months behind. I know that companies
like cheapbytes get CD's out to customers within a few weeks of having
the bits ready. So a quarterly release would be fine with me. At
that point downloading updates from a cpan mirror wouldn't be so slow.
If someone with a mirror is offering to burn CPAN cd-r's for a
reasonable fee, I'd be willing to buy one (Fedex not needed, regular
mail is ok).
Thanks
------------------------------
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 3426
**************************************