[30911] in Perl-Users-Digest
Perl-Users Digest, Issue: 2156 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Jan 25 00:14:19 2009
Date: Sat, 24 Jan 2009 21:14:10 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Sat, 24 Jan 2009 Volume: 11 Number: 2156
Today's topics:
Re: Peer Review for Folder Delete Script <someone@example.com>
Re: Peer Review for Folder Delete Script <XXjbhuntxx@white-star.com>
Re: Peer Review for Folder Delete Script <larry@example.invalid>
Re: Peer Review for Folder Delete Script sln@netherlands.com
Re: Peer Review for Folder Delete Script <larry@example.invalid>
Re: Peer Review for Folder Delete Script sln@netherlands.com
Re: Peer Review for Folder Delete Script <XXjbhuntxx@white-star.com>
Re: Peer Review for Folder Delete Script sln@netherlands.com
Re: Peer Review for Folder Delete Script <XXjbhuntxx@white-star.com>
Re: Peer Review for Folder Delete Script <tadmc@seesig.invalid>
Re: Peer Review for Folder Delete Script <tadmc@seesig.invalid>
Re: Peer Review for Folder Delete Script <XXjbhuntxx@white-star.com>
syntax color lang source code in blogs or website <xahlee@gmail.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sat, 24 Jan 2009 15:32:51 -0800
From: "John W. Krahn" <someone@example.com>
Subject: Re: Peer Review for Folder Delete Script
Message-Id: <ByNel.3434$2o3.432@newsfe10.iad>
Cosmic Cruizer wrote:
> Thanks for your input uri.
>
> Some of my code probably ended up pretty sloppy since my 60 minute project
> turned into about 3 hours worth of frustrations. (Fortunately, I was
> running it on a test system, so no real data loss occurred.)
>
> For example, I should not have needed someone to point out I should have
> used: my $mtime = (stat($entry))[9] instead of the long drawn out method I
> originally used. But then again... that's why we have code reviews. ;)
>
>
> I also simplified a few other items and cleaned up the superfluous syntax.
> (But I kept the end of line comments because that's how I like to do it...
> and at least I add comments.)
>
> Thank you very much!
One thing that Uri failed to mention, in the line:
> my ($month, $day, $year) = (split / /, scalar localtime)[1,2,4];
You are using the pattern / / which will not work correctly on all dates:
$ perl -le'print for ( split / /, localtime 1232827200 )[1,2,4]'
Jan
24
2009
$ perl -le'print for ( split / /, localtime 1231358400 )[1,2,4]'
Jan
12:00:00
That is because a single digit day number will have *two* spaces in
front of it. You need to use the special split pattern ' ' instead:
$ perl -le'print for ( split " ", localtime 1231358400 )[1,2,4]'
Jan
7
2009
John
--
Those people who think they know everything are a great
annoyance to those of us who do. -- Isaac Asimov
------------------------------
Date: Sat, 24 Jan 2009 23:41:00 GMT
From: Cosmic Cruizer <XXjbhuntxx@white-star.com>
Subject: Re: Peer Review for Folder Delete Script
Message-Id: <Xns9B9D9F4C83B93ccruizermydejacom@207.115.33.102>
"John W. Krahn" <someone@example.com> wrote in
news:ByNel.3434$2o3.432@newsfe10.iad:
> Cosmic Cruizer wrote:
>> Thanks for your input uri.
>>
>> Some of my code probably ended up pretty sloppy since my 60 minute
>> project turned into about 3 hours worth of frustrations.
>> (Fortunately, I was running it on a test system, so no real data loss
>> occurred.)
>>
>> For example, I should not have needed someone to point out I should
>> have used: my $mtime = (stat($entry))[9] instead of the long drawn
>> out method I originally used. But then again... that's why we have
>> code reviews. ;)
>>
>>
>> I also simplified a few other items and cleaned up the superfluous
>> syntax. (But I kept the end of line comments because that's how I
>> like to do it... and at least I add comments.)
>>
>> Thank you very much!
>
> One thing that Uri failed to mention, in the line:
>
>> my ($month, $day, $year) = (split / /, scalar localtime)[1,2,4];
>
> You are using the pattern / / which will not work correctly on all
> dates:
>
> $ perl -le'print for ( split / /, localtime 1232827200 )[1,2,4]'
> Jan
> 24
> 2009
> $ perl -le'print for ( split / /, localtime 1231358400 )[1,2,4]'
> Jan
>
> 12:00:00
>
>
> That is because a single digit day number will have *two* spaces in
> front of it. You need to use the special split pattern ' ' instead:
>
> $ perl -le'print for ( split " ", localtime 1231358400 )[1,2,4]'
> Jan
> 7
> 2009
>
>
>
> John
Thanks John, but I had already changed it to use the following:
my $timestamp = localtime;
But the next time I use split with localtime, I will use the format you
showed.
...Cos
------------------------------
Date: Sat, 24 Jan 2009 16:52:14 -0700
From: Larry Gates <larry@example.invalid>
Subject: Re: Peer Review for Folder Delete Script
Message-Id: <42rt36aygn14.41n2bafqk011$.dlg@40tude.net>
On Sat, 24 Jan 2009 21:19:28 GMT, Cosmic Cruizer wrote:
> Thanks for your input uri.
>
> Some of my code probably ended up pretty sloppy since my 60 minute project
> turned into about 3 hours worth of frustrations. (Fortunately, I was
> running it on a test system, so no real data loss occurred.)
>
> For example, I should not have needed someone to point out I should have
> used: my $mtime = (stat($entry))[9] instead of the long drawn out method I
> originally used. But then again... that's why we have code reviews. ;)
>
>
> I also simplified a few other items and cleaned up the superfluous syntax.
> (But I kept the end of line comments because that's how I like to do it...
> and at least I add comments.)
>
> Thank you very much!
>
> ...Cos
Please post a cleaned up version. I only looked at it cursorily as the
comments were worse than distracting. Which directory is deleted?
--
larry gates
But at some point you just give up and call it cheating, er,
I mean, AOP. :-)
-- Larry Wall in <20050307173849.GA16558@wall.org>
------------------------------
Date: Sun, 25 Jan 2009 00:08:45 GMT
From: sln@netherlands.com
Subject: Re: Peer Review for Folder Delete Script
Message-Id: <16bnn4hvs90ik147rl8ablp87k5v12nlsu@4ax.com>
On Sat, 24 Jan 2009 21:19:28 GMT, Cosmic Cruizer <XXjbhuntxx@white-star.com> wrote:
>Thanks for your input uri.
>
>Some of my code probably ended up pretty sloppy since my 60 minute project
>turned into about 3 hours worth of frustrations. (Fortunately, I was
>running it on a test system, so no real data loss occurred.)
>
So you are being paid to write this code under a deadline then.
>For example, I should not have needed someone to point out I should have
>used: my $mtime = (stat($entry))[9] instead of the long drawn out method I
>originally used. But then again... that's why we have code reviews. ;)
>
And you are posting here to clean up you code (review) before anybody at
work see's it.
>
>I also simplified a few other items and cleaned up the superfluous syntax.
>(But I kept the end of line comments because that's how I like to do it...
>and at least I add comments.)
>
>Thank you very much!
>
>...Cos
Jeez, where can I get a job like that?
sln
------------------------------
Date: Sat, 24 Jan 2009 17:11:16 -0700
From: Larry Gates <larry@example.invalid>
Subject: Re: Peer Review for Folder Delete Script
Message-Id: <vjnt1b92lslw$.apcu6oelk9so.dlg@40tude.net>
On Sat, 24 Jan 2009 15:32:51 -0800, John W. Krahn wrote:
> You are using the pattern / / which will not work correctly on all dates:
>
> $ perl -le'print for ( split / /, localtime 1232827200 )[1,2,4]'
> Jan
> 24
> 2009
> $ perl -le'print for ( split / /, localtime 1231358400 )[1,2,4]'
> Jan
>
> 12:00:00
>
>
> That is because a single digit day number will have *two* spaces in
> front of it. You need to use the special split pattern ' ' instead:
>
> $ perl -le'print for ( split " ", localtime 1231358400 )[1,2,4]'
> Jan
> 7
> 2009
>
>
>
> John
John,
I'm trying to split something on a space and was using / /. How again does
it differ from " "?
while (my $line = <$gh>) {
my @s = split / /, $line;
print STDOUT @s;
}
How could I send @s to STDOUT to see if I'm splitting where I think I am?
--
larry gates
It's certainly easy to calculate the average attendance for Perl
conferences.
-- Larry Wall in <199710071721.KAA19014@wall.org>
------------------------------
Date: Sun, 25 Jan 2009 00:21:05 GMT
From: sln@netherlands.com
Subject: Re: Peer Review for Folder Delete Script
Message-Id: <uvbnn4ltjgop3nrnobdi7d5uniu527jcs7@4ax.com>
On Sat, 24 Jan 2009 17:11:16 -0700, Larry Gates <larry@example.invalid> wrote:
>On Sat, 24 Jan 2009 15:32:51 -0800, John W. Krahn wrote:
>
>> You are using the pattern / / which will not work correctly on all dates:
>>
>> $ perl -le'print for ( split / /, localtime 1232827200 )[1,2,4]'
>> Jan
>> 24
>> 2009
>> $ perl -le'print for ( split / /, localtime 1231358400 )[1,2,4]'
>> Jan
>>
>> 12:00:00
>>
>>
>> That is because a single digit day number will have *two* spaces in
>> front of it. You need to use the special split pattern ' ' instead:
>>
>> $ perl -le'print for ( split " ", localtime 1231358400 )[1,2,4]'
>> Jan
>> 7
>> 2009
>>
>>
>>
>> John
>
>John,
>
>I'm trying to split something on a space and was using / /. How again does
>it differ from " "?
>
> while (my $line = <$gh>) {
>
> my @s = split / /, $line;
> print STDOUT @s;
>}
>
>How could I send @s to STDOUT to see if I'm splitting where I think I am?
From what I hear:
"As a special case, specifying a PATTERN of space (' ') will split on white space
just as split with no arguments does. Thus, split(' ') can be used to emulate awk's
default behavior, whereas split(/ /) will give you as many null initial fields as
there are leading spaces. A split on /\s+/ is like a split(' ') except that any
leading whitespace produces a null first field.
A split with no arguments really does a split(' ', $_) internally."
sln
------------------------------
Date: Sun, 25 Jan 2009 00:34:36 GMT
From: Cosmic Cruizer <XXjbhuntxx@white-star.com>
Subject: Re: Peer Review for Folder Delete Script
Message-Id: <Xns9B9DA862C2698ccruizermydejacom@207.115.33.102>
sln@netherlands.com wrote in
news:16bnn4hvs90ik147rl8ablp87k5v12nlsu@4ax.com:
> On Sat, 24 Jan 2009 21:19:28 GMT, Cosmic Cruizer
> <XXjbhuntxx@white-star.com> wrote:
>
>>Thanks for your input uri.
>>
>>Some of my code probably ended up pretty sloppy since my 60 minute
>>project turned into about 3 hours worth of frustrations. (Fortunately,
>>I was running it on a test system, so no real data loss occurred.)
>>
> So you are being paid to write this code under a deadline then.
>
>>For example, I should not have needed someone to point out I should
>>have used: my $mtime = (stat($entry))[9] instead of the long drawn
>>out method I originally used. But then again... that's why we have
>>code reviews. ;)
>>
> And you are posting here to clean up you code (review) before anybody
> at work see's it.
>>
>>I also simplified a few other items and cleaned up the superfluous
>>syntax. (But I kept the end of line comments because that's how I like
>>to do it... and at least I add comments.)
>>
>>Thank you very much!
>>
>>...Cos
>
> Jeez, where can I get a job like that?
>
> sln
>
>
No, I'm not a programmer and I don't get paid to write code. I write
code/utilities to make life easier on myself and others. The way I see it,
if there is a task that needs to be done more than once, automate it.
Generally, I don't post my code, but in this case, I kept deleting files
and directories I was not targeting. Therefore, I thought I would have
others look at it before I put it on a production system.
Besides, I find creating Perl programs is much more fun than doing
crossword puzzles. In both case, I'm not really very good at either one,
but that does not stop me from trying.
------------------------------
Date: Sun, 25 Jan 2009 00:55:01 GMT
From: sln@netherlands.com
Subject: Re: Peer Review for Folder Delete Script
Message-Id: <bednn4t0jn3oa1j2lenm0emo1j315sujlv@4ax.com>
On Sun, 25 Jan 2009 00:34:36 GMT, Cosmic Cruizer <XXjbhuntxx@white-star.com> wrote:
>sln@netherlands.com wrote in
>news:16bnn4hvs90ik147rl8ablp87k5v12nlsu@4ax.com:
>
>> On Sat, 24 Jan 2009 21:19:28 GMT, Cosmic Cruizer
>> <XXjbhuntxx@white-star.com> wrote:
>>
>>>Thanks for your input uri.
>>>
>>>Some of my code probably ended up pretty sloppy since my 60 minute
>>>project turned into about 3 hours worth of frustrations. (Fortunately,
>>>I was running it on a test system, so no real data loss occurred.)
>>>
>> So you are being paid to write this code under a deadline then.
>>
>>>For example, I should not have needed someone to point out I should
>>>have used: my $mtime = (stat($entry))[9] instead of the long drawn
>>>out method I originally used. But then again... that's why we have
>>>code reviews. ;)
>>>
>> And you are posting here to clean up you code (review) before anybody
>> at work see's it.
>>>
>>>I also simplified a few other items and cleaned up the superfluous
>>>syntax. (But I kept the end of line comments because that's how I like
>>>to do it... and at least I add comments.)
>>>
>>>Thank you very much!
>>>
>>>...Cos
>>
>> Jeez, where can I get a job like that?
>>
>> sln
>>
>>
>
>No, I'm not a programmer and I don't get paid to write code. I write
>code/utilities to make life easier on myself and others. The way I see it,
>if there is a task that needs to be done more than once, automate it.
>
>Generally, I don't post my code, but in this case, I kept deleting files
>and directories I was not targeting. Therefore, I thought I would have
>others look at it before I put it on a production system.
>
>Besides, I find creating Perl programs is much more fun than doing
>crossword puzzles. In both case, I'm not really very good at either one,
>but that does not stop me from trying.
Unfortunately, you really, really have to know what your doing to
automate deleting files and directories on a production machine.
This does not sound like a hobby nor crossword puzzles.
And your not a programmer, your just making life easier on behalf of
yourself and others.
Why didn't you just say from the outset your f*cking around for personal,
amatuer reasons, why make it sound like its a job?
If you had years of experience you wouldn't ask these questions. If you
don't, the production crap is out as far as a company. Either way its
sleezy sounding.
Stop blowing sunshine up peoples ass', your not fooling anybody.
In fact, nobody cares what your using the 'code review' for, maybe
as a non-programmer, you should stop slinging buzzwords so it doesen't
sound like your taking advantage of somebody here.
sln
------------------------------
Date: Sun, 25 Jan 2009 01:54:34 GMT
From: Cosmic Cruizer <XXjbhuntxx@white-star.com>
Subject: Re: Peer Review for Folder Delete Script
Message-Id: <Xns9B9DB51336E12ccruizermydejacom@207.115.17.102>
Larry Gates <larry@example.invalid> wrote in
news:42rt36aygn14.41n2bafqk011$.dlg@40tude.net:
> Please post a cleaned up version. I only looked at it cursorily as
> the comments were worse than distracting. Which directory is deleted?
Larry,
Just in case you are still interested, here is the code without all the
comments. As Uri recommended, I tried File::Slurp. Since I do not have
the library on my local computer, I'm not sure if it is on the production
system, therefore, I did not implement that change.
This is pretty much what I will be trying next week. The bi-weekly full
backup was on Friday to a VTL, so if something does happen, it will be
relatively easy to have data restored.
use strict;
use File::Find;
# use warnings;
my $base_dir='E:\05-09-07\Cal Poly';
my $days=31;
my $output = 'delete_directories.txt';
my $deltime=time-$days*86400;
my $delete_flag = 0;
my $timestamp = localtime;
open(OUT," >> $output") || die $!;
print OUT "$timestamp\n";
opendir(DIR,$base_dir) || die $!;
my @children = grep !/^\./, readdir (DIR);
closedir (DIR);
foreach my $child (@children) {
my $entry = "$base_dir\\$child";
if (-d $entry){
my $mtime = (stat($entry))[9];
my $ftime=$mtime;
if ($ftime<$deltime) {
finddepth (\&remove_dir, $entry);
rmdir ( $entry ) or print OUT "\tCould not remove $entry\n";
$delete_flag = 1;
print OUT "\t$entry\n";
}
}
}
print OUT "\tNo directories deleted\n", if($delete_flag eq 0);
print OUT "\n";
close(OUT);
exit;
### Subroutines ###
sub remove_dir {
# for a directory, this will be 0
if ( ! (stat($File::Find::name))[7] ) {
rmdir($File::Find::name);
}
else {
unlink($File::Find::name);
}
}
------------------------------
Date: Sat, 24 Jan 2009 21:45:47 -0600
From: Tad J McClellan <tadmc@seesig.invalid>
Subject: Re: Peer Review for Folder Delete Script
Message-Id: <slrngnno3b.vt.tadmc@tadmc30.sbcglobal.net>
Cosmic Cruizer <XXjbhuntxx@white-star.com> wrote:
> # use warnings;
You lose the benefits of that pragma when you comment it out...
> my $base_dir='E:\05-09-07\Cal Poly';
my $base_dir='E:/05-09-07/Cal Poly';
> open(OUT," >> $output") || die $!;
open my $OUT, '>>', $output or die "could not open '$output' $!";
> print OUT "$timestamp\n";
print $OUT "$timestamp\n";
> my $entry = "$base_dir\\$child";
my $entry = "$base_dir/$child";
--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"
------------------------------
Date: Sat, 24 Jan 2009 21:41:41 -0600
From: Tad J McClellan <tadmc@seesig.invalid>
Subject: Re: Peer Review for Folder Delete Script
Message-Id: <slrngnnnrl.vt.tadmc@tadmc30.sbcglobal.net>
Larry Gates <larry@example.invalid> wrote:
> On Sat, 24 Jan 2009 15:32:51 -0800, John W. Krahn wrote:
>
>> You are using the pattern / / which will not work correctly on all dates:
>> That is because a single digit day number will have *two* spaces in
>> front of it. You need to use the special split pattern ' ' instead:
>>
>> $ perl -le'print for ( split " ", localtime 1231358400 )[1,2,4]'
> I'm trying to split something on a space and was using / /. How again does
^
^ John's code splits on *one or more* spaces
> it differ from " "?
perldoc -f split
...
As a special case, specifying a PATTERN of space ...
> print STDOUT @s;
> How could I send @s to STDOUT to see if I'm splitting where I think I am?
print "'$_'\n" for @s;
or
print join(':', @s), "\n";
or
{ local $" = ':';
print "@s\n";
}
--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"
------------------------------
Date: Sun, 25 Jan 2009 04:19:03 GMT
From: Cosmic Cruizer <XXjbhuntxx@white-star.com>
Subject: Re: Peer Review for Folder Delete Script
Message-Id: <Xns9B9DCE70498E1ccruizermydejacom@207.115.33.102>
Hi Tad, it's been a few years since I've had the pleasure of you critiquing
my code. Your input is much appreciated.
When I use warnings, I generally only have it enabled while I'm testing.
I've never tried using open in the following format:
open my $OUT, '>>', $output or die "could not open '$output' $!";
I'll give it a try.
Thanks!
------------------------------
Date: Sat, 24 Jan 2009 18:17:24 -0800 (PST)
From: Xah Lee <xahlee@gmail.com>
Subject: syntax color lang source code in blogs or website
Message-Id: <c029d7f7-d995-4857-b9ff-5cc756e62e95@g1g2000pra.googlegroups.com>
For those of you using emacs, here's the elisp code that allows you to
syntax color computer language source code in your blog or website.
http://xahlee.org/emacs/elisp_htmlize.html
to comment, here:
http://xahlee.blogspot.com/2009/01/dehtmlize-source-code-in-emacs-lisp.html
Xah
=E2=88=91 http://xahlee.org/
=E2=98=84
------------------------------
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 V11 Issue 2156
***************************************