[31669] in Perl-Users-Digest
Perl-Users Digest, Issue: 2932 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu May 6 14:09:41 2010
Date: Thu, 6 May 2010 11:09:05 -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 Thu, 6 May 2010 Volume: 11 Number: 2932
Today's topics:
Re: Bug in GD? <newsojo@web.de>
Re: Bug in GD? <smallpond@juno.com>
Re: Daemons and flie locking <brian.raven@osbsl.co.uk>
Re: Daemons and flie locking <dean.karres@gmail.com>
Re: Daemons and flie locking sln@netherlands.com
Re: Daemons and flie locking <xhoster@gmail.com>
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? <tadmc@seesig.invalid>
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? <jmcguire@liaison-intl.com>
Re: find/copy most recent version of file? <geoff@invalid.invalid>
Re: help me to write better code <sopan.shewale@gmail.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 06 May 2010 08:36:43 GMT
From: 0liver 'ojo' Bedf0rd <newsojo@web.de>
Subject: Re: Bug in GD?
Message-Id: <4be27f9b$0$6761$9b4e6d93@newsspool3.arcor-online.net>
Am Wed, 05 May 2010 22:59:15 +0100 schrieb Ben Morrow:
> What do the docs say?
I didn't find anything relevant.
> AFAICS, a full circle is more useful. There are many ways of producing a
> single line; a full circle, however, can only be produced like that.
Well, no.
The "right" way to produce a full circle is of course to set the starting
angle to 0° and the end angle to 360°. (*)
Should produce a full circle IMVHO:
$im->arc(100,100,50,50,0,360,$blue);
Should produce "nothing" IMVHO
$im->arc(100,100,50,50,90,90,$blue);
Oliver
(*) I'm aware that 0°==360° from a mathematical point of view
------------------------------
Date: Thu, 6 May 2010 07:41:40 -0700 (PDT)
From: smallpond <smallpond@juno.com>
Subject: Re: Bug in GD?
Message-Id: <e5f6f5db-2741-4851-8d6f-c53eb19e2281@o8g2000yqo.googlegroups.com>
On May 5, 4:53=A0pm, 0liver 'ojo' Bedf0rd <news...@web.de> wrote:
> The following code:
>
> #!/usr/bin/perl -w
>
> use strict;
> use GD;
>
> my $im =3D new GD::Image(500,500);
> my $white =3D $im->colorAllocate(255,255,255);
> my $black =3D $im->colorAllocate(0,0,0); =A0 =A0 =A0
> my $red =3D $im->colorAllocate(255,0,0); =A0 =A0 =A0
> my $blue =3D $im->colorAllocate(0,0,255);
> $im->arc(100,100,50,50,90,90,$blue);
> $im->filledArc(200,200,50,50,90,90,$red,gdEdged|gdNoFill);
> binmode STDOUT;
> print $im->png;
>
> produces full (360 =B0) circles in the output image, although I would
> have guessed that no output at all (or a single pixel/line) is produced.
> I still find it more sensible to assume that if start and end angle
> are the same "minimal" output is created and not the "maximum" one.
>
> So: am I wrong or is this a bug in GD?
>
According to the docs for gdImageArc:
"e must be greater than s"
http://www.libgd.org/Drawing
------------------------------
Date: Wed, 05 May 2010 23:10:50 +0100
From: Brian Raven <brian.raven@osbsl.co.uk>
Subject: Re: Daemons and flie locking
Message-Id: <87y6fyov85.fsf@osbsl.co.uk>
Dean Karres <dean.karres@gmail.com> writes:
> Hi,
>
> Tested on RedHat and Ubuntu
>
> I am trying to create a daemon the tails and parses a "binary" (fixed
> length record) log-file. I have tried using Proc::Daemon and rolling
> my own daemonization code and I really don't think that is the issue
> though. My problem is when I try to create a run-lock pid file in /
> var/run.
>
> the basic flow is:
>
> - start syslog
> - become a daemon
> - try to create/open & flock a pid file
> - ... everything else
>
> I know syslog is working even after the forks. I know the forks are
> working. I know the pid file is being initially created but flock
> bombs and tells me "Inappropriate ioctl for device".
>
> the pid file open code is:
>
> sysopen($PIDFILE, $PIDFILEPATH, O_CREAT | O_WRONLY) ||
> die "Can not open pid file: $PIDFILEPATH\n";
> if (flock($PIDFILE, LOCK_EX | LOCK_NB) != 0) {
> die "Can not lock pid file: $PIDFILEPATH: $!: $?\n";
> }
According to 'perodoc -f flock', flock "Returns true for success, false
on failure.", i.e much the same as sysopen and truncate.
> truncate($PIDFILE, 0) ||
> die "Can not truncate pid file: $PIDFILEPATH\n";
> print $PIDFILE "$$\n";
>
> The "$PIDFILEPATH" is /var/run/filename.pid
>
> ideas?
--
--
Brian Raven
------------------------------
Date: Wed, 5 May 2010 15:26:33 -0700 (PDT)
From: Dean Karres <dean.karres@gmail.com>
Subject: Re: Daemons and flie locking
Message-Id: <ac53f1b9-ccbe-490c-b8ef-29e3309ce724@e1g2000yqe.googlegroups.com>
Ben, Brian,
You are both absolutely correct. Bone-headed me. Same thing with the
"$?". I have been floundering for a while and forgot what all I had
tried. I still have issues but it is not this.
thanks for the extra eyes
------------------------------
Date: Wed, 05 May 2010 15:56:06 -0700
From: sln@netherlands.com
Subject: Re: Daemons and flie locking
Message-Id: <5ss3u5pmc2d3grda3eurlbcp005c6fkmpp@4ax.com>
On Wed, 5 May 2010 13:49:27 -0700 (PDT), Dean Karres <dean.karres@gmail.com> wrote:
>Hi,
>
>Tested on RedHat and Ubuntu
>
>I am trying to create a daemon the tails and parses a "binary" (fixed
>length record) log-file. I have tried using Proc::Daemon and rolling
>my own daemonization code and I really don't think that is the issue
>though. My problem is when I try to create a run-lock pid file in /
>var/run.
>
>the basic flow is:
>
>- start syslog
>- become a daemon
>- try to create/open & flock a pid file
>- ... everything else
>
>I know syslog is working even after the forks. I know the forks are
>working. I know the pid file is being initially created but flock
>bombs and tells me "Inappropriate ioctl for device".
>
>the pid file open code is:
>
> sysopen($PIDFILE, $PIDFILEPATH, O_CREAT | O_WRONLY) ||
> die "Can not open pid file: $PIDFILEPATH\n";
> if (flock($PIDFILE, LOCK_EX | LOCK_NB) != 0) {
> die "Can not lock pid file: $PIDFILEPATH: $!: $?\n";
> }
> truncate($PIDFILE, 0) ||
> die "Can not truncate pid file: $PIDFILEPATH\n";
> print $PIDFILE "$$\n";
>
>The "$PIDFILEPATH" is /var/run/filename.pid
>
>ideas?
Even though this posting is about mod_perl, look at this:
http://www.perlmonks.org/?node_id=837196
But, if you search for "Inappropriate ioctl for device" on
the internet it seems to be default $! for the open function
via ENOTTY for it.
So even though open worked, the flock is or'd with
a non-blocking wait and returns right away.
You have to check the return value true/false.
But it looks like you die if the return value is true ( != 0 ).
The other thing might be the file permission, but it opened ok.
Try the flock without the non-blocking.
if (!flock($PIDFILE, LOCK_EX)) {
die "Can not lock pid file: $PIDFILEPATH: $!: $?\n";
}
Of course it could be anything. It depends on what your
OS does with locks.
I'm no expert, its just what I read about it.
-sln
------------------------------
Date: Wed, 05 May 2010 22:51:16 -0700
From: Xho Jingleheimerschmidt <xhoster@gmail.com>
Subject: Re: Daemons and flie locking
Message-Id: <4be26263$0$23720$ed362ca5@nr5-q3a.newsreader.com>
Dean Karres wrote:
...
>
> I know syslog is working even after the forks. I know the forks are
> working. I know the pid file is being initially created but flock
> bombs and tells me "Inappropriate ioctl for device".
Others have already pointed out the wrong sense on your err check. I
thought that that was the case before even seeing your code, because to
"Inappropriate ioctl" just screams 'You are inspecting $! when you ought
not be'. I don't think I've ever seen that error reported under any
other situation.
Xho
------------------------------
Date: Wed, 05 May 2010 23:28:55 +0100
From: Geoff <geoff@invalid.invalid>
Subject: Re: find/copy most recent version of file?
Message-Id: <vor3u5pdql7hskbipa3cgnap9as1iihr8d@4ax.com>
On Wed, 5 May 2010 08:57:04 -0700 (PDT), Justin M
<jmcguire@liaison-intl.com> wrote:
>Use "stat," http://perldoc.perl.org/functions/stat.html
>
>Similar to Martijn's solution...
>
>#!/usr/bin/perl -l
>
>use strict;
>use warnings;
>use File::Find;
>
>my %file_access;
>my %file_full;
>die "dirs required\n" unless @ARGV;
>
>find(\&wanted, @ARGV);
>print foreach values %file_full;
>
>sub wanted {
> return unless /hello/; ## redo this with your own file pattern,
>likely /^cl_\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;
>}
Justin,
Thanks for the code. I haven't got it working yet ....
Should there be use
File::stat; ?
Also I can add
my $new = '';
I add the name of the folder below where the perl file is but I get a
blank for "Laatest File name is".
I am missing something!
Cheers
Geoff
------------------------------
Date: Wed, 5 May 2010 23:50:46 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: find/copy most recent version of file?
Message-Id: <6b99b7-u1f1.ln1@osiris.mauzo.dyndns.org>
Quoth Geoff <geoff@invalid.invalid>:
> On Wed, 5 May 2010 08:57:04 -0700 (PDT), Justin M
> <jmcguire@liaison-intl.com> wrote:
>
>
> >Use "stat," http://perldoc.perl.org/functions/stat.html
> >
> >Similar to Martijn's solution...
> >
> >#!/usr/bin/perl -l
> >
> >use strict;
> >use warnings;
> >use File::Find;
> >
> >my %file_access;
> >my %file_full;
> >die "dirs required\n" unless @ARGV;
> >
> >find(\&wanted, @ARGV);
> >print foreach values %file_full;
> >
> >sub wanted {
> > return unless /hello/; ## redo this with your own file pattern,
> >likely /^cl_\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;
> >}
>
> Thanks for the code. I haven't got it working yet ....
>
> Should there be use
>
> File::stat; ?
Not in the code as given, though I would always rather use it.
File::stat overrides the core stat function so it returns an object,
meaning you can write
my $access_time = stat($_)->atime;
instead of remembering (or looking up) that it is the tenth entry in the
list.
> Also I can add
>
> my $new = '';
>
> I add the name of the folder below where the perl file is but I get a
> blank for "Laatest File name is".
I don't understand what you are asking here. What output do you get, and
what output do you expect?
Ben
------------------------------
Date: Wed, 05 May 2010 20:04:12 -0500
From: Tad McClellan <tadmc@seesig.invalid>
Subject: Re: find/copy most recent version of file?
Message-Id: <slrnhu452n.3kd.tadmc@tadbox.sbcglobal.net>
Geoff <geoff@invalid.invalid> wrote:
> On Wed, 5 May 2010 08:57:04 -0700 (PDT), Justin M
><jmcguire@liaison-intl.com> wrote:
>
>
>>Use "stat," http://perldoc.perl.org/functions/stat.html
That is a poor way to refer someone to Perl's documentation.
perldoc -f stat
is better in that it will match the version of Perl being used,
and it is also a hint that the stat() is a built-in function.
>> my $access_time = (stat($_))[9];
> Should there be use
>
> File::stat; ?
No. Justin's code makes use of the built-in stat function,
not the File::stat Perl module.
Did you read the documentation for File::stat?
perldoc File::stat
Does it look like it can be used the way Justin used stat()?
--
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: Wed, 05 May 2010 20:09:33 -0500
From: Tad McClellan <tadmc@seesig.invalid>
Subject: Re: find/copy most recent version of file?
Message-Id: <slrnhu45co.3kd.tadmc@tadbox.sbcglobal.net>
Geoff <geoff@invalid.invalid> wrote:
> On Wed, 5 May 2010 08:57:04 -0700 (PDT), Justin M
><jmcguire@liaison-intl.com> wrote:
>>#!/usr/bin/perl -l
>>
>>use strict;
>>use warnings;
>>use File::Find;
>>
>>my %file_access;
>>my %file_full;
>>die "dirs required\n" unless @ARGV;
>>
>>find(\&wanted, @ARGV);
>>print foreach values %file_full;
>>
>>sub wanted {
>> return unless /hello/; ## redo this with your own file pattern,
>>likely /^cl_\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;
>>}
> Also I can add
>
> my $new = '';
>
> I add the name of the folder below where the perl file is but I get a
> blank for "Laatest File name is".
>
> I am missing something!
I am pressing my forehead against the screen...
...
... nope, it's just not coming through.
I cannot help troubleshoot code that cannot be seen.
Where did you add the my $new line?
Where do you put something other than the empty string into $new?
Where is an output statement that could produce "Laatest File name is"?
If you post a short and complete program *that we can run* that
illustrates your problem, then we can surely help you solve your
problem.
Have you seen the Posting Guidelines that are posted here frequently?
--
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: Thu, 06 May 2010 06:47:06 +0100
From: Geoff <geoff@invalid.invalid>
Subject: Re: find/copy most recent version of file?
Message-Id: <erl4u55ceu227bdfedv83408t4gfff0j2r@4ax.com>
On Wed, 05 May 2010 20:09:33 -0500, Tad McClellan
<tadmc@seesig.invalid> wrote:
>If you post a short and complete program *that we can run* that
>illustrates your problem, then we can surely help you solve your
>problem.
Tad,
I am entering
perl latest3.pl <top folder name> with the following code,
Cheers
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_cl_\d+\.mp4$/; ## redo this with your own
file pattern,
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, 6 May 2010 07:10:34 -0700 (PDT)
From: Justin M <jmcguire@liaison-intl.com>
Subject: Re: find/copy most recent version of file?
Message-Id: <71c59da0-cc74-4d0e-b307-04ce5b91a18d@r11g2000yqa.googlegroups.com>
On May 6, 1:47=A0am, Geoff <ge...@invalid.invalid> wrote:
> #!/usr/bin/perl -l
>
> use strict;
> use warnings;
> use File::Find;
> my $new =3D '';
> my %file_access;
> my %file_full;
> die "dirs required\n" unless @ARGV;
>
> find(\&wanted, @ARGV);
> print foreach values %file_full;
>
> sub wanted {
> =A0 =A0 return unless /^video_cl_\d+\.mp4$/; ## redo this with your own
> file pattern,
> =A0 =A0 my $access_time =3D (stat($_))[9];
> =A0 =A0 return if ($file_access{$_} and $access_time < $file_access{$_});
> =A0 =A0 $file_full{$_} =3D $File::Find::name;
> =A0 =A0 $file_access{$_} =3D $access_time;
>
> } =A0 =A0print "Latest File name is $new\n";
>
>
The $new variable isn't ever assigned to, so it'll always be blank.
Also, I don't know what it should be for.
Lets clarify something. The original code will find the most recent
version of *each* filename, not just the one most recently modified
file.
So if you have this:
a/hello1 <-- modified on May 1
a/hello2 <-- modified on May 1
b/hello2 <-- modified on May 2
The script will print this:
a/hello1
b/hello2
Is this what you're looking for?
--
Justin McGuire
Perl Firefighter
------------------------------
Date: Thu, 06 May 2010 16:57:03 +0100
From: Geoff <geoff@invalid.invalid>
Subject: Re: find/copy most recent version of file?
Message-Id: <idp5u5d5arao8lqiict23sanaolmgcejo8@4ax.com>
On Thu, 6 May 2010 07:10:34 -0700 (PDT), Justin M
<jmcguire@liaison-intl.com> wrote:
>On May 6, 1:47 am, Geoff <ge...@invalid.invalid> wrote:
>> #!/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_cl_\d+\.mp4$/; ## redo this with your own
>> file pattern,
>> 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";
>>
>>
>
>The $new variable isn't ever assigned to, so it'll always be blank.
>Also, I don't know what it should be for.
>
>Lets clarify something. The original code will find the most recent
>version of *each* filename, not just the one most recently modified
>file.
>
>So if you have this:
>
>a/hello1 <-- modified on May 1
>a/hello2 <-- modified on May 1
>b/hello2 <-- modified on May 2
>
>The script will print this:
>
>a/hello1
>b/hello2
>
>Is this what you're looking for?
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
------------------------------
Date: Wed, 5 May 2010 23:26:40 -0700 (PDT)
From: "sopan.shewale@gmail.com" <sopan.shewale@gmail.com>
Subject: Re: help me to write better code
Message-Id: <6b009041-2d25-43b4-a2d5-6023298be7be@24g2000yqy.googlegroups.com>
Thanks Ben,
Its possible to have one array-without suffering performance.
I am sticking to two array solution-just because i have already
committed that to repository and easy for average people (like me) to
understand easily.
Thanks for all responses.
On May 6, 2:51=A0am, Ben Morrow <b...@morrow.me.uk> wrote:
> Quoth Willem <wil...@turtle.stack.nl>:
>
>
>
> > Something like this:
>
> > =A0my $query =3D App::Request->new();
>
> > =A0my @filenames =3D grep { defined $query->{uploads}{$_} }
> > =A0 =A0map { $query->param("filepath$_") } ('', 1 .. 9);
> > =A0my @upload_objs =3D @{$query->{uploads}}{@filenames};
>
> > Note that even though this is more concise, it actually
> > reads the 'uploads' hash twice and might not be as fast.
>
> It's probably better to have one array anyway:
>
> =A0 =A0 my @uploads =3D
> =A0 =A0 =A0 =A0 grep defined $_->{obj},
> =A0 =A0 =A0 =A0 map =A0+{
> =A0 =A0 =A0 =A0 =A0 =A0 name =A0 =A0=3D> $_,
> =A0 =A0 =A0 =A0 =A0 =A0 obj =A0 =A0 =3D> $query->{uploads}{$_},
> =A0 =A0 =A0 =A0 },
> =A0 =A0 =A0 =A0 map =A0$query->param("filepath$_"),
> =A0 =A0 =A0 =A0 "", 1..9;
>
> Unwrapping that into two arrays (if that's really necessary) is then
> just a matter of
>
> =A0 =A0 my @filenames =A0 =3D map $_->{name}, @uploads;
> =A0 =A0 my @upload_objs =3D map $_->{obj}, @uploads;
>
> 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 2932
***************************************