[24510] in Perl-Users-Digest
Perl-Users Digest, Issue: 6690 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Jun 14 18:05:50 2004
Date: Mon, 14 Jun 2004 15:05:08 -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 Mon, 14 Jun 2004 Volume: 10 Number: 6690
Today's topics:
[Qs] re "Abigails Coding Guidelines" <jkrugman345@yahbitoo.com>
Re: [Qs] re "Abigails Coding Guidelines" <gnari@simnet.is>
Re: [Qs] re "Abigails Coding Guidelines" <usenet@morrow.me.uk>
Re: ActivePerl and Expect question <usenet@morrow.me.uk>
Re: definition of a "straight hash"? <gnari@simnet.is>
Howto capture interactive SQL*Plus session info on Win3 <wolfphaedrus@hotmail.com>
HTML::Parser not stripping out comments <boatingN.O.S.P.A.M@cox.net>
lib->unimport ??? <please_post@nomail.edu>
Re: lib->unimport ??? <pinyaj@rpi.edu>
More stupid strict tricks! <jkrugman345@yahbitoo.com>
Re: More stupid strict tricks! <bmb@ginger.libs.uga.edu>
Re: More stupid strict tricks! <ittyspam@yahoo.com>
Re: parsing file name assigning extension to a variable (Alexander Heimann)
Re: parsing file name assigning extension to a variable <ittyspam@yahoo.com>
Re: rearrange "columns" of a multi-level hash? <usenet@morrow.me.uk>
Re: rearrange "columns" of a multi-level hash? (hymie!)
Re: rearrange "columns" of a multi-level hash? <usenet@morrow.me.uk>
Re: redirect as POST with hidden fields <tadmc@augustmail.com>
Should build/install mung the #! line? <jkrugman345@yahbitoo.com>
Re: Should build/install mung the #! line? <usenet@morrow.me.uk>
Re: Taint mode and PERL5LIB <socyl@987jk.com>
Re: Taint mode and PERL5LIB <jkrugman345@yahbitoo.com>
Re: Taint mode and PERL5LIB <usenet@morrow.me.uk>
Re: Taint mode and PERL5LIB <usenet@morrow.me.uk>
What is best module for LDAP <r.hazeltine@uws.edu.au>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Mon, 14 Jun 2004 18:46:04 +0000 (UTC)
From: J Krugman <jkrugman345@yahbitoo.com>
Subject: [Qs] re "Abigails Coding Guidelines"
Message-Id: <cakrpc$d3u$1@reader2.panix.com>
[ This post appears to have gone to never-never land, so I'm
reposting; sorry for any repeats. ]
I recently came across "Abigails Coding Guidelines", at
http://perl.abigail.nl/Musings/coding_guidelines.html
which I found on the whole very interesting and instructive. But
some points (especially guideline 16) went over my head, or (like
guideline 3) prompted new questions, and I was hoping someone would
clue me in.
* Guideline 3 says "All system calls should be checked,
including, but not limited to, close, seek, flock, fork and exec."
Is there a comprehensive list of *all* of Perl's system calls?
* Guideline 5 says "Signals can be sent to the program. There are
default actions--but they are not always appropriate. If not,
signal handlers need to be installed. Care should be taken since
not everything is reentrant."
What does "reentrant" mean?
* In (15), "Subroutines in standalone modules SHOULD perform argument
checking and MUST NOT assume valid arguments are passed."
I'm not clear on why the Guidelines specify "standalone" modules.
What's are examples of standalone and non-standalone modules?
* Guideline (16) is this:
"Objects SHOULD NOT use data inheritance unless it is appropriate.
This means that 'normal' objects, where attributes are stored
inside anonymous hashes or arrays should not be used. Non-OO
programs benefit from namespaces and strictness, why shouldn't
objects? Use objects based on keying scalars, like fly-weight
objects, or inside-out objects. You wouldn't use public
attributes in Java all over the place either, would you?"
This one is 100% over my head! *Every word* of it. If someone
could spell it out for me I'd appreciate it. More specifically,
what is/are "keying scalars" (I can't tell whether "keying" here
is meant as a gerund or as an adjective)? What are fly-weight
objects and inside-out objects? And what do they have to do with
overusing public attributes in Java? Also, it is not clear to
me what's wrong with storing object attributes in anonymous hashes
or arrays, and in particular, it is not clear to me why using
them amounts to not benefiting from "namespaces and strictness."
Many thanks in advance,
jill
--
To s&e^n]d me m~a}i]l r%e*m?o\v[e bit from my a|d)d:r{e:s]s.
------------------------------
Date: Mon, 14 Jun 2004 19:43:56 -0000
From: "gnari" <gnari@simnet.is>
Subject: Re: [Qs] re "Abigails Coding Guidelines"
Message-Id: <cakv2d$l4v$1@news.simnet.is>
"J Krugman" <jkrugman345@yahbitoo.com> wrote in message
news:cakrpc$d3u$1@reader2.panix.com...
[about Abigails Coding Guidelines]
> * Guideline 5 says "Signals can be sent to the program. There are
> default actions--but they are not always appropriate. If not,
> signal handlers need to be installed. Care should be taken since
> not everything is reentrant."
>
> What does "reentrant" mean?
a bit of code is said to be reentrant when it can tolerate to be
entered again before finishing. if a new signal is sent to a program
while it is still processing a previous one, the signal handler needs
to be reentrant. example of non-reentrant behaviour is to store
critical temporary information in globals.
>
> * In (15), "Subroutines in standalone modules SHOULD perform argument
> checking and MUST NOT assume valid arguments are passed."
>
> I'm not clear on why the Guidelines specify "standalone" modules.
> What's are examples of standalone and non-standalone modules?
my guess is that non-"standalone" modules are modules that are only
written to support a particular program (or set of programs), and
are typically distributed with them.
"standalone" modules are modules intended to be used with any
program. CPAN modules are typically "standalone". example of
non-standalone modules *might* be the DBD modules, that only expect
to be called by DBI and may perform less strict tests on some arguments.
>
> * Guideline (16) is this:
>
> "Objects SHOULD NOT use data inheritance unless it is appropriate.
> Also, it is not clear to
> me what's wrong with storing object attributes in anonymous hashes
> or arrays, and in particular, it is not clear to me why using
> them amounts to not benefiting from "namespaces and strictness."
one part of OO programming is encapsulation. in perl, if a class inherits
data from a parent class, it's author needs to make sure any new attributes
do not clash with "private" attributes of any ancestors. thus they are not
really private, and no namespace benefits exist.
gnari
------------------------------
Date: Mon, 14 Jun 2004 20:12:37 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: [Qs] re "Abigails Coding Guidelines"
Message-Id: <cal0rl$p3s$1@wisteria.csv.warwick.ac.uk>
Quoth J Krugman <jkrugman345@yahbitoo.com>:
>
>
> [ This post appears to have gone to never-never land, so I'm
> reposting; sorry for any repeats. ]
>
> I recently came across "Abigails Coding Guidelines", at
>
> http://perl.abigail.nl/Musings/coding_guidelines.html
>
> which I found on the whole very interesting and instructive. But
> some points (especially guideline 16) went over my head, or (like
> guideline 3) prompted new questions, and I was hoping someone would
> clue me in.
>
> * Guideline 3 says "All system calls should be checked,
> including, but not limited to, close, seek, flock, fork and exec."
>
> Is there a comprehensive list of *all* of Perl's system calls?
System calls are a function of your operating system, not Perl. On a
unix-like system, you can check the contents of section 2 of the
manpages.
Having said that, a syscall is how you communicate with the world
outside your process; so any function in perlfunc that does more than
manipulate data makes a syscall.
> * Guideline 5 says "Signals can be sent to the program. There are
> default actions--but they are not always appropriate. If not,
> signal handlers need to be installed. Care should be taken since
> not everything is reentrant."
>
> What does "reentrant" mean?
Reentrant means that a piece of code can stand being executed twice at
the same time. Basically code is non-reentrant if it uses global
resources without locking them, so this:
our ($subref, $string);
# call with a subref to call and a string to print
sub call_and_print {
($subref, $string) = @_;
$subref->();
print $string;
}
is not reentrant, as if you write
call_and_print \&call_and_print, 'hello world'
the second copy of the sub will stomp on the global, and the data to
print will no longer be there. This is obviously contrived: it is hard
to make code non-reentrant in Perl.
C is a quite different matter, though, and perl-the-C-program makes
extensive use of global variables. It used to be the case that signal
handlers you installed in Perl would run as soon as the signal arrived,
when perl might well be halfway through running a particular opcode. As
the guts of perl are not reentrant, this could mess things up; the
chances of this were much much higher if you did anything more
complicated in a signal handler than setting a variable which already
had a value.
Since 5.8 this has been fixed, as the C signal handler simply makes a
note that perl should call the Perl signal handler as soon as everything
is in a consistent state and it is safe to do so.
> * In (15), "Subroutines in standalone modules SHOULD perform argument
> checking and MUST NOT assume valid arguments are passed."
>
> I'm not clear on why the Guidelines specify "standalone" modules.
> What's are examples of standalone and non-standalone modules?
An example of a non-standalone module is Carp::Heavy: it has notices on
it saying it is only to be used through the interface of Carp, so it can
safely assume that Carp has set everything up correctly where this is
helpful.
> * Guideline (16) is this:
>
> "Objects SHOULD NOT use data inheritance unless it is appropriate.
>
> This means that 'normal' objects, where attributes are stored
> inside anonymous hashes or arrays should not be used. Non-OO
> programs benefit from namespaces and strictness, why shouldn't
> objects? Use objects based on keying scalars, like fly-weight
> objects, or inside-out objects. You wouldn't use public
> attributes in Java all over the place either, would you?"
>
> This one is 100% over my head! *Every word* of it. If someone
> could spell it out for me I'd appreciate it. More specifically,
> what is/are "keying scalars" (I can't tell whether "keying" here
> is meant as a gerund or as an adjective)? What are fly-weight
> objects and inside-out objects? And what do they have to do with
> overusing public attributes in Java? Also, it is not clear to
> me what's wrong with storing object attributes in anonymous hashes
> or arrays, and in particular, it is not clear to me why using
> them amounts to not benefiting from "namespaces and strictness."
As to the problem, consider your typical Perl object: it is a blessed
hashref, with data stored in the hash. The trouble with this is that
subclasses need to know both that it is a hashref and what keys in the
hash the parent object has used, so that they don't stomp on the parents
data. The first violates encapsulation (it should be possible to change
any aspect of the implementation without anything breaking); the second
is exactly the same problem as making all your variables global, which
Perl deals with with packages (namespaces) and 'use strict'.
As to the solutions, I have to say that the more advanced forms of Perl
OO are way over my head too...
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: Mon, 14 Jun 2004 18:46:33 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: ActivePerl and Expect question
Message-Id: <cakrq9$krh$1@wisteria.csv.warwick.ac.uk>
Quoth dipakprasad@hotmail.com (Dipak Prasad):
>
> I had done some Expect/Tcl scripting a long time ago, and for this
> current requirement it appeared that if a similar extension was
> available for Perl I can achieve what I wanted to do. I did some
> digging around and came across the Expect.pm module, but found out it
> was incompatible with ActivePerl.
> In essence, I am looking to get the Expect/Tcl behavior within
> ActivePerl.
This will be difficult: win32 doesn't have ptys, which are usually
necessary to get programs to behave as though they're talking to a user.
If the programs you want to talk to will (can be made to) behave, you
could perhaps download Expect.pm and edit Expect::new and Expect::spawn
to start processes on pipes or sockets instead of ptys; you could rename
it to Expect::Win32 or so and install it in your perl tree by hand.
You might perhaps have luck with cygwin (and perl built for cygwin), but
if the programs you're trying to talk to are native win32 then I suspect
that however cygwin fakes ptys won't work with them.
As a very final resort, if you must get this working, you could start
the windows telnet server and use Net::Telnet, maybe with a gutted
version of Expect.
Ben
--
"The Earth is degenerating these days. Bribery and corruption abound.
Children no longer mind their parents, every man wants to write a book,
and it is evident that the end of the world is fast approaching."
-Assyrian stone tablet, c.2800 BC ben@morrow.me.uk
------------------------------
Date: Mon, 14 Jun 2004 19:20:12 -0000
From: "gnari" <gnari@simnet.is>
Subject: Re: definition of a "straight hash"?
Message-Id: <caktls$l1g$1@news.simnet.is>
"John Davis" <tudmuf2b@onebox.com> wrote in message
news:7167a8d.0406140645.7be83377@posting.google.com...
> I was looking at some of the posts and was a little confused on that
> term. What exactly is a straight hash? I've tried doing a search for
> it but came up empty. Is that just an ordinary associative array or is
> something special with references, etc...
I googled for the term in clpm and came up with 3 references.
2 of them were discussing the use of exists() as opposed to
a straight hash expression/access. here 'straight' applies
to 'expression' or 'access', not to 'hash'. in other words:
straight (hash expression), not (straight hash) expression.
the third post was discussing refhash versus straight hash,
i.e.: $foo{bar} vs $foo->{bar}
i do not think 'straight hash' has any particular meaning out
of context.
gnari
------------------------------
Date: Mon, 14 Jun 2004 22:16:39 +0100
From: "James" <wolfphaedrus@hotmail.com>
Subject: Howto capture interactive SQL*Plus session info on Win32?
Message-Id: <mAozc.97273$wd7.58990@front-1.news.blueyonder.co.uk>
Hi All,
I am trying to capture the output of an Oracle SQL*Plus session into
an array but can't find any examples; specifically o retrieve a list of
tablespaces. I can get it to log on and run the script but capturing it is
a different game entirely. I realise Perl has its own native Oracle DBD
module but that won't compile with Perl2exe(at least I can't work out how
to). I can have Perl call SQL*Plus with an external script but I'm trying
to do without loads of temp sql files. Is this even possible or is a major
rethink in order?
Thanks in advance for any hints
James
------------------------------
Date: Mon, 14 Jun 2004 15:20:32 -0400
From: "Jay" <boatingN.O.S.P.A.M@cox.net>
Subject: HTML::Parser not stripping out comments
Message-Id: <ARmzc.20666$Qv1.5290@lakeread03>
I'm trying to get HTML::Parser to strip out the comments using some of the
sample code from the man page. I'm using the ignore_elements and I still
get comments in the dtext. Am I doing something wrong?
Tia,
Jay
CODE:
use HTML::Parser ();
# Create parser object
$p = HTML::Parser->new( api_version => 3,
start_h => [\&start, "tagname, attr"],
end_h => [\&end, "tagname"],
comment_h => [\&comment, "self,text"],
text_h => [\&dtext, "self,text"],
marked_sections => 1,
);
$p->ignore_elements( qw(script, comment, style) );
$p->strict_comment( [1] );
# Parse directly from file
$p->parse_file("0");
sub start {
my($self, $tagname, $attr, $attrseq, $origtext) = @_;
#...
}
sub end {
my($self, $tagname, $origtext) = @_;
#...
}
sub text {
my($self, $origtext, $is_cdata) = @_;
#...
}
sub comment{
#my($self, $origtext, $is_cdata) = @_;
#...
}
sub dtext {
my($self, $dtext ) = @_;
$dtext=~s/\s+/ /g;
print "DTEXT: $dtext\n";
}
Example of some of the output from parsing some web page:
DTEXT: <!-- /* You may give each page an identifying name, server, and
channel on the next lines. */ var s_pageName="buy"; var s_server="CWEB15";
var s_channel="buy"; var s_pageTyp
e=""; var s_prop1="Autoweb Direct to Site"; var s_prop2="Autoweb Direct to
Site 10714"; var s_prop3=""; var s_prop4=""; var s_prop5=""; var s_prop6="";
var s_prop7="buy|"; var s_pr
op8=""; var s_prop9="buy|Autoweb Direct to Site|10714"; var s_prop10="buy|";
var s_prop11="Autoweb Direct to Site|10714|taweb"; var s_prop12="||"; var
s_prop13="||||||buy||No"; var
s_prop14="Autoweb Direct to Site|10714|taweb|||||buy||No"; var s_prop15="No
Article|No Article"; var s_prop16=""; var s_prop17=""; var s_prop18="Autoweb
Direct to Site|10714|buy";
var s_prop19="Autoweb Direct to Site|10714||buy"; var
s_prop20="buy||||sky|ban|Autoweb Direct to Site"; /* E-commerce Variables */
var s_campaign="10714"; var s_state=""; var s_zi
p=""; var s_events=""; var s_products=""; var s_purchaseID=""; var
s_eVar1="Autoweb Direct to Site"; var s_eVar2="Autoweb Direct to Site
10714"; var s_eVar3="NT-sky-ban"; var s_eVa
r4=""; var s_eVar5=""; /********* INSERT THE DOMAIN AND PATH TO YOUR CODE
BELOW ************/ /********** DO NOT ALTER ANYTHING ELSE BELOW THIS LINE!
*************/ var s_code=' '/
/-->
DTEXT:
DTEXT:
------------------------------
Date: Sat, 12 Jun 2004 15:51:42 +0000 (UTC)
From: bill <please_post@nomail.edu>
Subject: lib->unimport ???
Message-Id: <caf8qe$kkb$1@reader2.panix.com>
The version of lib.pm installed in our system includes a definition
for a sub called unimport. It is not used elsewhere in lib.pm,
and it is not mentioned in the POD for lib. Also 'perldoc -f
unimport' turns up nothing (same for 'perldoc -q unimport' for that
matter). So why does lib define unimport at all? I became aware
of it when I found "lib->unimport" while reading some fairly eminent
module's source, from CPAN. The author of this module has produced
some very widely used modules, so I don't think this person would,
without good reason, break the precept of never going outside the
published API.
So, what's the official status of lib->unimport ? Should it be
regarded as if it were part of lib's published API?
And what about unimporting other modules besides lib?
-bill
------------------------------
Date: Mon, 14 Jun 2004 15:30:26 -0400
From: Jeff 'japhy' Pinyan <pinyaj@rpi.edu>
Subject: Re: lib->unimport ???
Message-Id: <Pine.SGI.3.96.1040614152736.292900B-100000@vcmr-64.server.rpi.edu>
On Sat, 12 Jun 2004, bill wrote:
>The version of lib.pm installed in our system includes a definition
>for a sub called unimport. It is not used elsewhere in lib.pm,
>and it is not mentioned in the POD for lib. Also 'perldoc -f
>unimport' turns up nothing (same for 'perldoc -q unimport' for that
>matter). So why does lib define unimport at all? I became aware
>of it when I found "lib->unimport" while reading some fairly eminent
>module's source, from CPAN. The author of this module has produced
>some very widely used modules, so I don't think this person would,
>without good reason, break the precept of never going outside the
>published API.
'unimport' is the method called when you write
no Module;
just like 'import' is the method called when you write
use Module;
See 'perldoc -f use' for more information.
--
Jeff Pinyan RPI Acacia Brother #734 RPI Acacia Corp Secretary
"And I vos head of Gestapo for ten | Michael Palin (as Heinrich Bimmler)
years. Ah! Five years! Nein! No! | in: The North Minehead Bye-Election
Oh. Was NOT head of Gestapo AT ALL!" | (Monty Python's Flying Circus)
------------------------------
Date: Sat, 12 Jun 2004 12:53:53 +0000 (UTC)
From: J Krugman <jkrugman345@yahbitoo.com>
Subject: More stupid strict tricks!
Message-Id: <caeud1$hoi$1@reader2.panix.com>
Here's one more strict kink in the bug/feature duality manifold
(see also http://tinyurl.com/32blm ).
Apparently starting a variable's name with ^ cloaks it from strict:
use strict;
use warnings;
${^SNEAK} = "LOOK MA NO HANDS!!!\n";
print ${^SNEAK};
exit 0;
__END__
% perl stupid_strict_tricks.pl
LOOK MA NO HANDS!!!
Hmmmm... Is this "feature" documented anywhere? I was not able
to find mention of it in the strict manpage.
jill
--
To s&e^n]d me m~a}i]l r%e*m?o\v[e bit from my a|d)d:r{e:s]s.
------------------------------
Date: Mon, 14 Jun 2004 14:26:10 -0400
From: Brad Baxter <bmb@ginger.libs.uga.edu>
Subject: Re: More stupid strict tricks!
Message-Id: <Pine.A41.4.58.0406141423460.43176@ginger.libs.uga.edu>
On Sat, 12 Jun 2004, J Krugman wrote:
>
> Apparently starting a variable's name with ^ cloaks it from strict:
>
> use strict;
> use warnings;
>
> ${^SNEAK} = "LOOK MA NO HANDS!!!\n";
>
> print ${^SNEAK};
>
> exit 0;
> __END__
>
>
> % perl stupid_strict_tricks.pl
> LOOK MA NO HANDS!!!
>
> Hmmmm... Is this "feature" documented anywhere? I was not able
> to find mention of it in the strict manpage.
In perlvar:
In particular, the new special "${^_XYZ}" variables are
always taken to be in package "main", regardless of any
"package" declarations presently in scope.
I didn't notice explicit reference to cloaking it from strict, but I
suspect that's the expected behavior.
Regards,
Brad
------------------------------
Date: Mon, 14 Jun 2004 14:34:20 -0400
From: Paul Lalli <ittyspam@yahoo.com>
Subject: Re: More stupid strict tricks!
Message-Id: <20040614142954.H20623@dishwasher.cs.rpi.edu>
On Sat, 12 Jun 2004, J Krugman wrote:
> Here's one more strict kink in the bug/feature duality manifold
> (see also http://tinyurl.com/32blm ).
>
> Apparently starting a variable's name with ^ cloaks it from strict:
>
> use strict;
> use warnings;
>
> ${^SNEAK} = "LOOK MA NO HANDS!!!\n";
>
> print ${^SNEAK};
>
> exit 0;
> __END__
>
>
> % perl stupid_strict_tricks.pl
> LOOK MA NO HANDS!!!
>
> Hmmmm... Is this "feature" documented anywhere? I was not able
> to find mention of it in the strict manpage.
perldoc perlvar
Finally, new in Perl 5.6, Perl variable names may be
alphanumeric strings that begin with control characters (or
better yet, a caret). These variables must be written in
the form "${^Foo}"; the braces are not optional. "${^Foo}"
denotes the scalar variable whose name is a control-"F"
followed by two "o"'s. These variables are reserved for
future special uses by Perl, except for the ones that begin
with "^_" (control-underscore or caret-underscore). No
control-character name that begins with "^_" will acquire a
special meaning in any future version of Perl; such names
may therefore be used safely in programs. $^_ itself,
however, is reserved.
Perl identifiers that begin with digits, control characters,
or punctuation characters are exempt from the effects of the
"package" declaration and are always forced to be in package
"main". A few other names are also exempt:
ENV STDIN
INC STDOUT
ARGV STDERR
ARGVOUT
SIG
In particular, the new special "${^_XYZ}" variables are
always taken to be in package "main", regardless of any
"package" declarations presently in scope.
Since the variable in question is automatically defined as belonging to
package main, it's equivalent of putting something like this in your
program:
$main::sneak = 'Look Ma no hands!';
which is also allowed by strict.
Paul Lalli
------------------------------
Date: 14 Jun 2004 13:35:37 -0700
From: AlexanderHeimann@yahoo.com (Alexander Heimann)
Subject: Re: parsing file name assigning extension to a variable
Message-Id: <1c63154d.0406141235.9a724bb@posting.google.com>
maybe someone can tell me why I am unable to read the file when i do
each step individually it was working but i am having trouble putting
it all together..
use File::Basename;
fileparse_set_fstype("MSDOS");
opendir (DIR, "D:/D2") or die "couldn't open directory\n";
while (defined($file = readdir(DIR))) {
($name, $dir, $ext) = fileparse($file, '\..*');
$ext =~s/^\.//;
print " dir is $dir, name is $name, extension is $ext\n";
my $input;
open($input, "<", "$file")
#or die "Couldn't open file :!\n";
while(<$input>){
undef $/;
$content = <INPUT>;
print if /of/;
print $content;
}
close($input);
}
closedir DIR;
------------------------------
Date: Mon, 14 Jun 2004 16:43:05 -0400
From: Paul Lalli <ittyspam@yahoo.com>
Subject: Re: parsing file name assigning extension to a variable
Message-Id: <20040614164134.T20623@dishwasher.cs.rpi.edu>
On Mon, 14 Jun 2004, Alexander Heimann wrote:
> maybe someone can tell me why I am unable to read the file when i do
> each step individually it was working but i am having trouble putting
> it all together..
You've left off at least two vital pieces of information, necessary for
anyone to effectively help you:
1) What is your desired goal and/or output?
2) What is the result / output of the code you tried? (this includes all
errors and warnings that may be printed).
Paul Lalli
>
>
> use File::Basename;
> fileparse_set_fstype("MSDOS");
>
>
> opendir (DIR, "D:/D2") or die "couldn't open directory\n";
> while (defined($file = readdir(DIR))) {
>
>
>
> ($name, $dir, $ext) = fileparse($file, '\..*');
> $ext =~s/^\.//;
> print " dir is $dir, name is $name, extension is $ext\n";
>
> my $input;
> open($input, "<", "$file")
> #or die "Couldn't open file :!\n";
> while(<$input>){
> undef $/;
> $content = <INPUT>;
> print if /of/;
>
> print $content;
>
>
> }
> close($input);
>
>
>
>
>
>
>
> }
>
>
> closedir DIR;
>
------------------------------
Date: Mon, 14 Jun 2004 18:32:20 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: rearrange "columns" of a multi-level hash?
Message-Id: <cakqvk$j8k$1@wisteria.csv.warwick.ac.uk>
Quoth Ben Morrow <usenet@morrow.me.uk>:
>
> This is a mess :). I would recast it with a dispatch table (untested)...:
>
> my %no;
>
> sub do_keys {
> my $ivalue = shift;
^
...but without a typo (yes, I use vim) :).
> my $action = shift;
>
> if ('HASH' eq ref $value) {
[...]
>
> Quoth hymie@lactose.smart.net (hymie!):
> >
> > What I want to know is if there is
> > (*) an easier way to re-arrange the first hash (visualize taking a column
> > in a spreadsheet and moving it over, then resorting with the new
> > column order)?
>
> The obvious, though maybe not the most efficient, way is to unwrap it
> into a big list of records and wrap it up again:
...except there's no need to actually build the list.
> # old order: customer type product appno vendor
> # new order: customer vendor type product appno
>
> my %new_list;
>
> # customer is still first, so we can leave that
>
> for my $cust (keys %list) {
>
> my @records;
We don't need this temp array.
> my %me;
>
> do_keys $list{$cust},
> sub { $me{type} = $_[0] },
> sub { $me{prod} = $_[0] },
> sub { $me{appn} = $_[0] },
> sub { $me{vend} = $_[0] },
> sub { push @records, { %me, code => $_[0] } }
Gah! another typo... clearly not concentrating :(.
Anyway, this last should have been:
sub {
$new_list{ $cust }
{ $me{vend} }
{ $me{type} }
{ $me{prod} }
{ $me{appn} } = $_[0];
};
> for (@records) {
...and then we don't need to loop over the data a second time.
Ben
--
perl -e'print map {/.(.)/s} sort unpack "a2"x26, pack "N"x13,
qw/1632265075 1651865445 1685354798 1696626283 1752131169 1769237618
1801808488 1830841936 1886550130 1914728293 1936225377 1969451372
2047502190/' # ben@morrow.me.uk
------------------------------
Date: Mon, 14 Jun 2004 18:59:11 -0000
From: hymie@lactose.smart.net (hymie!)
Subject: Re: rearrange "columns" of a multi-level hash?
Message-Id: <10crtbv3trt3b1e@corp.supernews.com>
In our last episode, the evil Dr. Lacto had captured our hero,
Ben Morrow <usenet@morrow.me.uk>, who said:
>
>Quoth hymie@lactose.smart.net (hymie!):
>>
>> Co-worker wrote the script with (I don't know the correct term) a multi-
>> level hash:
>
>That term'll do fine... some people here use HoH, for Hash-of-Hash.
>Also, a hash key that doesn't exist will return
>a value of undef, which is zero in numeric context (with a warning you
>can turn off)...
Excellent. That was one of my fears. :)
>...so this whole lot can be replaced with the one line
>
>$list{$customer}{$type}{$productCode}{$appNo}{$vendor}{$returnCode} = 1
> if grep $_ == $returnCode, qw/130 150 385/;
>
>If you need the keys of the last hash to be right, or you specifically
>need the zeros, you could do
I don't specifically need the zeros as long as (like you said) an
undefined hash will return 0.
>Why is the data stored like this at all? Surely it would be better to
>store the return code straight in the hash, rather than have another
>level with only one (significant) value?
Because a single set of customer-type-productcode-appno-vendor may have
more than one return code, and I need to track all of them that appear.
But I'll probaby switch it something like
$list{$customer}...{$vendor} .= "$returnCode:"
if grep $_ == $returnCode, qw/130 150 385/;
and then I can m// through the values later.
>Also, what happens if the return code *isn't* in the list?
Then I can ignore that entire line of data.
>> foreach $customer ( keys(%list) )
>
>This is not sorted. Did you simply mean 'grouped by', or should it be
Sorting isn't required.
>> {
>> print "Customer: $customer\n\n" ;
>> foreach $type ( keys(%{$list{ $customer }}) )
>> {
>> printf "\n Type: %s", $type ;
>
>Don't use printf when interpolation will do.
Oops. Oversight.
>This should be a hash. Variables with systematically similar names
>nearly always should be.
>
> $no{385}++;
It's actually a little more complicated than that, but the hash is still
a good idea.
>This is a mess :). I would recast it with a dispatch table (untested):
I apprecite the table, but this is probably beyond my ability to
maintain and troubleshoot. But it's a great idea and, if nothing else,
a learning exercise.
>> What I want to know is if there is
>> (*) an easier way to re-arrange the first hash (visualize taking a column
>> in a spreadsheet and moving it over, then resorting with the new
>> column order)?
>
>The obvious, though maybe not the most efficient, way is to unwrap it
>into a big list of records and wrap it up again:
No, but somewhere along the line, you gave me an idea -- in short, when
I process
$list{$cust}{$type}{$prod}{$appno}{$vend}
I can create
$list2{$cust}{$vend}{$type}{$prod}{$appno}
> Razors pain you / Rivers are damp
> Acids stain you / And drugs cause cramp.
> Guns aren't lawful / Nooses give
> Gas smells awful / You might as well live.
Ooh! I'd been looking for that poem. Thank you.
hymie! http://www.smart.net/~hymowitz hymie@lactose.smart.net
===============================================================================
------------------------------
Date: Mon, 14 Jun 2004 20:38:53 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: rearrange "columns" of a multi-level hash?
Message-Id: <cal2ct$q9q$1@wisteria.csv.warwick.ac.uk>
Quoth hymie@lactose.smart.net (hymie!):
> In our last episode, the evil Dr. Lacto had captured our hero,
> Ben Morrow <usenet@morrow.me.uk>, who said:
> >
> >Why is the data stored like this at all? Surely it would be better to
> >store the return code straight in the hash, rather than have another
> >level with only one (significant) value?
>
> Because a single set of customer-type-productcode-appno-vendor may have
> more than one return code, and I need to track all of them that appear.
>
> But I'll probaby switch it something like
> $list{$customer}...{$vendor} .= "$returnCode:"
> if grep $_ == $returnCode, qw/130 150 385/;
> and then I can m// through the values later.
Oooh, no, that's very shell :).
Use an array:
push @{ $list{...} }, $returnCode if ...;
Ben
--
perl -e'print map {/.(.)/s} sort unpack "a2"x26, pack "N"x13,
qw/1632265075 1651865445 1685354798 1696626283 1752131169 1769237618
1801808488 1830841936 1886550130 1914728293 1936225377 1969451372
2047502190/' # ben@morrow.me.uk
------------------------------
Date: Mon, 14 Jun 2004 16:19:09 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: redirect as POST with hidden fields
Message-Id: <slrnccs5id.cdk.tadmc@magna.augustmail.com>
Radek G. <rgasiore@wp.pl> wrote:
> better you avoid help like this -
> helpless.
So when you asked for "any suggestions", you didn't really mean it?
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Mon, 14 Jun 2004 19:26:19 +0000 (UTC)
From: J Krugman <jkrugman345@yahbitoo.com>
Subject: Should build/install mung the #! line?
Message-Id: <caku4r$drl$1@reader2.panix.com>
When a distribution includes executable scripts, should the
build/install procedure mung the first (#!) line of these scripts,
to make sure they match the path to perl in the local system? Or
should this problem be handled by including appropriate manual
configuration instructions in a README or INSTALL file? Is there
a "standard practice" for this?
TIA,
jill
--
To s&e^n]d me m~a}i]l r%e*m?o\v[e bit from my a|d)d:r{e:s]s.
------------------------------
Date: Mon, 14 Jun 2004 20:43:43 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: Should build/install mung the #! line?
Message-Id: <cal2lv$q9q$2@wisteria.csv.warwick.ac.uk>
Quoth J Krugman <jkrugman345@yahbitoo.com>:
>
>
> When a distribution includes executable scripts, should the
> build/install procedure mung the first (#!) line of these scripts,
> to make sure they match the path to perl in the local system? Or
> should this problem be handled by including appropriate manual
> configuration instructions in a README or INSTALL file? Is there
> a "standard practice" for this?
perldoc ExtUtils::MakeMaker:
| EXE_FILES
| Ref to array of executable files. The files will be copied to the
| INST_SCRIPT directory. Make realclean will delete them from there
| again.
|
| If your executables start with something like #!perl or
| #!/usr/bin/perl MakeMaker will change this to the path of the perl
| Makefile.PL was invoked with so the programs will be sure to run
| properly even if perl is not in /usr/bin/perl.
Ben
--
Lie all men in Babylon I have been a proconsul; like all, a slave ... During
one lunar year, I have been declared invisible; I shrieked and was not heard,
I stole my bread and was not decapitated.
~ ben@morrow.me.uk ~ Jorge Luis Borges, 'The Babylon Lottery'
------------------------------
Date: Sat, 12 Jun 2004 11:35:57 +0000 (UTC)
From: kj <socyl@987jk.com>
Subject: Re: Taint mode and PERL5LIB
Message-Id: <caepqs$gk6$1@reader2.panix.com>
In <cadebt$d8u$1@wisteria.csv.warwick.ac.uk> Ben Morrow <usenet@morrow.me.uk> writes:
>Quoth kj <socyl@987jk.com>:
>>
>> When running under taint mode (-T switch), $ENV{PERL5LIB} is ignored.
>> This presents a problem to CGI scripts that want to run in taint
>> mode but need libraries installed in directories not mentioned in
>> the default value of @INC [1].
>>
>> Then again, is running under taint mode really necessary past the
>> development and testing phase? In other words, is taint mode
>> anything more than an additional check that the developer can make
>> prior to releasing the code to make sure that there are no security
>> gaps in the code, but once the code passes, taint mode can be safely
>> turned off?
>No.
>> [1] I realize that I could add appropriate "use lib /path/to/my/libs"
>> lines to the CGI scripts, but at installation time this is a royal
>> pain, especially if many CGI scripts are involved, since every user
>> installing this software would have to mung these lines in all its
>> CGI scripts. At the very least, make would have to do the munging,
>> which gives me the creeps; I'd prefer to find some other solution.
>I am presuming you are looking for a solution you can write into new
>scripts, rather than one which will work with existing ones?
>At the start of each script, examine $ENV{PERL5LIB}, untaint it, check
>that its value looks like a reasonable Perl library dir, etc., split it
>on colons and 'use lib'.
If that's all there is to it, then I don't see why Perl should
disregard PERL5LIB when running under taint mode, instead of just
doing what you say above, and using PERL5LIB as usual if it checks
out.
>You can (obviously) put all this in a module,
>so you can just say something like
>use MyApp::Perl5Lib;
>at the top of each individual script.
Wouldn't this strategy fail precisely due to the problem it is
trying to solve (how would Perl be able to load MyApp/Perl5Lib.pm
unless it was already in a directory mentioned in the default @INC)?
kj
--
NOTE: In my address everything before the period is backwards.
------------------------------
Date: Sat, 12 Jun 2004 15:16:29 +0000 (UTC)
From: J Krugman <jkrugman345@yahbitoo.com>
Subject: Re: Taint mode and PERL5LIB
Message-Id: <caf6od$jsh$1@reader2.panix.com>
In <caf3h3$gp8$1@mamenchi.zrz.TU-Berlin.DE> anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) writes:
>Gunnar Strand <MyFirstnameHere.News1@gustra.org> wrote in comp.lang.perl.misc:
>> Ben Morrow wrote:
>> > Quoth kj <socyl@987jk.com>:
>> >
>> >>When running under taint mode (-T switch), $ENV{PERL5LIB} is ignored.
>> >>This presents a problem to CGI scripts that want to run in taint
>> >>mode but need libraries installed in directories not mentioned in
>> >>the default value of @INC [1].
>> >>
>> >>Then again, is running under taint mode really necessary past the
>> >>development and testing phase? In other words, is taint mode
>> >>anything more than an additional check that the developer can make
>> >>prior to releasing the code to make sure that there are no security
>> >>gaps in the code, but once the code passes, taint mode can be safely
>> >>turned off?
>> >
>> >
>> > No.
>>
>> That is interesting. According to the Perl taint faq i found
>> (http://gunther.web66.com/FAQS/taintmode.html):
>>
>> Run-time checking means that you need to test all logical paths of
>> execution your script might take so that "legal operations" do not
>> get halted because of taint mode.
>>
>> I get the impression that if the testing is thorough enough, taint
>> mode could be turned off for release code. I do *not* argue that
>> it *should* be turned off, I am just curious to know if there are
>> situations after testing which could cause taint to fail, for
>> instance that it would object to the contents of input, despite
>> untainting?
>Well, for one, there is more than tainted data that may make a taint
>test fail. If $ENV{ PATH} points to something that is writable by
>anyone but its owner, you can launder the string all day but "system"
>and friends will fail in taint mode. That is one test that can only
>be done at run time, there are certainly more.
>But even if without run time tests, for a complete cover of all cases
>you'd have to determine the set of all variables in your program
>whose taintedness may matter (including parts of %ENV) and check the
>behavior for every combination of tainted/untainted there is.
>A look at the long section (in perlsec) that lists which Perl functions
>may be taint-sensitive and in which way is discouraging.
>So, taint mode must stay on in production, for fundamental and
>practical reasons.
Still it is not clear to me why Perl doesn't offer a builtin function
or a standard module to untaint PERL5LIB. I found an interesting
and not too ancient thread on this at http://tinyurl.com/yr4vs .
There is a module called perl5lib in CPAN that does the job, but
I think it should be part of the distribution. (BTW, is there a
standard channel for requesting adding a feature to future releases
of Perl?)
jill
--
To s&e^n]d me m~a}i]l r%e*m?o\v[e bit from my a|d)d:r{e:s]s.
------------------------------
Date: Mon, 14 Jun 2004 20:20:20 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: Taint mode and PERL5LIB
Message-Id: <cal1a4$p3s$2@wisteria.csv.warwick.ac.uk>
Quoth J Krugman <jkrugman345@yahbitoo.com>:
>
> Still it is not clear to me why Perl doesn't offer a builtin function
> or a standard module to untaint PERL5LIB.
Builtin??? Come off it... that's way too specific :). Look at
Scalar::Util: those are things that *failed* to become builtins.
A standard module is a possibility, but the usage would not be high.
Apart from anything else, the conditions under which a given value of
PERL5LIB is safe vary hugely from situation to situation. OTOH it is a
tiny module, and it might make people's lives easier on webhosts who'll
only install the standard distro.
> There is a module called perl5lib in CPAN that does the job, but
> I think it should be part of the distribution. (BTW, is there a
> standard channel for requesting adding a feature to future releases
> of Perl?)
perl5-porters@perl.org
Ben
--
I must not fear. Fear is the mind-killer. I will face my fear and
I will let it pass through me. When the fear is gone there will be
nothing. Only I will remain.
ben@morrow.me.uk Frank Herbert, 'Dune'
------------------------------
Date: Mon, 14 Jun 2004 20:24:17 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: Taint mode and PERL5LIB
Message-Id: <cal1hh$p3s$3@wisteria.csv.warwick.ac.uk>
Quoth kj <socyl@987jk.com>:
> In <cadebt$d8u$1@wisteria.csv.warwick.ac.uk> Ben Morrow <usenet@morrow.me.uk> writes:
>
> >At the start of each script, examine $ENV{PERL5LIB}, untaint it, check
> >that its value looks like a reasonable Perl library dir, etc., split it
> >on colons and 'use lib'.
>
> If that's all there is to it, then I don't see why Perl should
> disregard PERL5LIB when running under taint mode, instead of just
> doing what you say above, and using PERL5LIB as usual if it checks
> out.
*THINK*. How can Perl possibly know what is safe and what isn't? It
depends entirely on the situation. That's the whole point of taint mode:
perl forces you to check things are safe, because it can't check for
you.
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: Tue, 15 Jun 2004 07:41:45 +1000
From: Robert Hazeltine <r.hazeltine@uws.edu.au>
Subject: What is best module for LDAP
Message-Id: <Pine.GSO.4.40.0406150738160.29087-100000@isis.virago.org.au>
Hi
Any suggestions as to the best choice of a module for LDAP. A quick look
though CPAN indicates that some of the packages are a couple of years
old, but they still look good in that they support LDAPv3.
Rob
------------------------------
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.
NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice.
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 6690
***************************************