[25773] in Perl-Users-Digest
Perl-Users Digest, Issue: 8012 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Apr 25 18:15:53 2005
Date: Mon, 25 Apr 2005 15:15:42 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Mon, 25 Apr 2005 Volume: 10 Number: 8012
Today's topics:
one-time and one-line programs <mdetomaso@bak.rr.com>
Re: one-time and one-line programs <pilsl@goldfisch.at>
Re: one-time and one-line programs xhoster@gmail.com
Re: one-time and one-line programs <john@castleamber.com>
Re: one-time and one-line programs <tadmc@augustmail.com>
Re: perl doesn't recogize alias? <joe@inwap.com>
Re: Problem with setting LD_LIBRARY_PATH <moritz.karbach@desy.de>
Re: Q on BEGIN and INIT <joe@inwap.com>
rename not working on files with accents in names <noneedto@email.me>
Re: rename not working on files with accents in names <matternc@comcast.net>
Re: rename not working on files with accents in names <tadmc@augustmail.com>
Re: rename not working on files with accents in names <noneedto@email.me>
Re: rename not working on files with accents in names <matternc@comcast.net>
Re: rename not working on files with accents in names <matternc@comcast.net>
Re: searc and replace <joe@inwap.com>
sound (playing few wavs at once) <nobody@this.home.com>
Speeding up glob? <jckstrw@gmail.com>
Re: Speeding up glob? <mark.clementsREMOVETHIS@wanadoo.fr>
Re: Speeding up glob? <glex_nospam@qwest.invalid>
Re: Speeding up glob? xhoster@gmail.com
Re: Speeding up glob? <tintin@invalid.invalid>
Re: Speeding up glob? <pilsl@goldfisch.at>
Re: Speeding up glob? <notvalid@email.com>
Re: Speeding up glob? <tadmc@augustmail.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Mon, 25 Apr 2005 20:08:22 GMT
From: "Michael De Tomaso" <mdetomaso@bak.rr.com>
Subject: one-time and one-line programs
Message-Id: <W6cbe.21038$JB.4324@tornado.socal.rr.com>
In reviewing the -p -e -n command line options, I've been trying to
find/understand more examples...
Q:I'd like to know how many perl people keep a stash of one liners and what
are their favorite quickie code concoctions might be ?
- thanks & take care M.D.
<aka>
_ _
| |_ ___ _ __ ___ __ _ | |_ ___ ___
| __| / _ \ | '_ ` _ \ / _` | | __| / _ \ / _ \
| |_ | (_) | | | | | | | | (_| | | |_ | (_) | | __/
\__| \___/ |_| |_| |_| \__,_| \__| \___/ \___|
------------------------------
Date: Mon, 25 Apr 2005 22:41:14 +0200
From: peter pilsl <pilsl@goldfisch.at>
Subject: Re: one-time and one-line programs
Message-Id: <426d5643$0$3240$79720d31@newsreader.inode.at>
Michael De Tomaso wrote:
> In reviewing the -p -e -n command line options, I've been trying to
> find/understand more examples...
>
> Q:I'd like to know how many perl people keep a stash of one liners and what
> are their favorite quickie code concoctions might be ?
>
sadly I dont keep them, but I use them every day. Whenever I have to
deep-in analyze a log or convert some files or process a longer output
of find or ls I write a small one-line-filter in perl.
And I use to test regular expressions in a one-liner before writing them
inside the big project.
And I use one-liners to run a command n times, cause I never can
remember the bash-syntax for this.
peter
--
http://www.goldfisch.at/know_list
------------------------------
Date: 25 Apr 2005 21:18:46 GMT
From: xhoster@gmail.com
Subject: Re: one-time and one-line programs
Message-Id: <20050425171846.205$zp@newsreader.com>
"Michael De Tomaso" <mdetomaso@bak.rr.com> wrote:
> In reviewing the -p -e -n command line options, I've been trying to
> find/understand more examples...
>
> Q:I'd like to know how many perl people keep a stash of one liners and
I very rarely save one liners, other than in my scrollback buffer. If a
one-liner becomes so complex that it would no longer be trivial to recreate
it, I figure it deserves to have more than one line.
> what are their favorite quickie code concoctions might be ?
Here's are a couple I used recently:
time perl -e 'system q{perl -e "use strict;use CGI"} foreach 1..100'
time perl -e 'system q{perl -e "use strict;use DBI"} foreach 1..100'
Also, I have "deparse" aliased to
perl -MO=Deparse,-p
So that I can easily check out constructs for which I'm not sure of the
precedence, associativity, or parsing.
Xho
--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service $9.95/Month 30GB
------------------------------
Date: 25 Apr 2005 21:40:19 GMT
From: John Bokma <john@castleamber.com>
Subject: Re: one-time and one-line programs
Message-Id: <Xns9643A99001976castleamber@130.133.1.4>
Michael De Tomaso wrote:
> In reviewing the -p -e -n command line options, I've been trying to
> find/understand more examples...
>
> Q:I'd like to know how many perl people keep a stash of one liners and
> what are their favorite quickie code concoctions might be ?
http://johnbokma.com/mexit/2005/02/22/
http://johnbokma.com/mexit/2005/02/24/processing-fields-perl.html
Since I rarely use -p, -n, -s, -F, it might be not the best stuff to read.
I use -e often to check something, or do something that's easier with perl
compared to the cli. But most of the time I end up writing a very small
script :-D. (Easier to reuse).
--
John Small Perl scripts: http://johnbokma.com/perl/
Perl programmer available: http://castleamber.com/
Happy Customers: http://castleamber.com/testimonials.html
------------------------------
Date: Mon, 25 Apr 2005 16:26:50 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: one-time and one-line programs
Message-Id: <slrnd6qo4q.ruu.tadmc@magna.augustmail.com>
Michael De Tomaso <mdetomaso@bak.rr.com> wrote:
> In reviewing the -p -e -n command line options, I've been trying to
> find/understand more examples...
>
> Q:I'd like to know how many perl people keep a stash of one liners and what
> are their favorite quickie code concoctions might be ?
perl -n -e 'print' file1 file2... # cat
perl -pe1 file1 file2.... # Tiger Woods cat
perl -n -e 'print if /PATTERN/' file1 file2... # grep -h
perl -n -e 'print "$ARGV: $_" if /PATTERN/' file1... # grep -H
perl -p -i -e 'tr/\r//d' file1 file2... # dos2unix
perl -p -i -e 's/\n/\r\n/' file1 file2... # unix2dos
perl -p -e 'tr/a-zA-Z/n-za-mN-ZA-M/' file1... # rot13
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Sat, 23 Apr 2005 01:48:01 -0700
From: Joe Smith <joe@inwap.com>
Subject: Re: perl doesn't recogize alias?
Message-Id: <uIidnUKRJddPlvffRVn-uw@comcast.com>
Jianping Wu wrote:
> Hi, I am confused by the following problem:
>
> On bash shell, I did:
> alias gcc='grep'
That command affects the current bash shell only.
It affects how command lines in the current shell
are interpreted. You should not expect anything
else to see the alias. Perl won't see it, and
neither will any programs invoked by perl.
------------------------------
Date: Thu, 21 Apr 2005 20:18:32 +0200
From: Moritz Karbach <moritz.karbach@desy.de>
Subject: Re: Problem with setting LD_LIBRARY_PATH
Message-Id: <d4il7b$2k9tf$1@claire.desy.de>
Steven Kuo wrote:
> Forgot that the output from `pwd` includes newline at the end?
Aaaarrg! That was exactly the problem! So f** simple! And I spent hours in
googling before I asked here...
Thanks a lot,
- Moritz
------------------------------
Date: Mon, 25 Apr 2005 03:51:00 -0700
From: Joe Smith <joe@inwap.com>
Subject: Re: Q on BEGIN and INIT
Message-Id: <hsOdnVN6crMLVvHfRVn-pQ@comcast.com>
J Krugman wrote:
> ? And 2) what's a reasonably common, realistic scenario in which
> compilation would happen once, execution many times, and the
> distinction between BEGIN and INIT was meaningful
One blatant example is perlcc.
Use perlcc to parse Perl creating C code, compile the C code
creating and executable binary. Run the binary multiple times.
perldoc perlcc
Here's an example where INIT is executed only once, but the 'when'
of execution is significant.
http://groups-beta.google.com/group/comp.lang.perl.misc/msg/21bf0b72893b2f16
Alex Lee wrote:
> Does anyone know how I can silence this error from eval?
Simply redirect STDERR to a string in a BEGIN block.
linux% cat eval.pl
use strict; use warnings;
BEGIN { our $err = ''; close STDERR; open STDERR,'>',\$err; }
CHECK { our $err; print "Compile: $err" if $err; }
INIT { our $err = ''; close STDERR; open STDERR,'>',\$err; }
END { our $err; print "Runtime: $err" if $err; }
$_ = "abc" + 3;
$a = "xyz"; $b = 3; $_ = $a + $b;
linux% perl eval.pl
Compile: Argument "abc" isn't numeric in addition (+) at eval.pl line 7.
Runtime: Argument "xyz" isn't numeric in addition (+) at eval.pl line 8.
Note how it outputs 'Compile:' for one warning and 'Runtime:' for the other.
------------------------------
Date: Sat, 23 Apr 2005 23:04:54 -0400
From: Tom Bates <noneedto@email.me>
Subject: rename not working on files with accents in names
Message-Id: <qo1m61hjvr5hqr84au10n9c609nfrci1s1@4ax.com>
ActiveState perl 5.8.0 build 806 on Windows 2000 Pro...
The statement:
rename $src, $dst;
returns an error when $src is:
Tecatitlán.txt
If I remove the accented character, the rename operation succeeds.
I tried using File::Copy's move operation as well as setting
${^WIDE_SYSTEM_CALLS} to 1. Neither works.
Any suggestions?
TIA
tbone
------------------------------
Date: Sun, 24 Apr 2005 00:24:28 -0400
From: Chris Mattern <matternc@comcast.net>
Subject: Re: rename not working on files with accents in names
Message-Id: <ie6dnbTj7fThgvbfRVn-1w@comcast.com>
Tom Bates wrote:
> ActiveState perl 5.8.0 build 806 on Windows 2000 Pro...
>
> The statement:
> rename $src, $dst;
> returns an error when $src is:
> Tecatitlán.txt
> If I remove the accented character, the rename operation succeeds.
>
> I tried using File::Copy's move operation as well as setting
> ${^WIDE_SYSTEM_CALLS} to 1. Neither works.
>
> Any suggestions?
Print out $! to have it tell you what the error is. The obvious
one that occurs to me is that Perl doesn't think you have a file
named Tecatitlán.txt because Perl and the OS aren't using the
same character encoding scheme.
> TIA
> tbone
--
Christopher Mattern
"Which one you figure tracked us?"
"The ugly one, sir."
"...Could you be more specific?"
------------------------------
Date: Sun, 24 Apr 2005 03:42:04 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: rename not working on files with accents in names
Message-Id: <slrnd6mmus.cia.tadmc@magna.augustmail.com>
Tom Bates <noneedto@email.me> wrote:
> The statement:
> rename $src, $dst;
> returns an error when $src is:
> Tecatitlán.txt
> Any suggestions?
I suggest sharing the text of the error message!
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Sun, 24 Apr 2005 09:35:51 -0400
From: Tom Bates <noneedto@email.me>
Subject: Re: rename not working on files with accents in names
Message-Id: <jd7n619lqvpsjgsshhsahcfgv3icd4t8jg@4ax.com>
Thanks for reminding me about being able to see the actual error info
(I referred to the Perl help pages for the available error variables).
After the rename fails:
$! == "No such file or directory"
$^E == "The system cannot find the file specified"
$? == 0
I have many files with other accented characters that cause the same
problem, BTW. I'm just using this one to narrow down the problem.
Thanks for the help...
tbone
On Sat, 23 Apr 2005 23:04:54 -0400, Tom Bates <noneedto@email.me>
wrote:
>ActiveState perl 5.8.0 build 806 on Windows 2000 Pro...
>
>The statement:
> rename $src, $dst;
>returns an error when $src is:
> Tecatitlán.txt
>If I remove the accented character, the rename operation succeeds.
>
>I tried using File::Copy's move operation as well as setting
>${^WIDE_SYSTEM_CALLS} to 1. Neither works.
>
>Any suggestions?
>TIA
>tbone
------------------------------
Date: Sun, 24 Apr 2005 22:23:47 -0400
From: Chris Mattern <matternc@comcast.net>
Subject: Re: rename not working on files with accents in names
Message-Id: <uaidnSuymLYuyfHfRVn-gw@comcast.com>
Tom Bates wrote:
> Thanks for reminding me about being able to see the actual error info
> (I referred to the Perl help pages for the available error variables).
> After the rename fails:
>
> $! == "No such file or directory"
> $^E == "The system cannot find the file specified"
> $? == 0
>
> I have many files with other accented characters that cause the same
> problem, BTW. I'm just using this one to narrow down the problem.
Please don't top-post. Put your reply after the text you are replying
to. That said, I firmly believe that your problem is that your Perl
program and Windows aren't using the same character set--that is,
"á" in your Perl program and "á" on your command line aren't in fact
the same character. As I very rarely need to fool with non-ASCII
character sets, I'll leave your solutions to somebody who understands
them better.
>
> Thanks for the help...
> tbone
>
> On Sat, 23 Apr 2005 23:04:54 -0400, Tom Bates <noneedto@email.me>
> wrote:
>
>>ActiveState perl 5.8.0 build 806 on Windows 2000 Pro...
>>
>>The statement:
>>rename $src, $dst;
>>returns an error when $src is:
>>Tecatitlán.txt
>>If I remove the accented character, the rename operation succeeds.
>>
>>I tried using File::Copy's move operation as well as setting
>>${^WIDE_SYSTEM_CALLS} to 1. Neither works.
>>
>>Any suggestions?
>>TIA
>>tbone
--
Christopher Mattern
"Which one you figure tracked us?"
"The ugly one, sir."
"...Could you be more specific?"
------------------------------
Date: Mon, 25 Apr 2005 08:43:22 -0400
From: Chris Mattern <matternc@comcast.net>
Subject: Re: rename not working on files with accents in names
Message-Id: <EIidnbNzwcF3ePHfRVn-rw@comcast.com>
Chris Mattern wrote:
> Tom Bates wrote:
>
>> Thanks for reminding me about being able to see the actual error info
>> (I referred to the Perl help pages for the available error variables).
>> After the rename fails:
>>
>> $! == "No such file or directory"
>> $^E == "The system cannot find the file specified"
>> $? == 0
>>
>> I have many files with other accented characters that cause the same
>> problem, BTW. I'm just using this one to narrow down the problem.
>
> Please don't top-post. Put your reply after the text you are replying
> to. That said, I firmly believe that your problem is that your Perl
> program and Windows aren't using the same character set--that is,
> "á" in your Perl program and "á" on your command line aren't in fact
> the same character. As I very rarely need to fool with non-ASCII
> character sets, I'll leave your solutions to somebody who understands
> them better.
It occurs to me that there is a simple test for this. Have your
Perl program create "Tecatitlán.txt". Then look at the file
in Windows. If it has a weird character instead of "á", then
that's your problem.
--
Christopher Mattern
"Which one you figure tracked us?"
"The ugly one, sir."
"...Could you be more specific?"
------------------------------
Date: Sat, 23 Apr 2005 01:31:25 -0700
From: Joe Smith <joe@inwap.com>
Subject: Re: searc and replace
Message-Id: <aPmdnUoAMoFwmvffRVn-oQ@comcast.com>
freedom wrote:
> 1.I m getting text document instead of html source code when i enter a url
> in the first textfield..
What do you mean by that? Are you saying that
$document = $response->content();
is not returning a string of text?
> 2. I can not do the search and replace in the second and third field
> s/$_/$pattern/;
There's a big difference between
$_ =~ s/$_/$pattern/;
and
$string =~ s/$_/$pattern/;
or even
$string =~ s/$search_for/$replace_with/g;
Which one are you trying to accomplish?
-Joe
------------------------------
Date: Sat, 23 Apr 2005 12:59:42 +0200
From: Krystian <nobody@this.home.com>
Subject: sound (playing few wavs at once)
Message-Id: <hkak61h1348o59dihn87n0uth19n2kkh7l@4ax.com>
hi there
I'm searching for any perl module which can play few wavs at once
(game sounds). There is also one more wish ... it should be possible
to obtain this 'sound' module as ppm for win32 from somewhere. I've
tried Wind32::Sound but it stops playing current sample when the new
one is started. I also searched for SDL, Bass, Fmod but couldn't find
ppm link ... please help with this, does anyone know SDL, Bass or Fmod
perl interfaces which could be installed via ppm? or any other
solution?
thanks in advance
best
krychu
------------------------------
Date: Mon, 25 Apr 2005 13:34:14 -0400
From: Jim <jckstrw@gmail.com>
Subject: Speeding up glob?
Message-Id: <MPG.1cd6f405eb560be49896af@news.duke.edu>
Hi
I have a very simple perl program that runs _very_ slowly. Here's my
code:
#!/usr/local/bin/perl
#
# script to keep only a weeks worth of files
#
use File::stat;
$time = time;
# get list of all files in the backup directory
@files = glob ("/backup/output.log*");
unless (@files[0]) {
print "No files to process\n";
exit;
}
while (<@files>) {
$filename = $_;
$st = stat($_);
$mod_time = $time - $st->mtime;
# if file edit time is greater than x days, delete the file
# 1440 minutes in a day
# 86400 seconds in a day
# 604800 seconds in a week
# 2419200 seconds in a month
# 7257600 seconds in 90 days
if ($mod_time > 7257600) {
print "Deleting file $filename\n";
unlink ($filename);
}
else {
#do nothing
}
}
There are several thousand files (~21K) in this directory and many
thousands of those files fit the criteria to delete. It takes a really
long time to run this program. What's the holdup? Is it glob? My OS
(Solaris 8)? IO? Any way to speed this up? Thanks.
Jim
------------------------------
Date: Mon, 25 Apr 2005 19:51:06 +0200
From: Mark Clements <mark.clementsREMOVETHIS@wanadoo.fr>
Subject: Re: Speeding up glob?
Message-Id: <426d2e10$0$1228$8fcfb975@news.wanadoo.fr>
Jim wrote:
> Hi
>
> I have a very simple perl program that runs _very_ slowly. Here's my
> code:
>
> #!/usr/local/bin/perl
> #
> # script to keep only a weeks worth of files
> #
You need to run with strict and warnings turned on. Please read the
posting guidelines (subject "Posting Guidelines for
comp.lang.perl.misc"), which are posted regularly.
> use File::stat;
>
> $time = time;
>
> # get list of all files in the backup directory
> @files = glob ("/backup/output.log*");
>
> unless (@files[0]) {
> print "No files to process\n";
> exit;
> }
>
> while (<@files>) {
> $filename = $_;
> $st = stat($_);
<snip>
> There are several thousand files (~21K) in this directory and many
> thousands of those files fit the criteria to delete. It takes a really
> long time to run this program. What's the holdup? Is it glob? My OS
> (Solaris 8)? IO? Any way to speed this up? Thanks.
Solaris doesn't (or didn't - I stand open to correction) perform very
well with large directories on ufs. How long does eg ls take to complete
in this directory?
Secondly, you can benchmark your programs using a number of different
methods to work out where bottlenecks are. check out
Benchmark::Timer
Devel::DProf
regards,
Mark
------------------------------
Date: Mon, 25 Apr 2005 13:30:56 -0500
From: "J. Gleixner" <glex_nospam@qwest.invalid>
Subject: Re: Speeding up glob?
Message-Id: <BHabe.32$636.2455@news.uswest.net>
Jim wrote:
> There are several thousand files (~21K) in this directory and many
> thousands of those files fit the criteria to delete. It takes a really
> long time to run this program. What's the holdup? Is it glob? My OS
> (Solaris 8)? IO? Any way to speed this up? Thanks.
Using File::Find or readdir, and process & unlinking each one, if it
passes your test, would probably be better. Similar to reading &
processing each line of a file, compared to slurping in the entire file
and then iterating through each line.
The "fastest" option would be to just used find (man find), and you'll
probably need to use xargs also (man xargs).
------------------------------
Date: 25 Apr 2005 18:35:07 GMT
From: xhoster@gmail.com
Subject: Re: Speeding up glob?
Message-Id: <20050425143507.731$M8@newsreader.com>
Jim <jckstrw@gmail.com> wrote:
> Hi
>
> I have a very simple perl program that runs _very_ slowly. Here's my
> code:
>
...
> @files = glob ("/backup/output.log*");
>
> while (<@files>) {
You are double globbing. Don't do that.
Xho
--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service $9.95/Month 30GB
------------------------------
Date: Tue, 26 Apr 2005 07:39:45 +1200
From: "Tintin" <tintin@invalid.invalid>
Subject: Re: Speeding up glob?
Message-Id: <3Ibbe.1224$Od6.184852@news.xtra.co.nz>
"Jim" <jckstrw@gmail.com> wrote in message
news:MPG.1cd6f405eb560be49896af@news.duke.edu...
> Hi
>
> I have a very simple perl program that runs _very_ slowly. Here's my
> code:
>
> #!/usr/local/bin/perl
> #
> # script to keep only a weeks worth of files
> #
> use File::stat;
>
> $time = time;
>
> # get list of all files in the backup directory
> @files = glob ("/backup/output.log*");
>
> unless (@files[0]) {
> print "No files to process\n";
> exit;
> }
>
> while (<@files>) {
> $filename = $_;
> $st = stat($_);
>
> $mod_time = $time - $st->mtime;
>
> # if file edit time is greater than x days, delete the file
> # 1440 minutes in a day
> # 86400 seconds in a day
> # 604800 seconds in a week
> # 2419200 seconds in a month
> # 7257600 seconds in 90 days
>
> if ($mod_time > 7257600) {
> print "Deleting file $filename\n";
> unlink ($filename);
> }
> else {
> #do nothing
> }
> }
>
> There are several thousand files (~21K) in this directory and many
> thousands of those files fit the criteria to delete. It takes a really
> long time to run this program. What's the holdup? Is it glob? My OS
> (Solaris 8)? IO? Any way to speed this up? Thanks.
The bottleneck is mostly going to be OS & I/O, but you could try
find /backups -name "output.log*" -mtime +7 | xargs rm -f
------------------------------
Date: Mon, 25 Apr 2005 22:31:07 +0200
From: peter pilsl <pilsl@goldfisch.at>
Subject: Re: Speeding up glob?
Message-Id: <426d53e4$0$3236$79720d31@newsreader.inode.at>
Jim wrote:
> Hi
>
> I have a very simple perl program that runs _very_ slowly. Here's my
> code:
>
> #!/usr/local/bin/perl
> #
> # script to keep only a weeks worth of files
> #
> use File::stat;
>
> $time = time;
>
> # get list of all files in the backup directory
> @files = glob ("/backup/output.log*");
>
> unless (@files[0]) {
> print "No files to process\n";
> exit;
> }
>
> while (<@files>) {
> $filename = $_;
> $st = stat($_);
>
> $mod_time = $time - $st->mtime;
>
> # if file edit time is greater than x days, delete the file
> # 1440 minutes in a day
> # 86400 seconds in a day
> # 604800 seconds in a week
> # 2419200 seconds in a month
> # 7257600 seconds in 90 days
>
> if ($mod_time > 7257600) {
> print "Deleting file $filename\n";
> unlink ($filename);
> }
> else {
> #do nothing
> }
> }
>
> There are several thousand files (~21K) in this directory and many
> thousands of those files fit the criteria to delete. It takes a really
> long time to run this program. What's the holdup? Is it glob? My OS
> (Solaris 8)? IO? Any way to speed this up? Thanks.
>
> Jim
just for comparison:
I just wrote a small script that creates 20k empty files and get the
stat of the files and deletes them again.
Its pretty fast on my machine: a linux 2.4.x on Athlon1800XP with 1GB
Ram and IDE with softwareraid level1 and loads of daemons running on it.
So definitely not a machine with fast I/O.
# time ./p.pl create
0.18user 0.71system 0:00.88elapsed 100%CPU (0avgtext+0avgdata 0maxresident)k
0inputs+0outputs (357major+76minor)pagefaults 0swaps
# time ./p.pl delete
0.12user 1.18system 0:01.29elapsed 100%CPU (0avgtext+0avgdata 0maxresident)k
0inputs+0outputs (364major+820minor)pagefaults 0swaps
So its not the globbing, but maybe the double-globbing as Xho pointed
out already !!
Try the following on your machine:
#!/usr/bin/perl -w
use strict;
if ($ARGV[0]=~/create/) {
foreach (0..20000) {
open (FH,">x$_"); close FH;
}
}
if ($ARGV[0]=~/delete/) {
my @files=glob ("x*");
foreach(@files) {
stat($_);
unlink($_);
}
}
best,
peter
--
http://www.goldfisch.at/know_list
------------------------------
Date: Mon, 25 Apr 2005 21:00:24 GMT
From: Ala Qumsieh <notvalid@email.com>
Subject: Re: Speeding up glob?
Message-Id: <ITcbe.1259$zu.249@newssvr13.news.prodigy.com>
Jim wrote:
> I have a very simple perl program that runs _very_ slowly. Here's my
> code:
> unless (@files[0]) {
This works. But you probably meant:
unless (@files) {
or
unless ($files[0]) {
Type this for more info on the diff between $files[0] and @files[0]:
perldoc -q 'difference.*\$array'
> while (<@files>) {
This is doing much more work than you think it is. Change it to:
foreach (@files) {
--Ala
------------------------------
Date: Mon, 25 Apr 2005 16:38:29 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Speeding up glob?
Message-Id: <slrnd6qoql.ruu.tadmc@magna.augustmail.com>
Jim <jckstrw@gmail.com> wrote:
> unless (@files[0]) {
You should always enable warnings when developing Perl code!
> # if file edit time is greater than x days, delete the file
> # 1440 minutes in a day
> # 86400 seconds in a day
> # 604800 seconds in a week
> # 2419200 seconds in a month
You do not need "in a week" nor "in a month".
You already have how many in a day, multiply by 90 to get how
many are in 90 days.
> # 7257600 seconds in 90 days
Wrong answer...
> if ($mod_time > 7257600) {
if ($mod_time > 60 * 60 * 24 * 90) {
Perl will constant-fold it for you.
> There are several thousand files (~21K) in this directory
Then the largest bottleneck is probably the OS and filesystem,
not the programming language (though your algorithm seems
sub-optimal too).
> It takes a really
> long time to run this program. What's the holdup?
There are several thousand files (~21K) in that directory.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
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 8012
***************************************