[23521] in Perl-Users-Digest
Perl-Users Digest, Issue: 5730 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Oct 30 14:09:09 2003
Date: Thu, 30 Oct 2003 11:05:14 -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 Thu, 30 Oct 2003 Volume: 10 Number: 5730
Today's topics:
Re: Call Perl Scripts from Other Dir in Linux, Path Mes <grazz@pobox.com>
Re: Checkbox - database checkbox, if checked gives val (randy)
Re: Checkbox - database checkbox, if checked gives val <jurgenex@hotmail.com>
Re: Checkbox - database checkbox, if checked gives val <vilain@spamcop.net>
Re: Checkbox - database checkbox, if checked gives val <noreply@gunnar.cc>
Re: difference between defined & exists <nobull@mail.com>
Re: Equivalent of "ls -t" ? <stanb@panix.com>
Re: Equivalent of "ls -t" ? (Anno Siegel)
Re: Equivalent of "ls -t" ? <stanb@panix.com>
Re: Equivalent of "ls -t" ? <stanb@panix.com>
Help with Video::Capture module <stanb@panix.com>
Re: In search of elegant code: inverting a string (Roy Johnson)
Re: In search of elegant code: inverting a string (David Filmer)
Re: multiline regular expression, is it possible? (Bill)
Need help with OCIDefineObject <ggershSNACK@CAKEctc.net>
Re: Parsing of blocks (e.g. foo { bar }) <bharnish@technologist.com>
Re: Parsing of blocks (e.g. foo { bar }) <torh+news@removethisbitbeforethedot.bogus.net>
Re: Parsing of blocks (e.g. foo { bar }) <usenet@dwall.fastmail.fm>
Perl Cut Command <jc_va@hotmail.com>
Re: Perl Cut Command <jc_va@hotmail.com>
Re: regex for stripping HTML <flavell@ph.gla.ac.uk>
Re: Singleton process (Roy Johnson)
Re: Singleton process ctcgag@hotmail.com
Re: Sort two dimensional array with multiple keys (Milkweed)
Re: Sort two dimensional array with multiple keys (Milkweed)
Re: Sort two dimensional array with multiple keys (Greg Bacon)
Re: Sort two dimensional array with multiple keys (Milkweed)
Re: sourcing a file from perl <jaws@ericsson.ca>
ssh2+checksum+ perl module ? <zeke03_@caramail.com>
Threads and perl? (Math55)
Re: Threads and perl? <noreply@gunnar.cc>
UNIX domain sockets <anderiv@spam.me.not.visi.com>
Re: UNIX domain sockets <theaney@cablespeed.com>
Re: Video::Capture example? <stanb@panix.com>
Re: What am I doing wrong?! (Roy Johnson)
Re: What am I doing wrong?! <jurgenex@hotmail.com>
Re: What am I doing wrong?! <tore@aursand.no>
Re: What am I doing wrong?! <jurgenex@hotmail.com>
Re: What am I doing wrong?! <usenet@dwall.fastmail.fm>
Win::OLE excel function run twice (Jason Chen)
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Thu, 30 Oct 2003 16:30:41 GMT
From: Steve Grazzini <grazz@pobox.com>
Subject: Re: Call Perl Scripts from Other Dir in Linux, Path Messed Up
Message-Id: <R0bob.28465$294.24621@nwrdny03.gnilink.net>
In comp.lang.perl.misc Bart Lateur <bart.lateur@pandora.be> wrote:
>> For instance, have a look at perldoc -m FindBin. What FindBin does
>> is make a rather more sophisticated attempt than you recommend at
>> extracting the path of the script out of $0
>
> - FindBin does a useless search. There is *no need* to scan $PATH, as
> perl scripts aren't ever searched in it.
One of the authors said on p5p (http://xrl.us/2gb)
On some platforms when a script is called via PATH, instead of
directly, $0 does not contain the full path to the script (I am
assuming that caller would return the same value as $0 in such
a case). This is why FindBin goes to a great extent to locate
the real position of the script.
But I'm not sure whether this is correct. It looks to me like the
only time perl searches $PATH is when running under the -S switch,
regardless of platform. And when perl finds the script in $PATH, it
will always set $0 to an absolute path or a path relative to the
current directory.
Getting rid of the $PATH search would also fix the "KNOWN BUG" in
FindBin's documentation.
> - It sometimes fails because it can't have access to directories it
> wants to look into. Even though the original path works, thank you very
> much, FindBin prefers to returns an empty string (or undef?), which
> doesn't work.
Do you know if either of these have been reported as bugs?
I found this ticket (from 1999, marked "resolved") but couldn't find
the explanation.
http://rt.perl.org/rt2/Ticket/Display.html?id=1845
--
Steve
------------------------------
Date: 30 Oct 2003 06:30:27 -0800
From: searsdvdtech@yahoo.com (randy)
Subject: Re: Checkbox - database checkbox, if checked gives value of 1 .. how to sum ?
Message-Id: <506a5f6b.0310300630.39b68fbf@posting.google.com>
I don't need you to tell me how to handle my messages. If I want to
top post. This is my choice. Who are you the Internet miss manners
police? If you can't help then don't post to this thread.
------------------------------
Date: Thu, 30 Oct 2003 16:11:20 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: Checkbox - database checkbox, if checked gives value of 1 .. how to sum ?
Message-Id: <IKaob.9833$Q9.3617@nwrddc02.gnilink.net>
randy wrote:
> I don't need you to tell me how to handle my messages. If I want to
> top post. This is my choice.
Certainly. And it's everyone's else choice not to read you.
*PLONK*
jue
------------------------------
Date: Thu, 30 Oct 2003 08:24:16 -0800
From: "Michael Vilain <vilain@spamcop.net>"
Subject: Re: Checkbox - database checkbox, if checked gives value of 1 .. how to sum ?
Message-Id: <vilain-2B7E47.08241630102003@comcast.ash.giganews.com>
In article <506a5f6b.0310300630.39b68fbf@posting.google.com>,
searsdvdtech@yahoo.com (randy) wrote:
> I don't need you to tell me how to handle my messages. If I want to
> top post. This is my choice. Who are you the Internet miss manners
> police? If you can't help then don't post to this thread.
Actually, you do. Someone has told you that you have BO. You've
decided to think of it as "natural" rather than shower and clean up.
And you wonder why people avoid you at parties and you haven't been laid
lately...
*Plonk*
--
DeeDee, don't press that button! DeeDee! NO! Dee...
------------------------------
Date: Thu, 30 Oct 2003 15:31:41 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Checkbox - database checkbox, if checked gives value of 1 .. how to sum ?
Message-Id: <bnr7po$137nv7$1@ID-184292.news.uni-berlin.de>
randy wrote:
> If I want to top post. This is my choice.
On Usenet it's not. Your choice is: Either change attitude and comply
with the netiquette, or leave Usenet.
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: 30 Oct 2003 18:06:07 +0000
From: Brian McCauley <nobull@mail.com>
Subject: Re: difference between defined & exists
Message-Id: <u9d6cesir4.fsf@wcl-l.bham.ac.uk>
Ben Morrow <usenet@morrow.me.uk> writes:
> exists applies to array or hash members: it tests whether there
> is any value, defined or no, there at all.
Someone with an understanding of the difference between exists() and
defined() could see that what you just said is a true description.
On the other hand it probably wouldn't make any sense someone who
didn't already understand.
For hashes is easiest to think of exists() as testing if a given key
is in list of keys of a hash.
For arrays is easiest to not to think about exists() at all as it
doesn't really do anything useful.
To slightly rephrase what Ben said:
For and array element exists() tests whether there is storage space
for a scalar value (SV) allocated for that element. Even if there is
an SV allocated it may still contain undef.
For most arrays you encounter exists($array[$n]) is true for all $n in
(-@array .. $#array) and false otherwise.
exists($array[$n]) can also be false if you've used delete() on array
elements or have extended the array by assigning $#array.
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: Thu, 30 Oct 2003 14:43:25 +0000 (UTC)
From: Stan Brown <stanb@panix.com>
Subject: Re: Equivalent of "ls -t" ?
Message-Id: <bnr82d$ib3$1@reader2.panix.com>
In <slrnbq25ur.a97.abigail@alexandra.abigail.nl> Abigail <abigail@abigail.nl> writes:
>Stan Brown (stanb@panix.com) wrote on MMMDCCXII September MCMXCIII in
><URL:news:bnr1vh$gap$1@reader2.panix.com>:
>\\ I need to get a list of all the files in a given directory, sorted in
>\\ oldest -> newest into an array for processing.
>ls -t orders them from newest to oldest. Anyway, here's a solution
>(oldest to newest).
>my $dir = ".";
>opendir my $dh => $dir or die;
>my @files = map {substr $_ => 8}
> sort
> map {sprintf "%08x$_" => (stat) [9], $_} grep {! /^\./} readdir $dh;
>closedir $dh;
thanks for the help!
This works great in a small test program, but when I put this fragment in
to my bigger program (which is using "strict:). I get the following run
time error:
Can't use string ("/usr/images/20031026") as a SCALAR ref while "strict
refs" in use at ./make_movie.pl line 474.
"/usr/images/20031026" is the directory I'm trying to get a list of files
from.
How can I fix this?
--
"They that would give up essential liberty for temporary safety deserve
neither liberty nor safety."
-- Benjamin Franklin
------------------------------
Date: 30 Oct 2003 14:45:20 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Equivalent of "ls -t" ?
Message-Id: <bnr860$5gr$1@mamenchi.zrz.TU-Berlin.DE>
Abigail <abigail@abigail.nl> wrote in comp.lang.perl.misc:
> Stan Brown (stanb@panix.com) wrote on MMMDCCXII September MCMXCIII in
> <URL:news:bnr1vh$gap$1@reader2.panix.com>:
> \\ I need to get a list of all the files in a given directory, sorted in
> \\ oldest -> newest into an array for processing.
>
>
> ls -t orders them from newest to oldest. Anyway, here's a solution
> (oldest to newest).
>
> my $dir = ".";
> opendir my $dh => $dir or die;
> my @files = map {substr $_ => 8}
> sort
> map {sprintf "%08x$_" => (stat) [9], $_} grep {! /^\./} readdir $dh;
^^
That second "$_" seems to be a remnant of an earlier version. Otherwise,
it's a very true replication of "ls -tr", skipping files beginning with
"." and, cleverly, sorting alphabetically files that have the same mod-time.
Oh, but it fails for a file named "hundred%safe". Maybe the earlier version
was preferable :)
Why the hex format?
Anno
------------------------------
Date: Thu, 30 Oct 2003 14:46:22 +0000 (UTC)
From: Stan Brown <stanb@panix.com>
Subject: Re: Equivalent of "ls -t" ?
Message-Id: <bnr87u$icr$1@reader2.panix.com>
In <bnr82d$ib3$1@reader2.panix.com> Stan Brown <stanb@panix.com> writes:
>In <slrnbq25ur.a97.abigail@alexandra.abigail.nl> Abigail <abigail@abigail.nl> writes:
>>Stan Brown (stanb@panix.com) wrote on MMMDCCXII September MCMXCIII in
>><URL:news:bnr1vh$gap$1@reader2.panix.com>:
>>\\ I need to get a list of all the files in a given directory, sorted in
>>\\ oldest -> newest into an array for processing.
>>ls -t orders them from newest to oldest. Anyway, here's a solution
>>(oldest to newest).
>>my $dir = ".";
>>opendir my $dh => $dir or die;
>>my @files = map {substr $_ => 8}
>> sort
>> map {sprintf "%08x$_" => (stat) [9], $_} grep {! /^\./} readdir $dh;
>>closedir $dh;
>thanks for the help!
>This works great in a small test program, but when I put this fragment in
>to my bigger program (which is using "strict:). I get the following run
>time error:
>Can't use string ("/usr/images/20031026") as a SCALAR ref while "strict
>refs" in use at ./make_movie.pl line 474.
>"/usr/images/20031026" is the directory I'm trying to get a list of files
>from.
>How can I fix this?
It would help if I posted the line I bet :-(
opendir my $dh => $$::src_dir or die;
--
"They that would give up essential liberty for temporary safety deserve
neither liberty nor safety."
-- Benjamin Franklin
------------------------------
Date: Thu, 30 Oct 2003 15:02:14 +0000 (UTC)
From: Stan Brown <stanb@panix.com>
Subject: Re: Equivalent of "ls -t" ?
Message-Id: <bnr95m$io6$1@reader2.panix.com>
In <bnr87u$icr$1@reader2.panix.com> Stan Brown <stanb@panix.com> writes:
>In <bnr82d$ib3$1@reader2.panix.com> Stan Brown <stanb@panix.com> writes:
>>In <slrnbq25ur.a97.abigail@alexandra.abigail.nl> Abigail <abigail@abigail.nl> writes:
>>>Stan Brown (stanb@panix.com) wrote on MMMDCCXII September MCMXCIII in
>>><URL:news:bnr1vh$gap$1@reader2.panix.com>:
>>>\\ I need to get a list of all the files in a given directory, sorted in
>>>\\ oldest -> newest into an array for processing.
>>>ls -t orders them from newest to oldest. Anyway, here's a solution
>>>(oldest to newest).
>>>my $dir = ".";
>>>opendir my $dh => $dir or die;
>>>my @files = map {substr $_ => 8}
>>> sort
>>> map {sprintf "%08x$_" => (stat) [9], $_} grep {! /^\./} readdir $dh;
>>>closedir $dh;
>>thanks for the help!
>>This works great in a small test program, but when I put this fragment in
>>to my bigger program (which is using "strict:). I get the following run
>>time error:
>>Can't use string ("/usr/images/20031026") as a SCALAR ref while "strict
>>refs" in use at ./make_movie.pl line 474.
>>"/usr/images/20031026" is the directory I'm trying to get a list of files
>>from.
>>How can I fix this?
>It would help if I posted the line I bet :-(
>opendir my $dh => $$::src_dir or die;
Never mind!
Is there a rule that says you won't see your stupid typo, till you post it
for the world to see :-(
--
"They that would give up essential liberty for temporary safety deserve
neither liberty nor safety."
-- Benjamin Franklin
------------------------------
Date: Thu, 30 Oct 2003 14:16:22 +0000 (UTC)
From: Stan Brown <stanb@panix.com>
Subject: Help with Video::Capture module
Message-Id: <bnr6fm$hn1$1@reader2.panix.com>
I'm trying to replace some system() calls to v4lctl in a script I'm
writing.
Looks like I can use Video::Capture, but I dont understand the examples.
Looks like I start off by creating an object like this:
$grab = new Video::Capture::V4l
or die "Unable to open Videodevice: $!";
But, since I have more than one captur card (eg /dev/video0 ...
/dev/vdieon), how do I specify which one the objetc opens?
Also, how do I set the sourec *eg telivision, Composire1)
--
"They that would give up essential liberty for temporary safety deserve
neither liberty nor safety."
-- Benjamin Franklin
------------------------------
Date: 30 Oct 2003 06:47:08 -0800
From: rjohnson@shell.com (Roy Johnson)
Subject: Re: In search of elegant code: inverting a string
Message-Id: <3ee08638.0310300647.316bc835@posting.google.com>
yf110@vtn1.victoria.tc.ca (Malcolm Dew-Jones) wrote in message news:<3fa05ae9@news.victoria.tc.ca>...
> I am guessing you tried
> print reverse 'ABCDEFG' ;
> unfortunately that would be misleading. Instead you must type
> print scalar reverse 'ABCDEFG';
> or
> $reversed = reverse 'ABCDEFG';
> print $reversed;
or
print my $reversed=reverse 'ABCDEFG';
or even
print ''.reverse 'ABCDEFG';
or, to avoid reverse (for whatever reason):
$foo='ABCDEFG';
print map(substr($foo,-$_,1), 1..length $foo)
------------------------------
Date: 30 Oct 2003 10:05:27 -0800
From: IneverReadAnythingSentToMe@hotmail.com (David Filmer)
Subject: Re: In search of elegant code: inverting a string
Message-Id: <e4c916dd.0310301005.142e2ebf@posting.google.com>
>
> I would use reverse $string ;
>
> I am guessing you tried
>
> print reverse 'ABCDEFG' ;
>
> unfortunately that would be misleading. Instead you must type
>
> print scalar reverse 'ABCDEFG';
>
> or
>
> $reversed = reverse 'ABCDEFG';
> print $reversed;
>
>
> Print puts things in list context, so reverse reverses your _list_ of
> strings, but there's only one string in your list, so reversing your list
> made no difference (if you tried what I suspected).
Yup, I did try "print reverse 'ABCDEFG' ;" and it didn't work.
'scalar' does the trick. On reflection, I prefer the "print $foo =
reverse $foo;" syntax.
Thanks to everyone who offered these elegant solutions, as well as
those who offered some not-so-elegant but definately thought-provoking
alternatives.
------------------------------
Date: 30 Oct 2003 07:57:17 -0800
From: wherrera@lynxview.com (Bill)
Subject: Re: multiline regular expression, is it possible?
Message-Id: <239ce42f.0310300757.14ceddb1@posting.google.com>
"Bernard El-Hagin" <bernard.el-haginDODGE_THIS@lido-tech.net> wrote in message news:<Xns94246338DD8E1elhber1lidotechnet@62.89.127.66>...
> (Bill) wrote:
>
> [...]
>
> > Interesting...the last time I came across this was with parsing the
> > 'clit' formatted pages
> ^^^^^^
>
>
> Come on, admit it, you made that name up! ;-)
No, but I had to turn off the Internet filter on the PC to send the posting :>.
Google for 'clit HTML'
------------------------------
Date: Thu, 30 Oct 2003 10:01:55 -0500
From: Greg G <ggershSNACK@CAKEctc.net>
Subject: Need help with OCIDefineObject
Message-Id: <fuSdnQQASqdBtDyiRVn-vA@ctc.net>
I'm totally confused as to how to do an OCIDefineObject to get an object
from a database. Here's the short form:
I've got an object K_PAIR defined as a KEY (varchar 20) and VALUE
(varchar 64). I also have a table type of K_TABLE which is a table of
K_PAIR objects.
The select statement I want to use is something along the lines of:
SELECT username, keys FROM MYTABLE;
username is just a plain old varchar and keys is a K_TABLE.
Of course, I get a message that I haven't done an OCIDefineObject.
Everything I've looked at is a confusing mash of parameters that I can't
quite decipher. Is there an *easy* way to do this binding?
Thanks.
-Greg G
------------------------------
Date: Thu, 30 Oct 2003 15:16:30 GMT
From: Brian Harnish <bharnish@technologist.com>
Subject: Re: Parsing of blocks (e.g. foo { bar })
Message-Id: <pan.2003.10.30.15.16.51.999857@technologist.com>
-----BEGIN xxx SIGNED MESSAGE-----
Hash: SHA1
On Thu, 30 Oct 2003 12:36:39 +0000, Tor Houghton wrote:
> Hi,
>
> I'm wondering if there is a more elegant way of parsing "blocks" of data.
[snip]
> Before I go "all out" and complete this section of the code using the
> above technique, I was wondering if there was other (better) ways of doing
> this (for one, I'm not sure how to catch out any errors in the file, for
> instance:
>
> some.host.here {
> another.host {
> /usr
> /opt
> }
> /etc
> /var/mail
> }
>
> .. here the current code fails miserably. Mind you, I'm probably the only
> one going to use this, so that may not be such a big deal :-> )
You didn't really say how you wanted to handle this condition. Is it a
valid condition, or can your program just abort?
If you need to handle that condition, then instead of using the scalar
".."'s flag, use a nesting counter:
my $nest = 0;
while(<CONF>) {
$nest++ if (/(\S+)\s*\{/);
$nest-- if (/\}/);
if($nest == 1) { # Or, $nest >= 1
# Handle conditions.
}
}
Actually, thinking about it, aborting would use very similar logic.
- Brian
-----BEGIN xxx SIGNATURE-----
Version: GnuPG v1.2.2 (GNU/Linux)
iD8DBQE/oStgiK/rA3tCpFYRAjpzAKCDOI/WgKFUnNmnG7Bf4hNuTSg1qQCgxvWm
vrQkYrxLEaFNq65GM8MwIEI=
=3Yc1
-----END PGP SIGNATURE-----
------------------------------
Date: Thu, 30 Oct 2003 16:56:20 +0000
From: Tor Houghton <torh+news@removethisbitbeforethedot.bogus.net>
Subject: Re: Parsing of blocks (e.g. foo { bar })
Message-Id: <pan.2003.10.30.16.56.15.64326@removethisbitbeforethedot.bogus.net>
On Thu, 30 Oct 2003 15:16:30 +0000, Brian Harnish wrote:
> [snip]
>
> You didn't really say how you wanted to handle this condition. Is it a
> valid condition, or can your program just abort?
>
Hm. No, it's an invalid condition, so the program should just abort.
> If you need to handle that condition, then instead of using the scalar
> ".."'s flag, use a nesting counter:
> my $nest = 0;
> while(<CONF>) {
> $nest++ if (/(\S+)\s*\{/);
> $nest-- if (/\}/);
> if($nest == 1) { # Or, $nest >= 1
> # Handle conditions.
> }
> }
>
> Actually, thinking about it, aborting would use very similar logic.
>
Ah. I didn't think about doing it that way. Thanks!
Tor
------------------------------
Date: Thu, 30 Oct 2003 18:55:42 -0000
From: "David K. Wall" <usenet@dwall.fastmail.fm>
Subject: Re: Parsing of blocks (e.g. foo { bar })
Message-Id: <Xns94248DB03DD3Ddkwwashere@216.168.3.30>
Tor Houghton <torh+news@removethisbitbeforethedot.bogus.net> wrote:
> I'm wondering if there is a more elegant way of parsing "blocks"
> of data.
[snip]
> Before I go "all out" and complete this section of the code using
> the above technique, I was wondering if there was other (better)
> ways of doing this
If you're not tied to that particular format you could use
Config::Simple or one of the numerous other Config::* modules in the
CPAN.
But I may be revealing some ignorance here; your data may be the
output of another program that requires that format.
--
David Wall
------------------------------
Date: Thu, 30 Oct 2003 18:49:49 GMT
From: "Buck Turgidson" <jc_va@hotmail.com>
Subject: Perl Cut Command
Message-Id: <2b80f0b4eb23d637d017ded1a65e79a0@news.teranews.com>
I have a file of data that is 60 bytes long. I want to cut (remove) bytes
21-40, and just print 1-20 and 21 thru 60 on a line.
The Unix cut command does the opposite of what I want. "cut --bytes=21-40"
returns those bytes, but I want to remove them.
Is there a simple perl one-liner that will remove them?
I appreciate it.
------------------------------
Date: Thu, 30 Oct 2003 18:52:10 GMT
From: "Buck Turgidson" <jc_va@hotmail.com>
Subject: Re: Perl Cut Command
Message-Id: <5b7ba9e6f01d566443bd8afe957bc122@news.teranews.com>
> 21-40, and just print 1-20 and 21 thru 60 on a line.
>
That should read "just print 1-20 and 41 thru 60 on a line"
------------------------------
Date: Thu, 30 Oct 2003 16:46:42 +0000
From: "Alan J. Flavell" <flavell@ph.gla.ac.uk>
Subject: Re: regex for stripping HTML
Message-Id: <Pine.LNX.4.53.0310301638060.32163@ppepc56.ph.gla.ac.uk>
On Thu, 30 Oct 2003, DOV LEVENGLICK ...
Bogosity alerts:
1:
Content-Type: multipart/alternative;
boundary="------------030500060107020504030609"
2: TOFU-posting
3: cross-posted without further comment to a dead newsgroup
comp.lang.perl
and need I mention the SHOUTED PERSONAL NAME?
> ... wrote:
>
> you have to escape < because it can be used as a search delimiter
Well, Q.E.D.
I suppose it's wasted effort to suggest you might get a grasp on your
material and the conventions of your chosen forum -before- stepping up
to the plate to offer answers to technical questions?
If you had been _asking_ a question, then such behaviour *might*
just be a tad[1] more excusable.
[1] No pun intended.
------------------------------
Date: 30 Oct 2003 06:27:24 -0800
From: rjohnson@shell.com (Roy Johnson)
Subject: Re: Singleton process
Message-Id: <3ee08638.0310300627.43651d1b@posting.google.com>
Ben Morrow <usenet@morrow.me.uk> wrote in message news:<bnphpr$sbi$2@wisteria.csv.warwick.ac.uk>...
> rjohnson@shell.com (Roy Johnson) wrote:
> > For some reason, both suggestions (using $0 and using DATA) fail on my
> > Unix box. I am using flock, though, and when I create a throwaway file
> > for the purpose, it works properly.
>
> Out of interest: which Unix are you on, what error do you get, and
> does your perl use flock() or fcntl() locking (if you can tell)?
I'm on Solaris (5.8).
The error message I get is
Bad file number
I don't know how to check which form of locking is being done. Here's
a sample program:
#!perl
use strict;
use warnings;
use Fcntl ':flock';
open SELF, $0 or die "Could not open $0: $!\n";
flock SELF, LOCK_EX | LOCK_NB
or die "Could not flock $0: $!\n";
close SELF;
print "Done\n";
------------------------------
Date: 30 Oct 2003 16:02:42 GMT
From: ctcgag@hotmail.com
Subject: Re: Singleton process
Message-Id: <20031030110242.968$iN@newsreader.com>
rjohnson@shell.com (Roy Johnson) wrote:
> Ben Morrow <usenet@morrow.me.uk> wrote in message
> news:<bnphpr$sbi$2@wisteria.csv.warwick.ac.uk>...
> > rjohnson@shell.com (Roy Johnson) wrote:
> > > For some reason, both suggestions (using $0 and using DATA) fail on
> > > my Unix box. I am using flock, though, and when I create a throwaway
> > > file for the purpose, it works properly.
> >
> > Out of interest: which Unix are you on, what error do you get, and
> > does your perl use flock() or fcntl() locking (if you can tell)?
>
> I'm on Solaris (5.8).
> The error message I get is
> Bad file number
>
> I don't know how to check which form of locking is being done. Here's
> a sample program:
>
> #!perl
>
> use strict;
> use warnings;
>
> use Fcntl ':flock';
> open SELF, $0 or die "Could not open $0: $!\n";
> flock SELF, LOCK_EX | LOCK_NB
> or die "Could not flock $0: $!\n";
> close SELF;
> print "Done\n";
I get the same thing on my version of perl on that OS. changing it to open
SELF, "+<$0" worked.
Apparently this is an instance of the "can't lock exclusively if you don't
intend to write" issue.
Xho
--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service New Rate! $9.95/Month 50GB
------------------------------
Date: 30 Oct 2003 08:08:33 -0800
From: chris.mielke@drake.edu (Milkweed)
Subject: Re: Sort two dimensional array with multiple keys
Message-Id: <f0f3e49.0310300808.46334b9b@posting.google.com>
> Unlikely. The variable $timestamp isn't assigned a value.
I forgot to mention the $timestamp variable is assigned using the
localtime function further up in the code. Sorry for not explaining
this in my previous post.
> Assume your data is given like this (what it should be, but isn't, after
> the loop over @xlate):
This is what is looks like.
> my @entries = (
> [ qw( 207.28.198.86 10.36.1.121 0310291642)],
> [ qw( 207.28.198.86 10.36.1.121 0310291753)],
> [ qw( 207.28.201.113 10.77.2.241 0310291642)],
> [ qw( 207.28.200.113 10.75.2.87 0310291642)],
> [ qw( 207.28.199.86 10.76.1.80 0310291642)],
> [ qw( 207.28.198.104 10.1.3.153 0310291642)],
> [ qw( 207.28.198.86 10.36.1.121 0310291324)],
> [ qw( 207.28.199.104 10.2.2.77 0310291642)],
> [ qw( 207.28.195.33 10.2.4.111 0310291642)],
> );
>
> For sorting, compare any two IPs as strings. If they are equal,
> compare the timestamps as numbers. The result is your sorted list:
>
> my @sorted = sort
> { $a->[ 0] cmp $b->[ 0] or $a->[ 2] <=> $b->[ 2] }
> @entries;
>
> print "@$_\n" for @sorted;
>
> Anno
The above code works. Thanks! I'm worried about how fast the two
subsorts will perform. I could potentially have hundreds of thousands
of entries, which is why I was trying to do something with an indexed
search in the first place. Thanks again for your help.
Chris
------------------------------
Date: 30 Oct 2003 09:40:00 -0800
From: chris.mielke@drake.edu (Milkweed)
Subject: Re: Sort two dimensional array with multiple keys
Message-Id: <f0f3e49.0310300940.72d4604b@posting.google.com>
> Try this (the technique is known as the Schwartzian Transform after
> Randal Schwartz):
>
> my @sorted = map { $_->[0] }
> sort { $b->[1] cmp $a->[1] }
> map { [ $_, $_->[0].$_->[2] ] }
> @entries;
>
> This will sort in ASCIIbetical order, first of global IP and then of
> timestamp. If you want the IPs in a better order you could use
> map { [ $_, inet_aton($_->[0]).$_->[2] ] }
> for the first map instead (after using Socket, obviously).
When I try this:
my @sorted =
map { $_->[0] }
sort { $b->[1] cmp $a->[1] }
map { $_, inet_aton($_->[0]).$_->[2] }
@entries;
I get the following error:
Can't use string ("ÏÄÈ0310301117") as an ARRAY ref while "strict refs"
in use at ./NAT.pl line 73.
Any idea how to get past this?
Thanks,
Chris
------------------------------
Date: Thu, 30 Oct 2003 18:06:38 -0000
From: gbacon@hiwaay.net (Greg Bacon)
Subject: Re: Sort two dimensional array with multiple keys
Message-Id: <vq2kpe720mohb1@corp.supernews.com>
In article <f0f3e49.0310300940.72d4604b@posting.google.com>,
Milkweed <chris.mielke@drake.edu> wrote:
: When I try this:
: my @sorted =
: map { $_->[0] }
: sort { $b->[1] cmp $a->[1] }
: map { $_, inet_aton($_->[0]).$_->[2] }
: @entries;
:
: I get the following error:
:
: Can't use string ("ÏÄÈ0310301117") as an ARRAY ref while "strict refs"
: in use at ./NAT.pl line 73.
Your first map should produce a list of array references:
...
map { [ $_, inet_aton($_->[0]) . $_->[2] ] }
@entries;
Greg
--
I am sorry, but I just cannot accept that as a proper definition of
patriotism. Blind allegiance is the mother of tyranny, not patriotism.
-- R. Lee Wrights
------------------------------
Date: 30 Oct 2003 10:28:37 -0800
From: chris.mielke@drake.edu (Milkweed)
Subject: Re: Sort two dimensional array with multiple keys
Message-Id: <f0f3e49.0310301028.7cc30e14@posting.google.com>
> Try this (the technique is known as the Schwartzian Transform after
> Randal Schwartz):
>
> my @sorted = map { $_->[0] }
> sort { $b->[1] cmp $a->[1] }
> map { [ $_, $_->[0].$_->[2] ] }
> @entries;
>
> This will sort in ASCIIbetical order, first of global IP and then of
> timestamp. If you want the IPs in a better order you could use
> map { [ $_, inet_aton($_->[0]).$_->[2] ] }
> for the first map instead (after using Socket, obviously).
>
> I found out about this from http://perl.plover.com/: a very useful
> resource.
>
> Ben
Forget my last reply. I'm a dork. I forgot to put the outside [ ] in
the first map statement. Once I put those in it worked perfectly.
Thanks for your help!
Chris
------------------------------
Date: Thu, 30 Oct 2003 09:36:47 -0500
From: JAWS <jaws@ericsson.ca>
Subject: Re: sourcing a file from perl
Message-Id: <3FA121FF.1AE2C5E6@ericsson.ca>
Thanx for all the suggestions, i'll have to call a csh script from my perl
since i need to do some treatment before the sourcing and it is a pretty
nasty script that sources others that sources... you get the idea...
c-ya
jp
JAWS wrote:
> I need to use the csh source command or anything equivalent form a perl
> script but i can't access the source command because the shell fired by
> perl is sh. Ideally, i also need to be able to use the new environment
> variables in the rest of my perl program...
>
> thanks in advance for suggestions
>
> jp
------------------------------
Date: 30 Oct 2003 15:57:55 GMT
From: zeke03 <zeke03_@caramail.com>
Subject: ssh2+checksum+ perl module ?
Message-Id: <20031030-175755-456078@foorum.com>
Hello,
I would like to work on ssh and checksum. In fact, this is what i would like to
do :
- chekcsum files to send on the local server
- send files + checksum files by ssh (ssh2) to the distant server
- connect to the distant server by ssh (the public key are ok) to do a checksum
on the files which were send
- compare the two checksums
=> so, my questions is : is there a perl module that allow such things ?!
which one ?
Thanks a lot !
zeke03@caramail.com
--
Ce message a ete poste via la plateforme Web club-Internet.fr
This message has been posted by the Web platform club-Internet.fr
http://forums.club-internet.fr/
------------------------------
Date: 30 Oct 2003 06:33:27 -0800
From: magelord@t-online.de (Math55)
Subject: Threads and perl?
Message-Id: <a2b8188a.0310300633.2249c685@posting.google.com>
hello, i want to use threads in my perl program. i want to build a
method that compares a time in the future with the current time. if
both timestamps are equal i want to do something. how could i do that.
can i do that without threads?
THANKS:)
------------------------------
Date: Thu, 30 Oct 2003 15:59:58 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Threads and perl?
Message-Id: <bnr9et$143s3h$1@ID-184292.news.uni-berlin.de>
Math55 wrote:
> hello, i want to use threads in my perl program.
Why?
> i want to build a method that compares a time in the future with
> the current time. if both timestamps are equal i want to do
> something. how could i do that.
This is what I'm doing to have a program run an update routine daily:
my $currenttime = time;
open FH, '+< update.txt' or die $!;
if ($currenttime > <FH>) {
seek FH, 0, 0;
print FH updatetime();
# run update routine
}
close FH or die $!;
sub updatetime {
# Next day at 3:47 a.m. local time
require Time::Local;
return 100000 + Time::Local::timelocal(
0,0,0,(localtime $currenttime)[3..5]);
}
Hope that helps.
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Thu, 30 Oct 2003 08:52:59 -0600
From: Erik Anderson <anderiv@spam.me.not.visi.com>
Subject: UNIX domain sockets
Message-Id: <3fa125cc$0$75897$a1866201@authen.newsreader.visi.com>
I'm trying to implement IPC using IO::Socket::UNIX, but have come into
significant difficulty. I've searched groups.google.com, and have been
able to find very few examples of the proper use of IO::Socket::UNIX.
I have written a very simple client and server system to test this. The
code is below. The client sends some data to the server, which should
display it...it's not working though. Any ideas?
Client Code:
--------------------
#!/usr/bin/perl
use IO::Handle;
use IO::Socket;
$socket = IO::Socket::UNIX->new( Peer => "/sckt",
Type => SOCK_STREAM,
Timeout => 10 ) or die "$!\n$@";
$socket->autoflush(1);
$num=0;
while(1) {
print $socket "$num";
$socket->flush();
$num++;
sleep(2);
}
exit;
--------------------
Server code:
--------------------
#!/usr/bin/perl
use IO::Handle;
use IO::Socket;
unlink "/sckt";
my $Server = IO::Socket::UNIX->new( Local => "/sckt",
Type => SOCK_STREAM,
Listen => 5
) or die $@;
while($session = $Server->accept) {
chomp($line = <$session>);
print "From client: " . $line . "\n";
$Server->flush();
sleep(1);
}
exit;
--------------------
Thanks!
-Erik Anderson
------------------------------
Date: Thu, 30 Oct 2003 11:27:11 -0500
From: Tim Heaney <theaney@cablespeed.com>
Subject: Re: UNIX domain sockets
Message-Id: <87ekwur8rk.fsf@mrbun.watterson>
Erik Anderson <anderiv@spam.me.not.visi.com> writes:
> print $socket "$num";
If you want to read from the socket with <>, then you have to send the
newline
print $socket "$num\n";
I hope this helps,
Tim
------------------------------
Date: Thu, 30 Oct 2003 18:29:25 +0000 (UTC)
From: Stan Brown <stanb@panix.com>
Subject: Re: Video::Capture example?
Message-Id: <bnrla5$n1n$1@reader2.panix.com>
In <4u32qvgthijulq4baguj941i6a9jhr8g7p@4ax.com> zentara <zentara@highstream.net> writes:
>On Wed, 29 Oct 2003 15:15:27 +0000 (UTC), Stan Brown <stanb@panix.com>
>wrote:
>>I'm writing a perl script to capture images from some cameras, and make
>>mpes out of them on Linux.
>>
>>I't basicly working using system() calls to v4lctl, but that is slowing
>>things dow, spawning a seperate task for each capture.
>>
>>I've found the Video::Captur module, and I think it's the way to go.
>>However it has no documentation for the calls, and the example programs
>>have no comments.
>>
>>Could anyone point me to a working example of capturing an image using
>>this? I suspect I jyst need to traslate a couple of v4;ctl commands to the
>>corect syntax for using this module. EG:
>Here is a Tk camera capture program is wrote. The biggest obstacles are
>making sure the camera syncs, and converting the raw BGR data to RGB.
>There are a couple of different ways you can do this, I used a technique
>of reversing the data, then flipping it with Imager. Imager also has a
>more direct matrix method, but I think it was a bit slower that way.
>Read "perldoc Imager::Transformations".
Thanks for this.m It looks like it will help a lot
Sorry I missed it earlier :-(
--
"They that would give up essential liberty for temporary safety deserve
neither liberty nor safety."
-- Benjamin Franklin
------------------------------
Date: 30 Oct 2003 07:09:53 -0800
From: rjohnson@shell.com (Roy Johnson)
Subject: Re: What am I doing wrong?!
Message-Id: <3ee08638.0310300709.2c574086@posting.google.com>
tony.walker@dhl.com (Tony Walker) wrote in message news:<72461e59.0310300212.1a948130@posting.google.com>...
> I'm now trying
>
> for (my $i=0..@entry)
> or
> for (@entry)
>
> And neither seem to be working??
You may have two loops that use $_ as their loop variables. You need
to post the whole section of code and say *how* it's not working. The
code in the example to which you replied looked good to me.
------------------------------
Date: Thu, 30 Oct 2003 16:09:45 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: What am I doing wrong?!
Message-Id: <dJaob.9827$Q9.4370@nwrddc02.gnilink.net>
Tony Walker wrote:
> A question related to one of the responses:
>
> I'm now trying
>
> for (my $i=0..@entry)
Sorry, that was from me and it was rather inconsidered of me to post this
piece code without testing.
What I meant was
for my $i (0..$#entry)
> or
> for (@entry)
>
>
> And neither seem to be working??
This is a useless error description.
Both are working fine as standalone lines of code, but they may not be doing
what you think they are doing or they may not be doing in context what you
think they are doing.
Without you telling us what you except them to do and without showing us
your new program code there is no way to tell why you they behave different
then you expect (except that I still remembered that my piece of code had
the right idea, but was coded wrong).
jue
------------------------------
Date: Thu, 30 Oct 2003 18:01:57 +0100
From: Tore Aursand <tore@aursand.no>
Subject: Re: What am I doing wrong?!
Message-Id: <pan.2003.10.30.12.03.56.591821@aursand.no>
On Thu, 30 Oct 2003 02:12:54 -0800, Tony Walker wrote:
> I'm now trying
>
> for (my $i=0..@entry)
> or
> for (@entry)
>
> And neither seem to be working??
Use 'foreach';
foreach ( @array ) {
}
If you need to know - or count - the element index, just use a counter;
my $cnt = 0;
foreach ( @array ) {
$cnt++;
print $_ . ' is element #' . $cnt . "\n";
}
--
Tore Aursand <tore@aursand.no>
------------------------------
Date: Thu, 30 Oct 2003 18:10:17 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: What am I doing wrong?!
Message-Id: <ducob.31595$AU.21034@nwrddc01.gnilink.net>
Tore Aursand wrote:
> On Thu, 30 Oct 2003 02:12:54 -0800, Tony Walker wrote:
>> I'm now trying
>> for (@entry)
>>
> Use 'foreach';
> foreach ( @array )
What exactly would be the difference between 'for' and 'foreach' (besides
the additional 4 letters)?
jue
------------------------------
Date: Thu, 30 Oct 2003 18:32:55 -0000
From: "David K. Wall" <usenet@dwall.fastmail.fm>
Subject: Re: What am I doing wrong?!
Message-Id: <Xns942489D32C682dkwwashere@216.168.3.30>
Jürgen Exner <jurgenex@hotmail.com> wrote:
> Tore Aursand wrote:
>> On Thu, 30 Oct 2003 02:12:54 -0800, Tony Walker wrote:
>>> I'm now trying
>>> for (@entry)
>>>
>> Use 'foreach';
>> foreach ( @array )
>
> What exactly would be the difference between 'for' and 'foreach'
> (besides the additional 4 letters)?
It's a bit more explicit about what it's doing? perlsyn gives
'readability' as the justification for the existence of 'foreach', but
that's arguable, and I don't really see the need for it. 'foreach' is
a bit of dead yeast left in the Perl beer, IMHO; forget the yeast and
enjoy the flavor. :-)
--
David Wall
------------------------------
Date: 30 Oct 2003 10:46:24 -0800
From: jason4chen@yahoo.com (Jason Chen)
Subject: Win::OLE excel function run twice
Message-Id: <508693ba.0310301046.2667b69f@posting.google.com>
I have an excel macro in file c:\temp\test1.xls as this:
Public Function test1(str As String)
Debug.Print "the string is: " & str
End Function
I run the macro through perl like this:
use Win32::OLE;
my $Excel = Win32::OLE->GetActiveObject('Excel.Application');
my $Book = $Excel->Workbooks->Open("C:\\temp\\test1.xls");
$Excel->Run('Test1("kabc")');
Here is Result:
here is kabc
here is kabc
The problem is the test1 function is run TWICE!!!
I am using Windows 2000 and ActivateState Perl 5.6.
Help!
------------------------------
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.
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 V10 Issue 5730
***************************************