[7057] in Perl-Users-Digest
Perl-Users Digest, Issue: 682 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Jun 29 13:27:22 1997
Date: Sun, 29 Jun 97 10:00:22 -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 Sun, 29 Jun 1997 Volume: 8 Number: 682
Today's topics:
*.,mak <von-der-heyden@metronet.de>
*.,mak <von-der-heyden@metronet.de>
Re: Can I get STDERR of `command` ?? <merlyn@stonehenge.com>
EMULATING 'C' STRUCTURES <ansa@informatica.com>
FREE Computer Equipment <focusmrktng@earthlink.net>
Re: Genericity a.k.a. Parametrized types in Perl <alexk@tti.com>
Getting Perl 5.00401 to compile on SCO 3.2.4 (Ed Wilborne)
Re: I just dont't get this -- opening a new filehandle <merlyn@stonehenge.com>
Re: msqlPERL - comon' baby! david@manifold-id.com
Perl 5.004_01 is available (Maintenance Release 1 for P (Tim Bunce)
Perl and killing processes (Jim Hribnak)
Perl call of 'C' library function <prw1@execpc.com>
Perl interface to IRC? (Nathan Neulinger)
Re: Question: split and anonymous arrays <merlyn@stonehenge.com>
Re: Question: split and anonymous arrays <merlyn@stonehenge.com>
Y2K and Perl (was Re: Y2K problems??) <rra@stanford.edu>
Zombie processes under system load <wayne@cta-challenge.com.au>
Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sat, 28 Jun 1997 23:11:44 +0200
From: "Peter von der Heyden" <von-der-heyden@metronet.de>
Subject: *.,mak
Message-Id: <5p5jgo$3nq$4@news.zentrale.metronet.de>
Hi,
I haven't MS C++, but I like to programm in perl. How can I made the
makefile.
*** Please answer with Mail *** +++ *** Sorry for dupes ***
bye
--
~ Peter von der Heyden ~
~von-der-heyden@metronet.de hai@poboxes.com ~
~vonderheyden@mailcity.com (c) 1997 by Peter ~
~ http://www.cd-cie.com/homepage/von-der-heyden ~
------------------------------
Date: Sat, 28 Jun 1997 23:11:44 +0200
From: "Peter von der Heyden" <von-der-heyden@metronet.de>
Subject: *.,mak
Message-Id: <5p5jgk$3nm$5@news.zentrale.metronet.de>
Hi,
I haven't MS C++, but I like to programm in perl. How can I made the
makefile.
*** Please answer with Mail *** +++ *** Sorry for dupes ***
bye
--
~ Peter von der Heyden ~
~von-der-heyden@metronet.de hai@poboxes.com ~
~vonderheyden@mailcity.com (c) 1997 by Peter ~
~ http://www.cd-cie.com/homepage/von-der-heyden ~
------------------------------
Date: 29 Jun 1997 09:03:21 -0700
From: Randal Schwartz <merlyn@stonehenge.com>
To: wesley@woais.com, Pierre BERGDOLT <Pierre.Bergdolt@ansf.alcatel.fr>
Subject: Re: Can I get STDERR of `command` ??
Message-Id: <8cwwndcs6u.fsf@gadget.cscaper.com>
>>>>> "Wesley" == Wesley Miaw <wesley@woais.com> writes:
Wesley> Pierre BERGDOLT wrote:
>>
>> I have a set of perl scripts that perform various operations using
>> `command`. Normally `command` is executed in a subshell, I can get
>> return code of `command` using $?, but can I get what `command` put to
>> STDERR in the subshell? The aim of this is to put warning or error
>> message in a log file. Thanks to answer by e-mail.
Wesley> I think that $! will return the error you want. $? returns
Wesley> $CHILD_ERROR while $! returns $OS_ERROR and $ERRNO.
Nope, the way to get STDERR from a qx child is to read the FAQ
(specifically perlfaq8) under "How can I capture STDERR from an
external command?", which I quote here:
Perlfaq8> How can I capture STDERR from an external command?
Perlfaq8> There are three basic ways of running external commands:
Perlfaq8> system $cmd; # using system()
Perlfaq8> $output = `$cmd`; # using backticks (``)
Perlfaq8> open (PIPE, "cmd |"); # using open()
Perlfaq8> With system(), both STDOUT and STDERR will go the same place
Perlfaq8> as the script's versions of these, unless the command
Perlfaq8> redirects them. Backticks and open() read only the STDOUT
Perlfaq8> of your command.
Perlfaq8> With any of these, you can change file descriptors before
Perlfaq8> the call:
Perlfaq8> open(STDOUT, ">logfile");
Perlfaq8> system("ls");
Perlfaq8> or you can use Bourne shell file-descriptor redirection:
Perlfaq8> $output = `$cmd 2>some_file`;
Perlfaq8> open (PIPE, "cmd 2>some_file |");
Perlfaq8> You can also use file-descriptor redirection to make STDERR
Perlfaq8> a duplicate of STDOUT:
Perlfaq8> $output = `$cmd 2>&1`;
Perlfaq8> open (PIPE, "cmd 2>&1 |");
Perlfaq8> Note that you cannot simply open STDERR to be a dup of
Perlfaq8> STDOUT in your Perl program and avoid calling the shell to
Perlfaq8> do the redirection. This doesn't work:
Perlfaq8> open(STDERR, ">&STDOUT");
Perlfaq8> $alloutput = `cmd args`; # stderr still escapes
Perlfaq8> This fails because the open() makes STDERR go to where
Perlfaq8> STDOUT was going at the time of the open(). The backticks
Perlfaq8> then make STDOUT go to a string, but don't change STDERR
Perlfaq8> (which still goes to the old STDOUT).
Perlfaq8> Note that you must use Bourne shell (sh(1)) redirection
Perlfaq8> syntax in backticks, not csh(1)! Details on why Perl's
Perlfaq8> system() and backtick and pipe opens all use the Bourne
Perlfaq8> shell are in
Perlfaq8> http://www.perl.com/CPAN/doc/FMTEYEWTK/versus/csh.whynot .
Perlfaq8> You may also use the IPC::Open3 module (part of the standard
Perlfaq8> perl distribution), but be warned that it has a different
Perlfaq8> order of arguments from IPC::Open2 (see the IPC::Open3
Perlfaq8> manpage).
--
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: 26 Jun 1997 17:48:27 GMT
From: "Ansa Sekharan" <ansa@informatica.com>
Subject: EMULATING 'C' STRUCTURES
Message-Id: <01bc8259$77eaad60$ac4407ce@ansa.informatica.com>
Hi Folks,
I have a structure defined in a C program as
struct PACKET {
long fld1,
int fld2,
char fld3;
}
HOW DO I EMULATE THIS STRUCTURE IN PERL.. IN OTHER
WORDS HOW CAN I WRITE THE SAME STRUCTURE IN PERL
AND PASS IT TO A FUNCTION...
Appreciate your help
ansa
------------------------------
Date: Sun, 29 Jun 1997 08:42:01 -0700
From: Focus Marketing <focusmrktng@earthlink.net>
Subject: FREE Computer Equipment
Message-Id: <33B68249.75CD@earthlink.net>
Register to win FREE computer equipment!
<http://home.earthlink.net/~focusmrktng/>
------------------------------
Date: Sat, 28 Jun 1997 23:28:25 -0700
From: Alex Kravets <alexk@tti.com>
To: Larry D'Anna <ldanna@hotmail.com>
Subject: Re: Genericity a.k.a. Parametrized types in Perl
Message-Id: <33B60089.61E64A4F@tti.com>
Larry D'Anna wrote:
>
> Alex Kravets wrote:
>
> > Does anyone know of any implementations of Genericity( a la C++
> > template
>>...
> > In other words, is it possible to have classes parametrized by types?
> > Or to restate the same problem: Is an STL port to Perl possible?
>>...
>
> I think this would be fairly simple to write as a perl
> module, but I don't see why you would want it. Perl has
> built in methods of doing pretty much anything you can
> do with the STL, and the syntax is a lot more readable.
> What STL like stuff are you trying to do in perl?
> There is probably a equivalent data structure in
> perl.
Ok, let me restate the question:
I've done some fairly complicated projects in perl
and am fully aware of its power.
What I have in mind is the following:
Suppose, one whould wish to write an STL-like library
in perl. It is fairly clear that there would be no need
for any special syntax, i.e. the classes whould probably take
the package name of the parametrizing types as one of the
arguments to their constructors; however the question
arises, how can perl runtime ensure proper parsing/comilation
if the name of the class by which one would like to parametrize
can possibly be available only at run time ( i.e. a daemon)
basically seems to me that perl would not be even able to
invoke GenericType->new() because at compile time it would be
undefined (at least this would hold true for -w and/or "use strict"
set).
Can anyone comeup with a better idea for implementing Genericity
in perl?
P.S. I'm aware that perl has a lot of STL-like goodies already;
however STL is designers can *garantee* O(n) performance of
their algorithms and also their memory consumption, whereas in perl
the general rule of thum is: "the fancier constructs you use, the more
memory
is consumed".
P.P.S. This question came about from long discussions about usability
of different languages for a large VLSI-chip-optimizing project where
even in C++ 512 megs of RAM is sometimes not enough. Also the perl
prototype
turned out to be around 70! times slower than the final STL-based code
------------------------------
Date: Sun, 29 Jun 1997 16:43:09 GMT
From: NOstargazer@gamewood.net (Ed Wilborne)
Subject: Getting Perl 5.00401 to compile on SCO 3.2.4
Message-Id: <33b6902f.12877910@news.gamewood.net>
I'm having a hard time using the Configure script to get Perl 5
compiled on SCO V 3.2.4. Can anybody recommend a place to look for
installation help with this release, or make other recommendations if
you have it up and running successfully?
Thanks!
Ed
(remove NO from e-mail address to reply)
Astronomy Software: http://www3.gamewood.net/mew3/
Astronomy Web Page: http://www3.gamewood.net/astronomy/
------------------------------
Date: 29 Jun 1997 09:09:15 -0700
From: Randal Schwartz <merlyn@stonehenge.com>
To: topaz56@one.net
Subject: Re: I just dont't get this -- opening a new filehandle
Message-Id: <8cu3ihcrx0.fsf@gadget.cscaper.com>
>>>>> "topaz56" == topaz56 <topaz56@one.net> writes:
topaz56> First, I want to thank those in this group that have helped
topaz56> w/ this -- you know who you are. Now for the next
topaz56> question...
topaz56> I'm importing some POST data, dumping all the wierd http
topaz56> chars, then matching a ulf & name, then pushing this to a web
topaz56> page.
topaz56> My problem is that the POST data that come in on STDIN and is
topaz56> dumped into $datafile. The script chomps on $datafile for
topaz56> awhile so that it's formatted properly for a long regex, and
topaz56> then I try to open a new filehandle that the regex can match
topaz56> against. The problem is (& I've tried ~ 10^6 different ways
topaz56> to do this) is that I can not open the new filehandle. I keep
topaz56> getting "document contains no data", & in the error_log it's
topaz56> clear where this script hangs. Can anyone enlighten me?
[non CGI.pm script deleted...]
No, that's not your problem. You have two problems, both different
from what you asked:
(1) You aren't using CGI.pm. You're trying to roll your own, which
means you are wasting valuable neurons (and some of our time)
reinventing an already thoroughly debugged wheel.
(2) There's a newsgroup specifically for Perl web applications, called
comp.infosystems.www.authoring.cgi. Usenet-iquette requires that you
post in the most specific group that applies to your problem. Sure,
you can post other places, but you'll be ignored or considered rude.
(Like walking into a movie theatre and loudly announcing that you have
a car for sale.)
Please get CGI.pm. Read it. Use it. And if you're still having
problems, post to comp.infosystems.www.authoring.cgi. I'll be happy
to help you, *over there*.
print "Just another Perl hacker," # but not what the media calls "hacker!" :-)
## legal fund: $20,495.69 collected, $182,159.85 spent; just 428 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: Sun, 29 Jun 1997 11:53:00 -0600
From: david@manifold-id.com
Subject: Re: msqlPERL - comon' baby!
Message-Id: <867601321.16982@dejanews.com>
In article <prof-ya02408000R2206971256230001@snews.zippo.com>,
prof@katz.com (professor katz) wrote:
>
> Is it me, or is the documentation for msqlperl woefully inadequate? I'm a
> SQL newbie to be sure, but I just want a list of functions and usage. I've
> checked through ALL of the documentation, but there is just some confusing
> stuff, and it's not at all clearly laid out.
>
> For instance the documentation points out:
>
> # Now we create two tables that are certainly not in the test database
> # If you don't understand the trickery here, just skip this section, No big
> deal.
> {
> my $goodtable = "TABLE00";
> my(%foundtable,@foundtable);
> @foundtable = $dbh->listtables;
> @foundtable{@foundtable} = (1) x @foundtable; # all existing tables are
> now keys in %foundtable
> my $limit = 0;
>
> for ($firsttable, $secondtable) {
> while () {
> next if $foundtable{++$goodtable};
> my $query = qq{
> create table $goodtable (
> she char(32),
> him char(32) not null,
> who char (32)
> )
> };
> unless ($dbh->query($query)){
> die "Cannot create table: query [$query] message
> [$Msql::db_errstr]\n" if $limit++ > 1000;
> next;
> }
> $_ = $goodtable;
> last;
> }
> }
> # For the tests in this script we have two tablenames that we can
> # peruse: $firsttable and $secondtable
> }
>
> Well, I don't understand the trickery, but I really need to! That qq{}
> business really throws me. But I'm new to PERL object-oriented stuff. The
> thing that really throws me, is that I can create a table just by typing:
>
> $sth = $dbh->query("create table test_table (
> name char(32),
> rank char(32),
> sn char(32)
> ));
>
> So what's the big whoop here? But one thing that I can't figure out is how
> to make a keyfield using msqlperl. There's no mention anywhere that I can
> find.
>
> Any help, support, or hints to finding more material would be greatly
> appeciated. BTW, I already found the mailing list archives, and I have
> subscribed to the mailing list. Most of my problems are pretty basic
> programming issues, and not related to setting up the programs on the
> server. LIke I said, I am fairly new to this stuff but I am struggling to
> find decent documentation. Also, If you're in my position, respond to my
> post and we'll start a mutual support group via email or something.
>
> Thanks,
> Katz
Katz,
Sounds like we're in the same boat. Have you had any luck finding better
documentation for msqlperl?
-------------------==== Posted via Deja News ====-----------------------
http://www.dejanews.com/ Search, Read, Post to Usenet
------------------------------
Date: 29 Jun 1997 16:21:30 GMT
From: timbo@ig.co.uk (Tim Bunce)
Subject: Perl 5.004_01 is available (Maintenance Release 1 for Perl5.004)
Message-Id: <5p622a$a9c$1@nadine.teleport.com>
The Perl development team is pleased to announce the release of
Perl 5.004_01. This is the first Maintenance Release for Perl 5.004.
Work on Perl has been split into separate development and maintenance
tracks from Perl 5.004 onwards.
The development track is focused on major enhancements to Perl and
will typically have a fairly long major release cycle. Work on 5.005
(which should include threading and improved compiler support) is
underway now. Alpha releases should be available in the coming months
with subversion numbers starting from 5.004_50.
The maintenance track is focussed on improving the quality of a given
Perl release (through bug fixes, documentation fixes and greater
portability etc) and will typically have a shorter release cycle.
Maintenance releases have subversion numbers starting from 5.004_01.
One goal of the maintenance track is that users should always feel
confident about installing a maintenance release subversion, such as
5.004_01, as an upgrade for the corresponding major version.
This release builds on the excellent work that went into the 5.004
release and adds these significant enhancements:
BUG FIXES
Fixed (..., undef, ...) = split(...) bug.
Fixed memory leak when using tied hashes and arrays.
Fixed backreferences with case-blind matching regexps.
Fixed scope for nested regexps.
Fixed AutoLoader problems with __DIE__.
Fixed list assignment to %ENV.
GREATER PORTABILITY
Greatly improved support for Win32. Many fixes.
Fixes for AIX, FreeBSD, NEWS-OS, NeXt/OpenStep and VMS.
OTHER FIXES AND ENHANCEMENTS
Many documentation and documentation tool fixes and updates including
perldelta, perldiag, perlembed, perlfaq8, perlfaq9, perlfunc, perlguts,
perllol, perlop, perlsub, perltoot, pod2man and Pod::Html.
installhtml now runs twice as fast and with fewer warnings.
@INC contents listed in use or require "Can't find" error.
Added more Fcntl constants.
KNOWN PROBLEMS / LATE BREAKING NEWS
General:
splitpod (called by installhtml) is broken. Use splitpod from 5.004.
pp.c and util.c may generate (harmless) compiler warnings.
Configure mistakenly finds getpgrp in UNICOS 9 where there is none.
The perlbug script does not work if the cwd is non-writable.
Fixes for gnuwin32/cygwin32 support have not been included.
Win32:
Test 1 of lib/timelocal.t may fail for some timezones.
Autoloading fails when perl is installed with a UNC path.
On DOSISH platforms, "perl -S" fails for absolute paths with backslashes.
The -d operator fails for some UNC top directories (//share/dir).
Most of these also exist in 5.004. Many, if not all, will be fixed in
the next maintenance release which is currently planned for mid to late July.
THINGS YOU NEED TO KNOW AND THINGS YOU NEED TO DO
[ These notes are primarily for people installing Perl for the first time
or upgrading from Perl 5.003 (or earlier). If you are upgrading a successful
5.004 installation then you should be able to follow the same procedure you
used before. ]
As usual it is *vital* that you read the file "INSTALL" before building this
release; it contains information you absolutely need to know. For example,
"INSTALL" explains how you can install Perl without removing previous
version(s) of Perl, and how you can make this Perl binary-compatible with
Perl 5.003 (and why you have a choice).
There are several new functions and features in Perl 5.004, including a
small number of unavoidable incompatibilities. See the change notices for
details, in the file "pod/perldelta.pod". It is *highly* recommended that
you read "pod/perldelta.pod" before using this release if you have any
previous experience with Perl.
IF YOU HAVE ANY PROBLEMS
If you find a bug, please report it to us with the "perlbug" script in the
"utils" directory of the distribution. Since you may have older versions
of "perlbug" installed, run it as "./perl utils/perlbug"; to display its
documentation, use the "-h" flag. If you cannot send external E-Mail from
your development platform, you can still use "perlbug" to prepare the bug
report and save it to a file, which you should then mail to
<perlbug@perl.com>.
If Perl didn't even compile, then you won't be able to use "perlbug".
Instead, compose your bug report by hand, being sure to include the output
of the "myconfig" shell script included in the distribution, and mail it to
<perlbug@perl.com>.
We re-emphasize: *Please* read "INSTALL" and "pod/perldelta.pod" carefully.
We are happy to answer questions, but our time is limited. By reading the
excellent documentation included with Perl before asking for help, you will
save yourself time, you will save us time, and you will help us debug the
documentation.
WHERE TO FIND IT
You will find this release on CPAN, the Comprehensive Perl Archive Network.
The following URL at Tom Christiansen's web server (perl.com) will
automatically direct your request to a CPAN FTP site appropriate for your
location:
http://www.perl.com/CPAN/src/5.0/perl5.004_01.tar.gz
http://www.perl.com/CPAN/src/5.0/perl5.004_01.patch.gz
If you wish to retrieve the file entirely with HTTP, you can use this URL
at The Perl Institute (perl.org):
http://www.perl.org/CPAN/src/5.0/perl5.004_01.tar.gz
http://www.perl.org/CPAN/src/5.0/perl5.004_01.patch.gz
MD5 checksums:
perl5.004_01.tar.gz => 'bc29b3bd93b6511234455ba733913ea0'
perl5.004_01.patch.gz => 'd9fdf41a62ff7e78be1b5aba169c225b'
Finally, to quote Douglas Adams: "Share and enjoy!"
Signed,
The Perl Development Team
------------------------------
Date: 28 Jun 97 14:23:41 GMT
From: hribnak@nucleus.com (Jim Hribnak)
Subject: Perl and killing processes
Message-Id: <33b51e6d.0@news.nucleus.com>
Is there a module out there that one can use to scan for certain programs
and kill them if they are around too long? IE I run a perl script I got
from someone, what it does is every 5 mins via crom it runs, connects to
our portmasters and counts how many people are online, if for some reason
it times out, the perl program will stick around, as well as the telnet
that is spawns.. Livingston Portmasters can only have i believe 5 telnet
sessions to it at once.
I want to add something to this perl program that will check to see if
its running from the last time, and kill the process ID of the old one
and also kill the telnet session that the original process spawned IE
Pmlog runs via cron every 5 mins
spawns a telnet session to a portmaster, does its logging and logs off
if forsome reason it cant connect to the portmaster, the pmlog and its
spawned telnet session do not exit they just sit there (telnet session is
a c program to do a variety of things)
Next time pmlog runs it may fail or it may not depending on the number of
hung telnet sessions to the particular portmaster. if its full of
telnets..it will not connect.
I want to add something to this perl script to check for OLD pmlogs still
running and old telnets that go a portmaster (via ps -ax telnet shows up
like: telnet <portmaster host> <port>)
Jim
------------------------------
Date: Sat, 28 Jun 1997 15:37:05 -0500
From: Al Aeby <prw1@execpc.com>
Subject: Perl call of 'C' library function
Message-Id: <33B575F1.371@execpc.com>
I have a C program table library that I want to be able to call from
Perl5. The table library of com files is named TABLES.LIB, I don't have
access to the source and it's 121K big.
The C Function Prototypes are:
void calcWidth( BOX_INFO_Ptr boxTTinfo );
void calcHeight( BOX_INFO_Ptr boxTTinfo );
void calcLenght( BOX_INFO_Ptr boxTTinfo );
void getTTableVersion( char* versString );
I know how to call these in C (which I am still a rookie at), but now
need to know how to do the setup and how to use them from a Perl CGI.
I've looked over the doc's for Perl and I get the believe that it can be
done, but that there are several approaches. Being new to Perl I am left
with a lot of confusion as to how. Any help would very much be
appreciated.
Al
------------------------------
Date: Sun, 29 Jun 1997 10:49:01 -0500
From: nneul@umr.edu (Nathan Neulinger)
Subject: Perl interface to IRC?
Message-Id: <nneul-2906971049020001@dialup-pkr-10-16.network.umr.edu>
Has anyone developed a perl interface to IRC?
I'm not talking about running a tool under one of the other IRC packages,
but a direct interface.
-- Nathan
------------------------------------------------------------
Nathan Neulinger Univ. of Missouri - Rolla
EMail: nneul@umr.edu Computing Services
WWW: http://www.umr.edu/~nneul SysAdmin: rollanet.org
------------------------------
Date: 29 Jun 1997 08:54:50 -0700
From: Randal Schwartz <merlyn@stonehenge.com>
To: "Jon Ewing" <jon@webdev.co.uk>
Subject: Re: Question: split and anonymous arrays
Message-Id: <8c3eq1e75h.fsf@gadget.cscaper.com>
>>>>> "Jon" == Jon Ewing <jon@webdev.co.uk> writes:
Jon> If I understand things right, [split /\t/, $line] will create an
Jon> anonymous reference to the array created by splitting the line
Jon> $line at every tab.
Yes.
Jon> Then, to get an element out we can do something like
Jon> $mainarray = [split /\t/, $line];
Jon> print @$mainarray[0];
That should be $mainarray->[0], but yours would work for reasons that
are dangerous in other contexts... hint: please use $foo[3] when
accessing a scalar, and @foo[3,4,5] when accessing a slice.
Jon> But is it possible to avoid using the string $mainarray?
Yes.
Jon> i.e. why doesn't this work..
Jon> print @[split /\t/, $line][0];
Because it's slightly bad syntax. This will work:
print [split /\t/, $line]->[0];
As will this uglier equivalent form:
print ${[split /\t/, $line]}[0];
The problem is that:
${ listref }[$index]
works as the canonical de-ref-to-get-an-element form, and we can get
rid of the { } if listref is a scalar variable, but not otherwise.
Yours fell into the "otherwise" category.
But rather than create an anonlist just to use a piece of it, I'd
go back to the standby perl4 syntax of a literal slice:
print +(split /\t/, $line)[0];
Unfortunately, I have to prefix it with + for print, but you'll get
the idea I hope.
Jon> I realise there are easier ways to get the first member of the list, but
Jon> I'm curious...
Another way to get the first member is with an array assignment to
a list literal:
($first) = split /\t/, $line;
That's generally how I do it when I want just the first word.
print "Just another Perl hacker," # but not what the media calls "hacker!" :-)
## legal fund: $20,495.69 collected, $182,159.85 spent; just 429 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: 29 Jun 1997 08:58:19 -0700
From: Randal Schwartz <merlyn@stonehenge.com>
To: wesley@woais.com
Subject: Re: Question: split and anonymous arrays
Message-Id: <8czps9csf8.fsf@gadget.cscaper.com>
>>>>> "Wesley" == Wesley Miaw <wesley@woais.com> writes:
Wesley> I'm not completely sure if this is what you're looking for, or if it will work
Wesley> correctly, but to forget $mainarray, might you do the following?
Wesley> [split(/\t/, $line)];
Wesley> print $_[0];
Wesley> I don't know if the array reference will be passed to the
Wesley> default variable $_, but if it does, that would work and you
Wesley> aren't creating an extra variable, which is just about the
Wesley> only reason I can think of avoiding $mainarray, other than
Wesley> hoping for faster execution.
No, it won't. See my other answer in this thread for more details.
Your code would generate a split, take the results and create an
anonlist, and then throw away the reference to that. @_ is unaffected
by all that.
As a matter of historical trivia, the now-deprecated form:
split /\t/, $line;
print $_[0];
*would* have worked. But please don't use this in new code, because
the meaning for @_ has now shifted exclusively to "the subroutine arg
list".
print "Just another Perl hacker," # but not what the media calls "hacker!" :-)
## legal fund: $20,495.69 collected, $182,159.85 spent; just 429 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: 29 Jun 1997 02:50:57 -0700
From: Russ Allbery <rra@stanford.edu>
To: "Rick Stanback" <rstanbac@ix.netcom.com>
Subject: Y2K and Perl (was Re: Y2K problems??)
Message-Id: <m3n2o9yby6.fsf_-_@windlord.Stanford.EDU>
[ Newsgroups trimmed to the appropriate one, comp.software.year-2000
added, copies e-mailed to both askers. ]
In comp.lang.perl.misc, Rick Stanback <rstanbac@ix.netcom.com> writes:
> Jyoti Patel <jyoti@net.com> wrote:
>> We need to identify any Year 2000 problems that exist in the third
>> party software we use.
>> We also use the following: [...] perl5.003
> I would also like this information. If anyone can answer please post to
> the group.
Perl itself is a language. This is very similar to asking whether C has a
year 2000 problem. The answer is "it depends."
There is nothing about the Perl language that inherently forces or causes
year 2000 problems, just like with C. If you pick your data structures
appropriatly and think about what you're doing, it's quite easy to avoid
problems. One major thing to watch out for is the same as C; be careful
with localtime. In particular, know what localtime returns in an array
context (similar to knowing what a struct tm is in C). The year returned
is *the number of years since 1900*. It's *not* the last two digits of
the year, and it does *not* have a year 2000 problem, but you have to know
what to do with it.
To get the full year from the year returned by localtime, you need to add
1900. Perl code that does something like:
$year = '19' . (localtime)[5];
will result in a year of 20100 in 2000.
Other common problems for Perl scripts are using filenames that contain
only the last two digits of the year, or getting dates from `date`
(possibly with some format string) rather than from the builtin localtime
or gmtime functions. This is bad; this is why you always want to use the
built-ins. /bin/date *does* have Y2K problems on some platforms. For
example, on SunOS /bin/date has no way of returning the full year rather
than just the last two digits. The solution is to upgrade to Solaris,
install GNU date, or preferrably make sure all your Perl scripts use the
builtin Perl functions which call the C library calls and do the right
thing. Even on Solaris, make sure you use a format string of %Y rather
than %y to get the year. (This is the same issue as strftime(3) in C
programs.)
--
#!/usr/bin/perl -- Russ Allbery, Just Another Perl Hacker
$^=q;@!>~|{>krw>yn{u<$$<[~||<Juukn{=,<S~|}<Jwx}qn{<Yn{u<Qjltn{ > 0gFzD gD,
00Fz, 0,,( 0hF 0g)F/=, 0> "L$/GEIFewe{,$/ 0C$~> "@=,m,|,(e 0.), 01,pnn,y{
rw} >;,$0=q,$,,($_=$^)=~y,$/ C-~><@=\n\r,-~$:-u/ #y,d,s,(\$.),$1,gee,print
------------------------------
Date: Sun, 29 Jun 1997 23:15:08 +1000
From: Wayne Blick <wayne@cta-challenge.com.au>
Subject: Zombie processes under system load
Message-Id: <33B65FDC.5CA8@cta-challenge.com.au>
Hi all,
I've tried several of the documented child "reaper" coding examples.
I'm using a forked process to handle activity on a network socket.
Everything works OK under light load, and child processes are cleaned up
by the parent "reaper".
But, when several forks are required in say a 5 second period, the
"reaper" code misses some child signals and they become zombies.
Any ideas? I'm using Linux 1.2.13 and Perl 5.003.
Thanks.
Wayne Blick
------------------------------
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 682
*************************************