[23518] in Perl-Users-Digest
Perl-Users Digest, Issue: 5727 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Oct 29 18:06:13 2003
Date: Wed, 29 Oct 2003 15:05:12 -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 Wed, 29 Oct 2003 Volume: 10 Number: 5727
Today's topics:
Re: array reference expected <bharnish@technologist.com>
Re: array reference expected <usenet@morrow.me.uk>
Re: calculate an average <glex_nospam@qwest.invalid>
Re: calculate an average <noreply@gunnar.cc>
Re: calculate an average <mbudash@sonic.net>
Re: calculate an average <bharnish@technologist.com>
Re: calculate an average <glex_nospam@qwest.invalid>
Re: calculate an average <mbudash@sonic.net>
Re: Call Perl Scripts from Other Dir in Linux, Path Mes <bart.lateur@pandora.be>
Re: Call Perl Scripts from Other Dir in Linux, Path Mes <usenet@morrow.me.uk>
Re: Checkbox - database checkbox, if checked gives val <jwillmore@remove.adelphia.net>
converting text data (Vumani Dlamini)
Re: converting text data <usenet@morrow.me.uk>
Re: converting text data <noreply@gunnar.cc>
Re: Java with apache from perl script? <jwillmore@remove.adelphia.net>
Re: job: perl script for authorize.net AIM (advanced in <dha@panix.com>
Re: job: perl script for authorize.net AIM (advanced in <jwillmore@remove.adelphia.net>
Probably a FAQ, recursivly creating a directory tree? <stanb@panix.com>
Re: Probably a FAQ, recursivly creating a directory tre <usenet@morrow.me.uk>
Re: Probably a FAQ, recursivly creating a directory tre <stanb@panix.com>
Re: Resetting //g (Roy Johnson)
Re: Resetting //g <usenet@morrow.me.uk>
Re: Rounding a float in Perl? <nospam-abuse@ilyaz.org>
Re: Singleton process <bart.lateur@pandora.be>
Re: Singleton process (Roy Johnson)
Re: tie problem <rschurchill@freenet.co.uk>
Re: What am I doing wrong?! <usenet@dwall.fastmail.fm>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 29 Oct 2003 19:57:45 GMT
From: Brian Harnish <bharnish@technologist.com>
Subject: Re: array reference expected
Message-Id: <pan.2003.10.29.19.58.02.553111@technologist.com>
On Wed, 29 Oct 2003 10:50:50 -0800, bnapus wrote:
> Perlers -
>
> I want to assign a value to an annonymous hash:
> $hash->[$i][$j]{Score} = 1;
>
> Why won't it accept a scalar? I get an error about perl expecting an
> address to an array. What I envisioned was a hash within a 2D array.
>
> I ended up using this:
> $hash->[$i]{$j}{Score} = 1;
>
> and it does what I want it to - just curious.
>
> Josh
Without seeing the rest of your code, I don't have an answer for you. But
yes, it is possible to do what you want to do:
perl -MData::Dumper -we '$hash->[0][0]{Score}=1;print Dumper $hash'
I believe you are supposed to breakdown your problem to a simple script
that shows the problem, then post that script. Often durring this process,
you find the error yourself.
- Brian
------------------------------
Date: Wed, 29 Oct 2003 20:00:04 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: array reference expected
Message-Id: <bnp684$nlk$1@wisteria.csv.warwick.ac.uk>
bnapus@yahoo.com (bnapus) wrote:
> I want to assign a value to an annonymous hash:
> $hash->[$i][$j]{Score} = 1;
This implies $hash is a
reference to an array containing
references to arrays containing
references to hashes,
i.e., that the structure you want is
$hash = [
($i - 1 elements),
[
($j - 1 elements),
{
Score => 1
}
]
];
> Why won't it accept a scalar? I get an error about perl expecting an
> address to an array. What I envisioned was a hash within a 2D array.
>
> I ended up using this:
> $hash->[$i]{$j}{Score} = 1;
...which implies that the structure you actually have is
$hash = [
($i - 1 elements),
{
$j => {
Score => 1
}
}
];
. The error about 'reference to an array' is referring to the contents
of $hash->[$i]: by attempting to dereference it with [$j] you are
assuming it contains an arrayref, when it seems as though it in fact
contains a hashref.
> and it does what I want it to - just curious.
I don't think it does. For a start, the elements of $hash->[$i] are
ordered in the structure you (thought you) wanted, whereas here they
are not.
I think you have misunderstood either your data structure or how
references work in Perl. Add 'use Data::Dumper;' to the top of your
script and 'print Dumper $hash;' just before this line. Then carefully
re-read perllol and perlreftut again, and compare with what you see.
If you still don't understand, then explain carefully what you are
trying to achieve with this data structure and show the code you have
at present, and someone will be better placed to tell you which one
you meant and what is wrong with your code.
Ben
--
If you put all the prophets, | You'd have so much more reason
Mystics and saints | Than ever was born
In one room together, | Out of all of the conflicts of time.
ben@morrow.me.uk |----------------+---------------| The Levellers, 'Believers'
------------------------------
Date: Wed, 29 Oct 2003 13:31:41 -0600
From: "J. Gleixner" <glex_nospam@qwest.invalid>
Subject: Re: calculate an average
Message-Id: <pxUnb.35$C22.36592@news.uswest.net>
Jack wrote:
> I need to calculate an average of every last-3-values.
> I feel there is a better way or faster code than this
How 'bout something like:
foreach my $idx (0 .. $#data-2)
{
print "average=",
($data[$idx] + $data[$idx+1] + $data[$idx+2])/3, "\n";
}
You'll need to deal with rounding or truncating...but that's covered in
the perl FAQs.
------------------------------
Date: Wed, 29 Oct 2003 20:36:12 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: calculate an average
Message-Id: <bnp55o$13j2k4$1@ID-184292.news.uni-berlin.de>
Jack wrote:
> I need to calculate an average of every last-3-values.
<code snipped>
> I feel there is a better way or faster code than this
You'd be able to shorten the code by using the splice() function:
foreach my $item ( splice @data, -3 )
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Wed, 29 Oct 2003 19:47:07 GMT
From: Michael Budash <mbudash@sonic.net>
Subject: Re: calculate an average
Message-Id: <mbudash-C8CFFB.11470829102003@typhoon.sonic.net>
In article <pxUnb.35$C22.36592@news.uswest.net>,
"J. Gleixner" <glex_nospam@qwest.invalid> wrote:
> Jack wrote:
> > I need to calculate an average of every last-3-values.
>
> > I feel there is a better way or faster code than this
>
>
> How 'bout something like:
>
> foreach my $idx (0 .. $#data-2)
> {
> print "average=",
> ($data[$idx] + $data[$idx+1] + $data[$idx+2])/3, "\n";
> }
>
> You'll need to deal with rounding or truncating...but that's covered in
> the perl FAQs.
>
not quite. with this data:
my @data = qw/1 2 3 4 5 6 7/;
that code produces these results:
average=2
average=3
average=4
average=5
average=6
try this instead:
my $size = 3;
my $idx = 0;
while (1) {
print "average=",
($data[$idx] + $data[$idx+1] + $data[$idx+2])/$size, "\n";
$idx += $size;
last if $idx > $#data;
}
this code produces:
average=2
average=5
average=2.33333333333333
hth-
--
Michael Budash
------------------------------
Date: Wed, 29 Oct 2003 19:51:52 GMT
From: Brian Harnish <bharnish@technologist.com>
Subject: Re: calculate an average
Message-Id: <pan.2003.10.29.19.52.09.367848@technologist.com>
-----BEGIN xxx SIGNED MESSAGE-----
Hash: SHA1
On Thu, 30 Oct 2003 05:57:32 -0800, Jack wrote:
> I need to calculate an average of every last-3-values.
[snip...]
> I feel there is a better way or faster code than this
Try this:
# Assumes that scalar(@data) >= 3
my @data = 1..10;
my $avg = $data[0];
foreach (1..$#data) {
$avg += $data[$_];
$avg -= $data[$_-3] if($_>2);
print $avg/3 if ($_ >= 2);
}
__END__
- Brian
-----BEGIN xxx SIGNATURE-----
Version: GnuPG v1.2.2 (GNU/Linux)
iD8DBQE/oBpmiK/rA3tCpFYRAnBoAJ9aydbV4k7XXeabELeGSHW1x8A/mQCgksuC
XNYn5odaocxpgZMNfAv4NHs=
=EevM
-----END PGP SIGNATURE-----
------------------------------
Date: Wed, 29 Oct 2003 15:03:22 -0600
From: "J. Gleixner" <glex_nospam@qwest.invalid>
Subject: Re: calculate an average
Message-Id: <vTVnb.50$C22.43716@news.uswest.net>
Michael Budash wrote:
> not quite. with this data:
>
> my @data = qw/1 2 3 4 5 6 7/;
>
> that code produces these results:
>
> average=2
> average=3
> average=4
> average=5
> average=6
I took "every last-3-values" as [0-2], [1-3], ... instead of [0-2],
[3-5], ... oh well, one of them likely does what the OP wants.
See ya
------------------------------
Date: Wed, 29 Oct 2003 21:07:21 GMT
From: Michael Budash <mbudash@sonic.net>
Subject: Re: calculate an average
Message-Id: <mbudash-FF5BC7.13072129102003@typhoon.sonic.net>
In article <vTVnb.50$C22.43716@news.uswest.net>,
"J. Gleixner" <glex_nospam@qwest.invalid> wrote:
> Michael Budash wrote:
>
> > not quite. with this data:
> >
> > my @data = qw/1 2 3 4 5 6 7/;
> >
> > that code produces these results:
> >
> > average=2
> > average=3
> > average=4
> > average=5
> > average=6
>
> I took "every last-3-values" as [0-2], [1-3], ... instead of [0-2],
> [3-5], ... oh well, one of them likely does what the OP wants.
>
> See ya
>
his original code (however obfuscated) seemed to indicate he wanted the
latter, but, as you say, "one of them likely does what the OP wants."
cheers
--
Michael Budash
------------------------------
Date: Wed, 29 Oct 2003 20:48:01 GMT
From: Bart Lateur <bart.lateur@pandora.be>
Subject: Re: Call Perl Scripts from Other Dir in Linux, Path Messed Up
Message-Id: <fh90qvg0js97otpb52f7m9plcpu9545hps@4ax.com>
Ben Morrow wrote:
>> The approach I'm advocating, is to simply figure out the path,
>> either absolute or relative, out of $0, the name for the script,
>> since that is *always* a valid path, at startup. At least, I can't
>> think of any counter-examples.
>
>You should check what you write before you post. 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: the fact that it sometimes refuses to work is
>because this is not always possible.
Let me point you to this node:
FindBin is broken (RE: How do I get the full path to the script
executing?)
<http://perlmonks.org/index.pl?node_id=41213>
Points:
- FindBin does a useless search. There is *no need* to scan $PATH, as
perl scripts aren't ever searched in it.
- 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.
--
Bart.
------------------------------
Date: Wed, 29 Oct 2003 21:48:13 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: Call Perl Scripts from Other Dir in Linux, Path Messed Up
Message-Id: <bnpcit$qgi$1@wisteria.csv.warwick.ac.uk>
Bart Lateur <bart.lateur@pandora.be> wrote:
> Ben Morrow wrote:
> Let me point you to this node:
>
> FindBin is broken (RE: How do I get the full path to the script
> executing?)
> <http://perlmonks.org/index.pl?node_id=41213>
The final comment on that post is pertinent... setid scripts ought to
only get a /dev/fd argument for the script, in which case the task is
impossible... interestingly, mine seem not no. Worrying...
> Points:
>
> - FindBin does a useless search. There is *no need* to scan $PATH, as
> perl scripts aren't ever searched in it.
What's the -S option for then? No, OK, in that case perl knows the
full path and can put in $0.
> - 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.
OK, FindBin is broken. Let's work out what's wrong, and fix it. :)
Ben
--
Joy and Woe are woven fine,
A Clothing for the Soul divine William Blake
Under every grief and pine 'Auguries of Innocence'
Runs a joy with silken twine. ben@morrow.me.uk
------------------------------
Date: Wed, 29 Oct 2003 19:23:55 GMT
From: James Willmore <jwillmore@remove.adelphia.net>
Subject: Re: Checkbox - database checkbox, if checked gives value of 1 .. how to sum ?
Message-Id: <20031029142354.30218050.jwillmore@remove.adelphia.net>
On 29 Oct 2003 10:11:42 -0800
searsdvdtech@yahoo.com (randy) wrote:
> This is a Perl 5 Based Database . if you can ... Please go to
> www.baseportal.com, and you can setup your own perl 5 based database
> or create a page based in Perl 5.
> So with that out of the way.... I created a database with a field
> named "comp"
> it is a checkbox type of field, i can not put it any other terms .
> Also the field
> has two default values: if checked = 1, if no check 0. That much
> works good .
> it displays in a page , as a colum and if checked has value of 1 in
> the record that checked. Now at the bottom of that colum i would
> like the total of the field
> "comp".. to display the sum of all the records that have been
> checked.
>
> I hope this helps... Thanks for all your help.
>
> see page at
> http://baseportal.com/cgi-bin/baseportal.pl?htx=/searsdvdtech/testforperl.
>
>
> Has anyone looked at this Page? It might help you to understand the
> structure of the output of the database.
>
> Thanks Again..
Please don't top post - it is rude :-)
And, I did look at the URL you mentioned. *Contact the author*!
Since the author _may_ be able to help you.
--
Jim
Copyright notice: all code written by the author in this post is
released under the GPL. http://www.gnu.org/licenses/gpl.txt
for more information.
a fortune quote ...
Sturgeon's Law: 9027777763302f everything is crud.
------------------------------
Date: 29 Oct 2003 12:43:11 -0800
From: dvumani@hotmail.com (Vumani Dlamini)
Subject: converting text data
Message-Id: <4b35f3c9.0310291243.4ebf5ffa@posting.google.com>
I have data which is in this format:
### data ###
area=1101
home=003
mzer=00020
mzec=101
pmpr=00000
pmpc=102
bnsr=00000
bnsc=103
potr=00100
potc=104
swtr=00000
### end ####
and would like to produce the following data
area|home|amount|code
1101,003,00020,101
1101,003,00100,104
In short I would like to drop codes with a zero amount.
I am able to read in the file and produce the data, zero's included
using this code, but am unable to drop the lines corresponding to zero
amounts;
### code ####
my ($area , $home, $amount);
while (<DATA>){
if (/area=(\d+)/) {
$area = $1;
}
elsif (/home=(\d+)/) {
$home = $1;
}
elsif (/(\S+)r=(\d+)/) {
$home = $2;
}
elsif (/(\S+)c=(\d+)/) {
print <OUTFILE> "$area,$home,$amount,$2\"
}
}
I would also like to have my PERL programs in another directory rather
than in the one where the <DATA> file is. I also need help on how I
can change directory within the PERL program.
Thanks a lot.
Vumani
------------------------------
Date: Wed, 29 Oct 2003 21:02:53 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: converting text data
Message-Id: <bnp9tt$pad$1@wisteria.csv.warwick.ac.uk>
dvumani@hotmail.com (Vumani Dlamini) wrote:
> I have data which is in this format:
> ### data ###
> area=1101
> home=003
> mzer=00020
> mzec=101
> pmpr=00000
> pmpc=102
> bnsr=00000
> bnsc=103
> potr=00100
> potc=104
> swtr=00000
> ### end ####
>
> and would like to produce the following data
>
> area|home|amount|code
> 1101,003,00020,101
> 1101,003,00100,104
>
> In short I would like to drop codes with a zero amount.
>
> I am able to read in the file and produce the data, zero's included
> using this code, but am unable to drop the lines corresponding to zero
> amounts;
Am I to take it
a. that the area= and home= fields at the top apply to
the whole file,
b. that there will always be exactly one *c field for each *r field,
and
b. that only the *r fields will ever be zero?
> ### code ####
Standard questions:
Are you using strict?
Are you using warnings?
Did you check the return value of your open call?
> my ($area , $home, $amount);
> while (<DATA>){
You want to be careful using DATA. It is magic: see perldoc perldata.
> if (/area=(\d+)/) {
> $area = $1;
> }
> elsif (/home=(\d+)/) {
> $home = $1;
> }
> elsif (/(\S+)r=(\d+)/) {
If you do not need to record the \S+ part of the field, don't capture it.
> $home = $2;
I presume you meant
$amount = $2;
? Don't retype code.
> }
> elsif (/(\S+)c=(\d+)/) {
> print <OUTFILE> "$area,$home,$amount,$2\"
<> here will not at all do what you want. It will attempt to read a
line from OUTFILE and treat that string as the name of a filehandle to
write to. Unless you were using strict, which of corse you were... :)
What is the '\' for? Have you *tried* running this code?
print OUTFILE "$area,$home,$amount,$2" if $amount;
> }
> }
>I would also like to have my PERL
Perl or perl, never PERL.
>programs in another directory rather than in the one where the <DATA>
>file is. I also need help on how I can change directory within the
>PERL program.
perldoc -f chdir.
Ben
--
I've seen things you people wouldn't believe: attack ships on fire off the
shoulder of Orion; I've watched C-beams glitter in the darkness near the
Tannhauser Gate. All these moments will be lost, in time, like tears in rain.
Time to die. |-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-| ben@morrow.me.uk
------------------------------
Date: Wed, 29 Oct 2003 22:43:33 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: converting text data
Message-Id: <bnpckr$13alo9$1@ID-184292.news.uni-berlin.de>
Vumani Dlamini wrote:
> I have data which is in this format:
> ### data ###
> area=1101
> home=003
> mzer=00020
> mzec=101
> pmpr=00000
> pmpc=102
> bnsr=00000
> bnsc=103
> potr=00100
> potc=104
> swtr=00000
> ### end ####
>
> and would like to produce the following data
>
> area|home|amount|code
> 1101,003,00020,101
> 1101,003,00100,104
>
> In short I would like to drop codes with a zero amount.
>
> I am able to read in the file and produce the data, zero's
> included using this code, but am unable to drop the lines
> corresponding to zero amounts;
Below please find suggested minimal changes.
> ### code ####
> my ($area , $home, $amount);
Replace that line with:
my ($area , $home, $record);
> while (<DATA>){
> if (/area=(\d+)/) {
> $area = $1;
> }
> elsif (/home=(\d+)/) {
> $home = $1;
> }
> elsif (/(\S+)r=(\d+)/) {
> $home = $2;
Replace that line with:
$record = $2 > 0 ? "$area,$home,$2" : '';
> }
> elsif (/(\S+)c=(\d+)/) {
> print <OUTFILE> "$area,$home,$amount,$2\"
Replace that line with:
print OUTFILE "$record,$2\n" if $record;
$record = '';
(I assume that you opened a file for writing, and that you named the
handle OUTFILE.)
> }
> }
>
> I would also like to have my PERL programs in another directory
> rather than in the one where the <DATA> file is.
So? Then just state the path explicitly when opening the input file.
> I also need help on how I can change directory within the PERL
> program.
http://www.perldoc.com/perl5.8.0/pod/func/chdir.html
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Wed, 29 Oct 2003 19:32:40 GMT
From: James Willmore <jwillmore@remove.adelphia.net>
Subject: Re: Java with apache from perl script?
Message-Id: <20031029143239.1681c06a.jwillmore@remove.adelphia.net>
On 29 Oct 2003 09:26:16 -0800
i5513@hotmail.com (i5513) wrote:
> Hi, I'm running Apache server with mod_perl active.
>
> I can run my script from command line and all is fine, but when I
> run my script from navigator, it doesn't run fine because my script
> is:
>
> ...
> system "java program_java";
> ...
>
> How can I do Apache to run java programs?
If you want to have a Java Applet server, visit:
http://jakarta.apache.org/tomcat/index.html
<snip>
You _could_ use Perl to execute a Java application, but IMHO it would
be better to use an actual Java server to perform the task.
HTH
--
Jim
Copyright notice: all code written by the author in this post is
released under the GPL. http://www.gnu.org/licenses/gpl.txt
for more information.
a fortune quote ...
A fool must now and then be right by chance.
------------------------------
Date: Wed, 29 Oct 2003 20:49:43 +0000 (UTC)
From: "David H. Adler" <dha@panix.com>
Subject: Re: job: perl script for authorize.net AIM (advanced integration method)
Message-Id: <slrnbq09v7.hct.dha@panix2.panix.com>
In article <27c6f057.0310290842.7027eef4@posting.google.com>, dave the
spazz wrote:
> we need someone to write a perl script
You have posted a job posting or a resume in a technical group.
Longstanding Usenet tradition dictates that such postings go into
groups with names that contain "jobs", like "misc.jobs.offered", not
technical discussion groups like the ones to which you posted.
Had you read and understood the Usenet user manual posted frequently to
"news.announce.newusers", you might have already known this. :) (If
n.a.n is quieter than it should be, the relevent FAQs are available at
http://www.faqs.org/faqs/by-newsgroup/news/news.announce.newusers.html)
Another good source of information on how Usenet functions is
news.newusers.questions (information from which is also available at
http://www.geocities.com/nnqweb/).
Please do not explain your posting by saying "but I saw other job
postings here". Just because one person jumps off a bridge, doesn't
mean everyone does. Those postings are also in error, and I've
probably already notified them as well.
If you have questions about this policy, take it up with the news
administrators in the newsgroup news.admin.misc.
http://jobs.perl.org may be of more use to you
Yours for a better usenet,
dha
--
David H. Adler - <dha@panix.com> - http://www.panix.com/~dha/
_Day of Wrath_ is probably Dreyer's most popular film, which already
indicates something of the problems it poses.
- David Bordwell, The Films of Carl-Theodor Dreyer
------------------------------
Date: Wed, 29 Oct 2003 19:27:54 GMT
From: James Willmore <jwillmore@remove.adelphia.net>
Subject: Re: job: perl script for authorize.net AIM (advanced integration method)
Message-Id: <20031029142753.78df633f.jwillmore@remove.adelphia.net>
On 29 Oct 2003 08:42:19 -0800
opencityproject@yahoo.com (dave the spazz) wrote:
> MUST BE NEW YORK BASED
>
> we need someone to write a perl script for us as we move from SIM to
> AIM using authorize.net
>
> if you have experience with this please email me asap. thanks!
Post this to http://jobs.perl.org/ - _not_ here.
This is a USENET group - _not_ a billboard :-)
--
Jim
Copyright notice: all code written by the author in this post is
released under the GPL. http://www.gnu.org/licenses/gpl.txt
for more information.
a fortune quote ...
Painting, n.: The art of protecting flat surfaces from the
weather, and exposing them to the critic. -- Ambrose Bierce
------------------------------
Date: Wed, 29 Oct 2003 20:55:35 +0000 (UTC)
From: Stan Brown <stanb@panix.com>
Subject: Probably a FAQ, recursivly creating a directory tree?
Message-Id: <bnp9g7$ln$1@reader2.panix.com>
Givne a string containing a fullu qualified directory path name, I need a
routine that will verify it's existence, and atempt to create any missing
parts of it.
Surely someone has invented this wheel?
--
"They that would give up essential liberty for temporary safety deserve
neither liberty nor safety."
-- Benjamin Franklin
------------------------------
Date: Wed, 29 Oct 2003 21:51:28 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: Probably a FAQ, recursivly creating a directory tree?
Message-Id: <bnpcp0$qgi$2@wisteria.csv.warwick.ac.uk>
Stan Brown <stanb@panix.com> wrote:
> Givne a string containing a fullu qualified directory path name, I need a
> routine that will verify it's existence, and atempt to create any missing
> parts of it.
>
> Surely someone has invented this wheel?
perldoc File::Path
Ben
--
For the last month, a large number of PSNs in the Arpa[Inter-]net have been
reporting symptoms of congestion ... These reports have been accompanied by an
increasing number of user complaints ... As of June,... the Arpanet contained
47 nodes and 63 links. [ftp://rtfm.mit.edu/pub/arpaprob.txt] * ben@morrow.me.uk
------------------------------
Date: Wed, 29 Oct 2003 22:27:15 +0000 (UTC)
From: Stan Brown <stanb@panix.com>
Subject: Re: Probably a FAQ, recursivly creating a directory tree?
Message-Id: <bnpes3$2o6$1@reader2.panix.com>
In <bnpcp0$qgi$2@wisteria.csv.warwick.ac.uk> Ben Morrow <usenet@morrow.me.uk> writes:
>Stan Brown <stanb@panix.com> wrote:
>> Givne a string containing a fullu qualified directory path name, I need a
>> routine that will verify it's existence, and atempt to create any missing
>> parts of it.
>>
>> Surely someone has invented this wheel?
>perldoc File::Path
Thansk, tahts' perfect!
--
"They that would give up essential liberty for temporary safety deserve
neither liberty nor safety."
-- Benjamin Franklin
------------------------------
Date: 29 Oct 2003 11:45:16 -0800
From: rjohnson@shell.com (Roy Johnson)
Subject: Re: Resetting //g
Message-Id: <3ee08638.0310291145.6a20a141@posting.google.com>
Ben Morrow <usenet@morrow.me.uk> wrote in message news:<bnoo6h$hr4$1@wisteria.csv.warwick.ac.uk>...
> From perldoc perlop:
>
> | The position after the last match can be read or set using the pos()
> | function; see "pos" in perlfunc.
I shoulda thought of that. Thanks.
> /Nota bene/ that you call pos on $str, not $pat.
>
> > Incidentally, the best way to get the $nth match of $pat in $str is
> > $str =~ /(?:.*?($pat)){$n}/;
> > but I'm still curious about short-circuited global matches.
>
> I would have said a better way would be
> $nthmatch = ($str =~ /($pat)/g)[$n];
> , not least because it actually works, but maybe that's just me... :)
What makes you think that my pattern doesn't work? It does, while
yours actually doesn't: you need to index $n-1 unless you've reset $[
to 1. The difference is that yours does about twice the work, and so
takes about twice as long. The aborting for loop is even slower.
Some benchmark code for your amusement:
#!perl
use strict;
use warnings;
use Benchmark;
my $str='abcabbcabbbbcabcabbcab';
my $n = 3; ## Find the $nth occurrence
my $pat = qr/ab+/; ## of this pattern
sub pat_n;
sub for_g;
sub m_g;
print "pat_n Match $n in $str is ", pat_n, "\n";
print "for_g Match $n in $str is ", for_g, "\n";
print "m_g Match $n in $str is ", m_g, "\n";
timethese( 100_000, {
'$pat{$n}' => \&pat_n,
'for //g' => \&for_g,
'm_g' => \&m_g,
});
sub pat_n {
$str =~ /(?:.*?($pat)){$n}/;
}
sub for_g {
my $NthMatch;
for (1..$n) {
$str =~ /($pat)/g;
$NthMatch = $1;
}
pos($str) = 0;
$NthMatch;
}
sub m_g {
($str =~ /($pat)/g)[$n-1];
}
------------------------------
Date: Wed, 29 Oct 2003 20:29:23 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: Resetting //g
Message-Id: <bnp7v3$o9v$1@wisteria.csv.warwick.ac.uk>
rjohnson@shell.com (Roy Johnson) wrote:
> Ben Morrow <usenet@morrow.me.uk> wrote in message
> news:<bnoo6h$hr4$1@wisteria.csv.warwick.ac.uk>...
> > > Incidentally, the best way to get the $nth match of $pat in $str is
> > > $str =~ /(?:.*?($pat)){$n}/;
> > > but I'm still curious about short-circuited global matches.
> >
> > I would have said a better way would be
> > $nthmatch = ($str =~ /($pat)/g)[$n];
> > , not least because it actually works, but maybe that's just me... :)
>
> What makes you think that my pattern doesn't work?
Sorry, I must have misread it... or something. I thought it would fail
on inputs like
ab ab ab abb
and get the 'abb' instead of the third 'ab', but I was wrong.
> It does, while yours actually doesn't: you need to index $n-1 unless
> you've reset $[ to 1.
Yes, of course... :(
> The difference is that yours does about twice the work, and so
> takes about twice as long. The aborting for loop is even slower.
>
> Some benchmark code for your amusement:
Actually, on my machine my code runs slowest of the three for that
input... :)
Ben
--
If I were a butterfly I'd live for a day, / I would be free, just blowing away.
This cruel country has driven me down / Teased me and lied, teased me and lied.
I've only sad stories to tell to this town: / My dreams have withered and died.
ben@morrow.me.uk <=>=<=>=<=>=<=>=<=>=<=>=<=>=<=>=<=>=<=>=<=> (Kate Rusby)
------------------------------
Date: Wed, 29 Oct 2003 21:01:47 +0000 (UTC)
From: Ilya Zakharevich <nospam-abuse@ilyaz.org>
Subject: Re: Rounding a float in Perl?
Message-Id: <bnp9rr$11le$1@agate.berkeley.edu>
[A complimentary Cc of this posting was sent to
Anno Siegel
<anno4000@lublin.zrz.tu-berlin.de>], who wrote in article <bno3ra$1p7$1@mamenchi.zrz.TU-Berlin.DE>:
> It (i.e. my implementation on my machine) is still 44% faster than sprintf,
> as opposed to 113% for the non-scaling version. Then again, it can also
> round 1234 to 1000 for a negative "number of decimal places", something
> sprintf doesn't do.
>
> But we're approaching bean-counting territory here...
On my machine (EMX on 850MHz Athlon) your version takes 5.03 us per
iteration (when non-scaling). sprintf takes 0.15 us per iteration.
Apparently your CRT implementation is completely broken speedwise...
Enough said.
Hope this helps,
Ilya
------------------------------
Date: Wed, 29 Oct 2003 20:41:38 GMT
From: Bart Lateur <bart.lateur@pandora.be>
Subject: Re: Singleton process
Message-Id: <v990qvo2e5ico3s210uveo0frac0s00545@4ax.com>
Mark Jason Dominus wrote:
>Can I suggest the following delightful and foolproof solution to this
>problem?
>
> http://perl.plover.com/yak/flock/samples/slide006.html
Hmm... I can think of systems that refuse to flock files exclusively
when they're not opened for writing. Neither of the above examples
complies to that condition.
See paragraph 6 in
<http://www.perldoc.com/perl5.8.0/pod/func/flock.html>
Note that the fcntl(2) emulation of flock(3) requires that
FILEHANDLE be open with read intent to use LOCK_SH and requires
that it be open with write intent to use LOCK_EX.
--
Bart.
------------------------------
Date: 29 Oct 2003 14:28:20 -0800
From: rjohnson@shell.com (Roy Johnson)
Subject: Re: Singleton process
Message-Id: <3ee08638.0310291428.e8a9459@posting.google.com>
mjd@plover.com (Mark Jason Dominus) wrote in message news:<bnopno$7e7$1@plover.com>...
> Can I suggest the following delightful and foolproof solution to this
> problem?
>
> http://perl.plover.com/yak/flock/samples/slide006.html
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.
------------------------------
Date: Wed, 29 Oct 2003 20:49:35 -0000
From: "Richard Churchill" <rschurchill@freenet.co.uk>
Subject: Re: tie problem
Message-Id: <uKVnb.2301$lm1.12905@wards.force9.net>
"Ben Morrow" <usenet@morrow.me.uk> wrote in message
news:bnov85$kqk$1@wisteria.csv.warwick.ac.uk...
>
> rschurchill@freenet.co.uk (Richard) wrote:
> > I am writing a script which accesses a DBM file using SDBM. The
> > program works but throws out a warning of: -
> >
> > Argument "O_RDWR" isn't numeric in null operation
> >
> > I've included Fcntl but that doesn't solve the problem. Does anyone
> > know why this is happening?
>
> Try again like this:
>
> #!/usr/bin/perl
>
> use warnings;
> use strict;
>
> > use SDBM_File;
> > use Fcntl;
> >
> > tie (%DB, 'SDBM_File', "fund.dbm",O_RDWR, 0644) or die "Couldn't find
> > file\n";
>
> Don't put \n on the end: it suppresses useful information about where
> the error occurred.
>
> Do include $!.
>
> SDMB_File suggests you should usually use 0666 for the mode, as it is
> modified by the umask.
>
> > foreach $fund (keys %DB) {
> > print $fund;
> > }
> >
> > untie %DB;
>
> You should probably use
>
> untie %DB or die "failed to untie: $!";
>
> here, as well.
>
> If you get an error about O_RDWR, post again. 'use Fcntl' ought to
> define it.
>
> Ben
>
> --
> "If a book is worth reading when you are six, *
ben@morrow.me.uk
> it is worth reading when you are sixty." - C.S.Lewis
Thanks, my problem turned out to be something different. I was using this
code inside a package and declaring the modules outside of the package, for
some reason Fcntl was not picked up correctly, but SDBM was. Once they were
both declared inside the package the warning went away.
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.532 / Virus Database: 326 - Release Date: 27/10/2003
------------------------------
Date: Wed, 29 Oct 2003 20:11:09 -0000
From: "David K. Wall" <usenet@dwall.fastmail.fm>
Subject: Re: What am I doing wrong?!
Message-Id: <Xns94239A7A99659dkwwashere@216.168.3.30>
Tore Aursand <tore@aursand.no> wrote:
> Very C'ish, indeed. Let's do the same thing Perl'ish;
>
> open( ER, 'ALL_errors' ) or die "Couldn't open file; $!\n";
> my @entry = <ER>;
> close( ER );
> chomp( @entry );
>
> open( LOG, 'all.log' ) or die "Couldn't open file; $!\n";
> while my $cur ( <LOG> ) {
> chomp( $cur );
> foreach my $line ( @entry ) {
> print $cur if ( $cur =~ /$line/ );
> }
> }
> close( LOG );
That has far more parentheses than I would normally use. Are you sure
it isn't Lisp-ish? :-)
--
David Wall
------------------------------
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 5727
***************************************