[22173] in Perl-Users-Digest
Perl-Users Digest, Issue: 4394 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Jan 13 14:05:47 2003
Date: Mon, 13 Jan 2003 11:05:09 -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 Mon, 13 Jan 2003 Volume: 10 Number: 4394
Today's topics:
Re: $size = -s /home/temp/$_" Doesn't work <bol@adv.magwien.gv.at>
Re: finding largest repeat values in array (Tad McClellan)
Re: finding largest repeat values in array ctcgag@hotmail.com
Re: finding largest repeat values in array (Tad McClellan)
Re: finding largest repeat values in array (Tad McClellan)
Re: FULL VERSION: Hi all gurus. What is wrong in my s <camerond@mail.uca.edu>
Re: FULL VERSION: Hi all gurus. What is wrong in my s (Tad McClellan)
Re: How does one determine why perl prog runs so slow?? <cwilbur@mithril.chromatico.net>
Re: How does one determine why perl prog runs so slow?? <eighner@io.com>
Re: How does one determine why perl prog runs so slow?? <flavell@mail.cern.ch>
Re: How does one determine why perl prog runs so slow?? <joe+usenet@sunstarsys.com>
Re: How to check responce on specific tcp-ports? <a@b.c>
Re: How to check responce on specific tcp-ports? <a@b.c>
Re: how to redirect STDIN to such place like /dev/null pauli@johannes-pauli.de
Re: Isogest 3.1 New release <jpagnew@vcu.edu>
Re: Match-time code evaluation <invalid@invalid.com>
Re: My, our, etc. <koos_pol@NO.nl.JUNK.compuware.MAIL.com>
Re: My, our, etc. <jpagnew@vcu.edu>
Re: My, our, etc. <spikey-wan@bigfoot.com>
Re: My, our, etc. <spikey-wan@bigfoot.com>
Re: My, our, etc. (Ben Morrow)
Newbie - how to tell if module installed ... (Joe Halbrook)
Re: ppm query <No_Mail_Address@cox.net>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Mon, 13 Jan 2003 18:02:20 +0100
From: "Ferry Bolhar" <bol@adv.magwien.gv.at>
Subject: Re: $size = -s /home/temp/$_" Doesn't work
Message-Id: <1042477181.750983@mozart.adv.magwien.gv.at>
> I need to check if the file is complity on my disk from FTP program.
> So I check the file's size and wait a while and check it again. If
> size is same file is ready for action else do nothing. Here is what I
> can't get work:
Well - let's see...
> while (<TEXTFILE>) {
1) If you get lines from a file, they are terminated with a "\n" (carriage
return). You need to remove this character with 'chomp'.
> $size1 = -s "/temp/$_";
> system('sleep 20');
2) No need for 'system'. Perl provides its own 'sleep' command.
> $size2 = -s "/temp/$_";
>
> if ($size1 = $size2 ) {
3) = is an assign operator - in this case, you assign the value of $size2
to $size1 and check whether it is true (not zero). For numerical equality
operations, use ==.
So your code should like this:
while (<TEXTFILE>) {
chomp;
$size1 = -s /temp/$_;
sleep 20;
$size2 = -s /temp/$_;
if (size1 == $size2) {
BTW: == (and its complement !=) are for numerical equality operations only.
Use eq/ne and friends for compare operations with strings. See perldoc
perlop for a detailled description.
HTH, Ferry
---
------------------------------
Date: Mon, 13 Jan 2003 08:13:12 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: finding largest repeat values in array
Message-Id: <slrnb25ibo.2ki.tadmc@magna.augustmail.com>
hugo <hugo@geoinformex.com> wrote:
> I would like to find the greatest number of identical values in this
> array
> I have tried this using a loop, i.e.
^^^^^^^^^^ ^^^^
I doubt that...
> for ($i =0; $i < @myArray; $i++) {
> if (myArray[$i] eq myArray[$i -1]) {
^^ ^^
Syntax error.
Must have been some _other_ loop that you tried.
Do not re-type Perl code
Use copy/paste or your editor's "import" function rather than
attempting to type in your code. If you make a typo you will get
followups about your typos instead of about the question you are
trying to get answered.
You've been posting here a long time, and have been referred to
the Posting Guidelines in the past. Please don't ignore the
advice given there.
> Any help, particularly a code example,
Do you want real code, or pseudo code containing typos?
It is likely that folks attempting to answer your question
want the same thing. Please apply the Golden Rule to your
postings. <grin>
----------------------------
#!/usr/bin/perl
use strict;
use warnings;
my @myArray = qw/ a b b c c c c /;
my $big_key = $myArray[0];
my %seen;
foreach ( @myArray ) {
$seen{$_}++;
$big_key = $_ if $seen{$_} > $seen{$big_key};
}
print "'$big_key' appeared $seen{$big_key} times\n";
----------------------------
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: 13 Jan 2003 16:52:43 GMT
From: ctcgag@hotmail.com
Subject: Re: finding largest repeat values in array
Message-Id: <20030113115243.042$00@newsreader.com>
Andrew Lee wrote:
> On 07 Jan 2003 16:44:36 GMT, ctcgag@hotmail.com wrote:
>
> >hugo <hugo@geoinformex.com> wrote:
> >> Hi
> >>
> [question snipped]
>
> >You need to reset repeat, and capture the greatest value.
> >
> >my $most=-1;
> >my $repeat=1;
> >for my $i (1..@myArray) {
> > if (myArray[$i] eq myArray[$i -1]) {
> > $repeat++;
>
> Ack!!!
>
> That won't work unless you have reset $[ (a soon to be deprectaed
> "feature").
Other than the missing $s, which $[ won't affect, why won't it work?
Xho
--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service New Rate! $9.95/Month 50GB
------------------------------
Date: Mon, 13 Jan 2003 12:08:18 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: finding largest repeat values in array
Message-Id: <slrnb2604i.3fh.tadmc@magna.augustmail.com>
ctcgag@hotmail.com <ctcgag@hotmail.com> wrote:
> Andrew Lee wrote:
>> On 07 Jan 2003 16:44:36 GMT, ctcgag@hotmail.com wrote:
>>
>> >hugo <hugo@geoinformex.com> wrote:
>> >You need to reset repeat, and capture the greatest value.
>> >
>> >my $most=-1;
>> >my $repeat=1;
>> >for my $i (1..@myArray) {
>> > if (myArray[$i] eq myArray[$i -1]) {
>> > $repeat++;
>> That won't work unless you have reset $[ (a soon to be deprectaed
>> "feature").
>
> Other than the missing $s, which $[ won't affect, why won't it work?
Try it with: my @myArray = qw/ c b b c c c c /;
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Mon, 13 Jan 2003 12:21:23 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: finding largest repeat values in array
Message-Id: <slrnb260t3.3jc.tadmc@magna.augustmail.com>
Tad McClellan <tadmc@augustmail.com> wrote:
> ctcgag@hotmail.com <ctcgag@hotmail.com> wrote:
>> Andrew Lee wrote:
>>> That won't work unless you have reset $[ (a soon to be deprectaed
>>> "feature").
>>
>> Other than the missing $s, which $[ won't affect, why won't it work?
Doh! I forgot about your "array is sorted" assumption...
> Try it with: my @myArray = qw/ c b b c c c c /;
... so never mind that.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Mon, 13 Jan 2003 09:42:52 -0600
From: Cameron Dorey <camerond@mail.uca.edu>
Subject: Re: FULL VERSION: Hi all gurus. What is wrong in my script?
Message-Id: <3E22DE7C.4020807@mail.uca.edu>
juha wrote:
> I need to check if the file is complity on my disk from FTP program.
> So I check the file's size and wait a while and check it again. If
> size is same as firts time, file is ready for action, else do nothing.
> Here is what I can't get work:
>
> while (<TEXTFILE>) {
> $size1 = -s "/temp/$_";
> system('sleep 20');
> $size2 = -s "/temp/$_";
>
> if ($size1 = $size2 ) {
>
> do something;
> }
>
> }
>
> Why this woun't work ?
You obviously did not use the -w switch or use warnings; (not sure of
capitalization here) and use strict; in your script. If you had, Perl
would have told you automatically.
Cameron
--
Cameron Dorey
Associate Professor of Chemistry
University of Central Arkansas
Phone: 501-450-5938
camerond@mail.uca.edu
------------------------------
Date: Mon, 13 Jan 2003 10:08:35 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: FULL VERSION: Hi all gurus. What is wrong in my script?
Message-Id: <slrnb25p43.35c.tadmc@magna.augustmail.com>
Cameron Dorey <camerond@mail.uca.edu> wrote:
> juha wrote:
>> if ($size1 = $size2 ) {
> You obviously did not use the -w switch or use warnings; (not sure of
> capitalization here) and use strict; in your script. If you had, Perl
> would have told you automatically.
If you are referring to the mistake in the line of code above,
then warnings won't help.
That statement does not generate a warning.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Mon, 13 Jan 2003 15:00:20 GMT
From: Charlton Wilbur <cwilbur@mithril.chromatico.net>
Subject: Re: How does one determine why perl prog runs so slow????
Message-Id: <87smvxumkd.fsf@mithril.chromatico.net>
>>>>> "BM" == Bob Mariotti <R.Mariotti@FinancialDataCorp.com> writes:
BM> It also has been my experience that not all persons involved
BM> in perl can spend their entire waking hours concentrating on
BM> an issue.
Exactly. Which is why we sometimes answer questions with 'perldoc -q
keyword' instead of taking the time to write out an extensive answer
on our own. There are a lot of perldocs, and finding the information
you want in them is a skill that can take some time to pick up.
I can quite easily bill for my time, and you aren't paying me. I'm
doing this out of the goodness of my heart. You really want me to
rewrite entire swaths of the perldocs in my own words just because you
feel insulted when someone answers a question with a pointer to docs?
Get a grip.
BM> So, please, those of you on high horses... get the HELL down
BM> to earth where reality is. And if you don't like to help
BM> someone who might not possess the exact piece of knowledge the
BM> you think you do, then move on to the next topic. It's THAT
BM> easy.
Offering a brief reference to the place in the documentation that s/he
can find the answer s/he is looking for *is* helping someone who might
not possess the exact piece of knowledge that I do. It's THAT easy.
Charlton
------------------------------
Date: Mon, 13 Jan 2003 09:26:49 -0600
From: Lars Eighner <eighner@io.com>
Subject: Re: How does one determine why perl prog runs so slow????
Message-Id: <slrnb25moh.ii8.eighner@dumpster.io.com>
In our last episode,
<3e1f9aaf.7348417@news.cshore.com>,
the lovely and talented Bob Mariotti
broadcast on comp.lang.perl.misc:
> Honestly! I HAVE searched this group, other perl sites, perlfaqs, etc
> and I cannot find anything that actually covers this topic. It IS
> perl so I'm posting in the perl group.
You wouldn't happen to be using objects, would you? Or
object type modules? There is no surer way to turn a
computer into a doorstop.
I suggest learning to do real programming, and doing stuff
yourself. Objects are for morons who can't be trusted to do
the right thing with library functions otherwise. You don't
see training wheels on Lance Armstrong's bike, and you won't
see objects in efficient programs. Leave the modules alone.
They will seldom do exactly what you want, anyway, and they
are written by grad students who are long on theory and
short on the skills required to write efficient programs.
--
Lars Eighner -finger for geek code- eighner@io.com http://www.io.com/~eighner/
Dynamic linking error: Your mistake is now everywhere.
------------------------------
Date: Mon, 13 Jan 2003 17:04:27 +0100
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: How does one determine why perl prog runs so slow????
Message-Id: <Pine.LNX.4.40.0301131650100.10976-100000@lxplus071.cern.ch>
On Jan 12, Bob Mariotti inscribed on the eternal scroll:
[demonstrates his usenet ineptness by quoting Tad's entire posting
including .sig...]
> And, now for my own two cents: Having been a top level programmer
> for over 25 years and for the last 10 years concentrating on the *nix
> environment I have been using perl since 1996. I am also a member of
> the Hartford Perl Mongers and also attended some Boston PM meetings.
I'm sure we're all duly impressed and humbled. So what's your excuse
for not making yourself sufficiently familar with the core resources
of Perl to be able to find your way around them? And what's your
excuse for turning abusive when pointed to the appropriate place in
them?
> Usenet is one of the best resources I have ever seen in all my years.
> I read many groups daily (even on weekends) and if I feel qualified to
> provide a meaningful answer to someone's question I do so willingly
> hoping to make that persons task somewhat easier.
Let's hope you don't offer one-off ad hoc answers to questions that
have already been researched and the answers peer-reviewed in the form
of FAQs.
> I also thing that I personally have funded much of O'Reilley's empire
> based solely on the number of their titles I have purchased. So,
> published/printed documentation is NOT foreign to me. In addition to
> usenet I also frequent several private tech support sites (i.e.:
> tek-tips and others). Again, give and take is the way it works.
Which is why some folks put a deal of effort into collating and
improving FAQs, and get frustrated when (a) respondents march up and
give one-off answers which almost always turn out to be lower-quality
than the FAQs that they're hiding, and (b) questioners come back and
start whining at the very suggestion that they might read those FAQ
answers for themselves instead of getting one-off answers composed for
them.
> So, please, those of you on high horses...
Please, don't change your posting address.
bye
------------------------------
Date: 13 Jan 2003 12:03:03 -0500
From: Joe Schaefer <joe+usenet@sunstarsys.com>
Subject: Re: How does one determine why perl prog runs so slow????
Message-Id: <m3of6lhtiw.fsf@mumonkan.sunstarsys.com>
Lars Eighner <eighner@io.com> writes:
> You wouldn't happen to be using objects, would you? Or
> object type modules? There is no surer way to turn a
> computer into a doorstop.
Perl's object model hasn't changed significantly between 5.005
and 5.8. I doubt it is to blame for the performance lag here.
What may be to at fault is the new utf8 stuff, which can have a
drastic impact on regexp performance. Or maybe something funny
is going on in the new, improved PerlIO system. Who knows?
Other than arbitrary guessing, a reasonable way for OP to determine
the problem is by analyzing the slowest sections of his code. But
you usually need to run a profiler to figure out where those sections
are.
--
Joe Schaefer "I was gratified to be able to answer promptly, and I did. I
said I didn't know."
--Mark Twain
------------------------------
Date: Mon, 13 Jan 2003 16:01:45 +0100
From: ZZT <a@b.c>
Subject: Re: How to check responce on specific tcp-ports?
Message-Id: <avukcp$7ln$1@news1.wdf.sap-ag.de>
Josef Möllers wrote:
> This is called a port scan.
> It is very rude, to say the least.
> Not giving your real name indicates that you know that.
thanks for your answer, but didn't help to much.
Believe it or not but there are reasonable tasks for checking port, for
instance if you want to detect that a service is running.
If I would like to do a port-scan I wouldn't use perl!
bye
------------------------------
Date: Mon, 13 Jan 2003 17:55:59 +0100
From: ZZT <a@b.c>
Subject: Re: How to check responce on specific tcp-ports?
Message-Id: <avur2v$d65$1@news1.wdf.sap-ag.de>
I found a very simple solution :)
use IO::Socket;
$remote = IO::Socket::INET->new(
Proto => "tcp",
PeerAddr => $server,
PeerPort => $port,
)
or die "cannot connect to $port at $server";
close $remote;
------------------------------
Date: Mon, 13 Jan 2003 18:01:02 +0100
From: pauli@johannes-pauli.de
Subject: Re: how to redirect STDIN to such place like /dev/null ??
Message-Id: <3E22F0CE.AF254227@johannes-pauli.de>
oooooops wrote:
> I set up a script for catching output of a pipe
> from aother program as following.
> but I can not close the STDIN
Why do you want to close STDIN anyway?
>
> or just redirect else behind double "\n"
> input. if I run it with
> $perl to_file.pl
> I have to type three time enter to end
> the script, but there is only two "\n"
> in the file catched. I am confused with it.
Me too, because it takes two "\n" to finish the programm on my linux
box.
>
>
> could you give me some advice ??
>
> Thanks!!
>
> [test@mail test]$ less to_file.pl
> #!/usr/bin/perl -w
>
> use strict;
>
> my $i;
> open (DEST, ">>/home/test/testfile.dat")||die "$!";
> $i=0;
> OUTER: while (<STDIN>){
> if ($_ eq "\n" && $i==1){
> # close STDIN;
> last OUTER;
> }elsif($_ eq "\n" && $i==0){
> $i=1;
> }else{
> $i=0;
> }
> print DEST $_;
> }
> close (DEST);
--
PI4: Wir forschen gern!
\\|//
(. .)
------------------------------oOOo-(_)-oOOo---------------------
Johannes Pauli
Physikalisches Institut IV
Erwin-Rommel-Str. 1
91058 Erlangen
Germany
-o) | Tel. : ++49-(0)9131-852-7153
/\\ | Web : http://www.johannes-pauli.de
_\_v | email : pauli@johannes-pauli.de
------------------------------
Date: Mon, 13 Jan 2003 10:11:47 -0500
From: Jim Agnew <jpagnew@vcu.edu>
Subject: Re: Isogest 3.1 New release
Message-Id: <3E22D733.2BB051C1@vcu.edu>
would it work with sun-os and ibm's db2???
jim
Clay Irving wrote:
>
> In article <avkuge$fuu$1@lacerta.tiscalinet.it>, Dante Ortolani wrote:
> > Hi,
> > you can try on line by a demo the last release of my software written in
> > pure perl.
> > Isogest is a Office Suite that work with Mysql or Postgres.
> >
> > Site http://isogest.sourceforge.net/
> > Demo http://isogest.sourceforge.net/Demo/
>
> Which gives:
>
> Internal Server Error
> The server encountered an internal error or misconfiguration and was unable
> to complete your request.
>
> --
> Clay Irving <clay@panix.com>
> IMMODEST, adj. Having a strong sense of one's own merit, coupled with a
> feeble conception of worth in others.
> - Ambrose Bierce
------------------------------
Date: Mon, 13 Jan 2003 18:50:52 GMT
From: ramm <invalid@invalid.com>
Subject: Re: Match-time code evaluation
Message-Id: <4j262vs3udppd6vtmvuqpjltsqua3gq3a3@4ax.com>
On Sun, 12 Jan 2003 13:09:32 GMT, ramm <invalid@invalid.com> wrote:
Thank you everybody, it makes much more sense now! Sorry for the
missing book reference.
------------------------------
Date: Mon, 13 Jan 2003 14:54:41 +0100
From: Koos Pol <koos_pol@NO.nl.JUNK.compuware.MAIL.com>
Subject: Re: My, our, etc.
Message-Id: <newscache$5znn8h$y49$1@news.emea.compuware.com>
Simon Andrews wrote (Monday 13 January 2003 14:35):
>> "Koos Pol" <koos_pol@NO.nl.JUNK.compuware.MAIL.com> wrote in message
>> news:newscache$u43i8h$cb7
Just to make the remark you are replying/quoting on a follow up iso the real
thing. That big chunk is not mine.
Cheers,
--
KP
------------------------------
Date: Mon, 13 Jan 2003 10:13:23 -0500
From: Jim Agnew <jpagnew@vcu.edu>
Subject: Re: My, our, etc.
Message-Id: <3E22D793.DD683DD9@vcu.edu>
Thank you guys, for this very, very timely article. it helped greatly,
and would like to ack you all.
jim
Jay Tilton wrote:
>
> "Richard S Beckett" <spikey-wan@bigfoot.com> wrote:
>
> : In fact, as
> : long as they're not duplicated, what's wrong with our anyway, just to be on
> : the safe side?
>
> The "as long as they're not duplicated" part is a big issue.
> _The_ issue, in fact.
>
> Writing a program while manually ensuring that variables do not get
> clobbered is hard.
>
> Writing a program (or portion thereof) where variables have guaranteed
> privacy and cannot get clobbered is easy.
>
> Defensive programming is where it's at, cat.
------------------------------
Date: Mon, 13 Jan 2003 16:37:57 -0000
From: "Richard S Beckett" <spikey-wan@bigfoot.com>
Subject: Re: My, our, etc.
Message-Id: <avuq2o$1l1$1@newshost.mot.com>
> [snip a couple of other forms of the same problem]
> > <test2.pl>
> > use strict;
> > use warnings;
> > use Tk;
> > our ($frame, $entry);
> > $entry = $frame -> Entry (
> > -validatecommand => \&valid_routine,
> > -invalidcommand => sub {
> > print "invalid entry, try again\n";
> > $entry -> focus;}
> > ) -> pack ();
> > <test2.pl>
> >
> > Can't call method "Entry" on an undefined value at test2.pl line 10.
[Which
> > we'll call success, in this instance.]
>
> But it isn't a success - you've just managed to generate a slightly
> different fatal warning! You have exactly the same problems in the last
> example as you had in the others, just shuffled around a bit!
>
> Perl is desperately trying to tell you you're in trouble and you need to
> listen to it :-)
I'm sorry, I didn't realise you would take me so literally.
I started this thread, because I posted a sample of my code when I had
another problem. In the sample I quoted, I predeclared my varoables with
our, and got told off for it. I was wondering why?
Some of my variables get written to a text file, and can be imported later,
with the "do filename;" command. These variables must be predefined with
'our' otherwise they don't work.
However at another point in my script, I tried to use my, as told, but
couldn't get it to work. Here's another sample of the problem. Run the
script as is, and you will get the following error:
Global symbol "$entry" requires explicit package name at D:\Perl\My
Scripts\Working\my-our.pl line 28.
Execution of D:\Perl\My Scripts\Working\my-our.pl aborted due to compilation
errors.
======
use strict;
use warnings;
use Tk;
my $main_window = MainWindow -> new ();
$main_window -> Label(
-text=> 'A window',
-relief => "ridge",
-borderwidth => "5",
-background => "blue",
-foreground => "white",
)
->pack (
-side => "top",
-fill => "x",
-expand => 'both',
-padx => "1",
);
my $frame = $main_window -> Frame ()
-> pack (
-side => "top",
-fill => "both",
-expand => "both",
);
my $entry = $frame -> Entry (
-validatecommand => \&valid_routine,
-invalidcommand => sub {
print "invalid entry, try again\n";
$entry -> focus;}
) -> pack ();
MainLoop;
======
If you then change this line:
my $entry = $frame -> Entry (
to this:
our $entry = $frame -> Entry (
You will get the following error:
Variable "$entry" is not imported at D:\Perl\My Scripts\Working\my-our.pl
line 28.
Global symbol "$entry" requires explicit package name at D:\Perl\My
Scripts\Working\my-our.pl line 28.
Execution of D:\Perl\My Scripts\Working\my-our.pl aborted due to compilation
errors.
If you then change this line:
our $entry = $frame -> Entry (
to this:
our $entry;
$entry = $frame -> Entry (
The script works fine.
SO....Why shouldn't I just predeclare all my variables with 'our', so that I
don't have to worry about whether my variables will be accepted.
Note: This is a variable and 'my', 'our' problem, not a Tk problem.
Thanks.
R.
------------------------------
Date: Mon, 13 Jan 2003 16:51:56 -0000
From: "Richard S Beckett" <spikey-wan@bigfoot.com>
Subject: Re: My, our, etc.
Message-Id: <avuqsu$24i$1@newshost.mot.com>
"Jim Agnew" <jpagnew@vcu.edu> wrote in message
news:3E22D793.DD683DD9@vcu.edu...
> Thank you guys, for this very, very timely article. it helped greatly,
> and would like to ack you all.
>
> jim
>
> Jay Tilton wrote:
> >
> > "Richard S Beckett" <spikey-wan@bigfoot.com> wrote:
> >
> > : In fact, as
> > : long as they're not duplicated, what's wrong with our anyway, just to
be on
> > : the safe side?
> >
> > The "as long as they're not duplicated" part is a big issue.
> > _The_ issue, in fact.
> >
> > Writing a program while manually ensuring that variables do not get
> > clobbered is hard.
> >
> > Writing a program (or portion thereof) where variables have guaranteed
> > privacy and cannot get clobbered is easy.
> >
> > Defensive programming is where it's at, cat.
Oh dear!! I've just seen this post. Unfortunately I haven't seen the post it
referrs to.
A quick brows on google reveals that there are far more posts in this thread
than my news server seems to have, so if I came across as really stupid [1]
or rude to anyone, I apologise. I'm just nipping off to google to read _all_
the posts before I make an even bigger pillock of myself than necessary ;-)
Thanks for your replies [2], and sorry.
R.
[1] I'm only _quite_ stupid ;-)
[2] Even though I've yet to read them.
------------------------------
Date: Mon, 13 Jan 2003 18:18:59 +0000 (UTC)
From: mauzo@mimosa.csv.warwick.ac.uk (Ben Morrow)
Subject: Re: My, our, etc.
Message-Id: <avuvuj$q1f$1@wisteria.csv.warwick.ac.uk>
"Richard S Beckett" <spikey-wan@bigfoot.com> wrote:
>Some of my variables get written to a text file, and can be imported later,
>with the "do filename;" command. These variables must be predefined with
>'our' otherwise they don't work.
In general, this is a bad way to do this. You're much better off using
Storable.pm (standard with 5.8, otherwise install from CPAN) or one of the
other modules which do this sort of thing. Apart from anything else, they work
correctly with my() variables :). But also, you have to be _very_ sure that
noone else is going to modify your text file: what if someone managed to insert
system("rm -rf /"); at the top?
>However at another point in my script, I tried to use my, as told, but
>couldn't get it to work. Here's another sample of the problem. Run the
>script as is, and you will get the following error:
>
>Global symbol "$entry" requires explicit package name at D:\Perl\My
>Scripts\Working\my-our.pl line 28.
>Execution of D:\Perl\My Scripts\Working\my-our.pl aborted due to compilation
>errors.
>
<snip>
>
>If you then change this line:
>my $entry = $frame -> Entry (
>to this:
>our $entry = $frame -> Entry (
>
>You will get the following error:
>
>Variable "$entry" is not imported at D:\Perl\My Scripts\Working\my-our.pl
>line 28.
>Global symbol "$entry" requires explicit package name at D:\Perl\My
>Scripts\Working\my-our.pl line 28.
>Execution of D:\Perl\My Scripts\Working\my-our.pl aborted due to compilation
>errors.
>
>If you then change this line:
>our $entry = $frame -> Entry (
>to this:
>our $entry;
>$entry = $frame -> Entry (
>
>The script works fine.
>
>SO....Why shouldn't I just predeclare all my variables with 'our', so that I
>don't have to worry about whether my variables will be accepted.
I believe I've answered this question already. The problem is not my/our, but
the fact that if you look at the line in question:
>my $entry = $frame -> Entry (
> -validatecommand => \&valid_routine,
> -invalidcommand => sub {
> print "invalid entry, try again\n";
> $entry -> focus;}
^^^^^^
> ) -> pack ();
you will see that you use $entry in the RHS. As the RHS of an assignment is
evaluated before the LHS, neither my $entry = or our $entry = will work under
strictures (and _not_ under strictures, you'll get a result you didn't expect,
at least with my). The answer is to declare the variable before you use it, as
you seem to have worked out, and this will work perfectly well with either my
or our. Thus, you should use my, as it scopes the variable properly.
[Question to those who know more about this than me: will the code even work
with our? I was under the impression that a variable had to be my for a closure
to properly keep a hold of it, and thus that code (which will presumably be
called from package Tk somewhere) would not then refer to $main::entry but
$Tk::summat::entry? Or am I misunderstanding?]
>Note: This is a variable and 'my', 'our' problem, not a Tk problem.
No, this is an I-didn't-read-the-answer-last-time problem. :)
Ben
------------------------------
Date: 13 Jan 2003 09:18:19 -0800
From: jhalbrook@bjc.org (Joe Halbrook)
Subject: Newbie - how to tell if module installed ...
Message-Id: <8105bd43.0301130918.256cd4ec@posting.google.com>
Wouldn't the code need to look like this:
if (eval{ require MIME::QuotedPrint; import MIME::QuotedPrint; }) {
# Not installed actions
} else {
# Installed actions
}
.
.
.
Andras Malatinszky <nobody@dev.null> wrote in message news:<3E223E0B.6010909@dev.null>...
> Joe Halbrook wrote:
>
> > I know this has been asked a zillion times, but how
> > can I tell if a particular package is installed?
> >
> >
>
> A package and a module are not the same thing. I'll assume you are
> talking about modules.
>
> Suppose you want to find out if module Foo::Bar is installed. Write a
> script with just
>
> require Foo::Bar;
>
> in it and run it. If it runs OK, then Foo::Bar is installed; otherwise
> perl will complain that it "Can't locate Foo/Bar.pm in @INC" (@INC being
> the array containing the locations where perl checked for the presence
> of Foo::Bar).
>
> Of course, this is a fatal error, and you may want to handle the absence
> of Foo::Bar more gracefully. If that's the case, use the eval() function
> like this:
>
> if (eval{require Foo::Bar; import Foo::Bar}){
> #Foo::Bar is there, so we can use its features:
> my $enigma = new Foo::Bar; #Creating fictitious
> #object with Foo::Bar
> my $answer=$enigma->{'answer'}; #More fictitious syntax
> #involving Foo:Bar
> } else {
> #Sorry, no Foo::Bar
> my $answer=42; #We'll just have to guess the answer
>
> }
------------------------------
Date: Mon, 13 Jan 2003 14:14:39 GMT
From: Fred <No_Mail_Address@cox.net>
Subject: Re: ppm query
Message-Id: <3E22CA4D.1B7B3D28@cox.net>
Ingo Wiarda wrote:
>
> Fred wrote:
>
>> (SNIP)
>
> Have you tried "ppm" at the prompt? This should start ppm in interactive
> mode. A following 'query foo' will be displayed page by page.
>
> Ingo
Thank you, that made the difference: If I first enter the ppm shell
and then type
query <enter>,
then I get the response screen by screen...
---
Fred
------------------------------
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.
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 4394
***************************************