[7733] in Perl-Users-Digest
Perl-Users Digest, Issue: 1358 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Nov 22 10:08:32 1997
Date: Sat, 22 Nov 97 07:00:36 -0800
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, 22 Nov 1997 Volume: 8 Number: 1358
Today's topics:
Re: [Q] Why does this behave this way? <markm@nortel.ca>
Re: [Q] Why does this behave this way? (Eric Bohlman)
Re: [Q]: Arbitrary sort on field names <rjk@coos.dartmouth.edu>
advantages of perl being dynamically scoped <s_rsshaffer@mail.clarion.edu>
Re: Any Perl-compatible database available <luo@eng.fsu.edu>
Re: Atomic operations (was Re: exclusive file rights) <billg@networkapparel.com>
Re: Base64 Encoding Code Snippett? <markm@nortel.ca>
CPU Intensive code? <sbekman@iil.intel.com>
Re: Good Perl book (Gabor)
Re: Help: What dir am I in <webmaster@fccj.cc.fl.us>
How can I hide the Query string in the URL? gonzalo@interimagen.com
Re: How can I hide the Query string in the URL? <bowlin@sirius.com>
How to: push (condition ? @this : @that),$value; (Toutatis)
Re: is it possible to reference a sub-array? <markm@nortel.ca>
Re: Learning Perl in win95 <luu_tran@geocities.com>
Need help setting up Satan to work with Perl. (Mark London)
Re: Novice needs help...inventory script <mak@mark.dircon.net>
Perl / mSQL / Access <info@welnet.co.uk>
Re: Perl / mSQL / Access (Jonathan Feinberg)
ref to typeglob and filehandles <bowlin@sirius.com>
Re: removing lines from a file?? (Jason Gloudon)
Re: Safe use of flock() -- was Re: giving up on flock <markm@nortel.ca>
Re: Sorting an array <markm@nortel.ca>
Re: string comparison question... <markm@nortel.ca>
Re: string comparison question... (Eric Bohlman)
Re: Waiting for multiple background processes to Finish (Jason Gloudon)
Re: What's wrong w/this picture? <rjk@coos.dartmouth.edu>
Re: Win32 and Word (Luke Diamand)
Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 22 Nov 1997 03:35:11 -0500
From: Mark Mielke <markm@nortel.ca>
Subject: Re: [Q] Why does this behave this way?
Message-Id: <lq1d8jt5nsw.fsf@bmers2e5.nortel.ca>
lm@binary9.net writes:
> #!/usr/bin/perl
> @a=qw ( Hello );
> $a=sprintf @a;
> print "sprintf: $a\n";
> print "printf : "; printf @a; print "\n";
> Now, when I run this, I get:
> sprintf: 1
> print : Hello
> Shouldn't they produce the same result? Am I missing something
> incredibly stupid and easy?
The answer is kinda... screwed... but i think sprintf() must be
defined to have a prototype of ($@).
(i.e. first argument is ALWAYS taken in scalar() context)
sprintf "abc" -> sprintf("abc")
sprintf "%d", 123 -> sprintf("%d", 123)
sprintf @a -> sprintf(scalar(@a))
sprintf @a, 123 -> sprintf(scalar(@a), 123)
Uhhh work-around? you could try something like:
sub LOG
{
my $format = shift;
$ERROR = sprintf $format, @_;
print STDERR "[err] $ERROR\n";
}
As well i've removed the double call to sprintf/printf... hope you don't mind.
mark
-- _________________________
. . _ ._ . . .__ . . ._. .__ . . . .__ | Northern Telecom Ltd. |
|\/| |_| |_| |/ |_ |\/| | |_ | |/ |_ | Box 3511, Station 'C' |
| | | | | \ | \ |__ . | | .|. |__ |__ | \ |__ | Ottawa, ON K1Y 4H7 |
markm@nortel.ca / al278@freenet.carleton.ca |_______________________|
------------------------------
Date: Sat, 22 Nov 1997 03:35:37 GMT
From: ebohlman@netcom.com (Eric Bohlman)
Subject: Re: [Q] Why does this behave this way?
Message-Id: <ebohlmanEK13BE.8tG@netcom.com>
lm@binary9.net wrote:
: I'm confused about the behavior of something (in Perl5.004_04). I was
: trying to do something like this:
: sub LOG {
: $ERROR=sprintf @_;
The first argument to sprintf (the format string) is a scalar, so @_ is
being evaluated in scalar context, giving you, tada! the number of
elements in @_
: print STDERR "[err] ";
: printf STDERR @_;
Same problem here.
: print STDERR "\n";
: }
How many arguments is LOG() supposed to take? If only one, then just
replace @_ with $_[0]. If several, then you aren't going to be able to
use sprintf; something like
$ERROR=join(' ',@_)
might work.
------------------------------
Date: Sat, 22 Nov 1997 03:50:33 -0500
From: Chipmunk <rjk@coos.dartmouth.edu>
Subject: Re: [Q]: Arbitrary sort on field names
Message-Id: <34769CD8.20B6@coos.dartmouth.edu>
Prince Mystery wrote:
>
> @fieldnames = ("name", "address1", "address2", "city", "state");
>
> If I give the user the option to list a variable amount of field names,
> and end up with an array similar (but smaller) to the one above, how do
> I sort so that they will always appear in some semblance to the order
> implied by the @fieldnames array? (i.e. an array of ("city","name")
> would be sorted to ("name", "city")).
You already have an array sorted in the order you want it. No need to
sort again:
$matchnames = join('|', map (quotemeta $_, @inputfieldnames));
@somefieldnames = grep (/^($matchnames)$/, @fieldnames);
Chipmunk
------------------------------
Date: Wed, 19 Nov 1997 19:13:23 -0500
From: Rob Shaffer <s_rsshaffer@mail.clarion.edu>
Subject: advantages of perl being dynamically scoped
Message-Id: <347380A3.7330@mail.clarion.edu>
i am writing a paper on scoping rules for perl. i was wondering why is
perl dynamically scoped? are there advantages for this?
------------------------------
Date: Sat, 22 Nov 1997 02:28:27 -0600
From: Jun Luo <luo@eng.fsu.edu>
To: Thomas Beardshear <u2537@shurflo.com>
Subject: Re: Any Perl-compatible database available
Message-Id: <347697AB.B47F3A06@eng.fsu.edu>
Thomas Beardshear wrote:
> I want to query data from a database from a browser and I can't find
> anyone or any support for the database I'm using.
>
> I'm trying to find ANY database engine that will output database queried
> data to a browser via a Perl CCI script successfully.
I'm not sure DBI in perl is the things you are looking for. It supports
most of the major datebase. I used Perl to write some CGI scripts to do
query, delete and insert with my Oracle. it is not very to do this with DBI.
Please refer to http://www.perl.com Maybe you can find sth. useful there.
Jun
------------------------------
Date: Sat, 22 Nov 1997 08:20:49 -0500
From: Bill Guindon <billg@networkapparel.com>
Subject: Re: Atomic operations (was Re: exclusive file rights)
Message-Id: <3476DC31.83A1B9AC@networkapparel.com>
Since you seem to be on the topic anyway...
I'm playing with the Sprite module (found on CPAN). I'm running it on a
Unix box, but want to develop on Win95. Is there an easy way to get around
the fact that flock doesn't work on 95?
I don't want to eliminate it entirely, but want to knock it out ONLY when it
is running on 95. On the same thought, I've been testing the SERVER_NAME to
determine where I'm running, is there any way to get the OS so my test can
be a bit more portable?
Cameron Dorey wrote:
> Jeremy D. Zawodny wrote:
> >
> [snip]
> >
> > If you use flock() on a Win32 system it appears to work right. [Note
> > that I've only *tested* this on NT, but I suspect it works on 95 as
> > well.]
> >
> > Using flock(), you can lock the files that you need to mess with.
>
> "To lock, perchance to flock, ay, there's the rub" (with apologies to
> WS, Hamlet, Act 5, sc. 2)
>
> flock(), although implemented in WinNT, is *not* implemented in Win95
> (5.00402, GS port). That's why I've had to use the create/unlink as a
> workaround.
------------------------------
Date: 22 Nov 1997 02:39:50 -0500
From: Mark Mielke <markm@nortel.ca>
Subject: Re: Base64 Encoding Code Snippett?
Message-Id: <lq1ra895qd5.fsf@bmers2e5.nortel.ca>
munn@bigfoot.com (Thomas Munn) writes:
> Has anyone authored a bit of PERL that will convert plaintext to base64
> encoding? I need it for a program that I am writing.
As other people mentioned, you should use MIME::Base64... but if you
just want a snippet that works 99%... (it doesn't put the end-of-text
pad character... but that's ok for netscape/cgi stuff and most other...
Three lines of perl to encode and three for decode... :-)
------- CUT HERE --------
# -*- perl -*-
package Base64;
require 5.000;
require Exporter;
use strict;
use vars qw(@EXPORT @ISA @Table @DecodeTable);
@EXPORT = qw(base64_encode base64_decode);
@ISA = qw(Exporter);
INITIALIZE: {
@Table = (('A' .. 'Z'), ('a' .. 'z'), ('0' .. '9'), '+', '/');
for ($_ = 0; $_ <= $#Table; $_++) {
$DecodeTable[ord($Table[$_])] = $_;
}
}
sub base64_encode
{
local $_ = unpack('B*', $_[0]);
$_ .= '0' x (6 - (length($_) % 6)) if (length($_) % 6) != 0;
s/.{6}/$Table[ord(pack('B6', $&)) >> 2]/eg; $_;
}
sub base64_decode
{
local $_ = $_[0];
s/./unpack('B6', chr($DecodeTable[ord($&)] << 2))/eg;
pack('B' . (int(length($_) / 8) * 8), $_);
}
1;
------- CUT HERE --------
i wrote this code like a year ago for doing authentication in my CGI.
of course i didn't want very much overhead for loading the perl code
so it had to be small... and the code would be executed only like...
once per cgi execution so it didn't need to be horribly efficient. :-)
mark
-- _________________________
. . _ ._ . . .__ . . ._. .__ . . . .__ | Northern Telecom Ltd. |
|\/| |_| |_| |/ |_ |\/| | |_ | |/ |_ | Box 3511, Station 'C' |
| | | | | \ | \ |__ . | | .|. |__ |__ | \ |__ | Ottawa, ON K1Y 4H7 |
markm@nortel.ca / al278@freenet.carleton.ca |_______________________|
------------------------------
Date: Sat, 22 Nov 1997 11:34:28 +0200
From: Stas Bekman <sbekman@iil.intel.com>
Subject: CPU Intensive code?
Message-Id: <Pine.A32.3.93.971122112700.41740G-100000@ilx374.iil.intel.com>
Hi,
My perl cgi-script has been shoutdowned by my ISP, the reason CPU heavy
code!
I have a simple counter script based on Matt's well known script (it uses
'fly' to concatenate basic digit images to one real image number)
All I added is some code, which uses
use URI::URL ();
use CGI qw(:standard);
I checked -- it takes 5-15% CPU (looked at the 'top' util) for a few
seconds but the site's traffic is heavy so the counters runs every few
seconds...
How can I fix it? Or how can I look what are the CPU intensive parts?
(I guess the 'fly' part? But everyone use it?
Any ideas?
Thanks
______________________________________________________________________
Stas Bekman mailto:sbekman@iil.intel.com [just another webmaster]
Linux Installation Party [Technion] http://instaparty.israel.eu.org/
Home Page: http://www.eprotect.com/stas
A must visit: http://www.eprotect.com/stas/TULARC (Java,CGI,PC,Linux)
Linux-il Home: http://www.linux.org.il/
------------------------------
Date: 22 Nov 1997 14:45:17 GMT
From: gabor@vinyl.quickweb.com (Gabor)
Subject: Re: Good Perl book
Message-Id: <slrn67drl0.m7m.gabor@vinyl.quickweb.com>
In article <weghg95a715.fsf@plato.cs.concordia.ca>, KARABOTSOS george wrote:
>Hello,
>
>I will be shoping for a Perl book soon, so any suggestions are
>welcome.
>
>Thank you.
Programming Perl from O'Reilly Associates ISBN 1-56592-149-6
That's the second edition that covers Perl5
I hear Learning Perl is pretty good, too.
Also, get Mastering Regular Expressions from O'Reilly ISBN 1-56592-257-3
gabor.
--
And don't tell me there isn't one bit of difference between null and
space, because that's exactly how much difference there is. :-)
-- Larry Wall in <10209@jpl-devvax.JPL.NASA.GOV>
mharris@gov.on.ca he, he, he
------------------------------
Date: Fri, 21 Nov 1997 14:33:53 -0500
From: "Bill Jones, FCCJ Webmaster" <webmaster@fccj.cc.fl.us>
Subject: Re: Help: What dir am I in
Message-Id: <3475E221.B4AB53FF@fccj.cc.fl.us>
This is a multi-part message in MIME format.
--------------57BEF20C19C863047974F0F1
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
David J. Boyd wrote:
> How does one go about determine what directory I am from perl? Where the
> directory script is?
>
> ...
> TIA
Instead of checking where you are - chdir to where you want to be :-)
But there is a CWD package...
--------------57BEF20C19C863047974F0F1
Content-Type: text/x-vcard; charset=us-ascii; name="vcard.vcf"
Content-Transfer-Encoding: 7bit
Content-Description: Card for Bill Jones
Content-Disposition: attachment; filename="vcard.vcf"
begin: vcard
fn: Bill Jones
n: Jones;Bill
org: FCCJ
adr: 501 W. State St.;;MCCS Rm. 270;Jacksonville;FL;32202;USA
email;internet: webmaster@fccj.cc.fl.us
title: Webmaster
tel;work: (904) 632-3089
tel;fax: (904) 632-3007
tel;home: Pager: 1 (904) xxx-xxxx
x-mozilla-cpt: ;0
x-mozilla-html: TRUE
version: 2.1
end: vcard
--------------57BEF20C19C863047974F0F1--
------------------------------
Date: Sat, 22 Nov 1997 03:11:34 -0600
From: gonzalo@interimagen.com
Subject: How can I hide the Query string in the URL?
Message-Id: <880189320.28539@dejanews.com>
Hi everybody,
Please help me to handle this. I have a script that works with forms;
it works, but I want to know how can I remove the data sent to the script
from the URL, it means:
http://xxx.xxx.xxx/cgi-bin/mu.cgi?name=blah&email=blah&address=blah
I want this
http://xxx.xxx.xxx/cgi-bin/mu.cgi
Thank you four your Hel.
Good Luck!!
-------------------==== Posted via Deja News ====-----------------------
http://www.dejanews.com/ Search, Read, Post to Usenet
------------------------------
Date: Sat, 22 Nov 1997 02:00:43 -0800
From: Jim Bowlin <bowlin@sirius.com>
To: gonzalo@interimagen.com
Subject: Re: How can I hide the Query string in the URL?
Message-Id: <3476AD4B.59992E5F@sirius.com>
gonzalo@interimagen.com wrote:
>
> Hi everybody,
>
> Please help me to handle this. I have a script that works with forms;
> it works, but I want to know how can I remove the data sent to the script
> from the URL, it means:
>
> http://xxx.xxx.xxx/cgi-bin/mu.cgi?name=blah&email=blah&address=blah
>
> I want this
>
> http://xxx.xxx.xxx/cgi-bin/mu.cgi
In the html form use <form method=post ...>
You will also need to change your CGI to read $ENV{'CONTENT_LENGTH'} bytes
from STDIN instead of reading $ENV{'QUERY_STRING'}. CGI.pm does this for
you automatically.
HTH -- Jim Bowlin
------------------------------
Date: 22 Nov 1997 11:06:35 GMT
From: toutatis@no.mail.please (Toutatis)
Subject: How to: push (condition ? @this : @that),$value;
Message-Id: <toutatis-ya023180002211971206350001@news.euro.net>
This is the way i've been typing it so far, and every time i did, I thought
there must be a shorter way.
my $value = "some_value";
if (condition){
push @this, $value;
else {
push @that, $value;
}
I'd like to write something like
push (condition ? @this : @that),$value;
But then something that works. map ik ok as well, as long as it's _short_.
--
Toutatis
------------------------------
Date: 22 Nov 1997 03:08:19 -0500
From: Mark Mielke <markm@nortel.ca>
Subject: Re: is it possible to reference a sub-array?
Message-Id: <lq1k9e15p1o.fsf@bmers2e5.nortel.ca>
Zenin <zenin@best.com> writes:
> function ( \( @ARGV[2..#$ARGV] ) );
> If there are 4 elements in the array, this would be identical to
> saying:
> function ( \$ARGV[2], \$ARGV[3] );
> The advantage of the first is of course that you can dynamically set
> your array slice limites, and it's shorter to type, but the effect
> is the same.
It doesn't work: try this...
sub function
{
my $array_ref = shift;
foreach (@$array_ref) { $_ = uc } # Line 7 (see below)
}
my @a = @ARGV;
function(\@a);
print "Array result: @a\n";
my @b = @ARGV;
function(\(@b[2..4]));
print "Array slice result: @b\n";
And try calling:
$ array_splice_test a b c d e f g
Array result: A B C D E F G
Not an ARRAY reference at g line 7.
It doesn't work i tell you... perl doesn't even claim to be able to do
such a thing :-) The interesting part is that \(@b[...]) seems to
return a ref to a scalar?
mark
-- _________________________
. . _ ._ . . .__ . . ._. .__ . . . .__ | Northern Telecom Ltd. |
|\/| |_| |_| |/ |_ |\/| | |_ | |/ |_ | Box 3511, Station 'C' |
| | | | | \ | \ |__ . | | .|. |__ |__ | \ |__ | Ottawa, ON K1Y 4H7 |
markm@nortel.ca / al278@freenet.carleton.ca |_______________________|
------------------------------
Date: 22 Nov 1997 06:02:55 GMT
From: "Luu Tran" <luu_tran@geocities.com>
Subject: Re: Learning Perl in win95
Message-Id: <35755.9192378472luutrangeocitiescom@207.217.242.11>
[posted and mailed]
On Thu, 20 Nov 1997, Pearl Fox <fox@securenet.net> wrote:
> If there is a site where I can get the information that I need to get
>me started in learning how to program in Perl with win 95
>environment, I would really appreciate it. I downloaded the Perl
>program but don't know how to use it with win 95?
>
>Thanks
Goto http://www.perl.com and follow the windows 95 link
http://reference.perl.com/query.cgi?windows
There are various ports for win95/nt. A popular one is by ActiveState
http://www.activestate.com/
although I think you're required to compile the package yourself.
Gurusamy Sarathy has a binary distribution. It's quite complete and is
what I use.
http://www.perl.com/CPAN-local/ports/nt/Gurusamy_Sarathy/
I don't know what you plan to do with Perl. For the most part, Perl
programs (like the ones you find in textbooks) should run on any platform
with little or no modification. There are some Unix-specific stuff like
crypt and flock that won't work on win95. Conversely, there are some
modules available for doing win95-specific stuff like reading the registry
and ODBC. Check out the above links. I think there's even a perl-win32
mailing list somewhere.
HTH
-- luu
http://www.bayscenes.com/np/mdonline/
Please remove the underscore _ in my address when replying by email
------------------------------
Date: 21 NOV 97 16:51:57 GMT
From: mrl@psfc.mit.edu (Mark London)
Subject: Need help setting up Satan to work with Perl.
Message-Id: <21NOV97.16515712@psfc.mit.edu>
Hi-
I installed satan on a silicon graphics indy running irix 5.3.
I also installed the latest version of Perl (I did that when I installed
majordomo a month ago so I know it works). When I start up Satan and it
then starts up netscape, and I try clicking on any of the entries on the
configuration page, it pops up a window with lots of syntax errors,
such as "Bareword found where operator expected, etc.) The only other
thing I did was to configure the helper preferences within netscape to
run the command "/bin/perl %s" for the file type "image/x-perl". I hope
that is the correct definition. Any suggestions? Thanks.
Mark London
MRL@PSFC.MIT.EDU
------------------------------
Date: Sat, 22 Nov 1997 14:07:48 +0000
From: Mark Morgan <mak@mark.dircon.net>
Subject: Re: Novice needs help...inventory script
Message-Id: <3476E734.A941F2F2@mark.dircon.net>
A few guidelines for this:
1) Use File::Find;
2) instead of checking the extension, which the scripts may or may not
have as their extension, I would go with either looking at the first
line of each file, for the shebang line...alternatively, you could do
`file $filename` and get the type of file from that(but that would be
quite slow, and non-perlish :).
You could also do a similar with a complicated find command from the
command prompt...
Mark.
Mark Buhl wrote:
>
> I have written a perl script to do an inventory of my system identifying
> all shell and perl scripts and the number of lines in each file. I have
> quite a kluge of a script, wondering if someone can show me how to make
> it more efficient.
>
> Thanks
>
> #!/usr/local/bin/perl
> #
> #
> $host = `uname -n`;
> $outfile = "/common/etc/Y2Klisting."."$host";
> open(OUT, ">>$outfile") || die "Unable to open $outfile!!";
> foreach (@ARGV) {
> $filename = $_;
> if ( -T $_ ) {
> if ( -s $_ ) {
> while (<>) {
> if (/^#!.*sh/) {
> $type = "Sh Script";
> }
> elsif (/^#!.*perl/) {
> $type = "Perl Script";
> }
> else {
> exit;
> }
> last;
>
> }
> while (<>) {
> $count++;
> }
> $count++;
>
> printf(OUT "%-40s %-10s %-10s\n", $filename,$type,$count);
> }
> }
> }
------------------------------
Date: 22 Nov 1997 11:34:13 GMT
From: "Martin Williams" <info@welnet.co.uk>
Subject: Perl / mSQL / Access
Message-Id: <01bcf73b$b65e5d60$05a726a4@howdy.dixons.co.uk>
How do I get my perl script to read my Access database using mSQL ?
Sure wish I could find someone to help !
Thanks in advance
Martin
------------------------------
Date: Sat, 22 Nov 1997 09:42:21 -0500
From: jdf@pobox.com (Jonathan Feinberg)
Subject: Re: Perl / mSQL / Access
Message-Id: <MPG.ee0b95a727ab8d5989687@news.concentric.net>
info@welnet.co.uk said...
> How do I get my perl script to read my Access database using mSQL ?
Why would mSQL be able to read an Access database?
You want the Win32 ODBC module, available at CPAN, I expect.
--
Jonathan Feinberg jdf@pobox.com Sunny Manhattan, NY
------------------------------
Date: Sat, 22 Nov 1997 01:06:16 -0800
From: Jim Bowlin <bowlin@sirius.com>
Subject: ref to typeglob and filehandles
Message-Id: <3476A088.9385510F@sirius.com>
I am updating Perl 4/5 code to be compatible with "use strict;"
I was able to pass file handles around in Perl 4/5 as follows:
$file = '/etc/passwd';
open($file, $file);
&process($file);
sub process {
local(*HANDLE) = @_;
while (<HANDLE>) {
...
}
}
One nice feature of this approach was that unexpected system error
messages would tell me the name of the file that was being processed
since the name of the file is the filehandle.
When I convert this to refs to typeglobs, it seems I lose
the ability to name filehandles after the name of the file.
Should I just give up on naming filehandles after the files themselves?
------------------------------
Date: 22 Nov 1997 06:02:44 GMT
From: jgloudon@bbn.remove.com (Jason Gloudon)
Subject: Re: removing lines from a file??
Message-Id: <655si4$mdr$3@daily.bbnplanet.com>
Burt Lewis (burt@ici.net) wrote:
: Hi,
: I need to remove the lines that end with a - and keep the rest.
: Not having much luck with this and would appreciate any help/
: fosters.GIF - Fri Nov 21 23:19:44 EST 1997 - abcde
: fosters - Fri Nov 21 23:19:47 EST 1997 -
: fosters - Fri Nov 21 23:19:49 EST 1997 - xyz
: whist - Fri Nov 21 23:22:16 EST 1997 -
: whist - Fri Nov 21 23:24:47 EST 1997 - rewt
: whist - Fri Nov 21 23:31:19 EST 1997 -
while(<STDIN>){
print unless /-\s*$/;
}
Jason Gloudon
------------------------------
Date: 22 Nov 1997 02:42:02 -0500
From: Mark Mielke <markm@nortel.ca>
Subject: Re: Safe use of flock() -- was Re: giving up on flock
Message-Id: <lq1oh3d5q9h.fsf@bmers2e5.nortel.ca>
aml@world.std.com (Andrew M. Langmead) writes:
> Mark Mielke <markm@nortel.ca> writes:
> >Oh yeah... Tom... I just found a section in the manpage that says that:
>
> > To avoid the possibility of mis-coordination, Perl
> > flushes FILEHANDLE before (un)locking it.
> > (man perlfunc - flock)
> but what if the flush fails?
If the flush() fails... how do you think the close() will succeed?
seriously :-)
mark
-- _________________________
. . _ ._ . . .__ . . ._. .__ . . . .__ | Northern Telecom Ltd. |
|\/| |_| |_| |/ |_ |\/| | |_ | |/ |_ | Box 3511, Station 'C' |
| | | | | \ | \ |__ . | | .|. |__ |__ | \ |__ | Ottawa, ON K1Y 4H7 |
markm@nortel.ca / al278@freenet.carleton.ca |_______________________|
------------------------------
Date: 22 Nov 1997 03:16:36 -0500
From: Mark Mielke <markm@nortel.ca>
Subject: Re: Sorting an array
Message-Id: <lq1en495onv.fsf@bmers2e5.nortel.ca>
lm@binary9.net writes:
> On Fri, 21 Nov 1997 10:49:55 +0100, Yann <ycueff@club-internet.fr>
> wrote:
> >I've some problems to sort an array.
> >Could someone help me ?
> >For example I'd like to sort this array by the 3rd field.
> >
> >bcv64wd8:solaris:5.5:sun4m:SUN1.05:AGL
> >bcv67wcb:solaris:5.5.1:sun4m:SUN0535:AGL
> >bcv67w50:solaris:5.5.1:sun4c:SUN0424:AGL
> >bcv67w5b:solaris:5.5:sun4m:SUN0535:AGL
> >bcv66m14:AIX:3.2:::AGL
> >bcv66w58:sun4:4.1.3_U1:sun4m:SUN1.05:AGL
> >bcv95wc4:solaris:5.5.1:sun4c:SUN0424:AGL
> Assuming this information is in @ARR ...
> for (sort { (split(/:/,$a))[2] <=> (split(/:/,$b))[2] } @ARR) {
> print "$_\n";
> }
This is a bad answer for reasons of efficiency. sort { } will do this
compare many times. (i forget the theory... is it n * log(n)?) Anyways...
If you have 1000+ you WILL notice the difference between using the
transform described in earlier posts including mine. (namely they are
exponentially faster? :-) )
mark
-- _________________________
. . _ ._ . . .__ . . ._. .__ . . . .__ | Northern Telecom Ltd. |
|\/| |_| |_| |/ |_ |\/| | |_ | |/ |_ | Box 3511, Station 'C' |
| | | | | \ | \ |__ . | | .|. |__ |__ | \ |__ | Ottawa, ON K1Y 4H7 |
markm@nortel.ca / al278@freenet.carleton.ca |_______________________|
------------------------------
Date: 22 Nov 1997 03:12:23 -0500
From: Mark Mielke <markm@nortel.ca>
Subject: Re: string comparison question...
Message-Id: <lq1hg955ouw.fsf@bmers2e5.nortel.ca>
jgloudon@bbn.remove.com (Jason Gloudon) writes:
> Robert G. Ferrell (robertf@geminet.com) wrote:
> : In article <3475EC71.98F942E2@redrose.net>, tjbiuso@redrose.net says...
> : >would $hereisastring eq "" work to check if a string is null?
> : >
> : Yes, but you could also say
> : [code] if ($hereisastring)
> No. If $hereisastring == '0'. $hereisastring is false.
> You have to say if hereastring eq "".
The way i would suggest is:
if (length($hereisastring) == 0) {
...
}
In perl code you will often see the construct:
if (length($mystring)) {
# stuff to do if $mystring is not empty.
} else {
# stuff to do if $mystring is empty.
}
The if (length($mystring)) is actually among the most efficient as well.
mark
-- _________________________
. . _ ._ . . .__ . . ._. .__ . . . .__ | Northern Telecom Ltd. |
|\/| |_| |_| |/ |_ |\/| | |_ | |/ |_ | Box 3511, Station 'C' |
| | | | | \ | \ |__ . | | .|. |__ |__ | \ |__ | Ottawa, ON K1Y 4H7 |
markm@nortel.ca / al278@freenet.carleton.ca |_______________________|
------------------------------
Date: Sat, 22 Nov 1997 04:03:34 GMT
From: ebohlman@netcom.com (Eric Bohlman)
Subject: Re: string comparison question...
Message-Id: <ebohlmanEK14Ly.AJH@netcom.com>
Robert G. Ferrell (robertf@geminet.com) wrote:
: In article <3475EC71.98F942E2@redrose.net>, tjbiuso@redrose.net says...
: >would $hereisastring eq "" work to check if a string is null?
: >
: Yes, but you could also say
: [code] if ($hereisastring)
: or
: if ($hereisastring) {
: [code]
: }
: or even
: unless (!$hereisastring) [code]
: and so on.
: Perl gives you a lot of options.
Some of which don't do what you want...
Try all of them out after doing:
$hereisastring="0";
------------------------------
Date: 22 Nov 1997 05:50:08 GMT
From: jgloudon@bbn.remove.com (Jason Gloudon)
Subject: Re: Waiting for multiple background processes to Finish
Message-Id: <655rqg$mdr$2@daily.bbnplanet.com>
William Wei Liong Young (i0l1@ugrad.cs.ubc.ca) wrote:
: Hah...wouldn't you know it. 3 seconds after i post my message,
: i figure out how to do it myself. for those who care (probably
: no-one...but i like to hear myself type :) this is what i was originaly
: doing (which would not work):
: # wait for all 10 commands to finish
: for( $i = 0 ; $i < 10 ; $i++ )
: {
: wait;
: }
: but i have a new query...is there any better way to wait for all
: the processes besides putting the 'wait' in a loop?
No.
You could make the loop a little shorter like this
1 while wait != -1;
Jason Gloudon
------------------------------
Date: Sat, 22 Nov 1997 03:21:46 -0500
From: Chipmunk <rjk@coos.dartmouth.edu>
Subject: Re: What's wrong w/this picture?
Message-Id: <34769619.6649@coos.dartmouth.edu>
Tad McClellan wrote:
>
> Mike King (m.king.garbage@praxa.garbage.com.au) wrote:
> : if ($this_file =~ !/^./)
>
> Now the script will not do the Right Thing for the '.newsrc' file...
>
> Ignoring the fact that the dot was not escaped, so the if() test
> will *never* be true...
>
Not to mention the fact that /^./ is being matched against $_, and the
negation of the result is being matched against $this_file.
DB<1> $this_file = '123'
DB<2> $_ = 'abc'
DB<3> p $this_file =~ !/1/
1
DB<4> p not $this_file =~ /1/
DB<5> p $this_file =~ !/4/
1
DB<6> p not $this_file =~ /4/
1
DB<7> p $this_file =~ !/a/
DB<8> p not $this_file =~ /a/
1
------------------------------
Date: 22 Nov 1997 07:27:29 GMT
From: Diamand@btinternet.com (Luke Diamand)
Subject: Re: Win32 and Word
Message-Id: <6561h1$fm7@argon.btinternet.com>
># None of these statements appear to do anything
> $WordApp->FileOpen('testfile.doc');
[Is there a testfile.doc wherever word looks for documents by default?]
Have you tried:
my $ole_err = Win32::OLELastError;
die (Win32::FormatError $ole_err . "\n") if $ole_err;
[You may have to check the manual for the exact names].
Luke Diamand
------------------------------
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 1358
**************************************