[13170] in Perl-Users-Digest
Perl-Users Digest, Issue: 580 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Aug 18 21:07:24 1999
Date: Wed, 18 Aug 1999 18:05:11 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Wed, 18 Aug 1999 Volume: 9 Number: 580
Today's topics:
Re: A prime numbers program. (Benjamin Franz)
Re: cannot write description to eventlog (elephant)
Re: CGI and NT (Tom Dominico, Jr.)
Re: CGI and NT (elephant)
Re: Counting the amount of lines in a file.. (elephant)
Does anyone know Perl call PL/SQL store procedure URL l <weiming@wt.infi.net>
Re: Forking??? <mpersico@erols.com>
Re: GMT not local server time? <crt@kiski.net>
How to get length of multidimensional array element (Greg Shalette)
Re: Icon in systray on Windows NT (elephant)
Re: kill (0, $pid) (Charles DeRykus)
learning perl from a book,need help <bzhaainc@erols.com>
Re: Matt's cookielib and Unicode <mpersico@erols.com>
net use won't work in perl <chansam@worldnet.att.net>
Re: Newbie question: Creating a NT login script in Perl (elephant)
Re: parse array content <makkulka@cisco.com>
Perl/C++/xsubpp <vyl@leland.Stanford.EDU>
Re: Q:Two perl programs printing to one txt file (elephant)
reverse() weirdness (IGuthrie)
Re: reverse() weirdness (IGuthrie)
Re: Running Perl CGI in Apache on WinNT (elephant)
Re: shell script translation (Larry Rosler)
Re: someone pleae help (Tom Dominico, Jr.)
system() under Win32 <john@dlugosz.com>
Re: what does eq do on lists? <john@dlugosz.com>
Re: what does eq do on lists? <john@dlugosz.com>
Re: what does eq do on lists? (elephant)
What does gmtime[3,4,5] do? <john@dlugosz.com>
Re: What does gmtime[3,4,5] do? <meowing@banet.net>
Re: What does gmtime[3,4,5] do? (elephant)
while ($filename = <*.pm> (Derek)
Re: Why use Perl when we've got Python?! (Mark W. Schumann)
Digest Administrivia (Last modified: 1 Jul 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Thu, 19 Aug 1999 00:11:17 GMT
From: snowhare@long-lake.nihongo.org (Benjamin Franz)
Subject: Re: A prime numbers program.
Message-Id: <FYHu3.565$IZ4.34337@typhoon01.swbell.net>
In article <x3ypv0kly5z.fsf@tigre.matrox.com>,
Ala Qumsieh <aqumsieh@matrox.com> wrote:
>
>Here you are taking the brute force approach of testing if $number
>(which is odd) is divisible by any odd number greater than 2 and
>smaller than the square root of $number. Which is WRONG.
>Your numbers should go all the way up to $number/2:
No. It is correct. Think about it - How can a number have *both*
divisors larger than the square root of the number? At least
one divisor will be smaller than that - and so there is no
point in checking larger divisors than the square root of
the number.
--
Benjamin Franz
------------------------------
Date: Thu, 19 Aug 1999 09:39:32 +1000
From: elephant@squirrelgroup.com (elephant)
Subject: Re: cannot write description to eventlog
Message-Id: <MPG.1224aa09fc396e76989c3f@news-server>
da_minch@my-deja.com writes ..
>In article <MPG.122399e2a428ab6c989c38@news-server>,
> elephant@squirrelgroup.com (elephant) wrote:
>
>> I have no idea where you're reading your documentation for this
>module
>> from .. I couldn't find any in the module itself .. but the
>> documentation that you're using is clearly wrong - because your hash
>> keys are all screwy .. and you seem to have a warped idea of what the
>> first parameter to 'new' is (it's NOT the section of the event log)
>>....
>
>thanks. (i didn't have any docs just the module.) i do have some
>sorting of my code to do as my hash keys are screwy and i have actually
>been writing jibberish to the eventlog and didn't realize it.
>entvwr.exe returns an error when trying to view the description of my
>manual entries and it wasn't until i pulled the $h{strings} portion of
>the hash via a $Event->Read script that i was able to see what i had
>been inserting..
yes .. (a) I was getting an error when trying to open an event entered
with the code you supplied - "The system cannot find the file specified"
.. and (b) my code will create valid events when reading the event log
with both the Win32::EventLog module AND with the NT Event Viewer
> it appears that a path to a message file for a given
>app must be stored in the registry at:
>HKEY_LOCAL_MACHINE
> System
> CurrentControlSet
> Services
> EventLog
> Application
> WhatEverApp
> EventLogMessageFile
>for eventvwr.exe to display a messsage. (but this is not my concern as
>the purpose of what i am doing is to avoid dependency on eventvwr.exe.)
oic .. that's where you map an EventID to an Event string .. you must
have to provide an entry point for the eventvwr.exe to call into .. I
wonder how to do THAT in Perl - don't you love new projects *8^)
--
jason - elephant@squirrelgroup.com -
------------------------------
Date: Wed, 18 Aug 1999 16:32:19 -0700
From: news@tomd.SPAMfree.org (Tom Dominico, Jr.)
Subject: Re: CGI and NT
Message-Id: <MPG.1224e259f8629d03989682@news.netasset.com>
In article <7pdbna$nl9$1@garnet.nbnet.nb.ca>, stevencNOSPAM@nbnet.nb.ca
uttered these pearls of wisdom...
> I am trying to run CGI scripts on an IIS NT4 with activeperl installed and
> the .PL extension associated to perl.exe in the web server
<snip>
Without any more background, who knows how to help? This is probably
not a Perl question, but instead related to IIS or CGI. All I can say
is that Perl was up and running for me in minutes... Check your
permissions, etc. You *DID* map the .pl extension to perl.exe %s %s,
right? (Pause for Homer Simpson-like "DOH!!!")
=================================
Tom Dominico, Jr.
Application Developer
Holm-Dietz Computer Systems, Inc.
news@tomd.org
------------------------------
Date: Thu, 19 Aug 1999 09:40:30 +1000
From: elephant@squirrelgroup.com (elephant)
Subject: Re: CGI and NT
Message-Id: <MPG.1224ebcafd74ed2d989c47@news-server>
Caper writes ..
>I am trying to run CGI scripts on an IIS NT4 with activeperl installed and
>the .PL extension associated to perl.exe in the web server, can anyone help.
yeah .. the documentation .. see one of the 26 billions posts per day to
this newsgroup on this subject and the subsequent direction to the
appropriate ActiveState Win32 FAQ
>Please email stevenc@nbnet.nb.ca
not likely
--
jason - elephant@squirrelgroup.com -
------------------------------
Date: Thu, 19 Aug 1999 09:39:38 +1000
From: elephant@squirrelgroup.com (elephant)
Subject: Re: Counting the amount of lines in a file..
Message-Id: <MPG.1224db74eeeb8349989c42@news-server>
Larry Rosler writes ..
>In article <37B9B3DB.40FE7ED9@cisco.com> on Tue, 17 Aug 1999 12:11:23 -
>0700, Makarand Kulkarni <makkulka@cisco.com> says...
>> [ Andrew Weller wrote:
>>
>> > Is it possible to read in a file and count in the amount of lines so that a
>> > for loop can be initialised with the amount of lines (or data points)?
>>
>> Yes. You could read one line at a time and keep a count of
>> how many you read. Or read all lines into an array and then
>> find how many elements this array contains ( assign this array
>> to a scalar, for example ). Perl also has $. ( dollar DOT ) a
>> special variable that will have the current input line number
>> of the last filehandle that was read.
>
>And there is even a FAQ! perlfaq5: "How do I count the number of lines
>in a file?"
and even more amazingly .. the originator didn't realise he could do
while (<FILEHANDLE>) { ... }
what's this group coming to ? - the infants are getting stupider .. are
they teaching Perl to people who can't read these days or something ??
.. I can see the code now...
#!usr\loca\perl
$x = "file1";
$x = system( "wc -l $x");
$x = $x =~ /([0123456789]*)/g;
for ( $i = 0; $i <= $x; $i++)
{
# $l = system( "head -n $i $x | tail -n 1");
$l = system( "head -n $i file1 | tail -n 1");
print $l;
}
# the end
--
jason - elephant@squirrelgroup.com -
------------------------------
Date: Wed, 18 Aug 1999 19:23:22 -0300
From: Weiming He <weiming@wt.infi.net>
Subject: Does anyone know Perl call PL/SQL store procedure URL links?
Message-Id: <37BB325A.2149@wt.infi.net>
Hi
Does anyone know Perl call PL/SQL store procedure URL links?
Especially for transaction PL/SQL procedure. If someone knows
please drop me lines. Thanks in advance.
Weiming
------------------------------
Date: Wed, 18 Aug 1999 20:12:11 -0400
From: "Matthew O. Persico" <mpersico@erols.com>
Subject: Re: Forking???
Message-Id: <37BB4BDB.B2AC07A7@erols.com>
Run, don't walk and get yourself a copy of The Perl Cookbook. I just went
through the same learning curve this week and flattened it out to a
straight line thanks to chapter... can't remember the number, the book is
at work.
Bob Freedman wrote:
>
> I am trying to launch several instances of a perl program (test.pl)
> while my parent process continues processing. Below is the parent
> process but I am having trouble launching the child process.
>
> foreach (@URL) {
> $summaryFile = "$i\.summary";
> $run = "/usr/local/bin/perl /cgi-bin/test.pl";
> open(SUMMARIES,"$run $_ $var $summaryFile");
> }
>
> Any help is greatly appreciated.
--
Matthew O. Persico
You'll have to pry my Emacs from my cold dead oversized
control-pressing left pinky finger. -- Randal L. Schwartz
------------------------------
Date: Wed, 18 Aug 1999 19:01:12 -0400
From: "Casey R. Tweten" <crt@kiski.net>
Subject: Re: GMT not local server time?
Message-Id: <Pine.OSF.4.10.9908181859410.20389-100000@home.kiski.net>
On Wed, 18 Aug 1999, Pelican Brief wrote:
:Is there any easy way to display the time in GMT with perl
perhaps the gmtime() function?
perldoc -f gmtime
I 'hope' this helps.
--
Casey R. Tweten <joke> This
Web Developer is 100% certified
HighVision Associates virus and bug
crt@highvision.com free code. </joke>
------------------------------
Date: 18 Aug 1999 21:01:22 -0400
From: gshalet@panix.com (Greg Shalette)
Subject: How to get length of multidimensional array element
Message-Id: <7pfl12$c2q$1@panix3.panix.com>
How does one get the length of one element of a multidimensional array?
Eg.
$#ComData[2] doesn't work for getting the length of the 3rd element of
the array ComData.
Thanks!
--
Greg Shalette
gshalet@panix.com
------------------------------
Date: Thu, 19 Aug 1999 09:40:00 +1000
From: elephant@squirrelgroup.com (elephant)
Subject: Re: Icon in systray on Windows NT
Message-Id: <MPG.1224e4f3d7f258fe989c44@news-server>
Patrick Renaud writes ..
>I work on Windows NT 4 and want the icon of a program (of the DOS window of
>my program) to go in the systray (near the clock) instead of being displayed
>in the taskbar.
>
>How can I do this with my favourite Perl ?
assuming that there's not already a module on CPAN that does this (which
I certainly can't be bothered finding out) then you'll have to write
your own
the systray and taskbar operations are DLL calls .. so you'll need to
read up on how to make DLL calls from within Perl .. start with
perldoc perlxs
then have a look at this page on Microsoft's web page (note - you'll
have to paste the URL back together)
http://msdn.microsoft.com/library/periodic/period96/periodic/msj/f1/d4/s
dbe.htm
it should set you on the right path
--
jason - elephant@squirrelgroup.com -
------------------------------
Date: Wed, 18 Aug 1999 23:59:34 GMT
From: ced@bcstec.ca.boeing.com (Charles DeRykus)
Subject: Re: kill (0, $pid)
Message-Id: <FGoqnA.A51@news.boeing.com>
In article <7pc21p$6g1$1@nnrp1.deja.com>, <lan_chai@my-deja.com> wrote:
>Hi everyone. I'm a newbie and I have this problem. I opened a process with
>open(PROC, "something arg|"). I time it with a while loop and if it takes
>too long, I kill it. The test to see if it's still running is by "kill (0,
>$pid)" (I read this in Perl5 Unleashed). This way of doing it doesn't seem
>to give me that the process has ended if I did not get the output of the
>process yet. Is it true that a process is not really completed if it doesn't
>have all the output read yet?
>
>
You've opened a pipe from the process. All the output almost
certainly will not be seen until you close the filehandle.
Closing will transparently reap the forked process and flush the
buffers. See the doc for C<close>, perldoc -f close.
The process will hang around until the C<close> in
any case. I don't believe a C<kill> is the way to go;
a better method would block C<eval> that entire section
of code with an C<alarm>. perldoc -f alarm for an example
of this. If, there's a time out, then you could terminate
the process with a kill TERM, $pid for instance. Or,
perhaps, you might want to send a kill,0 to see what
happened. Take a look at "Sending a Signal" in the Perl
Cookbook for instance. Here's a short segment:
use POSIX qw(:errno_h);
if (kill 0 => $minion) {
print "$minion is alive\n";
} elsif ($! = EPERM) {
print "$minion has escaped my control\n";
} elsif ($! = ESRCH) {
print "$minion is deceased\n; # or zombied
} else {
warn "Odd, I couldn't check on the status of $minion: $!\n";
}
hth,
--
Charles DeRykus
------------------------------
Date: Wed, 18 Aug 1999 20:27:06 -0400
From: "Ben Horowitz" <bzhaainc@erols.com>
Subject: learning perl from a book,need help
Message-Id: <7pfj4t$ao4$1@autumn.news.rcn.net>
i need help, i dont understand the jargan?,what is a string?,when do you use
double postrophies",and when do you use single postrophies'?is it possiable
to learn only from a book,i just started and am a real newbie,?
------------------------------
Date: Wed, 18 Aug 1999 20:17:18 -0400
From: "Matthew O. Persico" <mpersico@erols.com>
Subject: Re: Matt's cookielib and Unicode
Message-Id: <37BB4D0E.ACC06E00@erols.com>
David Huggins-Daines wrote:
>
> BTW, it's a generally accepted fact that learning Perl via Matt's
> Scripts is a bad idea :)
Gee. I thought I wrote decent scripts. My employer thinks so anyway. :-)
Well you can imagine my chagrin at having my name (even if it is only my
first!) tarnished on what seems to be a weekly basis. I've never seen these
scripts. Anyone have a URL? I'd like to see just how bad it is for the fun
of it.
If you think it would be a bad idea to post a pointer to allegedly rotten
code, feel free to mail privately.
Much obliged.
--
Matthew O. Persico
fork() die() reap(). It's enough to make me hug the kids
real hard when I get home...
------------------------------
Date: Wed, 18 Aug 1999 20:25:01 -0400
From: "Sam Chan" <chansam@worldnet.att.net>
Subject: net use won't work in perl
Message-Id: <7pfje4$h0g$1@bgtnsc02.worldnet.att.net>
I am using Perl to map a drive. However, it never works. Here is my
statement:
system( "net use t: \\\\srvrabc\\c\$ /user:administrator" );
or `net use t: \\\\srvrabc\c$ /user:administrator`;
Please advice
------------------------------
Date: Thu, 19 Aug 1999 09:39:36 +1000
From: elephant@squirrelgroup.com (elephant)
Subject: Re: Newbie question: Creating a NT login script in Perl
Message-Id: <MPG.1224ab7b7700cca5989c40@news-server>
SH writes ..
>no I use Frontpage for my Perl scripts =-).
wicked dude .. I dig those narly Microsoft apps
where did that come from ? .. no idea .. I guess (no offense intended -
but feel free to take it anyway) that I always imagine Microsoft people
speaking with those lamer than lame Baywatch accents that signify a
complete lack of understanding in anything unrelated to aesthetics
--
jason - elephant@squirrelgroup.com -
------------------------------
Date: Wed, 18 Aug 1999 17:51:52 -0700
From: Makarand Kulkarni <makkulka@cisco.com>
Subject: Re: parse array content
Message-Id: <37BB5528.534D9BFF@cisco.com>
[webmaster@man.amis.com wrote:
how can i parse array content so that
@params = q->param('bu')
#where bu is the name of a checkbox form
@params will look like ('01','02','03').
--Example using CGI.pm --
use CGI ;
use Data::Dumper;
$page = new CGI;
print $page ->header ;
print $page ->start_html ();
if ( ! $page->param ())
{
print $page->start_form();
print $page-> checkbox_group(-name=>'bu',
-values=>['01','02','03','04'],
-defaults=>['01','02']) ;
print $page->submit();
print $page->end_form();
}
else
{
my @v = $page->param ( 'bu' );
print Dumper \@v ;
}
print $page ->end_html ();
exit;
--
------------------------------
Date: Wed, 18 Aug 1999 16:21:43 -0700
From: Vyl Chan <vyl@leland.Stanford.EDU>
Subject: Perl/C++/xsubpp
Message-Id: <Pine.GSO.3.96.990818161659.9062A-100000@myth3.Stanford.EDU>
Hi,
I'm trying to call functions from a C++ library from within my
perl script. First, can this be done through h2xs? or do i need to compile
through xsubpp -C++? Also, I can't seem to be able to get a xsubpp man
page on my Linux machine. I have perl 5 installed. Is xsubpp not a feature
on perl 5? Any insight/help would be greatly appreciated =) Thanks!
--Vyl
Vyl Chan
Stanford University
------------------------------
Date: Thu, 19 Aug 1999 09:39:48 +1000
From: elephant@squirrelgroup.com (elephant)
Subject: Re: Q:Two perl programs printing to one txt file
Message-Id: <MPG.1224e274df01202989c43@news-server>
Eric The Read writes ..
>Makarand Kulkarni <makkulka@cisco.com> writes:
>> > Opening the file in each program to append is all that is necessary. The
>> > seek is unnecessary.
>>
>> Yes. Only if you assume that you want to do a single append and immediately
>> after opening the file.
>
>No, it's unnecessary at all times. Opening a file for append means that
>the underlying C library always writes all data to the end of the file.
>That is, even if you open it as "+>>file", no matter where you're reading
>from, the data is always written at the end of the file. There is an
>implicit seek(), if you like.
that's weird .. certainly my experiements seem to support this .. but I
had the impression that it wasn't this way at all .. mainly from the
example in the flock() documentation which includes a
seek( FILEHANDLE, 0, 2);
with the comment of
"in case someone appended while we were waiting"
my experiments are in Win32 .. could it be possible that you need to
seek on other OSs ?
--
jason - elephant@squirrelgroup.com -
------------------------------
Date: 18 Aug 1999 23:45:58 GMT
From: iguthrie@aol.com (IGuthrie)
Subject: reverse() weirdness
Message-Id: <19990818194558.21912.00001319@ng-ch1.aol.com>
Hi I was mucking around with reversing a flat file so that the first line would
end up on the bottom. Anyway I wrote a two line program to do this and print
the reversed file to STDOUT.
If I do this it works fine:
open(FILE, "$file") || die "$! $file\n";
print reverse(<FILE>);
But if I do this:
open(FILE, "$file") && print reverse(<FILE>) || die "$! $file\n";
Not only does it reverse the order of the file but all of the charactes in the
file are printed in reverse order. Why does one do one thing and he other do
another?
Thanks
BTW I am using 5.004_01
------------------------------
Date: 19 Aug 1999 00:25:35 GMT
From: iguthrie@aol.com (IGuthrie)
Subject: Re: reverse() weirdness
Message-Id: <19990818202535.21913.00001143@ng-ch1.aol.com>
Oops I forgot to enclose the print in () which was why I wasnt gettting the
output I wanted.
Thaks
------------------------------
Date: Thu, 19 Aug 1999 09:40:10 +1000
From: elephant@squirrelgroup.com (elephant)
Subject: Re: Running Perl CGI in Apache on WinNT
Message-Id: <MPG.1224e8b1faf542c5989c45@news-server>
apothen@my-deja.com writes ..
> I've recently installed the most recent
>release of Active Perl on my WinNT machine. I
>downloaded a simple file upload script, installed
>it per instructions (that much I can do :), and
>gave it a whirl. Unfortunately, whenever I
>attempt to upload a file Apache returns the
>unhelpful "Server Error"; checking the error log,
>it says "No such file or directory: Unable to
>spawn child process "e:\<path>"."
try reading the Win32 FAQs that came with your ActiveState distribution
.. the answer is in there .. it's the one that's cryptically named "Web
Server Config" .. perlwin32faq6 from memory .. but I can't be bothered
looking it up for you
--
jason - elephant@squirrelgroup.com -
------------------------------
Date: Wed, 18 Aug 1999 17:51:44 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: shell script translation
Message-Id: <MPG.1224f4f836c26628989e71@nntp.hpl.hp.com>
In article <slrn7rmabh.poq.elflord@panix3.panix.com> on 18 Aug 1999
17:45:22 -0400, Donovan Rebbechi <elflord@panix.com> says...
...
> in perl, like shellscript, variables are expanded inside single ( but
> not double ) quotes.
You have that backwards.
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Wed, 18 Aug 1999 16:24:25 -0700
From: news@tomd.SPAMfree.org (Tom Dominico, Jr.)
Subject: Re: someone pleae help
Message-Id: <MPG.1224e080de73fd85989681@news.netasset.com>
In article <37BA9B4F.FC0C00D9@cig.mot.com>, cerna@cig.mot.com uttered
these pearls of wisdom...
> Guys I have never wrote a perl script...
<snip>
Boy, when that is the first line of the post, things can only go
downhill... I used to think that some of the regulars on this NG were a
little harsh on the newbies, but after lurking about for a month and
reading dozens of posts like these, I'm starting to understand... The
people on this NG are MUCH more willing to help if you have made your
best effort to help yourself. For instance, "Here's a script I've
written but am having problems with. I've checked the FAQs, etc..."
The programmers in this group probably have plenty of work to do without
doing your work as well. Get a good book or check out one of the many
online tutorials, but for God's sake, put a little effort in.
=================================
Tom Dominico, Jr.
Application Developer
Holm-Dietz Computer Systems, Inc.
news@tomd.org
------------------------------
Date: Wed, 18 Aug 1999 19:04:10 -0500
From: "John M. Dlugosz" <john@dlugosz.com>
Subject: system() under Win32
Message-Id: <ED54358BD8CF567A.3BA87139CB3D1854.19A40CC684DA1732@lp.airnews.net>
Consider the call: system $x;
That is, one argument to system, holding a string.
If the string contains
foo.exe arg arg arg
it works just fine.
If the string contains
"foo.exe" arg arg arg
the spawning process fails to find the program.
In this case, it's not necessary. But if the program name contained spaces,
the quotes would be required. Shouldn't the logic behind system()
understand this?
As a work-around, I used two arguments to system: the first containing the
program name, the second containing the args. This handles the case where
the first arg contains spaces.
--John
------------------------------
Date: Wed, 18 Aug 1999 18:19:48 -0500
From: "John M. Dlugosz" <john@dlugosz.com>
Subject: Re: what does eq do on lists?
Message-Id: <FFFC7759843292C7.0444B597A2418BF0.711ED0516FAC75C4@lp.airnews.net>
Sam Holden <sholden@pgrad.cs.usyd.edu.au> wrote in message
news:slrn7rk4v9.die.sholden@pgrad.cs.usyd.edu.au...
> It does a string comparison of @a[0..3] and @b.
> ...
> I'm not sure what you mean by undef being the result though
Here is a test program:
#!perl -w
use strict;
my @a= qw(one two three four five);
my @b= qw(one two three four);
my $result= @a[0..3] eq @b;
print "result is [$result]\n";
I get an empty result "[]" printed, when I expected "[1]" or some other TRUE
value.
So I conclude that it's not comparing the strings.
--John
------------------------------
Date: Wed, 18 Aug 1999 18:31:01 -0500
From: "John M. Dlugosz" <john@dlugosz.com>
Subject: Re: what does eq do on lists?
Message-Id: <686157B27A494FB5.7527189AD044D973.B357D81D577B0281@lp.airnews.net>
William Herrera <posting.account@lynxview.com> wrote in message
news:37ba4752.15705811@news.rmi.net...
> On Tue, 17 Aug 1999 20:41:07 -0500, "John M. Dlugosz" <john@dlugosz.com>
wrote:
> same as (scalar @a[0..3]) eq (scalar @b) ie compares the number of
elements in
> the arrays.
Thanks for the simple answer.
So I should get
4 eq 4
which would be TRUE. Hmm, that explaination doesn't match the data
presented.
Though the conclusions are wrong, the point that eq implies scalar context
for its arguments is the correct answer. Rick Delaney points out the
ramifications in his post, earlier in this thread.
> look up join in perlfunc
Why would I want to do that?
I know what join does, and it was discussed as a possible way to compare
four elements earlier in this discussion thread.
--John
------------------------------
Date: Thu, 19 Aug 1999 09:40:20 +1000
From: elephant@squirrelgroup.com (elephant)
Subject: Re: what does eq do on lists?
Message-Id: <MPG.1224eb80d9a9c5a7989c46@news-server>
Rick Delaney writes ..
>@a[0..3] is a list ($a[0], $a[1], $a[2], $a[3]), not an array, so in
>scalar context it returns $a[3], which just happens to be 4 in your
>example. @b is an array so it returns its number of elements in scalar
>context which is also 4.
thank you .. I was just puzzling over why this worked - had forgotten
the slice thingy
--
jason - elephant@squirrelgroup.com -
------------------------------
Date: Wed, 18 Aug 1999 18:40:10 -0500
From: "John M. Dlugosz" <john@dlugosz.com>
Subject: What does gmtime[3,4,5] do?
Message-Id: <2E4E840F164BDED4.A1DBB8413B3072E1.FDAFCE9A56832023@lp.airnews.net>
When I wrote
my ($d,$m,$y) = gmtime [3,4,5];
I got 52, 52, 7. Now the value 7 is found at subscript 4 from the original
list, but 52 is not found anywhere, in the return value from gmtime, so
where is this number coming from?
Writing it using a temporary,
@x= gmtime;
my ($d,$m,$y) = @x [3,4,5];
gives the expected results, so I know the values are there, and gmtime by
itself does what I expect.
But what is the first way doing?
If the subscript is taken as scalar, then 3,4,5 is simply 5, and applying
[5] to list context return from gmtime doesn't produce any of these values,
and in any case would only produce =one= value ($m and $y would be undef).
Applying a subscript to the scalar context return from gmtime, a string,
produces a syntax error.
Anybody know what this statement does?
--John
------------------------------
Date: 18 Aug 1999 20:14:27 -0400
From: meow <meowing@banet.net>
Subject: Re: What does gmtime[3,4,5] do?
Message-Id: <87n1vod3to.fsf@banet.net>
John M Dlugosz <john@dlugosz.com> wrote:
> When I wrote
> my ($d,$m,$y) = gmtime [3,4,5];
> I got 52, 52, 7. Now the value 7 is found at subscript 4 from the original
> list, but 52 is not found anywhere, in the return value from gmtime, so
> where is this number coming from?
I'm sure this is documented somewhere, but can't seem to locate the
spot, so...
To get individual elements from a function, stuff it inside parens,
like:
my ($d,$m,$y) = (gmtime())[3,4,5];
------------------------------
Date: Thu, 19 Aug 1999 10:37:37 +1000
From: elephant@squirrelgroup.com (elephant)
Subject: Re: What does gmtime[3,4,5] do?
Message-Id: <MPG.1225fcdf104f4f28989c49@news-server>
John M. Dlugosz writes ..
>When I wrote
> my ($d,$m,$y) = gmtime [3,4,5];
you were actually doing this
my ($d,$m,$y) = gmtime([3,4,5]);
what you wanted to do was to evaluate gmtime() - or even more explicitly
gmtime(time()) - in a list context and take a slice .. that would be
like this
my ($d,$m.$y) = (gmtime)[3,4,5];
what your original will do is to take the scalar numeric value of
[3,4,5] which will be some memory address somewhere .. and pass it to
the gmtime function .. you can see what it will use by doing this
my $x = [3,4,5];
print $x, "\n";
my ($d,$m,$y) = gmtime($x); # confirming the same results
print "$d $m $y\n";
>Anybody know what this statement does?
when in doubt .. print it out
--
jason - elephant@squirrelgroup.com -
------------------------------
Date: Thu, 19 Aug 1999 10:55:54 +1000
From: nospam-derek@realware.com.au (Derek)
Subject: while ($filename = <*.pm>
Message-Id: <MPG.12251dafb807fd64989683@news.hutch.com.au>
I am using Perl on NT4 (activePerl)
My script
use strict;
use diagnostics -verbose;
use CGI qw(:standard);
my $path = param('path') or die "No path specified";
my $filename;
my $line;
my $match = "FindThis";
while ($filename = <$path>)
{
print "checking $filename\n";
open (FILE, $filename);
while ($line = <FILE>)
{
chop($line);
if ( $line =~ /$match/i )
{
print "Match found in: $filename \n";
close FILE;
last;
}
}
}
exit;
The line
while ($filename = <$path>)
causes the error
Uncaught exception from user code:
Can't use string ("*.pm") as a symbol ref while "strict refs" in use at
G:\Build\file_report.pl line 21.
when I run the script with parameters
script.pl path=*.pm
I can say
while ($filename = <*.pm>)
which works
I have looked in perlref, but have not figured out how to get $path to satisfy
the requirements. Is it possible.
I want to be able to specifiy the name path to search on the command line.
I realize I can use grep to do what this script does, but I want to do other
operations when a match is found. For example I want to read the file header
and and function headers in the file and print them to an output file. If there
is a module to do this sort of thing already perhaps you would be so kind to
point me at it. Though I would still apreciate an answer to my question as I
will have other uses for it.
Thanks
Derek
------------------------------
Date: 18 Aug 1999 20:34:39 -0400
From: catfood@apk.net (Mark W. Schumann)
Subject: Re: Why use Perl when we've got Python?!
Message-Id: <7pfjev$ita@junior.apk.net>
In article <37B44618.ED01B54@pacbell.net>,
Miles Egan <milese@pacbell.net> wrote:
>Of course, now that the STL is a part of standard C++, nobody has much
>of an excuse to do this in C++.
["this" being reinventing data structures such as linked lists and
trees, not "this" as in "like $self"]
Bizarrely, I still see people doing this all the time. I have no
idea why they don't just use the darned templates and be done with
it.
------------------------------
Date: 1 Jul 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 1 Jul 99)
Message-Id: <null>
Administrivia:
The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc. For subscription or unsubscription requests, send
the single line:
subscribe perl-users
or:
unsubscribe perl-users
to almanac@ruby.oce.orst.edu.
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" from
almanac@ruby.oce.orst.edu. The real FAQ, as it appeared last in the
newsgroup, can be retrieved with the request "send perl-users FAQ" from
almanac@ruby.oce.orst.edu. 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" from
almanac@ruby.oce.orst.edu.
For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V9 Issue 580
*************************************