[14042] in Perl-Users-Digest
Perl-Users Digest, Issue: 1452 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Nov 22 00:11:56 1999
Date: Sun, 21 Nov 1999 21:10:55 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <943247455-v9-i1452@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Sun, 21 Nov 1999 Volume: 9 Number: 1452
Today's topics:
Re: Encryption Algorithm for Perl Source Code?? jut@letterbox.com
Re: Encryption Algorithm for Perl Source Code?? jut@letterbox.com
Re: Encryption Algorithm for Perl Source Code?? <kbandes@home.com>
Re: Encryption Algorithm for Perl Source Code?? (Matthew Bafford)
Re: environment vars <cassell@mail.cor.epa.gov>
Re: environment vars (Martien Verbruggen)
Escape Character/CGI Script Trouble <rydaron@sonic.net>
Escape Character/CGI Script Trouble <rydaron@sonic.net>
Re: Escape Character/CGI Script Trouble <tony_curtis32@yahoo.com>
Re: Escape Character/CGI Script Trouble <flavell@mail.cern.ch>
Re: Escape Character/CGI Script Trouble <cassell@mail.cor.epa.gov>
Re: Getting HTML tags via regular expression <kbandes@home.com>
Re: Help -Mod-perl Configuration <cassell@mail.cor.epa.gov>
Re: Help With CyberCash.... (brian d foy)
Re: How do I take all of the email addresses out of an <aqumsieh@matrox.com>
Re: How do I take all of the email addresses out of an (Simon Cozens)
Re: How do I take all of the email addresses out of an <cassell@mail.cor.epa.gov>
Re: How do I take all of the email addresses out of an <cassell@mail.cor.epa.gov>
Re: How do I take all of the email addresses out of an <cassell@mail.cor.epa.gov>
Re: How to create file in other directory ? <cassell@mail.cor.epa.gov>
Re: How to create file in other directory ? <flavell@mail.cern.ch>
Re: How to create file in other directory ? <slanning@bu.edu>
Re: How to create file in other directory ? <lr@hpl.hp.com>
Re: How to create file in other directory ? <lr@hpl.hp.com>
Re: How to create file in other directory ? (Abigail)
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sun, 21 Nov 1999 17:23:44 GMT
From: jut@letterbox.com
Subject: Re: Encryption Algorithm for Perl Source Code??
Message-Id: <38382a80.3048722@news.singnet.com.sg>
Nope, I'd love to give it a shot. downloading it now from CPAN.
Thanks man.
On 21 Nov 1999 09:47:15 GMT, simon@brecon.co.uk (Simon Cozens) wrote:
>jut@letterbox.com (comp.lang.perl.misc):
>>The code IS obfuscated and defeats all my attempts to print the
>>plain-text code to a file because it's really the compiler which sort
>>of decodes it. However, with the aid of my trusty debugger, I managed
>>to view the plain-text nevertheless. :)
>
>Would this be a bad time to mention B::Deparse, then?
------------------------------
Date: Sun, 21 Nov 1999 17:35:44 GMT
From: jut@letterbox.com
Subject: Re: Encryption Algorithm for Perl Source Code??
Message-Id: <383a2ce8.3665313@news.singnet.com.sg>
I'm sorry man, but I'm afraid it doesn't do much! It still prints out
the obfuscated code! Don't even begin to ask me why. Logically any
data readable by the compiler should have been readable already.
However, I think it's some kind of double protection thing. <shrug> So
the compiler executes a series of string operations which makes it
compiler-friendly again. Pretty interesting huh?
On 21 Nov 1999 09:47:15 GMT, simon@brecon.co.uk (Simon Cozens) wrote:
>jut@letterbox.com (comp.lang.perl.misc):
>>The code IS obfuscated and defeats all my attempts to print the
>>plain-text code to a file because it's really the compiler which sort
>>of decodes it. However, with the aid of my trusty debugger, I managed
>>to view the plain-text nevertheless. :)
>
>Would this be a bad time to mention B::Deparse, then?
------------------------------
Date: Sun, 21 Nov 1999 19:51:18 GMT
From: Kenneth Bandes <kbandes@home.com>
Subject: Re: Encryption Algorithm for Perl Source Code??
Message-Id: <38384D63.DF5E9D21@home.com>
jut@letterbox.com wrote:
>
> I'm sorry man, but I'm afraid it doesn't do much! It still prints out
> the obfuscated code! Don't even begin to ask me why. Logically any
> data readable by the compiler should have been readable already.
>
> However, I think it's some kind of double protection thing. <shrug> So
> the compiler executes a series of string operations which makes it
> compiler-friendly again. Pretty interesting huh?
Look in the original code for a call to eval. Sounds like it's
got a bunch of code encoded in some ugly way. It then decodes
this and passes the decoded result to eval. So you should see
eval, and also a call to some kind of decoding function. The
rest of the program is probably one big ugly string containing
an encoded program.
Ken Bandes
------------------------------
Date: Sun, 21 Nov 1999 20:00:03 GMT
From: *@dragons.duesouth.net (Matthew Bafford)
Subject: Re: Encryption Algorithm for Perl Source Code??
Message-Id: <slrn83gi3d.bkd.*@dragons.duesouth.net>
[Please place your replies below the message you are replying to. This
lets people quickly glance over the previous message and freshen up on
what's going on.]
On Sun, 21 Nov 1999 17:35:44 GMT, jut@letterbox.com poured coffee onto a
keyboard, producing the following in comp.lang.perl.misc:
: On 21 Nov 1999 09:47:15 GMT, simon@brecon.co.uk (Simon Cozens) wrote:
: >Would this be a bad time to mention B::Deparse, then?
:
: I'm sorry man, but I'm afraid it doesn't do much! It still prints out
: the obfuscated code! Don't even begin to ask me why. Logically any
: data readable by the compiler should have been readable already.
Perhaps you aren't using B::Deparse correctly? It's a bit unintuitive.
perl -MO=Deparse myprogram
For example:
#!/usr/bin/perl -w
($o=shift)||die"Usage: rename expr [files]\n";
chomp(@ARGV=<STDIN>)unless@ARGV;eval"sub z{$o}1";
die"$@\n$o\n"if$@;for(@ARGV){$was=$_;&z;rename($was,$_)
unless$was eq$_;}
Becomes:
die "Usage: rename expr [files]\n" unless $o = shift @ARGV;
chomp(@ARGV = <STDIN>) unless @ARGV;
eval "sub z{$o}1";
die "$@\n$o\n" if $@;
foreach $_ (@ARGV) {
$was = $_;
&z;
rename $was, $_ unless $was eq $_;
}
If you use the -p option to O=Deparse; perl -MO=Deparse,-p myprogram, you
get:
(($o = shift(@ARGV)) or die("Usage: rename expr [files]\n"));
(@ARGV or chomp((@ARGV = <STDIN>)));
eval("sub z{$o}1");
($@ and die("$@\n$o\n"));
foreach $_ (@ARGV) {
($was = $_);
&z;
(($was eq $_) or rename($was, $_));
}
Which helps emphasize precedence.
Also, B::Deparse may not work unless it comes with your version of Perl.
--Matthew
------------------------------
Date: Sun, 21 Nov 1999 16:46:01 -0800
From: David Cassell <cassell@mail.cor.epa.gov>
Subject: Re: environment vars
Message-Id: <38389249.E76E80EC@mail.cor.epa.gov>
Uri Guttman wrote:
>
> >>>>> "DC" == David Cassell <cassell@mail.cor.epa.gov> writes:
>
> DC> David, yes I am spending lots of time with my four-year-old,
> DC> why do you ask?
>
> i bet s/he is a better perl hacker already then most of our favorite
> newbies.
Well, Ben may still be at the cut-and-paste stage, so to speak,
but at least he doesn't spell 'cool' with a K and a W. :-)
David
--
David Cassell, OAO cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician
------------------------------
Date: Mon, 22 Nov 1999 01:30:09 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: environment vars
Message-Id: <B01_3.153$Eu1.4395@nsw.nnrp.telstra.net>
On Fri, 19 Nov 1999 23:27:03 -0500,
Chris Collins <cpcollin@wam.umd.edu> wrote:
> Wow,
>
> I'm catching alot of flak for asking an innocent question.
> Maybe I'll just write all my code in ADA from now on
Not you. Jakob is.
Martien
--
Martien Verbruggen |
Interactive Media Division | Useful Statistic: 75% of the people
Commercial Dynamics Pty. Ltd. | make up 3/4 of the population.
NSW, Australia |
------------------------------
Date: Sat, 20 Nov 1999 13:30:23 -0800
From: "rydaron" <rydaron@sonic.net>
Subject: Escape Character/CGI Script Trouble
Message-Id: <817ktr$7rr$1@ultra.sonic.net>
In a message board CGI script I own, I did a search for and found every
instance where the script writes some html code. Since I want my page to
look very specific, I wanted to add a style sheet at the beginning of each
of the instances where the script writes some html code. I want to add the
following piece of code to the CGI script:
print "<style type="text/css">\n";
print "<!--\n";
print " body {font-family: arial; font-size: 8pt}\n";
print " ul {font-family: arial; font-size: 8pt}\n";
print " hr {width: 75%; color: #000000}\n";
print " a {font-family: arial; font-size: 8pt; font-weight: bold;
text-decoration: underline; color: #000000}\n";
print " a:link {font-family: arial; font-size: 8pt; font-weight: bold;
text-decoration: underline; color: #000000}\n";
print " a:hover {font-family: arial; font-size: 8pt; font-weight: bold;
text-decoration: none; color: #999999}\n";
print "-->\n";
print "</style>\n";
When I tried adding that code for the style sheet in each of the sections,
it spat out a 500 error at me. Now, I'm a bright guy, and I assumed that the
problem was because of all the semicolons (gee, you suppose?), so I tried
inserting \; wherever I saw a semicolon, but apparently that wasn't the
escape character. Or if it was, it wasn't the only thing screwing up the
code. If somebody could provide me with the escape character for the
semicolon, and pointers on anything else wrong in the code, I'd appreciate
it.
Please help, thanks.
- The Mad Goblin (madgob@aol.com)
------------------------------
Date: Sat, 20 Nov 1999 13:30:23 -0800
From: "rydaron" <rydaron@sonic.net>
Subject: Escape Character/CGI Script Trouble
Message-Id: <81748c$5cs$1@ultra.sonic.net>
In a message board CGI script I own, I did a search for and found every
instance where the script writes some html code. Since I want my page to
look very specific, I wanted to add a style sheet at the beginning of each
of the instances where the script writes some html code. I want to add the
following piece of code to the CGI script:
print "<style type="text/css">\n";
print "<!--\n";
print " body {font-family: arial; font-size: 8pt}\n";
print " ul {font-family: arial; font-size: 8pt}\n";
print " hr {width: 75%; color: #000000}\n";
print " a {font-family: arial; font-size: 8pt; font-weight: bold;
text-decoration: underline; color: #000000}\n";
print " a:link {font-family: arial; font-size: 8pt; font-weight: bold;
text-decoration: underline; color: #000000}\n";
print " a:hover {font-family: arial; font-size: 8pt; font-weight: bold;
text-decoration: none; color: #999999}\n";
print "-->\n";
print "</style>\n";
When I tried adding that code for the style sheet in each of the sections,
it spat out a 500 error at me. Now, I'm a bright guy, and I assumed that the
problem was because of all the semicolons (gee, you suppose?), so I tried
inserting \; wherever I saw a semicolon, but apparently that wasn't the
escape character. Or if it was, it wasn't the only thing screwing up the
code. If somebody could provide me with the escape character for the
semicolon, and pointers on anything else wrong in the code, I'd appreciate
it.
Please help, thanks.
- The Mad Goblin (madgob@aol.com)
------------------------------
Date: 21 Nov 1999 19:46:08 +0000
From: Tony Curtis <tony_curtis32@yahoo.com>
Subject: Re: Escape Character/CGI Script Trouble
Message-Id: <wku2mfhblr.fsf@yahoo.com>
"rydaron" <rydaron@sonic.net> writes:
> print "<style type="text/css">\n";
(mis-matched " characters...)
Have you output the Content-Type header(s) yet?
> print "<!--\n";
> print " body {font-family: arial; font-size: 8pt}\n";
> print " ul {font-family: arial; font-size: 8pt}\n";
> print " hr {width: 75%; color: #000000}\n";
> print " a {font-family: arial; font-size: 8pt; font-weight: bold;
> text-decoration: underline; color: #000000}\n";
> print " a:link {font-family: arial; font-size: 8pt; font-weight: bold;
> text-decoration: underline; color: #000000}\n";
> print " a:hover {font-family: arial; font-size: 8pt; font-weight: bold;
> text-decoration: none; color: #999999}\n";
> print "-->\n";
> print "</style>\n";
It might make more sense to put this style sheet
into a file and reference it as a link in the
document <HEAD>.
Using the CGI module simplifies this (I find,
anyway). The header() method includes some support
for linking in style-sheets.
hth
tony
------------------------------
Date: Sun, 21 Nov 1999 21:06:48 +0100
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: Escape Character/CGI Script Trouble
Message-Id: <Pine.HPP.3.95a.991121205451.23568H-100000@hpplus01.cern.ch>
On Sat, 20 Nov 1999, rydaron wrote:
> print "<style type="text/css">\n";
> print "<!--\n";
> print " body {font-family: arial; font-size: 8pt}\n";
> print " ul {font-family: arial; font-size: 8pt}\n";
> print " hr {width: 75%; color: #000000}\n";
> print " a {font-family: arial; font-size: 8pt; font-weight: bold;
> text-decoration: underline; color: #000000}\n";
> print " a:link {font-family: arial; font-size: 8pt; font-weight: bold;
> text-decoration: underline; color: #000000}\n";
> print " a:hover {font-family: arial; font-size: 8pt; font-weight: bold;
> text-decoration: none; color: #999999}\n";
> print "-->\n";
> print "</style>\n";
You definitely want to discover the here-document construction for
this kind of snippet, in this case something like:
print <<EOD;
...all your stuff...
EOD
Look for it in perldoc perldata (or your favourite Perl tutorial/book).
That's if you really did need to generate it inline into the generated
document. For a harmonious site style, you may be better off creating a
site-wide external stylesheet: but that has nothing to do with Perl, so
I'll stop there.
> When I tried adding that code for the style sheet in each of the sections,
> it spat out a 500 error at me.
One of the benefits of using the CGI.pm module (even if you decide
to output some of your stuff in the raw anyway) is that it has an
online debugging mode, where you can get most of these errors out of the
way from your command line, before you start struggling with a web
server.
It _is_ possible to mock up the enviroment variables and run a CGI
script more-or-less as it would get run by a web server, but it's a
chore.
But again, these are not Perl language issues, so you should be on
comp.infosystems.www.authoring.cgi, where they might ask you whether you
had output your header(s) (Content-type: and anything else you need)
before starting on the content.
good luck
------------------------------
Date: Sun, 21 Nov 1999 17:34:02 -0800
From: David Cassell <cassell@mail.cor.epa.gov>
Subject: Re: Escape Character/CGI Script Trouble
Message-Id: <38389D8A.ED20CF09@mail.cor.epa.gov>
rydaron wrote:
[snip]
> print "<style type="text/css">\n";
[snip]
> When I tried adding that code for the style sheet in each of the sections,
> it spat out a 500 error at me. Now, I'm a bright guy, and I assumed that the
> problem was because of all the semicolons (gee, you suppose?), so I tried
> inserting \; wherever I saw a semicolon, but apparently that wasn't the
> escape character. Or if it was, it wasn't the only thing screwing up the
It isn't the semicolons. It's the double quotes inside your
double quotes. \ is the escape character, but you'll be
much better off using a here-doc [as discussed in the perldata
pages] or the qq() operator [as discussed in the perlop
pages].
A style sheet seems like a reasonable idea, but is really more
of a CGI issue than a Perl issue, so further discussion of that
tangent is better in a different newsgroup.
David
--
David Cassell, OAO cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician
------------------------------
Date: Sun, 21 Nov 1999 22:12:49 GMT
From: Kenneth Bandes <kbandes@home.com>
Subject: Re: Getting HTML tags via regular expression
Message-Id: <38386E8F.319CC595@home.com>
Abigail wrote:
> Jonathan Stowe (gellyfish@gellyfish.com) wrote ...
> %% On 20 Nov 1999 08:22:33 -0600 Abigail wrote:
> %% >
> %% > HTML is an SGML application. Parsing SGML is far from trivial.
[snip]
> %%
> %% Fine. Do you then suggest that for every querent who comes here
> %% with a similar request we:
> %%
> %% A) Tell them to learn about SGML, understand the relevant DTD
> %% and then build their own parser.
> %%
> %% B) Tell them to use an external SGML parser with reference to
> %% the appropriate DTD.
>
> There is nsgmls.
This is what the W3C validation service uses (along with weblint).
My own limited experience is that any useful data extraction of
web pages requires custom regexes (pretty much what Abigail is
saying), for two reasons:
1) A lot of the web is in Pidgin HTML, which chokes nsgmls or
any rigorous parsing technique.
2) HTML anyway provides no useful context for most interesting
data.
If the web consisted of documents conforming to well-designed
XML or SGML DTDs, you might expect the data of interest to be
wrapped in appropriate, semantically freighted tags.
But it doesn't, so the identifying context for your data almost
never coincides with what an HTML parser would consider a
token. It may be a fragment of the content of one tag, or
it may span several tags. Either way, handling the data
one token at a time in callback functions is not likely to
be a useful way to find what you want. Anyway, that's been
true for me, although I should say I don't really make my
living shredding web pages.
Finding email addresses in email is easy, because they occur
in appropriately-marked headers. Finding them in HTML is hard,
because they can occur anywhere.
[snip]
> %% D) Go through the usual eternal iterative process of helping
> %% them decompose their HTML using a regex or other language
> %% feature.
>
> And yes, I plan to make a real HTML parser in pure Perl. But that
> will take a while, because it won't be easy.
Randal Schwartz has also mentioned
(http://www.deja.com/=rj/getdoc.xp?AN=538426419&fmt=text)
some plans to write an HTML parser. He seems to have some
intention of making it forgiving of at least some abuses of HTML.
I wouldn't presume to tell Randal what's possible, but parsing Pidgin
HTML is certainly daunting (Pidgins by definition have no definable
grammar). The existence of Netscape and Internet Exploder could be
argued, with some justice, as either examples or counterexamples for
the tractability of this project.
Ken Bandes
------------------------------
Date: Sun, 21 Nov 1999 16:45:09 -0800
From: David Cassell <cassell@mail.cor.epa.gov>
Subject: Re: Help -Mod-perl Configuration
Message-Id: <38389215.A72114EA@mail.cor.epa.gov>
Moin wrote:
>
> Can any one tell me how to configure mod-perl. [.....}
[snip]
I'm sorry, but you seem to be in the wrong newsgroup. Did
Deja.com stick you here by accident? This is a group for
discussing programming in Perl. Perhaps you want a group
about webservers, or specifically about Apache.
David
--
David Cassell, OAO cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician
------------------------------
Date: Sun, 21 Nov 1999 16:19:46 -0500
From: brian@smithrenaud.com (brian d foy)
Subject: Re: Help With CyberCash....
Message-Id: <brian-2111991619460001@sri.dialup.access.net>
In article <3836B6D8.BC30CC93@voxel.net>, Raj Dutt <rdutt@voxel.net> wrote:
>> extensively with CyberCash about this and they indicate it is not
>> their policy to help with stuff like this. I have modified the script
>
>This has absolutely nothing to do with Cybercash. And I don't see what it has to
>do with perl either.
well, they have a Perl API, so dealing with them is about Perl. the
original poster is not complaining about Cybercash not working, just that
they don't provide technical support.
--
brian d foy
Perl Mongers <URI:http://www.perl.org>
CGI MetaFAQ
<URI:http://www.smithrenaud.com/public/CGI_MetaFAQ.html>
------------------------------
Date: Sun, 21 Nov 1999 17:58:40 -0500
From: Ala Qumsieh <aqumsieh@matrox.com>
Subject: Re: How do I take all of the email addresses out of an email? 2 of 2
Message-Id: <x3ybt8nzc2n.fsf@tigre.matrox.com>
simon@brecon.co.uk (Simon Cozens) writes:
> Poohba (comp.lang.perl.misc):
> > if($name =~ /@/i) {
>
> And I'll meet you @8pm.
> Luser spambot fuckwits.
Note that he's matching for both uppercase and lowercase @.
--Ala
------------------------------
Date: 21 Nov 1999 23:33:34 GMT
From: simon@brecon.co.uk (Simon Cozens)
Subject: Re: How do I take all of the email addresses out of an email? 2 of 2
Message-Id: <slrn83h0ae.rvt.simon@othersideofthe.earth.li>
Ala Qumsieh (comp.lang.perl.misc):
>simon@brecon.co.uk (Simon Cozens) writes:
>> Luser spambot fuckwits.
Ooh, ouch. I think posting to USENET while angry comes under the
category of making speeches. Apologies for turning the air blue.
>Note that he's matching for both uppercase and lowercase @.
Ah, uhm, it's to do with locale settings? :)
--
Writing software is more fun than working.
------------------------------
Date: Sun, 21 Nov 1999 17:41:36 -0800
From: David Cassell <cassell@mail.cor.epa.gov>
Subject: Re: How do I take all of the email addresses out of an email? 2 of 2
Message-Id: <38389F50.9C261E11@mail.cor.epa.gov>
Simon Cozens wrote:
>
> Ala Qumsieh (comp.lang.perl.misc):
> >simon@brecon.co.uk (Simon Cozens) writes:
> >> Luser spambot fuckwits.
>
> Ooh, ouch. I think posting to USENET while angry comes under the
> category of making speeches. Apologies for turning the air blue.
No problem. We all lose our tempers around here sooner
or later. I try not to post until I can at least make my
hands stop clenching into claws. :-)
> >Note that he's matching for both uppercase and lowercase @.
>
> Ah, uhm, it's to do with locale settings? :)
heh.
The moral of the story? Use lots of '@' in your writing. :-)
I'm sure plenty of kewl d@@ds will get a few hundred hits
with that 'clever' bit of email screening. And all the people
who write 'poohba at whatever dot snark' will escape from his
clutches.
David
--
David Cassell, OAO cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician
------------------------------
Date: Sun, 21 Nov 1999 16:53:57 -0800
From: David Cassell <cassell@mail.cor.epa.gov>
Subject: Re: How do I take all of the email addresses out of an email?
Message-Id: <38389425.C7BADE44@mail.cor.epa.gov>
Poohba wrote:
>
> I am trying to get all of the email addresses out of a letter that I have
> so that I can put in my address book.
It cannot be done in a general form, since people like to put
so many variants in so many different places in their posts.
If you have only one or two letters, then perhaps you should
do this by hand.
If you want to do this for every letter you receive, then you
should consider why you want to do this, and whether other
people will appreciate this.
email addresses in headers are usually available to your mail
software, and should be captured using your mail program.
David
--
David Cassell, OAO cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician
------------------------------
Date: Sun, 21 Nov 1999 16:56:49 -0800
From: David Cassell <cassell@mail.cor.epa.gov>
Subject: Re: How do I take all of the email addresses out of an email?
Message-Id: <383894D1.DF2BF776@mail.cor.epa.gov>
Lionel Andre wrote:
>
> HI Poohba.
>
> When you have an answer to this (if you do, could you please be as kind as to
> send it my way, since I was going to ask for just THAT! :)
No, this is not the same question at all. You have a problem
which can be solved using the Perl Mail::* modules, since you
have email addresses defined in mail headers.
Poohba has email addresses scattered without definition in one
or more messages. There is no automatic way of handling that
problem. And since this is what spammers want, it is highly
unlikely that any white-hat Perlite will write a module to
handle this well.
David
--
David Cassell, OAO cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician
------------------------------
Date: Sun, 21 Nov 1999 17:15:30 -0800
From: David Cassell <cassell@mail.cor.epa.gov>
Subject: Re: How to create file in other directory ?
Message-Id: <38389932.40EA3416@mail.cor.epa.gov>
Honey wrote:
>
> foreach $Name (@AllNames) {
> if (-d $Name) {next}
> { print "$Name"}
> }
I hate to be a pest, but I want to let you know a couple things.
[1] This didn't answer the poster's question.
[2] The '-d $Name' part is likely to fail - unless you can
guarantee that the files are all in the current dir.
[3] 'next if EXPR;' is more Perlish;
[4] You don't need quotes there in your print() statement.
Automatic use of quotes in print()s will bite you sooner
or later. And a "\n" would be useful there.
[5] So a line which says
print $Name, "\n" unless (-d $Dir/$Name);
would really work nicer.
[6] And you could then put that line in front of the foreach
if you have 5.005 .
[7] When posting here, it is really helpful if you make sure
that your code works. Otherwise, other people will have
to correct you, and then you'll get aggravated at having
people complain about your code.
[8] And when posting here, please put your reply *after* the
quoted [and properly-trimmed] text from the querent.
[9] Thank you for reading down this far.
> hope this helps
I don't think it did. But I hope this note is helpful to
you, and not just something which pi$$es you off.
David
--
David Cassell, OAO cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician
------------------------------
Date: Mon, 22 Nov 1999 03:12:36 +0100
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: How to create file in other directory ?
Message-Id: <Pine.HPP.3.95a.991122030325.2670A-100000@hpplus01.cern.ch>
On Sun, 21 Nov 1999, David Cassell wrote:
> > if (-d $Name) {next}
> [3] 'next if EXPR;' is more Perlish;
What's the general feeling about constructions in this kind of form:
EXPR and next;
which I saw extensively used in someone else's code recently.
(I must admit I've always found the idea of "do-this ... if EXPR;" to
be a bit like the navigator that shouts to the driver, "TURN LEFT....
in about a quarter of a mile" - see what I'm getting at?).
cheers
------------------------------
Date: 21 Nov 1999 22:08:19 -0500
From: Scott Lanning <slanning@bu.edu>
Subject: Re: How to create file in other directory ?
Message-Id: <kusn1s7te8s.fsf@bottom.bu.edu>
"Alan J. Flavell" <flavell@mail.cern.ch> writes:
> (I must admit I've always found the idea of "do-this ... if EXPR;" to
> be a bit like the navigator that shouts to the driver, "TURN LEFT....
> in about a quarter of a mile" - see what I'm getting at?).
I know what you're saying, but it is more Perlish, like David said.
I find something like
while(<>){
if(/foo/){
is_foo();
}
if(/bar/){
is_bar();
}
if(/baz/){
is_baz();
}
}
to be uglier than
while(<>){
is_foo() if /foo/;
is_bar() if /bar/;
is_bas() if /baz/;
}
I also think
foreach my $file (@files){
print "file: $file\n";
}
would be uglier than
for(@files){
print "file: $_\n";
}
I tend to be as minimal as possible. I suppose floating in the
back of my mind is that it might be more efficient, though I don't
whether that's really the case.
Regarding the "EXPR and do-that" idiom, I do that too
but prefer "EXPR && do-that", though that might be due to C bias.
I understand that and is lower precedence, but the and seems to
get lost, while the && stands out better (just look at this
sentence).
--
"I'm going to have fun telling you about this absurdity, because I
find it delightful." --Richard Feynman
------------------------------
Date: Sun, 21 Nov 1999 19:28:46 -0800
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: How to create file in other directory ?
Message-Id: <MPG.12a25840ae46a6fe98a24a@nntp.hpl.hp.com>
In article <Pine.HPP.3.95a.991122030325.2670A-100000@hpplus01.cern.ch>
on Mon, 22 Nov 1999 03:12:36 +0100, Alan J. Flavell
<flavell@mail.cern.ch> says...
> On Sun, 21 Nov 1999, David Cassell wrote:
>
> > > if (-d $Name) {next}
>
> > [3] 'next if EXPR;' is more Perlish;
>
> What's the general feeling about constructions in this kind of form:
>
> EXPR and next;
>
> which I saw extensively used in someone else's code recently.
>
> (I must admit I've always found the idea of "do-this ... if EXPR;" to
> be a bit like the navigator that shouts to the driver, "TURN LEFT....
> in about a quarter of a mile" - see what I'm getting at?).
I like the left-to-right construct when it focuses on the decision and
not on the consequent. In contrast, writing the following is simply
hideous:
die "Couldn't open '$file'. $!\n" unless open FILE, $file;
But I've seen lots of stuff written that way, perhaps to be 'more
Perlish'.
If the consequent is the more usual case, then right-to-left seems OK.
next unless /rare_event/;
# deal with the rare event...
/common_event/ or next;
# deal with the common event...
In any case (though you didn't ask), I would always use 'and' or 'or' in
this situation (flow control) rather than '&&' or '||' (logical
conjunction or disjunction), even if the precedence would tolerate the
latter forms in a flow-control situation. I.e., never this:
open(FILE, $file) || die ...
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Sun, 21 Nov 1999 20:03:12 -0800
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: How to create file in other directory ?
Message-Id: <MPG.12a2605bcf26022a98a24c@nntp.hpl.hp.com>
In article <kusn1s7te8s.fsf@bottom.bu.edu> on 21 Nov 1999 22:08:19 -
0500, Scott Lanning <slanning@bu.edu> says...
> "Alan J. Flavell" <flavell@mail.cern.ch> writes:
> > (I must admit I've always found the idea of "do-this ... if EXPR;" to
> > be a bit like the navigator that shouts to the driver, "TURN LEFT....
> > in about a quarter of a mile" - see what I'm getting at?).
>
> I know what you're saying, but it is more Perlish, like David said.
> I find something like
>
> while(<>){
> if(/foo/){
> is_foo();
> }
> if(/bar/){
> is_bar();
> }
> if(/baz/){
> is_baz();
> }
> }
The only excuse for that style would be if the later 'if's were
'elsif's. If they are truly sequential tests, then it would be much
better written as:
while (<>) {
/foo/ and is_foo();
/bar/ and is_bar();
/baz/ and is_baz();
}
where I also put in the unnecessary whitespace token separators that you
eschewed.
> to be uglier than
>
> while(<>){
> is_foo() if /foo/;
> is_bar() if /bar/;
> is_bas() if /baz/;
> }
I don't think much of that way around -- cart before the horse, and all
that.
> I also think
>
> foreach my $file (@files){
> print "file: $file\n";
> }
>
> would be uglier than
>
> for(@files){
> print "file: $_\n";
> }
Those are almost isomorphic, to my eye.
> I tend to be as minimal as possible. I suppose floating in the
> back of my mind is that it might be more efficient, though I don't
> whether that's really the case.
Then you should write the last example in Perl 5.005:
print "file: $_\n" for @files;
> Regarding the "EXPR and do-that" idiom, I do that too
> but prefer "EXPR && do-that", though that might be due to C bias.
> I understand that and is lower precedence, but the and seems to
> get lost, while the && stands out better (just look at this
> sentence).
But the 'and' doesn't get lost in Perl code, which isn't likely to have
barewords on each side of it.
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: 21 Nov 1999 22:38:48 -0600
From: abigail@delanet.com (Abigail)
Subject: Re: How to create file in other directory ?
Message-Id: <slrn83hicr.m2v.abigail@alexandra.delanet.com>
Scott Lanning (slanning@bu.edu) wrote on MMCCLXXIV September MCMXCIII in
<URL:news:kusn1s7te8s.fsf@bottom.bu.edu>:
||
|| while(<>){
|| is_foo() if /foo/;
|| is_bar() if /bar/;
|| is_bas() if /baz/;
|| }
||
|| I tend to be as minimal as possible.
Then you should decrease the number of lines with 80%:
s/foo|bar|baz/"is_$&"->()/eg while<>;
Assuming there wouldn't be multiple foo's, bar's or bazzes on a line.
Perl golf anyone?
Abigail
--
%0=map{reverse+chop,$_}ABC,ACB,BAC,BCA,CAB,CBA;$_=shift().AC;1while+s/(\d+)((.)
(.))/($0=$1-1)?"$0$3$0{$2}1$2$0$0{$2}$4":"$3 => $4\n"/xeg;print#Towers of Hanoi
-----------== Posted via Newsfeeds.Com, Uncensored Usenet News ==----------
http://www.newsfeeds.com The Largest Usenet Servers in the World!
------== Over 73,000 Newsgroups - Including Dedicated Binaries Servers ==-----
------------------------------
Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 16 Sep 99)
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: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.
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 V9 Issue 1452
**************************************