[6662] in Perl-Users-Digest
Perl-Users Digest, Issue: 287 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Apr 12 10:07:12 1997
Date: Sat, 12 Apr 97 07:00:28 -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 Sat, 12 Apr 1997 Volume: 8 Number: 287
Today's topics:
Re: Circumventing garbage collection (M.J.T. Guy)
Code readability and idiom (was Re: New Microsoft Perl <dbenhur@egames.com>
Re: confusion about interface methods and internal clas <dbenhur@egames.com>
Dromidarius Odiferus (Geoff Simmons)
Re: errors making test for perl 5.003 on Sequent (Laurent P. Montaron)
Re: HTML parsing <dbenhur@egames.com>
Re: Icon vs. Perl (was: No GUI environment for Perl?) <kjj@gfroth.phx.mcd.mot.com>
Latest documentation for Oracle DBI ? (David Cowie)
Logging scripts (Alan Fraser)
Mail header rewriting - fixed (Dave Schenet)
Re: Negative lookahead and nested stars BUG? <dbenhur@egames.com>
Re: Newbie: Why tr/+/ / Instead of s/+/ / ? (Tim Gim Yee)
Re: Newbie: Why tr/+/ / Instead of s/+/ / ? (Eric Bohlman)
Re: Perl NT problems (M.J.T. Guy)
Re: Perl-Books. <merlyn@stonehenge.com>
Re: References to built-in functions/commands <dbenhur@egames.com>
Slurp entire file to SCALAR without changing $/ (Stephen L. Ulmer)
Re: sort array? <dbenhur@egames.com>
Re: Split a line on "^M" <passani@eunet.no>
Re: Split a line on "^M" (Tad McClellan)
split with lookahead (Bart Lateur)
Re: split with lookahead (David Alan Black)
Re: split with lookahead (Tad McClellan)
Re: Strange warning about split, without a split being <dbenhur@egames.com>
Re: Transliterate from a pattern? (Tad McClellan)
Re: Unix and ease of use (WAS: Who makes more ...) (Steve Mading)
Re: Why are no elements returned from split(/X/,'')? <dbenhur@egames.com>
Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 12 Apr 1997 08:47:49 GMT
From: mjtg@cus.cam.ac.uk (M.J.T. Guy)
Subject: Re: Circumventing garbage collection
Message-Id: <5ini7l$hm@lyra.csx.cam.ac.uk>
In article <334D64E6.38DD@pnl.gov>, Z Todd Taylor <zt_taylor@pnl.gov> wrote:
>perlobj alludes to "destruct levels" and an environment
>variable PERL_DESTRUCT_LEVEL but I can't find any
>expanded discussion of them.
>From the perlrun man page:
PERL_DESTRUCT_LEVEL
Relevant only if your perl executable was built
with -DDEBUGGING, this controls the behavior of
global destruction of objects and other
references.
(Not what I'd call "expanded", but it's a start.)
Mike Guy
------------------------------
Date: Mon, 07 Apr 1997 21:49:34 -0700
From: Devin Ben-Hur <dbenhur@egames.com>
Subject: Code readability and idiom (was Re: New Microsoft Perl Product (fwd))
Message-Id: <3349CE5E.44E0@egames.com>
Alasdair Thomson wrote:
> Eric Bohlman wrote:
> > Paddy Spencer (paddy.spencer@parallax.co.uk) wrote:
> > : $arg eq "-n" || die "Use -n you moron!!\n";
[snip]
> > : or does one have to use the incredibly passe if(...){} construct?
>
> I'm sorry, but I am the only harrased person who has to understand
> scripts written by lots of developers who *thought* they were the best
> by choosing the shortest, least user friendly code . . .
Brevity doesn't necc. make code less comprehensible.
Nor does pedantic explaination necc. make it more so.
> While I understand *completely* the issues involved I would still like
> to see programmers put READABILITY above most other issues, at least
> comment yout bloody code.
This is a huge issue. And there's no cut and dried answer
that works for everyone. It's quite easy to over comment
too. For example, I find the following comment
$counter++; # increment counter
absolutely absurd. It tells me *nothing* that the code
itself doesn't but requires the extra mental overhead
of reading the comment and determining that there's no
useful information not already imparted by the code.
Unfortunately, the "always comment everything" school
produces a lot of this kind of fluff.
> I'm sorry, but the use of the "incredibly passe" if (...){} construct at
> least makes it obvious what it's attempting to do, and ensures that LESS
> MISTAKES happen during coding.
I'll certainly agree that the idea of if(...){...} being
passe is silly.
However, one *should* use the common idioms of the lenguage
and environment they're programming in.
The code form:
assert(this) or handle_exception();
is perfectly valid, easy to read and understand, and quite
common in Perl as well as some other languages.
open(FILE,$name) or die("couldn't open file: $!");
vs.
unless (open(FILE,$name)) {
die("couldn't open file: $!");
}
Both are correct.
The former is actually much cleaner and more READABLE.
> > : $arg eq "-n" || $arg = "-n";
This is perhaps less nice (and I presume the original
post was about why it didn't work with the high-precedence
|| instead of "or"). Still, in a language where
"open(...) or die" is commonplace, I would hope that
75% of Perl programmers would understand it painlessly
and that most of the rest wouldn't scratch their heads
more than a minute the first couple times they saw it.
Still, there are better ways to express this kind of
thing:
$arg = $default_arg unless valid_arg($arg);
or:
valid_arg($arg) or $arg = $default_arg;
or:
assert( is_valid($arg) ) or $arg = $default_arg;
vs:
if (not valid_arg($arg)) {
$arg = $default_arg;
}
> Perhaps that's the difference between people that muck around with
> languages at college and people who's jobs depend upon them.
Well, I've been mucking around for 23 years now, and
it's been my profession for 17. I agree 100%, that
any code with an expected useful lifespan greater than
a few weeks should be written for maintainablity and
readability. Most of the people I've passed code
on to or collaborated with have remarked well on the
quality and readability of my code.
However, I've encountered a few "professional" programmers
who barely understand the tools they're using, and I refuse
to add graceless comments or unneccessarily awkward constructs
so they can have a prayer of understanding my code without
taking the trouble to gain a jouneyman's understanding of
the language it's expressed in.
--
Devin Ben-Hur <dbenhur@egames.com>
eGames.com, Inc. http://www.egames.com/
eMarketing, Inc. http://www.emarket.com/
"It's better to be lucky than good." -- Elizabeth Bourne
------------------------------
Date: Mon, 07 Apr 1997 11:10:10 -0700
From: Devin Ben-Hur <dbenhur@egames.com>
To: Curtis Hrischuk <ceh@sundance.sce.carleton.ca>
Subject: Re: confusion about interface methods and internal class methods
Message-Id: <33493882.78E3@egames.com>
[mail&post]
Curtis Hrischuk wrote:
> Hi. I have run into the situation where the object reference is not
> passed on the parameter stack for internal class methods, but it is
> passed by external class methods. The package toot is an example
> (below).
>
> I can't believe that Perl is implemented this way becuase it requires
> the programmer to keep track of which methods are accessed externally
> and internally what am I doing wrong?
What you're doing wrong is you're calling your internal
methods as if they're ordinary functions rather than
object methods. Try doing this instead:
package toot;
sub external_toot { # Accessed only from external object call
my $self = shift; # NOTE get object reference
$self->internal_toot(@_);
}
sub internal_toot {
my $self = shift; # NOTE: this way we get object reference
my($local_var) = @_;
$local_var++;
}
HTH
--
Devin Ben-Hur <dbenhur@egames.com>
eGames.com, Inc. http://www.egames.com/
eMarketing, Inc. http://www.emarket.com/
"It's better to be lucky than good." -- Elizabeth Bourne
------------------------------
Date: Sat, 12 Apr 1997 13:39:58 +0100
From: g.simmons@elmshorn.netsurf.de (Geoff Simmons)
Subject: Dromidarius Odiferus
Message-Id: <g.simmons-ya023580001204971339580001@news.shlink.de>
Like most three-year-olds, my son has a sense of humor that barely gets
beyond the scatological.
So this morning I showed him the cover of "Programming in Perl" and said,
"Look, there's a camel." He pressed his nose right on to the cover where
the camel is and exclaimed, "That stinks!"
Well, it made *me* chuckle.
Best,
Geoff
"Trust in Allah, but tie your camel anyway."
------------------------------
Date: 12 Apr 1997 11:32:46 +0200
From: montaron@nebin.eurecom.fr (Laurent P. Montaron)
Subject: Re: errors making test for perl 5.003 on Sequent
Message-Id: <5inkru$99u@nebin.eurecom.fr>
umask 022
gunzip -dc perl-5.003.tar.gz | tar xpf -
cd perl-5.003
chmod 644 sv.c x2p/str.c
Perl attempts to access the symbol _filbuf (ugly ugly). Well there is no
_filbuf on ptx but there is a __filbuf (with a double leading underscore
instead of a single one).
So, edit sv.c and x2p/str.c and replace each occurrence of _filbuf by
__filbuf
If you want to use the NDBM_File module, you need to provide dbm functions
to perl. Sequent Dynix/ptx provides native NDBM support, located in
/lib/libc.so and /lib/libc.a but not in /lib/libc.so.1. Which means that
you must link statically the various calls to dbm_open(), etc. in your
NDBM_File module. To do that, just edit the file ext/NDBM_File/Makefile.PL
and use -lc in the LIBS hash:
chmod 644 ext/NDBM_File/Makefile.PL
vi ext/NDBM_File/Makefile.PL
the line LIBS looks like this before you edit:
LIBS => ["-L/usr/local/lib -lndbm", "-ldbm -lucb"],
here is what it should be after:
LIBS => ["-lc"],
That should be all you need to patch before configuring and compiling perl
5.003 on ptx 4.2.
In article <860776172.6995@dejanews.com>, <pptse@uswnvg.com> wrote:
>Hi,
> I am trying to compile perl5.003 on Sequent running Dynix/Ptx 4.1.3.
>I have managed to get it to compile and make minitest went fine. But
>when I tried to make test, I got the following error message:
>
>lib/ndbm.......Can't load '../lib/auto/NDBM_File/NDBM_File.so' for module
>NDBM_File: Unknown error - dlerror() not implemented at
> ../lib/DynaLoader.pm line 140. at ../lib/NDBM_File.pm line 17 FAILED on
>test 0
>
>Any suggestions? I used dlopen.xs in config.sh and I linked the program
>with lseq, lm and ldl. Thanks in advance.
>
>Philip Tse
>pptse@uswnvg.com
>
>-------------------==== Posted via Deja News ====-----------------------
> http://www.dejanews.com/ Search, Read, Post to Usenet
--
Laurent Montaron sylvestre@world-company.com
Portland, Oregon 97124, USA, North America meow@pobox.com
Earth (G-"Sol" III), South-West Milky Way Le_Chat on IRC/IRCNet
Universe E45-A North, Continuum 28 CEDEX PGP key available
------------------------------
Date: Wed, 09 Apr 1997 16:39:52 -0700
From: Devin Ben-Hur <dbenhur@egames.com>
To: Ron Watkins <ron@argus.lpl.Arizona.EDU>
Subject: Re: HTML parsing
Message-Id: <334C28C8.2EC3@egames.com>
[mail&post]
Ron Watkins wrote:
> I need to find a way to parse out multiple META tags from an HTML document.
[snip]
> I have tried the following but it's not doing what I need. I just don't know
> how to proceed? What am I looking for?
>
> ($name,$content) = ($html =~ s/.*<Meta\s+Name="(\w+)"\s+Content="(\w*)">.*/$1 $2/g);
Try:
%meta = ( $html =~ /<Meta\s+Name="([^"]*)"\s+Content="([^"]*)"/ig );
The regex-match operator with the /g modifier returns a list
containing the contents of all the matches for the () enclosed
subexpressions in the RE. Assigning this list to a hash produces an
associative array whose keys are the name parts and values are the
contents. So for:
<Meta Name="aaa" Content="bbb">
<Meta Name="description" Content="An HTML document">
$meta{'aaa'} will be 'bbb' and
$meta{'description'} will be 'An HTML document'
HTH
--
Devin Ben-Hur <dbenhur@egames.com>
eGames.com, Inc. http://www.egames.com/
eMarketing, Inc. http://www.emarket.com/
"It's better to be lucky than good." -- Elizabeth Bourne
------------------------------
Date: 10 Apr 1997 07:32:20 -0700
From: Kevin Johnson <kjj@gfroth.phx.mcd.mot.com>
Subject: Re: Icon vs. Perl (was: No GUI environment for Perl?)
Message-Id: <c0gd8s37xu3.fsf@gfroth.phx.mcd.mot.com>
rdd@access4.digex.net (R. D. Davis) writes:
> In article <01bc42ae$9220d820$1eee1ace@jupiter.viser.net>,
> <blueox@mail.cyberhighway.com> wrote:
> >Is there any gui environment for programming available? I don't mind
> >working with text files made in dos, but a gui wouldn't hurt. Also, it
> [...]
> Ermmm, I don't mean to get a "holy war" started here, but if you
> need graphics, why not give Icon a try? Icon's rather portable, as
> it runs under UNIX, VMS, MS-DOS, etc. and, from what I can tell,
> seems to be a rather nice language for text-processing, as well as
> other things. In addition to providing graphics support, it's got a
> visual interface builder (VIB) and can be used with an interpreter
> or a compiler.
> Does anyone care to comment, in an unbiased manner, on the issue of
> Perl versus Icon? Are there others here who have used both? Both
> seem like rahter nice languages... perhaps someone should create a
> hybrid of the two, allowing one to have at least three ways of
> accomplishing the same thing using the same language.
Mmm.... Icon...
Very nice language with some very nice features.
When I looked at it (granted that was several years ago) it's
interface to the undelying operating system was rather limited.
--
thx,
kjj
------------------------------
Date: Sat, 12 Apr 1997 09:40:13 GMT
From: dcowie@dial.pipex.com.remove-this (David Cowie)
Subject: Latest documentation for Oracle DBI ?
Message-Id: <334f5838.59492473@news.dial.pipex.com>
Hi
Can anyone provide a URL for the latest uptodate documentation ?
The one at Hermatica is out of date according to the guru
many thanks
Dave
---------------------------------------------
David Cowie dcowie@dial.pipex.com
Southfields
LONDON, UK
http://www.aztec.co.za/users/dcowie/
Junk e-mail prevention: to reply, delete
'.remove-this' from end of my reply address
---------------------------------------------
------------------------------
Date: Sat, 12 Apr 1997 15:04:32 -0500
From: a_fraser@one.net (Alan Fraser)
Subject: Logging scripts
Message-Id: <a_fraser-1204971504330001@port-26-38.access.one.net>
The following scripts are available at the home page in my signature
below. When you get there, click on the Source Code button to retrieve
them (and a collection of others I've written).
logger.cgi - Writes a log record whenever there is a hit on the page.
This includes the source page so you can find out how the visitor got to
you.
logreader.cgi - Displays the information in the log files created by logger.cgi
logdata.cgi - Formats the information as the number of hits by country
logmaint.cgi - This one is used to easily initialize a log file to prevent
it from eating up all your disk space.
The people using them have had relatively little difficulty installing
them. All site-specific installation options are set at the beginning of
each script.
There is no charge for use of the scripts and they won't expire after some
period of time passes.
--
Alan Fraser
Home Page: http://w3.one.net/~a_fraser/
------------------------------
Date: 12 Apr 1997 13:28:50 GMT
From: shodan@shodan.erols.com (Dave Schenet)
Subject: Mail header rewriting - fixed
Message-Id: <5io2mi$nns@boursy.news.erols.com>
Cool, I got it working. Rather than pipe my form through /bin/mail, and
have the return-path go to "nobody", I can use sendmail itself, something
along the lines of:
----
open (MAIL, "|/usr/sbin/sendmail -t");
print MAIL <<EOF;
To: someguy\@somedomain.com
From: myself\@realdomain.com
Subject: hello
Blah
.
EOF
----
Enjoy
--
+------------------------------------+--------------------------------------+
|Dave Schenet - shodan@erols.com | Erols Internet Services, INC. |
|Junior Internet Developer | Springfield, VA. |
+------------------------------------+--------------------------------------+
------------------------------
Date: Mon, 07 Apr 1997 20:53:36 -0700
From: Devin Ben-Hur <dbenhur@egames.com>
To: vinny@nmg.nl
Subject: Re: Negative lookahead and nested stars BUG?
Message-Id: <3349C140.213B@egames.com>
[mail&post]
Vincent Partington wrote:
> While messing about with regexpes for parsing HTML documents I think I
> stumbled upon a bug. It concerns the following script:
[misc snips]
> # this regexp hangs perl5.002 and perl5.003
> $re1 = '\[if\b((?:[^\]\'"]*|([\'"]).*?\2)*)\](?!\])';
> # this one does not
> $re2 = '\[if\b((?:[^\]\'"]*|([\'"]).*?\2))\](?!\])';
> print "trying re2 on simple text\n";
> 'hi' =~ m{$re2}is;
> print "trying re2 on complex text\n";
> 'hi [[if _nr exists]]something else[[/if]] there' =~ m{$re2}is;
> When this script is run using perl 5.002 on FreeBSD the interpreter hangs
> after printing "trying re1 on complex text\n", when running the script
> using perl 5.003 on Linux the interpreter waits a few seconds after
> printing the same line and then quits with a segmentation violation.
This is not a bug in Perl, it's a bug in your RE. Nested
quantifiers can easily require more time than the age of the
universe to evaluate for moderately long strings. Effectively,
you've sent Perl's NFA regex engine into a nearly infinite loop
trying too many permutations of the possible ways the nested
*-controlled sub-expressions can match. The segment fault
probably resulted from the regex engine pushing too many
intermediate (backtrack and try again here) states on some
internal stack.
> I've been able to work around the bug for the script I was writing, but I
> hope somebody can explain to me why the interpreter hangs, I'm just
> curious.
It didn't really hang, you just weren't patient enough :)
Hope you have a few trillion years.
If you want a detailed exploration of how the regex
engine works and why nested quantifier REs may take
extremely long times, I suggest you read Jeffrey
Friedl's excellent "Mastering Regular Expressions".
HTH
--
Devin Ben-Hur <dbenhur@egames.com>
eGames.com, Inc. http://www.egames.com/
eMarketing, Inc. http://www.emarket.com/
"It's better to be lucky than good." -- Elizabeth Bourne
------------------------------
Date: Sat, 12 Apr 1997 08:02:10 GMT
From: tgy@chocobo.org (Tim Gim Yee)
Subject: Re: Newbie: Why tr/+/ / Instead of s/+/ / ?
Message-Id: <334f3988.51186422@news.seanet.com>
On 12 Apr 1997 00:54:07 GMT, "Jeff Oien" <jeffo@execpc.com> wrote:
>
>Hi,
>I was wondering why form mail scripts always use
>tr/+/ /
>instead of
>s/+/ /
>with only one character, wouldn't they be the same?
s/\+/ /g; # You meant this, right? :)
Maybe 'tr/+/ /;' is faster. Maybe the authors all came from a unix
background and wanted to type as few characters as possible. Or maybe
they were just looking to *translate* one character to another.
-- Tim Gim Yee tgy@chocobo.org
http://www.dragonfire.net/~tgy/moogle.html
"Will hack perl for a moogle stuffy, kupo!"
------------------------------
Date: Sat, 12 Apr 1997 09:09:45 GMT
From: ebohlman@netcom.com (Eric Bohlman)
Subject: Re: Newbie: Why tr/+/ / Instead of s/+/ / ?
Message-Id: <ebohlmanE8IpG9.LB1@netcom.com>
Jeff Oien (jeffo@execpc.com) wrote:
: Hi,
: I was wondering why form mail scripts always use
: tr/+/ /
: instead of
: s/+/ /
: with only one character, wouldn't they be the same?
Actually, the second one would have to be written as:
s/\+/ /
since the plus sign is a special character in regular expressions.
The main reason is speed. The tr solution merely requires a table lookup
for each character in the string. The s solution, on the other hand,
requires that the single-character regular expression be compiled into an
internal representation and that every character in the string be run
through the regular expression matching engine, which is going to be slow
because the engine needs to execute code to deal with all sorts of
contingencies that aren't going to be present in this case.
------------------------------
Date: 12 Apr 1997 08:42:21 GMT
From: mjtg@cus.cam.ac.uk (M.J.T. Guy)
Subject: Re: Perl NT problems
Message-Id: <5inhtd$be@lyra.csx.cam.ac.uk>
Nathan V. Patwardhan <nvp@shore.net> wrote:
>
>Interestingly enough, any of the examples given in the original posting
>(and my follow-up) worked from the command-line on Solaris 2.5, SunOS 4.1.3,
>FreeBSD-2.1.5, and Linux 1.2.13.
Get thee to the FAQ. Sadly, the last sentence says it all:
=head2 Why don't perl one-liners work on my DOS/Mac/VMS system?
The problem is usually that the command interpreters on those systems
have rather different ideas about quoting than the Unix shells under
which the one-liners were created. On some systems, you may have to
change single-quotes to double ones, which you must I<NOT> do on Unix
or Plan9 systems. You might also have to change a single % to a %%.
For example:
# Unix
perl -e 'print "Hello world\n"'
# DOS, etc.
perl -e "print \"Hello world\n\""
# Mac
print "Hello world\n"
(then Run "Myscript" or Shift-Command-R)
# VMS
perl -e "print ""Hello world\n"""
The problem is that none of this is reliable: it depends on the command
interpreter. Under Unix, the first two often work. Under DOS, it's
entirely possible neither works. If 4DOS was the command shell, I'd
probably have better luck like this:
perl -e "print <Ctrl-x>"Hello world\n<Ctrl-x>""
Under the Mac, it depends which environment you are using. The MacPerl
shell, or MPW, is much like Unix shells in its support for several
quoting variants, except that it makes free use of the Mac's non-ASCII
characters as control characters.
I'm afraid that there is no general solution to all of this. It is a
mess, pure and simple.
[Some of this answer was contributed by Kenneth Albanowski.]
Mike Guy
------------------------------
Date: 12 Apr 1997 06:17:03 -0700
From: Randal Schwartz <merlyn@stonehenge.com>
To: fl_aggie@hotmail.com (I R A Aggie)
Subject: Re: Perl-Books.
Message-Id: <8chghc1iuo.fsf@gadget.cscaper.com>
>>>>> "I" == I R A Aggie <fl_aggie@hotmail.com> writes:
I> Indeedly doodlie! My [comments] follow.
I> Learning Perl, Randal L. Schwartz, ISBN 1-56592-042-2.
I> [a kindler, gentler introduction, suitable for people learning their first
I> programming language, AKA the llama]
As much as I'd like that to be true, that's not the case. The llama
does *not* teach fundamental programming concepts, such as "what is a
variable", "what is an array", and "why would I need a subroutine".
That book would have needed about 75 more pages over the 250 pages of
the llama. There are other books on the market that (attempt to :-)
teach Perl to non-programmers. My book was intended as a crossover,
requiring some other algol-like languge (C, Pascal, Fortran, BASIC)
before stumbling in.
print "Just another Perl hacker," # but not what the media calls "hacker!" :-)
## legal fund: $20,495.69 collected, $182,159.85 spent; just 507 more days
## before I go to *prison* for 90 days; email fund@stonehenge.com for details
--
Name: Randal L. Schwartz / Stonehenge Consulting Services (503)777-0095
Keywords: Perl training, UNIX[tm] consulting, video production, skiing, flying
Email: <merlyn@stonehenge.com> Snail: (Call) PGP-Key: (finger merlyn@ora.com)
Web: <A HREF="http://www.stonehenge.com/merlyn/">My Home Page!</A>
Quote: "I'm telling you, if I could have five lines in my .sig, I would!" -- me
------------------------------
Date: Mon, 07 Apr 1997 21:52:05 -0700
From: Devin Ben-Hur <dbenhur@egames.com>
To: bernie@rev.net
Subject: Re: References to built-in functions/commands
Message-Id: <3349CEF5.42E1@egames.com>
[mail&post]
Bernard Cosell wrote:
> I'm setting up a dispatch table, the kind of thing with:
> $tbl{cmd1} = \&fcn1 ; $tbl{cmd2} = \&fcn2 ; ...
> and I wanted one of the dispatches just to do an 'exit'. Of course, I
> could do the trivial --- sub myexit { exit ; } --- but that seemed a
> LOT less elegant than putting the link to 'exit' right into the
> dispatch table... so I tried:
> $tbl{exitcmd} = \&exit ;
> but that didn't work at all.. Is there some way to make this work?
Try an anonymous subroutine constructor:
$tbl{exitcmd} = sub { exit; };
HTH
--
Devin Ben-Hur <dbenhur@egames.com>
eGames.com, Inc. http://www.egames.com/
eMarketing, Inc. http://www.emarket.com/
"It's better to be lucky than good." -- Elizabeth Bourne
------------------------------
Date: 09 Apr 1997 00:20:03 -0400
From: ulmer@mercury.net (Stephen L. Ulmer)
Subject: Slurp entire file to SCALAR without changing $/
Message-Id: <slhghgzv2k.fsf@beaker.mercury.net>
Is there anything overtly (or subtly) stupid about:
my $filecontents = join('', <FILE>);
to slurp the entire (remaining) contents of FILE into a scalar without
tinkering with $/? This works, but TANSTAAFL...
Thanks,
--
Stephen L. Ulmer http://www.mercury.net/~ulmer/
Senior Systems Administrator ulmer@mercury.net
Mercury Communications USA, Inc. (352) 332-1300
------------------------------
Date: Mon, 07 Apr 1997 11:19:13 -0700
From: Devin Ben-Hur <dbenhur@egames.com>
To: Geoffrey Hebert <soccer@microserve.net>
Subject: Re: sort array?
Message-Id: <33493AA1.5996@egames.com>
Geoffrey Hebert wrote:
> @line_is = (
> ["10", "line data"],
> ["1", "line data"],
...
> ); # problem one how to print line
> @sorted= sort {$line_is[$a][1] <=> $line_is[$b][1]} @line_is;
> # sort gives OUT OF MEMORY
@sorted= sort {$a->[0] <=> $b->[0]} @line_is;
@line_is is an array of array-references. The $a,$b
values will be references to the sub-arrays in question
not indexes into the original array as you wrote.
Also, perl arrays are normally indexed origined at
0 not 1, so if you wanted the number field from your
records, you should supscript [0].
This isn't so much a sorting question as a nested data
structures question. I suggest you review man perlref
or the Camel ch.4.
HTH
--
Devin Ben-Hur <dbenhur@egames.com>
eGames.com, Inc. http://www.egames.com/
eMarketing, Inc. http://www.emarket.com/
"It's better to be lucky than good." -- Elizabeth Bourne
------------------------------
Date: Sat, 12 Apr 1997 11:37:10 +0200
From: Luca Passani <passani@eunet.no>
To: QUN WENG <qxw8184@gamma.uta.edu>
Subject: Re: Split a line on "^M"
Message-Id: <334F57C6.46C6@eunet.no>
I suspect that what you are really trying to do is making a script for
"undosifying" dos files on unix.
In this case I would use something like:
perl -npi -e 's/\r//g' <filename>
or
perl -npi -e 's/\r/\n/g' <filename>
you can also use shell-globbing for catching many filenames at the same
time.
Unfortunately I couldn't test it rigth now.
luca
QUN WENG wrote:
>
> Could anybody please tell me how to split a line into an array based on
> the "^M" character. "^M" is not visible on stdout. Samples follows:
> char mark;^M> >^M> >public:^M> > player( int s, int t)^M> >
>
> I use @result=split(/^M/, $need_to_split_line); but failed.
>
> Any hint is greatly appreciated.
------------------------------
Date: Sat, 12 Apr 1997 07:15:02 -0500
From: tadmc@flash.net (Tad McClellan)
Subject: Re: Split a line on "^M"
Message-Id: <6cuni5.al.ln@localhost>
Luca Passani (passani@eunet.no) wrote:
: I suspect that what you are really trying to do is making a script for
: "undosifying" dos files on unix.
: In this case I would use something like:
: perl -npi -e 's/\r//g' <filename>
^^
If you use 'p', then you do not also need 'n'... (see perlrun)
: or
: perl -npi -e 's/\r/\n/g' <filename>
: you can also use shell-globbing for catching many filenames at the same
: time.
: Unfortunately I couldn't test it rigth now.
: luca
: QUN WENG wrote:
: >
: > Could anybody please tell me how to split a line into an array based on
: > the "^M" character. "^M" is not visible on stdout. Samples follows:
: > char mark;^M> >^M> >public:^M> > player( int s, int t)^M> >
: >
: > I use @result=split(/^M/, $need_to_split_line); but failed.
: >
: > Any hint is greatly appreciated.
--
Tad McClellan SGML Consulting
Tag And Document Consulting Perl programming
tadmc@flash.net
------------------------------
Date: Sat, 12 Apr 1997 13:22:51 GMT
From: bart.mediamind@tornado.be (Bart Lateur)
Subject: split with lookahead
Message-Id: <334f8547.76730@news.tornado.be>
I was trying to build a simple arithmetic expression evaluator, that can
only handle addition and subtraction. An example of what it should be
able to evaluate:
8.15+3+-16.5--2.4+-+3
I would have liked this to be split into
('8.15','+3','+-16.5','--2.4','+-+3')
because deleting all the plusses and all double minusses for every term
is enough to get the value to add to the running total.
split(/([+\-]+)/);
will turn the above into
('8.15','+','3','+-','16.5','--','2.4','+-+','3')
The delimiters will always be in the even numbered fields, even if the
expression starts with a '-', so I already found a workaround.
However, when I tried using split with pattern matching with
"lookahead", I got some pretty bizarre results.
split(/(?=([+\-]+)/);
yields
('8.15','+3','+','-16.5','-','-2.4','+-','+3')
So: it "works", but only for one character of the delimiter: the last
one.
I guess lookahead isn't intended for these purpouses, or else, is there
a limit in the lookahead to only one character? The docs say nothing
about this, although it *is* the usual case.
What exactly is going on?
Gent (Ghent, Gand),
Belgium,
Europe,
3rd planet from the sun.
------------------------------
Date: 12 Apr 1997 13:26:23 GMT
From: dblack@icarus.shu.edu (David Alan Black)
Subject: Re: split with lookahead
Message-Id: <5io2hv$nkc@pirate.shu.edu>
Hello -
bart.mediamind@tornado.be (Bart Lateur) writes:
>I was trying to build a simple arithmetic expression evaluator, that can
>only handle addition and subtraction. An example of what it should be
>able to evaluate:
> 8.15+3+-16.5--2.4+-+3
[ ... ]
>However, when I tried using split with pattern matching with
>"lookahead", I got some pretty bizarre results.
> split(/(?=([+\-]+)/);
You've got an extra paren (after the =).
>yields
> ('8.15','+3','+','-16.5','-','-2.4','+-','+3')
and '+-' here should be '+', '-'.
>So: it "works", but only for one character of the delimiter: the last
>one.
>I guess lookahead isn't intended for these purpouses, or else, is there
>a limit in the lookahead to only one character? The docs say nothing
>about this, although it *is* the usual case.
Those crazy docs :-)
What's happening is that your regex consists of only a lookahead
assertion; otherwise, it specifies a null delimiter. So it's
really trying to split at every character (see perlfunc), but it
rejects any split which immediately precedes anything but + or -.
That's why each of the returned elements (except [0]) starts with
either + or -, and, starting with itself, continues up to and
including the next character it finds which is followed by + or -.
(And that's why '+-' is impossible - it would stop after the +.)
You might have better luck with a regular expression, such as:
@elements = $input =~ /([+\-]*[\d.]+)/g;
David Black
dblack@icarus.shu.edu
------------------------------
Date: Sat, 12 Apr 1997 07:40:26 -0500
From: tadmc@flash.net (Tad McClellan)
Subject: Re: split with lookahead
Message-Id: <qrvni5.5r.ln@localhost>
Bart Lateur (bart.mediamind@tornado.be) wrote:
: I was trying to build a simple arithmetic expression evaluator, that can
: only handle addition and subtraction. An example of what it should be
: able to evaluate:
: 8.15+3+-16.5--2.4+-+3
: I would have liked this to be split into
^^^^^^^^^^^^^^^^^^
: ('8.15','+3','+-16.5','--2.4','+-+3')
You got it:
@terms = grep /./, split /([+\-]+[\d.]+)/; # grep to eliminate null fields
print join(', ', @terms), "\n";
--
Tad McClellan SGML Consulting
Tag And Document Consulting Perl programming
tadmc@flash.net
------------------------------
Date: Mon, 07 Apr 1997 11:29:38 -0700
From: Devin Ben-Hur <dbenhur@egames.com>
Subject: Re: Strange warning about split, without a split being used.
Message-Id: <33493D12.5766@egames.com>
Eike Grote wrote:
> Abigail wrote:
> > Earlier today, I did:
> > $ENV {PATH} = qw (/usr/bin /bin);
> > (Of course I wanted to do: $ENV {PATH} = join ":", qw (/usr/bin /bin);)
> >
> > The warning I got when running this was:
> > Use of implicit split to @_ is deprecated at - line 1.
> > That surprised me, as there is no split being used.
> > Is this a bug, or does qw call split when being used in a scalar context?
> The 'perlop' man page says:
> qw/STRING/
> Returns a list of the words extracted out of STRING, using
> embedded whitespace as the
> word delimiters. It is exactly equivalent to
> split(' ', q/STRING/);
This is all well and good, but where does @_ come in?
What Eike didn't point out to Abigail is that she
has a space between the 'qw' and the opening '('.
The list/string delimiter must be the next character
after q, qq, or qw.
Apparently at some time in Perl's murky past, the bareword
'qw' implied @_ as its argument. This is what the error
is complaining about (deprecated behavior of bare qw
-> split(' ',@_)).
HTH
--
Devin Ben-Hur <dbenhur@egames.com>
eGames.com, Inc. http://www.egames.com/
eMarketing, Inc. http://www.emarket.com/
"It's better to be lucky than good." -- Elizabeth Bourne
------------------------------
Date: Fri, 11 Apr 1997 22:40:21 -0500
From: tadmc@flash.net (Tad McClellan)
Subject: Re: Transliterate from a pattern?
Message-Id: <570ni5.gug.ln@localhost>
Jeff Vannest (jefflv@tir.com) wrote:
: Does anyone know of a method of transliterating a string by a pattern?
: It's not even really a transliteration; I want to delete leading and
: trailing spaces from a string.
: The tr// would work except that it deletes ALL spaces in the string
: and will not recognize the patterns "^ " (caret +space) or " $"
: (space+dollar).
: Any ideas? currently I'm using:
: $value =~ /^ /;
: if ($& eq " ") {
: $value = $';
: }
: $value =~ / $/;
: if ($& eq " ") {
: $value = $`;
: }
: but it looks WAY too clunky for me (although it works).
: Thanks for your ideas.
$value =~ /^\s+//; # delete leading spaces
$value =~ /\s+$//; # delete trailing spaces
--
Tad McClellan SGML Consulting
Tag And Document Consulting Perl programming
tadmc@flash.net
------------------------------
Date: 11 Apr 1997 18:45:40 -0500
From: madings@earth.execpc.com (Steve Mading)
Subject: Re: Unix and ease of use (WAS: Who makes more ...)
Message-Id: <5imif4$6ek$1@earth.execpc.com>
Kevin Handy (kth@srv.net) wrote:
[ Example of Ugly COBOL snipped (ugly COBOL - that's redundant) ]
: So, I really don't like to see LOC, or any other counting methids
: to specify the real complexity of a program. A clever ptogrammer
: would use a more complex method (IMHO) and do the same thing
: using arrays, and have a program using a small percentage of the
: code.
Re-read my post. I started by saying that better coding does
lead to less code, which is exactly your point. *After* I
said that, I continued by saying that as long as you are going
to count code by volume, you might as well use a more accurate
technique than LOC.
And besides, counting code by volume is still useful for other
analyses, like predicting how long the compiler will take to
process it, or predicting how long it will take a new person
to read it through and understand it. I, like you, just don't
like using it for measuring how complex the task is.
------------------------------
Date: Wed, 09 Apr 1997 16:57:55 -0700
From: Devin Ben-Hur <dbenhur@egames.com>
To: "Kent S. Gordon" <kgor@inetspace.com>
Subject: Re: Why are no elements returned from split(/X/,'')?
Message-Id: <334C2D03.5133@egames.com>
[mail&post]
Kent S. Gordon wrote:
> Why are no elements returned from split(/X/,'')?
[snip]
> This behavior is different than I would expect from looking at the Camel
> Book (2nd Edition) under split (p220) which talks about returning the
> original string if the string being split does not have the delimiter
> in it. I tested and this behavior is the same under perl 5.003 and
> perl 4.036.
Somehow you missed the second paragraph on p220 which says:
... If LIMIT is omitted, trailing null fields are stripped
from the result ...
HTH
--
Devin Ben-Hur <dbenhur@egames.com>
eGames.com, Inc. http://www.egames.com/
eMarketing, Inc. http://www.emarket.com/
"It's better to be lucky than good." -- Elizabeth Bourne
------------------------------
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 287
*************************************