[25138] in Perl-Users-Digest
Perl-Users Digest, Issue: 7387 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Nov 10 06:05:22 2004
Date: Wed, 10 Nov 2004 03:05:06 -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 Wed, 10 Nov 2004 Volume: 10 Number: 7387
Today's topics:
Re: 'stat' and it's exceptions <fred@localhost.net>
Re: 'stat' and it's exceptions <fred@localhost.net>
Re: 'stat' and it's exceptions <fred@no##!$%regex.com>
Re: braindead languages? <1usa@llenroc.ude.invalid>
Re: braindead languages? <matthew.garrish@sympatico.ca>
Re: braindead languages? <bik.mido@tiscalinet.it>
Re: Extract a number from a string. <wyzelli@yahoo.com>
FAQ 6.6: How can I make "\w" match national character s <comdog@panix.com>
FAQ 7.24: Why can't a method included in this same file <comdog@panix.com>
Re: Firefox broswer staring Perl CGI <vetler@gmail.com>
Re: Generalize Problem : Generate all possible combinat <do-not-use@invalid.net>
Re: Has anyone used tail from PPT in a Tk App? (Win32) <jentzsch@cadence.com>
Legacy End of File Problems with 012 and 000 (Greg Ennis)
Re: Legacy End of File Problems with 012 and 000 <see@sig.invalid>
Read package required? (Mortgageloan2004)
Re: Read package required? <Joe.Smith@inwap.com>
Re: references to OTHER objects <nospam@nospam.com>
Re: references to OTHER objects <nospam@nospam.com>
Re: references to OTHER objects <tassilo.von.parseval@rwth-aachen.de>
Re: Reflection or discovery of object methods in perl? (Anno Siegel)
Re: Reflection or discovery of object methods in perl? <Joe.Smith@inwap.com>
Tail a File using POE and Tk <goodcall1@hotmail.dot.com>
Re: YHBT (Was: Re: braindead languages?) <noreply@gunnar.cc>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Tue, 09 Nov 2004 18:43:59 -0500
From: fred <fred@localhost.net>
Subject: Re: 'stat' and it's exceptions
Message-Id: <pan.2004.11.09.23.43.59.17758@localhost.net>
"So you are an honest freeloader?"
You bet! I later read on the advise of Michele and learned that {1,2}
means match n things m times... so it gets both dots!
"Why no tell you to RTFM?"
Becuase I *knew* the answer was in the docs! I just wanted to be spoon fed
like a big baby!
;)
Thanks for your answer!
------------------------------
Date: Tue, 09 Nov 2004 19:05:15 -0500
From: fred <fred@localhost.net>
Subject: Re: 'stat' and it's exceptions
Message-Id: <pan.2004.11.10.00.05.09.853007@localhost.net>
> But that's only a minor detail. However I'm under the impression that
> the OP has got the script from some{one,where} else and is trying to
> make sense of it...
>
>
> Michele
Actually, it's an original script I wrote. I did get a lot of help here
just lurking.
I enjoy CLPM but must confess I don't contribute any. I take a whole lot.
On the other hand, I have been prgramming for a living 5 years... and I've
been at perl for 6 months. So it's best I don't jump in often..
perl was real hard to pick up at first. Once I made sense of $_ it started
betting easier.. at first this seemed incomprehensible: my(%times) = map
{$_, (stat("$dir/$_"))[9]}grep(!/^\.{1,2}$/,readdir(DIR)) [snip]
Then you get to know that your loading a hash with a key and a value in a
call to (1) stat and (2) grep and (3) readdir with the stat getting the
file times as key and the grep avoiding the . and .. and the readdir
geting you the filenames you wanted.
>I don't understand this question: you are only statting the files that
>match the pattern, if that's what you mean.
Yes eliminating .. and . -- that's everything! Then I have to
backtrack and iterate again to get the matches I was looking for. Say I
was really wanting only *.tmp but the pattern to be held in $pattern --
the regex in the grep would have needed more muscle that I knew how to
give it.
But I got it done. And you know that's subjective... Did "I" really get it
done or did CLPM get it done... well CLPM did not write the script per
se... or did it? It might be true to say: "Without CLPM you would have
never written that script!!!!" and I'd have to agree! On the other hand I
did "type" the script... and did have to consider the flow of the logic,
did have to be unsatisfied that I knew it was not as efficeint as it could
be. So I can't blame that on CLPM... but it wrote the script didn't it?
Wait a minute.
Perhaps one might say... "CLPM wrote the script but you screwed it up and
made it less elegant than it should have been."
Wow, OK maybey that's it! Maybey in spite of CLPM I wrote the script. Or
perhaps CLPM wrote the script as we together struggled for control of the
keyboard....
I wonder... if you took all the perl scipts in the world, and then
filtered all thier logic through every post to this NG and declared that
any script that held any code such as the volumes of it presented here was
guilty of plagerism... wonder what you'd have left? ;)
Thanks and I mean it.
------------------------------
Date: Tue, 09 Nov 2004 19:58:07 -0600
From: Fred aka.... Fred <fred@no##!$%regex.com>
Subject: Re: 'stat' and it's exceptions
Message-Id: <rbt2p09mv9ksflv5hlkphu6itq9qscfpn0@4ax.com>
On Tue, 9 Nov 2004 19:24:38 +0000 (UTC), Juha Laiho
<Juha.Laiho@iki.fi> wrote:
> So, matching (the preceding expression, that is, the literal dot)
> a total of one to two times. Read out straight, will match either
> "." or "..".
Thank you very much for that detailed answer, it helped me understand
what was *really* going on...
Fred, aka FRED
------------------------------
Date: 9 Nov 2004 23:15:23 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: braindead languages?
Message-Id: <Xns959CB9B78B724asu1cornelledu@132.236.56.8>
Sherm Pendley <spamtrap@dot-app.org> wrote in news:R4ednZZu9s64qQzcRVn-
og@adelphia.com:
> A. Sinan Unur wrote:
>
>> ITYM
>
> I think she means to sabotage the group by increasing the noise level.
> Her flamebait was posted to C++ and Java groups as well - with followups
> directed here, so that c.l.p.m gets all of the outraged responses from
> the denizens of those groups.
Ah, I am really sorry ... I did not pay attention. Should have known
better. Thanks for pointing it out.
--
A. Sinan Unur
1usa@llenroc.ude.invalid
(remove '.invalid' and reverse each component for email address)
------------------------------
Date: Tue, 9 Nov 2004 19:20:03 -0500
From: "Matt Garrish" <matthew.garrish@sympatico.ca>
Subject: Re: braindead languages?
Message-Id: <S8dkd.20652$km5.994313@news20.bellglobal.com>
"Laura" <lwt0301@bellsouth.net> wrote in message
news:10p2a8hlu4vro74@news.supernews.com...
> perldoc perltoot | grep 'braindead' -A 1 -B 1
>
A rather pointless post if ever there was one, especially since you seem to
hope it will be taken out of context:
<quote>
There, if that doesn't excite the Scheme folks, then I just don't know what
will. Translation of this technique into C++, Java, or any other
braindead-static language is left as a futile exercise for aficionados of
those camps.
...
If you were wondering when Hubris, the third principle virtue of a
programmer, would come into play, here you have it. (More seriously, Hubris
is just the pride in craftsmanship that comes from having written a sound
bit of well-designed code.)
</quote>
In other words, for the less cranially developed such as yourself, that
paragraph was meant to be taken tongue-in-cheek.
Matt
------------------------------
Date: Wed, 10 Nov 2004 09:34:33 +0100
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: braindead languages?
Message-Id: <h9k3p0hkdg1pfrobr6alp0isb4e2e5tbpo@4ax.com>
On 9 Nov 2004 21:06:07 GMT, "A. Sinan Unur" <1usa@llenroc.ude.invalid>
wrote:
>ITYM
>
>perldoc perltoot | grep -A1 -B1 braindead
>
>Usage: grep [OPTION]... PATTERN [FILE]...
Sorry to disagree with you and implicitly agree with the troll, but
she's right: it will work the other way too, even though the usage
line suggests differently. I don't know with more ancient
implementations, but nowadays grep is often GNU grep, and the cmd line
is processed with GNU getopts library a feature of which being that
switches can appear almost anywhere and in any order. Some times it is
necessary to protect the pattern with -e, and I often use it anyway
for clarity, even if redundant. Note: what I wrote may be sloppy
technically in some places, but should be fundamentally correct.
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: Wed, 10 Nov 2004 09:08:57 GMT
From: "Peter Wyzl" <wyzelli@yahoo.com>
Subject: Re: Extract a number from a string.
Message-Id: <JUkkd.31161$K7.11226@news-server.bigpond.net.au>
"Ben Morrow" <usenet@morrow.me.uk> wrote in message
news:7b4762-sp5.ln1@osiris.mauzo.dyndns.org...
>
> Quoth "Peter Wyzl" <wyzelli@yahoo.com>:
>> "Adam" <adam_cheney@hotmail.com> wrote in message
>> news:214d0889.0411080642.7942a3e1@posting.google.com...
>> > "Peter Wyzl" <wyzelli@yahoo.com> wrote in message
>> > news:<CfIjd.27076$K7.12840@news-server.bigpond.net.au>...
>>
>> <..>
>>
>> > ($lic_usage{$lic_type}{$max}) = /(\d+)/ if (/Maximum/);
>>
>> What happens here when /Maximum/ matches and /(\d+)/ fails to capture
>> anything?
>>
>> You end up assigning whatever happens to be in $1 at that time (maybe
>> nothing, more likely the result of the last successful match) to
>> $lic_usage{$lic_type}{$max}. This is a _bad_ thing.
>
> Did you try it? You actually get the empty string.
>
> You should never use the $n variables without checking the match
> succeeded, but list assognment of a match does not use the $n variables.
No, I didn't try it cos I was making the point that it was 'a bad thing'(tm)
and not what I had replied with earlier.
--
Wyzelli
print "But he didn't listen\n";
------------------------------
Date: Wed, 10 Nov 2004 05:03:01 +0000 (UTC)
From: PerlFAQ Server <comdog@panix.com>
Subject: FAQ 6.6: How can I make "\w" match national character sets?
Message-Id: <cms7e5$aur$1@reader1.panix.com>
This message is one of several periodic postings to comp.lang.perl.misc
intended to make it easier for perl programmers to find answers to
common questions. The core of this message represents an excerpt
from the documentation provided with Perl.
--------------------------------------------------------------------
6.6: How can I make "\w" match national character sets?
Put "use locale;" in your script. The \w character class is taken from
the current locale.
See perllocale for details.
--------------------------------------------------------------------
Documents such as this have been called "Answers to Frequently
Asked Questions" or FAQ for short. They represent an important
part of the Usenet tradition. They serve to reduce the volume of
redundant traffic on a news group by providing quality answers to
questions that keep coming up.
If you are some how irritated by seeing these postings you are free
to ignore them or add the sender to your killfile. If you find
errors or other problems with these postings please send corrections
or comments to the posting email address or to the maintainers as
directed in the perlfaq manual page.
Note that the FAQ text posted by this server may have been modified
from that distributed in the stable Perl release. It may have been
edited to reflect the additions, changes and corrections provided
by respondents, reviewers, and critics to previous postings of
these FAQ. Complete text of these FAQ are available on request.
The perlfaq manual page contains the following copyright notice.
AUTHOR AND COPYRIGHT
Copyright (c) 1997-2002 Tom Christiansen and Nathan
Torkington, and other contributors as noted. All rights
reserved.
This posting is provided in the hope that it will be useful but
does not represent a commitment or contract of any kind on the part
of the contributers, authors or their agents.
------------------------------
Date: Wed, 10 Nov 2004 11:03:03 +0000 (UTC)
From: PerlFAQ Server <comdog@panix.com>
Subject: FAQ 7.24: Why can't a method included in this same file be found?
Message-Id: <cmssh7$g02$1@reader1.panix.com>
This message is one of several periodic postings to comp.lang.perl.misc
intended to make it easier for perl programmers to find answers to
common questions. The core of this message represents an excerpt
from the documentation provided with Perl.
--------------------------------------------------------------------
7.24: Why can't a method included in this same file be found?
Some possible reasons: your inheritance is getting confused, you've
misspelled the method name, or the object is of the wrong type. Check
out perltoot for details about any of the above cases. You may also use
"print ref($object)" to find out the class $object was blessed into.
Another possible reason for problems is because you've used the indirect
object syntax (eg, "find Guru "Samy"") on a class name before Perl has
seen that such a package exists. It's wisest to make sure your packages
are all defined before you start using them, which will be taken care of
if you use the "use" statement instead of "require". If not, make sure
to use arrow notation (eg., "Guru->find("Samy")") instead. Object
notation is explained in perlobj.
Make sure to read about creating modules in perlmod and the perils of
indirect objects in "Method Invocation" in perlobj.
--------------------------------------------------------------------
Documents such as this have been called "Answers to Frequently
Asked Questions" or FAQ for short. They represent an important
part of the Usenet tradition. They serve to reduce the volume of
redundant traffic on a news group by providing quality answers to
questions that keep coming up.
If you are some how irritated by seeing these postings you are free
to ignore them or add the sender to your killfile. If you find
errors or other problems with these postings please send corrections
or comments to the posting email address or to the maintainers as
directed in the perlfaq manual page.
Note that the FAQ text posted by this server may have been modified
from that distributed in the stable Perl release. It may have been
edited to reflect the additions, changes and corrections provided
by respondents, reviewers, and critics to previous postings of
these FAQ. Complete text of these FAQ are available on request.
The perlfaq manual page contains the following copyright notice.
AUTHOR AND COPYRIGHT
Copyright (c) 1997-2002 Tom Christiansen and Nathan
Torkington, and other contributors as noted. All rights
reserved.
This posting is provided in the hope that it will be useful but
does not represent a commitment or contract of any kind on the part
of the contributers, authors or their agents.
------------------------------
Date: Wed, 10 Nov 2004 11:25:12 +0100
From: "Vetle Roeim" <vetler@gmail.com>
Subject: Re: Firefox broswer staring Perl CGI
Message-Id: <opsg8u8ap8x7nu7z@quickfix.opera.com>
On 9 Nov 2004 18:44:18 GMT, John Bokma <postmaster@castleamber.com> wrote:
> Chris Cole wrote:
>
>> On Mon, 08 Nov 2004 06:55:04 +0000, John Bokma wrote:
>
> [ CGI.pm uses XHTML as default ]
>
>> So what? XHTML is a perfectly valid way of creating web pages (CGI or
>> otherwise). I have no problems with firefox displaying perl CGI using
>> the default XHTML output.
>
> XHTML is a joke.
I've never heard this statement before, and I'm somewhat intrigued. This
is a little OT for this group, but could you explain it, or do you have
any pointers to where I can read a critique of XHTML?
[...]
--
It's not a bug, it's the future.
------------------------------
Date: 10 Nov 2004 11:26:21 +0100
From: Arndt Jonasson <do-not-use@invalid.net>
Subject: Re: Generalize Problem : Generate all possible combinations
Message-Id: <yzdfz3if19u.fsf@invalid.net>
tiltonj@erols.com (Jay Tilton) writes:
> my @a = (
> [1, 2, 3],
> [4, 5],
> [6, 7],
> );
> local($,,$")="\n";print<@{[map{local$"=',';"{@$_}"}@a]}>;
Nice. Here is a broken up and rearranged version, so that the ones
confused by the one-liner can work out for themselves how it works:
my @a = (
[1, 2, 3],
[4, 5],
[6, 7],
);
{
local($,,$");
$" = ",";
my @l1 = map {"{@$_}"} @a;
$" = "";
my @l2 = <@l1>;
$, = "\n";
print @l2;
}
print "\n";
(My perl 5.005 didn't like $" being undef, so I set it to "".)
------------------------------
Date: Wed, 10 Nov 2004 07:01:22 +0100
From: Eyck Jentzsch <jentzsch@cadence.com>
Subject: Re: Has anyone used tail from PPT in a Tk App? (Win32)
Message-Id: <4191ad8b$1@news.cadence.com>
Johnny Google wrote:
> I need to use a tail like functionality on a Win32 perl Tk app.
> The tail modules (File::Tail, etc) are not ported for Win32.
>
>
> Someone on another list referred me to the tail function from PPT (Perl
> Power Tools). This is a command line file function and not a module...
> it seems to do the job when run from the command line.
>
> When trying to implement it as in my other post on fileevent:
>
> open(H, "c:/perl/bin/tail -f -n 25 $pipe_in|") or die "Nope:
> $OS_ERROR";
> $mw->fileevent(H, 'readable', [\&fill_text_widget, $t]);
>
> - it not only does not work - it leaves the perl process running after
> I kill the app.
>
> I have noticed that it appears to trap the interrupt signal - why I
> have no idea! - but this makes it hard to kill as a command line and I
> think it is what is causing it to continue on after my perl app dies.
>
> I also can't figure out why it isn't working to fill my widget with the
> file data...
>
> Any clues - has anyone used this tail function in a perl script before?
> In a Tk app? Any other Tail-like functions, modules, Win32 functions?
> Thanks,
>
> John
>
I did not use it under windows but for other reasons I implemented a
tail-like function in pure perl:
> sub add_tail {
> my($file)=@_;
> my @stat=stat($file);
> my @oldstat=@{$widget{$file}->[1]};
> my $fh=$widget{$file}->[1];
> # empty the text widget if file is truncated or recreated
> if($stat[1] != $oldstat[0] or $stat[7]<$oldstat[2]){
> $widget{$file}->[0]->delete(qw/1.0 end/);
> $oldstat[2]=0;
> }
> if($stat[7]>$oldstat[2]){
> open(FH, '<', $file);
> seek(FH, $oldstat[2], 0);
> read(FH, $_, $stat[7] - $oldstat[2]);
> close(FH);
> $widget{$file}->[0]->insert("end", $_);
> $widget{$file}->[0]->SetCursor("end-1char") if($mode);
> $widget{$file}->[1]=[$stat[1], $stat[9], $stat[7]];
> }
> # recall my self in 0.5 sec
> $MW->after(500,[\&add_tail, $file])
> }
HTH
-Eyck
------------------------------
Date: 9 Nov 2004 16:55:47 -0800
From: PoMec@PoMec.Net (Greg Ennis)
Subject: Legacy End of File Problems with 012 and 000
Message-Id: <6c2fdba7.0411091655.3285bb7a@posting.google.com>
Everyone,
I am using perl to interface some mail receipts to a legacy system on
a SCO Unix system that is causing some problems.
The legacy system's grammer for text files requires the end of the
file be a null. 000 in octal. Many of the legacy text files end with
012 000 (Octal), some just end in 000. The description of text files
by this system stipulates that the end of file for text files is a
null.
The problem I am having is that a text file built and maintinted by
this system usually ends in 012 000. When I use perl to append to
this file, perl puts the data after the null so that it looks like 012
000 051 etc. I can read the file without difficulty using unix tools,
but the legacy system will stop the read at the null missing all of
the appended data.
I have been studying this problem for 2 days and have not been able to
figure out a perl solution. Is there a way for perl to start the
write process at the point of the null? and is there a way for perl to
add a null after the 012 so that every EOF is 012 000.
Would appreciate your suggestions and help.
Thanks,
Greg
------------------------------
Date: Tue, 09 Nov 2004 21:42:24 -0500
From: Bob Walton <see@sig.invalid>
Subject: Re: Legacy End of File Problems with 012 and 000
Message-Id: <41917dca$1_4@127.0.0.1>
Greg Ennis wrote:
...
> The legacy system's grammer for text files requires the end of the
> file be a null. 000 in octal. Many of the legacy text files end with
> 012 000 (Octal), some just end in 000. The description of text files
> by this system stipulates that the end of file for text files is a
> null.
>
...
> figure out a perl solution. Is there a way for perl to start the
> write process at the point of the null? and is there a way for perl to
> add a null after the 012 so that every EOF is 012 000.
>
> Would appreciate your suggestions and help.
perldoc -f seek
print $fh "\x00";
Also check out
perldoc perlvar
particularly the variable $\ .
...
> Greg
--
Bob Walton
Email: http://bwalton.com/cgi-bin/emailbob.pl
------------------------------
Date: 10 Nov 2004 08:23:10 GMT
From: mortgageloan2004@aol.com (Mortgageloan2004)
Subject: Read package required?
Message-Id: <20041110032310.08281.00000491@mb-m04.aol.com>
Global symbol "$I" requires explicit package name at test2.cgi line 9.
Global symbol "$I" requires explicit package name at test2.cgi line 18.
Global symbol "$I" requires explicit package name at test2.cgi line 19.
Bareword "FORM" not allowed while "strict subs" in use at test2.cgi line 16.
Bareword "FORM" not allowed while "strict subs" in use at test2.cgi line 20.
Bareword "FORM" not allowed while "strict subs" in use at test2.cgi line 21.
Execution of test2.cgi aborted due to compilation errors.
I got this error for my script. It was working doing the housekeeping for
making a directory and copying a couple files. But the minute I put in the
part where it reads the subdirectory, it gave me this.
#!/usr/bin/perl
use CGI::Carp qw/fatalsToBrowser warningsToBrowser/;
warningsToBrowser(1);
use File::Copy;
use strict;
use warnings;
my $form = '';
my $newapp = '../../$form/loanapp.htm';
my $newdatabase = '../../$form/database.txt';
$I=0;
# open up the form database-we keep track of who has what form number in
here-the subdirectories
# are numbered sequentially starting at 1 i.e. form1, form2, form3, etc..This
will be a flat
# file database with the form number and the username-The program only appends
after reading it
# in to see what the next form will be.
Open(FORM, 'subdirectory.txt') || die "cannot open subdirectory.txt for
reading: $!";
while (<FORM>) { #read a line from subdirectoy database into $_
$I++; }
$form = "FORM" . $I ;# How do you contanate the word FORM and the value of $I?
Close(FORM);
Open(FORM, '>>subdirectory.txt') || die "cannot open subdirectory.txt for
appending: $!";
print FORM $form . "|";
Close FORM;
# This is the housekeeping program that sets up the users files after they
create their login and pw
# First we need to make a subdirectory unique to the login just created by the
user
# The variable $login is accessible from the current program. This should be a
subroutine to another program.
mkdir("../../$form",0777) || die "cannot mkdir $form $!";
copy("../database.txt","$newdatabase");
# Next we need to copy the master database with just the field names from the
its location to the new location
# THe location is in mortgage-applications-online/cgi-bin/database.txt it goes
into the subdirectory just
# created above. (i.e. mortgage-applications-online/$login/database.txt
# copy .. I don't know how to do this.
# Thirdly we need to read in the master html form and modify it at line 1702 to
include an additional line with
# a hidden field which is passed to the cgiprogram so it will recognize where
to look for the correct database.
open(IN,'../../pwc/loanapp.htm') || die "cannot open loanapp.htm for reading:
$!";
open(OUT,">$newapp") || die "cannot create $newapp: $!";
while (<IN>) { #read a line from file $a into $_
print OUT $_; #print that line to file $b
#use $. to determine what line you're at in IN
if ($. == 1702) {
print OUT '<INPUT TYPE="hidden" NAME="subject" VALUE="test">';
}
}
close IN;
close OUT;
------------------------------
Date: Wed, 10 Nov 2004 09:18:58 GMT
From: Joe Smith <Joe.Smith@inwap.com>
Subject: Re: Read package required?
Message-Id: <62lkd.15820$V41.10648@attbi_s52>
Mortgageloan2004 wrote:
> the minute I put in the part where it reads the subdirectory, it gave me this.
The problem not with subdirectory reading; it lies elsewhere.
> Global symbol "$I" requires explicit package name at test2.cgi line 9.
That means you have "use strict;" and forgot to put "my" in "my $I;".
> Bareword "FORM" not allowed while "strict subs" in use at test2.cgi line 16.
> Open(FORM, 'subdirectory.txt') || die "cannot open subdirectory.txt for
That means that FORM is not interpreted as a file handle because you used
Open(FORM) instead of open(FORM) and Open() is undefined.
-Joe
------------------------------
Date: Wed, 10 Nov 2004 01:25:46 -0500
From: "daniel kaplan" <nospam@nospam.com>
Subject: Re: references to OTHER objects
Message-Id: <1100068009.184171@nntp.acecape.com>
"Sherm Pendley" <spamtrap@dot-app.org> wrote in message
news:yoGdnT3ec6WhuAzcRVn-rQ@adelphia.com...
[a lot]
which thanks for taking the time to write all that, but i *still* have to
ask one more thing.
"the variable will be retained so long as one or more references to it are
viable. "
i like this, in that it seems that Perl does handle for you all the
background managment of "references", which is great, but you mentioned:
> When the last reference to an object is gone, before the object's memory
> is released, its DESTROY() method is called if it has one. This is
i was curious, and have to ask, not because i plan on doing it, just because
it could happen...what if one piece of code calls the DESTROY() method,
while a reference exists? does Perl itself have some sort of protection for
that, if there isn't something written within the DESTROY method itself to
protect from that? not asking how, but am assuming there is probably a way
to get the handle to the count of a referenced object/variable/etc.
which, i am sorry, i must ask one more thing....i can't find it right now,
but i was given flack for saying that aren't "dereferencing and casting the
same thing?" i just want to make sure i have it right, going by the book i
am reading:
if you do have................$a = "cat"
this is referencing: $a_ref = \$ref;
and this $$a_ref = "dog";
is dereferencing....now to me, that's just casting a reference as a
scalar...
what i just want to be sure of is that i am not misunderstanding and if
something else is going on behind the scenes here when i "derefence a
reference"
thanks for the time in your post..
daniel
------------------------------
Date: Wed, 10 Nov 2004 01:39:33 -0500
From: "daniel kaplan" <nospam@nospam.com>
Subject: Re: references to OTHER objects
Message-Id: <1100068835.885502@nntp.acecape.com>
"daniel kaplan" <nospam@nospam.com> wrote in message
news:1100068009.184171@nntp.acecape.com...
oops, obviosuly when i said:
if you do have................$a = "cat"
this is referencing: $a_ref = \$ref;
and this $$a_ref = "dog";
that middle line shoud read $a_ref = \$a;
------------------------------
Date: Wed, 10 Nov 2004 07:58:26 +0100
From: "Tassilo v. Parseval" <tassilo.von.parseval@rwth-aachen.de>
Subject: Re: references to OTHER objects
Message-Id: <slrncp3f0i.rp.tassilo.von.parseval@localhost.localdomain>
Also sprach daniel kaplan:
> "Sherm Pendley" <spamtrap@dot-app.org> wrote in message
> news:yoGdnT3ec6WhuAzcRVn-rQ@adelphia.com...
>
> [a lot]
>
> which thanks for taking the time to write all that, but i *still* have to
> ask one more thing.
>
> "the variable will be retained so long as one or more references to it are
> viable. "
>
> i like this, in that it seems that Perl does handle for you all the
> background managment of "references", which is great, but you mentioned:
>
>> When the last reference to an object is gone, before the object's memory
>> is released, its DESTROY() method is called if it has one. This is
>
> i was curious, and have to ask, not because i plan on doing it, just because
> it could happen...what if one piece of code calls the DESTROY() method,
> while a reference exists? does Perl itself have some sort of protection for
> that, if there isn't something written within the DESTROY method itself to
> protect from that? not asking how, but am assuming there is probably a way
> to get the handle to the count of a referenced object/variable/etc.
That entirely depends on what the DESTROY method does. If no such
method has been implemented (and in absence of an AUTOLOAD method), you
get the expected "Can't locate object method "DESTROY" via package...".
If there is one, it is treated as an ordinary method. If it delibaretly
destroying the objects (by maybe closing underlying filehandles or
deleting necessary tempfiles), then the object will understandably not
be functional afterwards.
Note that DESTROY is not the same as ~Class() in C++. Think of DESTROY
as a hook that allows you to do something when an object is destroyed by
perl. In most cases, you don't have to bother writing one yourself.
However, sometimes it is really a deconstructor which has to free memory
and such. This can be the case with modules written in XS (that is: C)
where the Perl object might be a very thin wrapper around a C struct
whose memory was dynamically allocated and needs deallocation in order
to avoid leaks. It stands to reason that manually calling such a DESTROY
method is roughly equivalent to 'free(ptr)' in C after which 'ptr' is
unusable.
Anyway, never try to be too smart to do the work perl is supposed to do.
When DESTROY is called, don't even think of figuring out the reference
count of the object yourself and take actions based on that. The
reference count has to be zero, otherwise DESTROY would have never been
triggered.
> which, i am sorry, i must ask one more thing....i can't find it right now,
> but i was given flack for saying that aren't "dereferencing and casting the
> same thing?" i just want to make sure i have it right, going by the book i
> am reading:
>
> if you do have................$a = "cat"
> this is referencing: $a_ref = \$ref;
> and this $$a_ref = "dog";
> is dereferencing....now to me, that's just casting a reference as a
> scalar...
It's not really a cast because you have no choice into which type you
cast. Try this:
$a = "cat";
$ref = \$a;
%hash = %$ref;
__END__
Not a HASH reference at - line 3.
That is very much different from C, where you could happily do:
#include <stdio.h>
int main (int argc, char **argv) {
int a = 42;
FILE *f = (FILE*)a;
fprintf(f, "I bet this doesn't work");
return 0;
}
and see the segfaults flying by.
So a cast allows you to turn one type into the other. It really doesn't
matter whether those two types are incompatible (at least not in proper
languages like C).
A Perl reference on the other hand wont give you this freedom. You have
one type to which you are allowed to make a reference. After that, you
have a reference type. This reference refers to a value with a very
distinct type that you are not allowed to change. Never.
The closest you may get to typecasting in Perl is changing the class
into which an object is blessed:
my $obj = Foo->new;
bless $obj => "Bar";
That however is a very uncommon operation in Perl. And it doesn't even
make sense because it requires objects of the classes Foo and Bar to
have the same internal structure.
> what i just want to be sure of is that i am not misunderstanding and if
> something else is going on behind the scenes here when i "derefence a
> reference"
Here's an analogy of what a reference/dereference operation would be
like in C and the below can be translated into Perl verbatimly:
int a = 42;
int *b = &a; /* take a reference */
int c = *b; /* dereference */
Note how each variable either is or points to an 'int'. As soon as you
have a typecast in there, it would no longer be an operation possible in
Perl.
Tassilo
--
$_=q#",}])!JAPH!qq(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?<=sub).+q#q!'"qq.\t$&."'!#+sexisexiixesixeseg;y~\n~~dddd;eval
------------------------------
Date: 9 Nov 2004 23:11:47 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Reflection or discovery of object methods in perl?
Message-Id: <cmrirj$g7m$1@mamenchi.zrz.TU-Berlin.DE>
Michele Dondi <bik.mido@tiscalinet.it> wrote in comp.lang.perl.misc:
> On 9 Nov 2004 12:25:55 GMT, anno4000@lublin.zrz.tu-berlin.de (Anno
> Siegel) wrote:
>
> > sub foo {} # define a sub, or you won't see much
> > print "$_\n" for grep defined( &{ $main::{ $_}}), keys %main::
>
> Dear Anno, please forgive me if I'm dumb: of course I have much less
> experience than you have, in these matters, but wouldn't it be better
> to grep on
>
> *{$_}{CODE}
>
> instead, especially in a more general setting, since we cannot rely on
> return values of subs (and we may risk side effects running them)?
Uh, no. I'm not running them, that would be suicidal... Also,
as you note, there's no telling what they return.
"defined &foo" is special, it tests if a sub is defined (has code
associated with it). It's the standard way of testing if a sub
exists, I just adapted it to the situation, making use of the fact
that a glob can be de-referenced like a ref. The glob_as_a_hash
syntax you're using just didn't come to mind as readily, so I
used the first thing that worked. How's that for the praxis of
experience? :)
> Also, were I doing this for a generic package, say $pkg, rather than
> main, should I use something like
>
> *{"${pkg}::$_"}{CODE}
Well... it works.
> instead? Or are there better ways?
>
> *{ ${"${pkg}::"}{$_} }{CODE}
>
> seems to work, even though I had naively and erroneously assumed that
> the outer *{ ... } wouldn't have been necessary, but is even more
> verbose and clumsy...
That looks like an attempt to restrict the symref what's absolutely
necessary. "$_", which went into the symref above, is now a respectable
piece of data (a hash key). But you can't avoid a symref altogether
(I don't think so), so why bother.
Then again, it gains a little when the '::' is made part of $pkg (or
never stripped off in the first place):
*{ ${ $pkg}{ $_}}{ CODE}
doesn't look half bad.
Anno
------------------------------
Date: Wed, 10 Nov 2004 10:02:58 GMT
From: Joe Smith <Joe.Smith@inwap.com>
Subject: Re: Reflection or discovery of object methods in perl?
Message-Id: <mHlkd.23393$5K2.21134@attbi_s03>
bboett@sept.u-strasbg.fr wrote:
> BTW a chance to easily try to extrapolate what return type the subs
> might have (means without actually executing them...)?
You are aware, I hope, that subs using wantarray() can return more
than one type, depending on context (list, scalar, void).
-Joe
------------------------------
Date: Wed, 10 Nov 2004 06:24:55 GMT
From: "Jack D" <goodcall1@hotmail.dot.com>
Subject: Tail a File using POE and Tk
Message-Id: <Xuikd.89943$VA5.47836@clgrps13>
"Johnny Google" <john_pataki@yahoo.com> wrote in message
news:1100004772.745747.71580@f14g2000cwb.googlegroups.com...
> I need to use a tail like functionality on a Win32 perl Tk app.
> The tail modules (File::Tail, etc) are not ported for Win32.
[snip]
> Any clues - has anyone used this tail function in a perl script before?
> In a Tk app? Any other Tail-like functions, modules, Win32 functions?
You can do this using POE::Wheel::FollowTail. I don't profess to know much
about POE and how it co-exists with Tk. I only know what the few examples
show.
Here is full working example of a tail utility:
######################################
#!/usr/bin/perl
use warnings;
use strict;
# Tk support is enabled if the Tk module is used before POE itself.
use Tk;
use Tk::ROText;
use POE;
use POE::Wheel::FollowTail;
my $FILENAME = "C:/temp/myfile.txt"; #Win32 example
open (TAIL,">$FILENAME") or die;
select(TAIL);
my $ID;
POE::Session->create
( inline_states =>
{ _start => \&ui_start,
gotline => \&ui_read,
ev_clear => \&ui_clear,
writeline => \&ui_write,
stopwrite => \&ui_stop,
}
);
$poe_kernel->run();
exit 0;
sub ui_start {
my ( $kernel, $session, $heap ) = @_[ KERNEL, SESSION, HEAP ];
$heap->{text_widget} =
$poe_main_window->Scrolled('ROText',-scrollbars=>'ose' )->pack;
$poe_main_window->Button
( -text => "Write to File",
-command => $session->postback("writeline")
)->pack;
$poe_main_window->Button
( -text => "Stop Writing to File",
-command => $session->postback("stopwrite")
)->pack;
$poe_main_window->Button
( -text => "Clear Widget",
-command => $session->postback("ev_clear")
)->pack;
$heap->{tail} =
POE::Wheel::FollowTail->new
(
Filename => $FILENAME,
InputEvent => 'gotline');
}
sub ui_read {
$_[HEAP]->{text_widget}->insert('end',$_[ARG0]);
$_[HEAP]->{text_widget}->insert('end',"\n");
$_[HEAP]->{text_widget}->see('end');
}
sub ui_clear {
$_[HEAP]->{text_widget}->delete('1.0','end');
}
sub ui_write {
$ID->cancel if ($ID);
$|=1;
$ID = $_[HEAP]->{text_widget}->repeat(1000,sub {
print TAIL scalar gmtime,"\n"});
}
sub ui_stop {
return unless ($ID);
$ID->cancel if ($ID);
$ID = undef;
$_[HEAP]->{text_widget}->insert('end',"Writing stopped....!!!!!\n\n");
}
######################################
HTH
Jack
------------------------------
Date: Wed, 10 Nov 2004 02:02:58 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: YHBT (Was: Re: braindead languages?)
Message-Id: <2vd7niF2ju4pjU1@uni-berlin.de>
Sherm Pendley wrote:
> Please don't feed the troll by replying to this.
Agreed.
And since we don't want to see 'debates' bases on such braindead
wordings, maybe somebody should better reconsider the including of such
troll invitations in the docs?
Just a thought.
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
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 V10 Issue 7387
***************************************