[8871] in Perl-Users-Digest
Perl-Users Digest, Issue: 2488 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon May 4 05:06:27 1998
Date: Mon, 4 May 98 02:00:33 -0700
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Mon, 4 May 1998 Volume: 8 Number: 2488
Today's topics:
Re: 'each' and recursion, do they mix? (Chip Salzenberg)
(new Win32::ODBC($DSN1)) doesn't work <dmitri-b@usa.net>
Re: 1701 days hath September (was: Re: rename funciton) (John Stanley)
Re: 1701 days hath September (was: Re: rename funciton) (John Stanley)
Re: 1701 days hath September (was: Re: rename funciton) <ljz@asfast.com>
cd with a perl-script <michael.pokerschnig@stk.co.at>
Re: cd with a perl-script (Arthur Hagen)
CGI.pm question - user friendly labels for popup_menu scott.seaton@aus.sun.com
Re: date problem (Leonard Miller)
Directory usage in Perl for win32 <marz@tamu.edu>
Re: Getting the filehandle from a typeglob (Chip Salzenberg)
Re: HELP win32 perl (Ethan H. Poole)
Re: How do I print an array in the format I want it? <tchrist@mox.perl.com>
How many files can I open? (Hans Xie)
killing a child PID <justin@nectar.com.au>
Re: Length of a variable <roach@necrosis.com>
Re: Length of a variable <rootbeer@teleport.com>
Re: Length of a variable (Leonard Miller)
Re: Length of a variable <rjk@coos.dartmouth.edu>
Re: Length of a variable (Martien Verbruggen)
Re: Length of a variable <sami@ersatz_microsoft.com>
Multiple packages in a single .pm file (John Siracusa)
Re: Multiple packages in a single .pm file <tchrist@mox.perl.com>
Re: Multiple packages in a single .pm file (John Siracusa)
Replacement for grep using map bart.mediamind@tornado.be
Replacement for grep using map bart.mediamind@tornado.be
Re: Strange problem. <rootbeer@teleport.com>
Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sun, 03 May 1998 21:55:26 GMT
From: chip@mail.atlantic.net (Chip Salzenberg)
Subject: Re: 'each' and recursion, do they mix?
Message-Id: <6iip7i$c8u$1@cyprus.atlantic.net>
Keywords: fractious Grayson multiplication pug
According to mjd@op.net (Mark-Jason Dominus):
>This really is the problem I alluded to in my earlier post. Here is
>Chip's summary:
>
># The result of comiling a //o is stored in the REGEXP structure which
># is attached to the OP for the match. And the key is this: That OP
># is shared by all closures cloned from a given sub {}.
How eloquently stated that is. :-)
>I would suspect (without testing) that other stateful operators
>exhibit these same problems. For example, what happens to scalar
>.. in a `closure'? Similarly, `pos' is attched to the regex, so
>matches_foo will reset the results of `pos' in matches_bar. You can
>undoubtedly think of other examples yourself.
Yes, scalar '..' does have the same problem as //o.
OTOH, pos() doesn't; the pos() for any given scalar is stored as
hidden data attached to that scalar. Thus, in C<$$a =~ //g>, the
position at which the match starts is entirely determined by pos($$a).
In general, any construct in Perl that needs to keep state, and that
doesn't have a convenient variable or other value to keep it in, is
probably keeping its state in the OP tree, thus counfounding closures.
--
Chip Salzenberg - a.k.a. - <chip@pobox.com>
"I brought the atom bomb. I think it's a good time to use it." //MST3K
-> Ask me about Perl training and consulting <-
Like Perl? Want to help out? The Perl Institute: www.perl.org
------------------------------
Date: 3 May 98 23:10:38 GMT
From: "Dmitri Budchenko" <dmitri-b@usa.net>
Subject: (new Win32::ODBC($DSN1)) doesn't work
Message-Id: <01bd7712$ab761080$685992c6@senspro>
For some reason, the following statement always returns False and prints
"Failure":
if (!($O1 = new Win32::ODBC($DSN1))){
print "Failure. \n";
I'm using Perl 5.004 Windows95. I've put odbc.pll into
perl\lib\auto\Win32\odbc, and I have odbc.pm installed in
perl\lib\site\Win32. PATH contains actual path to my perl directory.
The part which makes DSN connection to my Access database works fine.
What's wrong?
------------------------------
Date: 4 May 1998 04:21:12 GMT
From: stanley@skyking.OCE.ORST.EDU (John Stanley)
Subject: Re: 1701 days hath September (was: Re: rename funciton)
Message-Id: <6ijfno$gc4$1@news.NERO.NET>
In article <Pine.A41.3.95a.980503150708.35574G-100000@rsplus13.cern.ch>,
Alan J. Flavell <flavell@mail.cern.ch> wrote:
>One doesn't have to even write software to deal with this problem.
>There's a whole range of solutions. If you want to, you could create an
>email address exclusively for your usenet activities, which (except at
>the specific times or for the specific purposes that you need to respond
>to it, e.g to authorize a posting) dumps everything in the bit bucket,
>preferably at the server without even downloading it to your own
>machine.
Yes, the idea of paying for yet another account has already been
suggested. You apparently missed the part where it involves paying for
another account.
>PROCMAIL is one approach, albeit somewhat fiddly to set up.
If someone is in a situation where it costs to transport email,
procmail is too late.
>But I don't see why we're discussing it here. There are plenty of ways
>that email addresses get loose on the Internet and added to spam-mailing
>lists; you're only considering one of those ways.
Yes, I am considering only one of those ways. I make the assumption
that those who cannot afford to get spam are already taking steps to
prevent the other ways from occurring. For example, they munge their
addresses when they post. That leaves us with the problem of a
newsgroup presumably intended to help people having as the price of
admission a spammable email address.
------------------------------
Date: 4 May 1998 04:28:28 GMT
From: stanley@skyking.OCE.ORST.EDU (John Stanley)
Subject: Re: 1701 days hath September (was: Re: rename funciton)
Message-Id: <6ijg5c$gm6$1@news.NERO.NET>
In article <ltiunncv7p.fsf@no.where>,
Reply to unauthorized spam <nospam@no.where> wrote:
>
>stanley@skyking.OCE.ORST.EDU (John Stanley) writes:
>
>>
>> Except those for whom the cost of getting spammed is more than they can
>> afford.
>
>You seem to forget that everyone in the world with usenet access would
>be able *read* the spam-free c.l.p.moderated newsgroup.
No, I don't seem to forget this. It isn't an issue, and it isn't
relevant to the costs of email spam to those who otherwise would be
able to post.
>The only
>restrictions on that group would concern *posting*.
That's right.
>This is how all moderated usenet newsgroups work.
No, that is NOT how all moderated newsgroups work. Very few require
people to post with a spammable address.
>Therefore, every usenet user in the
>world would benefit from the lower costs of reading a spam-free,
>Perl-based newsgroup.
Yes, they would. But the elimination of spam is already provided by
being moderated, and the requirement of a posting with a spammable
address is extraneous to this.
>Secondly, even if you post to a moderated newsgroup, your email
>address would be present on the post just like it would be present in
>a non-moderated newsgroup.
That is not correct. If you post to a normal moderated newsgroup, or to
comp.lang.perl.misc, with a munged address, your email address is not in
the posting.
>And finally, everyone is accruing the costs you mention right now when
>they read c.l.p.misc, even though c.l.p.moderated doesn't exist yet.
That is incorrect. Those who munge their addresses are not "accruing"
the costs of email spam.
------------------------------
Date: 04 May 1998 01:12:31 -0400
From: Lloyd Zusman <ljz@asfast.com>
Subject: Re: 1701 days hath September (was: Re: rename funciton)
Message-Id: <ltogxety9s.fsf@asfast.com>
stanley@skyking.OCE.ORST.EDU (John Stanley) writes:
> In article <ltiunncv7p.fsf@no.where>,
> Reply to unauthorized spam <nospam@no.where> wrote:
> >
> > [ ... ]
> >
> >The only
> >restrictions on that group would concern *posting*.
>
> That's right.
>
> >This is how all moderated usenet newsgroups work.
>
> No, that is NOT how all moderated newsgroups work. Very few require
> people to post with a spammable address.
Aha! Now I understand your issue. It has to do with the statement in
the RFD concerning not accepting posts to c.l.p.moderated that have
munged addresses. I must have missed your earlier post where this was
spelled out. I'm sorry about that.
Well ... why not just continue to post to c.l.p.misc with your
non-spammable address? That would still be as much of an option after
c.l.p.moderated's creation as it is now. I know I'm an optimist, but
I believe that there will still be plenty of experienced Perl users
fielding questions in c.l.p.misc even after c.l.p.moderated is
created.
> > [ ... ]
--
Lloyd Zusman ljz@asfast.com
perl -e '$n=170;for($d=2;($d*$d)<=$n;$d+=(1+($d%2))){for($t=0;($n%$d)==0;
$t++){$n=int($n/$d);}while($t-->0){push(@r,$d);}}if($n>1){push(@r,$n);}
$x=0;map{$x+=(($_>0)?(1<<log($_-0.5)/log(2.0)+1):1)}@r;print"$x\n"'
------------------------------
Date: Mon, 04 May 1998 09:54:46 +0200
From: Michael Pokerschnig <michael.pokerschnig@stk.co.at>
Subject: cd with a perl-script
Message-Id: <354D7446.250CD97A@stk.co.at>
Hi,
I want to change to a sub-directory, using a perl script. The script
calculates this directory using reversal parsing of some softlinks and
searching for a filename. If the script finds the file it should set the
current working dircetory
of the shell from which it was called.
Can anybody tell me how i can change the directory of the shell from
wich I'm starting the perl script ?
Kind regards
Mike.
--
\\///
(.|.)
___________________________oOO_(_)_OOo________ _ ___ __ __ .
Michael Pokerschnig > | (__) |-< |-<
Software Development
_________________________________________________________________
Schablonentechnik Kufstein AG (STK) Phone: +43/(0)5372/6993-240
a company of STORK-Group Fax: +43/(0)5372/6993-54
------------------------------
Date: Mon, 4 May 1998 10:26:35 +0200
From: art@flying.broomstick.com (Arthur Hagen)
Subject: Re: cd with a perl-script
Message-Id: <r3uji6.1tr.ln@flying.broomstick.com>
In article <354D7446.250CD97A@stk.co.at>, Michael Pokerschnig <michael.pokerschnig@stk.co.at> writes:
> Can anybody tell me how i can change the directory of the shell from
> wich I'm starting the perl script ?
Short answer: You can't.
It's an underlying concept of unix that you can only inherit from your
parents, and not from your offspring. When you start a shell script
(or perl script), it inherits environment variables, cwd, and similar
from its parent. And not vice versa.
What you can do, however, is to bake a shell into the perl script,
where perl acts as a frontend to the shell. Then for all practical
purposes you will achieve what you want.
Or you may make the perl script output the name of the new working
directory to a file, which you then can read from the old shell and set
the path. Depending on the shell, this can be done with a minimum of
intervention from the user, for example with tcsh's precmd which may by
default be set to check if a special file exists (which should have the
parent pid of the perl script baked into the file name), and if so cd
to the contents of that file, and then delete the file.
Note that this approach will only work with one specific shell, and it's
not 100% robust (there may be leftover files if no command is executed,
which may cause the cd to occur the next time a shell gets that process
id).
Hope this helps,
--
*Art
------------------------------
Date: Mon, 04 May 1998 02:57:39 -0600
From: scott.seaton@aus.sun.com
Subject: CGI.pm question - user friendly labels for popup_menu
Message-Id: <6ijsdi$1p0$1@nnrp1.dejanews.com>
Hi
I'm trying to setup a CGI interface to a fax system. I'm using perl and
CGI.pm, but I'm having trouble getting a popup_menu going....
The menu comes up OK, but only displays the values. I'd like it to display
something else, but can't get it working.
Here's a code extract:
use CGI qw(:all);
$query = new CGI;
print $query->header(-type=>'text/html');
print $query->start_html;
print $query->start_form(-method=>POST);
print table({-border=>'',-width=>'100%'},
Tr({-align=>LEFT,-valign=>CENTER},
td('Your Name:'),
td(popup_menu(-name=>'requestor',
-values=>[qw/name1 name2 name3 name4 name5/],
-labels=>{'Firstname Lastname1'=>'one',
'Firstname Lastname2'=>'two',
'Firstname Lastname3'=>'three',
'Firstname Lastname4'=>'four',
'Firstname Lastname5'=>'five'},
-default=>'name1')),
td('some text goes here')
)
);
print $query->submit;
print $query->reset;
print $query->end_form;
print $query->end_html;
I'd like the popup_menu to display the "Firstname LastnameX" label, but don't
seem to be able to get it working... All I get is the entry from the values
array.
Thanks
Scott
==============================================================================
,-_|\ Scott Seaton - Customer Services Systems Consultant
/ \ Sun Microsystems Australia Pty Ltd E-mail : scott.seaton@aus.sun.com
\_,-\_+ 828 Pacific Highway Phone : +61 2 9844 5381
v Gordon, N.S.W., 2072, AUSTRALIA Fax : +61 2 9844 5161
==============================================================================
-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/ Now offering spam-free web-based newsreading
------------------------------
Date: Sun, 03 May 1998 21:36:16 -0700
From: millers3@sonic.net (Leonard Miller)
Subject: Re: date problem
Message-Id: <millers3-0305982136160001@d173.pm5.sonic.net>
In article <6ij2jp$nm8$2@comdyn.comdyn.com.au>, mgjv@comdyn.com.au
(Martien Verbruggen) wrote:
> How exactly does this have anything to do with perl modules?
>
> In article <354CFBD1.3FF7@swipnet.se>,
> Nils-Roger Edvardsson <nr.edv@swipnet.se> writes:
> > I have this string :
> >
> > $date_command = "/usr/bin/date";
> >
> > In my guestbook were the date shall show up, I get this instead :
> >
> > - $date_command +"%A, %B %d, %Y at %T (%Z)
> >
> > Hmm, what is wrong ?
>
> How are we supposed to know? You probably alter your 'string'
> somewhere else. Run the thing in the debugger or something. grep your
> code for 'date_command'. Do the usual things one does when a problem
> occurs: DEBUG.
>
> I really don't need this on a monday morning.
Should be something like:
$date_command = `date +"%D"`;
Note the backquotes, these will run a system operation like date.
Check out the manpage on date, you'll find many variables.
Good luck,
-Leonard
------------------------------
Date: Sun, 3 May 1998 23:58:01 -0500
From: Mike Marziani <marz@tamu.edu>
Subject: Directory usage in Perl for win32
Message-Id: <Pine.NXT.3.96.980503235221.29753A-100000@support.tamu.edu>
I have a mail server (running under windows NT) with roughly 200 user
directories. I want a quick and easy way to generate a report that will
show me everyone who is using over a certain amount of space so that I can
keep disk usage down. I have a bit of code that will get me the file size
for any directory tree I give it:
use File::Find;
@ARGV = ('.') unless @ARGV;
my $sum = 0;
find sub { $sum += -s }, @ARGV;
print "@ARGV contains $sum bytes\n";
But what is the best way to read in the list of directories and apply this
function to each directory in turn? I am sort of new to perl (but not to
programming) so if this is some info readily available in the docs, please
point me to it.
Thanks in advance,
Mike
------------------------------
Date: Sun, 03 May 1998 22:00:18 GMT
From: chip@mail.atlantic.net (Chip Salzenberg)
Subject: Re: Getting the filehandle from a typeglob
Message-Id: <6iipgm$c9l$1@cyprus.atlantic.net>
According to tchrist@mox.perl.com (Tom Christiansen):
>You are confused because you are trying to use a glob as an object.
>You can't do that.
use Symbol;
sub new { bless gensym }
?
--
Chip Salzenberg - a.k.a. - <chip@pobox.com>
"I brought the atom bomb. I think it's a good time to use it." //MST3K
-> Ask me about Perl training and consulting <-
Like Perl? Want to help out? The Perl Institute: www.perl.org
------------------------------
Date: 4 May 1998 07:42:58 GMT
From: ehp@gte.net (Ethan H. Poole)
Subject: Re: HELP win32 perl
Message-Id: <6ijri2$4b0$1@gte2.gte.net>
In article <35584527.12007866@news.wwa.com>, sweiner@usa.net says...
>
>no, but the activestate's version of Perl does NOT support sockets so
>Ping does not work.
Not entirely correct. *I* use sockets with the ActiveState version and have no
particular problems. Have never specifically tried the Ping module though.
--
Ethan H. Poole | Website Design and Hosting,
| CGI Scripting...
========Personal========= | ============================
* ehp @ gte . net * | --Interact2Day--
http://home1.gte.net/ehp/ | http://www.interact2day.com/
------------------------------
Date: 4 May 1998 04:39:03 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: How do I print an array in the format I want it?
Message-Id: <6ijgp7$iql$1@csnews.cs.colorado.edu>
[courtesy cc of this posting sent to cited author via email]
In comp.lang.perl.misc, "Larry Rosler" <lr@hpl.hp.com> writes:
:> sprintf "%3d.%3d.%3d.%3d", split /\./, $ip;
Those are not IP addresses, you know. Run it on "127.1",
which is, to see what I mean. You might also try to telnet
to port 80 of 3502894896 while you're at it.
When a three part address is specified, the last part is
interpreted as a 16-bit quantity and placed in the right
most two bytes of the network address. This makes the
three part address format convenient for specifying Class
B network addresses as 128.net.host.
When a two part address is supplied, the last part is
interpreted as a 24-bit quantity and placed in the right-
most three bytes of the network address. This makes the
two part address format convenient for specifying Class A
network addresses as net.host.
When only one part is given, the value is stored directly
in the network address without any byte rearrangement.
>But who would want to engage in a pithing contest with Randal
>Schwartz???
Somehow who knows what an IP address is, perhaps.
sprintf("%3d.%3d.%3d.%3d\n", unpack("C4", Socket::inet_aton(shift)));
--tom
--
Tom Christiansen tchrist@jhereg.perl.com
If you can stick your finger in it, you can hang from it. --Andrew Hume
------------------------------
Date: Mon, 04 May 98 07:50:37 GMT
From: hans.xie@its.csiro.au (Hans Xie)
Subject: How many files can I open?
Message-Id: <6ijs0d$i6_001@its.csiro.au>
HI,
It looks like I can only open 60 files for writing. When I try to open more,
the file is not created, and no complain information send back!
How to get beyond this limits? I need to open about 200 files for writing.
I am using PERL 5.004_04 on Solaris 2.5
Thanks in advance.
Hans.
------------------------------
Date: Mon, 04 May 1998 17:31:39 +1000
From: Justin Wills <justin@nectar.com.au>
Subject: killing a child PID
Message-Id: <354D6EDA.1A89BE96@nectar.com.au>
this code works for some reason :), but I don't understand why :(
the kill statement won;t work if I use some other
variable name, but $pid doesn't contain anything either.
#!/usr/bin/perl
use POSIX;
use Getopt::Std;
trap_signals(); # trap SIGALRM and run the sig_handler
function.
getopt('t');
$TMOUT=($opt_t ? $opt_t : 120);
alarm $TMOUT;
system("rsh @ARGV");
exit;
sub sig_handler
{
my($signal)=shift;
# I don't know why $pid works when it's not set, but it does (at
least
# under linux)
kill 9, $pid;
exit(1);
}
--
Justin Wills
justin@nectar.com.au
------------------------------
Date: Mon, 04 May 1998 04:48:16 +0000
From: Brian Roach <roach@necrosis.com>
Subject: Re: Length of a variable
Message-Id: <354D4890.26A83BDE@necrosis.com>
niting@cyberdude.com wrote:
>
> Is there any function in PERL which will return the
> length of a variable?
[snip]
You mean other than the one described in the
documentation that comes with perl, dozens of
times in the perl FAQ (search for 'length'),
every reference book available, and coincidentally
is called 'length'?
Nope.
;)
Cheers!
- Brian
------------------------------
Date: Mon, 04 May 1998 05:10:37 GMT
From: Tom Phoenix <rootbeer@teleport.com>
To: niting@cyberdude.com
Subject: Re: Length of a variable
Message-Id: <Pine.GSO.3.96.980503220919.14139G-100000@user2.teleport.com>
On Sun, 3 May 1998 niting@cyberdude.com wrote:
> Is there any function in PERL which will return the length of a variable?
This should be easy to find in the documentation. If you can't find it,
please tell us where you looked, so that we will know what documentation
isn't working for you. Hope this helps!
--
Tom Phoenix Perl Training and Hacking Esperanto
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: Sun, 03 May 1998 22:39:43 -0700
From: millers3@sonic.net (Leonard Miller)
Subject: Re: Length of a variable
Message-Id: <millers3-0305982239430001@d173.pm5.sonic.net>
In article <6ijak5$dk0$1@nnrp1.dejanews.com>, niting@cyberdude.com wrote:
> Is there any function in PERL which will return the length of a variable?
>
> e.g:
>
> $foo = "hello";
>
> length of $foo is 5 (numeric)
>
> Thanks in advance.
>
> -Nitin
>
> -----== Posted via Deja News, The Leader in Internet Discussion ==-----
> http://www.dejanews.com/ Now offering spam-free web-based newsreading
Try:
$foo = "hello";
$length = rindex($foo,"");
print $length;
-Leonard
------------------------------
Date: Mon, 04 May 1998 01:53:55 -0400
From: Ronald J Kimball <rjk@coos.dartmouth.edu>
Subject: Re: Length of a variable
Message-Id: <354D5801.65D28CDF@coos.dartmouth.edu>
Brian Roach wrote:
>
> niting@cyberdude.com wrote:
> >
> > Is there any function in PERL which will return the
> > length of a variable?
>
> [snip]
>
> You mean other than the one described in the
> documentation that comes with perl, dozens of
> times in the perl FAQ (search for 'length'),
> every reference book available, and coincidentally
> is called 'length'?
>
> Nope.
Not true. There are plenty of other functions in Perl which will return the
length of a variable.
A few simple examples:
$length = tr///c;
$length = () = /./gs;
$length = () = split //, $_;
$length = 0; $temp = $_; $length++ while chop $temp;
More interesting examples have been posted in answer to previous incarnations
of this question.
:-)
--
_ / ' _ / - aka - rjk@coos.dartmouth.edu
( /)//)//)(//)/( Ronald J. Kimball chipmunk@m-net.arbornet.org
/ http://www.ziplink.net/~rjk/
"It's funny 'cause it's true ... and vice versa."
------------------------------
Date: 4 May 1998 05:36:05 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: Length of a variable
Message-Id: <6ijk45$pfj$1@comdyn.comdyn.com.au>
In article <6ijak5$dk0$1@nnrp1.dejanews.com>,
niting@cyberdude.com writes:
> Is there any function in PERL which will return the length of a variable?
>
> e.g:
>
> $foo = "hello";
>
> length of $foo is 5 (numeric)
<GROAN>
Yes, there is such a function. Its name is (surprise, surprise) length!
# perldoc -f length
# perldoc perlfunc
You really should get yourself a good book on perl (www.perl.com), or
at least read through the following documentation to become familiar
with perl and perl builtin functions:
# perldoc perl
# perldoc perldoc
# perldoc perlsyn
# perldoc perlop
# perldoc perldata
# perldoc perlfunc
also a good read are:
# perldoc perltoc
# perldoc perlfaq
Martien
--
Martien Verbruggen |
Webmaster www.tradingpost.com.au | "In a world without fences,
Commercial Dynamics Pty. Ltd. | who needs Gates?"
NSW, Australia |
------------------------------
Date: 4 May 1998 06:39:57 GMT
From: "Sam Inala" <sami@ersatz_microsoft.com>
Subject: Re: Length of a variable
Message-Id: <01bd7727$1021ea90$f255389d@sami1>
Leonard Miller <millers3@sonic.net> wrote in article
<millers3-0305982239430001@d173.pm5.sonic.net>...
> In article <6ijak5$dk0$1@nnrp1.dejanews.com>, niting@cyberdude.com wrote:
>
> > Is there any function in PERL which will return the length of a
variable?
> > e.g: $foo = "hello";
> > length of $foo is 5 (numeric)
> $foo = "hello";
> $length = rindex($foo,"");
> print $length;
Alternatively:
$foo = "hello";
print "Length is ", length( $foo ), "\n";
--
Sam Inala < s a m i @ m i c r o s o f t . c o m >
------------------------------
Date: 4 May 1998 04:09:04 GMT
From: macintsh@cs.bu.edu (John Siracusa)
Subject: Multiple packages in a single .pm file
Message-Id: <6ijf10$87p$1@news1.bu.edu>
Subject says it all: good, bad, or indifferent? Opinions?
-----------------+----------------------------------------
John Siracusa | If you only have a hammer, you tend to
macintsh@bu.edu | see every problem as a nail. -- Maslow
------------------------------
Date: 4 May 1998 04:40:14 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: Multiple packages in a single .pm file
Message-Id: <6ijgre$iql$2@csnews.cs.colorado.edu>
[courtesy cc of this posting sent to cited author via email]
In comp.lang.perl.misc,
macintsh@cs.bu.edu (John Siracusa) writes:
:Subject says it all: good, bad, or indifferent? Opinions?
Most people don't understand the import issues. Therefore, bad.
--tom
--
Tom Christiansen tchrist@jhereg.perl.com
When in doubt, mumble.
------------------------------
Date: 4 May 1998 05:33:21 GMT
From: macintsh@cs.bu.edu (John Siracusa)
Subject: Re: Multiple packages in a single .pm file
Message-Id: <6ijjv1$daq$1@news1.bu.edu>
Tom Christiansen (tchrist@mox.perl.com) wrote:
: Most people don't understand the import issues. Therefore, bad.
Worse, I'm probably one of them. But where does this leave
classes that are only used internally? Is it okay to have a
bunch of .pm files that should never be "use"ed anywhere except
inside some "parent" module? Example:
use Cooking::Lunch;
Inside /usr/local/lib/perl5/site_perl/Cooking/Lunch/
Chef.pm
Fridge.pm
Knife.pm
Sandwich.pm
...etc....
A user should probably never "use Cooking::Lunch::Knife" by
itself, but how should this be conveyed? Should there be PODs
for these internally-used .pm files? Should the docs for
Lunch.pm just say "don't use such and such modules because
they're for internal use by Lunch.pm only"? Is the Good
Programmer(tm) responsible for creating user documentation for
all these internal modules, or is it okay to just say, "stick to
the public spec, because the the 'helper' modules are subject
to change without notice"?
Questions, questions...
-----------------+----------------------------------------
John Siracusa | If you only have a hammer, you tend to
macintsh@bu.edu | see every problem as a nail. -- Maslow
------------------------------
Date: Mon, 04 May 1998 03:05:56 -0600
From: bart.mediamind@tornado.be
Subject: Replacement for grep using map
Message-Id: <6ijst3$1un$1@nnrp1.dejanews.com>
[I've tried to post this this weekend, but my news server is acting strangly.
I doubt if it got through, my apologies if it did. I think it's worth a
repost. I lost the original message ("delete after send"), so it's completely
rewritten.]
I stumbled across a neat trick the other day. I don't think it's a well-known
idiom, well, *I* hadn't encountered it before. :-) It could even be useful at
times.
You can easily emulate grep, the list subselection function, using a map. This
is the grep syntax:
@result = grep { COND } LIST;
and this is the equivalent map:
@result = map { COND?$_:() } LIST;
It works because the map block is evaluated in list context, and the last
thing evaluated in this block, usually a scalar, gets pushed onto the list
that map is building at the time. Depending on the condition, it either pushes
a scalar, or an empty array (= nothing). That's all there is to it.
What use is it? You can replace a map(grep) chain with one single map:
@result = map { THING } grep { COND } LIST;
becomes
@result = map { COND?(THING):() } LIST;
This will probably even be faster.
You can push not just zero or one element, but more as well. Example:
@ary = qw(peanuts banana @zig apple pear peach @zag mango);
($\,$,)=("\n",':');
print 'grep', grep { /@/ }@ary;
print 'grep through map', map {/@/?$_:() } @ary;
# build a hash:
foreach(@ary) {
$letters{$_} = tr/a-zA-Z//;
}
print "Original hash",%letters;
#deleting part of the hash while adding the deleted items to a new hash:
%selection = map { /@/?($_,delete $letters{$_}):() } keys %letters;
print 'Selected hash',%selection;
print 'Remainder',%letters;
printout:
grep:@zig:@zag
grep through map:@zig:@zag
Original
hash:pear:4:peanuts:7:peach:5:banana:6:mango:5:@zag:3:apple:5:@zig:3
Selected hash:@zig:3:@zag:3
Remainder:pear:4:peanuts:7:peach:5:banana:6:mango:5:apple:5
Note that you could do a delete on a hash slice, like this:
@result = delete @letters{grep { /@/ } keys %letters};
but the result would only be an array of deleted associated values. The link
with the original keys is lost.
Bart.
-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/ Now offering spam-free web-based newsreading
------------------------------
Date: Mon, 04 May 1998 03:05:56 -0600
From: bart.mediamind@tornado.be
Subject: Replacement for grep using map
Message-Id: <6ijsud$pta$1@nnrp2.dejanews.com>
[I've tried to post this this weekend, but my news server is acting strangly.
I doubt if it got through, my apologies if it did. I think it's worth a
repost. I lost the original message ("delete after send"), so it's completely
rewritten.]
I stumbled across a neat trick the other day. I don't think it's a well-known
idiom, well, *I* hadn't encountered it before. :-) It could even be useful at
times.
You can easily emulate grep, the list subselection function, using a map. This
is the grep syntax:
@result = grep { COND } LIST;
and this is the equivalent map:
@result = map { COND?$_:() } LIST;
It works because the map block is evaluated in list context, and the last
thing evaluated in this block, usually a scalar, gets pushed onto the list
that map is building at the time. Depending on the condition, it either pushes
a scalar, or an empty array (= nothing). That's all there is to it.
What use is it? You can replace a map(grep) chain with one single map:
@result = map { THING } grep { COND } LIST;
becomes
@result = map { COND?(THING):() } LIST;
This will probably even be faster.
You can push not just zero or one element, but more as well. Example:
@ary = qw(peanuts banana @zig apple pear peach @zag mango);
($\,$,)=("\n",':');
print 'grep', grep { /@/ }@ary;
print 'grep through map', map {/@/?$_:() } @ary;
# build a hash:
foreach(@ary) {
$letters{$_} = tr/a-zA-Z//;
}
print "Original hash",%letters;
#deleting part of the hash while adding the deleted items to a new hash:
%selection = map { /@/?($_,delete $letters{$_}):() } keys %letters;
print 'Selected hash',%selection;
print 'Remainder',%letters;
printout:
grep:@zig:@zag
grep through map:@zig:@zag
Original
hash:pear:4:peanuts:7:peach:5:banana:6:mango:5:@zag:3:apple:5:@zig:3
Selected hash:@zig:3:@zag:3
Remainder:pear:4:peanuts:7:peach:5:banana:6:mango:5:apple:5
Note that you could do a delete on a hash slice, like this:
@result = delete @letters{grep { /@/ } keys %letters};
but the result would only be an array of deleted associated values. The link
with the original keys is lost.
Bart.
-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/ Now offering spam-free web-based newsreading
------------------------------
Date: Mon, 04 May 1998 05:08:54 GMT
From: Tom Phoenix <rootbeer@teleport.com>
To: Bob Tate <btate@primary.net>
Subject: Re: Strange problem.
Message-Id: <Pine.GSO.3.96.980503213921.14139F-100000@user2.teleport.com>
On Sun, 3 May 1998, Bob Tate wrote:
> Unix like Dos, does not allow the first character to be a space.
I don't know about DOS, but neither Perl nor Unix has a problem with a
filename containing a space. If someone (using Perl, shell, or anything
else) doesn't make allowance for filenames containing certain characters,
this can be an obstacle; but that's not an inherent limitation of either
Perl or Unix.
Cheers!
--
Tom Phoenix Perl Training and Hacking Esperanto
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: 8 Mar 97 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 8 Mar 97)
Message-Id: <null>
Administrivia:
The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc. For subscription or unsubscription requests, send
the single line:
subscribe perl-users
or:
unsubscribe perl-users
to almanac@ruby.oce.orst.edu.
To submit articles to comp.lang.perl.misc (and this Digest), send your
article to perl-users@ruby.oce.orst.edu.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.
The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq". The real FAQ, as it
appeared last in the newsgroup, can be retrieved with the request "send
perl-users FAQ". Due to their sizes, neither the Meta-FAQ nor the FAQ
are included in the digest.
The "mini-FAQ", which is an updated version of the Meta-FAQ, is
available by requesting "send perl-users mini-faq". It appears twice
weekly in the group, but is not distributed in the digest.
For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V8 Issue 2488
**************************************