[18869] in Perl-Users-Digest
Perl-Users Digest, Issue: 1037 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Jun 1 14:10:58 2001
Date: Fri, 1 Jun 2001 11:10:17 -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: <991419017-v10-i1037@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Fri, 1 Jun 2001 Volume: 10 Number: 1037
Today's topics:
Re: Posting Etiquette <jurgenex@hotmail.com>
Re: Posting Etiquette <godzilla@stomp.stomp.tokyo>
Re: Reading from strings... <mischief@velma.motion.net>
Re: Recursing a directory tree <nwang@shell3.shore.net>
releasing array memory nobody@nowhere.com
Re: releasing array memory <der.prinz@gmx.net>
Re: releasing array memory (Andrew J. Perrin)
Re: releasing array memory <der.prinz@gmx.net>
Re: Rename .htm to .html <Graham.T.Wood@oracle.com>
Re: Seek and destroy ! - s/// problems (E.Chang)
Re: Seek and destroy ! - s/// problems (Matthew J. Salerno)
Re: Workgrounds for perl2exe ?? <>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Fri, 1 Jun 2001 10:13:16 -0700
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: Posting Etiquette
Message-Id: <3b17cd1b$1@news.microsoft.com>
"Rob" <"relaxedrob@optushome.com.au"> wrote in message
news:S0ER6.5468$25.19644@news1.eburwd1.vic.optushome.com.au...
> > I did not threaten you.
> > What is threatening in the above?
> > Do you know what "killfile" means?
> >
> > >If my style is not acceptable to you, do not reply to my posts.
> >
> > I (and I expect, many others) will not be seeing any of your posts.
> > That is what "killfile" means.
>
> That is what 'threat' means.
Excuse me???
Do you seriously demand that everyone must listen to your poor manners?
Sorry, not me: PLONK
jue
------------------------------
Date: Fri, 01 Jun 2001 10:40:33 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: Posting Etiquette
Message-Id: <3B17D391.6685022B@stomp.stomp.tokyo>
Jürgen Exner wrote:
> Rob wrote:
> > > I did not threaten you.
> > > What is threatening in the above?
> > > Do you know what "killfile" means?
> > > >If my style is not acceptable to you, do not reply to my posts.
> > > I (and I expect, many others) will not be seeing any of your posts.
> > > That is what "killfile" means.
> > That is what 'threat' means.
> Excuse me???
> Do you seriously demand that everyone must listen to your poor manners?
> Sorry, not me: PLONK
Why do so many of you boys insist on spamming this
newsgroup with your announcements of killfiling
a person? Is this a primate testosterone induced
chest beating display?
We women might consider performing a similar ritual
but would do so with grace in the fashion of diplomatic
sabre rattling although our often choice is to take
silent action.
* thinks of Ronald Reagan *
Certainly it is past Bedtime For Gonzo.
Godzilla! Lover Of King Kong.
------------------------------
Date: Fri, 01 Jun 2001 15:37:10 -0000
From: Chris Stith <mischief@velma.motion.net>
Subject: Re: Reading from strings...
Message-Id: <thfdl6kulnub13@corp.supernews.com>
In comp.lang.perl.modules Chaos <mordor@fly.srk.fer.hr> wrote:
> Is there a module or a feature in Perl that would allow me to use scalars
> as files? Basically, I want something like this:
> my $scalar = "this is my\nstring that I\nwant to read as a file\n";
> some_call (FH, "<$scalar");
> while(<FH>) { print "$_"; }
> What do I put instead of some_call?
> The thing is that I have a module that takes a filename. I already have a
> file in memory and it seems ridicolous that I must first write the data to
> temporary file and read it from disk. I want to rewrite the module so that it
> takes a filehandle instead of filename. Then it wouldn't matter whether that
> filehandle refers to some string, file on disk, etc..
There are module answers, but since this is crossposted to
comp.lang.perl.misc, I feel I should point out that your
situation can be fixed without making the scalar look like
a file if you want.
my $scalar = "this is my\nstring that I\nwant to read as a file\n";
my @array = split /\n/, $scalar;
for( @array ) { print "$_\n" }
or
my $scalar = "this is my\nstring that I\nwant to read as a file\n";
while( $scalar =~ /(.*?\n)/gs ) { print "$1" }
will do what you want, albeit with different syntax than if you
were using a file. The former would be easiest if you wrote your
intial slurp as
my @array = <File>;
instead of slurping into a scalar then splitting into an array.
Chris
--
Disclaimer: Actual product may not resemble picture in ad in any way.
------------------------------
Date: Fri, 01 Jun 2001 17:40:51 GMT
From: Nan Wang <nwang@shell3.shore.net>
Subject: Re: Recursing a directory tree
Message-Id: <DsQR6.259$cN.24640@news.shore.net>
Arun Horne <a.b.horne@nospamexeter.ac.uk> wrote:
> Does anyone have some simple code to recurse a directory tree please?? Best
> regards Arun Horne.
Sure here's one, I did this a while ago without using Find:
sub traverse {
no strict 'refs';
my ($startdir,$i)=@_;
$i++;
my $FH="FH"."$i";
opendir ("$FH",$startdir) or die "blah";
my @allfiles=grep !/^\.\.?$/, readdir $FH;
closedir ($FH);
my $file='';
foreach $file (@allfiles) {
chomp $file;
my $file="$startdir/$file";
if (-f $file) {
# do whatever
} elsif (-d $file) {
&traverse ($dir,$i);
}
}
}
------------------------------
Date: Fri, 01 Jun 2001 16:34:22 GMT
From: nobody@nowhere.com
Subject: releasing array memory
Message-Id: <iuPR6.741$v4.27959@www.newsranger.com>
I have a tool which runs in the background.
I use an array @arrayname to store the data in it.
for eg,
while (1) {
@arrayname = `cat filename` ;
do processing ..
undef @arrayname ;
sleep(30);
}
Is this a proper procedure to release memory associated with @arrayname.
I don't want memory leak in my code.
Thanks.
------------------------------
Date: Fri, 1 Jun 2001 18:48:13 +0200
From: "Stefan Weiss" <der.prinz@gmx.net>
Subject: Re: releasing array memory
Message-Id: <3b17c72e@e-post.inode.at>
<nobody@nowhere.com> wrote:
> while (1) {
> @arrayname = `cat filename` ;
> do processing ..
> undef @arrayname ;
> sleep(30);
> }
>
> Is this a proper procedure to release memory associated with @arrayname.
>
> I don't want memory leak in my code.
perl won't return memory once it's allocated. It will however reuse
the memory it already has. The undef() in your code will not have
the desired effect (you can check it with top).
To avoid memory leaks, you might consider using strict and let perl
do Garbage Collection when the variables go out of scope.
cheers,
stefan
------------------------------
Date: 01 Jun 2001 13:08:23 -0500
From: aperrin@telocity.com (Andrew J. Perrin)
Subject: Re: releasing array memory
Message-Id: <87ofs8qdig.fsf@nujoma.perrins>
"Stefan Weiss" <der.prinz@gmx.net> writes:
> <nobody@nowhere.com> wrote:
>
> > while (1) {
> > @arrayname = `cat filename` ;
> > do processing ..
> > undef @arrayname ;
> > sleep(30);
> > }
> >
> > Is this a proper procedure to release memory associated with @arrayname.
> >
> > I don't want memory leak in my code.
>
> perl won't return memory once it's allocated. It will however reuse
> the memory it already has. The undef() in your code will not have
> the desired effect (you can check it with top).
>
> To avoid memory leaks, you might consider using strict and let perl
> do Garbage Collection when the variables go out of scope.
Well, use strict doesn't really do anything about memory leaks, it
just enforces behavior that tends to prevent them. The behavior can be
carried out without strict. (Not that you shouldn't be use()ing
strict, just to clarify its tangential relationship to this problem.)
My understanding, also, is that even letting variables go out of scope
won't return memory to the OS, although I suspect that's to some
extent a function of the OS, not of perl. Can anyone verify?
One technique for daemon-ish programs is to have them exec()
themselves every once in a while, which starts a new process thereby
returning all memory to the OS and then reclaiming it as
needed. There's an example in my rdial(d) script, which is at
http://www.unc.edu/~aperrin/tips/src/rdiald-pl.txt .
--
---------------------------------------------------------------------
Andrew J Perrin - andrew_perrin@unc.edu - http://www.unc.edu/~aperrin
Asst Professor of Sociology, U of North Carolina, Chapel Hill
From address is real but rarely checked; try andrew_perrin at unc.edu
------------------------------
Date: Fri, 1 Jun 2001 19:23:27 +0200
From: "Stefan Weiss" <der.prinz@gmx.net>
Subject: Re: releasing array memory
Message-Id: <3b17cf70$1@e-post.inode.at>
Andrew J. Perrin <aperrin@telocity.com> wrote:
> > perl won't return memory once it's allocated. It will however reuse
> > the memory it already has. The undef() in your code will not have
> > the desired effect (you can check it with top).
> >
> > To avoid memory leaks, you might consider using strict and let perl
> > do Garbage Collection when the variables go out of scope.
>
> Well, use strict doesn't really do anything about memory leaks, it
> just enforces behavior that tends to prevent them.
Yes, that's what I meant.
> My understanding, also, is that even letting variables go out of scope
> won't return memory to the OS,
But it does make it avaiable to perl again, so it can be reused for
new variables. One thing I noticed is that closures are best avoided
if you are afraid of leaking memory. I had a web application under
Apache/mod_perl that would segfault at ~ every 10th call or so,
and it only stopped when I replaced all closures with other constructs.
> One technique for daemon-ish programs is to have them exec()
> themselves every once in a while, which starts a new process thereby
> returning all memory to the OS and then reclaiming it as
> needed.
Good point.
cheers,
stefan
------------------------------
Date: Fri, 01 Jun 2001 16:06:55 +0100
From: Graham Wood <Graham.T.Wood@oracle.com>
Subject: Re: Rename .htm to .html
Message-Id: <3B17AF8F.F3A473A8@oracle.com>
This is a multi-part message in MIME format.
--------------DFEA4CBEFC42AABB9B602571
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit
felan wrote:
> Can any one show me a command i unix or a program i perl which
> converts all the .htm extension in a given directory to .html
> extensions?
>
> tnx
> felan_66@hotmail.com
Unix commands:
for i in *.htm
? do
? mv $i ${i}l
? done
Graham Wood
--------------DFEA4CBEFC42AABB9B602571
Content-Type: text/x-vcard; charset=UTF-8;
name="Graham.T.Wood.vcf"
Content-Transfer-Encoding: 7bit
Content-Description: Card for Graham Wood
Content-Disposition: attachment;
filename="Graham.T.Wood.vcf"
begin:vcard
n:Wood;Graham
x-mozilla-html:FALSE
org:;Worldwide Product Translation Group
adr:;;;;;;
version:2.1
email;internet:Graham.T.Wood@oracle.com
title:Senior QA Engineer
fn:Graham Wood
end:vcard
--------------DFEA4CBEFC42AABB9B602571--
------------------------------
Date: Fri, 01 Jun 2001 15:43:32 GMT
From: echang@netstorm.net (E.Chang)
Subject: Re: Seek and destroy ! - s/// problems
Message-Id: <Xns90B377C0FFBF2echangnetstormnet@207.106.92.86>
msalerno@my-deja.com (Matthew J. Salerno) wrote in
<6622f4b.0106010656.6985fe33@posting.google.com>:
>Hi all, I am having a problem. I am writing a script that will remove
>the "the" from the beginning of any txt file and will convert all
>spaces to underscores "_". There are other things it has to do, but
>the main problem I am having is that I cannot get the "the" in the
>beginning of the filename removed. I looked at the perlop and it
>recommends using something like "s/\bfoo\b/bar/g;" but it replaces the
>entire string to a 1 or 2. Please assist.
> #$filename =~ tr/^"the"//d;
> #$filename = s/the/ /;
You had a lot of the pieces, but not together. Try (assuming you want
to remove an initial "the" and one following space)
$filename =~ s/^the //i;
For example, running
#!/usr/local/bin/perl -w
while ($filename = <DATA>) {
$filename =~ s/^the //i;
$filename =~ tr/ /_/;
print "$filename";
}
__DATA__
The first one.txt
there is a second one.txt
this that and the other.txt
produces the output
first_one.txt
there_is_a_second_one.txt
this_that_and_the_other.txt
[rest snipped]
--
EBC
------------------------------
Date: 1 Jun 2001 10:41:45 -0700
From: msalerno@my-deja.com (Matthew J. Salerno)
Subject: Re: Seek and destroy ! - s/// problems
Message-Id: <6622f4b.0106010941.2718d92d@posting.google.com>
msalerno@my-deja.com (Matthew J. Salerno) wrote in message news:<6622f4b.0106010656.6985fe33@posting.google.com>...
> Hi all, I am having a problem. I am writing a script that will remove
> the "the" from the beginning of any txt file and will convert all
> spaces to underscores "_". There are other things it has to do, but
> the main problem I am having is that I cannot get the "the" in the
> beginning of the filename removed. I looked at the perlop and it
> recommends using something like "s/\bfoo\b/bar/g;" but it replaces the
> entire string to a 1 or 2. Please assist.
>
> Thanks,
> Matt
>
>
> #!/usr/local/bin/perl -w
> use strict;
> use File::Find;
>
> my $outpt;
> my $path = "/foo/bar/";
> my $logpath = "/foo/bar/changelog";
>
> my @files;
> find sub { push @files, $File::Find::name if /\.txt\z/i && -f; },
> "$path";
>
> open(LOGFILE, ">$logpath");
>
> foreach (@files){
> my $i = 0;
> my @filepath = split ("/" , $_);
> my $filename = $filepath[$#filepath];
> #$filename =~ tr/^"the"//d;
> #$filename = s/the/ /;
> $filename =~ tr/ /_/;
> $filepath[$#filepath] = $filename;
> my $finalnm = join("/", @filepath);
> if ( $_ ne $finalnm){
> $outpt = "Renaming $_ to $finalnm\n";
> $i++;
> }
> else {
> $outpt = "No Change - $_\n";
> }
> print $outpt;
> print LOGFILE $outpt;
>
> #rename $_, $finalnm if $i > 0;
> }
>
> close LOGFILE;
Sorry, I realized what I did wrong.
$filename =~ s/^the//i;
Typo error, my morning coffee hadn't kicked in yet.
Thanks,
Matt
------------------------------
Date: Fri, 01 Jun 2001 12:40:35 -0700
From: Darius <>
Subject: Re: Workgrounds for perl2exe ??
Message-Id: <2kpfhtkg6ih37gfo37fip0hur0m92dih26@4ax.com>
>>I have recently been playing around with writing GUI apps in Win32 and
>>using perl2exe in order to make executables, so that other people
>>without perl compilers can run my programs.
>>
>>However, in order to use the -gui command line option of perl2exe to
>>get rid of the console window, it costs $150, which I currently don't
>>have (and wouldn't pay anyway, since programming is a hobby for me and
>>I don't make money doing it).
>>
>Let me get this straight. You want help from this
>group in stealing from the company that makes
>perl2exe? And you want people to post their
>exploits here for all the world to see so that they
>can be prosecuted for their illegal behaviour?
>
Uhhhhh ..... no.
I was asking for another way to get rid of the console window from
executable perl apps, or an alternative to perl2exe.
I was not asking for a crack :P
-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----== Over 80,000 Newsgroups - 16 Different Servers! =-----
------------------------------
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 1037
***************************************