[31334] in Perl-Users-Digest
Perl-Users Digest, Issue: 2579 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Sep 2 14:09:50 2009
Date: Wed, 2 Sep 2009 11:09:14 -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, 2 Sep 2009 Volume: 11 Number: 2579
Today's topics:
create a form with cgi and a multidimensional array <mstep@podiuminternational.org>
FAQ 1.6 What is Perl 6? <brian@theperlreview.com>
FAQ 4.12 How do I find the day or week of the year? <brian@theperlreview.com>
FAQ 4.41 How can I remove duplicate elements from a lis <brian@theperlreview.com>
getopts::long & option string argument <sensorflo@gmail.com>
Re: getopts::long & option string argument <james.news@nixeagle.org>
Re: getopts::long & option string argument <sensorflo@gmail.com>
Re: getopts::long & option string argument <jurgenex@hotmail.com>
Re: log timestamp a script is used <gerhard_ulrike@yahoo.de>
need help, will pay <shambo_p@yahoo.com>
Re: need help, will pay <nat.k@gm.ml>
Re: need help, will pay <shambo_p@yahoo.com>
Re: need help, will pay <no@email.com>
Re: need help, will pay <jurgenex@hotmail.com>
Re: Perl 5.10.1 Smartmatch Num ~~ Numish <ben@morrow.me.uk>
Re: Perl 5.10.1 Smartmatch Num ~~ Numish <nospam-abuse@ilyaz.org>
Re: Possibly useful perl script to filter lines in one <benburch@pobox.com>
Re: Possibly useful perl script to filter lines in one <uri@StemSystems.com>
Re: Possibly useful perl script to filter lines in one <tadmc@seesig.invalid>
Re: Possibly useful perl script to filter lines in one <nat.k@gm.ml>
Re: Possibly useful perl script to filter lines in one <whynot@pozharski.name>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 2 Sep 2009 02:00:51 -0700 (PDT)
From: Marek <mstep@podiuminternational.org>
Subject: create a form with cgi and a multidimensional array
Message-Id: <e2949fc6-1e51-4d1c-9a9c-e19dae7e21a4@38g2000yqr.googlegroups.com>
Hello all!
I have a cgi problem, which I can not resolve alone.
I have a multidimensional array, to create a form like follows:
my @element_liste = (
{
type => "text",
name => "firma",
bez => "Firma:",
size => 36
},
etc.
my cgi script iterates over this array to create the form:
foreach my $f ( @{$element_liste_ref} ) {
my $type = $f->{type};
my $bez = $f->{bez};
if ( $type eq "text" ) {
push(
@zeile,
Tr(
td($bez),
td(
textfield(
-name => $f->{name},
-size => $f->{size}
)
)
)
);
}}
etc
Like that every table row is stocked into @zeile for later printing,
like follows:
tr
=================================================================
td td
| $bez | <input type="text" name="firma" size="36" /
> |
=================================================================
But now I have the problem, that I need to add a dimension more for
the date. Explication:
,
{
type => "popup",
name => "time",
bez => "day/month/year/ - hh:mm",
value => [ "01", "02", "03", etc. ]
},
{
type => "popup",
name => "time",
bez => "day/month/year/ - hh:mm",
value => [ "Jan", "Feb", etc. ],
},
{
type => "popup",
name => "time",
bez => "day/month/year/ - hh:mm",
value => [ "2009", "2010", "2011", "2012" ],
}
etc
And I need the cgi to creat *ONE* table row only with day/month/year -
hour:min
tr
=================================================================
td td
| $bez | <select name="time"> |
| | <option value="01"> |
| | 01 = days |
| | etc. |
| | same for /month/year - hour:min |
=================================================================
Could be somebody so kind, to help me with this?
Best greetings from Munich
marek
------------------------------
Date: Wed, 02 Sep 2009 16:00:04 GMT
From: PerlFAQ Server <brian@theperlreview.com>
Subject: FAQ 1.6 What is Perl 6?
Message-Id: <8Ewnm.128900$sC1.5635@newsfe17.iad>
This is an excerpt from the latest version perlfaq1.pod, which
comes with the standard Perl distribution. These postings aim to
reduce the number of repeated questions as well as allow the community
to review and update the answers. The latest version of the complete
perlfaq is at http://faq.perl.org .
--------------------------------------------------------------------
1.6: What is Perl 6?
At The Second O'Reilly Open Source Software Convention, Larry Wall
announced Perl 6 development would begin in earnest. Perl 6 was an oft
used term for Chip Salzenberg's project to rewrite Perl in C++ named
Topaz. However, Topaz provided valuable insights to the next version of
Perl and its implementation, but was ultimately abandoned.
If you want to learn more about Perl 6, or have a desire to help in the
crusade to make Perl a better place then peruse the Perl 6 developers
page at http://dev.perl.org/perl6/ and get involved.
Perl 6 is not scheduled for release yet, and Perl 5 will still be
supported for quite awhile after its release. Do not wait for Perl 6 to
do whatever you need to do.
"We're really serious about reinventing everything that needs
reinventing." --Larry Wall
--------------------------------------------------------------------
The perlfaq-workers, a group of volunteers, maintain the perlfaq. They
are not necessarily experts in every domain where Perl might show up,
so please include as much information as possible and relevant in any
corrections. The perlfaq-workers also don't have access to every
operating system or platform, so please include relevant details for
corrections to examples that do not work on particular platforms.
Working code is greatly appreciated.
If you'd like to help maintain the perlfaq, see the details in
perlfaq.pod.
------------------------------
Date: Wed, 02 Sep 2009 04:00:02 GMT
From: PerlFAQ Server <brian@theperlreview.com>
Subject: FAQ 4.12 How do I find the day or week of the year?
Message-Id: <65mnm.2923$UH2.2665@newsfe01.iad>
This is an excerpt from the latest version perlfaq4.pod, which
comes with the standard Perl distribution. These postings aim to
reduce the number of repeated questions as well as allow the community
to review and update the answers. The latest version of the complete
perlfaq is at http://faq.perl.org .
--------------------------------------------------------------------
4.12: How do I find the day or week of the year?
The localtime function returns the day of the year. Without an argument
localtime uses the current time.
$day_of_year = (localtime)[7];
The "POSIX" module can also format a date as the day of the year or week
of the year.
use POSIX qw/strftime/;
my $day_of_year = strftime "%j", localtime;
my $week_of_year = strftime "%W", localtime;
To get the day of year for any date, use "POSIX"'s "mktime" to get a
time in epoch seconds for the argument to localtime.
use POSIX qw/mktime strftime/;
my $week_of_year = strftime "%W",
localtime( mktime( 0, 0, 0, 18, 11, 87 ) );
The "Date::Calc" module provides two functions to calculate these.
use Date::Calc;
my $day_of_year = Day_of_Year( 1987, 12, 18 );
my $week_of_year = Week_of_Year( 1987, 12, 18 );
--------------------------------------------------------------------
The perlfaq-workers, a group of volunteers, maintain the perlfaq. They
are not necessarily experts in every domain where Perl might show up,
so please include as much information as possible and relevant in any
corrections. The perlfaq-workers also don't have access to every
operating system or platform, so please include relevant details for
corrections to examples that do not work on particular platforms.
Working code is greatly appreciated.
If you'd like to help maintain the perlfaq, see the details in
perlfaq.pod.
------------------------------
Date: Wed, 02 Sep 2009 10:00:01 GMT
From: PerlFAQ Server <brian@theperlreview.com>
Subject: FAQ 4.41 How can I remove duplicate elements from a list or array?
Message-Id: <Bmrnm.10538$u76.5844@newsfe10.iad>
This is an excerpt from the latest version perlfaq4.pod, which
comes with the standard Perl distribution. These postings aim to
reduce the number of repeated questions as well as allow the community
to review and update the answers. The latest version of the complete
perlfaq is at http://faq.perl.org .
--------------------------------------------------------------------
4.41: How can I remove duplicate elements from a list or array?
(contributed by brian d foy)
Use a hash. When you think the words "unique" or "duplicated", think
"hash keys".
If you don't care about the order of the elements, you could just create
the hash then extract the keys. It's not important how you create that
hash: just that you use "keys" to get the unique elements.
my %hash = map { $_, 1 } @array;
# or a hash slice: @hash{ @array } = ();
# or a foreach: $hash{$_} = 1 foreach ( @array );
my @unique = keys %hash;
If you want to use a module, try the "uniq" function from
"List::MoreUtils". In list context it returns the unique elements,
preserving their order in the list. In scalar context, it returns the
number of unique elements.
use List::MoreUtils qw(uniq);
my @unique = uniq( 1, 2, 3, 4, 4, 5, 6, 5, 7 ); # 1,2,3,4,5,6,7
my $unique = uniq( 1, 2, 3, 4, 4, 5, 6, 5, 7 ); # 7
You can also go through each element and skip the ones you've seen
before. Use a hash to keep track. The first time the loop sees an
element, that element has no key in %Seen. The "next" statement creates
the key and immediately uses its value, which is "undef", so the loop
continues to the "push" and increments the value for that key. The next
time the loop sees that same element, its key exists in the hash *and*
the value for that key is true (since it's not 0 or "undef"), so the
next skips that iteration and the loop goes to the next element.
my @unique = ();
my %seen = ();
foreach my $elem ( @array )
{
next if $seen{ $elem }++;
push @unique, $elem;
}
You can write this more briefly using a grep, which does the same thing.
my %seen = ();
my @unique = grep { ! $seen{ $_ }++ } @array;
--------------------------------------------------------------------
The perlfaq-workers, a group of volunteers, maintain the perlfaq. They
are not necessarily experts in every domain where Perl might show up,
so please include as much information as possible and relevant in any
corrections. The perlfaq-workers also don't have access to every
operating system or platform, so please include relevant details for
corrections to examples that do not work on particular platforms.
Working code is greatly appreciated.
If you'd like to help maintain the perlfaq, see the details in
perlfaq.pod.
------------------------------
Date: Wed, 2 Sep 2009 07:28:18 -0700 (PDT)
From: Florian Kaufmann <sensorflo@gmail.com>
Subject: getopts::long & option string argument
Message-Id: <3b58beac-e0a0-4da8-97c2-f3cc6ee8ce52@a7g2000yqo.googlegroups.com>
What can Getopt::Long, or any other 'standard' module offer me for
this problem task:
I have an option which expects a string argument. But a) only a finite
set of strings are to be accepted b) unique abbreviations shall be
accepted, e.g. if the set of valid strings is ("foo","bar","fly") then
"fo" should stand for "foo".
An example for such a use case is the --backup[=CONTROL] option of
many coreutils tools as for example cp, ln, install. CONTROL can only
be ("no","off","numbered"... and a few more).
------------------------------
Date: Wed, 02 Sep 2009 10:48:52 -0500
From: James Spahlinger <james.news@nixeagle.org>
Subject: Re: getopts::long & option string argument
Message-Id: <h7m454$sdg$1@news.eternal-september.org>
Florian Kaufmann wrote:
> What can Getopt::Long, or any other 'standard'
module offer me for
> this problem task:
>
> I have an option which expects a string
argument. But a) only a finite
> set of strings are to be accepted b) unique
abbreviations shall be
> accepted, e.g. if the set of valid strings is
("foo","bar","fly") then
> "fo" should stand for "foo".
>
> An example for such a use case is the --
backup[=CONTROL] option of
> many coreutils tools as for example cp, ln,
install. CONTROL can only
> be ("no","off","numbered"... and a few more).
What you want to do is exactly what Getopt is
for.
------------------------------
Date: Wed, 2 Sep 2009 09:52:06 -0700 (PDT)
From: Florian Kaufmann <sensorflo@gmail.com>
Subject: Re: getopts::long & option string argument
Message-Id: <298be692-e1ff-48d1-b3cc-caabd95a5044@o10g2000yqa.googlegroups.com>
> What you want to do is exactly what Getopt is
> for.
So which part of "perldoc Getopt::Long" tells me how I accomplish
point a) and b) from my question? I already used Getopt::Long before,
so I know the basics. Reading the documentation, the 'only' limitation
upon the argument of an option I can make, is to tell wheter it has to
be a string, an integer, or a float. I cant say, it has to be a string
of a certain finite set. See section "options with values".
------------------------------
Date: Wed, 02 Sep 2009 10:50:21 -0700
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: getopts::long & option string argument
Message-Id: <30ct95dd16ssj744s08thfmr24kt3kn6hk@4ax.com>
[Quoting in full]
James Spahlinger <james.news@nixeagle.org> wrote:
>Florian Kaufmann wrote:
>
>> What can Getopt::Long, or any other 'standard'
>module offer me for
>> this problem task:
>>
>> I have an option which expects a string
>argument. But a) only a finite
>> set of strings are to be accepted b) unique
>abbreviations shall be
>> accepted, e.g. if the set of valid strings is
>("foo","bar","fly") then
>> "fo" should stand for "foo".
>>
>> An example for such a use case is the --
>backup[=CONTROL] option of
>> many coreutils tools as for example cp, ln,
>install. CONTROL can only
>> be ("no","off","numbered"... and a few more).
>What you want to do is exactly what Getopt is
>for.
What on earth did you do with the quoted text. You _REALLY_ should check
your quoting style. It is absolutely impossible to tell what you were
quoting and what you were saying.
jue
------------------------------
Date: Wed, 2 Sep 2009 03:26:42 -0700 (PDT)
From: Gerhard <gerhard_ulrike@yahoo.de>
Subject: Re: log timestamp a script is used
Message-Id: <6d56b01c-4f9e-49c0-8d5e-8be637794286@y9g2000yqn.googlegroups.com>
On 24 Aug., 17:36, t...@panix.com (Tim McDaniel) wrote:
>
> Yeah. =A0And if this is, for example, running only several times a day,
> the overhead is negligable. =A0All too often, micro-optimization
> takes macro-effort to produce micro-results.
>
i see you and me we know of the german saying "wer misst misst
mist" ....
thanks for the hint, i've thougt about that and appreciated to be
about one thousand calls a day. (the counter exhibits that there are
"only" 700 a day)
That seems to be a lot, but the scripts i'd taken over look alike
scripts from a shell2perl converter. Within that scripts there is a
plenty of commands like this ones:
$first=3D`cd $workingdir; ls SA*.txt|sort|head -1`
$last =3D'cd $workingdir; ls SA*.txt|sort|tail -1`
etc.
I've counted 42 backticks and system-calls in only one script ....
therefore i had no scruple to do it in the same way.
Gerhard
------------------------------
Date: Wed, 2 Sep 2009 09:36:30 -0700 (PDT)
From: boman <shambo_p@yahoo.com>
Subject: need help, will pay
Message-Id: <4d0f73c0-9bb6-4895-9c31-46f7f6b2512c@d34g2000vbm.googlegroups.com>
Need help with a simple Perl cgi script running from Apache 2.2 on
Windows XP, willing to pay $100 for the solution. Please email me for
details. Prefer NYC-based coder, payment in cash.
------------------------------
Date: Wed, 02 Sep 2009 09:49:00 -0700
From: Nathan Keel <nat.k@gm.ml>
Subject: Re: need help, will pay
Message-Id: <1mxnm.329324$Ta5.176887@newsfe15.iad>
boman wrote:
> Need help with a simple Perl cgi script running from Apache 2.2 on
> Windows XP, willing to pay $100 for the solution. Please email me for
> details. Prefer NYC-based coder, payment in cash.
Why don't you post what the error is and the relevant portions of the
script? You can probably get good help for no charge right now.
------------------------------
Date: Wed, 2 Sep 2009 10:06:08 -0700 (PDT)
From: boman <shambo_p@yahoo.com>
Subject: Re: need help, will pay
Message-Id: <3945bc09-8d1c-44bb-8e8e-db0866fd4830@j9g2000vbp.googlegroups.com>
On Sep 2, 12:49=A0pm, Nathan Keel <na...@gm.ml> wrote:
> boman wrote:
> > Need help with a simple Perl cgi script running from Apache 2.2 on
> > Windows XP, willing to pay $100 for the solution. Please email me for
> > details. Prefer NYC-based coder, payment in cash.
>
> Why don't you post what the error is and the relevant portions of the
> script? =A0You can probably get good help for no charge right now.
This question has been asked before, and I've tried almost all of the
solutions, with no success. So I'm trying not to annoy this group by
asking the question again. After the reading the "why doesn't this
work" thread from Aug 20, I didn't want to start another brawl.
But you graciously asked, Nathan, so here goes!
1. display web page with simple form w/ radio buttons
2. user selects radio button and clicks submit
3. single parameter is passed from the radio button
4. exe command on web server is initiated (I was using
Win32::Process), parameter is passed
5. output of command is sent back to browser in real time (this is
where I'm stuck)
6. when command is done, start 2nd command, send output to browser in
real time
I've got 1-4 working, but cannot get output of command to the browser
in real time, as the output is generated. It simply waits for command
to finish, then sends the entire out put in one blob.
Yes, I've got the $|=3D1 set, and I made sure apache is not buffering
output, but can't get around the browsers doing the buffering (I think
this is what's happening).
Yes, I've read the stonehenge article which uses traceroute as an
example, but cannot get that to work on my Windows perl v5.8.8. I
tried some of the concepts from this article, but it's a bit out of my
league.
At this point I cannot spend much more time trying to get this to work
myself, and I need a simple, yet professional level solution. I've
read lots of forums, paged thru numerous books, I can't really spend
time on that anymore. I need something that works, and I need it this
week.
I know this can probably be done in javascript, but I'd prefer this to
be done in Perl. Also, I won't be able to install any modules, we'll
have to use what's installed by default.
thanks!
------------------------------
Date: Wed, 02 Sep 2009 18:57:36 +0100
From: Brian Wakem <no@email.com>
Subject: Re: need help, will pay
Message-Id: <7g7q0iF2ot5q7U1@mid.individual.net>
boman wrote:
> On Sep 2, 12:49 pm, Nathan Keel <na...@gm.ml> wrote:
>> boman wrote:
>> > Need help with a simple Perl cgi script running from Apache 2.2 on
>> > Windows XP, willing to pay $100 for the solution. Please email me for
>> > details. Prefer NYC-based coder, payment in cash.
>>
>> Why don't you post what the error is and the relevant portions of the
>> script? You can probably get good help for no charge right now.
>
> This question has been asked before, and I've tried almost all of the
> solutions, with no success. So I'm trying not to annoy this group by
> asking the question again. After the reading the "why doesn't this
> work" thread from Aug 20, I didn't want to start another brawl.
>
> But you graciously asked, Nathan, so here goes!
>
> 1. display web page with simple form w/ radio buttons
> 2. user selects radio button and clicks submit
> 3. single parameter is passed from the radio button
> 4. exe command on web server is initiated (I was using
> Win32::Process), parameter is passed
> 5. output of command is sent back to browser in real time (this is
> where I'm stuck)
> 6. when command is done, start 2nd command, send output to browser in
> real time
>
> I've got 1-4 working, but cannot get output of command to the browser
> in real time, as the output is generated. It simply waits for command
> to finish, then sends the entire out put in one blob.
>
> Yes, I've got the $|=1 set, and I made sure apache is not buffering
> output, but can't get around the browsers doing the buffering
A quick and easy way around browser buffering is to print something like
this 100 or so times after every line you output.
<!-- this wont show up on the page but will force the browser to flush -->
--
Brian Wakem
------------------------------
Date: Wed, 02 Sep 2009 11:03:33 -0700
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: need help, will pay
Message-Id: <06ct95lshlro684vadfveilspn18mb09al@4ax.com>
boman <shambo_p@yahoo.com> wrote:
>1. display web page with simple form w/ radio buttons
>2. user selects radio button and clicks submit
>3. single parameter is passed from the radio button
>4. exe command on web server is initiated (I was using
>Win32::Process), parameter is passed
>5. output of command is sent back to browser in real time (this is
>where I'm stuck)
>6. when command is done, start 2nd command, send output to browser in
>real time
>
>I've got 1-4 working, but cannot get output of command to the browser
>in real time, as the output is generated. It simply waits for command
>to finish, then sends the entire out put in one blob.
As has been explained to you back then this is _NOT(!)_ a Perl issue but
a problem somewhere in the long chain of receiving CGI response,
creating and sending HTTP response, receiving HTTP response, rendering
the page in the browser. You really need someone who is familiar with
those areas (no matter in which language) instead of someone who is
familiar with Perl.
In short: you are barking up the wrong tree.
>Yes, I've got the $|=1 set, and I made sure apache is not buffering
>output, but can't get around the browsers doing the buffering (I think
>this is what's happening).
As I said, you need someone who is familiar with web programming, not
someone familiar with Perl.
>I know this can probably be done in javascript, but I'd prefer this to
>be done in Perl.
That is not possible! Please, please, please, you already set the Perl
buffer to auto-flush. There REALLY is nothing else you can do in your
Perl code.
You said yourself that the buffering probably happens in the brower.
Maybe so, maybe somewhere else in the chain. But it really, really isn't
Perl.
Aside of that, "in real time" is a non-starter to begin with because the
HyperText Transfer Protocol is not real-time to begin with.
If you need real time then you need to look into a different protocol,
but that's even more off topic than web programming.
jue
------------------------------
Date: Wed, 2 Sep 2009 00:18:24 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: Perl 5.10.1 Smartmatch Num ~~ Numish
Message-Id: <0nm0n6-2l72.ln1@osiris.mauzo.dyndns.org>
Quoth Ilya Zakharevich <nospam-abuse@ilyaz.org>:
> On 2009-09-01, Ben Morrow <ben@morrow.me.uk> wrote:
> >>Quoth Ilya Zakharevich <nospam-abuse@ilyaz.org>:
>
> >> Obviously, there MUST be a way - otherwise one would not be able to
> >> "correctly" translate a 2-headed value into a 3-headed one... (Ask if
> >> one wants to know more details. ;-)
>
> > Yes, please... AFAIK, perl doesn't have any triplevars, if by that you
> > mean some sort of PVIVNV.
>
> IIRC, any variable except PV, IV, NV, PVIV may be a triple-variable (if
> all the corresponding flags are set).
You're right, of course. I was getting lost in the macros in sv.h, and
thought XPVNV didn't have an IV slot.
> > Numeric conversion between IV, UV and NV don't use the string value
> > at all.
>
> This is a bug. Consider $a = "1234568790123445678". After you use it in
> an NV context, it might be converted to 1234568790123445504; this
> value MUST be stored in the NV slot to avoid future slowdowns.
>
> However, this value may be exactly representable as an integer value.
> So the stored in NV slot value MUST be marked as "not trustworthy", so
> that a future conversion to integer would go PV --> IV, not NV --> IV.
>
> All this was working about 10 years ago...
Now it appears to do the IV conversion straight away (to preserve the
precision):
perl -MDevel::Peek -e'$x = "888888888888888888"; $x + 2.1;
Dump $x; warn sprintf "%.0f\n%i", $x, $x'
SV = PVNV(0x8102c6c) at 0x8117060
REFCNT = 1
FLAGS = (IOK,POK,pIOK,pNOK,pPOK)
IV = 888888888888888888
NV = 8.88888888888889e+17
PV = 0x811a7a0 "888888888888888888"\0
CUR = 18
LEN = 20
888888888888888960
888888888888888888 at -e line 1.
and it'll even give you an UV if necessary:
perl -MDevel::Peek -e'$x = "9888888888888888888"; $x + 2.1;
Dump $x; warn sprintf "%.0f\n%u", $x, $x'
SV = PVNV(0x8102c6c) at 0x8117060
REFCNT = 1
FLAGS = (IOK,POK,pIOK,pNOK,pPOK,IsUV)
UV = 9888888888888888888
NV = 9.88888888888889e+18
PV = 0x811a7a0 "9888888888888888888"\0
CUR = 19
LEN = 20
9888888888888889344
9888888888888888888 at -e line 1.
(this is on a perl with 64-bit IVs and 53-bit NVs). All this seems to be
governed by the NV_PRESERVES_UV and ..._BITS macros which Configure sets
as appropriate, so if you are on a system with 32-bit UVs and 53-bit NVs
and a NV can hold any UV with integer precision, it won't bother.
Ben
------------------------------
Date: Wed, 2 Sep 2009 05:47:27 +0000 (UTC)
From: Ilya Zakharevich <nospam-abuse@ilyaz.org>
Subject: Re: Perl 5.10.1 Smartmatch Num ~~ Numish
Message-Id: <slrnh9s1nf.u2l.nospam-abuse@chorin.math.berkeley.edu>
On 2009-09-01, Ben Morrow <ben@morrow.me.uk> wrote:
>> > Numeric conversion between IV, UV and NV don't use the string value
>> > at all.
>>
>> This is a bug. Consider $a = "1234568790123445678". After you use it in
>> an NV context, it might be converted to 1234568790123445504; this
>> value MUST be stored in the NV slot to avoid future slowdowns.
>>
>> However, this value may be exactly representable as an integer value.
>> So the stored in NV slot value MUST be marked as "not trustworthy", so
>> that a future conversion to integer would go PV --> IV, not NV --> IV.
>>
>> All this was working about 10 years ago...
>
> Now it appears to do the IV conversion straight away (to preserve the
> precision):
PV --> NV is only one of 6 possible pathways; doing *this one*
straight away is not going to be a waste of space, sine PVNV has an IV
slot anyway; however, the others might have serious effects on memory
usage...
Yours,
Ilya
------------------------------
Date: Tue, 01 Sep 2009 18:22:53 -0500
From: Ben Burch <benburch@pobox.com>
Subject: Re: Possibly useful perl script to filter lines in one file out of another.
Message-Id: <010920091822536230%benburch@pobox.com>
Why did I know somebody was going to object if I didn't make my hack
into a textbook example?
In article <slrnh93629.934.tadmc@tadmc30.sbcglobal.net>, Tad J
McClellan <tadmc@seesig.invalid> wrote:
> Ben Burch <benburch@pobox.com> wrote:
>
> > #!/usr/bin/perl
>
> use warnings;
> use strict;
>
> > open (EXCLUDE, $file2);
>
> You should always, yes *always*, check the return value from open():
>
> open my $EXCLUDE, '<', $file2 or die "could not open '$file2' $!";
Nope. Perl programmers are fond of their one-liners, but they are
unclear and missed in peer code inspections.
Much better is;
my $status = open (EXCLUDE, '<', $file2);
if( !$status )
{
print "File open error $!";
exit 1;
}
(You can die() if you want to, but no reason to do it unless you plan
to handle the signal...)
And there is no reason to make the FHs in scalar form at all, and its
less clear when you do.
>
> > while ($line = <EXCLUDE>)
>
> while ($line = <$EXCLUDE>)
>
> > if(!exists($exclude{$line}))
>
> unless ( exists $exclude{$line} )
Unless is an abomination when it comes to code that will have faults
found in code review.
>
> or at least make wise use of whitespace and punctuation:
>
> if ( ! exists $exclude{$line} )
Sure, run it through tidy and get some white space if you like, I never
have any trouble reading it without.
------------------------------
Date: Tue, 01 Sep 2009 19:39:52 -0400
From: "Uri Guttman" <uri@StemSystems.com>
Subject: Re: Possibly useful perl script to filter lines in one file out of another.
Message-Id: <87praas08n.fsf@quad.sysarch.com>
>>>>> "BB" == Ben Burch <benburch@pobox.com> writes:
BB> Why did I know somebody was going to object if I didn't make my hack
BB> into a textbook example?
because code posted here is always up for review.
BB> In article <slrnh93629.934.tadmc@tadmc30.sbcglobal.net>, Tad J
BB> McClellan <tadmc@seesig.invalid> wrote:
>>
>> > open (EXCLUDE, $file2);
>>
>> You should always, yes *always*, check the return value from open():
>>
>> open my $EXCLUDE, '<', $file2 or die "could not open '$file2' $!";
BB> Nope. Perl programmers are fond of their one-liners, but they are
BB> unclear and missed in peer code inspections.
huh? open or die is such a common idiom it is not missed. how much code
review do you do?
BB> Much better is;
BB> my $status = open (EXCLUDE, '<', $file2);
BB> if( !$status )
BB> {
BB> print "File open error $!";
BB> exit 1;
BB> }
and print/exit is what die does. that is 6 lines of verbosity vs 1 clear
line.
BB> (You can die() if you want to, but no reason to do it unless you plan
BB> to handle the signal...)
what???
BB> And there is no reason to make the FHs in scalar form at all, and its
BB> less clear when you do.
huh?? lexical handles are not globals which is the point of
them. globals are bad. if you try to defend globals, you are not on
solid ground.
>>
>> > while ($line = <EXCLUDE>)
>>
>> while ($line = <$EXCLUDE>)
>>
>> > if(!exists($exclude{$line}))
>>
>> unless ( exists $exclude{$line} )
BB> Unless is an abomination when it comes to code that will have faults
BB> found in code review.
again, who is reviewing that code? kindergarten coders? unless is
perfectly fine and is better than an extra noisy negation when reading code.
>>
>> or at least make wise use of whitespace and punctuation:
>>
>> if ( ! exists $exclude{$line} )
BB> Sure, run it through tidy and get some white space if you like, I never
BB> have any trouble reading it without.
but that won't pass code review!!
goose, meet gander!
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.sysarch.com --
----- Perl Code Review , Architecture, Development, Training, Support ------
--------- Gourmet Hot Cocoa Mix ---- http://bestfriendscocoa.com ---------
------------------------------
Date: Tue, 01 Sep 2009 21:07:19 -0500
From: Tad J McClellan <tadmc@seesig.invalid>
Subject: Re: Possibly useful perl script to filter lines in one file out of another.
Message-Id: <slrnh9rk6l.ghc.tadmc@tadmc30.sbcglobal.net>
Ben Burch <benburch@pobox.com> wrote:
> In article <slrnh93629.934.tadmc@tadmc30.sbcglobal.net>, Tad J
> McClellan <tadmc@seesig.invalid> wrote:
>
>> Ben Burch <benburch@pobox.com> wrote:
>> > open (EXCLUDE, $file2);
>>
>> You should always, yes *always*, check the return value from open():
>>
>> open my $EXCLUDE, '<', $file2 or die "could not open '$file2' $!";
>
> Nope.
Yes, you should always, yes *always*, check the return value from open().
> Perl programmers are fond of their one-liners, but they are
> unclear and missed in peer code inspections.
That does not have anything to do with checking the return value from open().
> Much better is;
>
> my $status = open (EXCLUDE, '<', $file2);
>
> if( !$status )
> {
> print "File open error $!";
Normal output should go on stdout, error output should go on stderr.
> exit 1;
> }
That *is* checking the return value from open(), so what was
the "Nope" in reference to?
I didn't say that you much check the return value using a die one-liner,
only that the return value should be checked.
> (You can die() if you want to, but no reason to do it unless you plan
> to handle the signal...)
What signal?
>> > if(!exists($exclude{$line}))
>>
>> unless ( exists $exclude{$line} )
>
> Unless is an abomination when it comes to code that will have faults
> found in code review.
At least we can agree on that.
> Sure, run it through tidy and get some white space if you like, I never
> have any trouble reading it without.
It must be luxurious to write code only for yourself. Most programmers
must write code for *other* programmers to read.
--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"
------------------------------
Date: Tue, 01 Sep 2009 21:56:58 -0700
From: Nathan Keel <nat.k@gm.ml>
Subject: Re: Possibly useful perl script to filter lines in one file out of another.
Message-Id: <uWmnm.17744$Y83.14772@newsfe21.iad>
Ben Burch wrote:
> my $status = open (EXCLUDE, '<', $file2);
>
> if( !$status )
> {
> print "File open error $!";
> exit 1;
> }
>
I don't get the correlation of one liners and Perl programmers? Some do
often when they can or want, and some do not. I wasn't aware one was
more frequent than the other? Anyway, what do you think you're if
statement is checking the status of? The return value of open is what.
No one said you have to (or should) die.
------------------------------
Date: Wed, 02 Sep 2009 10:14:52 +0300
From: Eric Pozharski <whynot@pozharski.name>
Subject: Re: Possibly useful perl script to filter lines in one file out of another.
Message-Id: <slrnh9s6rb.l9g.whynot@orphan.zombinet>
On 2009-09-01, Uri Guttman <uri@StemSystems.com> wrote:
>>>>>> "BB" == Ben Burch <benburch@pobox.com> writes:
*SKIP*
> BB> my $status = open (EXCLUDE, '<', $file2);
>
> BB> if( !$status )
> BB> {
> BB> print "File open error $!";
> BB> exit 1;
> BB> }
>
> and print/exit is what die does. that is 6 lines of verbosity vs 1 clear
> line.
And if code dies in debugger then debugger dumps stack. What's not the
case B<print>-B<exit>.
*CUT*
--
Torvalds' goal for Linux is very simple: World Domination
Stallman's goal for GNU is even simpler: Freedom
------------------------------
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 2579
***************************************