[31673] in Perl-Users-Digest
Perl-Users Digest, Issue: 2936 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat May 8 14:09:25 2010
Date: Sat, 8 May 2010 11:09:07 -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 Sat, 8 May 2010 Volume: 11 Number: 2936
Today's topics:
Re: find/copy most recent version of file? <jurgenex@hotmail.com>
Re: find/copy most recent version of file? <jurgenex@hotmail.com>
Re: find/copy most recent version of file? <jurgenex@hotmail.com>
Re: find/copy most recent version of file? <john@castleamber.com>
Re: find/copy most recent version of file? <geoff@invalid.invalid>
Re: find/copy most recent version of file? <m@rtij.nl.invlalid>
Re: find/copy most recent version of file? <geoff@invalid.invalid>
Re: find/copy most recent version of file? <geoff@invalid.invalid>
Re: find/copy most recent version of file? <uri@StemSystems.com>
Re: find/copy most recent version of file? <hjp-usenet2@hjp.at>
Re: how do i find the max value out of an array? <tadmc@seesig.invalid>
Re: how do i find the max value out of an array? <jurgenex@hotmail.com>
Re: how do i find the max value out of an array? <jurgenex@hotmail.com>
Re: how do i find the max value out of an array? <john@castleamber.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Fri, 07 May 2010 19:12:37 -0700
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: find/copy most recent version of file?
Message-Id: <hvh9u5tumqop9vha2ei60g37jft2meleqv@4ax.com>
Geoff <geoff@invalid.invalid> wrote:
>On Thu, 6 May 2010 11:50:12 -0700 (PDT), Justin M
><jmcguire@liaison-intl.com> wrote:
>
>Justin
>
>the code below, after your error found, does print out the names of
>the latest versions but how do I change the code to copy them to say
>c:\latest ?
>
>I have tried copy($new,"c:/latest/$new"); but that doesn't work.
"that doesn't work" is about the worst possible error description. What
happened? Did you computer blow up? Did your program just die? Did you
get an error message? Which one? Why didn't you ask Perl to tell you
what went wrong?
And yes, copy(...., ....) works just fine if used correctly. .
jue
------------------------------
Date: Fri, 07 May 2010 19:13:52 -0700
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: find/copy most recent version of file?
Message-Id: <t4i9u5humhp7u83smn3om9cjlt8c2adhgv@4ax.com>
"Peter J. Holzer" <hjp-usenet2@hjp.at> wrote:
>On 2010-05-07 01:16, Jim Gibson <jimsgibson@gmail.com> wrote:
>> Perl doesn't have a built-in copy function. You can tell the OS to do
>> it with system:
>>
>> system("cp $oldpath $newpath");
>
>Don't do that. Use
>
> system("cp", $oldpath, $newpath);
>
>instead.
Actually even better would be to use
copy( $oldpath, $newpath);
because it is portable and doesn't require a specific external command.
jue
------------------------------
Date: Fri, 07 May 2010 19:29:29 -0700
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: find/copy most recent version of file?
Message-Id: <e7i9u59d6irou3d8cq8b70vdt7n7ba2uti@4ax.com>
Martijn Lievaart <m@rtij.nl.invlalid> wrote:
>On Wed, 05 May 2010 01:58:48 -0700, Jürgen Exner wrote:
>
>> Geoff <geoff@invalid.invalid> wrote:
>>>I have a series of files called c1_1.mp4 to c1_120.mp4 which are spread
>>>over several folders.
>>>I would like to be able to copy the most recent version of each file to
>>>new folder.
>>
>> That is more of an algorithmic problem than a Perl problem. The easiest
>> way: walk through all the possible source folders and copy each c1_*.mp4
>> file into your target directory unless there exists a file with the same
>> name in the target directory already and the existing file is newer than
>> the file to be copied.
>
>That would mean a lot of unnecessary copying.
True, but probably not as much as you would think.
Assuming a completely random even distribution then if you have m
instances each of n different files, then the first iteration will copy
n files. For the second iteration on average you would only copy n/2
files. And for each following iteration even less. Looks like tthere is
probably something like m*log(n) involved, but I"m really too tired to
figure it out in detail.
But of course you are right, if you pre-compute the exact list then of
course you can reduce the number of copies to exactly n.
jue
------------------------------
Date: Fri, 07 May 2010 23:33:15 -0500
From: John Bokma <john@castleamber.com>
Subject: Re: find/copy most recent version of file?
Message-Id: <87k4rfko6s.fsf@castleamber.com>
Jürgen Exner <jurgenex@hotmail.com> writes:
> "that doesn't work" is about the worst possible error description.
You haven't met some of my customers then :-)
--
John Bokma j3b
Hacking & Hiking in Mexico - http://johnbokma.com/
http://castleamber.com/ - Perl & Python Development
------------------------------
Date: Sat, 08 May 2010 06:47:44 +0100
From: Geoff <geoff@invalid.invalid>
Subject: Re: find/copy most recent version of file?
Message-Id: <dnu9u5tc3u6nf8r1ule8jidtiohahqk54f@4ax.com>
On Sat, 8 May 2010 00:31:09 +0100, Ben Morrow <ben@morrow.me.uk>
wrote:
>
>Quoth Geoff <geoff@invalid.invalid>:
>> On Fri, 7 May 2010 21:46:00 +0100, Ben Morrow <ben@morrow.me.uk>
>> wrote:
>>
>> >Read the docs for File::Copy again. If the second argument to copy names
>> >an existing directory, it will copy the file into the directory with the
>> >same name.
>>
>> I cannot see ref to this aspect - could you point me at it?
>
>Huh. You're right, it isn't documented: I'll file a bug about that.
>Sorry, I should have checked.
>
>Regardless, this behaviour is exactly what you want.
OK - thanks Ben.
Cheers
Geoff
>
>Ben
------------------------------
Date: Sat, 8 May 2010 11:17:17 +0200
From: Martijn Lievaart <m@rtij.nl.invlalid>
Subject: Re: find/copy most recent version of file?
Message-Id: <tpmfb7-gau.ln1@news.rtij.nl>
On Fri, 07 May 2010 19:29:29 -0700, Jürgen Exner wrote:
> Martijn Lievaart <m@rtij.nl.invlalid> wrote:
>
>>That would mean a lot of unnecessary copying.
>
> True, but probably not as much as you would think.
>
> Assuming a completely random even distribution then if you have m
> instances each of n different files, then the first iteration will copy
> n files. For the second iteration on average you would only copy n/2
> files. And for each following iteration even less. Looks like there is
> probably something like m*log(n) involved, but I"m really too tired to
> figure it out in detail.
The same process is followed for each file, so the number is n*something.
For each file, I guess there will be log(m) copies made on average. The
minimum is 1, the maximum is m.
So min: n, max: n*m, avg: n*log(m).
If m is mall, there is not much difference to the optimal case, but as
file copying is relatively expensive (and remember, this was about mp4
files) this quickly adds up. Plus you get additional hard disk
fragmentation on file systems that are susceptible to that.
M4
------------------------------
Date: Sat, 08 May 2010 14:12:25 +0100
From: Geoff <geoff@invalid.invalid>
Subject: Re: find/copy most recent version of file?
Message-Id: <cnoau5t3nat76q6ku81onq32o8mf8m87k4@4ax.com>
On Fri, 07 May 2010 19:12:37 -0700, Jürgen Exner
<jurgenex@hotmail.com> wrote:
'just for the record I have finally got at least part of the message!
The code below works, i.e. I get the latest set of files!
Thanks a lot.
Cheers
Geoff
#!/usr/bin/perl -l
use strict;
use warnings;
use File::Find;
use File::Copy;
my $file_name ='';
my %file_access;
my %file_full;
my $destiny = "c:/a-temp3/$file_name";
die "dirs required\n" unless @ARGV;
find(\&wanted, @ARGV);
foreach $file_name (values %file_full) {
copy( $file_name, $destiny )
or die "Copy of '$file_name' to '$destiny' failed: $!";
}
sub wanted {
return unless /^video_c1_\d+\.mp4$/;
my $access_time = (stat($_))[9];
return if ($file_access{$_} and $access_time < $file_access{$_});
$file_full{$_} = $File::Find::name;
$file_access{$_} = $access_time;
}
------------------------------
Date: Sat, 08 May 2010 15:29:51 +0100
From: Geoff <geoff@invalid.invalid>
Subject: Re: find/copy most recent version of file?
Message-Id: <t8tau5h13dsptpftkvi7sad3tf7js7ag23@4ax.com>
On Fri, 07 May 2010 12:32:09 -0500, John Bokma <john@castleamber.com>
wrote:
I have the code below working but I wonder if someone could just talk
me through what is happening in function sub?
Cheers
Geoff
use strict;
use warnings;
use File::Find;
use File::Copy;
my $file_name ='';
my %file_access;
my %file_full;
my $destiny = "c:/0-c1/$file_name";
#print $destiny;
die "dirs required\n" unless @ARGV;
find(\&wanted, @ARGV);
foreach $file_name (values %file_full) {
#print "path/file = " . $file_name . " destiny = " . $destiny;
copy( $file_name, $destiny )
or die "Copy of '$file_name' to '$destiny' failed: $!";
}
sub wanted {
return unless /^video_c1_\d+\.mp4$/;
my $access_time = (stat($_))[9];
return if ($file_access{$_} and $access_time < $file_access{$_});
$file_full{$_} = $File::Find::name;
$file_access{$_} = $access_time;
}
------------------------------
Date: Sat, 08 May 2010 13:38:33 -0400
From: "Uri Guttman" <uri@StemSystems.com>
Subject: Re: find/copy most recent version of file?
Message-Id: <87wrveuwdi.fsf@quad.sysarch.com>
>>>>> "G" == Geoff <geoff@invalid.invalid> writes:
G> The code below works, i.e. I get the latest set of files!
for some value of work.
G> my $file_name ='';
G> my %file_access;
G> my %file_full;
G> my $destiny = "c:/a-temp3/$file_name";
what do you think is in $destiny now? what was in $file_name? this does
not do what you seem to think it does. interpolation is not delayed.
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.sysarch.com --
----- Perl Code Review , Architecture, Development, Training, Support ------
--------- Gourmet Hot Cocoa Mix ---- http://bestfriendscocoa.com ---------
------------------------------
Date: Sat, 8 May 2010 19:59:57 +0200
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: find/copy most recent version of file?
Message-Id: <slrnhub9kt.ona.hjp-usenet2@hrunkner.hjp.at>
On 2010-05-08 04:33, John Bokma <john@castleamber.com> wrote:
> Jürgen Exner <jurgenex@hotmail.com> writes:
>
>> "that doesn't work" is about the worst possible error description.
>
> You haven't met some of my customers then :-)
They tell you "everything is fine" and expect you to fix the problems
anyway?
hp
------------------------------
Date: Fri, 07 May 2010 20:09:29 -0500
From: Tad McClellan <tadmc@seesig.invalid>
Subject: Re: how do i find the max value out of an array?
Message-Id: <slrnhu9e4n.ghc.tadmc@tadbox.sbcglobal.net>
John Bokma <john@castleamber.com> wrote:
> Tad McClellan <tadmc@seesig.invalid> writes:
>
>> IJALAB <balaji.draj@gmail.com> wrote:
>>
>>> captured these 4
>>> elements in an array. how do i find the max of these values, which is
>>> in an array using perl?
>>
>> my($max) = sort {$b <=> $a} @array;
> A linear search /might/ be faster than sorting if @array is large.
He said n=4, which is why I quoted where he said that n=4
:-)
--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.liamg\100cm.j.dat/"
The above message is a Usenet post.
I don't recall having given anyone permission to use it on a Web site.
------------------------------
Date: Fri, 07 May 2010 19:43:31 -0700
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: how do i find the max value out of an array?
Message-Id: <ujj9u51ic1nmvfgo21ggf0mtrftnsacio7@4ax.com>
"sopan.shewale@gmail.com" <sopan.shewale@gmail.com> wrote:
>Once you have array, how about?
>my $max = (sort { $b <=> $a } @array)[0];
If you insist on being inefficient, then that is certainly a good
solution.
Sort is O(n*log n), while computing the max value can easily be done in
O(n).
jue
------------------------------
Date: Fri, 07 May 2010 19:46:44 -0700
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: how do i find the max value out of an array?
Message-Id: <t3k9u5ps9n4nnhko8jm7qd77amk9esr8t4@4ax.com>
Tad McClellan <tadmc@seesig.invalid> wrote:
>John Bokma <john@castleamber.com> wrote:
>> Tad McClellan <tadmc@seesig.invalid> writes:
>>
>>> IJALAB <balaji.draj@gmail.com> wrote:
>>>
>>>> captured these 4
>>>> elements in an array. how do i find the max of these values, which is
>>>> in an array using perl?
>>>
>>> my($max) = sort {$b <=> $a} @array;
>
>> A linear search /might/ be faster than sorting if @array is large.
>
>
>He said n=4, which is why I quoted where he said that n=4
Good catch, I missed it.
jue
------------------------------
Date: Fri, 07 May 2010 23:31:50 -0500
From: John Bokma <john@castleamber.com>
Subject: Re: how do i find the max value out of an array?
Message-Id: <87ocgrko95.fsf@castleamber.com>
Tad McClellan <tadmc@seesig.invalid> writes:
> John Bokma <john@castleamber.com> wrote:
>> Tad McClellan <tadmc@seesig.invalid> writes:
>>
>>> IJALAB <balaji.draj@gmail.com> wrote:
>>>
>>>> captured these 4
>>>> elements in an array. how do i find the max of these values, which is
>>>> in an array using perl?
>>>
>>> my($max) = sort {$b <=> $a} @array;
>
>> A linear search /might/ be faster than sorting if @array is large.
>
> He said n=4, which is why I quoted where he said that n=4
Yes, yes, I didn't miss this, hence the "/might/" and "large" ;-)
(Also, it was a bit of a plug for List::Util)
--
John Bokma j3b
Hacking & Hiking in Mexico - http://johnbokma.com/
http://castleamber.com/ - Perl & Python Development
------------------------------
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:
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
Back issues are available via anonymous ftp from
ftp://cil-www.oce.orst.edu/pub/perl/old-digests.
#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 2936
***************************************