[17712] in Perl-Users-Digest
Perl-Users Digest, Issue: 5132 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Dec 17 00:05:29 2000
Date: Sat, 16 Dec 2000 21:05:06 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <977029506-v9-i5132@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Sat, 16 Dec 2000 Volume: 9 Number: 5132
Today's topics:
deskcode.com hot new perl resource read more deskcode@my-deja.com
Re: Help with splitting a ongoing variable? <bwalton@rochester.rr.com>
Re: Help with splitting a ongoing variable? <trentm1@hotmail.com>
Re: Help with splitting a ongoing variable? <bart.lateur@skynet.be>
Re: Help with splitting a ongoing variable? <trentm1@hotmail.com>
Re: How to identify Windows platform from within a Perl (Tim Hammerquist)
Re: Is Perl dying? (Logan Shaw)
Re: Language evolution C->Perl->C++->Java->Python (Is P <bart.lateur@skynet.be>
Re: MIME::Lite error <harrisr@bignet.net>
Re: One-Liner to Sum a Stack of Numbers? (Craig Berry)
OT:Re: Perl programming (Tim Hammerquist)
Re: Posting Guidelines for comp.lang.perl.misc ($Revisi (Randal L. Schwartz)
Re: Q: installing perl on win98 (Tim Hammerquist)
Sendmail script problems <mikelin6@home.com>
thanks - Re: Trick problem, Selective purging of a dire <robert@chalmers.com.au>
Trick problem, Selective purging of a directory? <robert@chalmers.com.au>
Re: Trick problem, Selective purging of a directory? <harrisr@bignet.net>
Re: Trick problem, Selective purging of a directory? (Martien Verbruggen)
Re: Use PERL or Java? Which is faster? <ruben@mrbrklyn.com>
Re: Use PERL or Java? Which is faster? (Peter Schuller)
Re: Why are multiple zeroes true? <uri@sysarch.com>
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sun, 17 Dec 2000 01:47:05 GMT
From: deskcode@my-deja.com
Subject: deskcode.com hot new perl resource read more
Message-Id: <91h5uo$rap$1@nnrp1.deja.com>
www.DeskCode.com is a user-based web community for programmers and
developers. Offers resources to 15 different programming languages.
Please come and visit us, share your knowledge by submitting articles,
tutorials, code snippets, or whole programs. You can upload on to our
server or link to a homepage of your choice.
We really need the boost in our perl resources. Deskcode.com was just
luanched on the 13th of Decemeber. Come and give us a view.
Thank You
www.deskcode.com
Sent via Deja.com
http://www.deja.com/
------------------------------
Date: Sat, 16 Dec 2000 23:23:40 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: Help with splitting a ongoing variable?
Message-Id: <3A3BFAA0.51874E8@rochester.rr.com>
bab wrote:
...
> I am currently trying to split $cart up into diffrent variables so I can
> edit the data. The $cart variable holds all the product information put into
> the shopping cart. (product quanitiy, prize, and one other thing but I can't
> think of it)
>
> For example
> $cart currently ouputs this in a e-mail.
>
> product : 1 : 10 : 0
> product : 1 : 5 : 0
>
> I thought this line would splt it up correctly and it sorta does but Its not
> able to do what I want ....
>
> ($first,$second,$third,$fourth, $five, $six, $seven, $eight)= split (/\ : /,
> $cart);
>
> which then the then output looks this in a email...
> product,1,10,0
> product,,,
You didn't show your print statement, but my print statement:
print "$first,$second,$third,$fourth,$five,$six,$seven,$eight\n";
generates:
product,1,10,0
product,1,5,0
,
The reason for the extra field on the end is that you failed to match a
field separator between the end of the first line and the start of the
second line, so $fourth contains 0\nproduct, $seven matches 0\n, and
$eight doesn't match anything.
>
> The problem now becomes that it left out part of the second items data.
>
> The next problem is. If there are lets say 99 items in a shopping cart
> (unlikley but possible) how do I generate variables and then know what the
> generated variables are so I munipulate the data for using in a html email
> and online output use?
...
> trentm1@hotmail.com
Why not split it to an array? Then the quantity of information you are
splitting doesn't matter. In the following code, for example, you can
pick up the code ("product" in your example) in $data[1,5,9,...], the
next item in $data[2,6,10,...], etc.
use Data::Dumper;
@cart=<DATA>; #read the cart
$cart=join '',@cart; #generate $cart like you say you have it
@data=split / : |\n/,$cart; #split out the fields
print Dumper(\@data); #show what we got
__DATA__
product : 1 : 10 : 0
product : 1 : 5 : 0
Myself, I would recommend handling it a line at a time instead, and
making an array of arrays structure out of it for clarity and easier
handling.
--
Bob Walton
------------------------------
Date: Sat, 16 Dec 2000 17:51:38 -0600
From: "bab" <trentm1@hotmail.com>
Subject: Re: Help with splitting a ongoing variable?
Message-Id: <t3o01vher1j170@corp.supernews.com>
Thanks for responding so quickly!!!
I am still new at perl and am sorta learning as I go. (thought I should say
what)
If I put this in my script like it is below.. All I would have to do get
certain infomation is now just do a $data[1]
$data[2]
ect ?
just want to make sure I understand this before I try to implement it ?
use Data;
@cart=<DATA>; #read the cart
$cart=join '',@cart; #generate $cart like you say you have it
@data=split / : |\n/,$cart; #split out the fields
"Bob Walton" <bwalton@rochester.rr.com> wrote in message
news:3A3BFAA0.51874E8@rochester.rr.com...
> bab wrote:
> ...
> > I am currently trying to split $cart up into diffrent variables so I can
> > edit the data. The $cart variable holds all the product information put
into
> > the shopping cart. (product quanitiy, prize, and one other thing but I
can't
> > think of it)
> >
> > For example
> > $cart currently ouputs this in a e-mail.
> >
> > product : 1 : 10 : 0
> > product : 1 : 5 : 0
> >
> > I thought this line would splt it up correctly and it sorta does but Its
not
> > able to do what I want ....
> >
> > ($first,$second,$third,$fourth, $five, $six, $seven, $eight)= split (/\
: /,
> > $cart);
> >
> > which then the then output looks this in a email...
> > product,1,10,0
> > product,,,
>
> You didn't show your print statement, but my print statement:
>
> print "$first,$second,$third,$fourth,$five,$six,$seven,$eight\n";
>
> generates:
>
> product,1,10,0
> product,1,5,0
> ,
>
> The reason for the extra field on the end is that you failed to match a
> field separator between the end of the first line and the start of the
> second line, so $fourth contains 0\nproduct, $seven matches 0\n, and
> $eight doesn't match anything.
>
> >
> > The problem now becomes that it left out part of the second items data.
> >
> > The next problem is. If there are lets say 99 items in a shopping cart
> > (unlikley but possible) how do I generate variables and then know what
the
> > generated variables are so I munipulate the data for using in a html
email
> > and online output use?
> ...
> > trentm1@hotmail.com
>
> Why not split it to an array? Then the quantity of information you are
> splitting doesn't matter. In the following code, for example, you can
> pick up the code ("product" in your example) in $data[1,5,9,...], the
> next item in $data[2,6,10,...], etc.
>
> use Data::Dumper;
> @cart=<DATA>; #read the cart
> $cart=join '',@cart; #generate $cart like you say you have it
> @data=split / : |\n/,$cart; #split out the fields
> print Dumper(\@data); #show what we got
> __DATA__
> product : 1 : 10 : 0
> product : 1 : 5 : 0
>
> Myself, I would recommend handling it a line at a time instead, and
> making an array of arrays structure out of it for clarity and easier
> handling.
> --
> Bob Walton
------------------------------
Date: Sun, 17 Dec 2000 01:32:07 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Help with splitting a ongoing variable?
Message-Id: <ak5o3tgclie9j9mknnt36a3lcbuk6h8ja1@4ax.com>
bab wrote:
>I am currently trying to split $cart up into diffrent variables so I can
>edit the data. The $cart variable holds all the product information put into
>the shopping cart. (product quanitiy, prize, and one other thing but I can't
>think of it)
>
>For example
>$cart currently ouputs this in a e-mail.
>
>product : 1 : 10 : 0
>product : 1 : 5 : 0
I think your post is missing some vital information. How is this
variable $cart composed? What is the connection between $cart and the
"e-mail"?
If your "$cart" actually contains lines of text, one per product, and 4
peices of info (in this example) per line, then you can do:
$cart = "product : 1 : 10 : 0\nproduct : 1 : 5 : 0\n";
@product = map { [ split /\s*:\s*/ ] }split /\n/, $cart;
and @product will now contain two anonymous arrays, each containing 4
pieces of data. You can see exactly what it contains using this
debugging aid:
use Data::Dumper;
print Dumper \@product;
--
Bart.
------------------------------
Date: Sat, 16 Dec 2000 20:00:50 -0600
From: "bab" <trentm1@hotmail.com>
Subject: Re: Help with splitting a ongoing variable?
Message-Id: <t3o7kkppf8l907@corp.supernews.com>
What I am actually doing is making a script to interface with a online
e-commerace shopping cart. What this script is doing is taking the
information processed through this online shopping cart (on someone else
server) and passing it to my server so I can send html e-mails, save the
information in a database ect.
$cart basicaly boils down to the only important peice of data that I can't
seem to get sperated. (its about the only variable that has mulitiple pecies
of data attached to it) I don't know how the $cart is composed since it is
on someone else server.
I do know that if I put $cart in my script it ouputs all the items that
people have decided to purchase on my page
so if someone added 2 items into my basket and checked out this is what the
output would be.
yo-yo : 3 : 10 : 0
yo-yo-yo : 1 : 5 : 0
if someone ordered 5 diffrent product items it would be (just a example the
information under product:quanity:price would all be diffrent of course)
product : quanitiy : price : whatever
yo 1 : 10 : 0
yo-yo : 2 : 5 : 0
yo-yo-yo : 3 : 10 : 0
yo-yo-yo-yo : 4 : 5 : 0
yo-yo-yo-yo-yo : 5 : 9 : 0
Now this would be fine but the problem is if I send a html e-mail I want to
beable to put this into a nice little table... that is locacted below...
(The way the $cart is currently I can't do what I want with the data) (If I
do it like this which I am sure there is a way I need to somehow add in if
then statements or something so the table will be generated based on how
many items are in the cart?)
After I figure this one thing out I next be wanting to save all information
to a database that can be displayed and edit via a web user interface. Any
suggestions on this? I was thinking mysqual database or something similar
any good suggestions? But I think I had better stick to one thing at a time.
If I can't get the above done I am not sure the database idea is a good one.
THANKS FOR ALL YOUR HELP !!!!
<table border=0 cellspacing=0 cellpadding=1 width="550" align="CENTER">
<tr>
<td bgcolor=silver width="300">Product</td>
<td bgcolor=silver width="77">Quantity</td>
<td bgcolor=silver width="77" align="right">Price</td>
</tr>
<tr>
<td>$first</td>
<td>$second</td>
<td align=right>$third</td>
</tr>
<tr>
<td>$fourth</td>
<td>$fifth</td>
<td align=right>$six</td>
</tr>
</table>
"Bart Lateur" <bart.lateur@skynet.be> wrote in message
news:ak5o3tgclie9j9mknnt36a3lcbuk6h8ja1@4ax.com...
> bab wrote:
>
> >I am currently trying to split $cart up into diffrent variables so I can
> >edit the data. The $cart variable holds all the product information put
into
> >the shopping cart. (product quanitiy, prize, and one other thing but I
can't
> >think of it)
> >
> >For example
> >$cart currently ouputs this in a e-mail.
> >
> >product : 1 : 10 : 0
> >product : 1 : 5 : 0
>
> I think your post is missing some vital information. How is this
> variable $cart composed? What is the connection between $cart and the
> "e-mail"?
>
> If your "$cart" actually contains lines of text, one per product, and 4
> peices of info (in this example) per line, then you can do:
>
> $cart = "product : 1 : 10 : 0\nproduct : 1 : 5 : 0\n";
> @product = map { [ split /\s*:\s*/ ] }split /\n/, $cart;
>
> and @product will now contain two anonymous arrays, each containing 4
> pieces of data. You can see exactly what it contains using this
> debugging aid:
>
> use Data::Dumper;
> print Dumper \@product;
>
> --
> Bart.
------------------------------
Date: Sat, 16 Dec 2000 23:09:32 GMT
From: tim@degree.ath.cx (Tim Hammerquist)
Subject: Re: How to identify Windows platform from within a Perl program?
Message-Id: <slrn93ntkg.9mp.tim@degree.ath.cx>
Jeff Robertson <jeff_robertson@yahoo.com> wrote:
> > The Perl variable $^O will return the platform, but it's exact value
> on
> > Win32 platforms varies with the distribution. ActivePerl will return
> a
> > different value for any given platform than will MKS Perl.
>
> I'm pretty sure that (in ActivePerl, at least) $^O will simply
> be "MSWin32" on all of the platforms we are talking about here.
To clarify:
$AP_retval("Win95") ne $MKS_retval("Win95");
$AP_retval("Win98") ne $MKS_retval("Win98");
$AP_retval("WinNT") ne $MKS_retval("WinNT");
$MKS_retval("Win98") ne $MKS_retval("WinNT");
--
-Tim Hammerquist <timmy@cpan.org>
I don't have any solution, but I certainly admire the problem.
-- Ashleigh Brilliant
------------------------------
Date: 16 Dec 2000 19:21:32 -0600
From: logan@cs.utexas.edu (Logan Shaw)
Subject: Re: Is Perl dying?
Message-Id: <91h4es$ec$1@boomer.cs.utexas.edu>
In article <brian+usenet-0182D5.16135416122000@news.panix.com>,
brian d foy <brian+usenet@smithrenaud.com> wrote:
>however, you can't get rid of bad managers.
Yes you can. It's just that sometimes it takes many months of
cooperation from a large number of employees.
- Logan
------------------------------
Date: Sun, 17 Dec 2000 01:04:23 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Language evolution C->Perl->C++->Java->Python (Is Python the ULTIMATE oflanguages??)
Message-Id: <s54o3tggqpjrnjdjpm4vsc9oqsb81mieq6@4ax.com>
Just Me wrote:
>We will go back to basics and end up in Smalltalk which is the ultimate OO
>language where everything is an object and no types exist.
Don't you think, as I do, that the way of adding through numbers by
sending a "+" message and *one value* to the other value, is, er, rather
artificial? The arguments are not peers for the operation, as I feel
they should be.
--
Bart.
------------------------------
Date: Sat, 16 Dec 2000 20:46:00 -0500
From: "Randy Harris" <harrisr@bignet.net>
Subject: Re: MIME::Lite error
Message-Id: <t3o6ljsuid6n0c@corp.supernews.com>
Randy Harris <harrisr@bignet.net> wrote in message
news:t3m7dn5k29d67c@corp.supernews.com...
> I've installed MIME::Lite on an HP system. It seems to work but I get
> these errors whenever I use it. They also occurred when I ran 'make
> test' during the install. What do they mean, where do they come from
> and how do I stop them?
>
> Unrecognized escape \s passed through at (eval 2) line 11.
> Unrecognized escape \s passed through at (eval 2) line 11.
> Unrecognized escape \s passed through at (eval 2) line 11.
>
> Randy Harris
>
How about the (eval 2)? Can anyone shed light on what that is?
The error seems to be on line 11. Can anyone give me an idea, line 11
of what?
I'd be grateful for any suggestions.
Randy Harris
------------------------------
Date: Sun, 17 Dec 2000 00:23:16 -0000
From: cberry@cinenet.net (Craig Berry)
Subject: Re: One-Liner to Sum a Stack of Numbers?
Message-Id: <t3o1rkrvmaa585@corp.supernews.com>
revjack (revjack@revjack.net) wrote:
: More and more I find myself having to take a stream of
: numbers that comes from some process, like:
:
: 1192
[snip]
: 3384
:
: ...and simply determine the sum of them. I have been doing
: it like this:
:
: (process) | perl -wle 'while(<>){$x+=$_}print $x'
:
: Is there a better|smarter|faster|more elegant way to produce
: the sum of such output?
Well, a trivial way:
perl -nwle '$x+=$_}{print$x'
This works because -n actually behaves as it it's wrapping the -e code in
'while (<>) { ... }', so you can fake it out by inserting extra braces in
the middle of the -e code.
--
| Craig Berry - http://www.cinenet.net/~cberry/
--*-- "The hills are burning, and the wind is raging; and the clock
| strikes midnight in the Garden of Allah." - Don Henley
------------------------------
Date: Sat, 16 Dec 2000 23:48:16 GMT
From: tim@degree.ath.cx (Tim Hammerquist)
Subject: OT:Re: Perl programming
Message-Id: <slrn93nvt3.9mp.tim@degree.ath.cx>
SuperGumby <tick.toff@spam.com> wrote:
> I leave arguments about jeopardy posting to people who can't understand that
> the great majority of newsgroup users are using a newsreader with a preview
> pane and capable of 'threading'. I find it amusing that you 'jeopardied'
> this comment.
Do you understand that "the great majority of newsgroup users are using
a newsreader with a preview pane and capable of 'threading'"? Then why
are you arguing about jeopardy posting?
BTW: What are you implying by mentioning threading/previewing
newsreaders? Or did you mean to say "Micro$oft newsreader with a preview
pane and capable of threading"? Check out slrn
(http://slrn.sourceforge.net/); it has threading, preview panes, and
*gasp!* color! They were _even_ nice enough to precompile a Win32
binary for you who must shell out money for compilers.
--
-Tim Hammerquist <timmy@cpan.org>
Any emotion, if it is sincere, is involuntary.
-- Mark Twain
------------------------------
Date: 16 Dec 2000 17:00:41 -0800
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: Posting Guidelines for comp.lang.perl.misc ($Revision: 0.1 $)
Message-Id: <m11yv7g8ue.fsf@halfdome.holdit.com>
>>>>> "Philip" == Philip 'Yes, that's my address' Newton <nospam.newton@gmx.li> writes:
Philip> I think I knew that. I should have been more specific, I suppose.
Philip> Why "USENET" and not "Usenet" or "usenet"? I rather doubt it's an acronym.
USENET was traditionally used all uppercase, despite it not being an
acronym. That should be no more difficult to grasp than the fact that
Perl is capitalized as such, even though it can be described as being
an acronym.
--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
------------------------------
Date: Sat, 16 Dec 2000 23:32:24 GMT
From: tim@degree.ath.cx (Tim Hammerquist)
Subject: Re: Q: installing perl on win98
Message-Id: <slrn93nuvc.9mp.tim@degree.ath.cx>
Richard Leclair <leclair@iinet.net.au> wrote:
> I have written perl CGIs on my ISP (linux) with no problems, but I'd
> like to test stuff locally on my machine, and someone said that I could
> set up like a local server running ActivePerl.
Your ISP's server software is Apache, right? Grab Apache from
http://www.apache.org/ or mod_perl Apache via http://perl.apache.org/.
Install _ANY_ distribution of Perl you want, since Apache doesn't care
(unless you want mod_perl; mod_perl kinda rules out ActivePerl).
Install Perl at /usr/bin/perl and you have as close to completely
portable testing system as you're gonna get being on Win32.
Choose you're own server software, but Apache will get you much more
familiar with your options on the ISP server. Just don't expect Apache
(or any software) to be enterprise-scale stable on Win32. It's not
(yet).
Choose your own Perl distribution or (better yet) roll your own if
possible. And don't _ever_ think ActivePerl is the only Perl
distribution for Win32.
And PWS _will_ work with ActivePerl PerlScript and CGI scripts. It
almost always takes a registry hack which I could never endorse...unless
it's Windows. ;) Someone will usually ask how to hack it once every
week or two.
Oh, and once you get Perl installed on your box, read the extensive
documentation that comes with it. This is your best bet on staying
flame-free out of our killfiles. =)
--
-Tim Hammerquist <timmy@cpan.org>
Life is too serious to be taken seriously.
-- Mike Leonard
------------------------------
Date: Sat, 16 Dec 2000 23:11:39 GMT
From: Mike Lin <mikelin6@home.com>
Subject: Sendmail script problems
Message-Id: <3A3BF83D.6A8425D6@home.com>
Please take a look and tell me what you think is wrong.
#!/usr/local/bin/perl
$email = 'mikelin6@home.com';
##############################
#email download code to email specified
#
print "Content-type: text/html\n\n";
open (MAIL, "|/usr/bin/sendmail -t") || &MailError;
print MAIL "To: $email\nFrom: Industrial Network Solutions\n";
print MAIL "Subject: Trial Version Industrial SNMP Suite\n";
print MAIL "Here is the code: 1234\n";
close (MAIL);
I don't have Unix installed so I can't test the sendmail script
locally. I'm not allowed to telnet into my webhost to run the test the
script there. Basically, I can't check what the error messages are. I
upload the script then run it in my web browser to see if it works but
it doesn't.
Thanks
Mike Lin
------------------------------
Date: Sun, 17 Dec 2000 16:15:49 +1000
From: "Robert Chalmers" <robert@chalmers.com.au>
Subject: thanks - Re: Trick problem, Selective purging of a directory?
Message-Id: <wMX_5.25$x2.7670@nsw.nnrp.telstra.net>
Thanks to both answers - that's excellent.
Just what I wanted - and can probably use both methods in their places.
thanks again
Robert
--
---
Robert Chalmers
http://www.quantum-radio.net.au Quantum Radio robert@quantum-radio.net.au
http://www.inexpensivewebsites.com Domain Name Registrations info@inexpensivewebsites.com
"Martien Verbruggen" <mgjv@tradingpost.com.au> wrote in message news:slrn93oh0j.8i7.mgjv@martien.heliotrope.home...
> On Sun, 17 Dec 2000 15:19:09 +1000,
> Robert Chalmers <robert@chalmers.com.au> wrote:
>
> [Article reformatted to fit within 80 columns]
>
> > I'm trying to discover a way of selectively purging a directory of
> > files, leaving only the latest 30 files there. Perhaps run from a
> > cron job, or as part of another program, but basically it goes like this.
>
> #!/usr/local/bin/perl -wl
> use strict;
>
> my $dir = '/spare/backup';
> my $num_to_keep = 30;
>
> opendir(DIR, $dir) or die $!;
> my @files_by_mtime =
> sort { -M $a <=> -M $b }
> grep { -f }
> map { "$dir/$_" }
> readdir DIR;
> close DIR;
>
> my @delete = splice @files_by_mtime, $num_to_keep;
>
> print "Keep: ", scalar @files_by_mtime;
> print for @files_by_mtime;
>
> print "Delete: ", scalar @delete;
> print for @delete;
> __END__
>
> All you need to do instead of printing, is unlinking. You might want to
> check for errors when you do.
>
> Martien
> --
> Martien Verbruggen |
> Interactive Media Division | If at first you don't succeed, try
> Commercial Dynamics Pty. Ltd. | again. Then quit; there's no use
> NSW, Australia | being a damn fool about it.
------------------------------
Date: Sun, 17 Dec 2000 15:19:09 +1000
From: "Robert Chalmers" <robert@chalmers.com.au>
Subject: Trick problem, Selective purging of a directory?
Message-Id: <kXW_5.23$x2.7151@nsw.nnrp.telstra.net>
I'm trying to discover a way of selectively purging a directory of files, leaving only the latest 30 files there. Perhaps run from a
cron job, or as part of another program, but basically it goes like this.
The directory has a new file added each day, up until there are 30 files there - When the 31st file is added, the 1st file placed in
the directory is deleted. Leaving 30 files there, from the newest, the just added 30th file, to the oldest the now 1st file. In the
event that no daily file is added, no file is removed - still leaving 30 files in the directory.
Or perhaps put another way.
The directory is check each day after the 'add a file run' and if the count is greater than 30, then delete the oldest file(s) till
there is only 30 left, from the newest to the oldest.
any ideas. I'm looking at stat. Maybe feeding a directory listing into a %key or @array, counting them, sorting by oldest creation
time, and deleting the oldest. hmmm.
Trouble is, I cant' see a way to begin this. Maybe I need to take a break, but any help with ideas would be much appreciated. Or
even pointing to where some ideas may be found..
Thanks
Robert
--
---
Robert Chalmers
http://www.quantum-radio.net.au Quantum Radio robert@quantum-radio.net.au
http://www.inexpensivewebsites.com Domain Name Registrations info@inexpensivewebsites.com
------------------------------
Date: Sat, 16 Dec 2000 23:43:47 -0500
From: "Randy Harris" <harrisr@bignet.net>
Subject: Re: Trick problem, Selective purging of a directory?
Message-Id: <t3oh2vildapq03@corp.supernews.com>
Robert Chalmers <robert@chalmers.com.au> wrote in message
news:kXW_5.23$x2.7151@nsw.nnrp.telstra.net...
> I'm trying to discover a way of selectively purging a directory of
files, leaving only the latest 30 files there. Perhaps run from a
> cron job, or as part of another program, but basically it goes like
this.
>
> The directory has a new file added each day, up until there are 30
files there - When the 31st file is added, the 1st file placed in
> the directory is deleted. Leaving 30 files there, from the newest, the
just added 30th file, to the oldest the now 1st file. In the
> event that no daily file is added, no file is removed - still leaving
30 files in the directory.
>
> Or perhaps put another way.
> The directory is check each day after the 'add a file run' and if the
count is greater than 30, then delete the oldest file(s) till
> there is only 30 left, from the newest to the oldest.
>
> any ideas. I'm looking at stat. Maybe feeding a directory listing into
a %key or @array, counting them, sorting by oldest creation
> time, and deleting the oldest. hmmm.
>
> Trouble is, I cant' see a way to begin this. Maybe I need to take a
break, but any help with ideas would be much appreciated. Or
> even pointing to where some ideas may be found..
>
> Thanks
> Robert
>
Someone will probably give you a good Perl way to do this, but in case
not...
rm `ls -t | tail -n +30`
in Unix, will delete all files older than the first 30.
HTH
Randy Harris
------------------------------
Date: Sun, 17 Dec 2000 15:41:55 +1100
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: Trick problem, Selective purging of a directory?
Message-Id: <slrn93oh0j.8i7.mgjv@martien.heliotrope.home>
On Sun, 17 Dec 2000 15:19:09 +1000,
Robert Chalmers <robert@chalmers.com.au> wrote:
[Article reformatted to fit within 80 columns]
> I'm trying to discover a way of selectively purging a directory of
> files, leaving only the latest 30 files there. Perhaps run from a
> cron job, or as part of another program, but basically it goes like this.
#!/usr/local/bin/perl -wl
use strict;
my $dir = '/spare/backup';
my $num_to_keep = 30;
opendir(DIR, $dir) or die $!;
my @files_by_mtime =
sort { -M $a <=> -M $b }
grep { -f }
map { "$dir/$_" }
readdir DIR;
close DIR;
my @delete = splice @files_by_mtime, $num_to_keep;
print "Keep: ", scalar @files_by_mtime;
print for @files_by_mtime;
print "Delete: ", scalar @delete;
print for @delete;
__END__
All you need to do instead of printing, is unlinking. You might want to
check for errors when you do.
Martien
--
Martien Verbruggen |
Interactive Media Division | If at first you don't succeed, try
Commercial Dynamics Pty. Ltd. | again. Then quit; there's no use
NSW, Australia | being a damn fool about it.
------------------------------
Date: Sun, 17 Dec 2000 00:58:49 GMT
From: Brooklyn Linux Solutions CEO <ruben@mrbrklyn.com>
Subject: Re: Use PERL or Java? Which is faster?
Message-Id: <ddU_5.140525$DG3.2767660@news2.giganews.com>
Not in my benchmarks. Java showed by be about the 3rd the speed of
perl in serving up dynamic pages with moderate calculations.
Comparing Java to C++
You can through any benchmarks you care to, and I don't beleive them.
Java historically brings computers to their knees.
Ruben
Brooklyn Linux Solutions
http://www.mrbrklyn.com
http://www.brooklynonline.com
1-718-382-5752
------------------------------
Date: 17 Dec 2000 01:11:42 GMT
From: peter.schuller@infidyne.com (Peter Schuller)
Subject: Re: Use PERL or Java? Which is faster?
Message-Id: <91h3se$rd6$2@hecate.umd.edu>
>Not in my benchmarks. Java showed by be about the 3rd the speed of
>perl in serving up dynamic pages with moderate calculations.
Are you talking about perl CGI scrpts versus servlets or something?
That is NOT an accurate measurement of language speed.
>Java historically brings computers to their knees.
This isn't history. This is today. I'm sure the first implementation of perl
was dog slow too.
--
/ Peter Schuller, InfiDyne Technologies HB
PGP userID: 0x5584BD98 or 'Peter Schuller <peter.schuller@infidyne.com>'
Key retrival: Send an E-Mail to getpgpkey@scode.infidyne.com
E-Mail: peter.schuller@infidyne.com Web: http://scode.infidyne.com
------------------------------
Date: Sat, 16 Dec 2000 23:23:15 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: Why are multiple zeroes true?
Message-Id: <x7r938eysb.fsf@home.sysarch.com>
>>>>> "CB" == Craig Berry <cberry@cinenet.net> writes:
CB> Uri Guttman (uri@sysarch.com) wrote:
CB> : see my longer posts which say the same thing. :)
CB> Yours hadn't propagated to me when I wrote mine. Nice to form a
CB> faction with you, by the way. :)
i also am glad to see i am not the only one who looks at false that
way. i am planning an article on perl contexts and the boolean section
will be derived from my post. also tom's point how perl generated
boolean values are both '' and 0 at the same time is good to know. perl
obviously sets both the string and integer flags in the SV in that
case.
uri
--
Uri Guttman --------- uri@sysarch.com ---------- http://www.sysarch.com
SYStems ARCHitecture, Software Engineering, Perl, Internet, UNIX Consulting
The Perl Books Page ----------- http://www.sysarch.com/cgi-bin/perl_books
The Best Search Engine on the Net ---------- http://www.northernlight.com
------------------------------
Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 16 Sep 99)
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: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.
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 V9 Issue 5132
**************************************