[31670] in Perl-Users-Digest
Perl-Users Digest, Issue: 2933 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri May 7 03:09:29 2010
Date: Fri, 7 May 2010 00:09:06 -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 Fri, 7 May 2010 Volume: 11 Number: 2933
Today's topics:
Re: Bug in GD? <newsojo@web.de>
Re: find/copy most recent version of file? <jmcguire@liaison-intl.com>
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? <geoff@invalid.invalid>
Re: find/copy most recent version of file? <glex_no-spam@qwest-spam-no.invalid>
Re: find/copy most recent version of file? <ben@morrow.me.uk>
Re: find/copy most recent version of file? <geoff@invalid.invalid>
Re: find/copy most recent version of file? <ben@morrow.me.uk>
Re: find/copy most recent version of file? <jimsgibson@gmail.com>
Re: find/copy most recent version of file? <tadmc@seesig.invalid>
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? <jurgenex@hotmail.com>
Re: find/copy most recent version of file? <jurgenex@hotmail.com>
Re: help me to write better code <news@lawshouse.org>
Re: help me to write better code <rvtol+usenet@xs4all.nl>
Re: help me to write better code <ben@morrow.me.uk>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 06 May 2010 19:35:54 GMT
From: 0liver 'ojo' Bedf0rd <newsojo@web.de>
Subject: Re: Bug in GD?
Message-Id: <4be31a1a$0$6985$9b4e6d93@newsspool4.arcor-online.net>
Am Thu, 06 May 2010 07:41:40 -0700 schrieb smallpond:
> According to the docs for gdImageArc: "e must be greater than s"
>
> http://www.libgd.org/Drawing
Ah, OK. I didn't find it in the perl doc.
The problem here is that although e may be greater than s,
GD uses only integer values and you don't get what you might
expect. I still think this is not the ideal behaviour.
Oliver
------------------------------
Date: Thu, 6 May 2010 11:50:12 -0700 (PDT)
From: Justin M <jmcguire@liaison-intl.com>
Subject: Re: find/copy most recent version of file?
Message-Id: <5d7013b3-6c11-49d3-909f-723f1266346b@k19g2000yqm.googlegroups.com>
On May 6, 11:57=A0am, Geoff <ge...@invalid.invalid> wrote:
> Not quite - I think?!
>
> I am trying to find and then copy the latest versions of a range of
> files which are =A0held in around 20 different folders.
>
> For example, video_c1_1.mp4 exists as 4 different versions in 4
> different folders. There are also files
>
> video_c1_2.mp4, video_c1_3.mp4, video_c1_4.mp4 =A0through to file
> video_c1_120.mp4.
>
> I would like to have the latest versions for these 120 different files
> copied into the new folder.
>
> I hope I am making myself clear?!
>
> Cheers
>
> Geoff
I think I found it, there's a bug in the regexp, use this: /^video_c1_
\d+\.mp4$/
(c1, not cl.)
--
Justin McGuire
Perl Firefighter
------------------------------
Date: Thu, 06 May 2010 21:26:36 +0100
From: Geoff <geoff@invalid.invalid>
Subject: Re: find/copy most recent version of file?
Message-Id: <pe96u59mmmefa19keefuppnnq97bvk064r@4ax.com>
On Thu, 6 May 2010 11:50:12 -0700 (PDT), Justin M
<jmcguire@liaison-intl.com> wrote:
>On May 6, 11:57 am, Geoff <ge...@invalid.invalid> wrote:
>> Not quite - I think?!
>>
>> I am trying to find and then copy the latest versions of a range of
>> files which are held in around 20 different folders.
>>
>> For example, video_c1_1.mp4 exists as 4 different versions in 4
>> different folders. There are also files
>>
>> video_c1_2.mp4, video_c1_3.mp4, video_c1_4.mp4 through to file
>> video_c1_120.mp4.
>>
>> I would like to have the latest versions for these 120 different files
>> copied into the new folder.
>>
>> I hope I am making myself clear?!
>>
>> Cheers
>>
>> Geoff
>
>I think I found it, there's a bug in the regexp, use this: /^video_c1_
>\d+\.mp4$/
>
>(c1, not cl.)
Thanks Justin!
Cheers
Geoff
------------------------------
Date: Thu, 06 May 2010 21:52:51 +0100
From: Geoff <geoff@invalid.invalid>
Subject: Re: find/copy most recent version of file?
Message-Id: <fta6u51n2acli1h9lc04fbq9mcne1k6rlh@4ax.com>
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.
Cheers
Geoff
------------------------------
Date: Thu, 06 May 2010 22:03:23 +0100
From: Geoff <geoff@invalid.invalid>
Subject: Re: find/copy most recent version of file?
Message-Id: <mhb6u59mqhssvs1ivhei24auemu8a0lr3m@4ax.com>
On Thu, 6 May 2010 11:50:12 -0700 (PDT), Justin M
<jmcguire@liaison-intl.com> wrote:
Justin,
'have just realised that there is still a blank after
"Latest File name is" when the code below is run!?
Geoff
#!/usr/bin/perl -l
use strict;
use warnings;
use File::Find;
my $new = '';
my %file_access;
my %file_full;
die "dirs required\n" unless @ARGV;
find(\&wanted, @ARGV);
print foreach values %file_full;
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;
} print "Latest File name is $new\n";
------------------------------
Date: Thu, 06 May 2010 16:17:18 -0500
From: "J. Gleixner" <glex_no-spam@qwest-spam-no.invalid>
Subject: Re: find/copy most recent version of file?
Message-Id: <4be3278b$0$1327$815e3792@news.qwest.net>
Geoff wrote:
> On Thu, 6 May 2010 11:50:12 -0700 (PDT), Justin M
> <jmcguire@liaison-intl.com> wrote:
>
> Justin,
>
> 'have just realised that there is still a blank after
>
> "Latest File name is" when the code below is run!?
>
> Geoff
>
> #!/usr/bin/perl -l
>
> use strict;
> use warnings;
> use File::Find;
>
> my $new = '';
[...]
> print "Latest File name is $new\n";
You have NOT set it to a value, other than ''.
------------------------------
Date: Thu, 6 May 2010 22:39:58 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: find/copy most recent version of file?
Message-Id: <eipbb7-q7r1.ln1@osiris.mauzo.dyndns.org>
Quoth Geoff <geoff@invalid.invalid>:
> On Thu, 6 May 2010 11:50:12 -0700 (PDT), Justin M
> <jmcguire@liaison-intl.com> wrote:
>
> Justin,
I assume you are aware that posts to Usenet are generally read by more
than one person?
> 'have just realised that there is still a blank after
>
> "Latest File name is" when the code below is run!?
You are expected to make at least a basic effort to write your program
yourself.
Ben
------------------------------
Date: Thu, 06 May 2010 23:07:44 +0100
From: Geoff <geoff@invalid.invalid>
Subject: Re: find/copy most recent version of file?
Message-Id: <u7f6u5dgekst8p484nojtd2err6h0ovenb@4ax.com>
On Thu, 6 May 2010 22:39:58 +0100, Ben Morrow <ben@morrow.me.uk>
wrote:
>
>Quoth Geoff <geoff@invalid.invalid>:
>> On Thu, 6 May 2010 11:50:12 -0700 (PDT), Justin M
>> <jmcguire@liaison-intl.com> wrote:
>>
>> Justin,
>
>I assume you are aware that posts to Usenet are generally read by more
>than one person?
>
>> 'have just realised that there is still a blank after
>>
>> "Latest File name is" when the code below is run!?
>
>You are expected to make at least a basic effort to write your program
>yourself.
I do agree Ben but so far I am floundering a little! I have tried
various ideas but they have not worked.
If I use my $new = ''; then at least I get no error message. If I use
my $new; I get "unitialised value in conctentation or string at line
22" - line 22 being
} print "Latest File name is $new\n";
How do I initialise $new?
Geoff
>
>Ben
------------------------------
Date: Thu, 6 May 2010 23:26:15 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: find/copy most recent version of file?
Message-Id: <79sbb7-gfr1.ln1@osiris.mauzo.dyndns.org>
Quoth Geoff <geoff@invalid.invalid>:
> On Thu, 6 May 2010 22:39:58 +0100, Ben Morrow <ben@morrow.me.uk>
> wrote:
> >Quoth Geoff <geoff@invalid.invalid>:
> >> On Thu, 6 May 2010 11:50:12 -0700 (PDT), Justin M
> >> <jmcguire@liaison-intl.com> wrote:
> >>
> >> Justin,
> >
> >I assume you are aware that posts to Usenet are generally read by more
> >than one person?
> >
> >> 'have just realised that there is still a blank after
> >>
> >> "Latest File name is" when the code below is run!?
> >
> >You are expected to make at least a basic effort to write your program
> >yourself.
>
> I do agree Ben but so far I am floundering a little! I have tried
> various ideas but they have not worked.
>
> If I use my $new = ''; then at least I get no error message. If I use
> my $new; I get "unitialised value in conctentation or string at line
> 22" - line 22 being
>
> } print "Latest File name is $new\n";
>
> How do I initialise $new?
This is such a fundamental question there's really no way to answer it
with less than a two-week course on basic programming. Usenet is not the
place for that: you need to find yourself a (*good*) beginners' book on
Perl. 'Learning Perl' is the usual recommendation; full details are in
perldoc -q book.
Ben
------------------------------
Date: Thu, 06 May 2010 18:16:25 -0700
From: Jim Gibson <jimsgibson@gmail.com>
Subject: Re: find/copy most recent version of file?
Message-Id: <060520101816250765%jimsgibson@gmail.com>
In article <fta6u51n2acli1h9lc04fbq9mcne1k6rlh@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.
Perl doesn't have a built-in copy function. You can tell the OS to do
it with system:
system("cp $oldpath $newpath");
depending upon your OS, or you can use a Perl module that does have a
copy command:
use File::Copy;
...
copy($oldpath,$newpath) or die("Can't copy $oldpath to $newpath: $!");
See, for example
perldoc -f system
perldoc File::Copy
Good luck!
--
Jim Gibson
------------------------------
Date: Thu, 06 May 2010 20:25:50 -0500
From: Tad McClellan <tadmc@seesig.invalid>
Subject: Re: find/copy most recent version of file?
Message-Id: <slrnhu6qnb.agt.tadmc@tadbox.sbcglobal.net>
Geoff <geoff@invalid.invalid> wrote:
> On Thu, 6 May 2010 22:39:58 +0100, Ben Morrow <ben@morrow.me.uk>
> wrote:
>
>>
>>Quoth Geoff <geoff@invalid.invalid>:
>>> On Thu, 6 May 2010 11:50:12 -0700 (PDT), Justin M
>>> <jmcguire@liaison-intl.com> wrote:
>>>
>>> Justin,
>>
>>I assume you are aware that posts to Usenet are generally read by more
>>than one person?
>>
>>> 'have just realised that there is still a blank after
>>>
>>> "Latest File name is" when the code below is run!?
Yes, there is a blank there.
I expect you were wanting an answer to a different question.
If so, then you should *ask* a different question...
>>You are expected to make at least a basic effort to write your program
>>yourself.
>
> I do agree Ben but so far I am floundering a little! I have tried
> various ideas but they have not worked.
>
> If I use my $new = ''; then at least I get no error message. If I use
> my $new; I get "unitialised value in conctentation or string at line
> 22" - line 22 being
>
> } print "Latest File name is $new\n";
>
> How do I initialise $new?
By assigning a value to it, as in:
my $new = '';
I expect you were wanting an answer to a different question.
If so, then you should *ask* a different question...
--
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 05:41:46 +0100
From: Geoff <geoff@invalid.invalid>
Subject: Re: find/copy most recent version of file?
Message-Id: <sb67u51r392rrohl0v3hc5pscal3d8j38q@4ax.com>
On Thu, 06 May 2010 20:25:50 -0500, Tad McClellan
<tadmc@seesig.invalid> wrote:
>By assigning a value to it, as in:
>
> my $new = '';
>
>I expect you were wanting an answer to a different question.
>
>If so, then you should *ask* a different question...
Not sure what you mean?!
I did use
my $new = '';
and see a list of paths/file names from
print foreach values %file_full;
but
} print "Latest File name is $new\n";
gives a blank.
Geoff
PS code used
#!/usr/bin/perl -l
use strict;
use warnings;
use File::Find;
my $new ='';
my %file_access;
my %file_full;
die "dirs required\n" unless @ARGV;
find(\&wanted, @ARGV);
print foreach values %file_full;
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;
} print "Latest File name is $new\n";
------------------------------
Date: Fri, 07 May 2010 05:44:55 +0100
From: Geoff <geoff@invalid.invalid>
Subject: Re: find/copy most recent version of file?
Message-Id: <ug67u5pj6fcad96e1q7g7qkg0vur2u8j2f@4ax.com>
On Thu, 6 May 2010 23:26:15 +0100, Ben Morrow <ben@morrow.me.uk>
wrote:
>This is such a fundamental question there's really no way to answer it
>with less than a two-week course on basic programming. Usenet is not the
>place for that: you need to find yourself a (*good*) beginners' book on
>Perl. 'Learning Perl' is the usual recommendation; full details are in
>perldoc -q book.
I have used
my $new = '';
which is what I expected was necessary to initialise $new but $new is
not used again until the print on the last line so is something
missing?
Geoff
PS Code used
#!/usr/bin/perl -l
use strict;
use warnings;
use File::Find;
my $new ='';
my %file_access;
my %file_full;
die "dirs required\n" unless @ARGV;
find(\&wanted, @ARGV);
print foreach values %file_full;
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;
} print "Latest File name is $new\n";
>
>Ben
------------------------------
Date: Thu, 06 May 2010 21:52:09 -0700
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: find/copy most recent version of file?
Message-Id: <nr67u5p12r9vqe35lam5e451u22ms6lff5@4ax.com>
Geoff <geoff@invalid.invalid> wrote:
>I have used
>
>my $new = '';
>
>which is what I expected was necessary to initialise $new
No, it isn't. Contrary to e.g. C perl automatically initialzes variables
upon declaration. And the text value of a scalar will be initialized as
the empty string.
>but $new is
>not used again until the print on the last line so is something
>missing?
Apparently yes.
jue
------------------------------
Date: Thu, 06 May 2010 21:54:04 -0700
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: find/copy most recent version of file?
Message-Id: <v477u518os3djefrfauhs0o4d4v9q7hmt9@4ax.com>
Geoff <geoff@invalid.invalid> wrote:
>On Thu, 06 May 2010 20:25:50 -0500, Tad McClellan
><tadmc@seesig.invalid> wrote:
>
>>By assigning a value to it, as in:
>>
>> my $new = '';
>>
>>I expect you were wanting an answer to a different question.
>>
>>If so, then you should *ask* a different question...
>
>Not sure what you mean?!
>
>I did use
>
>my $new = '';
>
>and see a list of paths/file names from
>
>print foreach values %file_full;
>
>but
>
>} print "Latest File name is $new\n";
>
>gives a blank.
Well, what _DO_ you expect to happen is you never assign any other value
but the empty string to $new?
jue
------------------------------
Date: Thu, 06 May 2010 23:52:21 +0100
From: Henry Law <news@lawshouse.org>
Subject: Re: help me to write better code
Message-Id: <MtqdneACmva21X7WnZ2dnUVZ7rRi4p2d@giganews.com>
Ben Morrow wrote:
>
> defined $upload or next;
I too am keen to write better code. Looking at this I realise that I've
never coded that particular logic like that; instead I would have written
next unless defined $upload;
It seems -- though perhaps only to me -- to be more natural to read that
way. Is there a good reason - performance, perhaps, or reduction of
errors now or in the future -- why I should re-train my mind to write as
in Ben's example? TMTOWTDI but some W's may be better than others.
--
Henry Law Manchester, England
------------------------------
Date: Fri, 07 May 2010 01:27:56 +0200
From: "Dr.Ruud" <rvtol+usenet@xs4all.nl>
Subject: Re: help me to write better code
Message-Id: <4be3507c$0$22919$e4fe514c@news.xs4all.nl>
Henry Law wrote:
> Ben Morrow wrote:
>> defined $upload or next;
>
> I too am keen to write better code. Looking at this I realise that I've
> never coded that particular logic like that; instead I would have written
>
> next unless defined $upload;
>
> It seems -- though perhaps only to me -- to be more natural to read that
> way. Is there a good reason - performance, perhaps, or reduction of
> errors now or in the future -- why I should re-train my mind to write as
> in Ben's example? TMTOWTDI but some W's may be better than others.
It is good practice to put the most important part up front.
Your version I like to write as
next if !defined $upload;
But it all depends on what you want to stress,
for example: the normal flow, or the exception.
defined $upload or warn log("undef upload") and next;
warn log("undef upload") and next if !defined $upload;
next if !defined $upload and warn log("undef upload");
(disregarding that assuming warn() to always return true,
is really not good practice)
--
Ruud
------------------------------
Date: Fri, 7 May 2010 00:21:48 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: help me to write better code
Message-Id: <chvbb7-snr1.ln1@osiris.mauzo.dyndns.org>
Quoth Henry Law <news@lawshouse.org>:
> Ben Morrow wrote:
> >
> > defined $upload or next;
>
> I too am keen to write better code. Looking at this I realise that I've
> never coded that particular logic like that; instead I would have written
>
> next unless defined $upload;
>
> It seems -- though perhaps only to me -- to be more natural to read that
> way. Is there a good reason - performance, perhaps, or reduction of
> errors now or in the future -- why I should re-train my mind to write as
> in Ben's example? TMTOWTDI but some W's may be better than others.
There is no technical reason to prefer one over the other (in fact, they
compile to identical optrees). The advice given in perlstyle is
(approximately) 'put the interesting clause first'; in this case I
consider 'we are making sure $upload is defined' to be more interesting
than what happens if it isn't.
I think that in general I would write
CONDITION or ACTION;
if I expected CONDITION to usually be true (so ACTION is usually not
executed), but
ACTION unless CONDITION;
if I expected it to usually be false (and the other way around for
and/if, of course). That way I can read only the first half of each
statement and understand the 'normal' behaviour of the piece of code; I
can go back and fill in the exceptional conditions later. I would also
be a bit dubious about
ACTION unless CONDITION;
in circumstances where CONDITION has important side-effects, for the
same reason.
This is all, of course, purely personal style. There is no reason you
should change what you do here.
Ben
------------------------------
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 2933
***************************************