[8976] in Perl-Users-Digest
Perl-Users Digest, Issue: 2594 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu May 14 11:07:26 1998
Date: Thu, 14 May 98 08:01:10 -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 Thu, 14 May 1998 Volume: 8 Number: 2594
Today's topics:
Re: Accessing Oracle tables from Perl (brian d foy)
creating some sort of deamon <thijs@esense.nl>
dereferencing question <prl2@lehigh.edu>
Re: dereferencing question <tchrist@mox.perl.com>
Re: Does Perl have a IDE?I don't like command line. (Greg Bacon)
Re: Does Perl have a IDE?I don't like command line. (Greg Bacon)
Re: Does Perl have a IDE?I don't like command line. (Greg Bacon)
Re: Does Perl have a IDE?I don't like command line. (Frank)
Re: Grieving our dying community <tchrist@mox.perl.com>
Re: How can you break out of a 'while... ' loop in a fu (John Porter)
Re: How can you break out of a 'while... ' loop in a fu (Tina Marie Holmboe)
Re: How can you break out of a 'while... ' loop in a fu (John Porter)
Re: Is if ($a="something") a bad style? (Shaun Sides)
Re: Is if ($a="something") a bad style? (Mike Stok)
localized ctime? <mroos@ut.ee>
Re: Matching the last character in a scalar (Shaun Sides)
Re: Matching the last character in a scalar (Shaun Sides)
Re: MODULE MANIA STRIKES (Was Re: What does this do?) (John Porter)
Re: OO perl and speed <tchrist@mox.perl.com>
output to a certain place in the HTML-file <jm@kolumbus.fi>
Perl not and ! operator differences (Jari Aalto+usenet.nil)
Perl Not Showing Errors gwebb@reedtech.com
Re: regexp for strings of chars <tchrist@mox.perl.com>
Safe module and %SIG problem (Craig Ruff)
servers in a list <downs.bj.1@pg.com>
Viterbi algorithm in English wanted (John Porter)
Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Thu, 14 May 1998 10:41:20 -0400
From: comdog@computerdog.com (brian d foy)
Subject: Re: Accessing Oracle tables from Perl
Message-Id: <comdog-ya02408000R1405981041200001@news.panix.com>
Keywords: from just another new york perl hacker
In article <6jebok$9af$1@nnrp4.snfc21.pbi.net>, "ryant" <ryant@pacbell.net> posted:
>write some Perl code to access an Oracle database. My question here is how
>difficult would this be to perform straight from the script vs. writing
>persistent object layers to perform the same tasks?
some one has already doen the work of creating an abstract interface.
see the DBI package at CPAN.
>Additionally, how much
>time and effort is required to write object libraries in Perl.
well, they've been working on DBI for awhile, so it probably won't
be something you'll do over the weekend :)
--
brian d foy <comdog@computerdog.com>
CGI Meta FAQ <URL:http://computerdog.com/CGI_MetaFAQ.html>
Comprehensive Perl Archive Network (CPAN) <URL:http://www.perl.com>
Perl Mongers <URL:http://www.pm.org>
------------------------------
Date: 14 May 1998 14:03:59 GMT
From: "Mathijs Oosterom" <thijs@esense.nl>
Subject: creating some sort of deamon
Message-Id: <01bd7f40$e730a000$a44a6dc2@earl.esense.nl>
Hi,
I have a script that sends mail to certain persons after checking if today
is the right date to do that. So the scripts sends mail every day, but
every dat to different addresses. All data is stored in a database.
This script must be activated only once a day, because the date doesn't
change during the day :)). This means that this script can't be related to
accessing a website or filling out a form or something. It should act like
a deamon or something.
Does anyboy know how to realise this?
Thanks,
Thijs.
------------------------------
Date: Thu, 14 May 1998 09:26:06 -0400
From: "Phil R Lawrence" <prl2@lehigh.edu>
Subject: dereferencing question
Message-Id: <6jerdf$jtq@fidoii.cc.Lehigh.EDU>
Please see the following dereferencing test and question following:
DB<1> $self = {}
DB<2> $ary_ref = $self->{key1}{key2} = []
DB<3> p $ary_ref
ARRAY(0x20167120)
DB<4> p $self->{key1}{key2}
ARRAY(0x20167120)
DB<5> push @{ $ary_ref }, 'var1'
DB<6> p @{ $ary_ref }
var1
DB<7> push @$ary_ref, 'var2'
DB<8> p @$ary_ref
var1var2
DB<9> push @{ $self->{key1}{key2} }, 'var3'
DB<10> p @{ $self->{key1}{key2} }
var1var2var3
DB<11> push @$self->{key1}{key2}, 'var4'
Type of arg 1 to push must be array (not hash elem) at (eval 23) line 2, at EOF
DB<12> p @$self->{key1}{key2}
Not an ARRAY reference at (eval 25) line 2, <IN> chunk 12.
Cannot print stack trace, load with -MCarp option to see stack at...
QUESTION:
Why must I use the dereferencing brackets with $self->{key1}{key2}, but not with
$ary_ref?
--
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Phil R Lawrence phone: 610-758-3051
Programmer / Analyst e-mail: prl2@lehigh.edu
194 Lehigh University Computing Center
E.W. Fairchild - Martindale, Bldg. 8B
Bethlehem, PA 18018
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
------------------------------
Date: 14 May 1998 14:19:16 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: dereferencing question
Message-Id: <6jeuh4$l52$3@csnews.cs.colorado.edu>
[courtesy cc of this posting sent to cited author via email]
In comp.lang.perl.misc, "Phil R Lawrence" <prl2@lehigh.edu> writes:
:Why must I use the dereferencing brackets with $self->{key1}{key2},
:but not with $ary_ref?
Because it is thus documented. Again and again in perl there are
places where you *think* you can use any scalar expression but in fact
you cannot. You must use a simple scalar variable, plain and unadorned
without further operators or subscripts. These are all wrong:
print $fh->[37] "stuff\n";
method_call $objaryref->[37] "stuff\n";
$result = <$fh[37]>;
$result = method_call $objaryref->[37] "stuff\n";
push @$ref->[37], "data";
I advise beginners never to use @$foo instead of @{$foo}, because
while the latter is extensible to arbitrary $foo, as in $foo->{this}
or $foo[47], the former is not.
Please read the docs:
% man perlref
[...]
That's it for creating references. By now you're
probably dying to know how to use references to get back
to your long-lost data. There are several basic methods.
1. Anywhere you'd put an identifier (or chain of identifiers)
as part of a variable or subroutine name, you can replace the
identifier with a simple scalar variable containing a reference
of the correct type:
$bar = $$scalarref;
push(@$arrayref, $filename);
$$arrayref[0] = "January";
$$hashref{"KEY"} = "VALUE";
&$coderef(1,2,3);
print $globref "output\n";
It's important to understand that we are specifically *NOT*
dereferencing `$arrayref[0]' or `$hashref{"KEY"}' there. The
dereference of the scalar variable happens *BEFORE* it does
any key lookups. Anything more complicated than a simple
scalar variable must use methods 2 or 3 below. However, a
"simple scalar" includes an identifier that itself uses method
1 recursively. Therefore, the following prints "howdy".
$refrefref = \\\"howdy";
print $$$$refrefref;
2. Anywhere you'd put an identifier (or chain of identifiers)
as part of a variable or subroutine name, you can replace the
identifier with a BLOCK returning a reference of the correct
type. In other words, the previous examples could be written
like this:
$bar = ${$scalarref};
push(@{$arrayref}, $filename);
${$arrayref}[0] = "January";
${$hashref}{"KEY"} = "VALUE";
&{$coderef}(1,2,3);
$globref->print("output\n"); # iff IO::Handle is loaded
Admittedly, it's a little silly to use the curlies in this case,
but the BLOCK can contain any arbitrary expression, in particular,
subscripted expressions:
&{ $dispatch{$index} }(1,2,3); # call correct routine
Because of being able to omit the curlies for the simple
case of `$$x', people often make the mistake of viewing the
dereferencing symbols as proper operators, and wonder about
their precedence. If they were, though, you could use parentheses
instead of braces. That's not the case. Consider the difference
below; case 0 is a short-hand version of case 1, *NOT* case 2:
$$hashref{"KEY"} = "VALUE"; # CASE 0
${$hashref}{"KEY"} = "VALUE"; # CASE 1
${$hashref{"KEY"}} = "VALUE"; # CASE 2
${$hashref->{"KEY"}} = "VALUE"; # CASE 3
Case 2 is also deceptive in that you're accessing a variable
called %hashref, not dereferencing through $hashref to the hash
it's presumably referencing. That would be case 3.
--tom
--
"The purpose of most computer languages is to lengthen your resume by
a word and a comma." --Larry Wall
------------------------------
Date: 14 May 1998 14:24:06 GMT
From: gbacon@cs.uah.edu (Greg Bacon)
Subject: Re: Does Perl have a IDE?I don't like command line.
Message-Id: <6jeuq6$bem$3@info.uah.edu>
In article <6je3d3$o7q@news.nl.compuware.com>,
koos@stag (Koos Pol) writes:
: Flipping pages is
: better that flipping manpages after all...
I'm not sure who said it first (I suspect Tom C.), but you can't grep
dead trees.
: I program, but it
: doesn't mean it has to be the archaic way.
It's sad to learn that thought and understanding have been deprecated.
Greg
--
open(G,"|gzip -dc");$_=<<EOF;s/[0-9a-f]+/print G pack("h*",$&)/eg
f1b88000b620f22320303fa2d2e21584ccbcf29c84d2258084
d2ac158c84c4ece4d22d1000118a8d5491000000
EOF
------------------------------
Date: 14 May 1998 14:22:14 GMT
From: gbacon@cs.uah.edu (Greg Bacon)
Subject: Re: Does Perl have a IDE?I don't like command line.
Message-Id: <6jeumm$bem$2@info.uah.edu>
In article <yo9u36t2uia.fsf@nym.sc.philips.com>,
dont_use_this_ey@hotmail.com (Frank) writes:
: Using Perl _is_ dumbing down programming. Perl is full of constructs
: which behave strange (I think it is called special variables,MAGIC,
: context).
You exhibit a fundamental failure to understand what Perl is all about.
The difference between Perl and Visual Doomaflotchy 9000 is that Perl
decreases the pulled hair volume of programmers as opposed to leading
nonprogrammers to believe that they can program too.
Greg
--
open(G,"|gzip -dc");$_=<<EOF;s/[0-9a-f]+/print G pack("h*",$&)/eg
f1b88000b620f22320303fa2d2e21584ccbcf29c84d2258084
d2ac158c84c4ece4d22d1000118a8d5491000000
EOF
------------------------------
Date: 14 May 1998 14:47:18 GMT
From: gbacon@cs.uah.edu (Greg Bacon)
Subject: Re: Does Perl have a IDE?I don't like command line.
Message-Id: <6jf05m$bem$4@info.uah.edu>
In article <355A2993.A5F3EB23@gamespot.com>,
Jon Drukman <jsd@gamespot.com> writes:
: you can get ports of groff/eqn/everything you every needed to format a
: perl pod into man from sgi's on the freeware CD or from
: http://www.sgi.com/TasteOfDT/public/freeware1.0/fw_GNUgroff/
Usually one of the first things I do to a fresh IRIX installation is
build groff and do the required shell script hackery.
: in fact, if you are going to even THINK about progamming on IRIX, you
: should probably get the freeware CD. it has just about every GNU util
: plus useful-for-perl stuff like Berkeley DB. emacs and samba too...
Yep, I've built most of the GNU tools. I wish gcc and gdb support for
IRIX 6.x were better. I wish I could find a decent top for IRIX 6.x.
I wish the Linux/SGI port would hurry!! :-)
: if you install berkeley DB and groff (and set up your paths correctly)
: before installing perl, you will be WAY ahead of the game.
Been there, done that, got the t-shirt. :-)
Greg
--
open(G,"|gzip -dc");$_=<<EOF;s/[0-9a-f]+/print G pack("h*",$&)/eg
f1b88000b620f22320303fa2d2e21584ccbcf29c84d2258084
d2ac158c84c4ece4d22d1000118a8d5491000000
EOF
------------------------------
Date: 14 May 1998 16:44:48 +0200
From: dont_use_this_ey@hotmail.com (Frank)
Subject: Re: Does Perl have a IDE?I don't like command line.
Message-Id: <yo9somc3o9r.fsf@nym.sc.philips.com>
mwmaurer@mtu.edu (Mark Maurer) writes:
>
> Frank (dont_use_this_ey@hotmail.com) wrote:
> :
> : Tom Christiansen <tchrist@mox.perl.com> writes:
> : >
> : > See http://www.salon1999.com/21st/feature/ for more on this.
>
> A VERY good site, I thought...
>
> : This whole discussion makes me sick.
>
> ???
Hello Mark,
I meant the topic that Tom C. addresses constantly: The Perl community
should not support people using different ways of working.
Everyone is free to do so.
As far as I can see it the discusion goes in a direction that the
usage of Perl should be made artificially harder for people with
nonconfirming views//ways of working//operating systems.
This starts from registration/email issues with the proposed moderated
news group. Continues with documentation issues on non unix systems[No
need to make accessing information easier on these systems. Arguments
for this: (a) They have choosen their operating system, so let them
suffer, (b) they intentionally never read documentation, they
click]. I have inserted at the end of the mail my personal experiences
with Perl documentation accessing on Windows systems.
>
> : Using Perl _is_ dumbing down programming. Perl is full of constructs
> : which behave strange (I think it is called special variables,MAGIC,
> : context).
>
> Uhh, no. All useful (and many nonuseful) programming languages contain
> ideosyncracies. Having the special variables, such as $_, $|, etc does NOT
> make dumbed-down programming.
Perl is full of shortcuts to things and is presented in a way that
even novices use these shortcuts. Perl hides successfully what is
happening. This was one of the key points in the URL which Tom
C. cited. Therefore I said dumbing down programming.
I'm not discussing the usefulnes of these constructs. All things which
are useful do hide things which are harder to use. I tried to discuss
the silly attitude to call this "dumbed-down programming".
>
> : Perl is full of wizards (in this context called MODULES) which allow me
> : to tackle tasks which I should better have avoided. The usage of these
> : Modules/Wizards will backfire at some point of time.
>
> Well, they already have for some people. A LOT of people flat out do not use
> them.
>
> : Perls InstallShield wizard is called CPAN. Both will fail if you try
> : to influence the way they behave.
>
> You lost me here...
I think I lost you earlier. My fault. CPAN (CPAN.pm the MODULE which
automates the installation of Perl modules) is only an example of a
tool which makes life easier for some people. It gives (ugly) things a
shiny surface. Wizards/InstallShields do the same thing in the Windows
world. "Shiny surfaces" "hiding what is happening" was a key point of
the article cited by Tom C.
The missing point is _quality_. Hiding//Shiny surfaces only become a
problem when they do not work. They become a thing to avoid if you are
not able to change their code either because it is not present or it
is not documented or the code is using so many shortcut features of
the language that you decide to better not touch.
It is not a conceptional issue. IDEs are no bad thing. In my old days
(1987?) my preferred development system was Smalltalk running on a 286
DOS system with 1meg of RAM. For me it was a very usable grafical
development environment. I clicked and browsed the source code got
usable feedback and at the same time produced applications which
worked and which I liked.
Now I'm using Emacs & Perl (40meg RAM each session) and still only
have 10% of the features of the Smalltalk system. The only new thing I
see is an integrated news/email interface.
But of course in the old days everything was better.
>
> : To give new names to these things does not make them better.
>
> Well, perl is not just giving these things a new name, they are rather
> differeint, IMO...
>
> : - Perl is one of many ways to do things.
>
> In my estimation, usually one of the better ways...
I disagree with the religious attitude sometimes connected to Perl. Of
course for me it is useful.
regards
Frank
- Perl for NT4.0SP3 (perl 5.00404 from the same source as the unix
version) does not come with working documentation at all.
At least for me. On my system neither perldoc nor the HTML version was
usable. Perldoc never produced any output and the HTML browser(MS
Explorer 3) which is installed as default on these(only my?) systems
is not able to understand the URLs used in the documentation.
Deleted both the browser and Perl. Next step is to free the NT
partition.
Final goal is to get rid of the home computer. Perhaps then do more
sport. Or seeing friends. Or ....
------------------------------
Date: 14 May 1998 13:47:40 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: Grieving our dying community
Message-Id: <6jesls$j9f$1@csnews.cs.colorado.edu>
[courtesy cc of this posting sent to cited author via email]
In comp.lang.perl.misc,
sb@engelschall.com (Steffen Beyer) writes:
:I think it should be possible for "newbies" to ask their beginner's questions
:even if they are FAQs, because sometimes it's hard when one doesn't even know
:where to start searching for an answer, given the overwhelming volume of
:available Perl documentation.
The clueless flock always to the .wizards groups, never the .neophytes group.
--tom
--
Perl itself is usually pretty good about telling you what you shouldn't do. :-)
--Larry Wall in <11091@jpl-devvax.JPL.NASA.GOV>
------------------------------
Date: Thu, 14 May 1998 14:16:06 GMT
From: jdporter@min.net (John Porter)
Subject: Re: How can you break out of a 'while... ' loop in a function?
Message-Id: <MPG.fc4c8477c9b3af49896c1@news.min.net>
On 14 May 1998 07:23:27 GMT,
in article <6je65f$ch9$1@news1.sol.no>,
tina@scandinaviaonline.se (Tina Marie Holmboe) wrote:
>
> What I *am* saying is that in concept both next() and last() do the same
> thing to a loop that a goto() does - it interrupts the flow; it "breaks out"
> of it.
Sure. In fact, all branching is equivalent to goto. It's just a
matter of how the language sugar-coats it. I find
101 if ( false-expression ) {
# 100 lines of code
202 }
203 else {
# good stuff here
}
quite unappetizing, and I see it a lot.
It does a jump from line 101 to line 203.
> next() is by far the least 'harmful' - and note the 's there - of
> the two, as it merely skips to the next iteration.
If it's 'harmful' at all, it is the least of three VERY 'harmful'
things. Consider:
while (...) {
next;
...
}
is equivalent to
while (...) {
goto NEXT;
...
NEXT:
}
and
while (...) {
last;
...
}
is equivalent to
while (...) {
goto LAST;
...
}
LAST:
Not significantly different, in my estimation.
(Now before you nitpickers jump down my back, yes
I know about continue. I ignored it on purpose.)
> However, IMHO and all that, the last() function creates a situation where
> a loop as one entry point, and N>1 exit-points.
>[snip]
> It still isn't _hard_ to work with, but it suddenly had two exits...
>
> Now add - left as an exercise :) - more tests for special cases inside the
> block. The number of exits are then N>1. and the loop - again in my humble
> opinion - has become much harder to maintain and debug.
As pointed out in another response in this thread, sometimes you need
to exit a loop in more than one place -- the algorithm demands it.
Using structured techniques to enforce a single exit point always
introduces, in such cases, either inefficiency or reduced legibility,
or both.
The perl way:
for ( @records ) {
foo($_);
last if $_ eq 'lwall';
bar($_);
}
The structured way:
$last_found = 0;
$i = 0;
while ( $i <= $#records and ! $last_found ) {
$_ = $records[$i];
foo($_);
if ( $_ eq 'lwall' ) {
$last_found = 1;
}
else {
bar($_);
}
$i++;
}
So which of these is "harder to maintain and debug"?
%excerpt = (
'comment' => <<'COMMENT',
The following text is excerpted from the book
"Code Complete", chapter 16.1, which available
online at http://www.construx.com/stevemcc/ccgoto.htm
(It is from the section "The Argument for gotos".)
The whole article is very good.
COMMENT
'text' => <<'CCGOTO'
The argument for the goto is characterized by
advocating its use in specific circumstances rather
than its indiscriminate use. Most arguments against
gotos are based on indiscriminate use, rather than
careful use. The goto controversy began when
Fortran was the most popular language.
. . . .
Good programming doesn't mean eliminating gotos.
Methodical decomposition, refinement, and selection
of control structures automatically leads to goto-free
programs in most cases. gotolessness is not the aim,
but the outcome, and putting the focus on no gotos
isn't helpful.
. . . .
Two decades worth of research with gotos has been
inconclusive in demonstrating their badness. In a
survey of the literature, B. A. Sheil concluded that
unrealistic test conditions, poor data analysis, and
inconclusive results failed to support the claim that
the number of bugs was proportional to the number
of gotos (Sheil 1981).
CCGOTO
);
John Porter
------------------------------
Date: 14 May 1998 14:34:36 GMT
From: tina@scandinaviaonline.se (Tina Marie Holmboe)
Subject: Re: How can you break out of a 'while... ' loop in a function?
Message-Id: <6jevds$dll$1@news1.sol.no>
In article <MPG.fc4c8477c9b3af49896c1@news.min.net>,
jdporter@min.net (John Porter) writes:
> As pointed out in another response in this thread, sometimes you need
> to exit a loop in more than one place -- the algorithm demands it.
> Using structured techniques to enforce a single exit point always
> introduces, in such cases, either inefficiency or reduced legibility,
Yup - and as I've pointed out in the article you reply to, I agree with
that...
--
Tina Marie Holmboe
Application Developer (Geeks'R'Us) [tina@tech.scandinaviaonline.se]
Scandinavia Online AB Development Dept. (+46) 08 587 81000 (switchboard)
(+46) 08 587 81189 (direct)
------------------------------
Date: Thu, 14 May 1998 14:53:14 GMT
From: jdporter@min.net (John Porter)
Subject: Re: How can you break out of a 'while... ' loop in a function?
Message-Id: <MPG.fc4d102303208cb9896c4@news.min.net>
On Wed, 13 May 1998 15:35:29 GMT,
in article <3559bbe3.22846461@news.demon.co.uk>,
stu-w@usa.net.remove.everything.after.net (Stuart Wright) wrote:
> The specific example is this...
>
> # check membership number
> $memberfile = "members.txt";
> open(memberfileno, "$memberfile") || die "I can't open that because: $!\n";
> while(<memberfileno>) {
> chop;
> @all = split(/\n/);
This is a problem. You're splitting $_ on newlines.
How many newlines do you expect $_ to contain?
With $/ left at its default (as in you example),
$_ will never contain any newlines, so @all will only contain
one item. Which means you go through the foreach only
once per iteration of the while.
If that's what you want, then you can collapse the two loops
into one.
open(memberfileno, "$memberfile") || die "I can't open that because: \n";
while (<memberfileno>) {
chomp;
my( $filemember, $a1, $a2, $a3, $a4, $a5, $pc, $dateob )
= split( /%/, $_ ); # split $_, not $line
if ($filemember eq $member) {
$address1 = $a1;
$address2 = $a2;
$address3 = $a3;
$address4 = $a4;
$address5 = $a5;
$postcode = $pc;
$dob = $dateob;
last;
}
}
Of course, it might be nice to put this into a subroutine:
sub lookup_member {
my( $member, $file ) = @_;
open(MF, "< $file") || die "open $file: \n";
while (<MF>) {
my @a = split( /%/, $_ ); # split $_, not $line
my $mem = shift @a;
return @a if $mem eq $member;
}
(); # member not found in file
}
( $a1, $a2, $a3, $a4, $a5, $pc, $dateob )
= lookup_member( $member, $memberfile );
hth,
John Porter
------------------------------
Date: 14 May 1998 13:57:33 GMT
From: arch@abts.net (Shaun Sides)
Subject: Re: Is if ($a="something") a bad style?
Message-Id: <slrn6llbuj.f3o.arch@abts.net>
Original message by: angst <angst@scrye.com>
Date: 13 May 1998 15:36:22 GMT
Subject: Re: Is if ($a="something") a bad style?
> Or if $a is zero. You should wrap defined() around the statement (you need
> the parentheses due to precedence) if you ever want $a to legitimately hold
> the value zero.
Hmmm. Help me out here, cus I may be under a misconception.
I believe that undef is defined (no pun intended) as anything which
evaluates to 0, "0", or "".
--
Shaun L. Sides arch@abts.net
Business web site http://www.abts.net/~arch
Showershoe web site http://www.abts.net/~arch/showershoe
Recreational web site http://sara.mmlc.nwu.edu/~arch
------------------------------
Date: 14 May 1998 14:15:11 GMT
From: mike@stok.co.uk (Mike Stok)
Subject: Re: Is if ($a="something") a bad style?
Message-Id: <6jeu9f$cn6@news-central.tiac.net>
In article <slrn6llbuj.f3o.arch@abts.net>, Shaun Sides <arch@abts.net> wrote:
>Original message by: angst <angst@scrye.com>
>Date: 13 May 1998 15:36:22 GMT
>Subject: Re: Is if ($a="something") a bad style?
>
>
>> Or if $a is zero. You should wrap defined() around the statement (you need
>> the parentheses due to precedence) if you ever want $a to legitimately hold
>> the value zero.
>
>Hmmm. Help me out here, cus I may be under a misconception.
>
>I believe that undef is defined (no pun intended) as anything which
>evaluates to 0, "0", or "".
Those look like the defined values which are considered false by perl.
undef is a value which is undefined - when you use it as a string it is
like the empty string, when you use it as a number it's like 0 (but may
well get you some warnings under -w if you're using the undefined value as
if you expected it to have a defined value.)
One way in which undef is useful is when a sub can return *any* defined
value including the empty (but defined) string ''. undef can be used to
signal an error return e.g.
$val = &func ();
if (defined ($val)) {
...
}
else {
something's wrong
}
any good perl book will explain teh differnce between defined and
undefined values, and should also have a section on perl's ideas about
true & false values.
Hope this helps,
Mike
--
mike@stok.co.uk | The "`Stok' disclaimers" apply.
http://www.stok.co.uk/~mike/ | PGP fingerprint FE 56 4D 7D 42 1A 4A 9C
http://www.tiac.net/users/stok/ | 65 F3 3F 1D 27 22 B7 41
stok@colltech.com | Collective Technologies (work)
------------------------------
Date: 14 May 1998 14:21:48 GMT
From: Meelis Roos <mroos@ut.ee>
Subject: localized ctime?
Message-Id: <6jeuls$rpf$1@kadri.ut.ee>
Can anybody tell me where can I find a ctime() that uses my locale
settings?
--
Meelis Roos e-mail: mroos@ut.ee
www: http://www.cs.ut.ee/~mroos/
------------------------------
Date: 14 May 1998 14:05:33 GMT
From: arch@abts.net (Shaun Sides)
Subject: Re: Matching the last character in a scalar
Message-Id: <slrn6llcdj.f3o.arch@abts.net>
Original message by: Hauk Langlo <hauk@forumnett.no>
Date: Thu, 14 May 1998 13:19:31 +0200
Subject: Matching the last character in a scalar
> Hi there. After playing around with perl for a week or so, regular
> expressions still are somewhat confusing.
> Right now I would like to check if a scalars last letter(s) match either
> "/" or ".txt". The ".txt" mach is not too much of a problem because such
> a match would in most cases be the end of the scalar anyway. I know how
> to detect a / , but I would like a true condition only if it is the
> last character. For experienced perl programers, this should be no
> problem at all. I would be very thankfull if you could bother to help me
> on this one. Thanks
No experienced perl guy, but I try to answer all of these that I can.
Good practice, neh? ;-)
tmtowtdi, so
/(.*\/)|(.*\.txt)/
or
m#(.*/)|(.*\.txt)#
The second one tends to be a little easier to read, since you don't have
to escape the slash in the first part. You could also add 'i' to the
end of it if you want case-insensitivity.
--
Shaun L. Sides arch@abts.net
Business web site http://www.abts.net/~arch
Showershoe web site http://www.abts.net/~arch/showershoe
Recreational web site http://sara.mmlc.nwu.edu/~arch
------------------------------
Date: 14 May 1998 14:08:00 GMT
From: arch@abts.net (Shaun Sides)
Subject: Re: Matching the last character in a scalar
Message-Id: <slrn6llci5.f3o.arch@abts.net>
Original message by: Hauk Langlo <hauk@forumnett.no>
Date: Thu, 14 May 1998 13:19:31 +0200
Subject: Matching the last character in a scalar
> Hi there. After playing around with perl for a week or so, regular
> expressions still are somewhat confusing.
> Right now I would like to check if a scalars last letter(s) match either
> "/" or ".txt". The ".txt" mach is not too much of a problem because such
> a match would in most cases be the end of the scalar anyway. I know how
> to detect a / , but I would like a true condition only if it is the
> last character. For experienced perl programers, this should be no
> problem at all. I would be very thankfull if you could bother to help me
> on this one. Thanks
Argh.
On the followup I just sent, you also need the $
/(.*\/$)|(.*\.txt$)/
Geez, I remembered it just as my finger sent that. 8-P
Sorry.
--
Shaun L. Sides arch@abts.net
Business web site http://www.abts.net/~arch
Showershoe web site http://www.abts.net/~arch/showershoe
Recreational web site http://sara.mmlc.nwu.edu/~arch
------------------------------
Date: Thu, 14 May 1998 14:35:42 GMT
From: jdporter@min.net (John Porter)
Subject: Re: MODULE MANIA STRIKES (Was Re: What does this do?)
Message-Id: <MPG.fc4cce12c8f4689896c3@news.min.net>
On 14 May 1998 11:05:04 GMT,
in article <6jej50$hdh$4@news1.sol.no>,
tina@scandinaviaonline.se (Tina Marie Holmboe) wrote:
>...
> "I want to do CGI programming. Any tips?" - "Use CGI.pm" - GOOD answer.
> "I want to learn how the read() function works." - "Use CGI.pm" - NO answer.
This sounds good, in the classroom (rather like the admonition never
to use 'goto').
In my experience, in the many instances where I have given an answer
of the 'NO' variety described above, the original querant came back
to me to thank me profusely for helping them out of what seemed like
a sticky programming situation. Very rarely have they bitched that
I didn't answer the original question as asked.
Now I'm not against learning how to use read() -- I'm for it -- but
after a while you start to recognize that many questions, as asked,
are really symptoms of a deeper misunderstanding.
"Hey, doc, how can I walk without placing too much pressure on my
left leg? Can I have a crutch, or something?"
"No, let's get that compound fracture taken care of first."
John Porter
------------------------------
Date: 14 May 1998 14:07:06 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: OO perl and speed
Message-Id: <6jetqa$l52$1@csnews.cs.colorado.edu>
[courtesy cc of this posting sent to cited author via email]
In comp.lang.perl.misc,
jll@skynet.be writes:
:It seems that a method call has roughly the same cost as a hash access.
Your idea of rough diverges from my own.
Benchmark: timing 1000000 iterations of get Hash, get dual, get fast, get meth...
get Hash: 6 secs ( 5.21 usr 0.00 sys = 5.21 cpu)
get dual: 22 secs (20.91 usr 0.00 sys = 20.91 cpu)
get fast: 14 secs (12.48 usr 0.00 sys = 12.48 cpu)
get meth: 19 secs (16.96 usr 0.00 sys = 16.96 cpu)
Benchmark: timing 1000000 iterations of set Hash, set dual, set fast, set meth...
set Hash: 8 secs ( 7.14 usr 0.00 sys = 7.14 cpu)
set dual: 27 secs (25.85 usr 0.00 sys = 25.85 cpu)
set fast: 19 secs (18.82 usr 0.01 sys = 18.83 cpu)
set meth: 20 secs (21.02 usr 0.00 sys = 21.02 cpu)
--tom
use Benchmark;
$COUNT = 1_000_000;
sub fget_four { shift->{"fourth"} }
sub fset_four { shift->{"fourth"} = shift }
sub get_four {
my $obj = shift;
return $obj->{"fourth"};
}
sub set_four {
my $obj = shift;
my $arg = shift;
$obj->{"fourth"} = $arg;
}
sub four {
my ($obj, $arg) = @_;
$obj->{"fourth"} = $arg if @_ > 1;
return $obj->{"fourth"};
}
sub gimme { bless {} }
($ob = gimme)->{fourth} = "testing";
timethese $COUNT, {
"get meth" => sub { $ob->get_four },
"get dual" => sub { $ob->four },
"get fast" => sub { $ob->fget_four },
"get Hash" => sub { $ob->{fourth} },
};
timethese $COUNT, {
"set meth" => sub { $ob->set_four("value") },
"set dual" => sub { $ob->four("value") },
"set fast" => sub { $ob->fset_four("value") },
"set Hash" => sub { $ob->{fourth} = "value" },
};
--
"It's later than you don't think." --Larry Wall
------------------------------
Date: Thu, 14 May 1998 17:29:23 +0300
From: Jari Martikainen <jm@kolumbus.fi>
Subject: output to a certain place in the HTML-file
Message-Id: <355AFFC2.F05C0F97@kolumbus.fi>
Hi!
I have a script that adds the data from a form to the bottom of the
HTML-file. Is it possible to put the data to a certain place within
HTML? What is the Perl syntax and how do I define the place in HTML?
If this is not possible, what is the syntax to put the data to the top
of the HTML-document.
Thanks in advance,
Jari
Here is a part of the script:
sub reformat
{
local($tmp) = $_[0] ;
$tmp =~ s/\+/ /g ;
while ($tmp =~ /%([0-9A-Fa-f][0-9A-Fa-f])/)
{
$num = $1;
$dec = hex($num);
$chr = pack("c",$dec);
$chr =~ s/&/and/g;
$tmp =~ s/%$num/$chr/g;
}
return($tmp);
}
sub do_mail
{
local($filename) = "-$$";
open(TFILE,">$filename");
if ($Teksti ne "")
{
print TFILE "$Teksti\n";
}
print TFILE "<hr>\n";
print TFILE "\n";
close(TFILE);
`Type $filename >> document.htm`;
$mailstatus = $?;
unlink("$filename");
sub do_main
{
$cl = $ENV{'CONTENT_LENGTH'};
if ($cl > 0)
{
read(STDIN, $_, $cl);
$_ .= "&";
$pquery = &reformat($_);
while ($pquery =~ /Teksti=([^&]*)&/) {
if (!$Teksti) {
$Teksti = $1;
}
else {
$Teksti = $Teksti."\n ".$1;
}
$pquery =~ s/Teksti=([^&]*)//;
}
$Teksti = &reformat($Teksti);
------------------------------
Date: 14 May 1998 17:27:35 +0300
From: Jari Aalto <<jari.aalto@poboxes.com> (Jari Aalto+usenet.nil) >
Subject: Perl not and ! operator differences
Message-Id: <tbaf8llyg8.fsf@blue.sea.net>
Hi,
Can someone give me an example when I have to use ! operator
over "not". It seems that the more readable "not" is much
better in code that will be maintained in big projects.
jari
------------------------------
Date: Thu, 14 May 1998 14:33:07 GMT
From: gwebb@reedtech.com
Subject: Perl Not Showing Errors
Message-Id: <6jevb4$952$1@nnrp1.dejanews.com>
I have a problem when running large Perl programs where if there is an error
someplace, Perl will throw its hands up in the air and report only:
"XXXX had compilation errors."
and not tell me *anything* about those errors. My workaround has been to
iteratively comment out suspect code and rerun perl as "perl -c script_name"
until it returns:
"XXXX syntax OK"
so I can go back and uncomment until I find the line in error. Needless to
say this is extreemly irritating. I am running perl as "perl -w script_name"
and I include "use strict" at the beginning of my program. I just want perl
to report every single error it finds and not "save" me from seeing a flood of
errors that result from one faultly line.
Thanks,
Garth Webb
-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/ Now offering spam-free web-based newsreading
------------------------------
Date: 14 May 1998 14:08:22 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: regexp for strings of chars
Message-Id: <6jetsm$l52$2@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:
:>I'll play with the bug some more.
That's what I get for posting before coffee. I had been going back
and forth with (, (?:, and (?= for some tests and at some point didn't
propagate the required \1 and \2 changes through.
You know, I don't think that (foo\1stuff) can be reasonable
when \1 hasn't completed yet. I wonder whether that shouldn't
warn you.
--tom
--
"There is no idea so sacred that it cannot be questioned, analyzed...
and ridiculed." --Cal Keegan
------------------------------
Date: 14 May 1998 08:48:50 -0600
From: cruff@ncar.ucar.edu (Craig Ruff)
Subject: Safe module and %SIG problem
Message-Id: <6jf08i$ra2$1@ncar.ucar.edu>
>From my reading of the Safe module documentation, as shipped with 5.004_04,
it shouldn't be possible for code inside the compartment to access the
global %SIG hash. However, my tests show that it is possible to hijack
a signal handler with code inside the compartment. The code in the
compartment does not see the other global arrays like ARGV, ENV and INC.
Is this a known problem? Thanks.
--
Craig Ruff NCAR cruff@ncar.ucar.edu
(303) 497-1211 P.O. Box 3000
Boulder, CO 80307
------------------------------
Date: Thu, 14 May 1998 09:54:42 -0400
From: "Bruce J. Downs" <downs.bj.1@pg.com>
Subject: servers in a list
Message-Id: <355AF7A2.5450@pg.com>
I asking this question aqain, but this time I hope to be more clearer.
I have a perl script that I run on my NT server. The script is similar
to a "dir" command. It will return some info on the directories. My
problem is, I want to run this script command on a number of servers.
What I would like to do is run the script program on the servers that I
have put in a list. In essense, what I would like to see happen is the
script program to do the 'dir' command on each server I have in this
separate file. Can someone suggest how this can be done in Perl.
Thanks.
------------------------------
Date: Thu, 14 May 1998 14:26:57 GMT
From: jdporter@min.net (John Porter)
Subject: Viterbi algorithm in English wanted
Message-Id: <MPG.fc4cadbfeb95b249896c2@news.min.net>
Thanks very much,
John Porter
------------------------------
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 2594
**************************************