[15532] in Perl-Users-Digest
Perl-Users Digest, Issue: 2942 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu May 4 00:05:41 2000
Date: Wed, 3 May 2000 21:05:08 -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: <957413108-v9-i2942@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Wed, 3 May 2000 Volume: 9 Number: 2942
Today's topics:
Re: *** To retrieve remote files regularly? <goodman888@hongkong.com>
Re: [RegExp] Matching UPPERCASE words ... (Ilya Zakharevich)
CGI and Radio buttons <rriley@umd5.umd.edu>
Re: CGI and Radio buttons <dburch@teleport.com>
Re: CGI and Radio buttons <dburch@teleport.com>
Re: Help counting things with Perl (Steve)
Re: help! how to delete file? (Steve)
Re: help! how to delete file? (Tad McClellan)
Re: if file already exists then remove... (Ilya Zakharevich)
Re: If slices are so great... <rick.delaney@home.com>
Re: migrate modules to perl5.6.0 (Danny Aldham)
newbie needs help with a mock cgi form and a translator <torduange@geocities.com>
Re: newbie needs help with a mock cgi form and a transl <jeff@vpservices.com>
Re: perl on Windows 32 (ken_i_m)
Re: running perl from command line interface - NT 4.0 <brents@newsguy.com>
Startup script... <kellert@ithink.net>
Re: Startup script... <rootbeer@redcat.com>
TMTOWT set an unset variable (just for fun) <lancon@mail.ce.utexas.edu>
Re: TMTOWT set an unset variable (just for fun) <bwalton@rochester.rr.com>
Re: TMTOWT set an unset variable (just for fun) <fosterd@hartwick.edu>
Re: wait command or similar (Steve)
Why won't Perl's 'use' includes the directory where scr <johnlin@chttl.com.tw>
Re: Why won't Perl's 'use' includes the directory where <rootbeer@redcat.com>
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Thu, 04 May 2000 11:34:50 +0800
From: I'm a good man <goodman888@hongkong.com>
Subject: Re: *** To retrieve remote files regularly?
Message-Id: <3910EFDA.DD55D99D@hongkong.com>
> $myfile =
> fopen("ftp://username:password@mysite.com/images/downloadme.gif", "rb");
> if (!$myfile) {
> print("cannot retrieve file");
> }
I got a problem.
PHP replied no such file or directory.
But it's alright when I used my browser to retrieve it.
What can be the possible causes?
Thanks very much
Rgds,
Fung
------------------------------
Date: 4 May 2000 03:56:38 GMT
From: ilya@math.ohio-state.edu (Ilya Zakharevich)
Subject: Re: [RegExp] Matching UPPERCASE words ...
Message-Id: <8eqsdm$c3e$1@charm.magnus.acs.ohio-state.edu>
[A complimentary Cc of this posting was sent to Larry Rosler
<lr@hpl.hp.com>],
who wrote in article <MPG.137a5fb65581e6b098a9ed@nntp.hpl.hp.com>:
> > Are you sure there are not 7-bit locales around these days?
>
> I *think* ASCII is a mandatory subset of all current character sets
> (except EBCDIC, of course).
I'm pretty sure IBM never (?) changes codepages. If they need to
change one, they would assign a new codepage number to the changed
variant. And the part of locale (charset) we speak about is the
codepage half of the codepage/country settings in IBM-speak.
So old european 7-bit national-ASCII (whatever it means ;-) codepages
still exists somewhere in the libraries of AIX/whatever. And I would
guess that IBM makes it possible to access them via locale mechanism.
Ilya
------------------------------
Date: Wed, 03 May 2000 21:13:40 -0400
From: Winston Riley IV <rriley@umd5.umd.edu>
Subject: CGI and Radio buttons
Message-Id: <3910CEC4.3D670A7F@umd5.umd.edu>
I have an HTML form that hast two radio buttons (both with name 'first'
but with different values).
Everytime I try to read in the value of this button using CGI,
cgi-lib.pl, and $input{'first'}statement, I get a null string. I have
tripled checked varriable spellings, syntax, an everything I can think
of. No luck.
I have many other values passing to program but they are not radio
buttons.
Any suggestions?
Do cgi-lib.pl not support radio buttons?
Any help is greatly appreciated.
<<< Rex Riley >>>
------------------------------
Date: Wed, 03 May 2000 18:28:45 -0700
From: Dan Burch <dburch@teleport.com>
Subject: Re: CGI and Radio buttons
Message-Id: <3910D24C.FEE9B6C@teleport.com>
Winston Riley IV wrote:
> I have an HTML form that hast two radio buttons (both with name 'first'
> but with different values).
>
> Everytime I try to read in the value of this button using CGI,
> cgi-lib.pl, and $input{'first'}statement, I get a null string. I have
> tripled checked varriable spellings, syntax, an everything I can think
> of. No luck.
>
> I have many other values passing to program but they are not radio
> buttons.
>
> Any suggestions?
>
> Do cgi-lib.pl not support radio buttons?
>
> Any help is greatly appreciated.
>
> <<< Rex Riley >>>
I'm just a beginner and I may not be much help, but you might use the
CGI.pm. This is just a little hack, but it might give you some ideas.
#!perl -w
# The first line gives the location of
# ( or pathway to ) the Perl.exe on the local machine.
# Could be #!C:\perl\bin.
# The file must start with #!'location' followed by a blank line
# The -w is a debugger switch that give warnings about bad code.
# use strict is beyond the scope of this comment.
# See the manual pages that come with you perl distribution for more
information.
use strict;
# Use the CommonGatewayInterface Perl library module ( object ).
use CGI;
# Now call the DataBaseInterface module.
use DBI;
# Call the named param function.
CGI::use_named_parameters(1);
# Start a new CGI object named query.
my $query = new CGI();
# Set a variable with the location of the server. Null defaults to
localhost.
# Could be "www.yourdomain.com" or dns number.
my $server= "";
my $server_name = $query->server_name();
# Start a new driver object name driver, using mysql.
my $driver = DBI->install_driver('mysql');
# Now assign an array variable that conatins a list of all the databases
# within the driver object ( mysql databases on the server ).
my @databases = $driver->func($server, '_ListDBs');
# Send a http header to the browser using the CGI query objects standard
header function.
print $query->header();
# Start a html page with the query object's start_html function. Other
attribute can be added.
print $query->start_html(-title=>"Welcome to Dan Burch\'s MySQL
Mini-Serve",
-BGCOLOR=>'white',
- background=>"../images/mt.jpg");
print <<HERE;
<center><h1>Welcome to MySQL Mini-Serve</h1>
<p>Databases avaliable on $server_name :<br>
<table width="100%">
HERE
# Start a form with the method=post and action=database_show.pl.
print $query->startform( "post", "database_show.pl");
foreach (@databases)
{
if($_ eq "RECIPE_DEV01" || $_ eq "REMIND_DEV01" || $_ eq
"ECLECTIC_DATA" )
{
print "<tr><td align=\"center\" colspan=\"4\"\n>";
print "<b>\n";
print $query->radio_group("database", $_);
print "</b>\n";
print "</td></tr>\n";
}
}
print "</table>\n";
# Make a submit button.
print $query->submit("Show Database");
# end the form.
print "</FORM>\n";
print "</body></html>";
------------------------------
Date: Wed, 03 May 2000 19:18:53 -0700
From: Dan Burch <dburch@teleport.com>
Subject: Re: CGI and Radio buttons
Message-Id: <3910DE0D.A9EEEDD3@teleport.com>
Dan Burch wrote:
> Winston Riley IV wrote:
>
> > I have an HTML form that hast two radio buttons (both with name 'first'
> > but with different values).
> >
> > Everytime I try to read in the value of this button using CGI,
> > cgi-lib.pl, and $input{'first'}statement, I get a null string. I have
> > tripled checked varriable spellings, syntax, an everything I can think
> > of. No luck.
> >
> > I have many other values passing to program but they are not radio
> > buttons.
> >
> > Any suggestions?
> >
> > Do cgi-lib.pl not support radio buttons?
> >
> > Any help is greatly appreciated.
> >
> > <<< Rex Riley >>>
>
> I'm just a beginner and I may not be much help, but you might use the
> CGI.pm. This is just a little hack, but it might give you some ideas.
I'm sorry you about my first post. You wanted to read the value not create
the buttom.
This is another hack for reading the form in.
#!perl -w
use strict;
use CGI;
CGI::use_named_parameters(1);
my $query = new CGI();
my $back_button = $query->referer();
my $first_name = $query->param("first_name");
my $last_name = $query->param("last_name");
my $business_name = $query->param("business_name");
my $address = $query->param("address");
my $city = $query->param("city");
my $state = $query->param("state");
my $zip = $query->param("zip");
my $country = $query->param("country");
my $email = $query->param("email");
my $phone = $query->param("phone");
my $fax = $query->param("fax");
my $professional_status = $query->param("professional_status");
my $license = $query->param("license");
my $tax_id = $query->param("tax_id");
print $query->header();
print $query->start_html();
print <<ENDHTML;
<table>
<tr>
<tr>
<td>
Current Customer Information:
<p>
$title $first_name $last_name $professional_status<BR>
$address<br>
$city, $state $zip $country
<P>e-mail: $email<BR>
Phone: $phone<br>
Fax: $fax
<p>$license
ENDHTML
print $query->startform( "post", "confirm.pl");
print $query->hidden("title", $title);
print $query->hidden("first_name", $first_name);
print $query->hidden("last_name", $last_name);
print $query->hidden("address", $address);
print $query->hidden("city", $city);
print $query->hidden("state", $state);
print $query->hidden("zip", $zip);
print $query->hidden("email", $email);
print $query->submit("Confirm Information");
print "</FORM>\n";
print "</td>\n</tr>\n</table>\n";
print $query->end_html();
------------------------------
Date: 4 May 2000 01:46:09 GMT
From: sjlen@ndirect.co.uk (Steve)
Subject: Re: Help counting things with Perl
Message-Id: <slrn8h1g6l.u4a.sjlen@zero-pps.localdomain>
Don't know if you've got access to a linux or unix machine but it
sounds asthough a set of simple grep commands (in a simple shell
script) could do a lot of what you want and maybe just use perl
for the more complicated bits like working out averages etc.
If you can get onto a unix machine have a good read of the grep
manpage.
--
Cheers
Steve email mailto:sjlen@ndirect.co.uk
%HAV-A-NICEDAY Error not enough coffee 0 pps.
web http://www.ndirect.co.uk/~sjlen/
or http://start.at/zero-pps
12:56am up 7 days, 2:57, 3 users, load average: 1.14, 1.08, 1.02
------------------------------
Date: 4 May 2000 00:59:58 GMT
From: sjlen@ndirect.co.uk (Steve)
Subject: Re: help! how to delete file?
Message-Id: <slrn8h1dhg.ts4.sjlen@zero-pps.localdomain>
On Wed, 03 May 2000 16:04:41 -0700, james archer wrote:
>I know I'm gonna get some burn marks on my newbie ass for asking, but
>how does one go about deleting a file in Perl?
>
>I've spent several hours RingTFM and haven't found anything.
You need a book. Do a perldoc -f unlink and be careful.
--
Cheers
Steve email mailto:sjlen@ndirect.co.uk
%HAV-A-NICEDAY Error not enough coffee 0 pps.
web http://www.ndirect.co.uk/~sjlen/
or http://start.at/zero-pps
11:47pm up 7 days, 1:48, 3 users, load average: 1.01, 1.02, 1.00
------------------------------
Date: Wed, 3 May 2000 21:25:31 -0400
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: help! how to delete file?
Message-Id: <slrn8h1kcb.177.tadmc@magna.metronet.com>
On Wed, 03 May 2000 17:03:16 -0700, james archer <snowphoton@mindspring.com> wrote:
>perl is great, but sometimes a little to creative when naming things :o)
>
>somehow i think "erase" or "delete" or "rm" might have been nice...hehehe
Except that unlink() does NOT "erase", "delete", nor "rm" (remove)
the file.
So I think it is you who are too creative :-)
It decrements the link count.
The file is not actually deleted until the link count gets to zero
(to accomodate hard links).
So Perl's name is much more realistic than your suggestions.
--
Tad McClellan SGML Consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: 4 May 2000 03:50:32 GMT
From: ilya@math.ohio-state.edu (Ilya Zakharevich)
Subject: Re: if file already exists then remove...
Message-Id: <8eqs28$bur$1@charm.magnus.acs.ohio-state.edu>
[A complimentary Cc of this posting was sent to Larry Rosler
<lr@hpl.hp.com>],
who wrote in article <MPG.137a59ae938d81ad98a9eb@nntp.hpl.hp.com>:
> I doubt that Perl's bug rate is higher than those.
???? Frankly speaking, I'm stunned. C++ - I do not know. But
comparing Perl with C...
Ilya
------------------------------
Date: Thu, 04 May 2000 02:55:07 GMT
From: Rick Delaney <rick.delaney@home.com>
Subject: Re: If slices are so great...
Message-Id: <3910E795.7A8A3469@home.com>
"M.J.T. Guy" wrote:
>
> Rick Delaney <rick.delaney@home.com> wrote:
> >
> > (@keep[0,1], @keep) = split /,/, $string;
> >
> >That's why slices are so great.
>
> Only if you *know* that the final @keep has two or more elements.
Currently @keep is cleared if split's list has fewer than 2 elements.
> And of course the order of evaluation isn't defined, so you could be
> bitten someday ...
Well, there is that. :-(
But I really can't imagine anyone making
($scalar, @array) = qw(list);
ever result in a non-empty @array (for any values of $scalar, including
$a[0]).
--
Rick Delaney
rick.delaney@home.com
------------------------------
Date: 4 May 2000 01:20:37 GMT
From: danny@hendrix.postino.com (Danny Aldham)
Subject: Re: migrate modules to perl5.6.0
Message-Id: <8eqj95$v6d$1@hendrix.postino.com>
X-Newsreader: TIN [version 1.2 PL2]
Tom Phoenix (rootbeer@redcat.com) wrote:
: This isn't trivial. Alas. But you can find all the .pm files along the old
: @INC, using a technique like the one shown here:
: http://www.perlfaq.com/faqs/id/205
: Then you can check to see which of those modules is already available
: along the new @INC using a similar technique. After that, it shouldn't be
: too hard to run CPAN to install the module.
Tom, I cannot thank you enough. Your pointer lead me to this script:
#!/usr/local/bin/perl5.005_03 -w
use File::Find ;
foreach $start (@INC) { find(\&modules,$start) ; }
sub modules {
if (-d && /^[a-z]/) { $File::Find::prune = 1 ; return }
return unless /\.pm$/ ;
my $filename = "$File::Find::dir/$_";
$filename =~ s!^$start/!! ;
$filename =~ s!\.pm$!!;
$filename =~ s!/!::!g;
print "$filename\n";
}
the output of which I put into /tmp/mods.old . Then I wrote:
#!/usr/bin/perl -w
use CPAN ;
open (LIST,"/tmp/mods.old") ;
while (<LIST>) {
chomp ;
print "$_ \n";
install $_ ;
}
which took that file as input to CPAN and reinstalled all the modules.
I am right now doing the Snoopy happy dance. Thankyou again,
--
Danny Aldham Providing Certified Internetworking Solutions to Business
www.postino.com E-Mail, Web Servers, Mail Lists, Web Databases, SQL & Perl
------------------------------
Date: Wed, 03 May 2000 22:53:35 -0600
From: calla <torduange@geocities.com>
Subject: newbie needs help with a mock cgi form and a translator
Message-Id: <3910F43F.BACB181F@geocities.com>
i have two perl-based projects i need to finish. one involves a
pull-down menu/form, what have you. it has some preselected choices for
the user. the user picks one and hits submit. then the submitted form
spits out a graphic. i want to use perl to store the (tiny) database
containing the choices and when a choice is sent to the server, have a
perl script retrieve the matching graphic. i mainly need to know if the
graphics have to be in the same place as the list of choices and if so,
how you lay that out in perl.
the second project basically has a little form where the user puts in
an english word. perl runs through a text database on the server and
spits out the translated word (we'll call the other language foo).
alternatively, they can put in a foo word and get the english
translations. whichever. now, can cgi.pm do this for both things and if
not, what tweaking will i need to do to have the right thing output to
the user. and they're both in html pages. w00. my confusion isn't
with the basic cgi form, but how to retrieve linked data (graphics in
one case, sets of words in another)...unless i'm also confused about the
basic cgi form, heh. anyhow, any help would be ultra appreciated.
s.
ps: this is just curiosity, but could one use perl to draw (line
only)graphics and then retrieve them and if so, how much more work would
i be inflicting on myself?
------------------------------
Date: Wed, 03 May 2000 20:59:38 -0700
From: Jeff Zucker <jeff@vpservices.com>
Subject: Re: newbie needs help with a mock cgi form and a translator
Message-Id: <3910F5AA.C6EA2E63@vpservices.com>
calla wrote:
>
> i have two perl-based projects i need to finish. one involves a
> pull-down menu/form, what have you. it has some preselected choices for
> the user. the user picks one and hits submit. then the submitted form
> spits out a graphic. i want to use perl to store the (tiny) database
> containing the choices and when a choice is sent to the server, have a
> perl script retrieve the matching graphic. i mainly need to know if the
> graphics have to be in the same place as the list of choices and if so,
> how you lay that out in perl.
>
> the second project basically has a little form where the user puts in
> an english word. perl runs through a text database on the server and
> spits out the translated word (we'll call the other language foo).
> alternatively, they can put in a foo word and get the english
> translations. whichever. now, can cgi.pm do this for both things and if
> not, what tweaking will i need to do to have the right thing output to
> the user. and they're both in html pages. w00. my confusion isn't
> with the basic cgi form, but how to retrieve linked data (graphics in
> one case, sets of words in another)...unless i'm also confused about the
> basic cgi form, heh. anyhow, any help would be ultra appreciated.
CGI.pm can handle everything you've mentioned in the way of creating the
forms, reading the results of the forms, and writing back out the
response pages. To know how to get it to do those things, you pretty
much have to know how to do the HTML to do those things and just tell
CGI.pm to produce that HTML. The part where Perl comes in is in the
database retrieval. If this is a one time thing and/or it's a small
amount of data you can do it all right in the script e.g. create a hash
that has the English word as the key and the other language word as the
value. Or the name of the image as the key and the location of the
image as the value. Or you can put that information in a file and parse
the file, feeding that information into the hash. Or, for a longer term
solution, you can create a flat file database (comma separated, or pipe
"delimited", or tab "delimited, etc.) and use the DBD::RAM or DBD::CSV
modules to access them.
> ps: this is just curiosity, but could one use perl to draw (line
> only)graphics and then retrieve them
Yes, the GD module and its associates do that.
> and if so, how much more work would
> i be inflicting on myself?
I suppose that depends on how complex the image is and how much fun you
might have tweaking it.
Good luck!
--
Jeff
------------------------------
Date: Thu, 04 May 2000 03:34:47 GMT
From: ken_i_m@linuxstart.com (ken_i_m)
Subject: Re: perl on Windows 32
Message-Id: <3910edfd.72417927@news.mcn.net>
On Tue, 02 May 2000 16:38:49 -0700, Dan Burch <dburch@teleport.com>
wrote:
>> I have active perl installed but have been reading that to run under
>> win32 I need to recompile from the source, I have also seen from various
>> other posts that people are successfully running on Windows using
>> "mod_perl", is this what the recompiled perl is referred to as? is this
>> "recompiled" source available for download anywhere?
I have been using apache/mod_perl for a couple of months now on Win98.
I got it from here: ftp://theoryx5.uwinnipeg.ca/pub/other/
This is a Win32 binary. No compiling necessary. Set the Apache conf to
loopback 127.0.0.1
------------------------------
Date: Wed, 03 May 2000 22:41:00 -0500
From: Brent Stroh <brents@newsguy.com>
Subject: Re: running perl from command line interface - NT 4.0
Message-Id: <j7s1hsc17ftlp9lchfefvsu1ahna4n0r43@4ax.com>
Paul Spitalny <pauls@pauls.seanet.com> wrote:
>Hi,
>I have successfully installed activeware perl. I appended the path
>variable on my system ton incoude the directory where all my perl
>scripts live. Then I did this:
>
> ASSOC .pl=PerlScript
> FTYPE PerlScript=[full path to perl]\perl.exe %1 %*
>
>Let's say I have a fred.pl script that expects two arguments. Now, from
>the command line interface , in any directory, I should be able to
>type::
>
>fred 2 2 (where 2 and 2 are the args passed by $ARGV[0] and $ARGV[1])
>
>This used to work for me, but now it doesn't. Any tips
You're close. :)
On NT, you also need to add .PL to the value of %PATHEXT%. It should look
something like this:
.COM;.EXE;.BAT;.CMD;.PL
Then, the .PL extension is treated like the others in the list - you don't
have to type it anymore.
Hope this helps.
------------------------------
Date: Wed, 3 May 2000 23:36:19 -0700
From: "Todd Keller" <kellert@ithink.net>
Subject: Startup script...
Message-Id: <sh1rk9oc3432@corp.supernews.com>
Greets! I'm pretty experienced with perl right now, but I've just gotten
hung up
on one issue and I'm hoping to get some direction on the best way to do
this.
I want to start a process that writes to a log file in background (yes, this
is a
MUD startup script, rewritten in perl), but I can't get it to write to the
file after
the mud starts up. Here's what I have so far.
...
# just get the hour, minute, sec
$index=`date +%H%M%S`;
$logfile="../log/${index}.log";
system("../src/rom $port >&! ../log/$file");
}
This starts the mud when run, runs fine, I connect and everything with the
logfile created, but I can't get it to write to that file via the normal
routine, which (in tcsh) looks like this:
index=`date +%H%M%S.log`
logfile=../log/$index.log
touch $logfile
../src/rom $port >&! $logfile
Any help is greatly appreciated. Thanks in advance. =)
--Todd
------------------------------
Date: Wed, 3 May 2000 20:45:58 -0700
From: Tom Phoenix <rootbeer@redcat.com>
Subject: Re: Startup script...
Message-Id: <Pine.GSO.4.10.10005032041530.6766-100000@user2.teleport.com>
On Wed, 3 May 2000, Todd Keller wrote:
> system("../src/rom $port >&! ../log/$file");
> I can't get it to write to that file via the normal routine, which (in
> tcsh) looks like this:
> ../src/rom $port >&! $logfile
What's that '>&!' doing in there? That looks like a tcsh thing, but
system() runs everything through the One True /bin/sh. I'm not a shell
expert, but does this fix it?
system("../src/rom $port > ../log/$file 2>&1");
If that doesn't work, you could use the list form of system to call tcsh
after all. Maybe like this?
system('tcsh', '-cf', "../src/rom $port >&! ../log/$file");
Cheers!
--
Tom Phoenix Perl Training and Hacking Esperanto
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: Wed, 03 May 2000 20:15:15 -0500
From: Donald Lancon <lancon@mail.ce.utexas.edu>
Subject: TMTOWT set an unset variable (just for fun)
Message-Id: <3910CF23.5D6E6388@mail.ce.utexas.edu>
This is more an essay than anything. Or maybe a poll. I figured I
might turn up some interesting suggestions if I posted it here, so.....
Sorry if anyone thinks this is misuse of the newsgroup.
The task: Set a variable to a given value if it doesn't already have a
value, otherwise leave it alone.
The question: How many ways can you come up with to do it and which is
the "best" way?
To be specific, let the variable be $foo and let the "given value" be
"dog". Also, assume that it's sufficient to check the truth value of
$foo, not whether it's defined.
I'm interested in short, "simple" -- although not necessarily obvious --
solutions. That is, I'm not looking for an Obfuscated Perl Contest
winner. :-)
By way of example, the "most obvious" way (perhaps) would be something
like:
if (not $foo) { $foo = "dog" }
There are various ways of using this same basic approach but with
"trivial" differences. For example:
if (! $foo) { $foo = "dog" }
Those sorts of variations aren't very interesting. However, another way
that is "non-trivially" different (although logically equivalent, of
course) is:
$foo = "dog" unless $foo;
which is how I, personally, prefer to do it. :-)
So... how many other ways can you come up with?
[I'm about to give my answers if you want to think about it first.....]
Here are the ways I thought of, including the two above:
$foo = "dog" unless $foo; # or "if not $foo", or "if ! $foo"
if (not $foo) { $foo = "dog" } # or "if (! $foo)", or "unless ($foo)"
$foo or $foo = "dog"; # or use "||" with parentheses
not $foo and $foo = "dog"; # or "! $foo", or "&&" with paren's
$foo = $foo ? $foo : "dog"; # I like this one :-P
$foo = $foo || "dog";
$foo ||= "dog"; # didn't think of this till I RTFM :-)
You may consider the differences between the 3rd and 4th ways to be
"trivial", but I decided to list them separately anyway, mainly for
space reasons. I guess the last way is about as compact as you can get!
Note, BTW, that the first 5 ways can easily be modified to check for
definedness rather than just "truth". The last 2, because they involve
checking and assigning "at the same time", cannot.
What other "neat" ways of doing it haven't I thought of?
--
Donald Lancon
------------------------------
Date: Thu, 04 May 2000 02:26:19 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: TMTOWT set an unset variable (just for fun)
Message-Id: <3910DEDB.E327B68@rochester.rr.com>
Donald Lancon wrote:
...
> $foo = "dog" unless $foo; # or "if not $foo", or "if ! $foo"
> if (not $foo) { $foo = "dog" } # or "if (! $foo)", or "unless ($foo)"
> $foo or $foo = "dog"; # or use "||" with parentheses
> not $foo and $foo = "dog"; # or "! $foo", or "&&" with paren's
> $foo = $foo ? $foo : "dog"; # I like this one :-P
> $foo = $foo || "dog";
> $foo ||= "dog"; # didn't think of this till I RTFM :-)
...
> What other "neat" ways of doing it haven't I thought of?
...
> Donald Lancon
Well, there's:
$foo?0:($foo='dog');
--
Bob Walton
------------------------------
Date: Wed, 3 May 2000 22:49:22 -0400
From: Decklin Foster <fosterd@hartwick.edu>
Subject: Re: TMTOWT set an unset variable (just for fun)
Message-Id: <20000503224922.A27651@photek.dhs.org>
Bob Walton <bwalton@rochester.rr.com> writes:
> Well, there's:
>
> $foo?0:($foo='dog');
Here's a variation:
$foo?(undef):($foo)=("dog");
Which just goes to show that while there may be MTOWTDI, that doesn't
mean some of them shouldn't be taken out and shot. ;-)
--
Written with 100% free software. Please support the following websites:
www.debian.org www.noamazon.com www.gnu.org www.opendvd.org lpf.ai.mit.edu
------------------------------
Date: 4 May 2000 00:59:58 GMT
From: sjlen@ndirect.co.uk (Steve)
Subject: Re: wait command or similar
Message-Id: <slrn8h1dmu.ts4.sjlen@zero-pps.localdomain>
On Wed, 03 May 2000 22:40:48 GMT, Jonas Nilsson wrote:
>Hi.
>Are there any command to halt the script? I want a script to wait for
>5 seconds before it continue.
Do a perldoc -f sleep this section of the documentation explains it's
use.
--
Cheers
Steve email mailto:sjlen@ndirect.co.uk
%HAV-A-NICEDAY Error not enough coffee 0 pps.
web http://www.ndirect.co.uk/~sjlen/
or http://start.at/zero-pps
11:47pm up 7 days, 1:48, 3 users, load average: 1.01, 1.02, 1.00
------------------------------
Date: Thu, 4 May 2000 11:34:12 +0800
From: "John Lin" <johnlin@chttl.com.tw>
Subject: Why won't Perl's 'use' includes the directory where script is run?
Message-Id: <8eqr58$8ri@netnews.hinet.net>
Dear all,
I encounter this kind of situation again and again.
For a large program, I usually break it into small modules
(in the same directory). For example, in directory /test/here:
Part1.pm
Part2.pm
And 'use' them in main.pl:
use Part1;
use Part2;
If I run it from that directory, it is OK.
%/test/here> main.pl OK!!!
But if not (e.g: a PATH search, or run from another directory)
I will get error messages.
%/other/directory> /test/here/main.pl
Can't locate Part1.pm in @INC
BEGIN failed--compilation aborted
So I have to modify main.pl as
BEGIN { chdir '/test/here' or die $! }
use Part1;
use Part2;
It works. But, isn't it ugly?
Why won't Perl's 'use' includes the directory where script is run?
What is your suggestion for this situation?
Thank you.
John Lin
------------------------------
Date: Wed, 3 May 2000 20:50:51 -0700
From: Tom Phoenix <rootbeer@redcat.com>
Subject: Re: Why won't Perl's 'use' includes the directory where script is run?
Message-Id: <Pine.GSO.4.10.10005032046220.6766-100000@user2.teleport.com>
On Thu, 4 May 2000, John Lin wrote:
> Subject: Why won't Perl's 'use' includes the directory where script is run?
By default, it normally does.
> BEGIN { chdir '/test/here' or die $! }
> It works. But, isn't it ugly?
Well, yes. You should probably use 'use lib' instead.
> Why won't Perl's 'use' includes the directory where script is run?
It does include the current working directory, normally. Is that the one
you mean, or do you mean the one where your program happens to be stored?
(If that's it, maybe you want FindBin.)
> What is your suggestion for this situation?
Install all of your modules in, say, /home/waldo/.lib and 'use lib'
whenever you want. Unless waldo gets upset. Cheers!
--
Tom Phoenix Perl Training and Hacking Esperanto
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
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 2942
**************************************