[13660] in Perl-Users-Digest
Perl-Users Digest, Issue: 1070 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Oct 15 15:17:18 1999
Date: Fri, 15 Oct 1999 12:16:58 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <940015017-v9-i1070@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Fri, 15 Oct 1999 Volume: 9 Number: 1070
Today's topics:
Newbie question about time <Gizzzmo@pandora.be>
Re: Newbie question about time (Martien Verbruggen)
Re: Newbie question about time <azielke@hotmail.com>
Re: newbie question <webmaster@webdream.com>
Re: newbie question <gellyfish@gellyfish.com>
Re: newbie question <pj@produktiv.com>
Re: newbie question (Martien Verbruggen)
Newbie Question: How to use unix "CAL" command? (T.Y.)
Re: Newbie Question: How to use unix "CAL" command? (Martien Verbruggen)
Re: Newbie Question: How to use unix "CAL" command? <gellyfish@gellyfish.com>
nl Unix Command in Perl <musial@prefeitura.unicamp.br>
Re: nl Unix Command in Perl <gellyfish@gellyfish.com>
Re: nl Unix Command in Perl (Tad McClellan)
Re: nl Unix Command in Perl (Abigail)
Re: nl Unix Command in Perl (Alan Barclay)
Re: nl Unix Command in Perl <ltl@rgsun40.viasystems.com>
Re: nl Unix Command in Perl <uri@sysarch.com>
Re: nl Unix Command in Perl (Alan Barclay)
Re: nl Unix Command in Perl <ltl@rgsun40.viasystems.com>
Re: nl Unix Command in Perl (Larry Rosler)
Re: nl Unix Command in Perl <quint@granier.grenoble.xrce.xerox.com>
Re: nl Unix Command in Perl (Matthew Bafford)
Re: nl Unix Command in Perl (Larry Rosler)
Re: nl Unix Command in Perl (Larry Rosler)
Re: nl Unix Command in Perl (Abigail)
Re: nl Unix Command in Perl (Craig J Copi)
Re: nl Unix Command in Perl <ltl@rgsun5.viasystems.com>
non-blocking read - HOW ? (Piet Ruyssinck)
open(F,"+>foo.txt"); flock(F); <johnlin@chttl.com.tw>
Re: open(F,"+>foo.txt"); flock(F); <skilchen@swissonline.ch>
Opinions? Efficiency & Drain of Pack/UnPack <pdobbs@home.com>
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Fri, 15 Oct 1999 16:14:19 +0200
From: "Gizzzmo" <Gizzzmo@pandora.be>
Subject: Newbie question about time
Message-Id: <PDGN3.910$pw5.2303@afrodite.telenet-ops.be>
Hi,
I'm learning perl but I'm having some problems using timelocal.pl.
Can anyone tell me how to write a script that controls if a given date for
example 15/10/1999 (day/month/year)
is older (for example 4 months) than the current time?
Many Thanx in Advance.
Christophe
------------------------------
Date: 15 Oct 1999 14:28:50 GMT
From: mgjv@wobbie.heliotrope.home (Martien Verbruggen)
Subject: Re: Newbie question about time
Message-Id: <slrn80eeij.qim.mgjv@wobbie.heliotrope.home>
[Removed non-exisiting group comp.lang.perl. Please inform your news
admin that that group has been long, long dead, and should be
removed.]
On Fri, 15 Oct 1999 16:14:19 +0200,
Gizzzmo <Gizzzmo@pandora.be> wrote:
> Can anyone tell me how to write a script that controls if a given date for
> example 15/10/1999 (day/month/year)
> is older (for example 4 months) than the current time?
You get the module Date::Manip or Date::Calc from CPAN:
http://www.cpan.org/
or (on unix)
# perl -MCPAN -e shell
FAQ 8 gives some information on how to install modules.
# perldoc perlfaq8
If you use ActiveState on Win32, use their ppm module manager. See
their website and documentation.
Martien
--
Martien Verbruggen |
Interactive Media Division | Begin at the beginning and go on till you
Commercial Dynamics Pty. Ltd. | come to the end; then stop.
NSW, Australia |
------------------------------
Date: Fri, 15 Oct 1999 16:21:46 +0200
From: A Zielke <azielke@hotmail.com>
Subject: Re: Newbie question about time
Message-Id: <3807387A.35519D70@hotmail.com>
Use the module Date::Calc that comes with perl (Documentation is
included).
Gizzzmo schrieb:
>
> Hi,
>
> I'm learning perl but I'm having some problems using timelocal.pl.
>
> Can anyone tell me how to write a script that controls if a given date for
> example 15/10/1999 (day/month/year)
> is older (for example 4 months) than the current time?
>
> Many Thanx in Advance.
>
> Christophe
------------------------------
Date: Thu, 14 Oct 1999 13:54:17 GMT
From: "Craig Vincent" <webmaster@webdream.com>
Subject: Re: newbie question
Message-Id: <dglN3.426$CQ.383@198.235.216.4>
IMHO That's a very dangerous method of security for a server. Unless you're
using a secure connection a packet sniffer
could then grab the root password(s) from that submission and a hacker could
easily comprimise your server.
However to answer you're question I don't think it's possible to change the
HTTPD username dynamically (ie. It will always
be nobody or whatever you specified in the httpd.conf). I would simply
suggest hardcoding a username/password into the
perl script and give read/write permissions to that file for owner only
(chmod 600), and make the owner nobody.
If on the other hand there is a way to change HTTPDs user please let me
know...I could certainly use an attribute like that.
Sincerely,
Craig Vincet
Jason Rosenkowitz <jason@netralink.com> wrote in message
news:7u4lr6$dkt$1@ctb-nnrp2.saix.net...
Hi
How would one go about writing to a flat file which only has root wr
permissions in a cgi script. I would ultimately require the web user to
type in the root and su password in an html form to allow the file to be
written to.
Help would be most appreciated.
Jason Rosenkowitz
jason@netralink.com
------------------------------
Date: 14 Oct 1999 15:02:24 +0100
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: newbie question
Message-Id: <3805e270_2@newsread3.dircon.co.uk>
Jason Rosenkowitz <jason@netralink.com> wrote:
> Hi
>
> How would one go about writing to a flat file which only has root wr per
>
what is root wr per ?
/J\
--
"Mark my words, sex is never enough. Sooner of later she'll want a
dishwasher" - Policeman, City Central
------------------------------
Date: Thu, 14 Oct 1999 15:20:20 +0100
From: "Paul Jardine" <pj@produktiv.com>
Subject: Re: newbie question
Message-Id: <3805e2da.0@dns.amsinc.com>
Craig Vincent <webmaster@webdream.com> wrote in message
news:dglN3.426$CQ.383@198.235.216.4...
> IMHO That's a very dangerous method of security for a server. Unless
you're
> using a secure connection a packet sniffer
> could then grab the root password(s) from that submission and a hacker
could
> easily comprimise your server.
>
> However to answer you're question I don't think it's possible to change
the
> HTTPD username dynamically (ie. It will always
> be nobody or whatever you specified in the httpd.conf). I would simply
> suggest hardcoding a username/password into the
> perl script and give read/write permissions to that file for owner only
> (chmod 600), and make the owner nobody.
>
> If on the other hand there is a way to change HTTPDs user please let me
> know...I could certainly use an attribute like that.
>
> Sincerely,
>
> Craig Vincet
>
>
> Jason Rosenkowitz <jason@netralink.com> wrote in message
> news:7u4lr6$dkt$1@ctb-nnrp2.saix.net...
> Hi
>
> How would one go about writing to a flat file which only has root wr
> permissions in a cgi script. I would ultimately require the web user to
> type in the root and su password in an html form to allow the file to be
> written to.
>
> Help would be most appreciated.
>
> Jason Rosenkowitz
> jason@netralink.com
>
>
Hi,
Personally I would do it using a username and password unrelated to root
(possibly hardcoded, but specific to the CGI only) then if they passed that
'security' test, execute another script with the sticky bit set (man chmod,
set uid) to change the protected file. I would suggest that only the CGI
user would have execute priviledge (through the group). It's not a
watertight solution, but I think it would be a reasonable way to do it (your
sysadmin may disagree, as I have a feeling you are trying to edit the
/etc/passwd file!).
/Paul
----------------------------------------------------------------------------
---------------------------
Useability = Functionality / Security;
------------------------------
Date: Fri, 15 Oct 1999 00:01:40 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: newbie question
Message-Id: <E9uN3.108$Kd.2786@nsw.nnrp.telstra.net>
On Thu, 14 Oct 1999 15:29:48 +0200,
Jason Rosenkowitz <jason@netralink.com> wrote:
> This is a multi-part message in MIME format.
>
> ------=_NextPart_000_0086_01BF1658.F3543B20
> Content-Type: text/plain;
> charset="iso-8859-1"
> Content-Transfer-Encoding: base64
>
> SGkNCg0KSG93IHdvdWxkIG9uZSBnbyBhYm91dCB3cml0aW5nIHRvIGEgZmxhdCBmaWxlIHdoaWNo
Please don't post MIME stuff. Just so you know: The above is what I
see, and many others with me. Usenet is a plain text medium, please
use it that way.
Martien
PS. Yes, I know it's trivial to pipe it through some decoding thingy.
My point is that I won't. Therefore I won't read the message, and
therefore I won't answer it. And I'm not the only one.
PPS. A second reason for ignoring your post is the word 'newbie' in
the title. (my newsreader actually deleted it, but I'm just feeling
educational today)
Please read the following information on how to choose a good subject
line: http://www.perl.com/CPAN/authors/Dean_Roehrich/subjects.post
--
Martien Verbruggen |
Interactive Media Division | I took an IQ test and the results were
Commercial Dynamics Pty. Ltd. | negative.
NSW, Australia |
------------------------------
Date: Wed, 13 Oct 1999 07:17:58 GMT
From: tong@synergyprod.net (T.Y.)
Subject: Newbie Question: How to use unix "CAL" command?
Message-Id: <38043221$0$202@nntp1.ba.best.com>
I have search through some of the faq's but couldn't find the information that
I needed, probably because it is an easy question I suppose.
What I need is just to run the UNIX "cal" command to make a calendar and
then capture it into a text file using PERL. Can someone assist me with this?
THANX!!
I tried system() but it didn't work.
------------------------------
Date: 13 Oct 1999 11:22:39 GMT
From: mgjv@wobbie.heliotrope.home (Martien Verbruggen)
Subject: Re: Newbie Question: How to use unix "CAL" command?
Message-Id: <slrn808qtd.a18.mgjv@wobbie.heliotrope.home>
On Wed, 13 Oct 1999 07:17:58 GMT,
T.Y. <tong@synergyprod.net> wrote:
> What I need is just to run the UNIX "cal" command to make a calendar and
> then capture it into a text file using PERL. Can someone assist me with this?
> I tried system() but it didn't work.
You tried, but you didn't read the documentation, did you?
# perldoc -f system
[snip]
The return value is the exit status of the program as
returned by the C<wait()> call. To get the actual exit value divide by
256. See also L</exec>. This is I<NOT> what you want to use to capture
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
the output from a command, for that you should use merely backticks or
^^^^^^^^^^^^^^^^^^^^^^^^^
C<qx//>, as described in L<perlop/"`STRING`">.
[snip]
Martien
--
Martien Verbruggen |
Interactive Media Division |
Commercial Dynamics Pty. Ltd. | Can't say that it is, 'cause it ain't.
NSW, Australia |
------------------------------
Date: 13 Oct 1999 13:02:32 +0100
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: Newbie Question: How to use unix "CAL" command?
Message-Id: <380474d8_2@newsread3.dircon.co.uk>
T.Y. <tong@synergyprod.net> wrote:
> I have search through some of the faq's but couldn't find the information that
> I needed, probably because it is an easy question I suppose.
>
> What I need is just to run the UNIX "cal" command to make a calendar and
> then capture it into a text file using PERL. Can someone assist me with this?
> THANX!!
>
> I tried system() but it didn't work.
$cal = `cal 10 1999`;
/J\
--
"Mr Creutzfeldt and Mr Jakob: No-one had ever heard of these two eminent
medical men until someone had the
------------------------------
Date: Wed, 13 Oct 1999 09:17:14 -0300
From: "Rafael Musial" <musial@prefeitura.unicamp.br>
Subject: nl Unix Command in Perl
Message-Id: <7u1pg2$jm0$1@saturno.unicamp.br>
Does anyone have a source code of nl Unix command in Perl??
Does anyone kwon where I can find it??
Thanks...
Rafael Musial
------------------------------
Date: 13 Oct 1999 15:14:28 +0100
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: nl Unix Command in Perl
Message-Id: <380493c4_1@newsread3.dircon.co.uk>
Rafael Musial <musial@prefeitura.unicamp.br> wrote:
> Does anyone have a source code of nl Unix command in Perl??
> Does anyone kwon where I can find it??
>
while(<>)
{
print $.,"\t",$_;
}
;-}
/J\
--
"It needs to be said: Tinky Winky is ... an ideal role model for any
child without toes or genitalia" - Paul Rudnick, The Guardian
------------------------------
Date: Wed, 13 Oct 1999 05:58:38 -0400
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: nl Unix Command in Perl
Message-Id: <e4l1u7.n71.ln@magna.metronet.com>
Rafael Musial (musial@prefeitura.unicamp.br) wrote:
: Does anyone have a source code of nl Unix command in Perl??
Sure.
: Does anyone kwon where I can find it??
Here it is as a one-liner:
perl -ne 'BEGIN{$cnt=1} /^\s*$/ ? print : printf "%6d\t$_", $cnt++'
--
Tad McClellan SGML Consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: 13 Oct 1999 14:53:09 -0500
From: abigail@delanet.com (Abigail)
Subject: Re: nl Unix Command in Perl
Message-Id: <slrn809oom.nk2.abigail@alexandra.delanet.com>
Tad McClellan (tadmc@metronet.com) wrote on MMCCXXXIV September MCMXCIII
in <URL:news:e4l1u7.n71.ln@magna.metronet.com>:
?? Rafael Musial (musial@prefeitura.unicamp.br) wrote:
??
?? : Does anyone have a source code of nl Unix command in Perl??
??
?? Sure.
??
?? : Does anyone kwon where I can find it??
??
??
?? Here it is as a one-liner:
??
?? perl -ne 'BEGIN{$cnt=1} /^\s*$/ ? print : printf "%6d\t$_", $cnt++'
Or when playing Perl golf:
perl -pe '/\S/ && printf "%6d\t", ++$c'
Abigail
--
perl -wleprint -eqq-@{[ -eqw+ -eJust -eanother -ePerl -eHacker -e+]}-
-----------== Posted via Newsfeeds.Com, Uncensored Usenet News ==----------
http://www.newsfeeds.com The Largest Usenet Servers in the World!
------== Over 73,000 Newsgroups - Including Dedicated Binaries Servers ==-----
------------------------------
Date: Wed, 13 Oct 1999 23:05:23 GMT
From: gorilla@elaine.drink.com (Alan Barclay)
Subject: Re: nl Unix Command in Perl
Message-Id: <939856231.151461@elaine.drink.com>
In article <slrn809oom.nk2.abigail@alexandra.delanet.com>,
Abigail <abigail@delanet.com> wrote:
>Or when playing Perl golf:
>
> perl -pe '/\S/ && printf "%6d\t", ++$c'
perl -pe 's/\S/++$i"\t$1"/e'
formatting is slightly different, but saves several strokes.
------------------------------
Date: 14 Oct 1999 01:08:13 GMT
From: lt lindley <ltl@rgsun40.viasystems.com>
Subject: Re: nl Unix Command in Perl
Message-Id: <7u3adt$aq7$1@rguxd.viasystems.com>
Alan Barclay <gorilla@elaine.drink.com> wrote:
:>In article <slrn809oom.nk2.abigail@alexandra.delanet.com>,
:>Abigail <abigail@delanet.com> wrote:
:>>Or when playing Perl golf:
:>>
:>> perl -pe '/\S/ && printf "%6d\t", ++$c'
:> perl -pe 's/\S/++$i"\t$1"/e'
:>
:>formatting is slightly different, but saves several strokes.
Not right-justifying the numbers (you mentioned a different format,
but I don't think you should be able to change the location of
the pin and this is definitely part of the requirements).
Indents the numbers by the width of leading white space .
It also doesn't compile.
So I think your shot didn't make it past the ladies tee and so if
you were playing with certain people I know you would be required
to whip it out and leave it out until the next tee just to
prove you are a man. :-)
Maybe you meant this:
perl -pe 's/\S/++$i."\t$1"/e'
which still suffers from the other problems mentioned above.
You've been around here for a while. I'm flabbergasted that
you would have set yourself up for that abuse by posting
without testing it. If you did test it and it worked for
you, I would appreciate an explanation of how the string
in the replacement part got built.
--
// Lee.Lindley /// I used to think that being right was everything.
// @bigfoot.com /// Then I matured into the realization that getting
//////////////////// along was more important. Except on usenet.
------------------------------
Date: 13 Oct 1999 23:07:24 -0400
From: Uri Guttman <uri@sysarch.com>
Subject: Re: nl Unix Command in Perl
Message-Id: <x7vh8ak5cj.fsf@home.sysarch.com>
>>>>> "AB" == Alan Barclay <gorilla@elaine.drink.com> writes:
AB> In article <slrn809oom.nk2.abigail@alexandra.delanet.com>,
AB> Abigail <abigail@delanet.com> wrote:
>> Or when playing Perl golf:
>>
>> perl -pe '/\S/ && printf "%6d\t", ++$c'
AB> perl -pe 's/\S/++$i"\t$1"/e'
AB> formatting is slightly different, but saves several strokes.
it helps if it compiles. and what is in $1? you never grab anything.
this is what i think you meant:
perl -pe 's/^/$.\t/'
or if you only want that on lines with text like abigails does:
perl -pe '/\S/ && s/^/$.\t/'
uri
--
Uri Guttman ----------------- SYStems ARCHitecture and Software Engineering
uri@sysarch.com --------------------------- Perl, Internet, UNIX Consulting
www.sysarch.com ----- Perl Books: http://www.sysarch.com/cgi-bin/perl_books
The Best Search Engine on the Net ------------- http://www.northernlight.com
------------------------------
Date: Thu, 14 Oct 1999 03:30:49 GMT
From: gorilla@elaine.drink.com (Alan Barclay)
Subject: Re: nl Unix Command in Perl
Message-Id: <939872155.756281@elaine.drink.com>
In article <7u3adt$aq7$1@rguxd.viasystems.com>,
lt lindley <lee.lindley@bigfoot.com> wrote:
>Alan Barclay <gorilla@elaine.drink.com> wrote:
>:>In article <slrn809oom.nk2.abigail@alexandra.delanet.com>,
>:> perl -pe 's/\S/++$i"\t$1"/e'
>
>It also doesn't compile.
My mistake, somehow the '.' operator didn't survive the cut & paste,
as you correctly point out.
I suspect that I accentally pressed the wrong button while spell
checking.
------------------------------
Date: 14 Oct 1999 04:29:03 GMT
From: lt lindley <ltl@rgsun40.viasystems.com>
Subject: Re: nl Unix Command in Perl
Message-Id: <7u3m6f$evd$1@rguxd.viasystems.com>
Uri Guttman <uri@sysarch.com> wrote:
:>it helps if it compiles. and what is in $1? you never grab anything.
Shit. I missed that. It was lopping off the first non-space char
and I didn't even notice.
:>this is what i think you meant:
:>perl -pe 's/^/$.\t/'
:>or if you only want that on lines with text like abigails does:
:>perl -pe '/\S/ && s/^/$.\t/'
Eeek! You continue to propogate the misplaced pin location by
allowing the line number to be left justified, plus you cheat
by counting the empty lines, which the "nl" command does not.
Now the use of $. may qualify as a stroke reduction, but since it
cheats on one aspect of the problem, I would call it an illegal club
and chalk up a penalty stroke.
You guys are just like real golfers. You all cheat. You improve
your lie (sp?) when nobody is looking, and then lie about your
scores when you think you won't be caught. :-)
I think Abigail hit a hole-in-one on this one and you should just
move on to the next hole.
--
// Lee.Lindley /// I used to think that being right was everything.
// @bigfoot.com /// Then I matured into the realization that getting
//////////////////// along was more important. Except on usenet.
------------------------------
Date: Wed, 13 Oct 1999 11:33:00 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: nl Unix Command in Perl
Message-Id: <MPG.126e7038f9ab08d398a089@nntp.hpl.hp.com>
In article <e4l1u7.n71.ln@magna.metronet.com> on Wed, 13 Oct 1999
05:58:38 -0400, Tad McClellan <tadmc@metronet.com> says...
> Rafael Musial (musial@prefeitura.unicamp.br) wrote:
> : Does anyone have a source code of nl Unix command in Perl??
...
> Here it is as a one-liner:
>
> perl -ne 'BEGIN{$cnt=1} /^\s*$/ ? print : printf "%6d\t$_", $cnt++'
Golf, anyone? (Whitespace-stripping doesn't count.)
perl -pe '/\S/ ? printf "%6d\t", $. : --$.'
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: 14 Oct 1999 11:50:57 +0200
From: Julien Quint <quint@granier.grenoble.xrce.xerox.com>
Subject: Re: nl Unix Command in Perl
Message-Id: <thln96cltq.fsf@granier.grenoble.xrce.xerox.com>
lt lindley <ltl@rgsun40.viasystems.com> writes:
> I think Abigail hit a hole-in-one on this one and you should just
> move on to the next hole.
I don't want to nitpick but nl skips only blank lines, that is lines that
are completely empty. I would change Abigail's one-liner to:
perl -pe '/^$/ || printf "%6d\t", ++$c'
to have an output closer to nl (I am on Solaris, maybe some nl behave
differently...) Note that it has the exact same amount of keystrokes.
(it may even be faster: I expect the seasoned Perl hacker to find the
$ key faster than the S key...)
E.g.:
granier: proto/pl <556> cat > /tmp/t
should be 1
should be 2
should be 4 (notice the two whitespaces in the line above)
granier: proto/pl <557> nl /tmp/t
1 should be 1
2 should be 2
3
4 should be 4 (notice the two whitespaces in the line above)
granier: proto/pl <558> perl -pe '/\S/ && printf "%6d\t", ++$c' < /tmp/t
1 should be 1
2 should be 2
3 should be 4 (notice the two whitespaces in the line above)
granier: proto/pl <559> perl -pe '/^$/ || printf "%6d\t", ++$c' < /tmp/t
1 should be 1
2 should be 2
3
4 should be 4 (notice the two whitespaces in the line above)
granier: proto/pl <560>
Julien
------------------------------
Date: Thu, 14 Oct 1999 10:41:57 GMT
From: *@dragons.duesouth.net (Matthew Bafford)
Subject: Re: nl Unix Command in Perl
Message-Id: <slrn80bajb.q1.*@dragons.duesouth.net>
On Wed, 13 Oct 1999 11:33:00 -0700, Larry Rosler) held some poor
sysadmin at gunpoint, and typed the following into comp.lang.perl.misc:
: Golf, anyone? (Whitespace-stripping doesn't count.)
:
: perl -pe '/\S/ ? printf "%6d\t", $. : --$.'
perl -pe '/\S/ && printf "%6d\t", ++$c'
: (Just Another Larry) Rosler
--Matthew
------------------------------
Date: Wed, 13 Oct 1999 17:38:58 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: nl Unix Command in Perl
Message-Id: <MPG.126ec602fed69daa98a090@nntp.hpl.hp.com>
In article <939856231.151461@elaine.drink.com> on Wed, 13 Oct 1999
23:05:23 GMT, Alan Barclay <gorilla@elaine.drink.com> says...
> In article <slrn809oom.nk2.abigail@alexandra.delanet.com>,
> Abigail <abigail@delanet.com> wrote:
> >Or when playing Perl golf:
> >
> > perl -pe '/\S/ && printf "%6d\t", ++$c'
>
> perl -pe 's/\S/++$i"\t$1"/e'
>
> formatting is slightly different, but saves several strokes.
I assume you intended to post code that (a) compiled, and (b) worked
properly.
perl -pe 's/\S/++$i."\t$&"/e'
That is two bugs in one expression. Not a bad ratio.
Now, the fact that it doesn't do the same as what you are comparing to
disqualifies it as a Golf competitor.
perl -pe 's/\S/sprintf"%6d\t$&",++$i/e'
perl -pe '/\S/&&printf"%6d\t",++$c'
So Abigail wins by four strokes. Why am I not surprised?
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Thu, 14 Oct 1999 08:41:08 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: nl Unix Command in Perl
Message-Id: <MPG.126f996ca86e202c98a092@nntp.hpl.hp.com>
In article <slrn80bajb.q1.*@dragons.duesouth.net> on Thu, 14 Oct 1999
10:41:57 GMT, Matthew Bafford <*@dragons.duesouth.net> says...
> On Wed, 13 Oct 1999 11:33:00 -0700, Larry Rosler) held some poor
> sysadmin at gunpoint, and typed the following into comp.lang.perl.misc:
> : Golf, anyone? (Whitespace-stripping doesn't count.)
> :
> : perl -pe '/\S/ ? printf "%6d\t", $. : --$.'
>
> perl -pe '/\S/ && printf "%6d\t", ++$c'
Abigail got there first. Undoubtedly the winner.
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: 14 Oct 1999 16:08:24 -0500
From: abigail@delanet.com (Abigail)
Subject: Re: nl Unix Command in Perl
Message-Id: <slrn80chhn.cso.abigail@alexandra.delanet.com>
Julien Quint (quint@granier.grenoble.xrce.xerox.com) wrote on MMCCXXXV
September MCMXCIII in <URL:news:thln96cltq.fsf@granier.grenoble.xrce.xerox.com>:
;; lt lindley <ltl@rgsun40.viasystems.com> writes:
;;
;; > I think Abigail hit a hole-in-one on this one and you should just
;; > move on to the next hole.
;;
;; I don't want to nitpick but nl skips only blank lines, that is lines that
;; are completely empty. I would change Abigail's one-liner to:
;;
;; perl -pe '/^$/ || printf "%6d\t", ++$c'
;;
;; to have an output closer to nl (I am on Solaris, maybe some nl behave
;; differently...) Note that it has the exact same amount of keystrokes.
;; (it may even be faster: I expect the seasoned Perl hacker to find the
;; $ key faster than the S key...)
Oh, but in that case, I can save an extra character:
perl -pe '/./ || printf "%6d\t", ++$c'
Abigail
--
perl -we '$_ = q ;4a75737420616e6f74686572205065726c204861636b65720as;;
for (s;s;s;s;s;s;s;s;s;s;s;s)
{s;(..)s?;qq qprint chr 0x$1 and \161 ssq;excess;}'
-----------== Posted via Newsfeeds.Com, Uncensored Usenet News ==----------
http://www.newsfeeds.com The Largest Usenet Servers in the World!
------== Over 73,000 Newsgroups - Including Dedicated Binaries Servers ==-----
------------------------------
Date: 14 Oct 1999 22:09:43 GMT
From: cjc5@po.cwru.edu (Craig J Copi)
Subject: Re: nl Unix Command in Perl
Message-Id: <7u5kb8$3mm$1@pale-rider.INS.CWRU.Edu>
In article <slrn80chhn.cso.abigail@alexandra.delanet.com>,
abigail@delanet.com (Abigail) writes:
> Julien Quint (quint@granier.grenoble.xrce.xerox.com) wrote on MMCCXXXV
> September MCMXCIII in <URL:news:thln96cltq.fsf@granier.grenoble.xrce.xerox.com>:
> ;; I don't want to nitpick but nl skips only blank lines, that is lines that
> ;; are completely empty. I would change Abigail's one-liner to:
> ;;
> ;; perl -pe '/^$/ || printf "%6d\t", ++$c'
> ;;
> ;; to have an output closer to nl (I am on Solaris, maybe some nl behave
> ;; differently...) Note that it has the exact same amount of keystrokes.
> ;; (it may even be faster: I expect the seasoned Perl hacker to find the
> ;; $ key faster than the S key...)
>
> Oh, but in that case, I can save an extra character:
>
> perl -pe '/./ || printf "%6d\t", ++$c'
Actually && --------------^^
since you have changed the sense of the logic.
>
> Abigail
Craig
--
Craig J Copi | cjc5@po.cwru.edu
Case Western Reserve University | http://erebus.phys.cwru.edu/~copi/
Department of Physics | (216) 368-8831
------------------------------
Date: 14 Oct 1999 22:22:15 GMT
From: lt lindley <ltl@rgsun5.viasystems.com>
Subject: Re: nl Unix Command in Perl
Message-Id: <7u5l2n$45j$1@rguxd.viasystems.com>
Abigail <abigail@delanet.com> wrote:
:>Oh, but in that case, I can save an extra character:
:> perl -pe '/./ || printf "%6d\t", ++$c'
&&
I've been waiting for this for a long time. :-)
--
// Lee.Lindley /// I used to think that being right was everything.
// @bigfoot.com /// Then I matured into the realization that getting
//////////////////// along was more important. Except on usenet.
------------------------------
Date: 15 Oct 1999 13:01:39 GMT
From: pruyss@callisto.rug.ac.be (Piet Ruyssinck)
Subject: non-blocking read - HOW ?
Message-Id: <7u78jj$m3g$1@inf6serv.rug.ac.be>
How do I perform a non-blocking read on a socket or filehandle in Perl ?
--
--------------------------------------------------------
Piet RUYSSINCK Piet.Ruyssinck@rug.ac.be
Unix Systeem Administratie +32 9 264 4733
ACADEMISCH REKENCENTRUM (ARC) Universiteit Gent (RUG)
Krijgslaan 281, gebouw S9, bureel 4 9000 Gent, Belgie
------------------------------
Date: Thu, 14 Oct 1999 10:17:18 +0800
From: "John Lin" <johnlin@chttl.com.tw>
Subject: open(F,"+>foo.txt"); flock(F);
Message-Id: <7u3ec8$iqf@netnews.hinet.net>
When I first saw the usage of flock() -
open the file then lock on the file handle (two steps),
I thought there must me something wrong here.
Finally I encountered one in my program.
use Fcntl ':flock';
open(F,"+>foo.txt") or die;
flock(F,LOCK_EX|LOCK_NB) or die;
print F scalar(localtime);
close F;
The lock-unlock section has a leak
(truncation open(F,"+>foo.txt") is outside the section).
If we adhere to flock()'s two step locking,
it seems impossible to correct this.
OK, I've done my homework.
perldoc -q file.lock
My suggestion is: the "perldoc -f flock" document should
include some words to discuss this and warn that
flock() is not suitable for this situation,
use sysopen() with O_EXCL instead.
In this case, "Perl's portable file locking interface" seems
to be not so portable (you have to use another function)...
John Lin
------------------------------
Date: Thu, 14 Oct 1999 07:25:16 GMT
From: "Samuel Kilchenmann" <skilchen@swissonline.ch>
Subject: Re: open(F,"+>foo.txt"); flock(F);
Message-Id: <wzfN3.24220$m4.88819025@news.magma.ca>
John Lin <johnlin@chttl.com.tw> schrieb in im Newsbeitrag:
7u3ec8$iqf@netnews.hinet.net...
> When I first saw the usage of flock() -
> open the file then lock on the file handle (two steps),
> I thought there must me something wrong here.
>
[...]
> Finally I encountered one in my program.
>
> open(F,"+>foo.txt") or die;
This is a terrible mistake. Evidently you shoud be using:
open(F,"+<foo.txt") or die;
> use sysopen() with O_EXCL instead.
>
The O_EXCL Flag has absolutely nothing to do with locking. This flag is
needed to do a) the check if a file already exists and b) the opening of
the file in a single atomic operation. Locking remains a two step
procedure even if you use sysopen, and if you use the flags O_RDWR |
O_TRUNC | O_EXCL you have exactly the same problem as with your open
using "+>".
------------------------------
Date: Fri, 15 Oct 1999 12:34:19 GMT
From: Paul D <pdobbs@home.com>
Subject: Opinions? Efficiency & Drain of Pack/UnPack
Message-Id: <38072071.979AF582@home.com>
I've been working on a couple of nifty scripts here, and think I may
be drawing on the use of Pack and Unpack alot, so I just want to ask;
Is the use of Pack and Unpack a significant strain on a system? IE:
Does it make a script particularly slower and in need of more system
resources/memory to do these two functions?
------------------------------
Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 16 Sep 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.
| NOTE: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.
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.
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 1070
**************************************