[29008] in Perl-Users-Digest
Perl-Users Digest, Issue: 252 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Mar 22 09:09:59 2007
Date: Thu, 22 Mar 2007 06:09:08 -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 Thu, 22 Mar 2007 Volume: 11 Number: 252
Today's topics:
Re: A twist on Cookbook recipe 4.6 <perl4hire@softouch.on.ca>
Re: A twist on Cookbook recipe 4.6 <perl4hire@softouch.on.ca>
Re: any easy way to print a few tables in the same rows <scobloke2@infotop.co.uk>
Re: FAQ 8.4 How do I print something out in color? <bik.mido@tiscalinet.it>
Re: getting DBI and ODBC to work with PERL and MYSQL da <mritty@gmail.com>
Re: I dotn understand this error <bik.mido@tiscalinet.it>
newpage problem with PostScript::Simple <"v.niekerk at hccnet.nl">
non-greedy match breaks '?' match? <ahuxley@gmx.net>
Re: non-greedy match breaks '?' match? <wahab-mail@gmx.de>
Re: non-greedy match breaks '?' match? <ahuxley@gmx.net>
Re: non-greedy match breaks '?' match? <wahab-mail@gmx.de>
Re: non-greedy match breaks '?' match? <ahuxley@gmx.net>
Re: non-greedy match breaks '?' match? <wahab-mail@gmx.de>
Re: non-greedy match breaks '?' match? <mritty@gmail.com>
Re: non-greedy match breaks '?' match? (hymie!)
Re: non-greedy match breaks '?' match? <ahuxley@gmx.net>
Re: On Java's Interface (the meaning of interface in co <jimburton1@gmail.com>
Re: On Java's Interface (the meaning of interface in co <lew@nospam.lewscanon.com>
Re: On Java's Interface (the meaning of interface in co <lew@nospam.lewscanon.com>
Re: On Java's Interface (the meaning of interface in co <spamtrap@dot-app.org>
Re: On Java's Interface (the meaning of interface in co <development-2006-8ecbb5cc8aREMOVETHIS@ANDTHATm-e-leypold.de>
Re: perl feature request anno4000@radom.zrz.tu-berlin.de
problem using timelocal, localtime to discern d-o-w. <jfcampbell@aol.com>
Re: Stuck trying to pass an array that contains a hash <bik.mido@tiscalinet.it>
Re: Using @ARGV in object oriented script <bik.mido@tiscalinet.it>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Thu, 22 Mar 2007 07:51:50 -0400
From: Amer Neely <perl4hire@softouch.on.ca>
Subject: Re: A twist on Cookbook recipe 4.6
Message-Id: <m3uMh.9835$Sm.3751@read1.cgocable.net>
Ben Morrow wrote:
> Quoth Amer Neely <perl4hire@softouch.on.ca>:
>> I'm trying to get a count of those [duplicated] emails ALONG with
>> their respective IDs.
>>
>> My attempts so far:
>>
>> #! /usr/bin/perl
>> use strict;
>> use warnings;
>>
>> my ($ID,$Email);
>
> Don't declare variables before you need them. These should go inside the
> loop.
>
>> my %SeenEmails=();
>>
>> open IN,"<",$InFile or die "Can't open $InFile: $!\n";
>
> I would suggest
>
> open my $IN, ...
>
> instead. Global filehandles are as bad as any other global variable.
>
>> foreach my $line (<IN>)
>
> This will work, but is a terrible waste of time. <FH> in list context
> returns a list of lines, so you are reading in the file, splitting that
> into lines, and then going through them one at a time. If you want to go
> through one at a time, use while instead:
>
> while (my $line = <IN>) {
>
>> {
>> ($ID,$Email) = ((split /\|/, $line)[0,10]);
>> $SeenEmails{$Email}++;
>
> Here you want to store a list of the IDs, instead of just incrementing.
> Something like
>
> $SeenEmails{$Email} ||= [];
> push @{ $SeenEmails{$Email} }, $ID;
>
> which could be shortend to
>
> push @{ $SeenEmails{$Email} ||= [] }, $ID;
>
> once you're comfortable with the syntax.
>
> If you don't understand refs (the [] and @{...} stuff) read perldoc
> perlreftut.
>
>> }
>> close IN or die "Can't close $InFile: $!\n";;
>>
>> for (sort keys %SeenEmails)
>> {
>> if ($SeenEmails{$_} > 1)
>
> my $seen = $SeenEmails{$_};
>
> if (@$seen > 1) {
>
> I don't really understand what you want to generate from this, but
> perhaps you want something like
>
> print "$_ -> " . scalar(@$seen) . "\n";
>
> for my $id (@$seen) {
> print "\tdupe${id}_$_\n";
> }
>
> That print string is quite complicated; it can be split into
>
> "\t" . 'dupe' . $id . '_' . $_ . "\n"
>
> . A decent highlighting editor will help, of course.
>
> FWIW, while I often use $_ as an implicit 'for' loop variable, I only
> use it on the *innermost* loop. I find that once a loop gets large
> enough to have sub-loops of its own, it probably deserves a real
> variable; and having a $_ around that isn't 'the current item' is
> unhelpful and confusing :).
>
>> {
>> print "$_ -> $SeenEmails{$_}\n";
>> for my $i (1..($SeenEmails{$_}-1))
>> {
>> my $thisone=$_;
>> $thisone = 'dupe' . $i . '_' . $_;
>> print "\t$thisone\n";
>> }
>> }
>> }
>
> Ben
Ben, thanks for the advice and direction. I can see I need to get a good
handle on references.
--
Amer Neely
w: www.softouch.on.ca/
------------------------------
Date: Thu, 22 Mar 2007 07:58:26 -0400
From: Amer Neely <perl4hire@softouch.on.ca>
Subject: Re: A twist on Cookbook recipe 4.6
Message-Id: <y9uMh.9836$Sm.374@read1.cgocable.net>
John W. Krahn wrote:
> Ben Morrow wrote:
>> Quoth Amer Neely <perl4hire@softouch.on.ca>:
>>> {
>>> ($ID,$Email) = ((split /\|/, $line)[0,10]);
>>> $SeenEmails{$Email}++;
>> Here you want to store a list of the IDs, instead of just incrementing.
>> Something like
>>
>> $SeenEmails{$Email} ||= [];
>> push @{ $SeenEmails{$Email} }, $ID;
>>
>> which could be shortend to
>>
>> push @{ $SeenEmails{$Email} ||= [] }, $ID;
>
> All you really need is:
>
> push @{ $SeenEmails{ $Email } }, $ID;
>
>
> (Lookup autovivification in the docs.)
>
>
>
> John
Thank you for the alternative John, I'll do more reading :)
--
Amer Neely
w: www.softouch.on.ca/
------------------------------
Date: Thu, 22 Mar 2007 09:34:17 +0000
From: Ian Wilson <scobloke2@infotop.co.uk>
Subject: Re: any easy way to print a few tables in the same rows?
Message-Id: <46024d9b$0$22122$db0fefd9@news.zen.co.uk>
robertchen117@gmail.com wrote:
> all my tables maybe just two columns, I used this:
>
> my $cgi = new CGI;
>
> print $cgi->th("OS Type");
> print $cgi->th("Version");
>
> ...
> A lot of tables printed like the same way above.
>
> Using the CGI default th, td methods will output tables just all way
> through down the page...
>
> any easy way to print a few tables in the same rows?
>
This is really an HTML question not a Perl question.
I'd use float:left in the CSS and maybe enclose them in div tags if
necessary.
------------------------------
Date: Thu, 22 Mar 2007 13:46:25 +0100
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: FAQ 8.4 How do I print something out in color?
Message-Id: <oiu40395vhg6po232i8bcv02bp75gl6goa@4ax.com>
On 21 Mar 2007 15:18:16 -0700, joepeck02@gmail.com wrote:
>> comp.lang.perl.misc only since yesterday. As for the perl docs I
>> have have very limited experience with them since my previous
>> linux installation did not carry them (gasp) and I only recently
>> committed myself to giving perl a serious chance.
Oh, that bad habit of splitting a package into a "regular" one and a
"docs" one. I can't stand it. Well, certainly for Perl it doesn't make
much sense. For something else, it may. But not compellingly except in
some corner case, I suppose.
Michele
--
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
.'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
------------------------------
Date: 22 Mar 2007 05:28:26 -0700
From: "Paul Lalli" <mritty@gmail.com>
Subject: Re: getting DBI and ODBC to work with PERL and MYSQL data source
Message-Id: <1174566506.520721.83560@y66g2000hsf.googlegroups.com>
On Mar 22, 12:07 am, "Jack" <jack_posem...@yahoo.com> wrote:
> Hi folks,
>
> On windows server 2003 I installed the Mysql ODBC driver, created a
> dsn, and installed DBI and DBD::ODBC perl modules. Does anyone have
> experience issuing a SQL query through PERL to Mysql.. here is my
> program, the uncommented pieces worked great but when I remove the
> comments for the bottom 2 rows I get the error indicated:
>
> use DBD::ODBC;
> use strict;
> use diagnostics;
> use DBI;
> eval {
> my $dbh = DBI->connect('DBI:ODBC:mysqldsn;host=localhost;', 'root',
> 's1ghtspr1ng7281',
> { 'RaiseError' => 1, 'PrintError' => 0, 'AutoCommit' => 0} );
> }; # eval
> # $sth = $dbh->prepare("SELECT testcol1 FROM temptable");
> # $sth->execute( $baz );
>
> ERROR:
> E:\tmp>perl odbc_test2.pl
> Global symbol "$sth" requires explicit package name at odbc_test2.pl
> line 14.
This has nothing to do with DBI, MySQL, or anything similar. You
declared a lexical variable in a block (the eval {}) and then tried to
use it outside the block. You can't do that.
Why is that in the eval to begin with? The point of eval is to catch
fatal errors. So if the DBI->connect() call fails, you don't let Perl
exit, but then you continue on with the program like nothing's wrong.
Here are your options:
1) Get rid of the eval altogether.
1a) If you don't want the DBI->connect() failure to terminate the
program, simply set RaiseError to 0 instead of 1.
2) Move the declaration of $dbh outside the eval. So it would be
something like:
my $dbh;
eval {
$dbh = DBI->connect(...);
};
Paul Lalli
------------------------------
Date: Thu, 22 Mar 2007 13:51:25 +0100
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: I dotn understand this error
Message-Id: <9mu4031lv1rv4umgngamq400g70knemeut@4ax.com>
On 21 Mar 2007 15:08:54 -0700, "?????" <hackeras@gmail.com> wrote:
>> Where is it?
>
>Well when i try to copy/paste i get an error message that i cannot
>copy/paste binary files.
Hmmm, there must be something that makes it think it's binary. What
does Perl's -B() say, BTW?
In doubt, if you're under *NIX, you can use cat -A. If not, then still
(a port of) cat or some simple Perl script.
perl -lpe "s/[^[:print:]]//g"
for example, will remove all non printable charachters and may be a
good start.
>Iam using googles groups to talk here... how am i supposed to paste
>the code now?!
Feeling sorry for you. I *had* to use GG sporadically and it was a
major PITA...
Michele
--
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
.'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
------------------------------
Date: Thu, 22 Mar 2007 11:05:45 +0100
From: Huub <"v.niekerk at hccnet.nl">
Subject: newpage problem with PostScript::Simple
Message-Id: <460254f9$0$17627$e4fe514c@dreader26.news.xs4all.nl>
Hi,
I've written a script to read from MySQL and print to a .ps file. All
works very well for the first page. If the contents exceeds the first
page, a new page should be created and the printing should go on. The
latter doesn't happen: a new page is created but nothing is printed on it.
When I use eps=1, no newpage is created and the remaining contents is
printed on top of the page over the existing contents.
When I use eps=0, a newpage is created, but without the remaining
contents which just seem to disappear.
Creating of the document including 1 page:
my $ps = new PostScript::Simple(papersize => "A4",
colour => 0,
eps => 0,
units => "mm");
$ps->newpage;
$ps->setfont("Arial", 10);
New page is needed:
<snip>
if ($ps_line < 27)
{
$ps->newpage;
$ps_line = 280;
}
}
I suppose I do something wrong, and I read "perldoc PostScript::Simple"
but I still don't know. Thanks for helping.
Huub
------------------------------
Date: 22 Mar 2007 09:45:08 GMT
From: Alexis Huxley <ahuxley@gmx.net>
Subject: non-greedy match breaks '?' match?
Message-Id: <slrnf04k13.n3j.ahuxley@dione.no-ip.org>
The following code:
$x = "abc";
$x =~ /^(a)(b)(c?)/;
print "\$1=$1, \$2=$2, \$3=$3\n";
outputs this:
$1=a, $2=b, $3=c
which is just what I expect.
But with only the second line changed to:
$x =~ /^(a)(.*?)(c?)/;
Now the output changes to:
$1=a, $2=, $3=
Can some kind soul please explain to me why the 'c' is
no longer eaten by 'c?'. The only explanation I can
find is that the non-greediness of one part of the RE
(the '.*?') has a higher priority than the greediness of
another part of the RE (the 'c?' is no longer greedy).
What I'm tring to say is "extract 'a' and, if it is there,
then also extract 'c'".
I realise I can to this in a couple of steps ("try to
match one 'c', and if that fails then try to match
zero 'c's"), but there must be a more elegant way to
do that.
Many thanks!
Alexis
------------------------------
Date: Thu, 22 Mar 2007 10:57:58 +0100
From: Mirco Wahab <wahab-mail@gmx.de>
Subject: Re: non-greedy match breaks '?' match?
Message-Id: <ettk46$qiv$1@mlucom4.urz.uni-halle.de>
Alexis Huxley wrote:
> The following code:
> $x = "abc";
> $x =~ /^(a)(b)(c?)/;
> print "\$1=$1, \$2=$2, \$3=$3\n";
> outputs this:
> $1=a, $2=b, $3=c
>
> But with only the second line changed to:
> $x =~ /^(a)(.*?)(c?)/;
> Now the output changes to:
> $1=a, $2=, $3=
>
> Can some kind soul please explain to me why the 'c' is
> no longer eaten by 'c?'. The only explanation I can
> find is that the non-greediness of one part of the RE
> (the '.*?') has a higher priority than the greediness of
> another part of the RE (the 'c?' is no longer greedy).
The '?' in .* relates to the element of what follows, the: 'c?'
Because 'c?' has zero size on match, that propagates back
to the '.*?' which means now 0 or more chars *until nothing*,
which is nothing.
> What I'm tring to say is "extract 'a' and, if it is there,
> then also extract 'c'".
>
$x = "abc";
$x =~ /^(a)(?:b?)(c?)/;
Regards
M.
------------------------------
Date: 22 Mar 2007 10:24:23 GMT
From: Alexis Huxley <ahuxley@gmx.net>
Subject: Re: non-greedy match breaks '?' match?
Message-Id: <slrnf04man.o0a.ahuxley@dione.no-ip.org>
>> $x =~ /^(a)(.*?)(c?)/;
>
> The '?' in .* relates to the element of what follows, the: 'c?'
Err ... You don't mean that the '?' in '.*?' is applied to the
thing *after* that '?', right? No, no, you can't mean that :-)
Can you try to explain that again please :-) Thanks!
Alexis
------------------------------
Date: Thu, 22 Mar 2007 11:58:54 +0100
From: Mirco Wahab <wahab-mail@gmx.de>
Subject: Re: non-greedy match breaks '?' match?
Message-Id: <ettnmd$rjl$1@mlucom4.urz.uni-halle.de>
Alexis Huxley wrote:
>> The '?' in .* relates to the element of what follows, the: 'c?'
>
> Err ... You don't mean that the '?' in '.*?' is applied to the
> thing *after* that '?', right? No, no, you can't mean that :-)
Why not? The '?' is the "regex stop codon", it stops on the
expression after its position, which is - another nongreedy
thing (zero length gives a match! This makes it stop).
(this is what I know about the stuff ;-)
Regards
M.
------------------------------
Date: 22 Mar 2007 11:17:07 GMT
From: Alexis Huxley <ahuxley@gmx.net>
Subject: Re: non-greedy match breaks '?' match?
Message-Id: <slrnf04pdj.pl8.ahuxley@dione.no-ip.org>
>>>> $x =~ /^(a)(.*?)(c?)/;
> Why not? The '?' is the "regex stop codon", it stops on the
> expression after its position, which is - another nongreedy
> thing (zero length gives a match! This makes it stop).
Can you give me a pointer to some perl*(1) man page explaining
this, 'cos what I found, and what I intended by the '?' in '.*?'
was what it says in perlre(1):
By default, a quantified subpattern is "greedy", that is,
it will match as many times as possible (given a particular
starting location) while still allowing the rest of the pattern
to match. If you want it to match the minimum number of times
possible, follow the quantifier with a "?". Note that the
meanings don't change, just the "greediness":
*? Match 0 or more times
+? Match 1 or more times
?? Match 0 or 1 time
{n}? Match exactly n times
{n,}? Match at least n times
{n,m}? Match at least n but not more than m times
I.e. '.*' means "match as much as possible while still ensuring
that if a match of the entire RE is possible than a match of
the rest of the RE remains possible" and '.*?' means "match as
little as possible while still ensuring that if a match of
the entire RE is possible then a match of the rest of the
RE remains possible."
Have I misunderstood something? Quite possible ;-)
According to my reading of what I had written:
$x =~ /^(a)(.*?)(c?)/;
- and what I had intended it to do - is:
match an 'a' at the beginning of the line then match
a minimum amount of unspecified stuff followed by
zero or one 'c's - preferrably one (because of the
greed of the '?' in 'c?')
Clearly here I have misunderstood something here because otherwise
that would work.
I should also clarify that 'a', 'b' and 'c' are not necessary
simgle characters. So although your suggestion of:
>> $x =~ /^(a)(?:b?)(c?)/;
works, when I replace your 'b?' with '.*?' I'm back to my RE
and it not working as intended.
Alexis
------------------------------
Date: Thu, 22 Mar 2007 12:40:52 +0100
From: Mirco Wahab <wahab-mail@gmx.de>
Subject: Re: non-greedy match breaks '?' match?
Message-Id: <ettqah$sah$1@mlucom4.urz.uni-halle.de>
Alexis Huxley wrote:
> Can you give me a pointer to some perl*(1) man page explaining
> this, 'cos what I found, and what I intended by the '?' in '.*?'
> was what it says in perlre(1):
>[perlre]
Maybe the regex has to decide in advance (and doesn't do
what you expect) what the following item 'might' match
if you use non-greedy.
...
>>> $x =~ /^(a)(?:b?)(c?)/;
>
> works, when I replace your 'b?' with '.*?' I'm back to my RE
> and it not working as intended.
Oh, I see, then you may modify it to:
$x = "aadddddddcc";
$x =~ /^(aa)[^c]*(c?)/;
print "\$1=$1, \$2=$2\n";
Because the c? may have zero length, the
sequence between aa and c cannot be non-greedy.
Hmmm ...
Regards
M.
------------------------------
Date: 22 Mar 2007 05:23:04 -0700
From: "Paul Lalli" <mritty@gmail.com>
Subject: Re: non-greedy match breaks '?' match?
Message-Id: <1174566184.601846.7430@d57g2000hsg.googlegroups.com>
On Mar 22, 5:45 am, Alexis Huxley <ahux...@gmx.net> wrote:
> The following code:
>
> $x = "abc";
> $x =~ /^(a)(b)(c?)/;
> print "\$1=$1, \$2=$2, \$3=$3\n";
>
> outputs this:
>
> $1=a, $2=b, $3=c
>
> which is just what I expect.
>
> But with only the second line changed to:
>
> $x =~ /^(a)(.*?)(c?)/;
>
> Now the output changes to:
>
> $1=a, $2=, $3=
>
> Can some kind soul please explain to me why the 'c' is
> no longer eaten by 'c?'.
Match along with Perl.
Step 1: Start of string. Check.
Step 2: a. Check.
Step 3: 0 or more of any character, try to match as little as
possible. Therefore, match 0 characters. Check.
-- AT THIS POINT, Perl has not advanced past the 'b'. It is still
staring at the position between a and b, because it successfully
matched 0 characters there.
Step 4: 0 or 1 'c', preferring to match 1 (because it's greedy).
Fail. There is no c there.
Step 4b: 0 or 1 'c', falling back to match 0. Check.
End result - preferring to match 0 of any character at the 'b'
position does not advance the internal pointer, and therefore allows
c? to match 0 c's at that position.
You can take a look at how Perl sees this expression by including
use re 'debug'; in your script:
> The only explanation I can
> find is that the non-greediness of one part of the RE
> (the '.*?') has a higher priority than the greediness of
> another part of the RE (the 'c?' is no longer greedy).
Not quite. It's the left-to-right'ness of pattern matching that has a
higher precedence than greediness. Perl is never going to advance the
position pointer just so that a later qualifier can match as much as
possible.
Paul Lalli
------------------------------
Date: Thu, 22 Mar 2007 07:34:37 -0500
From: hymie_@_lactose.homelinux.net (hymie!)
Subject: Re: non-greedy match breaks '?' match?
Message-Id: <nsqdnR7eaLNA6p_bnZ2dnUVZ_tSunZ2d@comcast.com>
I don't know enough perl to solve your problem, but I believe I can
help end your confusion...
In our last episode, the evil Dr. Lacto had captured our hero,
Alexis Huxley <ahuxley@gmx.net>, who said:
> $x =~ /^(a)(.*?)(c?)/;
What this means is:
match a line beginning with the letter 'a', followed by a string of
characters as small as possible, which may or may not be followed by a 'c'.
The string
a
matches this request.
>- and what I had intended it to do - is:
>
> match an 'a' at the beginning of the line then match
> a minimum amount of unspecified stuff followed by
> zero or one 'c's - preferrably one (because of the
> greed of the '?' in 'c?')
The string
a
*still* matches this request.
Perhaps you want to add a $ to the end of your regex? That won't solve
the problem completely, but it should resolve the specific problem you're
seeing here.
hymie! http://www.smart.net/~hymowitz hymie@lactose.homelinux.net
===============================================================================
------------------------------
Date: 22 Mar 2007 12:34:38 GMT
From: Alexis Huxley <ahuxley@gmx.net>
Subject: Re: non-greedy match breaks '?' match?
Message-Id: <slrnf04tuu.rem.ahuxley@dione.no-ip.org>
> Perl is never going to advance the
> position pointer just so that a later qualifier can match as much as
> possible.
Ahh! Super! Thanks very much!
Alexis
------------------------------
Date: 22 Mar 2007 03:04:00 -0700
From: "Jim Burton" <jimburton1@gmail.com>
Subject: Re: On Java's Interface (the meaning of interface in computer programing)
Message-Id: <1174557840.338374.25990@d57g2000hsg.googlegroups.com>
On 21 Mar, 19:11, Lew <l...@nospam.lewscanon.com> wrote:
> Dr. Who wrote:
> > Don't Feed The Trolls :-)
>
> But, but - you fed me!?
>
[blah]
>
> We could put up a contest - whoever finds and corrects the most errors in the
> post wins. Ties broken by the quality of the correct explanations. Incorrect
> explanations count against the entry.
>
> -- Lew
Or you could stop feeding the trolls.
------------------------------
Date: Thu, 22 Mar 2007 08:43:43 -0400
From: Lew <lew@nospam.lewscanon.com>
Subject: Re: On Java's Interface (the meaning of interface in computer programing)
Message-Id: <57idnfxDTKdi5J_bnZ2dnUVZ_uzinZ2d@comcast.com>
Jim Burton wrote:
> Or you could stop feeding the trolls.
Does not apply. The OP was not being trollish, they were being spammish.
-- Lew
------------------------------
Date: Thu, 22 Mar 2007 08:45:50 -0400
From: Lew <lew@nospam.lewscanon.com>
Subject: Re: On Java's Interface (the meaning of interface in computer programing)
Message-Id: <57idnf5DTKfj55_bnZ2dnUVZ_uzinZ2d@comcast.com>
Jim Burton wrote:
> Or you could stop feeding the trolls.
People need to stop saying that. The original post was a detailed if incorrect
exposition of Java information. How in the world do you rate that trollish?
I have absolutely no reason to rate the OP as a troll or their post as trollish.
-- Lew
------------------------------
Date: Thu, 22 Mar 2007 08:45:56 -0400
From: Sherm Pendley <spamtrap@dot-app.org>
Subject: Re: On Java's Interface (the meaning of interface in computer programing)
Message-Id: <m2slbxbg57.fsf@local.wv-www.com>
Lew <lew@nospam.lewscanon.com> writes:
> Jim Burton wrote:
>> Or you could stop feeding the trolls.
>
> Does not apply. The OP was not being trollish
You obviously don't know Xah. He's been doing this for years, cross-
posting to various language groups trying to start an argument between
them. He even brags about being a troll on his web site.
sherm--
--
Web Hosting by West Virginians, for West Virginians: http://wv-www.net
Cocoa programming in Perl: http://camelbones.sourceforge.net
------------------------------
Date: Wed, 21 Mar 2007 14:24:29 +0100
From: Markus E Leypold <development-2006-8ecbb5cc8aREMOVETHIS@ANDTHATm-e-leypold.de>
Subject: Re: On Java's Interface (the meaning of interface in computer programing)
Message-Id: <l9mz26ivaq.fsf@hod.lan.m-e-leypold.de>
Lew <lew@nospam.lewscanon.com> writes:
> Xah Lee wrote:
>> In a functional language, a function can be specified by its name and
>
> Are you sure you know what a "functional language" is?
>
>> parameter specs. For example:
>> f(3)
>> f(3, [9,2])
>> f("some string")
>
> This is not really "typical" syntax for a functional language. LISP,
> for example, has the "function name" as an element of a list. (Some
> might argue that LISP isn't exactly a functional language.)
And nobody really cares, since syntax doesn't make a functional language anyways ...
Regards -- Markus
------------------------------
Date: 22 Mar 2007 11:17:12 GMT
From: anno4000@radom.zrz.tu-berlin.de
Subject: Re: perl feature request
Message-Id: <56f6toF291hbgU1@mid.dfncis.de>
Ben Morrow <ben@morrow.me.uk> wrote in comp.lang.perl.misc:
>
> Quoth anno4000@radom.zrz.tu-berlin.de:
> > Ben Morrow <ben@morrow.me.uk> wrote in comp.lang.perl.misc:
> > >
> > > I was going to say 'in 5.10 this exact feature has been included, as the
> > > new 'state' variables', but perlsub says
> > >
> > > | B<Caveat>: the code at the right side of the assignment to a state
> > > | variable will be executed every time; only the assignment is disabled.
> > > | So, avoid code that has side-effects, or that is slow to execute. This
> > > | might be optimized out in a future version of Perl.
> > >
> > > Doesn't this make state variables, uh, rather useless? Given that they
> > > are basically exactly equivalent to your example above, so all you save
> > > is one compile-time block? Have I missed something?
> >
> > No, they're not useless because they keep their value from one call to
> > another, while still being lexical variables. Currently, we must
> > declare a lexical variable outside the sub for that purpose.
>
> Yes, I realise that. What I was saying is that if
>
> sub foo {
> state $foo;
> ...;
> }
>
> is equivalent to
>
> {
> my $foo;
> sub foo {
> ...;
> }
> }
>
> is this really terribly useful?
That is, of course, a judgement call.
I have never been happy about having to use a bare block, and an extra
level of indentation, just to introduce a state-keeping variable.
Bare blocks containing lexicals and a set of functions to access them
are a useful means for structuring code. If you *have* to use that
technique for a single function and one or a few (state-) variables that
are conceptually part of the sub, that blurs the image and makes the
structure less obvious.
> I suppose if you had something like
>
> sub foo {
> # lotsa stuff
>
> {
> state $foo;
> ...;
> }
> }
>
> then you've gained a decrease in scope, but why not just use another
> sub? Is there some other use case I'm missing?
I don't know of any though I'm sure people will come up with the
weirdest uses for state variables. It's a small step that gets rid
of a small nuisance in Perl programming.
Compare it to the introduction of the fat comma "=>". All it does is
allow barewords on its left, a ridiculously small difference in the
abstract. Yet it has become very much part of the language.
Anno
------------------------------
Date: 22 Mar 2007 05:49:00 -0700
From: "John" <jfcampbell@aol.com>
Subject: problem using timelocal, localtime to discern d-o-w.
Message-Id: <1174567740.386766.159080@e65g2000hsc.googlegroups.com>
Given a date passed in from a spreadsheet, I'm trying to come up with
the day of the week.
Trying to use timelocal (http://search.cpan.org/~drolsky/Time-
Local-1.17/lib/Time/Local.pm) to turn the date into a scalar, then
localtime to return the full slate of results, including the day of
the week.
I seem to be getting back at least what I put in -- that is the month,
day and year are inverted, reverted and returned as I first called
timelocal. But the day of week is not matching my paper calendar.
#!/usr/bin/perl -w
use strict;
use Time::Local;
my $gdate;
my @wkdayname = ('Sunday', 'Monday', 'Tuesday', 'Wednesday',
'Thursday',
'Friday', 'Saturday', 'Sunday');
{
$gdate = "4/18/2007";
my ($gmonth, $gmday, $gyear);
($gmonth, $gmday, $gyear) = split(/\//,$gdate);
{
print "\ngmonth = $gmonth, ";
print "gmday = $gmday, ";
print "gyear = $gyear\n ";
}
my $gday;
my @timeScr;
my $scrTime=timelocal(0, 0, 11, $gmday, $gmonth, $gyear-1900);
@timeScr = localtime($scrTime);
print "timescr= @timeScr \n";
$gday = $timeScr[6];
print "using timescr6 gday = $gday\n";
$gday = $wkdayname[$gday];
print "gday = $gday\n";
}
Results:
gmonth = 4, gmday = 18, gyear = 2007
timescr= 0 0 11 18 4 107 5 137 1
using timescr6 gday = 5
gday = Friday
But it says here that April 18, 2007 is a Wednesday.
John Campbell
Haddonfield, NJ
Perldoc v3.09, under perl v5.008001 for darwin
------------------------------
Date: Thu, 22 Mar 2007 14:03:00 +0100
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: Stuck trying to pass an array that contains a hash to another subprogram
Message-Id: <jev4035d075m7dheqj46k0g0cnp62ua9bv@4ax.com>
On 21 Mar 2007 15:54:41 -0700, novak.dl@gmail.com wrote:
> am modifying a Perl program and I'm stuck trying to pass an array
>that contains a hash to another subprogram.
What is "another subprogram"? A sub? If so then just pass a complex
data structure. You may want to take a reference to your @array or
build an anonymous [@array] one on the fly. BTW: I didn't read your
code because it was still way not brief enough for my tastes, but I
noticed at a glance a number of &-sub-calls. These are now obsolete
and most likely not to do what you probably think they do. Read
perldoc perlsub
for more info.
HTH,
Michele
--
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
.'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
------------------------------
Date: Thu, 22 Mar 2007 13:58:30 +0100
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: Using @ARGV in object oriented script
Message-Id: <41v403daedlrq8p9rhetr00bnui9ju3jkk@4ax.com>
On 21 Mar 2007 09:36:46 -0700, "Jorge" <awkster@yahoo.com> wrote:
>As an exercise in learing Object Oriented Perl I am creating a class
>and a calling script which simply checks the command line arguments to
>see if each file is present. So far it appears to be working as
>expected but I have a question about the use of @ARGV in my calling
>script.
OO is a programming technique with some charachteristics and possible
advantages. @ARGV is an array. The two things are completely
orthogonal, well at least in Perl 5 since we normally do not have
autoboxing (i.e. not everything is an object by default) unless you
use a specific module, which is an aftertought anyway.
>The only way I could see to pass @ARGV as an object was to make it a
>scalar ... thus the line ...
To "pass @ARGV as an object" does not make sense at all. You can pass
@ARGV to an object or class method as a parameter, in wich case it
will be flattened to a list. If you want to keep its "arrayedness",
just take a reference \@ARGV, or build a new one for the purpose
[@ARGV].
>my $list_of_files = join ' ', @ARGV;
Awful! First of all, are all of @ARGV's elemnts filenames? And what if
any of them contsains a whitespace?
>Is there a way I can use a reference such as \@ARGV and somehow
>derference it in the package?
Yes, just like you would dereference it in any Perl program, OO or
not:
perldoc perlref
Michele
--
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
.'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
------------------------------
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 252
**************************************