[30208] in Perl-Users-Digest
Perl-Users Digest, Issue: 1451 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Apr 15 16:35:53 2008
Date: Tue, 15 Apr 2008 13:35:43 -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 Tue, 15 Apr 2008 Volume: 11 Number: 1451
Today's topics:
Re: perl should be improved and perl6 <m@rtij.nl.invlalid>
Re: Time::HiRes < 1.91 and glibc 2.4 incompatibility <m@rtij.nl.invlalid>
Accessing a hash whose name is constructed <roblund@gmail.com>
Re: Accessing a hash whose name is constructed xhoster@gmail.com
Re: Accessing a hash whose name is constructed <jurgenex@hotmail.com>
How to know if data is piped into my script <asolkar@gmail.com>
Re: How to know if data is piped into my script xhoster@gmail.com
Re: How to know if data is piped into my script <devnull4711@web.de>
Re: Print a separator between each iteration of a forea xhoster@gmail.com
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Tue, 15 Apr 2008 21:12:03 +0200
From: Martijn Lievaart <m@rtij.nl.invlalid>
Subject: Re: perl should be improved and perl6
Message-Id: <pan.2008.04.15.19.12.02@rtij.nl.invlalid>
On Sat, 12 Apr 2008 14:02:59 -0700, Gordon Etly wrote:
> RedGrittyBrick wrote:
>> Gordon Etly wrote:
>>> RedGrittyBrick wrote:
>>>> Gordon Etly wrote:
>>>>> RedGrittyBrick wrote:
>>>>>> Gordon Etly wrote:
>>>>>>> Sherman Pendley wrote:
>>>>>>>> "Gordon Etly" <get@bentsys.com> writes:
>>>>>>>>
>>>>>>>> ... endlessly ...
>>>>>>>>
>>>>>>>> Will you give it a bloody rest already? Larry Wall invented the
>>>>>>>> language, and he says it's not called PERL. His language, his
>>>>>>>> call.
>>>>>>> Wrong, Larry himeself described it the same way 'perldoc perl'
>>>>>>> does.
>>>>>> i.e. both Larry and the docs use "perl" or "Perl" but *never*
>>>>>> "PERL" and have done so for many years.
>>>>>>
>>>>>>
>>>>>>
>>>>>> See this page and the articles under "Culture".
>>>>>> http://www.wall.org/~larry/perl.html
>>>>>>
>>>>>> No mentions of PERL that I can see.
>>>>> 'perldoc perl' defines PERL as "Practical Extraction and Report
>>>>> Language" in the NAME line. Why do you ignore this?
>>>>>
>>>> 'perldoc perl' defines perl as "Practical Extraction and Report
>>>> Language" in the NAME line. I'm not ignoring that.
>>>>
>>>> 'perldoc perl' contains "Perl" hundreds of times and 'PERL' zero
>>>> times. Why do you ignore this?
>>>
>>> I'm not ignoring it at all. Whether or not "PERL" is used throughout
>>> the documentation isn't the issue here.
>>
>> I believe it is germane to the issue.
>
> Sorry, but no, that was never the issuer at hand, but rather a tangent
> off the issue.
>
>>> What is the issue is the fact that
>>> since the main document defines "Practical Extraction and Report
>>> Language", it should //not// be //wrong// to use "PERL".
>>
>> I think it is your opinion, not a "fact", that your conclusion flows
>> from your premise.
>
> 'perldoc perl' is not my opinion.
>
> It states "Practical Extraction and Report Language" and therefore I
> don't know why it should be considered wrong to use "PERL" as a short
> for that, which it very well is.
>
> [...]
Well if you just snip the arguments without addressing them, I guess
there is no arguing possible.
M4
------------------------------
Date: Tue, 15 Apr 2008 20:58:11 +0200
From: Martijn Lievaart <m@rtij.nl.invlalid>
Subject: Re: Time::HiRes < 1.91 and glibc 2.4 incompatibility
Message-Id: <pan.2008.04.15.18.58.10@rtij.nl.invlalid>
On Tue, 15 Apr 2008 12:07:33 -0400, Mark Seger wrote:
>> The useconds_t type is only defined to support values up to 1,000,000.
>> Depending on undefined behavior is a mistake on the caller's part. The
>> AIX C library also returns an error if values >1M are passed in; it's
>> not a glibc bug.
>> ualarm is replaced by setitimer, which has seconds and microseconds.
>> --S
>
> I've been thinking about this some more, and I guess the question in my
> mind is how did this ever work? pre HiRes .91, ularm of 10 seconds
> works with glibc 2.3 and doesn't work with glibc 2.4.
If something is defined only when <condition> holds it is not defined
that it will not work <condition> doesn't hold. It might even work in
case condition is not satisfied! But depending on that undefined
behaviour might break in the next release, as was most probably the case
here.
M4
------------------------------
Date: Tue, 15 Apr 2008 12:46:49 -0700 (PDT)
From: Gibbering <roblund@gmail.com>
Subject: Accessing a hash whose name is constructed
Message-Id: <8de82ba9-9ba8-48aa-be17-549ad79f6e00@q24g2000prf.googlegroups.com>
I want to access some data from a hash, but want to build that hash's
name on the fly... here's the code:
%hello = (a => 'doggy');
print ${'hell' . lc 'O'}{a};
does the trick as does:
print %{'hell' . lc 'O'}->{a};
however, under "use strict", this fails, since %hello isn't declared
with "my".
If I do put a my in front of the %hello declaration, the print
statement gives me nothing.
I have a sinking suspicion that the above code is wrong, dangerous,
and error prone since I'm not even sure why it works.
What is the proper way to do such a thing?
------------------------------
Date: 15 Apr 2008 19:56:53 GMT
From: xhoster@gmail.com
Subject: Re: Accessing a hash whose name is constructed
Message-Id: <20080415155655.919$Oi@newsreader.com>
Gibbering <roblund@gmail.com> wrote:
> I want to access some data from a hash, but want to build that hash's
> name on the fly... here's the code:
Most likely, you want a multi-level hash.
>
> %hello = (a => 'doggy');
> print ${'hell' . lc 'O'}{a};
>
> does the trick as does:
> print %{'hell' . lc 'O'}->{a};
my %hash;
$hash{hello} = {a => 'doggy'};
print $hash{'hell' . lc 'O'}->{a};
> however, under "use strict", this fails, since %hello isn't declared
> with "my".
Yes indeed, that is one the of things that use strict is there for. The
main one, even.
>
> If I do put a my in front of the %hello declaration, the print
> statement gives me nothing.
You are using two different variables. The lexical %hello, and the global
%main::hello. Since lexicals can't be accessed symbolically, your attempt
at symbolic access (in the absence of use strict) resolved to %main::hello.
Xho
--
-------------------- http://NewsReader.Com/ --------------------
The costs of publication of this article were defrayed in part by the
payment of page charges. This article must therefore be hereby marked
advertisement in accordance with 18 U.S.C. Section 1734 solely to indicate
this fact.
------------------------------
Date: Tue, 15 Apr 2008 20:08:01 GMT
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: Accessing a hash whose name is constructed
Message-Id: <lg2a049e8qipod83trtbau5qgdmjifqaqk@4ax.com>
Gibbering <roblund@gmail.com> wrote:
>I want to access some data from a hash, but want to build that hash's
>name on the fly... here's the code:
>
>%hello = (a => 'doggy');
>print ${'hell' . lc 'O'}{a};
>
>does the trick as does:
>print %{'hell' . lc 'O'}->{a};
>I have a sinking suspicion that the above code is wrong, dangerous,
>and error prone since I'm not even sure why it works.
See gazillions of previous articles about 'symbolic reference'.
Or just perldoc -q variable ' How can I use a variable as a variable
name?'
>What is the proper way to do such a thing?
Use your own hash instead of the system symbol table. In your case
becasue that would become a HoH (hash of [ref to] hash).
jue
------------------------------
Date: Tue, 15 Apr 2008 12:37:25 -0700 (PDT)
From: Mahesh Asolkar <asolkar@gmail.com>
Subject: How to know if data is piped into my script
Message-Id: <ac5acc86-4ea6-4289-85cc-e60692f54eb8@q10g2000prf.googlegroups.com>
I have the following script:
-----
#!/usr/bin/perl
use strict;
use warnings;
my %hist = ();
my @hist;
$hist{(split /\s+/)[3]}++
foreach (`$ENV{'SHELL'} -c history`);
print map {"$hist{$_} : $_\n"}
sort {$hist{$b} <=> $hist{$a}}
keys %hist;
-----
I want to change it such that it uses '`$ENV{'SHELL'} -c history`'
only if nothing is piped into the script. If I call the script like:
% myscript.pl
It should use '`$ENV{'SHELL'} -c history`'. However if it is called
like:
% history | myscript.pl
It should use the piped in data instead.
What would be the best approach?
Thanks,
Mahesh
------------------------------
Date: 15 Apr 2008 19:48:21 GMT
From: xhoster@gmail.com
Subject: Re: How to know if data is piped into my script
Message-Id: <20080415154823.690$qR@newsreader.com>
Mahesh Asolkar <asolkar@gmail.com> wrote:
> I have the following script:
>
> -----
> #!/usr/bin/perl
>
> use strict;
> use warnings;
>
> my %hist = ();
> my @hist;
>
> $hist{(split /\s+/)[3]}++
> foreach (`$ENV{'SHELL'} -c history`);
>
> print map {"$hist{$_} : $_\n"}
> sort {$hist{$b} <=> $hist{$a}}
> keys %hist;
> -----
Assuming it is safe to load all input into memory at once:
my @x=<>;
foreach (@x? @x : `$ENV{'SHELL'} -c history`) {
This will do what <> does, not just pipes. If you want only STDIN, and
only when STDIN is hooked up to a pipe, then maybe:
foreach (-p STDIN ? <STDIN> : `$ENV{'SHELL'} -c history`) {
Xho
--
-------------------- http://NewsReader.Com/ --------------------
The costs of publication of this article were defrayed in part by the
payment of page charges. This article must therefore be hereby marked
advertisement in accordance with 18 U.S.C. Section 1734 solely to indicate
this fact.
------------------------------
Date: Tue, 15 Apr 2008 21:49:06 +0200
From: Frank Seitz <devnull4711@web.de>
Subject: Re: How to know if data is piped into my script
Message-Id: <66kf62F2kl8ufU7@mid.individual.net>
Mahesh Asolkar wrote:
>
> It should use '`$ENV{'SHELL'} -c history`'. However if it is called
> like:
>
> % history | myscript.pl
>
> It should use the piped in data instead.
unless (-t) {
# STDIN is not opend to a tty but a file or pipe
}
Frank
--
Dipl.-Inform. Frank Seitz; http://www.fseitz.de/
Anwendungen für Ihr Internet und Intranet
Tel: 04103/180301; Fax: -02; Industriestr. 31, 22880 Wedel
------------------------------
Date: 15 Apr 2008 19:40:09 GMT
From: xhoster@gmail.com
Subject: Re: Print a separator between each iteration of a foreach loop
Message-Id: <20080415154011.916$h7@newsreader.com>
Ben Morrow <ben@morrow.me.uk> wrote:
> Quoth xhoster@gmail.com:
> > ShaunJ <sjackman@gmail.com> wrote:
> > > I want to print a separator between each iteration of a foreach loop,
> > > but not after the last element. How do I avoid printing the last
> > > extraneous comma in the following code snippet?
> > >
> > > foreach (@ARGV) {
> > > print $_, ',';
> > > }
> > > print "\n";
> > >
> > > In this simple example join ',' would suffice, but the real body of
> > > the foreach loop is more complicated.
> >
> > Unless it is huge, you could just change the print to be push @results,
> > $_; and then do the join on @results.
>
> print join ',', map {...} @ARGV; is cleaner than pushing onto an
> intermediate array.
Sure, but I thought he was hinting that the contents of the loop were more
complex than shown, and hence would be more complex than comfortable in a
map block. Of course, different people do have different comfort levels
when it comes to cramming complexity into map blocks.
> Or you can set $, and $\ and avoid the join and "\n"
> altogether.
Sure, but then I'd have look up which ones are which (I don't use them
enough to remember $, from $" from $;, and $\ from $/) and then I'd worry
about whether I should change them globally (i.e. will code later on use
them implicitly and get confused, either now or with likely future
evolution of the script) or if I need to localize them and then go look up
the details of localizing punctuation variables. Easier to just use join,
which I don't need to look up. So basically, I don't use them because I
don't use them enough to feel comfortable using them without looking things
up, kind of a self-reinforcing situation.
A Freudian analysis of Perl programming technique.
Xho
--
-------------------- http://NewsReader.Com/ --------------------
The costs of publication of this article were defrayed in part by the
payment of page charges. This article must therefore be hereby marked
advertisement in accordance with 18 U.S.C. Section 1734 solely to indicate
this fact.
------------------------------
Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 6 Apr 01)
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: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice.
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 V11 Issue 1451
***************************************