[19610] in Perl-Users-Digest
Perl-Users Digest, Issue: 1805 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Sep 24 14:05:31 2001
Date: Mon, 24 Sep 2001 11:05:11 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <1001354711-v10-i1805@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Mon, 24 Sep 2001 Volume: 10 Number: 1805
Today's topics:
Re: a bit of help please. (Matt Williams)
Re: a bit of help please. <na>
Re: a bit of help please. <dtweed@acm.org>
Re: a bit of help please. <na>
Re: a bit of help please. <na>
Re: a bit of help please. <tinamue@zedat.fu-berlin.de>
Re: ANNOUNCE: grepmail 4.51 released lvirden@yahoo.com
ANNOUNCE: HTML-Toc-0.91 <fvu@fvu.myweb.nl>
Re: As simply as I can put it.. <jurgenex@hotmail.com>
Re: As simply as I can put it.. nobull@mail.com
Checking for an empty hash?? <aperlprogrammer@yahoo.com>
Re: Checking for an empty hash?? <aperlprogrammer@yahoo.com>
Re: Creating a file (Mark Jason Dominus)
Re: Creating a file (Mark Jason Dominus)
Re: eval-statement fools garbage-collection ? <joe+usenet@sunstarsys.com>
Re: eval-statement fools garbage-collection ? nobull@mail.com
How do I compare strings? (Dimitri)
Re: How to remove whitespace without losing the 'real' nobull@mail.com
K shell to perl translator ? <neil@thump.org>
Looking for OO/AUTOLOAD info (Aaron Sherman)
Re: Net::DNS doesn't work when trying to query a namese <Usenet@bNamed.be>
Re: Net::FTP and AIX (Brian Duffy)
Re: Net::FTP and AIX (Brian Duffy)
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 24 Sep 2001 08:10:43 -0700
From: mwilliams@uk.ibm.com (Matt Williams)
Subject: Re: a bit of help please.
Message-Id: <5f5140d2.0109240710.5e5096f7@posting.google.com>
try this i know its a bit crude for those ready to criticise but here it is.
#! /usr/bin/perl -w
my $time = time;
my $seconds = 1;
my $minutes = 0;
while (1) {
if (time > $time) {
if ($seconds > 1) {
print "$minutes Mins and $seconds seconds.\n";
}
else {
print "$minutes Mins and $seconds second.\n";
}
$seconds++;
if ($seconds == 60) {
$minutes++;
$seconds = 0;
}
$time = time;
}
}
"NEWS" <na> wrote in message news:<3baf12aa$0$227$ed9e5944@reading.news.pipex.net>...
> hey there everybody, im new to perl and want to write a basic script that
> just counts up in seconds. doesn't sound too complicated, but i'll be
> ****ed if i have any idea of how to do it.
>
> anybody out there who can help ?
>
> cheers
>
> chris
------------------------------
Date: Mon, 24 Sep 2001 16:18:39 +0100
From: "NEWS" <na>
Subject: Re: a bit of help please.
Message-Id: <3baf4ed2$0$233$ed9e5944@reading.news.pipex.net>
i like crude. cheers
"Matt Williams" <mwilliams@uk.ibm.com> wrote in message
news:5f5140d2.0109240710.5e5096f7@posting.google.com...
> try this i know its a bit crude for those ready to criticise but here it
is.
>
> #! /usr/bin/perl -w
>
> my $time = time;
> my $seconds = 1;
> my $minutes = 0;
>
> while (1) {
> if (time > $time) {
> if ($seconds > 1) {
> print "$minutes Mins and $seconds seconds.\n";
> }
> else {
> print "$minutes Mins and $seconds second.\n";
> }
> $seconds++;
> if ($seconds == 60) {
> $minutes++;
> $seconds = 0;
> }
> $time = time;
> }
> }
>
> "NEWS" <na> wrote in message
news:<3baf12aa$0$227$ed9e5944@reading.news.pipex.net>...
> > hey there everybody, im new to perl and want to write a basic script
that
> > just counts up in seconds. doesn't sound too complicated, but i'll be
> > ****ed if i have any idea of how to do it.
> >
> > anybody out there who can help ?
> >
> > cheers
> >
> > chris
------------------------------
Date: Mon, 24 Sep 2001 15:23:18 GMT
From: Dave Tweed <dtweed@acm.org>
Subject: Re: a bit of help please.
Message-Id: <3BAF4EA1.6FC17682@acm.org>
NEWS wrote:
> thanks that is really handy, but for example how would i make the
> clock/timer count in 10's but by the second?
>
> 10
> 20
> 30
> 40 would be 4 secs
>
> but replacing the previous output rather than with a new line ?
Do you understand what I wrote? Do you understand Perl at all?
Obviously, you'd just multiply the printed value by 10.
my $start = time;
$| = 1; # force flushing of output
while (1) {
print "\r", 10*(time - $start);
sleep(1);
}
Note that on most systems, sleep pauses the script for *at least* the
number of seconds given, although on some older systems, it may sleep
for up to one second less. Depending on sleep alone to pace a script
is not going to be very accurate over the long term, especially if the
system is relatively busy with other processes.
Note that you could eliminate the sleep in the above script, and it
would still work correctly. However, it would be consuming a lot of
CPU time refreshing the display a fast as possible, even though the
value only changes once a second. If you don't like the fact that it
occasionally skips a value, you could use select to pause the script
for 0.1 or 0.2 seconds at a time and refresh the display 5-10 times
a second.
I'm not sure what you mean by "replacing the previous output". The
technique shown here causes each value to overstrike the previous
in the console window. Maybe you should tell us exactly what you're
trying to accomplish.
-- Dave Tweed
------------------------------
Date: Mon, 24 Sep 2001 16:30:57 +0100
From: "NEWS" <na>
Subject: Re: a bit of help please.
Message-Id: <3baf51b4$0$232$ed9e5944@reading.news.pipex.net>
errr TOFU ????????????????/
"Tina Mueller" <tinamue@zedat.fu-berlin.de> wrote in message
news:9ondsu$dm3e1$1@fu-berlin.de...
> please don't TOFU.
>
> NEWS <na> wrote:
> > thanks that is really handy, but for example how would i make the
> > clock/timer count in 10's but by the second?
>
> > 10
> > 20
> > 30
> > 40 would be 4 secs
>
> > but replacing the previous output rather than with a new line ?
>
> $|=1;
> my $i=0;
> while(1) {
> $i+=10;
> print "\r$i";
> sleep 1
> }
>
> hth, tina
>
> --
> http://www.tinita.de \ enter__| |__the___ _ _ ___
> tina's moviedatabase \ / _` / _ \/ _ \ '_(_-< of
> search & add comments \ \ _,_\ __/\ __/_| /__/ perception
------------------------------
Date: Mon, 24 Sep 2001 16:47:18 +0100
From: "NEWS" <na>
Subject: Re: a bit of help please.
Message-Id: <3baf5589$0$238$ed9e5944@reading.news.pipex.net>
no i dont - hence the opening lines of "im new to perl" just trying to learn
by using online info and comparing scripts to see what they do and how they
do it.
if you can offer advice without getting on your high horse, then dont offer
advise at all.
"Dave Tweed" <dtweed@acm.org> wrote in message
news:3BAF4EA1.6FC17682@acm.org...
> NEWS wrote:
> > thanks that is really handy, but for example how would i make the
> > clock/timer count in 10's but by the second?
> >
> > 10
> > 20
> > 30
> > 40 would be 4 secs
> >
> > but replacing the previous output rather than with a new line ?
>
> Do you understand what I wrote? Do you understand Perl at all?
> Obviously, you'd just multiply the printed value by 10.
>
> my $start = time;
> $| = 1; # force flushing of output
> while (1) {
> print "\r", 10*(time - $start);
> sleep(1);
> }
>
> Note that on most systems, sleep pauses the script for *at least* the
> number of seconds given, although on some older systems, it may sleep
> for up to one second less. Depending on sleep alone to pace a script
> is not going to be very accurate over the long term, especially if the
> system is relatively busy with other processes.
>
> Note that you could eliminate the sleep in the above script, and it
> would still work correctly. However, it would be consuming a lot of
> CPU time refreshing the display a fast as possible, even though the
> value only changes once a second. If you don't like the fact that it
> occasionally skips a value, you could use select to pause the script
> for 0.1 or 0.2 seconds at a time and refresh the display 5-10 times
> a second.
>
> I'm not sure what you mean by "replacing the previous output". The
> technique shown here causes each value to overstrike the previous
> in the console window. Maybe you should tell us exactly what you're
> trying to accomplish.
>
> -- Dave Tweed
------------------------------
Date: 24 Sep 2001 16:08:07 GMT
From: Tina Mueller <tinamue@zedat.fu-berlin.de>
Subject: Re: a bit of help please.
Message-Id: <9onlp7$e7bis$1@fu-berlin.de>
NEWS <na> wrote:
> errr TOFU ????????????????/
sorry, this is german and means Text Oben, Fullquote unten =
Text at the top, fullquote at the bottom.
i'm so used to this i forgot that english people
wouldn't understand...
please place your answer below the quote, and stripe verything
unneeded.
just like i did.
regards,
tina
--
http://www.tinita.de \ enter__| |__the___ _ _ ___
tina's moviedatabase \ / _` / _ \/ _ \ '_(_-< of
search & add comments \ \ _,_\ __/\ __/_| /__/ perception
------------------------------
Date: 24 Sep 2001 18:01:56 GMT
From: lvirden@yahoo.com
Subject: Re: ANNOUNCE: grepmail 4.51 released
Message-Id: <9onsek$1mr$1@srv38.cas.org>
According to Edward Avis <epa98@doc.ic.ac.uk>:
:strongly associated with Perl. The user doesn't need to know Perl to
:use it, or even care what language it is implemented in. There's no
:real point, IMHO, to a collection of programs with no common feature
:other than that they are written in Perl. Except as a source of
:examples and inspiration.
If perl were the only strong programming language one had on their
platform (say some kind of platform on 95% of desktops across the platform
if you listen to one large company in the USA NorthWest),
then it becomes very important to know the language in which an
app is written - as well as important to find a repository of applications
in that language...
--
--
"I know of vanishingly few people ... who choose to use ksh." "I'm a minority!"
<URL: mailto:lvirden@cas.org> <URL: http://www.purl.org/NET/lvirden/>
Even if explicitly stated to the contrary, nothing in this posting
------------------------------
Date: Thu, 20 Sep 2001 21:44:35 +0200
From: "Freddy Vulto" <fvu@fvu.myweb.nl>
Subject: ANNOUNCE: HTML-Toc-0.91
Message-Id: <tquo1m2f11uv66@corp.supernews.com>
NAME
HTML::Toc - Generate, insert and update HTML Table of Contents. Features
numbered tokens, multiple ToCs, customizable ToC tags and token tags.
DESCRIPTION
HTML::Toc consists out of the following packages:
HTML::Toc
HTML::TocGenerator
HTML::TocInsertor
HTML::TocUpdator
HTML::Toc is the object which will eventually hold the Table of Contents.
HTML::TocGenerator does the actual generation of the ToC. HTML::TocInsertor
handles the insertion of the ToC in the source. HTML::TocUpdator takes care
of updating previously inserted ToCs.
HTML::Parser is the base object of HTML::TocGenerator, HTML::TocInsertor and
HTML::TocUpdator. Each of these objects uses its predecessor as its
ancestor, as shown in the UML diagram underneath:
+---------------------+
| HTML::Parser |
+---------------------+
+---------------------+
| +parse() |
| +parse_file() |
+----------+----------+
/_\
|
+----------+----------+ <<uses>> +-----------+
| HTML::TocGenerator + - - - - - -+ HTML::Toc |
+---------------------+ +-----------+
+---------------------+ +-----------+
| +extend() | | +clear() |
| +extendFromFile() | | +format() |
| +generate() | +-----+-----+
| +generateFromFile() | :
+----------+----------+ :
/_\ :
| :
+----------+----------+ <<uses>> :
| HTML::TocInsertor + - - - - - - - - -+
+---------------------+ :
+---------------------+ :
| +insert() | :
| +insertIntoFile() | :
+----------+----------+ :
/_\ :
| :
+----------+----------+ <<uses>> :
| HTML::TocUpdator + - - - - - - - - -+
+---------------------+
+---------------------+
| +insert() |
| +insertIntoFile() |
| +update() |
| +updateFile() |
+---------------------+
When generating a ToC you'll have to decide which object you want to use:
TocGenerator:
for generating a ToC without inserting the ToC into the source
TocInsertor:
for generating a ToC and inserting the ToC into the source
TocUpdator:
for generating and inserting a ToC, removing any previously
inserted ToC elements
Thus in tabular view, each object is capable of:
generating inserting updating
---------------------------------
TocGenerator X
TocInsertor X X
TocUpdator X X X
EXAMPLE
The code underneath will generate a ToC of the HTML headings <h1>..<h6> from
a file index.htm:
use HTML::Toc;
use HTML::TocGenerator;
my $toc = HTML::Toc->new();
my $tocGenerator = HTML::TocGenerator->new();
$tocGenerator->generateFromFile($toc, 'index.htm');
print $toc->format();
For example, with index.htm containing:
<html>
<body>
<h1>Chapter</h1>
</body>
</html>
the output will be:
<!-- Table of Contents generated by Perl - HTML::Toc -->
<ul>
<li><a href=#h-1>Chapter</a>
</ul>
<!-- End of generated Table of Contents -->
AVAILABILITY
HTML::Toc has been uploaded to CPAN and is also available from:
http://fvu.myweb.nl/Projects/HtmlToc/Web/index.htm
Freddy Vulto
------------------------------
Date: Mon, 24 Sep 2001 08:28:24 -0700
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: As simply as I can put it..
Message-Id: <3baf511b@news.microsoft.com>
"Kalle Anka" <Kalle Anka@markisspecialisten.com> wrote in message
news:MeFr7.3207$aM.135472@newsc.telia.net...
Your problem is a lot clearer now, much appreciated.
> $filename is a file where the e-meil addresses are stored.
Actually (according to your code below) it contains only the filename of the
file with the email addresses. This is an important difference.
> $email is the "stand in" from a form, where you can type your address to
get
> it removed.
> Im using "use strict" in my script.
> Im letting my visitors to delete their e-meil addresses from my list.
> The e-mail addresses are written like this:
> karl@kalles.se<br>
> kalle@kalles.se<br>
> The big Q is how to delete the address line in $filename only if you match
> all the letters, not just the first ones.
Just to be on the safe side (I figure English is not your native languague):
I guess you meant "only if you match all the __characters__" (instead of
"all the letters"). So you want to identify lines, which are a 100% match
with the text the user entered.
> open (INFILE, "$filename") or die "Haha.': $!";
> my $line;
> while (<INFILE>) {
> chomp; # drops trailing newlines; can omit if undesirable
> $line = $_, last if /^\Q$email/i && ! /^$/; # substr match!
Personally I think a regular expression (RE) is overkill and doesn't do what
you want it to do. You want to match only if you found an identical line.
That is easier to do with a simple "eq" comparision.
The "<br>" at the end of each line in your data file is annoying, but not a
problem (can't you get rid of it?):
$line=$_, last if ($_ eq "$email<br>");
> }
>
> close INFILE;
> print "Your e-mail address is now deleted from our list.<br>\n\n" if
> defined $line;
>
> print "Your e-mail address do not exist in our list.<br>\n\n" unless
> defined $line;
In the rest of your code I don't see anything that actually modifies the
original file.
You need to write back your changes to the file, otherwise they will be lost
when you end the program.
You may want to read up on
perldoc -q "delete a line"
jue
------------------------------
Date: 24 Sep 2001 17:36:45 +0100
From: nobull@mail.com
Subject: Re: As simply as I can put it..
Message-Id: <u9g09cwnoi.fsf@wcl-l.bham.ac.uk>
"Kalle Anka" <Kalle Anka@markisspecialisten.com> writes:
> Subject: As simply as I can put it..
Please use your subject line to give real info about the subject of
your post and _not_ useless metainformation.
Anyhow you do not appear to have tried to reduce the question to its
simplest form.
> $filename is a file where the e-meil addresses are stored.
> $email is the "stand in" from a form, where you can type your address to get
> it removed.
> Im using "use strict" in my script.
> Im letting my visitors to delete their e-meil addresses from my list.
This sounds suspiciously like you are implementing an opt-out mailing
list. Do not do this.
> The e-mail addresses are written like this:
> karl@kalles.se<br>
> kalle@kalles.se<br>
That's all noise. The fact that the strings are lines of the file, or
that the file is a list of e-mail addresses is not relevant.
> The big Q is how to delete the address line in $filename
This is FAQ "How do I ... delete a line in a file...?" but I don't
think this is really your question.
> only if you match all the letters, not just the first ones.
So in it's simplest form your real question is "How do I tell if one
string is equal to another with some constant suffix appended?". By
appending the same suffix to the second string this trivially reduces
to "How can I tell if two strings are equal?".
The 'eq' operator tells you if two strings are equal.
if ( "$email<br>" eq $_ )
You can also use // if you prefer:
if ( /^\Q$email\E<br>$/ )
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: Mon, 24 Sep 2001 16:53:07 GMT
From: Carlos C. Gonzalez <aperlprogrammer@yahoo.com>
Subject: Checking for an empty hash??
Message-Id: <MPG.161912992aeab9f49897a2@news.edmonton.telusplanet.net>
Hi everyone,
I have been away from programming for a while but now that I am back I
was wondering if someone could give me some input on the following....
How do I check for the presence of an empty hash from the function
new_person() in the code below?
The code:
#!/usr/bin/perl -W
# Regular hash operations:
my %hash = (
first_name => "Tom",
last_name => "Smith",
age => 41 );
print $hash{first_name};
if (%hash = new_person()) {
print $hash{first_name};
}
else {
print "Empty";
}
sub new_person
{
return {};
}
I tried using the exists function but it doesn't work on just a hash
name. I also tried the defined function and have been looking all over
the place for some insight on how to check for an empty hash. Does
anyone have any suggestions?
I know the code doesn't do anything but I am still trying to figure out
how to work with hashes in how I want to use them. This is learning
code. In my production code I am filling the hash with values from a
database or returning an empty hash from a found() function. If the hash
is empty the values searched for were not found. If it is filled with
info it was found.
Thanks
---
Carlos
www.internetsuccess.ca (not operational yet)
------------------------------
Date: Mon, 24 Sep 2001 17:00:33 GMT
From: Carlos C. Gonzalez <aperlprogrammer@yahoo.com>
Subject: Re: Checking for an empty hash??
Message-Id: <MPG.1619150fecc198139897a3@news.edmonton.telusplanet.net>
Carlos C. Gonzalez at aperlprogrammer@yahoo.com said...
> How do I check for the presence of an empty hash from the function
> new_person() in the code below?
>
I think I finally figured it out. In an obscure Google news message I
discovered that a hash should be initialized to empty with "()" instead
of "{}" like I was using. At least new_person() is now working.
Please ignore this thread unless you wish to comment further (always
welcomed). Thanks.
---
Carlos
www.internetsuccess.ca (not operational yet)
------------------------------
Date: Mon, 24 Sep 2001 15:56:21 GMT
From: mjd@plover.com (Mark Jason Dominus)
Subject: Re: Creating a file
Message-Id: <3baf57a4.5256$d3@news.op.net>
In article <a18e5d95.0109200913.688a8c90@posting.google.com>,
Lorimer <djdjokic@yahoo.com> wrote:
>open (FILE, "> $file") || die "Could not open $!";
>
>Could not open No such file or directory at line 650
That normally means that $file has a path to a directory that does not exist.
'open' will create a file, but it will not create a directory.
If $file is 'path/to/the/file.txt', then the directories 'path',
'path/to', and 'path/to/the' must all exist already.
--
@P=split//,".URRUU\c8R";@d=split//,"\nrekcah xinU / lreP rehtona tsuJ";sub p{
@p{"r$p","u$p"}=(P,P);pipe"r$p","u$p";++$p;($q*=2)+=$f=!fork;map{$P=$P[$f^ord
($p{$_})&6];$p{$_}=/ ^$P/ix?$P:close$_}keys%p}p;p;p;p;p;map{$p{$_}=~/^[P.]/&&
close$_}%p;wait until$?;map{/^r/&&<$_>}%p;$_=$d[$q];sleep rand(2)if/\S/;print
------------------------------
Date: Mon, 24 Sep 2001 15:58:32 GMT
From: mjd@plover.com (Mark Jason Dominus)
Subject: Re: Creating a file
Message-Id: <3baf5826.5296$62@news.op.net>
In article <9Kxq7.33983$A5.5339252@typhoon.nyc.rr.com>,
Steve Grazzini <s_grazzini@hotmail.com> wrote:
>If you want to don't want to clobber a (possibly) existing file, test first
>with -e
>
>open FILE, -e $file ? ">> $file" : "> $file"
> or die "Couldn't open '$file': $!.";
At someone else pointed out, that won't always work. Some other
process might create the file after you do the -e and before you do
the open(); then you will clobber this file.
>(Seems like there should be an easier way to append-but-create-if-necessary,
>but I do not know it.)
open FILE, ">> $file"
or die ...;
--
@P=split//,".URRUU\c8R";@d=split//,"\nrekcah xinU / lreP rehtona tsuJ";sub p{
@p{"r$p","u$p"}=(P,P);pipe"r$p","u$p";++$p;($q*=2)+=$f=!fork;map{$P=$P[$f^ord
($p{$_})&6];$p{$_}=/ ^$P/ix?$P:close$_}keys%p}p;p;p;p;p;map{$p{$_}=~/^[P.]/&&
close$_}%p;wait until$?;map{/^r/&&<$_>}%p;$_=$d[$q];sleep rand(2)if/\S/;print
------------------------------
Date: 24 Sep 2001 11:34:40 -0400
From: Joe Schaefer <joe+usenet@sunstarsys.com>
Subject: Re: eval-statement fools garbage-collection ?
Message-Id: <m3ofo0k3fz.fsf@mumonkan.sunstarsys.com>
mgjv@tradingpost.com.au (Martien Verbruggen) writes:
> On Mon, 24 Sep 2001 14:12:05 +0200,
> peter pilsl <pilsl_@goldfisch.at> wrote:
[...]
> > I made subsequent tests and found out, that the memory is released
> > to the OS when I "manally" delete the structure. (see below,
> > dest($ptr) instead of undef $ptr) So I think its a problem of perl
> > (or better: a problem of my way to use perl)
>
> Nono. If this is the case, then I'd look at a problem in Perl. But
> first, I'd make sure that perl is indeed not freeing the memory at
> all, instead of just not giving it back to the OS.
I think the point he's making is IME quite valid- explicitly
undef'ing a variable often has a more precise effect on memory than
just (implicitly) dropping the refcount to zero. IOW, zeroing the
refcount just *schedules* a variable's resources for cleanup-
how/when/if that actually takes place is up to the gc, but IME
undef'ing it _usually_ causes immediate action.
Another unrelated point is that
sub foo {
eval 'sub { $_[0] + 5 }'
}
is constructed quite differently from
sub bar {
return sub { $_[0] + 5 }
}
Each call to foo() compiles a fresh new anonymous sub on each
invocation, whereas for bar(), a single anonymous sub is created
at compile time, and calls to bar just produce additional references
to it (no cloning necessary here).
[...]
> > perl on both machines is 5.6.0, and
[...]
> > is the same here. Maybe I should have a look at perl 5.6.1.
>
> That sounds like a good option to me.
Completely agreed- 5.6.1 is much improved over 5.6.0; but it's still
very easy to produce memory leaks when working with closures, eval,
and the like. A nasty one (and it's not entirely uncommon in a
modperl setting) was discussed recently on p5p and the modperl mailing
lists:
{
my $bigvar = "really big variable";
my $x = sub { sub { $bigvar } };
}
On each pass the outer sub is cloned, but the inner one is not
(which IMO is the opposite of what should happen). This causes
a reference loop: by construction the inner sub must acquire
$bigvar's value from the *outer* sub's pad, so it must also hold
a reference to the outer sub. Hence the outer sub's clone is
never garbage collected, and it's pad contains a copy of $bigvar.
--
Joe Schaefer
perl -wle '$,=" ";{ my @x;sub x {if(@_){push @x,@_; return sub{push @x,@_;@x}}
sub{push @x,@_;@x}}
} print x ("Just")->("another"), x -> ("perl","hacker,")'
------------------------------
Date: 24 Sep 2001 18:38:44 +0100
From: nobull@mail.com
Subject: Re: eval-statement fools garbage-collection ?
Message-Id: <u98zf4wkt7.fsf@wcl-l.bham.ac.uk>
peter pilsl <pilsl_@goldfisch.at> writes:
> Martien Verbruggen wrote:
> > When memory is freed, it is not necessary for the
> > process to hand it back to the OS immediately, or at all.
>
> Thats an interesting point.
It's also a red-herring in this discussion. The bug that Peter has
found is real and is an interaction between the eval(STRING) and
closure mechanisms.
Under the normal course of events a closure will keep alive any
lexicals that are mentioned within the closure but not any other
variables that were also in scope at the time the closure was created.
However if a closure is created within an eval(STRING) then it also
keeps alive any variables that are mentioned outside of any closure
but within the same eval.
To reproduce this bug use the following:
#!/usr/bin/perl
use strict;
use warnings;
use AtExit;
my ($sub1,$sub2);
{
my $foo1=AtExit->new(sub { print "\$foo1 DESTROYED\n"});
my $foo2=AtExit->new(sub { print "\$foo2 DESTROYED\n"});
eval q{
$sub1= sub { $foo1; undef };
$sub2= sub { $foo2; undef };
# Remove following line and we see normal behaviour
if (0) { $foo1; $foo2; undef };
};
};
print "undef \$sub1\n";
undef $sub1;
print "undef \$sub2\n";
undef $sub2;
print "done\n";
__END__
I've looked on perlbug and I can't find this bug so, Peter, since you
discovered the bug you get the honour of submitting it.
peter pilsl <pilsl_@goldfisch.at> writes:
> And this is why I discovered my problem: apache-webserver seemed to be
> memleaking when running my application on it.
To cope with memory leaks there's an option to limit the number of
requests that each server thread will handle.
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: 24 Sep 2001 10:46:10 -0700
From: mauroid@csi.forth.gr (Dimitri)
Subject: How do I compare strings?
Message-Id: <a3ebf7b8.0109240946.7510e51d@posting.google.com>
I have two very long strings, which I need to compare. I am looking for
the position of the first mismatching character :
$str1: abcdefghijklmn....
$str2: abcdefghiXklmn..
$pos : 9
How can I find this position, short of writing a for loop that will go
through each string and use substr to compare character by character?
for ($pos = 0; $pos < $len; $pos++) {
if (substr($str1, $pos, 1) ne substr($str, $pos, 1)) { last; }
}
I looked at the FAQ but couldn't find it there..
Thanks!
Dimitri
------------------------------
Date: 24 Sep 2001 17:35:42 +0100
From: nobull@mail.com
Subject: Re: How to remove whitespace without losing the 'real' whitespace?
Message-Id: <u9hetswnq9.fsf@wcl-l.bham.ac.uk>
Tim Heaney <theaney@toadmail.toad.net> writes:
> nobull@mail.com writes:
> > s/\s+$/; # Remove trailing spaces.
>
> Except he probably doesn't want to lose the newline.
Opps! I'd overlooked that the OP was operating on un-chomp()ed data.
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: Mon, 24 Sep 2001 17:09:25 +0100
From: Neil <neil@thump.org>
Subject: K shell to perl translator ?
Message-Id: <dVqvOwkhbWLh8YBDo0qV5bOcVc+X@4ax.com>
I can't find any mention of this anywhere but just incase the gurus know, has
anyone written a khell to perl translator ?
Neil
------------------------------
Date: 24 Sep 2001 08:30:13 -0700
From: ajs@ajs.com (Aaron Sherman)
Subject: Looking for OO/AUTOLOAD info
Message-Id: <eaa2c627.0109240730.2ea0feca@posting.google.com>
The following one-liner:
package foo;
sub AUTOLOAD {my$s=shift;my$f=$AUTOLOAD;$s->xxx($f,@_) unless $f =~
/DESTROY/}
sub xxx{my$s=shift;print "$_[0]($_[1])\n"}
package bar;
@ISA=qw(foo);
sub xxx{my$s=shift;print "$_[0]($_[1])\n"}
package main;
$f=bless {}, "foo";
$b=bless {}, "bar";
$f->yahoo("hello");
$b->yahoo("hello");'
works the way I expect. In other words, it prints:
foo::yahoo(hello)
bar::yahoo(hello)
So, what I'm trying to find out is... is this the way I *should* be
doing auto-loaded methods? My real-world application is a set of
classes wrapped around a database. I auto-load all of the field-names
through an virtual-base-class' AUTOLOAD, and call the child-class'
_field method which get/sets field values to/from the database.
Should this work? Should I be error-checking for anything other than
method invocations that aren't valid field names?
As a long-time user of c.l.p. back in the early 90s, thanks!
------------------------------
Date: Mon, 24 Sep 2001 15:06:58 GMT
From: Bart Mortelmans <Usenet@bNamed.be>
Subject: Re: Net::DNS doesn't work when trying to query a nameserver by domain and not by IP-address
Message-Id: <3BAF4BB7.7090705@bNamed.be>
Michael Fuhr wrote:
> Bart Mortelmans <Usenet@bNamed.be> writes:
>
>> [helpfull information about how to debug this problem]
Thanks for you answer! I'll be trying out you hints asap.
I also worked on this problem myself a bit more, and ended up using
===
$packed_addr = inet_aton($host);
if(defined($packed_addr)) {
$res->nameservers(inet_ntoa($packed_addr));
}
===
to convert het domainname into an IP-address. I did however run into an
other problem. It turns out that this will always work but not for the
nameserver of my provider.
My guess is that it can't find this nameserver because the nameserver
itself (also the SOA for it's domain) reports "Non-existent domain" when
asked about itself. To make it more clear: the nameserver is
ns1.oxygendns.net. The SOA for oxygendns.net is ns1.oxygendns.net and
when I ask ns1.oxygendns.net for the A-record of ns1.oxygendns.net, it
returns "Non-existent domain".
This is probably more a question for a newsgroups specialised in
nameservers, but if anyone in here can tell me whether the second or
maybe even the first problem could be caused by the absence of an
A-record for this nameserver, please let me know. For now my provider
seems to be reluctant to add the A-record.
Sincerely,
Bart Mortelmans
------------------------------
Date: 24 Sep 2001 08:10:39 -0700
From: bduffy@nycap.rr.com (Brian Duffy)
Subject: Re: Net::FTP and AIX
Message-Id: <8382da14.0109240710.51a52c6f@posting.google.com>
"Bob Densmore" <bdensmore@austin.rr.com> wrote in message news:<CEUp7.281835$g_3.63507077@typhoon.austin.rr.com>...
> I asked the Unix admins at the shop to install the Net::FTP perl module.
> They had never heard of CPAN and after looking around, basically said they
> would not install the perl module because it had not been tested and
> certified on AIX.
>
> What do you say about this?
>
> Bob D.
You need to talk to their boss, since they are dicking around with
you.
Either that or pay someone from IBM Global Services $300/hour to write
a buggy Net:FTP module for you.
------------------------------
Date: 24 Sep 2001 08:11:36 -0700
From: bduffy@nycap.rr.com (Brian Duffy)
Subject: Re: Net::FTP and AIX
Message-Id: <8382da14.0109240711.2f455057@posting.google.com>
"Bob Densmore" <bdensmore@austin.rr.com> wrote in message news:<CEUp7.281835$g_3.63507077@typhoon.austin.rr.com>...
> I asked the Unix admins at the shop to install the Net::FTP perl module.
> They had never heard of CPAN and after looking around, basically said they
> would not install the perl module because it had not been tested and
> certified on AIX.
>
> What do you say about this?
>
> Bob D.
You need to talk to their boss, since they are dicking around with
you.
Either that or pay someone from IBM Global Services $300/hour to write
a buggy Net::FTP for you.
------------------------------
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 1805
***************************************