[32878] in Perl-Users-Digest
Perl-Users Digest, Issue: 4156 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Feb 27 14:09:34 2014
Date: Thu, 27 Feb 2014 11:09:08 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Thu, 27 Feb 2014 Volume: 11 Number: 4156
Today's topics:
10 cent fixes (somewhat OT) <john@castleamber.com>
Re: 10 cent fixes (somewhat OT) <rweikusat@mobileactivedefense.com>
Re: additional group <gravitalsun@hotmail.foo>
Re: cookie <gravitalsun@hotmail.foo>
Re: hex print <cwilbur@chromatico.net>
Re: hex print <triflemenot@protocol.invalid>
Re: hex print <hjp-usenet3@hjp.at>
Re: hex print <rweikusat@mobileactivedefense.com>
Re: hex print <cwilbur@chromatico.net>
Re: hex print <cwilbur@chromatico.net>
Re: hex print <triflemenot@protocol.invalid>
Re: last iteration of a for loop <m@rtij.nl.invlalid>
Re: last iteration of a for loop <xhoster@gmail.com>
Re: last iteration of a for loop <johnblack@nospam.com>
Re: last iteration of a for loop <xhoster@gmail.com>
Re: last iteration of a for loop <tzz@lifelogs.com>
Re: last iteration of a for loop <rweikusat@mobileactivedefense.com>
Re: last iteration of a for loop <justin.1401@purestblue.com>
Re: last iteration of a for loop <tzz@lifelogs.com>
Re: last iteration of a for loop <janek_schleicher@yahoo.de>
Re: use strict; use warnings; <m@rtij.nl.invlalid>
Re: use strict; use warnings; <kaz@kylheku.com>
Re: use strict; use warnings; <m@rtij.nl.invlalid>
Re: use strict; use warnings; <rweikusat@mobileactivedefense.com>
Re: use strict; use warnings; <rweikusat@mobileactivedefense.com>
Re: use strict; use warnings; <mach2@hushmail.com>
Re: use strict; use warnings; <mach2@hushmail.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 26 Feb 2014 14:13:08 -0600
From: John Bokma <john@castleamber.com>
Subject: 10 cent fixes (somewhat OT)
Message-Id: <87lhwxy6nf.fsf@castleamber.com>
Quote from email (there was much more along the same line). See also sig
for why he talks about book(s).
Now, in the past I considered purchasing a book from your wishlist and
sending it to you as a thank you, but I realized that it wasn't worth
it. For two reasons: (1) most the books on your list are high
priced--try finding some $5 books that match the $5 fixes I ask you
about (where the shipping isn't going to cost me an arm and a leg on
top of it); (2) the cost of buying it and having it shipped to my
place only to re-ship it to Mexico is a rip off because I'm wasting
twice as much money just to get it to you.
As I said, I have only ever asked you how to fix what was wrong in MY
coding. I never asked you to re-write it or to write the entire thing
for me. If I had you write an entire script for me, then, yes, I would
send you a book or two or three. But asking you to EDIT my code so I
know where I'm going wrong is an entirely different story. I have
certainly not come to you with "unlimited" requests. The above example
demonstrates well the kind of EDITS that I ask about MY code. It's
like a 10 cent fix
I don't know what others come to you about, but if you paid attention
to what I write, my requests are very simple: tell me what I'm doing
wrong. I know the code I am using works, whether theoretically or
practically the way I have written it, and I just asked you to verify
that it should work (e.g., "($ctime)=(split(/\#/,$lines[1],6))[4];
$ctime=&GetLastDatePosted;") and/or to point out what is missing
(e.g., "grep { /\w/ }"). As found out, the reason my $ctime wasn't
working was because of an error in the &GetLastDatePosted; code
itself, using (time) instead of ($tm). If I was asking you to write
everything from scratch, or re-write everything, instead of asking you
to check and verify it for me (since I am not fluent with the
language), then you would have a very valid point about "unlimited
help." If that's a problem, then I won't bother you again. For a 10
cent fix, if you should actually provide that fix, a simple "Thank
you" should suffice.
I've kindly told him not to contact me again, but he might start
contacting other people, so be warned. This is a very ungrateful person
[1].
I have no problem helping people for free on Usenet. But I think it's
fair that if you mail me several times and ask for help that I can ask
something in return instead of the person deciding how much I should be
given.
[1] He suddenly contacted me again, after I had told him at least twice
that something in return would be appreciated. He did hide is name
from me, but from the code it was obvious this is the same person.
--
John Bokma j3b
Blog: http://johnbokma.com/ Perl Consultancy: http://castleamber.com/
Perl for books: http://johnbokma.com/perl/help-in-exchange-for-books.html
------------------------------
Date: Thu, 27 Feb 2014 16:50:50 +0000
From: Rainer Weikusat <rweikusat@mobileactivedefense.com>
Subject: Re: 10 cent fixes (somewhat OT)
Message-Id: <871tyojy8l.fsf@sable.mobileactivedefense.com>
John Bokma <john@castleamber.com> writes:
> Quote from email (there was much more along the same line). See also sig
> for why he talks about book(s).
>
> Now, in the past I considered purchasing a book from your wishlist and
> sending it to you as a thank you, but I realized that it wasn't worth
> it. For two reasons: (1) most the books on your list are high
> priced--try finding some $5 books that match the $5 fixes I ask you
> about
[stuff I'll hopefully not find in my mail]
Debugging code is at least as much work as writing code, more so if
debugging someone else's code and yet more so if "throw the crud away and
re-implement it sanely" is not an option.
> I've kindly told him not to contact me again, but he might start
> contacting other people, so be warned. This is a very ungrateful person
> [1].
"Very ungrateful" is not a term I'd use to describe someone who tries to
bully other people into doing his work because he is too lazy to do
it himself ...
------------------------------
Date: Thu, 27 Feb 2014 02:56:10 +0200
From: George Mpouras <gravitalsun@hotmail.foo>
Subject: Re: additional group
Message-Id: <lem2fa$9f0$1@news.ntua.gr>
> http://search.cpan.org/~bastian/User-getgrouplist-1.1.0/
>
> According to the Linux getgrouplist manpage, this will crash for glibc
> versions prior to 2.3.3. A pure-Perl implementation could look like
> this (side effect: group database will be closed afterwards):
>
> sub groups_of
> {
> my $user = $_[0];
> my (%groups, @grp, @pwd);
>
> @pwd = getpwnam($user) or return ();
>
> @grp = getgrgid($pwd[3]);
> $groups{$grp[0] // $pwd[3]} = 1;
>
> # close group database if open to make getgrent start from the start
> endgrent();
>
> while (@grp = getgrent()) {
> for (split(/ /, $grp[3])) {
> $groups{$grp[0]} = 1, last
> if $_ eq $user;
> }
> }
>
> endgrent();
> return keys(%groups);
> }
>
Based to your code, a small addition that checks if user's password is
ok , and optional if a user belongs to a group
my ($result, $message) = checklogin('someuser', 'somepassword',
'somegroup');
print "$result - $message";
# my ($result, $message) = checklogin( USERNAME, PASSWORD, [OPTIONAL
GROUP THAT THE USER SHOULD BELONG] );
sub checklogin
{
if ( my
($user,$shadowpasswd,$uid,$gid,$quota,$comment,$gcos,$dir,$shell,$expire) =
getpwnam $_[0] )
{
endgrent;
if ( $shadowpasswd eq crypt $_[1], $shadowpasswd )
{
if ( exists $_[2] )
{
if ( $_[2] ne getgrgid $gid )
{
my $ok;
while (my @grp = getgrent)
{
if (($_[2] eq $grp[0]) && ($grp[3]=~/\b$_[0]\b/))
{
$ok=1;
last
}
}
endgrent;
return (0, 'user do not belong to group') unless $ok
}
}
}
else
{
return (0, 'wrong password')
}
}
else
{
return (0, 'user does not exist')
}
1,'ok'
}
------------------------------
Date: Thu, 27 Feb 2014 00:33:19 +0200
From: George Mpouras <gravitalsun@hotmail.foo>
Subject: Re: cookie
Message-Id: <lelq3f$2ik7$1@news.ntua.gr>
> So that's your mistake. Although you have repeatedly written yourself
> that you cannot set the cookie after printing the header and although
> Xho showed you how to delay printing the header until you know what
> should go into it, you still do it in a way which you know cannot work.
> Why?
>
> hp
>
delay printing the header for the very first redirection ? there is no
problem there.
I test xho code (apache at centos 6.5) using firefox as client on
windows 8 box; there was no cookie after the form submission.
So what ? may at his environment worked, but not at mine.
I tired with this thread and I want to get stopped here, ( even more
after his last post )
------------------------------
Date: Wed, 26 Feb 2014 16:08:56 -0500
From: Charlton Wilbur <cwilbur@chromatico.net>
Subject: Re: hex print
Message-Id: <878usxr387.fsf@new.chromatico.net>
>>>>> "T" == Trifle Menot <triflemenot@protocol.invalid> writes:
T> On Tue, 25 Feb 2014 16:29:00 -0500, Charlton Wilbur
T> <cwilbur@chromatico.net> wrote:
>>>>>>> "T" == Trifle Menot <triflemenot@protocol.invalid> writes:
>>
T> To print a string
>> >> my $data = 'abc123';
>>
T> in hex, separated by single spaces
>>
>> >> 61 62 63 31 32 33
>>
T> can it be done without looping?
>>
>> No. Something will need to iterate; the best you can accomplish
>> is making it implicit rather than explicit.
T> I know what assembly language is, so I understand what you
T> mean. But those words may confuse people who only want to learn
T> enough Perl to solve their immediate problem.
A little learning is a dangerous thing;
drink deep, or taste not the Pierian spring.
T> It's not always wise to say everything you know.
And it is inordinately foolish to ask idiotic questions and expect to
not have the idiocy pointed out.
Charlton
--
Charlton Wilbur
cwilbur@chromatico.net
------------------------------
Date: Wed, 26 Feb 2014 22:17:27 +0000
From: Trifle Menot <triflemenot@protocol.invalid>
Subject: Re: hex print
Message-Id: <8opsg996kb2o9klt0a5f7aa85p3hm223rd@4ax.com>
On Wed, 26 Feb 2014 16:08:56 -0500, Charlton Wilbur
<cwilbur@chromatico.net> wrote:
>A little learning is a dangerous thing;
>drink deep, or taste not the Pierian spring.
>
> T> It's not always wise to say everything you know.
>
>And it is inordinately foolish to ask idiotic questions and expect to
>not have the idiocy pointed out.
>
>Charlton
Thanks for the pseudo intellectual advice, Charlton.
------------------------------
Date: Thu, 27 Feb 2014 11:47:41 +0100
From: "Peter J. Holzer" <hjp-usenet3@hjp.at>
Subject: Re: hex print
Message-Id: <slrnlgu5ud.q4f.hjp-usenet3@hrunkner.hjp.at>
On 2014-02-26 21:08, Charlton Wilbur <cwilbur@chromatico.net> wrote:
>>>>>> "T" == Trifle Menot <triflemenot@protocol.invalid> writes:
> T> On Tue, 25 Feb 2014 16:29:00 -0500, Charlton Wilbur
> T> <cwilbur@chromatico.net> wrote:
>
> >>>>>>> "T" == Trifle Menot <triflemenot@protocol.invalid> writes:
> >>
> T> To print a string
> >> >> my $data = 'abc123';
> >>
> T> in hex, separated by single spaces
> >>
> >> >> 61 62 63 31 32 33
> >>
> T> can it be done without looping?
> >>
> >> No. Something will need to iterate; the best you can accomplish
> >> is making it implicit rather than explicit.
>
> T> I know what assembly language is, so I understand what you
> T> mean. But those words may confuse people who only want to learn
> T> enough Perl to solve their immediate problem.
>
> A little learning is a dangerous thing;
> drink deep, or taste not the Pierian spring.
>
> T> It's not always wise to say everything you know.
>
> And it is inordinately foolish to ask idiotic questions and expect to
> not have the idiocy pointed out.
The question wasn't idiotic. It was somewhat academic (Solve problem A
without using obvious feature X), but that's often a good way to learn,
and especially in an interpreted language it is often worthwhile to use
complex builtins instead of explicitely coding a loop (less interpreter
overhead).
It is - well, I'd like to avoid words like "foolish" or "idiotic" here -
not useful to give an answer which is obviously true at some level, but
doesn't match the level of the question. Yes, using perl to run Perl
programs always involves loops. The compiler will loop over the source
text building the byte code[1], the interpreter will loop over the byte
code. Many primitive operations will also involve loops. @a = @b will
loop over both arrays. m/foo.*bar/ will loop over $_ and the pattern.
But at the level of the Perl language these are primitive operations,
not loops.
hp
[1] Is there a more generic term for this? It's not *byte* code after
all.
--
_ | Peter J. Holzer | Fluch der elektronischen Textverarbeitung:
|_|_) | | Man feilt solange an seinen Text um, bis
| | | hjp@hjp.at | die Satzbestandteile des Satzes nicht mehr
__/ | http://www.hjp.at/ | zusammenpaßt. -- Ralph Babel
------------------------------
Date: Thu, 27 Feb 2014 14:47:59 +0000
From: Rainer Weikusat <rweikusat@mobileactivedefense.com>
Subject: Re: hex print
Message-Id: <87d2i8k3xc.fsf@sable.mobileactivedefense.com>
"Peter J. Holzer" <hjp-usenet3@hjp.at> writes:
[...]
> The compiler will loop over the source
> text building the byte code[1], the interpreter will loop over the byte
> code.
[...]
> [1] Is there a more generic term for this? It's not *byte* code after
> all.
I think 'threaded code' would be the appropriate term.
------------------------------
Date: Thu, 27 Feb 2014 11:41:42 -0500
From: Charlton Wilbur <cwilbur@chromatico.net>
Subject: Re: hex print
Message-Id: <87d2i8pkxl.fsf@new.chromatico.net>
>>>>> "T" == Trifle Menot <triflemenot@protocol.invalid> writes:
T> Thanks for the pseudo intellectual advice, Charlton.
Pseudo intellectual is all I expect you're capable of understanding,
O idiot afraid to sign his name to his work.
Charlton
--
Charlton Wilbur
cwilbur@chromatico.net
------------------------------
Date: Thu, 27 Feb 2014 11:46:26 -0500
From: Charlton Wilbur <cwilbur@chromatico.net>
Subject: Re: hex print
Message-Id: <8761o0pkpp.fsf@new.chromatico.net>
>>>>> "PJH" == Peter J Holzer <hjp-usenet3@hjp.at> writes:
PJH> The question wasn't idiotic. It was somewhat academic (Solve
PJH> problem A without using obvious feature X), but that's often a
PJH> good way to learn, and especially in an interpreted language it
PJH> is often worthwhile to use complex builtins instead of
PJH> explicitely coding a loop (less interpreter overhead).
"Here's a list of things. I wish to translate them into another
representation without using a loop."
The question is fatuous on its face. You cannot do it without a loop;
the best thing you can do is to make the loop implicit rather than
explicit. Of course there are loops elsewhere in the code; but more
importantly than that, any solution to the problem will involve a loop
in the algorithm that does the calculation.
Asking an idiotic question under a pseudonym? I have no problem
applying the word "idiotic" and meaning it.
Charlton
--
Charlton Wilbur
cwilbur@chromatico.net
------------------------------
Date: Thu, 27 Feb 2014 18:55:07 +0000
From: Trifle Menot <triflemenot@protocol.invalid>
Subject: Re: hex print
Message-Id: <861vg9hjto2i6hkb6b7rv2sdkrgs2fdr62@4ax.com>
On Thu, 27 Feb 2014 11:47:41 +0100, "Peter J. Holzer"
<hjp-usenet3@hjp.at> wrote:
> It is ... not useful to give an answer which is obviously true at some
> level, but doesn't match the level of the question.
He still doesn't get it, after you spelled it out for him.
Some people just like showing their ass in public. I think that's one
reason why web forums are more popular than usenet. They can keep the
ass clowns under control.
Usenet is more efficient though, if you can ignore the ass clowns.
------------------------------
Date: Wed, 26 Feb 2014 22:20:24 +0100
From: Martijn Lievaart <m@rtij.nl.invlalid>
Subject: Re: last iteration of a for loop
Message-Id: <od22ua-vjp.ln1@news.rtij.nl>
On Wed, 26 Feb 2014 08:00:59 -0800, Jürgen Exner wrote:
> If it is just output you want to combine then maybe you can use the
> join() function:
>
> foreach ($elem in @list){
> push @results, process_item($elem);
> }
> print (join($separator, @results));
I would use:
print join($separator, map(process_item($_), @list);
M4
------------------------------
Date: Wed, 26 Feb 2014 18:13:09 -0800
From: Xho Jingleheimerschmidt <xhoster@gmail.com>
Subject: Re: last iteration of a for loop
Message-Id: <lema06$tjn$2@dont-email.me>
On 02/26/14 06:30, hymie! wrote:
> Greeings.
>
> So I've got a for loop. It's doing some printing, and at the end of
> what it prints, it prints a separator line like
>
> ----------
>
> Is there an easy way that I can tell my loop "don't print the separator
> after the last iteration"?
>
> I know I can say
> print "----------" unless $i==9;
> but I was hoping there might be something more robust or generic, or that
> would work in a more complex loop such as
> foreach $day (sort { daynum($a) <=> daynum($b) } keys %sched)
>
> Alternately, maybe I can print the separator at the **top** of my
> loop, except on the **first** iteration? I can probably do that
> with a flag, but again, I was hoping for something more robust and
> perl-ish.
I don't know of a clean solution, but have often wanted one. An "again"
block similar to the "continue" block, which only gets executed once it
is decided the loop actually will get executed again, would be nice.
(Whether it gets executed on "next" or not is an open question, I would
think not.)
I usually just use the construct
join "whatever", map {} ...
But that is certainly inconvenient when that data doesn't fit in memory
nicely, or should stream smoothly.
Xho
------------------------------
Date: Wed, 26 Feb 2014 21:21:17 -0600
From: John Black <johnblack@nospam.com>
Subject: Re: last iteration of a for loop
Message-Id: <MPG.2d786b286b2997709897ba@news.eternal-september.org>
In article <lema06$tjn$2@dont-email.me>, xhoster@gmail.com says...
> I don't know of a clean solution, but have often wanted one. An "again"
> block similar to the "continue" block, which only gets executed once it
> is decided the loop actually will get executed again, would be nice.
Isn't that what "redo" does?
John Black
------------------------------
Date: Wed, 26 Feb 2014 19:39:52 -0800
From: Xho Jingleheimerschmidt <xhoster@gmail.com>
Subject: Re: last iteration of a for loop
Message-Id: <lemc2r$6pp$1@dont-email.me>
On 02/26/14 19:21, John Black wrote:
> In article <lema06$tjn$2@dont-email.me>, xhoster@gmail.com says...
>> I don't know of a clean solution, but have often wanted one. An "again"
>> block similar to the "continue" block, which only gets executed once it
>> is decided the loop actually will get executed again, would be nice.
>
> Isn't that what "redo" does?
>
Not that I know of. The redo statement repeats the loop without
re-evaluating whether it ought to be repeated, and there is no redo block.
perl -le 'for (1..10) {print $_;} continue {print "-----"}'
a redo statement after the 'print $_;' sends this into an infinite loop,
and a continue statement does not alter the behavior from original.
Xho
------------------------------
Date: Thu, 27 Feb 2014 06:11:35 -0500
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: Re: last iteration of a for loop
Message-Id: <877g8gg68o.fsf@lifelogs.com>
On 26 Feb 2014 14:30:26 GMT hymie@lactose.homelinux.net (hymie!) wrote:
h> So I've got a for loop. It's doing some printing, and at the end of
h> what it prints, it prints a separator line like
h> ----------
h> Is there an easy way that I can tell my loop "don't print the separator
h> after the last iteration"?
Easiest way IMO, and a useful idiom regardless:
#+begin_src perl
#!/usr/bin/perl
use warnings;
use strict;
my @list = sort keys %ENV;
while (my $key = pop @list)
{
print "$key\n";
print "not last\n" if scalar @list;
print "last\n" unless scalar @list;
}
#+end_src
------------------------------
Date: Thu, 27 Feb 2014 14:37:20 +0000
From: Rainer Weikusat <rweikusat@mobileactivedefense.com>
Subject: Re: last iteration of a for loop
Message-Id: <87lhwwk4f3.fsf@sable.mobileactivedefense.com>
John Black <johnblack@nospam.com> writes:
> In article <lema06$tjn$2@dont-email.me>, xhoster@gmail.com says...
>> I don't know of a clean solution, but have often wanted one. An "again"
>> block similar to the "continue" block, which only gets executed once it
>> is decided the loop actually will get executed again, would be nice.
>
> Isn't that what "redo" does?
redo re-executes the loop body without evaluating the condition again.
That's a loop control 'verb' completely unrelated to the sought-after
feature. Perl has a continue-block which is executed after the loop body
and before the condition is evaluated. What would be needed here would
be a block which is executed after the loop body and after evaluating
the condition resulted in the descision to execute the loop body for
another time. This could be simulated in Perl like this:
{
my $repeated;
while (condition()) {
if ($repeated) {
# special block goes here
}
# ordinary loop body
$repeated = 1;
}
}
but this is really a bad implementation because it keeps assigning to
the indiciator variable and keeps retesting its value despite it'll
never change after the first iteration. A good implementation (in this
sense) would be
if (condition()) {
goto body;
do {
# special block
body:
# loop body
} while (condition());
}
but this is really a transformation which should be performed
automatically by a compiler and certainly shouldn't be implemented in
Perl. Since this is a common construct, a "high-level" syntax for
expressing it would be helpful, ie one which neither relies on explicit
gotos to indicate the desired control flow nor on mostly useless code.
------------------------------
Date: Thu, 27 Feb 2014 15:47:02 +0000
From: Justin C <justin.1401@purestblue.com>
Subject: Re: last iteration of a for loop
Message-Id: <m834ua-bfn.ln1@zem.masonsmusic.co.uk>
On 2014-02-27, Ted Zlatanov <tzz@lifelogs.com> wrote:
> print "not last\n" if scalar @list;
> print "last\n" unless scalar @list;
Maybe it's subtle, but I don't see a difference between the
above and the below:
print "not last\n" if @list;
print "last\n" unless @list;
Justin.
--
Justin C, by the sea.
------------------------------
Date: Thu, 27 Feb 2014 12:31:08 -0500
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: Re: last iteration of a for loop
Message-Id: <87y50wcvj7.fsf@lifelogs.com>
On Thu, 27 Feb 2014 15:47:02 +0000 Justin C <justin.1401@purestblue.com> wrote:
JC> On 2014-02-27, Ted Zlatanov <tzz@lifelogs.com> wrote:
>> print "not last\n" if scalar @list;
>> print "last\n" unless scalar @list;
JC> Maybe it's subtle, but I don't see a difference between the
JC> above and the below:
JC> print "not last\n" if @list;
JC> print "last\n" unless @list;
The scalar context is applied automatically, so there is no difference
here.
Having been bitten by this in the past (non-scalar context applied when
I wanted scalar), I prefer to always be explicit. Similarly, I use
"shift @_" and "shift @ARGV" explicitly in most situations. Both of
these are probably too cautious for typical Perl usage today.
Ted
------------------------------
Date: Thu, 27 Feb 2014 19:35:21 +0100
From: Janek Schleicher <janek_schleicher@yahoo.de>
Subject: Re: last iteration of a for loop
Message-Id: <bn9erjFf29cU1@mid.individual.net>
Am 27.02.2014 18:31, schrieb Ted Zlatanov:
> On Thu, 27 Feb 2014 15:47:02 +0000 Justin C <justin.1401@purestblue.com> wrote:
>
> JC> On 2014-02-27, Ted Zlatanov <tzz@lifelogs.com> wrote:
>>> print "not last\n" if scalar @list;
>>> print "last\n" unless scalar @list;
>
> JC> Maybe it's subtle, but I don't see a difference between the
> JC> above and the below:
>
> JC> print "not last\n" if @list;
> JC> print "last\n" unless @list;
>
> The scalar context is applied automatically, so there is no difference
> here.
>
> Having been bitten by this in the past (non-scalar context applied when
> I wanted scalar), I prefer to always be explicit. Similarly, I use
> "shift @_" and "shift @ARGV" explicitly in most situations. Both of
> these are probably too cautious for typical Perl usage today.
Of course, that's both personal style.
I agree to you, that you try to avoid unclear spots,
but there aren't anyone in boolean context.
For me, if there is a scalar ... line in source code, I always think
a) that is important
b) it can't be solved otherwise
c) something is wrong with our design, as we don't use the objects
naturally.
Greetings,
Janek
------------------------------
Date: Wed, 26 Feb 2014 22:29:07 +0100
From: Martijn Lievaart <m@rtij.nl.invlalid>
Subject: Re: use strict; use warnings;
Message-Id: <3u22ua-vjp.ln1@news.rtij.nl>
On Tue, 25 Feb 2014 22:15:23 +0000, Kaz Kylheku wrote:
> On 2014-02-25, Rainer Weikusat <rweikusat@mobileactivedefense.com>
> wrote:
>> years are being counted: The number for each new years is 'number of
>> years we have seen so far + 1'. There was never a year with 'number 0'
>> because 0 was the state 'no years seen so far'. This basic model works
>> the same of any (ordered) sequence of things.
>
> Even within measurement of time, not everything is idiotically
> one-based,
> luckily. The time after 23:59 is 00:00 (though twelve-hour time hides
> zero by calling it twelve). The first minute of every hour is 00, with
> seconds that go from 0 to 59.
Except when there is a leap second... :-)
M4
-- Date and time stuff is *hard* to get right. Don't try, use a CPAN
module --
------------------------------
Date: Thu, 27 Feb 2014 00:07:34 +0000 (UTC)
From: Kaz Kylheku <kaz@kylheku.com>
Subject: Re: use strict; use warnings;
Message-Id: <20140226160150.252@kylheku.com>
On 2014-02-26, Rainer Weikusat <rweikusat@mobileactivedefense.com> wrote:
> Loosely related: There isn't really a 'minute 0' on the clock, that's
> minute sixty of the past hour, after which the 'minute counter' wraps
> around to zero because the arithmetic is performed in the mod 60
> remainder ring.
LOL-inducting bull poo poo!
Every digital clock shows hh:00 for a full minute at the top of the hour. That
is "minute zero" (the first minute), loud and clear.
This is not a minute belonging to the past hour. The past hour's last minute
is "minute 59" (its sixtieth minute).
------------------------------
Date: Thu, 27 Feb 2014 09:10:45 +0100
From: Martijn Lievaart <m@rtij.nl.invlalid>
Subject: Re: use strict; use warnings;
Message-Id: <5h83ua-6lb.ln1@news.rtij.nl>
On Mon, 24 Feb 2014 11:50:32 -0600, Marek Novotny wrote:
> On Mon, 24 Feb 2014 12:45:34 +0100, Janek Schleicher wrote:
>
>>
>> PS: You problably don't know yet what this qw/../ operator means,
>> here it's just a short cut for qw/H D C S/ is the same as ("H", "D",
>> "C", "S").
>
> That they did cover. For whatever reason I like @array = qw( elem1 elem2
> ...) but I see everyone here has adopted qw/elem1 elem2/. I could easily
> adapt to this instead. For whatever reason the first is easier for to
> remember and think of.
qw/.../ is idiomatic, but it is not a very strong idiom afaik. Use
whatever you like best.
With qq/.../, m/.../, s/.../.../ etc sometimes choosing a different
character may be helpful, f.i. compare
s/\/.*\/([^\/])+\/.*/$1/;
with
s!/.*/([^/])+/.*!$1!;
Look up "leaning toothstick syndrome".
HTH,
M4
------------------------------
Date: Thu, 27 Feb 2014 14:46:39 +0000
From: Rainer Weikusat <rweikusat@mobileactivedefense.com>
Subject: Re: use strict; use warnings;
Message-Id: <87ha7kk3zk.fsf@sable.mobileactivedefense.com>
Martijn Lievaart <m@rtij.nl.invlalid> writes:
> On Mon, 24 Feb 2014 11:50:32 -0600, Marek Novotny wrote:
>> On Mon, 24 Feb 2014 12:45:34 +0100, Janek Schleicher wrote:
>>> PS: You problably don't know yet what this qw/../ operator means,
>>> here it's just a short cut for qw/H D C S/ is the same as ("H", "D",
>>> "C", "S").
>>
>> That they did cover. For whatever reason I like @array = qw( elem1 elem2
>> ...) but I see everyone here has adopted qw/elem1 elem2/. I could easily
>> adapt to this instead. For whatever reason the first is easier for to
>> remember and think of.
>
> qw/.../ is idiomatic, but it is not a very strong idiom afaik. Use
> whatever you like best.
>
> With qq/.../, m/.../, s/.../.../ etc sometimes choosing a different
> character may be helpful, f.i. compare
>
> s/\/.*\/([^\/])+\/.*/$1/;
>
> with
>
> s!/.*/([^/])+/.*!$1!;
>
> Look up "leaning toothstick syndrome".
s/stick/pick
Other considerations: This feature is specific to Perl. OTOH, the
/-using syntax is used by other tools to, meaning, one has to be able to
read and write it, anyway. Also, no particular 'separation character'
is universally useful without quoting. 'Hand-optimizing'
regex-constructs in order to avoid occasional quoting can be considered
a waste of time. Lastly, individualized seperators introduce noise into
source code (in the sense that the set of 'special characters' is
potentially larger and its members aren't known until all of the code
has been read).
------------------------------
Date: Thu, 27 Feb 2014 14:51:06 +0000
From: Rainer Weikusat <rweikusat@mobileactivedefense.com>
Subject: Re: use strict; use warnings;
Message-Id: <878uswk3s5.fsf@sable.mobileactivedefense.com>
Kaz Kylheku <kaz@kylheku.com> writes:
> On 2014-02-26, Rainer Weikusat <rweikusat@mobileactivedefense.com> wrote:
>> Loosely related: There isn't really a 'minute 0' on the clock, that's
>> minute sixty of the past hour, after which the 'minute counter' wraps
>> around to zero because the arithmetic is performed in the mod 60
>> remainder ring.
>
> LOL-inducting bull poo poo!
>
> Every digital clock shows hh:00 for a full minute at the top of the hour. That
> is "minute zero" (the first minute), loud and clear.
>
> This is not a minute belonging to the past hour. The past hour's last minute
> is "minute 59" (its sixtieth minute).
http://en.wikipedia.org/wiki/Begging_the_question
------------------------------
Date: Thu, 27 Feb 2014 10:47:06 -0600
From: Marek Novotny <mach2@hushmail.com>
Subject: Re: use strict; use warnings;
Message-Id: <R8adnWPL5N2X8ZLOnZ2dnUVZ_rqdnZ2d@supernews.com>
On Thu, 27 Feb 2014 09:10:45 +0100, Martijn Lievaart wrote:
> On Mon, 24 Feb 2014 11:50:32 -0600, Marek Novotny wrote:
>
>> On Mon, 24 Feb 2014 12:45:34 +0100, Janek Schleicher wrote:
>>
>>
>>> PS: You problably don't know yet what this qw/../ operator means, here
>>> it's just a short cut for qw/H D C S/ is the same as ("H", "D",
>>> "C", "S").
>>
>> That they did cover. For whatever reason I like @array = qw( elem1
>> elem2 ...) but I see everyone here has adopted qw/elem1 elem2/. I could
>> easily adapt to this instead. For whatever reason the first is easier
>> for to remember and think of.
>
> qw/.../ is idiomatic, but it is not a very strong idiom afaik. Use
> whatever you like best.
>
> With qq/.../, m/.../, s/.../.../ etc sometimes choosing a different
> character may be helpful, f.i. compare
>
> s/\/.*\/([^\/])+\/.*/$1/;
>
> with
>
> s!/.*/([^/])+/.*!$1!;
>
> Look up "leaning toothstick syndrome".
>
> HTH,
> M4
I'll do that. Looks like I'm not out of the woods either. They just asked
asked for further add-ons in my most recent lesson and I looked a little
forward to functions and they ask for additions twice more. Looks like
shuffling will need a rework soon. This is an overview Perl kind of
course so they are skipping through things quickly without much depth.
When I take the dedicated Perl course this will be more in depth. I'm
more than nervous thinking about the addons they are asking for. Should
get to it today or tomorrow.
:)
--
Marek Novotny
A member of the Linux Foundation
http://www.linuxfoundation.org
------------------------------
Date: Thu, 27 Feb 2014 10:56:35 -0600
From: Marek Novotny <mach2@hushmail.com>
Subject: Re: use strict; use warnings;
Message-Id: <R8adnWLL5N3e85LOnZ2dnUVZ_rqdnZ2d@supernews.com>
On Thu, 27 Feb 2014 14:46:39 +0000, Rainer Weikusat wrote:
> Martijn Lievaart <m@rtij.nl.invlalid> writes:
>> On Mon, 24 Feb 2014 11:50:32 -0600, Marek Novotny wrote:
>>> On Mon, 24 Feb 2014 12:45:34 +0100, Janek Schleicher wrote:
>>>> PS: You problably don't know yet what this qw/../ operator means,
>>>> here it's just a short cut for qw/H D C S/ is the same as ("H", "D",
>>>> "C", "S").
>>>
>>> That they did cover. For whatever reason I like @array = qw( elem1
>>> elem2 ...) but I see everyone here has adopted qw/elem1 elem2/. I
>>> could easily adapt to this instead. For whatever reason the first is
>>> easier for to remember and think of.
>>
>> qw/.../ is idiomatic, but it is not a very strong idiom afaik. Use
>> whatever you like best.
>>
>> With qq/.../, m/.../, s/.../.../ etc sometimes choosing a different
>> character may be helpful, f.i. compare
>>
>> s/\/.*\/([^\/])+\/.*/$1/;
>>
>> with
>>
>> s!/.*/([^/])+/.*!$1!;
>>
>> Look up "leaning toothstick syndrome".
>
> s/stick/pick
>
> Other considerations: This feature is specific to Perl. OTOH, the
> /-using syntax is used by other tools to, meaning, one has to be able to
> read and write it, anyway. Also, no particular 'separation character' is
> universally useful without quoting. 'Hand-optimizing' regex-constructs
> in order to avoid occasional quoting can be considered a waste of time.
> Lastly, individualized seperators introduce noise into source code (in
> the sense that the set of 'special characters' is potentially larger and
> its members aren't known until all of the code has been read).
Just went through a crash course in regex. Ouch that was painful. Dying
to get to the full course. This is all too quick for me.
Had to modify the card deck...
#!/usr/bin/perl
# file: obj12.pl
#
# In Lesson 10's Project 1, you wrote a script to shuffle a fake deck
# of cards. Copy that script to obj12.pl then make the following
additions:
#
# Create a loop that prints out the top five cards using regular
# expressions to switch the card suit letter with the full name.
# (For example, H would become Hearts).
use strict;
use warnings;
my @startingdeck = ("A H","2 H","3 H","4 H","5 H","6 H","7 H","8 H",
"9 H","10 H","J H","Q H","K H",
"A D","2 D","3 D","4 D","5 D","6 D","7 D","8 D",
"9 D","10 D","J D","Q D","K D",
"A C","2 C","3 C","4 C","5 C","6 C","7 C","8 C",
"9 C","10 C","J C","Q C","K C",
"A S","2 S","3 S","4 S","5 S","6 S","7 S","8 S",
"9 S","10 S","J S","Q S","K S");
my $i = 0; my @randomdeck;
while ($i < 51){
$randomdeck[$i] = shift(@startingdeck); $i++;
$randomdeck[$i] = pop(@startingdeck); $i++;
}
# obtain top 5 cards and search / replace abbreviations
$i = 0; my @array;
while ($i < 5){
$array[$i] = shift(@randomdeck);
$array[$i] =~ s/H/Hearts/;
$array[$i] =~ s/D/Diamonds/;
$array[$i] =~ s/C/Clubs/;
$array[$i] =~ s/S/Spades/;
$i++;
}
print "My top five cards are: @array.\n";
And did some quick and dirty regex
#!/usr/bin/perl
# ip.pl
#
use strict;
use warnings;
my $ip;
while (<STDIN>){
if (/(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})/){
$ip = $1;
print "I caught $ip\n";
}
}
:)
--
Marek Novotny
A member of the Linux Foundation
http://www.linuxfoundation.org
------------------------------
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:
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
Back issues are available via anonymous ftp from
ftp://cil-www.oce.orst.edu/pub/perl/old-digests.
#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 4156
***************************************