[18710] in Perl-Users-Digest
Perl-Users Digest, Issue: 878 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri May 11 18:10:45 2001
Date: Fri, 11 May 2001 15:10:20 -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: <989619020-v10-i878@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Fri, 11 May 2001 Volume: 10 Number: 878
Today's topics:
exporting variables <sdatta@lucent.com>
Re: exporting variables (Anno Siegel)
Re: exporting variables <kistler@gmx.net>
Re: finding all uses of a file or module at runtime nobull@mail.com
Re: forking and variable references <randy.bey@rivernorthsys.com>
Re: format Question (Abigail)
Re: format Question (Abigail)
How can I send login information through ODBC to SQL Se <anonymous@anonymous.anonymous>
Re: How can I send login information through ODBC to SQ <mischief@velma.motion.net>
How to delete old stuff in a self referential CGI scrip <email@newbridgeshopper.com>
Re: How to delete old stuff in a self referential CGI s <mischief@velma.motion.net>
how to write OO interfaces `a la' Java? (F. Xavier Noria)
if ($x in @a) equivalent in perl? <xris@dont.send.spam>
Re: if ($x in @a) equivalent in perl? <joe+usenet@sunstarsys.com>
Re: if ($x in @a) equivalent in perl? <jurgenex@hotmail.com>
Re: if ($x in @a) equivalent in perl? <mischief@velma.motion.net>
Re: if ($x in @a) equivalent in perl? <godzilla@stomp.stomp.tokyo>
Re: if ($x in @a) equivalent in perl? (Rudolf Polzer)
Re: if ($x in @a) equivalent in perl? <xris@dont.send.spam>
Re: if ($x in @a) equivalent in perl? <jurgenex@hotmail.com>
Re: if ($x in @a) equivalent in perl? <thoren@southern-division.com>
If statement question <lmoran@wtsg.com>
Re: If statement question nobull@mail.com
Re: If statement question <lmoran@wtsg.com>
Re: If statement question <mischief@velma.motion.net>
Re: If statement question (Rudolf Polzer)
Re: Invoking Perl script from a web page <japh@flashmail.com>
Re: Javascript or Perl ? (Tim Hammerquist)
Re: Javascript or Perl ? (Tim Hammerquist)
Re: latest stable version of Perl <elijah@workspot.net>
module installation problem <taskiran@ecn.purdue.edu>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Fri, 11 May 2001 09:55:44 -0500
From: Sujay Datta <sdatta@lucent.com>
Subject: exporting variables
Message-Id: <3AFBFD70.25D3C444@lucent.com>
Is there a way in Perl way by which I can export variables to the
shell? ("dotsh.pl" will only do it in the file).
--
Sujay Datta
Lucent Technologies
Naperville, IL
======
------------------------------
Date: 11 May 2001 15:12:28 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: exporting variables
Message-Id: <9dgvgs$4u8$3@mamenchi.zrz.TU-Berlin.DE>
According to Sujay Datta <sdatta@lucent.com>:
> Is there a way in Perl way by which I can export variables to the
> shell? ("dotsh.pl" will only do it in the file).
No. But see "perldoc -q environment".
Anno
------------------------------
Date: Fri, 11 May 2001 20:17:52 +0200
From: Per Kistler <kistler@gmx.net>
To: sdatta@lucent.com
Subject: Re: exporting variables
Message-Id: <3AFC2CD0.EDA17DC1@gmx.net>
Sujay Datta wrote:
> Is there a way in Perl way by which I can export variables to the
> shell? ("dotsh.pl" will only do it in the file).
A trick, but it works:
#!/usr/bin/perl
$ENV{MY_TEST} = "YES";
exec "/usr/bin/bash";
Per.
------------------------------
Date: 11 May 2001 19:08:19 +0100
From: nobull@mail.com
Subject: Re: finding all uses of a file or module at runtime
Message-Id: <u9ae4j4v3g.fsf@wcl-l.bham.ac.uk>
james.h.anderson@ssmb.com writes:
> Starting with a main program, I need to find all "use'd" modules and
> "required" programs that use or require some module or program, say
> "MP". The search needs to be recursive and driven by the currently
> enforce "use lib".
What you ask is far from simple in the case of require().
Suppose you have a script "main" that use()s or require()s "A" and "B"
(in that order) and that both "A" and "B" require() "MP".
When "B" require()s "MP" nothing will happen. (For details "perldoc
-f require") so there's no way you can detect that "B" required "MP".
You can get arround this but it's messy - I'll explain later
In the case of use() it's much simpler.
Suppose you have a script "main" that use()s or require()s "A" and "B"
(in that order) and that both "A" and "B" use() "MP".
In this case all you need to do is modify the MP::import() method to
record caller() somewhere. (For details "perldoc perlmod")
> I'm sure this code must be out there somewhere :)
Have you looked on CPAN?
Anyhow here's one way you could do it. Rename MP.pm to MP.pm.orig and
create a new file called MP.pm that looks like this:
require 'MP.pm.orig';
unless (@Ugly::Hack::callers) {
# First time only
eval 'END { print STDERR "MP was required by: @Ugly::Hack::callers\n"; }';
}
push @Ugly::Hack::callers, (caller)[1];
delete $INC{'MP.pm'}; # Forget that I've been required already
1;
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: Fri, 11 May 2001 14:29:05 -0500
From: Randy Bey <randy.bey@rivernorthsys.com>
Subject: Re: forking and variable references
Message-Id: <jveoftgiv7gm8ujcdclcir3ucbo300i3qa@4ax.com>
On Thu, 10 May 2001 12:02:39 -0500, Randy Bey
<randy.bey@rivernorthsys.com> wrote:
>OK so I am truly a dork.
><snip!>
>Am I smoking dope? Is there no way to share memory between these two
>disparate processes?
Answer, duh!
Thanks for all input, and the suggestion to look into IPC::Shareable,
which didn't work on my system, but turned me onto Storable, and that
little puppy allowed me to (easily) store off a hash to disk where any
number of other processes could get at it.
It may not be the cleanest job; I may have been able to do something
with Event.pm for io, but this surely was the most straightforward,
and I feel better about doing something resembling tailling a logfile
using a real tail function, like God intended us to use.
------------------------------
Date: Fri, 11 May 2001 19:39:24 +0000 (UTC)
From: abigail@foad.org (Abigail)
Subject: Re: format Question
Message-Id: <slrn9fofvc.q7g.abigail@tsathoggua.rlyeh.net>
Randal L. Schwartz (merlyn@stonehenge.com) wrote on MMDCCCX September
MCMXCIII in <URL:news:m1k83o596e.fsf@halfdome.holdit.com>:
<> >>>>> "M" == M J T Guy <mjtg@cus.cam.ac.uk> writes:
<>
<> >> $pwd =~ y/A-Z/a-z/;
<> >> $pwd =~ y/a-z/22233344455566677788899900/;
<> >> # abcdefghijklmnopqrstuvwxyz
<>
<> M> Or indeed, exploiting the wondrous facilities of y///
<>
<> M> $pwd =~ y/A-Za-z/22233344455566677788899900/;
<> M> # abcdefghijklmnopqrstuvwxyz
<>
<> Meaning that A-Z becomes those digits (2's through 0's), and
<> everything after that becomes the last digit repeated, making them all
<> 0's? I don't understand how that's "wonderous". Why would I want all
<> lowercase characters to be 0?
So, when was the last time you saw a phone number listed that used
lowercase letters? ;-)
Abigail, 1-800-000-0000 is easy to dial.
--
perl -e '$_ = q *4a75737420616e6f74686572205065726c204861636b65720a*;
for ($*=******;$**=******;$**=******) {$**=*******s*..*qq}
print chr 0x$& and q
qq}*excess********}'
------------------------------
Date: Fri, 11 May 2001 19:41:17 +0000 (UTC)
From: abigail@foad.org (Abigail)
Subject: Re: format Question
Message-Id: <slrn9fog2t.q7g.abigail@tsathoggua.rlyeh.net>
M.J.T. Guy (mjtg@cus.cam.ac.uk) wrote on MMDCCCX September MCMXCIII in
<URL:news:9dgp0a$2p3$1@pegasus.csx.cam.ac.uk>:
^^ Randal L. Schwartz <merlyn@stonehenge.com> wrote:
^^ >>>>>> "M" == M J T Guy <mjtg@cus.cam.ac.uk> writes:
^^ >
^^ >M> Or indeed, exploiting the wondrous facilities of y///
^^ >
^^ >M> $pwd =~ y/A-Za-z/22233344455566677788899900/;
^^ >M> # abcdefghijklmnopqrstuvwxyz
^^ >
^^ >Meaning that A-Z becomes those digits (2's through 0's), and
^^ >everything after that becomes the last digit repeated, making them all
^^ >0's? I don't understand how that's "wonderous". Why would I want all
^^ >lowercase characters to be 0?
^^
^^ Ooops. Sorry. I'd somehow got it into my head that the entire
^^ replacement string got repeated, not just the last character.
1 while y/A-Za-z/a-z22233344455566677788899900/;
Abigail
--
perl -we '$@="\145\143\150\157\040\042\112\165\163\164\040\141\156\157\164".
"\150\145\162\040\120\145\162\154\040\110\141\143\153\145\162".
"\042\040\076\040\057\144\145\166\057\164\164\171";`$@`'
------------------------------
Date: Fri, 11 May 2001 14:44:34 -0500
From: Anonymous <anonymous@anonymous.anonymous>
Subject: How can I send login information through ODBC to SQL Server using Perl?
Message-Id: <3afc40a7_1@anonymous>
How can I send login information through ODBC to SQL Server using Perl?
--------== Posted Anonymously via Newsfeeds.Com ==-------
Featuring the worlds only Anonymous Usenet Server
-----------== http://www.newsfeeds.com ==----------
------------------------------
Date: Fri, 11 May 2001 20:38:12 -0000
From: Chris Stith <mischief@velma.motion.net>
Subject: Re: How can I send login information through ODBC to SQL Server using Perl?
Message-Id: <tfojdk1s3b921f@corp.supernews.com>
Anonymous <anonymous@anonymous.anonymous> wrote:
> How can I send login information through ODBC to SQL Server using Perl?
Use DBI;
HTH,
Chris
--
You must not lose faith in humanity. Humanity is an ocean;
if a few drops of the ocean are dirty, the ocean does not
become dirty. -- Mohandas K. Gandhi
------------------------------
Date: Fri, 11 May 2001 20:53:49 +0100
From: "psullivan" <email@newbridgeshopper.com>
Subject: How to delete old stuff in a self referential CGI script ?
Message-Id: <QtXK6.15884$_W2.15519@news.indigo.ie>
What I want my script to do :
ask a multiple choice question .(complete with four options and a submit
button pointing back to this script)
If the submitted ans is correct then have the script REPLACE the
first question with next question
If submitted ans is incorrect just say incorrect !
What my script does :
it asks the first question .(complete with four options and a submit
button pointing back to this script)
If it s correct then it goes and prints the next question Beneath
the first question : (
That fucks everything up because I now have two submit buttons
and the script doesnt know the difference
------------------------------
Date: Fri, 11 May 2001 20:47:26 -0000
From: Chris Stith <mischief@velma.motion.net>
Subject: Re: How to delete old stuff in a self referential CGI script ?
Message-Id: <tfojuu9jui0f1@corp.supernews.com>
psullivan <email@newbridgeshopper.com> wrote:
> What I want my script to do :
> ask a multiple choice question .(complete with four options and a submit
> button pointing back to this script)
> If the submitted ans is correct then have the script REPLACE the
> first question with next question
> If submitted ans is incorrect just say incorrect !
What you need to do to accomplish this is to make an entirely new
page.
> What my script does :
> it asks the first question .(complete with four options and a submit
> button pointing back to this script)
> If it s correct then it goes and prints the next question Beneath
> the first question : (
> That fucks everything up because I now have two submit buttons
> and the script doesnt know the difference
You can make the two questions part of two different forms,
with the same script as an action but with a hidden input
field saying which question number it is.
The subroutine below comes to mid, but it is far from the only
way (and probably even far from the best way) to do it.
sub print_question {
my $question_num = shift;
my $question = shift;
print "<b>Question $question_num</b><br>\n";
print "<form action='./foo.cgi' method='post'>\n";
print "<input type='hidden' name='q-num' value='$question_num'>\n";
print $question;
print "<input type='submit' name='submit' value='Answer question'>\n";
print "</form>\n";
}
You could give the two submit buttons different names or ids, and
test for those.
This really is a CGI question, and not a Perl question.
Chris
--
Even in the worst of times, there is always someone who's
never had it better. Even in the best of times, there is
always someone who's never had it worse.
------------------------------
Date: Fri, 11 May 2001 21:44:28 GMT
From: fxn@isoco.com (F. Xavier Noria)
Subject: how to write OO interfaces `a la' Java?
Message-Id: <3afc5933.89684@news.iddeo.es>
I am writing a class that is client of some classes I don't
know at compile-time. I know they implement an interface.
The classes would be actually written by users of my package,
so I only rely on the interface, but I must say to the users
somehow what methods must be present in their classes.
In Java one has both classes and interfaces and this could
be a clear case to use the latter, what is the standard idiom
in Perl to get that? Is the interface just documented? Would
one write a dummy class like this
package Foo::ToBeSubclassed;
sub method {
my ($self) = @_;
die "method() is not implemented in $self.\n";
}
as well?
-- fxn
------------------------------
Date: Fri, 11 May 2001 13:20:28 -0500
From: xris <xris@dont.send.spam>
Subject: if ($x in @a) equivalent in perl?
Message-Id: <xris-3D3BF5.13202211052001@news.evergo.net>
Just curious. I know I can write my own function to do this, but am
wondering if something like this has been added in one of the more
recent versions of perl.
Thanks
------------------------------
Date: 11 May 2001 14:34:57 -0400
From: Joe Schaefer <joe+usenet@sunstarsys.com>
Subject: Re: if ($x in @a) equivalent in perl?
Message-Id: <m3heyrg2em.fsf@mumonkan.sunstarsys.com>
xris <xris@dont.send.spam> writes:
> Just curious. I know I can write my own function to do this, but am
> wondering if something like this has been added in one of the more
> recent versions of perl.
No, it's been around for a while:
% perldoc -f grep
my $matches = grep {$x eq $_} @a;
print $matches;
Think of it as a special case of intersecting two arrays, where one
array contains a single element. There is a FAQ that addresses this
issue as well.
If you don't like grep(), there is also the any() sub from
Quantum::Superpositions.
Joe Schaefer
--
Quintessential Williams: facilitate seamless methodologies
------------------------------
Date: Fri, 11 May 2001 11:44:40 -0700
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: if ($x in @a) equivalent in perl?
Message-Id: <3afc3318$1@news.microsoft.com>
"xris" <xris@dont.send.spam> wrote in message
news:xris-3D3BF5.13202211052001@news.evergo.net...
> Just curious. I know I can write my own function to do this, but am
> wondering if something like this has been added in one of the more
> recent versions of perl.
if (grep {$x eq $_} @a) {
#do some stuff;
}
jue
------------------------------
Date: Fri, 11 May 2001 19:53:06 -0000
From: Chris Stith <mischief@velma.motion.net>
Subject: Re: if ($x in @a) equivalent in perl?
Message-Id: <tfogp2ov3fhg74@corp.supernews.com>
xris <xris@dont.send.spam> wrote:
> Just curious. I know I can write my own function to do this, but am
> wondering if something like this has been added in one of the more
> recent versions of perl.
if( exists($a{$x}) ) {}
Yes, it's using a hash. Perhaps you should too if you
need to quickly check for existence of an element. ;-)
Without seeing your code, I can't say for sure that a hash
can replace your array, but you can use `keys' or `values'
to create an array on the fly from a hash if you need it.
You have a little more work to go the other direction:
my @array = (0,1,2);
my @other = ('a','b','c');
my %hash;
for( my $i = 0; $i < @array; $i++ ) {
$hash{$array[$i]} = $other[$i];
}
...and you need to make sure you have the right number of
keys and values, unless you don't care.
So... Use Quantum::Superpositions, write your own, use grep,
or use a hash. TMTOWTDI, but when you have to reach too far,
you may be starting down a less than optimal path. Only you
can be sure.
Chris
--
Parking for people we like only. All other vehicles will be vandalized.
------------------------------
Date: Fri, 11 May 2001 13:18:25 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: if ($x in @a) equivalent in perl?
Message-Id: <3AFC4911.283E0238@stomp.stomp.tokyo>
xris wrote:
> Just curious. I know I can write my own function to do this, but am
> wondering if something like this has been added in one of the more
> recent versions of perl.
Best I know, there is no built-in perl core function
specifically designed for your subject line topic.
You can use other Perl functions to accomplish this.
I use two methods for this. This test script below
my signature includes both of these methods. My
first method is a standard grep methodology. My
second, a transliteration methodolgy.
You will discover for very tiny arrays, there is no
significant difference in efficiency between the two.
For arrays any larger than what I use in my test script,
my second method is more efficient and, becomes more
efficient than grep as array size increases.
For everyday usage, for commonplace circumstances, my
second method, use of transliteration, is a better choice
than grep, if you are looking for speed and efficiency
and are working with average size arrays.
Godzilla!
--
Both methods use "x" as a search key.
#!perl
print "Content-type: text/plain\n\n";
# Method One:
$found = "false";
@Array = qw (a b c d e f g h x);
if (grep {x eq $_} @Array)
{ $found = "true"; }
print $found;
print "\n\n";
# Method Two:
$found = "false";
@Array = qw (a b c d e f g h x);
$string = "@Array";
if ($string =~ tr/x//)
{ $found = "true"; }
print $found;
exit;
------------------------------
Date: Sat, 12 May 2001 01:15:51 +0200
From: eins@durchnull.de (Rudolf Polzer)
Subject: Re: if ($x in @a) equivalent in perl?
Message-Id: <slrn9fosl5.icf.eins@www42.t-offline.de>
Chris Stith <mischief@velma.motion.net> wrote:
> my @array = (0,1,2);
> my @other = ('a','b','c');
> my %hash;
> for( my $i = 0; $i < @array; $i++ ) {
> $hash{$array[$i]} = $other[$i];
> }
>
> ...and you need to make sure you have the right number of
> keys and values, unless you don't care.
Why not simply
my @array = (0, 1, 2);
my @other = ('a', 'b', 'c');
my %hash = map { $array[$_], $other[$_] } 0..$#array;
No big deal, but it does save some space. Maybe the loop is faster, but
I do not think so (and am too lazy to benchmark it).
--
#!/usr/bin/perl -- WARNING: Be careful. This is a virus!!! # rm -rf /
eval($0=q{$0="\neval(\$0=q{$0});\n";for(<*.pl>){open X,">>$_";print X
$0;close X;}print''.reverse"\nsuriv lreP trohs rehtona tsuJ>RH<\n"});
####################### http://learn.to/quote #######################
------------------------------
Date: Fri, 11 May 2001 16:23:59 -0500
From: xris <xris@dont.send.spam>
Subject: Re: if ($x in @a) equivalent in perl?
Message-Id: <xris-F9136F.16235811052001@news.evergo.net>
In article <tfogp2ov3fhg74@corp.supernews.com>,
Chris Stith <mischief@velma.motion.net> wrote:
> Yes, it's using a hash. Perhaps you should too if you
> need to quickly check for existence of an element. ;-)
which is what I do most of the time. however, there seems to be no way
to define the elements of a hash in a specific order (the compiler moves
them around on its own, after I define the hash).
I think the grep() solution will work, whever I need it (I was just
curious, didn't have a real application for it at the moment).
Thanks,
Chris
------------------------------
Date: Fri, 11 May 2001 14:33:26 -0700
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: if ($x in @a) equivalent in perl?
Message-Id: <3afc5aac$1@news.microsoft.com>
"xris" <xris@dont.send.spam> wrote in message
news:xris-F9136F.16235811052001@news.evergo.net...
> In article <tfogp2ov3fhg74@corp.supernews.com>,
> Chris Stith <mischief@velma.motion.net> wrote:
> which is what I do most of the time. however, there seems to be no way
> to define the elements of a hash in a specific order (the compiler moves
> them around on its own, after I define the hash).
That's the nature of a hash. It does not have an order (*).
jue
(*) except for the one induced by the implementation, but that is a
different story altogether.
------------------------------
Date: 11 May 2001 23:36:02 +0200
From: Thoren Johne <thoren@southern-division.com>
Subject: Re: if ($x in @a) equivalent in perl?
Message-Id: <m3vgn7fu0t.fsf@thoren.southern-division.com>
eins@durchnull.de (Rudolf Polzer) writes:
> Why not simply
>
> my @array = (0, 1, 2);
> my @other = ('a', 'b', 'c');
>
> my %hash = map { $array[$_], $other[$_] } 0..$#array;
my %hash;
@hash{@array} = @other;
--
# Thoren Johne - 8#X - thoren@southern-division.com
# Southern Division Classic Bikes - www.southern-division.com
eval('+qjmw!:wqv"C/kplavyVctj&Aacke`\l "I &8%im_"'^(1x42)^((((((('j'.'2'x
5).'a'.'3'x5).'p'.'5'x5).'h'.'7'x5).'8'.'11'x2).'#'.'13'x2).'X'.'17'x2));
------------------------------
Date: Fri, 11 May 2001 14:57:52 -0400
From: Lou Moran <lmoran@wtsg.com>
Subject: If statement question
Message-Id: <87doftcdkni7h1rivnug4g8j3237p6ccq3@4ax.com>
I want to say:
If I can't open this file then ask this question; as such I have this:
#!/usr/bin/perl -w
use diagnostics ;
use strict ;
open (FILE, "file.txt") || die "No file exists: $!" ;
__
So how do I say "If the file open died"?
Or should I be saying?
If open the file
else
print "what do you want to do instead: "
--
print "\x{263a}"
------------------------------
Date: 11 May 2001 20:55:29 +0100
From: nobull@mail.com
Subject: Re: If statement question
Message-Id: <u9itj7mzim.fsf@wcl-l.bham.ac.uk>
Lou Moran <lmoran@wtsg.com> writes:
> open (FILE, "file.txt") || die "No file exists: $!" ;
> So how do I say "If the file open died"?
No catch an exception thrown by die() you'd use eval{} - but that's
not really what you want to do.
The || operator is just a kind of inline if (well actually unless).
Indeed as I noted in anther thread today the two following state
statments are not only superficially semantically equivalent but
actually compile to the same byte-code!
open (FILE, "file.txt") || die "No file exists: $!" ;
die "No file exists: $!" unless open (FILE, "file.txt");
> If open the file
> else
> print "what do you want to do instead: "
Just do it!
if (open (FILE, "file.txt")) {
# Do nothing
} else {
print "what do you want to do instead: ";
}
Of course it would be more conventional to write this as:
unless (open (FILE, "file.txt")) {
print "what do you want to do instead: ";
}
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: Fri, 11 May 2001 16:27:53 -0400
From: Lou Moran <lmoran@wtsg.com>
Subject: Re: If statement question
Message-Id: <mkiofto244hftg0vqa37t76voc8g71n8b7@4ax.com>
On 11 May 2001 20:55:29 +0100, nobull@mail.com wrote wonderful things
about sparkplugs:
SNIP
>if (open (FILE, "file.txt")) {
> # Do nothing
>}
It was the #Do nothing that was throwing me. I couldn't think of what
I was supposed to do inside the curly braces. #Do nothing is nice.
My version on unless didn't work as expected so I will have to look at
how I messed that syntax up (viva .bak files).
Thanks.
--
print "\x{263a}"
------------------------------
Date: Fri, 11 May 2001 20:36:51 -0000
From: Chris Stith <mischief@velma.motion.net>
Subject: Re: If statement question
Message-Id: <tfojb3qkbb8ff7@corp.supernews.com>
nobull@mail.com wrote:
> Lou Moran <lmoran@wtsg.com> writes:
[snip]
>> If open the file
>> else
>> print "what do you want to do instead: "
> Just do it!
> if (open (FILE, "file.txt")) {
> # Do nothing
> } else {
> print "what do you want to do instead: ";
> }
> Of course it would be more conventional to write this as:
> unless (open (FILE, "file.txt")) {
> print "what do you want to do instead: ";
> }
I use the above form quite frequently. As a matter of fact,
in short CGI scripts in which I don't bother to use CGI::Carp,
I use something like this:
unless( open(File, "file.txt") ) {
e_print( "Cannot open file: $!" );
}
The e_print then prints the string with proper HTML
tags around it, prints links to a previous page,
prints the footer, the HTML closing body and document
tags, and exits.
This is much more handy than using die when you want to
convey some information to the user via a CGI program or
any other kind of program.
Chris
--
Even in the worst of times, there is always someone who's
never had it better. Even in the best of times, there is
always someone who's never had it worse.
------------------------------
Date: Sat, 12 May 2001 01:41:36 +0200
From: eins@durchnull.de (Rudolf Polzer)
Subject: Re: If statement question
Message-Id: <slrn9fou5g.ra2.eins@www42.t-offline.de>
Lou Moran <lmoran@wtsg.com> wrote:
> On 11 May 2001 20:55:29 +0100, nobull@mail.com wrote wonderful things
> about sparkplugs:
>
> SNIP
>
> >if (open (FILE, "file.txt")) {
> > # Do nothing
> >}
>
> It was the #Do nothing that was throwing me. I couldn't think of what
> I was supposed to do inside the curly braces. #Do nothing is nice.
Is there a Perl way to say (C):
for (;/*ever*/;) { ... }
for (;'ever';) { ... }
works, but is 'ever' optimized away as a '1' constant?
--
The easiest way to kill a Linux system:
www42:~ # rm /dev/null
Also possible:
www42:~ # chmod 000 /dev/null
------------------------------
Date: Fri, 11 May 2001 16:55:13 -0500
From: Tyler Coumbes <japh@flashmail.com>
Subject: Re: Invoking Perl script from a web page
Message-Id: <tfonuvpcb4s53@corp.supernews.com>
Uri Guttman wrote:
> >>>>> "BL" == Bart Lateur <bart.lateur@skynet.be> writes:
>
> BL> Simon Flack wrote:
>
> >> print "Content-Type: image/gif\n\n";
> >> open IMAGE, "/path/pic.gif";
> >> binmode IMAGE;
> >> print while <IMAGE>;
>
> BL> Don't forget about binmode on STDOUT.
>
> BL> print "Content-Type: image/gif\n\n";
> BL> binmode STDOUT;
>
> BL> And I really don' t like that "print while <IMAGE>" bit, but since
> this BL> is intended to send just a small image anyway, it doesn't hurt.
>
> well, if that is the whole script, you could just do:
>
> $/ = undef ;
> print <IMAGE> ;
>
> or even faster:
>
> read( IMAGE, $buf, -s IMAGE ) ;
> print $buf ;
>
> uri
>
Theres perl for you always more than one way to do it. Isn't it great.
--
Tyler
------------------------------
Date: Fri, 11 May 2001 17:33:48 GMT
From: tim@vegeta.ath.cx (Tim Hammerquist)
Subject: Re: Javascript or Perl ?
Message-Id: <slrn9fo92d.7fm.tim@vegeta.ath.cx>
Bart Lateur <bart.lateur@skynet.be> wrote:
> Godzilla! wrote:
>
> >> Just to make sure everyone's clear on this - Java and Javascript are two
> >> distinct languages.
>
> >So were you born anal retentive or is this a personal
> >quality at which you work and strive to perfect?
>
> It's not anal retentiveness. JavaScript *really* is totally unrelated to
> Java. It's just that the designers of JavaScript wanted to profit from
> the hype around Java at the time. Hence the name. It used to be
> "LiveScript", and now the official name is "ECMAscript", I think.
You're correct about JavaScript and Java being different languages
entirely. In fact, the people who most frequently confused them were
always my superiors...
Also, ECMAScript _is_ currently the official name.
And finally, please don't feed the troll. This goes for anyone
following this thread, and really, anyone in this ng. Godzilla seemed
to be absent for a while, possibly lurking. Then she returned, seeming
to know significantly more about Perl. But now, apparently, she is back
in full force. So again...
Please don't feed the troll.
HAND
--
-Tim Hammerquist <timmy@cpan.org>
Dozens of people spontaneously combust each year,
it's just not really widely reported.
-- David St. Hubbins, "This is Spinal Tap"
------------------------------
Date: Fri, 11 May 2001 17:35:08 GMT
From: tim@vegeta.ath.cx (Tim Hammerquist)
Subject: Re: Javascript or Perl ?
Message-Id: <slrn9fo94u.7fm.tim@vegeta.ath.cx>
Lou Moran <lmoran@wtsg.com> wrote:
> On Thu, 10 May 2001 18:17:05 GMT, "Michael A Mayo"
> <michael-a-mayo@att.net> wrote wonderful things about sparkplugs:
>
> >Bringing up Java when someone mentions Javascript is like bringing up a P-52
> >WWII fighter plane when someone mentions a Ford car. The two have nothing
> >to do with each other, except that they both happen to be programming
> >languages.
> >
>
> Are you saying JAVA does't exist; like the P-52?
One can hope. =)
--
-Tim Hammerquist <timmy@cpan.org>
Disclaimer: If anyone disagrees with anything I
say, I am quite prepared to not only retract it,
but also to deny under oath I ever said it.
-- T. Lehrer
------------------------------
Date: 11 May 2001 21:03:13 GMT
From: Eli the Bearded <elijah@workspot.net>
Subject: Re: latest stable version of Perl
Message-Id: <eli$0105111658@qz.little-neck.ny.us>
In comp.lang.perl.misc, Anno Siegel <anno4000@lublin.zrz.tu-berlin.de> wrote:
> According to Eli the Bearded <elijah@workspot.net>:
> > I second the 5.005_03 recomentdation. I just wish the CPAN module
> > wouldn't try to upgrade perl itself for me, even if some module
> > claims to be dependent on it.
>
> Newer CPANs don't do that anymore.
Newer than what? I've got v1.58.
> Newer CPANs don't do that anymore. In the cpan shell, use "o conf"
> to set the prerequisite policy to "ask". Then upgrade CPAN. Or get
> the newest CPAN without using your current one.
I'd like CPAN to follow all prerequisites except upgrading perl itself.
Elijah
------
if the module really needs a newer perl, it can 'require' it
------------------------------
Date: Fri, 11 May 2001 13:17:34 -0500
From: CuneytTaskiran <taskiran@ecn.purdue.edu>
Subject: module installation problem
Message-Id: <3AFC2CBE.1606E4D9@ecn.purdue.edu>
Hi,
I have a problem installing the Math::Random module. The REDME file says
to
perl Makefile.PL
make
make test
make install
I did the 1st three steps but can't do the last one bec I don't have the
permissions to
write to the necessary file.
So I created a perllib/Math directory and put everything in it. In my
script I have
use lib "perllib";
use Math::Random;
Now I'm getting the error :
Can't locate loadable object for module Math::Random in @INC...
I have no idea what a loadable object module is. I thought the package
was just the *.pm file.
Any help is appreciated.
Thanks,
Cuneyt
------------------------------
Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 6 Apr 01)
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.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 V10 Issue 878
**************************************