[15552] in Perl-Users-Digest
Perl-Users Digest, Issue: 2965 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat May 6 06:05:29 2000
Date: Sat, 6 May 2000 03:05:07 -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: <957607507-v9-i2965@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Sat, 6 May 2000 Volume: 9 Number: 2965
Today's topics:
Re: associating a filename with a FileHandle <rootbeer@redcat.com>
Re: crypt problems <douceurNOdoSPAM@flashmail.com.invalid>
Error at line 0 ? [Was: Exceptions that can't be caught <johnlin@chttl.com.tw>
Re: Exceptions that can't be caught by eval {} and loca <johnlin@chttl.com.tw>
Re: Hash of hash of hash... <makarand_kulkarni@My-Deja.com>
Re: How single-line switch (/s) works in regexps? <phill@modulus.com.au>
Re: How to tell if <> operator will work on a given sca <rootbeer@redcat.com>
Re: How to tell if <> operator will work on a given sca (Ilya Zakharevich)
Ignoring Bold Letters <root@resnet-36-207.dorm.utexas.edu>
Re: mystery: perl -e '<>;<>' (Clinton A. Pierce)
Re: mystery: perl -e '<>;<>' <makarand_kulkarni@My-Deja.com>
perl-corba documentation.. <joydeep@corp.sgi.com>
Re: program that prints itself (Philip 'Yes, that's my address' Newton)
Re: Reading delimited file into hash <makarand_kulkarni@My-Deja.com>
Re: seeking a more elegant grouping algorithm than this <rick.delaney@home.com>
VBscript to Perl Conversion <Chris.Ottinger@iname.com>
What's become of perl-Expect? <safaria@mindspring.com>
Re: What's become of perl-Expect? <rootbeer@redcat.com>
Why are files required to return true values? <s2mdalle@titan.vcu.edu>
Re: Why are files required to return true values? <rootbeer@redcat.com>
Re: Why are files required to return true values? (Ilya Zakharevich)
Re: Why are files required to return true values? <s2mdalle@titan.vcu.edu>
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Fri, 5 May 2000 18:11:36 -0700
From: Tom Phoenix <rootbeer@redcat.com>
Subject: Re: associating a filename with a FileHandle
Message-Id: <Pine.GSO.4.10.10005051808270.6766-100000@user2.teleport.com>
On Fri, 5 May 2000, Donald Lancon wrote:
> Since a FileHandle object is just an anonymous glob, you should be
> able to use its hash member however you want, right?
Well, the implementation _probably_ won't change in the future. But I'd be
cautious about doing this unless there's no better way.
> In particular, you could store the filename for an opened FileHandle in
> the hash and it would be passed around with the FileHandle:
A better way might be to keep a global array indexed on the fileno() for
the handle. At least, it's "better" in that it'll keep working even if
someday filehandles are implemented differently!
--
Tom Phoenix Perl Training and Hacking Esperanto
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: Fri, 05 May 2000 22:30:28 -0700
From: douceur <douceurNOdoSPAM@flashmail.com.invalid>
Subject: Re: crypt problems
Message-Id: <0bf34ecd.380fecce@usw-ex0106-048.remarq.com>
Well, most of you said that I need to use the same salt. I am, and
it's still not working. I'll give you an example of what I'm doing:
at one point i do this:
if (crypt($FORM{'pword'}, $cpword{$FORM{'uname'}) eq
$cpword{$FORM{'uname'}}) { &blahblah; }
$cpword{username} is already set up to retrieve the password from
'username'. at this point in the script, it works.
and at another point, i do the exact same thing, and it doesn't work at
all. i really have no idea why, though. but so basically you guys are
all saying it should work. guess i'll have to stare at it a little
longer, while trying to make myself think i can solve the problem...
thanks, anyways.
* Sent from RemarQ http://www.remarq.com The Internet's Discussion Network *
The fastest and easiest way to search and participate in Usenet - Free!
------------------------------
Date: Sat, 6 May 2000 17:20:30 +0800
From: "John Lin" <johnlin@chttl.com.tw>
Subject: Error at line 0 ? [Was: Exceptions that can't be caught by eval {} and local $SIG]
Message-Id: <8f0o67$4mj@netnews.hinet.net>
John Lin wrote
> Here I think DBD::Oracle is dumping unnecessary warning messages
> (maybe everywhere) because I can check the return values, so it doesn't
> need to warn we at all.
Dear, I am really sorry. I just saw DBI::connect provides
{PrintError=>0} to shut them down.
But the last error message IS REALLY some bug in DBD::Oracle
I can narrow it down to only a few lines of code. (I think it's from
DBD::Oracle because DBD::ADO and DBD::ODBC are OK.)
Environment:
WinNT4 + ActivePerl 5.6 + Oracle8 + DBD::Oracle v1.03
#!perl -w
use strict;
use diagnostics;
use DBI;
my $connect=DBI->connect(
'dbi:Oracle:dvwork3','stat','stat',
{RaiseError=>0,PrintError=>0}
) or die 'connect failed'; # use a valid connection string to test
# do nothing, this is the end of testing script
Error message is:
(in cleanup) Uncaught exception from user code:
Can't call method "FETCH" on an undefined value
at D:/Perl/site/lib/Win32/TieRegistry.pm line 1486
during global destruction.
Win32::TieRegistry::DESTROY('Win32::TieRegistry=HASH(0x9307668)')
called at C:\DBIinsert.pl line 0
require 0 called at C:\DBIinsert.pl line 0
Require 0 called at line 0? How come?
John Lin
P.S. Currently, to avoid the last error message, I use
END { $^W=0 }
It works because the message shows up only when -w is active.
------------------------------
Date: Sat, 6 May 2000 10:10:57 +0800
From: "John Lin" <johnlin@chttl.com.tw>
Subject: Re: Exceptions that can't be caught by eval {} and local $SIG
Message-Id: <8evv0r$696@netnews.hinet.net>
Ilmari Karonen wrote
> John Lin wrote:
> >(2) Why can't I catch the execute error by eval {} ?
> >
> >(3) I don't think $SIG{__WARN__} = sub {} is the solution. But
> > DBD::Oracle v1.03 seems to be the newest version. What can I do?
>
> Warnings are not errors:
> Caught: Error in eval 1.
> Warning in eval 2.
> Still alive in eval 2.
Oh, oh. I was stupid trying to catch warning messages by eval {}...
Here I think DBD::Oracle is dumping unnecessary warning messages
(maybe everywhere) because I can check the return values, so it doesn't
need to warn we at all.
If I use global %SIG to shut them up (it's hard to find a minimal scope,
almost every function may warn, and some are in END section),
I might also filter out other useful warning messages.
What can I do?
Thank you.
John Lin
------------------------------
Date: Fri, 05 May 2000 16:24:38 -0700
From: Makarand Kulkarni <makarand_kulkarni@My-Deja.com>
Subject: Re: Hash of hash of hash...
Message-Id: <39135836.8610D6C1@My-Deja.com>
> next problem is to print the hash in a html table
A HTML table could show the data when dim ==2
How can it show something with dim =5.
It would mean that each cell in the table has
the burden of showing data from the last three dimensions..
------------------------------
Date: Sat, 06 May 2000 12:36:23 +1000
From: Peter Hill <phill@modulus.com.au>
Subject: Re: How single-line switch (/s) works in regexps?
Message-Id: <39138527.63F0@modulus.com.au>
nobull@mail.com wrote:
>
> Larry Rosler <lr@hpl.hp.com> writes:
>
> > In article <u9ya5qfrmr.fsf@wcl-l.bham.ac.uk> on 04 May 2000 13:04:44
> > +0100, nobull@mail.com <nobull@mail.com> says...
> >
> > ...
> >
> > > Given a prefix of string and a pattern is it possible to test if is
> > > necessary to read in more to know if (or what) the pattern will match
> > > in that prefix.
> > >
> > > eg.
> > >
> > > ("foo" . $unread) =~ /f/ # Matches
> > > ("foo" . $unread) =~ /o+/ # Matches but we dont know how many
> > > ("foo" . $unread) =~ /od/ # Don't know if is maches
> > > ("foo" . $unread) =~ /d/ # Doesn't match
My turn for density; isn't that ^^^^^^^^^^^^^ #Don't (yet) know if
it matches?
Or do you mean something different when you said "match in that prefix"
:- but no, that would invalidate your conclusions for results 2 and 3.
Just curious.
--
Peter Hill,
Modulus Pty. Ltd.,
http://www.modulus.com.au/
------------------------------
Date: Fri, 5 May 2000 22:24:55 -0700
From: Tom Phoenix <rootbeer@redcat.com>
Subject: Re: How to tell if <> operator will work on a given scalar?
Message-Id: <Pine.GSO.4.10.10005052209080.6766-100000@user2.teleport.com>
On Fri, 5 May 2000, Eryq wrote:
> Hmmmm.... I wonder then... it is *always* true that <$foo>
> will work if fileno($foo) is defined? In this uncertain
> age of tiehandle, I find myself just a wee bit unsure....
As am I. A tied filehandle may fail to implement FILENO properly. And if
$foo is STDERR, it's not likely that <$foo> will do something useful. :-P
I'd say that the only reasonable thing to do to catch _all_ possibilities
is to see what happens when you try it. But that doesn't tell you before
you try to read, as you asked.
Still, you could do something like the following... If it's tied, see
whether tied($foo)->can("READLINE") . Of course, even if that's true, it
may fail once you try it, but it's a start. If it's not tied, things are
even trickier: You could use the fcntl function to use F_GETFL and see
what mode the file was opened with. Again, even if that indicates that
it's open for read, it still may fail once you try it. And that's not
terribly portable. But this method is probably the closest you can get to
telling whether it'll work before you try it; it'll be able to, at least,
tell you that it _can't_ work for many common cases.
Good luck with it!
--
Tom Phoenix Perl Training and Hacking Esperanto
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: 6 May 2000 05:42:05 GMT
From: ilya@math.ohio-state.edu (Ilya Zakharevich)
Subject: Re: How to tell if <> operator will work on a given scalar?
Message-Id: <8f0bbd$clc$1@charm.magnus.acs.ohio-state.edu>
[A complimentary Cc of this posting was sent to Tom Phoenix
<rootbeer@redcat.com>],
who wrote in article <Pine.GSO.4.10.10005052209080.6766-100000@user2.teleport.com>:
> > Hmmmm.... I wonder then... it is *always* true that <$foo>
> > will work if fileno($foo) is defined? In this uncertain
> > age of tiehandle, I find myself just a wee bit unsure....
> Still, you could do something like the following... If it's tied, see
> whether tied($foo)->can("READLINE") .
And check whether $foo overloads '<>'...
Ilya
------------------------------
Date: Sat, 6 May 2000 01:47:19 -0500
From: root <root@resnet-36-207.dorm.utexas.edu>
Subject: Ignoring Bold Letters
Message-Id: <Pine.LNX.4.21.0005060134380.6529-100000@resnet-36-207.dorm.utexas.edu>
Hi. I am writing a IRC bot that uses Net::IRC for its interface.
When anyone talks in the channel, the bot compares what they typed
to some regex's to see if it needs to do anything.
Ex: if ($arg =~ /$mynick/i) - do something if a person says the bots
nick.
I am trying to get the bot to catalog using this: if ($arg =~ /^ #\d/i)
So the bot will only store the sentence if it matches that expr. Here
is an example sentence: "#4 44x [444] blah boo far"
It works fine if the sentence has no formatting, ie: underline,bold,etc
But if the beginning of the sentence (#4) is bold, the bot doesn't index
it. What do I need to do, to make the bot index the bold text as well?
Another problem I have is splitting up that line into different vars.
I would like "#4 45x [432] blah boo far" to be turned into:
4,45,432,blah boo far
but I am having trouble dealing with the white space cause there are
always 2 whites between #4 and 45x.
Each sentence requiring cataloging will have that same format:
#* ***x [***] <any number of words> but there could be any number
of the *'s. Ex: #445 2x [343jO3] <more words>
Any help would be most graciuosly(sp) appreciated.
Thanks,
Alan
------------------------------
Date: Sat, 06 May 2000 01:13:44 GMT
From: clintp@geeksalad.org (Clinton A. Pierce)
Subject: Re: mystery: perl -e '<>;<>'
Message-Id: <clKQ4.60680$h01.444059@news1.rdc1.mi.home.com>
[Posted and mailed]
In article <8evf7u$s72$1@nnrp1.deja.com>,
Daniel Pfeiffer <occitan@esperanto.org> writes:
> when I execute the above programme it waits for two lines of input, at
> least a newline each. Now, when I close the file by typing ^D, on the
> first <>, it sure enough returns the empty string. But the second <>
> again manages to read on that filehandle, even though it had already
> reached eof!
>
> How can this be? Does Perl somehow reopen the filehandle, or at least
> reset its eof-reached-state?
It's documented to work that way. perldoc perlop:
The <> symbol will return undef for end-of-file only once.
If you call it again after this it will assume you are
processing another @ARGV list, and if you haven't set
@ARGV, will input from STDIN.
--
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: Fri, 05 May 2000 16:21:16 -0700
From: Makarand Kulkarni <makarand_kulkarni@My-Deja.com>
Subject: Re: mystery: perl -e '<>;<>'
Message-Id: <3913576C.93FA256E@My-Deja.com>
Daniel Pfeiffer wrote:
> How can this be? Does Perl somehow reopen the filehandle, or at least
> reset its eof-reached-state?
>
From perldoc perlop
The <> symbol will return undef for end-of-file only once.
If you call it again after this it will assume you are
processing another @ARGV list
--
------------------------------
Date: Fri, 05 May 2000 23:32:45 -0700
From: Joydeep Roy Chowdhury <joydeep@corp.sgi.com>
Subject: perl-corba documentation..
Message-Id: <3913BC8D.A3327E39@corp.sgi.com>
i want to learn about implementation of CORBA in Perl. where can I get
started ?
--
Joydeep Roy Chowdhury
E-mail : joydeep@corp.sgi.com
Tel. # : (650) 933 - 6183
------------------------------
Date: Sat, 06 May 2000 07:47:03 GMT
From: nospam.newton@gmx.li (Philip 'Yes, that's my address' Newton)
Subject: Re: program that prints itself
Message-Id: <3913c020.353722044@news.nikoma.de>
On Wed, 3 May 2000 13:52:08 -0400, tadmc@metronet.com (Tad McClellan)
wrote:
>But it does not do that.
Well, yes, it was sort of cheating.
>Easily seen by doing s/quine\.pl/FOO/ in the program,
>and running it as before.
>
>Or, leaving the program as-is and changing the filename.
This happened to me, inadvertently, when I tried out the trick the first
time after having heard it from someone -- I created the file in the
current directory and called 'perl quine.pl', which failed, since there
were no slashes in the text ... so I changed the file and called it with
'perl $PWD/quine.pl'.
>It is rather cool, nonetheless :-)
That's what I though, too, when I saw it :-)
Cheers,
Philip
--
Philip Newton <nospam.newton@gmx.li>
If you're not part of the solution, you're part of the precipitate.
------------------------------
Date: Fri, 05 May 2000 16:58:20 -0700
From: Makarand Kulkarni <makarand_kulkarni@My-Deja.com>
Subject: Re: Reading delimited file into hash
Message-Id: <3913601C.9A889414@My-Deja.com>
> I need to read a text file (/share/answer.txt) into a hash.
why.
You can split each line read from the file using split ()
perldoc -f split
However, you need to decide what part of the line you want
to use as the key in the hash.
------------------------------
Date: Sat, 06 May 2000 05:01:06 GMT
From: Rick Delaney <rick.delaney@home.com>
Subject: Re: seeking a more elegant grouping algorithm than this ...
Message-Id: <3913A849.54EF70F0@home.com>
[posted & mailed]
Eric Smith wrote:
>
> I would like to get more elegantly from here ..
> item1,f,e,sssss
> item1,g,p,ddddd
> item1,h,y,ggggg
> item2,f,e,ddddd
> item2,g,p,eeeee
> item2,r,e,iiiii
> item3,f,e,sssss
> item3,g,p,ddddd
> item3,h,y,ggggg
> item4,t,g,ddddd
> item4,g,p,eeeee
> item4,r,e,iiiii
> item5,f,e,ddddd
> item5,g,p,eeeee
> item5,r,e,iiiii
>
> to here ..
> group1,item1,f,e,sssss
> group1,item1,g,p,ddddd
> group1,item1,h,y,ggggg
> group1,item3,f,e,sssss
> group1,item3,g,p,ddddd
> group1,item3,h,y,ggggg
> group2,item2,f,e,ddddd
> group2,item2,g,p,eeeee
> group2,item2,r,e,iiiii
> group2,item5,f,e,ddddd
> group2,item5,g,p,eeeee
> group2,item5,r,e,iiiii
> group3,item4,t,g,ddddd
> group3,item4,g,p,eeeee
> group3,item4,r,e,iiiii
>
> (the "group[123]" may just as well be a key like "fegphy")
Assuming the data is sorted and in a file and ignoring your code
completely, here is a simple way.
#!/usr/bin/perl -w
use strict;
$_ = <>;
my ($prev, $second, $third) = split /,/;
my $index = "$second$third";
my @current = $_;
my %result;
while(<>) {
my ($first,$second,$third) = split /,/;
if ($first ne $prev) {
push @{ $result{$index} }, @current;
$index = "$second$third";
@current = $_;
}
else {
$index .= "$second$third";
push @current, $_;
}
$prev = $first;
}
push @{ $result{$index} }, @current;
for my $key (sort keys %result) {
print map "$key,$_" => @{ $result{$key} };
}
--
Rick Delaney
rick.delaney@home.com
------------------------------
Date: Sat, 06 May 2000 05:59:12 GMT
From: "Chris Ottinger" <Chris.Ottinger@iname.com>
Subject: VBscript to Perl Conversion
Message-Id: <QwOQ4.9424$_l1.82573@typhoon.kc.rr.com>
Since I am very new to perl and slowly learning I was wondering if there was
anyone who could help me with this minor problem...
What I am trying to do is retrieve a list of DISTRIBUTION LISTS from an
Exchange 5.5 server using ADSI or whatever it takes. My server has many
containers and some with subcontainers. I have located this VBscript that
works...It retrieves all of my distro list throughout the site but I was
wondering if someone could help me convert it tho PERL...I don't need it in
HTML format, that was just the example I found....
If anyone can recommend any good reference material-books websites,
ect...-for learning PERL with ADSI or ADO I would greatly appreciate the
referral....
Thanx for any help in advance.
Chris.
<HTML>
<BODY>
<CENTER><H2>Global Address List</H2><CENTER>
<TABLE ALIGN=RIGHT>
<TR>
<TD>Mailboxes<TD BGCOLOR=RED>     </TD>
<TR>
<TD>Distribution Lists<TD BGCOLOR=GREEN>     </TD>
<TR>
<TD>Custom Recipients<TD BGCOLOR=BLUE>     </TD>
<TR>
</TABLE>
<%
'TO DO : Change the below name to your Exchange server name
'
' Note if you want to use NT Challenge Response authentication this
' will need to be the same machine as the ASP is running on
strServerName = "MyServer"
strUser = Request.ServerVariables("LOGON_USER") 'retrieve the user
if strUser = "" then
Response.Write "You are using Anonymous authentication you will need to
change it so the user can be identified"
Response.End
end if
set oConn = CreateObject("ADODB.Connection")
set oCommand = CreateObject("ADODB.Command")
set oRS = CreateObject("ADODB.Recordset")
oConn.Provider = "ADsDSOObject"
oConn.Open "Ads Provider"
set oCommand.ActiveConnection = oConn 'set the active connection
' Next we will build the LDAP query that will be used to retrieve the
contents of the GAL.
' We will specify which server we want to run the query against,
' a filter for what types of objects we are looking for, the attributes we
would like
' returned, and the type of search
' A filter of (objectClass=person) will return mailboxes, distribution
lists, and custom recipients
strQuery= "<LDAP://" & strServername &
">;(objectClass=person);cn,telephoneNumber,physicalDeliveryOfficeName,title,
company,objectClass,uid;subtree"
oCommand.CommandText = strQuery
oCommand.Properties("Page Size") = 99 'a paged query is used to avoid
Exchange LDAP server limits
set oRS = oCommand.Execute 'Execute the query
' Now we will loop through the results of our query
' and build a table to display the Global Address List
%>
<TABLE BORDER=3>
<TR>
<TH>Display Name<TH>Phone<TH>Office<TH>Title<TH>Company<TH>Alias
<%
While not oRS.EOF
%>
<TR>
<%
' Get the class of the object and set the appropriate color
vObjectClass=oRS.Fields("objectClass")
select case vObjectClass(0)
case "organizationalPerson"
strColor = "RED"
case "groupOfNames"
strColor = "GREEN"
case "Remote-Address"
strColor = "BLUE"
case else
' other may include mailbox agents, Public folders, etc.
strColor = "BLACK"
end select
%>
<TD><FONT COLOR=<%=strColor%>><%=oRS.Fields("cn")%></FONT>
<TD><%=oRS.Fields("telephoneNumber")%>
<TD><%=oRS.Fields("physicalDeliveryOfficeName")%>
<TD><%=oRS.Fields("title")%>
<TD><%=oRS.Fields("company")%>
<TD><%=oRS.Fields("uid")%>
<%
oRS.MoveNext
wend
%>
</TABLE>
</BODY>
</HTML>
------------------------------
Date: Fri, 5 May 2000 22:35:36 -0600
From: "Steven Faria" <safaria@mindspring.com>
Subject: What's become of perl-Expect?
Message-Id: <8f07g1$go2$1@slb7.atl.mindspring.net>
Am having fun thinking that a fine product like Expect may be bundled in a
Perl module. Have heard that such a module has been around since 1998 but
that it may not be ready for prime time. (A follow-on from Comm.pm?)
Looking forward to passwd edits and such. . .any caveats, alternatives?
Steve Faria
------------------------------
Date: Fri, 5 May 2000 22:31:16 -0700
From: Tom Phoenix <rootbeer@redcat.com>
Subject: Re: What's become of perl-Expect?
Message-Id: <Pine.GSO.4.10.10005052227470.6766-100000@user2.teleport.com>
On Fri, 5 May 2000, Steven Faria wrote:
> Am having fun thinking that a fine product like Expect may be bundled in a
> Perl module. Have heard that such a module has been around since 1998 but
> that it may not be ready for prime time. (A follow-on from Comm.pm?)
Am puzzled by the lack of subjects in sentences. Looked on CPAN?
http://search.cpan.org/search?dist=Expect.pm
http://search.cpan.org/
--
Tom Phoenix Perl Training and Hacking Esperanto
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: Fri, 05 May 2000 20:37:45 -0500
From: "David Allen" <s2mdalle@titan.vcu.edu>
Subject: Why are files required to return true values?
Message-Id: <8evt2c$gel$1@bob.news.rcn.net>
If I write a new module called Foo.pm, then of course before I run it,
it has to return a true value. Why is that?
When I write a module, I don't write any code that isn't inside of a
method belonging to the object the module represents.
I guess I could see why perl might want to have code outside
methods for specially labeled blocks and so on, but why a true
value specifically? Most people just put
1;
and they're done with it. why true? Why couldn't you put
undef;
and have it work?
Is there a syntactic or historical reason why perl requires this?
Because all it is to me is something that I have to fire my editor
back up to correct before I can test my module for the first time. :)
--
David Allen
http://opop.nols.com/
----------------------------------------
Our position on software releases...
What is this talk about releases? We do not make software "releases". Our
software escapes, leaving a bloody trail of desginers and quality assurance
people in its wake!
- http://www.enlightenment.org/
------------------------------
Date: Fri, 5 May 2000 21:19:48 -0700
From: Tom Phoenix <rootbeer@redcat.com>
Subject: Re: Why are files required to return true values?
Message-Id: <Pine.GSO.4.10.10005052038290.6766-100000@user2.teleport.com>
On Fri, 5 May 2000, David Allen wrote:
> If I write a new module called Foo.pm, then of course before I run it,
> it has to return a true value. Why is that?
Because modules are descended from libraries, that's why. :-)
When libraries for Perl were being designed, I think the plan was that a
library might rely upon something else (such as certain hardware, or a
data file). Larry chose to allow a library to return a success/failure
code in this way, so that the library could signal that it isn't usable.
Nowadays, we'd simply have the module (or library) die, and let the caller
trap that in an eval.
This _could_ probably be removed in newer perl versions, but you'll still
need to include the true value if you want to be compatible with the older
ones. And maybe, just maybe, there's a module or library out there which
actually uses this check. Is it worth breaking that code to save this
trivial amount of trouble? (Maybe it is, but if Larry thought so, he'd
probably have removed this restriction about five years ago.)
> Why couldn't you put
>
> undef;
>
> and have it work?
Because that's not true. :-) But if you're feeling playful, here are some
alternative values instead of the traditional 1. Some are cooler than
others:
"Why do I have to return a true value?";
"0 but true";
'That silly true value';
"You must really be bored if you're reading my source.";
'false';
007;
[ rand(5) + 1, "additional magic", my $secret, oct(0b00) ];
That last one should be accompanied by a comment to the effect that this
is documented to work in comments in the perl source. "Do not change!" :-)
> Because all it is to me is something that I have to fire my editor
> back up to correct before I can test my module for the first time. :)
Of course, if you're using h2xs to create the skeleton for your module, it
takes care of the return value for you. And if you're not using h2xs,
you're not being lazy enough.
Cheers!
--
Tom Phoenix Perl Training and Hacking Esperanto
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: 6 May 2000 04:31:59 GMT
From: ilya@math.ohio-state.edu (Ilya Zakharevich)
Subject: Re: Why are files required to return true values?
Message-Id: <8f077v$b09$1@charm.magnus.acs.ohio-state.edu>
[A complimentary Cc of this posting was sent to Tom Phoenix
<rootbeer@redcat.com>],
who wrote in article <Pine.GSO.4.10.10005052038290.6766-100000@user2.teleport.com>:
> [ rand(5) + 1, "additional magic", my $secret, oct(0b00) ];
>
> That last one should be accompanied by a comment to the effect that this
> is documented to work in comments in the perl source. "Do not change!" :-)
And remember that this value is available *to the first requirer* of this
module in the given script.
Ilya
------------------------------
Date: Sat, 06 May 2000 00:29:05 -0500
From: "David Allen" <s2mdalle@titan.vcu.edu>
Subject: Re: Why are files required to return true values?
Message-Id: <8f0ak5$26s$1@bob.news.rcn.net>
In article <Pine.GSO.4.10.10005052038290.6766-100000@user2.teleport.com>,
Tom Phoenix <rootbeer@redcat.com> wrote:
> Of course, if you're using h2xs to create the skeleton for your module,
> it takes care of the return value for you. And if you're not using h2xs,
> you're not being lazy enough.
Jeez...I always knew perl was easy, but I hadn't FULLY embraced the
lazy paradigm until a few weeks ago when I wrote a graphical FTP
client using Perl/Tk and Net::FTP in about 2 hours. It could do basic
stuff like login with username/password, do binary/ascii, change local
and remote directories, show lists of files, get and put, and close.
I'm still somewhat used to C where everything is
so agonizingly explicit. Sometimes, I do contract work in perl,
and it feels unethical taking money for some of the stuff I do
considering how much effort it REALLY takes with perl...
--
David Allen
http://opop.nols.com/
----------------------------------------
A closed mouth gathers no foot.
------------------------------
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 2965
**************************************