[16692] in Perl-Users-Digest
Perl-Users Digest, Issue: 4104 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Aug 23 09:05:32 2000
Date: Wed, 23 Aug 2000 06:05:19 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <967035918-v9-i4104@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Wed, 23 Aug 2000 Volume: 9 Number: 4104
Today's topics:
Re: @_ as array <skv@iis.nsk.su>
Re: @_ as array (Martien Verbruggen)
Re: @_ as array <skv@iis.nsk.su>
Re: @_ as array (Martien Verbruggen)
Re: A logfile problem (Mike Stok)
Re: A logfile problem (Martien Verbruggen)
Re: Associative arrays (Martien Verbruggen)
Re: Associative arrays <mtaylorlrim@my-deja.com>
Re: Associative arrays (Martien Verbruggen)
Best/Easiest SQL Server friendly module? <ryanc@nci1.net>
Re: creating an enviroment variable (Anno Siegel)
Creating new file and substituting data <dereknews@realware.com.au>
Re: Creating new file and substituting data <uackermann@orga.com>
Hashref infix misunderstood? (Anno Siegel)
Re: help with simple regexp - does my head in (Anno Siegel)
Re: how to generate unreadable from readable perl code (Merijn Broeren)
Re: how to generate unreadable from readable perl code (Martien Verbruggen)
Re: looking for taint resources tebrusca@my-deja.com
Re: lwp post method matt@NOSPAMcipherdesign.com
Re: lwp post method (Marcel Grunauer)
Re: lwp post method matt@NOSPAMcipherdesign.com
negative lookahead assertions in Perl Regex <dmcgahon@iol.ie>
Re: negative lookahead assertions in Perl Regex (Eric Bohlman)
Perl and dates zideon@my-deja.com
Re: Perl/MySQL vs ASP/MS-SQL af778@iname.com
problems with regex (Martin Gieseking)
Re: Programming Ethics (Tim Hammerquist)
Re: Rationale Behind 'Use of Uninitialized Value' Warni (Anno Siegel)
Re: would you recommend buying a book (Tim Hammerquist)
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 23 Aug 2000 17:06:25 +0600
From: "Konstantin Stupnik" <skv@iis.nsk.su>
Subject: Re: @_ as array
Message-Id: <8o07m4$bch$1@nl.novosoft.ru>
Hi!
> >>How can I best achieve to retrieve the second element (element 1) from
@_?
> >>
> >>I get a warning when I do @_[1], but I imagine $_[1] wouldn't work
either,
> >>as $_ is a reserved variable as well.
> >>
> >
> >my ($notwanted,$wanted) = @_;
> >
> Oh yes, sorry I forgot to mention that
> $_[1] will work too.
or:
shift;
my $wanted=shift;
:)
--
Best regards,
Konstantin.
Brainbench MVP for perl.
------------------------------
Date: Wed, 23 Aug 2000 21:49:08 +1000
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: @_ as array
Message-Id: <slrn8q7ehk.5ap.mgjv@martien.heliotrope.home>
[I wanted to remove alt.perl from the Newsgroups list, but then I
realised that that is most likely where this came from.
ALT.perl? Who ever came up with that idea?]
On Wed, 23 Aug 2000 17:06:25 +0600,
Konstantin Stupnik <skv@iis.nsk.su> wrote:
[reformatted and de-ms-outlooked article, original attributions were
already cut from article. Please don't do that.]
> Hi!
> > >>How can I best achieve to retrieve the second element (element 1)
> > >>from @_?
> > >>
> > >>I get a warning when I do @_[1], but I imagine $_[1] wouldn't work
> > >>either, as $_ is a reserved variable as well.
Did you read the warning? Did you read the perldata documentation?
# perldoc perldata
Or, as an alternative for all the people with advanced microsoft menu
systems: start menu, programs,activeperl, help or something like that.
$_[1] is a scalar variable corresponding to the first element in the
array @_. $_{foo} is a scalar variable correspoding to the value of the
key-value pair in the hash %_.
> > >my ($notwanted,$wanted) = @_;
> > >
> > Oh yes, sorry I forgot to mention that
> > $_[1] will work too.
>
> or:
> shift;
> my $wanted=shift;
That will get $_[0] in $wanted, and make @_ one element shorter. That
was clearly not what the OP was asking for.
If you want to get element 1, and remove it, you could use splice. But I
doubt that that is useful.
Martien
--
Martien Verbruggen |
Interactive Media Division | Never hire a poor lawyer. Never buy
Commercial Dynamics Pty. Ltd. | from a rich salesperson.
NSW, Australia |
------------------------------
Date: Wed, 23 Aug 2000 19:23:10 +0600
From: "Konstantin Stupnik" <skv@iis.nsk.su>
Subject: Re: @_ as array
Message-Id: <8o0fmh$ki7$1@nl.novosoft.ru>
"Martien Verbruggen" <mgjv@tradingpost.com.au> wrote in message
news:slrn8q7ehk.5ap.mgjv@martien.heliotrope.home...
> [I wanted to remove alt.perl from the Newsgroups list, but then I
> realised that that is most likely where this came from.
> ALT.perl? Who ever came up with that idea?]
>
> On Wed, 23 Aug 2000 17:06:25 +0600,
> Konstantin Stupnik <skv@iis.nsk.su> wrote:
>
> [reformatted and de-ms-outlooked article, original attributions were
> already cut from article. Please don't do that.]
>
> > Hi!
> > > >>How can I best achieve to retrieve the second element (element 1)
> > > >>from @_?
> > > >>
> > > >>I get a warning when I do @_[1], but I imagine $_[1] wouldn't work
> > > >>either, as $_ is a reserved variable as well.
>
> Did you read the warning? Did you read the perldata documentation?
>
> # perldoc perldata
>
> Or, as an alternative for all the people with advanced microsoft menu
> systems: start menu, programs,activeperl, help or something like that.
>
> $_[1] is a scalar variable corresponding to the first element in the
Actually second element :)
> array @_. $_{foo} is a scalar variable correspoding to the value of the
> key-value pair in the hash %_.
>
> > > >my ($notwanted,$wanted) = @_;
> > > >
> > > Oh yes, sorry I forgot to mention that
> > > $_[1] will work too.
> >
> > or:
> > shift;
> > my $wanted=shift;
>
> That will get $_[0] in $wanted, and make @_ one element shorter. That
> was clearly not what the OP was asking for.
No.
The code is:
shift;
my $wanted=shift;
First shift will remove first element, and $wanted=shift will
remove second and place it to $wanted.
> If you want to get element 1, and remove it, you could use splice. But I
> doubt that that is useful.
--
Best regards,
Konstantin.
Brainbench MVP for perl.
------------------------------
Date: Wed, 23 Aug 2000 22:36:13 +1000
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: @_ as array
Message-Id: <slrn8q7h9t.5ap.mgjv@martien.heliotrope.home>
On Wed, 23 Aug 2000 19:23:10 +0600,
Konstantin Stupnik <skv@iis.nsk.su> wrote:
> "Martien Verbruggen" <mgjv@tradingpost.com.au> wrote in message
> news:slrn8q7ehk.5ap.mgjv@martien.heliotrope.home...
> >
> > $_[1] is a scalar variable corresponding to the first element in the
>
> Actually second element :)
You are correct.
> > > or:
> > > shift;
> > > my $wanted=shift;
> >
> > That will get $_[0] in $wanted, and make @_ one element shorter. That
> > was clearly not what the OP was asking for.
> No.
> The code is:
> shift;
> my $wanted=shift;
I swear I read your original code a few times to find that first shift,
because I knew it had to be there for this to be correct, and I just did
_not_ see it. I must be getting old or something like that...
sorry.
Martien
--
Martien Verbruggen |
Interactive Media Division | Freudian slip: when you say one
Commercial Dynamics Pty. Ltd. | thing but mean your mother.
NSW, Australia |
------------------------------
Date: Wed, 23 Aug 2000 12:14:20 GMT
From: mike@stok.co.uk (Mike Stok)
Subject: Re: A logfile problem
Message-Id: <wePo5.11523$C5.167740@typhoon.austin.rr.com>
In article <39B17724@MailAndNews.com>,
James <jamesmckay@MailAndNews.com> wrote:
>Hi All,
> Does anyone know of a way of sending all the output of a perl script
>to
>a file, without having to resort to specific open-write-close operations for
>each step. Basically I want to generate a journal of every action the
>script
>performs, including all user interaction. This is simple in unix shell
>scripting, in that you simply make the whole script a function and divert
>the
>standard output. However I can't seem to do anything similar in perl. I'm
>sure there must be a way. Any ideas?
If you want to divert the standard output you can re-open STDOUT to a log
file, if that's successful then all output which would have gone to STDOUT
will go to that file. That's kind of brutal, and it's hard to retrieve
the old STDOUT again. If you want to do something a little better you could
investigate the (single argument) select in perl
perldoc -tf select
may be of use.
Hope this helps,
Mike
--
mike@stok.co.uk | The "`Stok' disclaimers" apply.
http://www.stok.co.uk/~mike/ |
GPG PGP Key 1024D/059913DA | Fingerprint 0570 71CD 6790 7C28 3D60
stok@colltech.com (CT - work) | 75D2 9EC4 C1C0 0599 13DA
------------------------------
Date: Wed, 23 Aug 2000 22:11:34 +1000
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: A logfile problem
Message-Id: <slrn8q7frm.5ap.mgjv@martien.heliotrope.home>
On Wed, 23 Aug 2000 06:00:41 -0400,
James <jamesmckay@MailAndNews.com> wrote:
> Hi All, Does anyone know of a way of sending all the output of a perl
> script to a file, without having to resort to specific
> open-write-close operations for each step.
This description is _not_ the same as
> Basically I want to
> generate a journal of every action the script performs, including all
> user interaction.
this description. If you want to do something, you should probably make
sure that you don't send mixed signals.
> This is simple in unix shell scripting, in that you
> simply make the whole script a function and divert the standard
> output.
This would be an answer to the first description, but not the second
one.
I don't think there is something like your second description... A
combination of sh -x, tee(1), redirecting stdout, and script(1) would
maybe do all that, but it certainly isn't a trivial exercise, like you
seem to be saying.
I suspect that what you really want is redirect STDOUT, and maybe
STDERR.
open(STDOUT, ">$file") or die "Cannot open $file: $!";
open(STDERR, ">&STDOUT") or die "Cannot dup STDOUT: $!";
Check perlopentut for more information.
# perldoc perlopentut
Martien
--
Martien Verbruggen |
Interactive Media Division | +++ Out of Cheese Error +++
Commercial Dynamics Pty. Ltd. | Reinstall Universe and Reboot +++
NSW, Australia |
------------------------------
Date: Wed, 23 Aug 2000 20:03:18 +1000
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: Associative arrays
Message-Id: <slrn8q78b6.5ap.mgjv@martien.heliotrope.home>
On Wed, 23 Aug 2000 10:30:58 +0100,
Alex Buell <alex.buell@tahallah.clara.co.uk> wrote:
> I was playing with associative arrays like so:
>
> %fields = ( "Member ID" => 0, "Forename" => 1, "Surname" = >2 );
>
> print $fields{"Member ID"), "\n";
>
> Why can't I do this:
>
> print $fields{0); # I want to print "Member ID" but it doesn't!
Because they are hashes, or associative arrays. The elements of these
things do not have an index. They're fundamentally unordered, and you
should not expect any order.
> My solution is to have the following:
>
> %field_numbers = ( "Member ID" => 0, "Forename" => 1, "Surname" => 2);
> %field_names = ( 0 => "Member ID", 1 => "Forename", 2 => "Surname");
In your case you should probably start with an array, and transform it
into a has when needed, IF needed.
@names = ("Member ID", "Forename", "Surname");
@names{@names} = (0 .. $#names);
That last bit is called a hash slice, and You are actually filling the
has with the name %names. You can read about that in the same
documentation that describes what a hash and an array are:
# perldoc perldata
> Wouldn't it be cool to be able to get at the values just by doing:
>
> print $fields{"Member ID"}; # to get 0
> print $fields{0}; # to get "Member ID"
I wouldn't think that would be cool at all. I hardly ever need a two way
lookup like that, and if I do, I'll just keep an array and a hash
around. I would never use a hash when an array would do. It's too
expensive. If you have ordered data, use an array. If you then need to
know in which spot of the array an element lives, revert it into a hash.
If you only have to do the lookup once, just loop over the hash, and
find it.
Martien
--
Martien Verbruggen |
Interactive Media Division |
Commercial Dynamics Pty. Ltd. | "Mr Kaplan. Paging Mr Kaplan..."
NSW, Australia |
------------------------------
Date: Wed, 23 Aug 2000 10:46:50 GMT
From: Mark <mtaylorlrim@my-deja.com>
Subject: Re: Associative arrays
Message-Id: <8o0a2n$3at$1@nnrp1.deja.com>
Check and see if you can use the 'keys' function here. The only
drawback is that the 'order' of the array is not preserved.
%fields = ( "Member ID" => 0, "Forename" => 1, "Surname" = >2 );
@names = keys(%fields);
print "@names\n";
Forename Surname Member ID
Mark
In article <0o57qs486dn57gf3fikuqm73q01t08m0l8@4ax.com>,
Alex Buell <alex.buell@tahallah.clara.co.uk> wrote:
> I was playing with associative arrays like so:
>
> %fields = ( "Member ID" => 0, "Forename" => 1, "Surname" = >2 );
>
> print $fields{"Member ID"), "\n";
>
> Why can't I do this:
>
> print $fields{0); # I want to print "Member ID" but it doesn't!
>
> My solution is to have the following:
>
> %field_numbers = ( "Member ID" => 0, "Forename" => 1, "Surname" => 2);
> %field_names = ( 0 => "Member ID", 1 => "Forename", 2 => "Surname");
>
> Wouldn't it be cool to be able to get at the values just by doing:
>
> print $fields{"Member ID"}; # to get 0
> print $fields{0}; # to get "Member ID"
>
> Cheers,
> Alex.
> --
> Real UNIX programmers do it with Perl.
>
> http://www.tahallah.clara.co.uk
>
--
Please reply to this newsgroup as my Deja mail
is used as a spam catcher only!
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Wed, 23 Aug 2000 21:42:50 +1000
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: Associative arrays
Message-Id: <slrn8q7e5q.5ap.mgjv@martien.heliotrope.home>
[please, in the future, put your reply after the suitably trimmed text
you reply to]
On Wed, 23 Aug 2000 10:46:50 GMT,
Mark <mtaylorlrim@my-deja.com> wrote:
[reorder post to respect the natural arrow of time]
> In article <0o57qs486dn57gf3fikuqm73q01t08m0l8@4ax.com>,
> Alex Buell <alex.buell@tahallah.clara.co.uk> wrote:
> > I was playing with associative arrays like so:
> >
> > %fields = ( "Member ID" => 0, "Forename" => 1, "Surname" = >2 );
> >
> > print $fields{"Member ID"), "\n";
> >
> > Why can't I do this:
> >
> > print $fields{0); # I want to print "Member ID" but it doesn't!
> >
> Check and see if you can use the 'keys' function here. The only
> drawback is that the 'order' of the array is not preserved.
Which defeats the purpose. The poster clearly wanted to find the key of
the pair in the hash with the value 0. How are you going to extract that
from your solution?
> %fields = ( "Member ID" => 0, "Forename" => 1, "Surname" = >2 );
And here you already lost the ordering of those pairs. The only order
that exists is in the values.
> @names = keys(%fields);
> print "@names\n";
>
>
> Forename Surname Member ID
Check some other posts in this thread for solutions that, most likely,
do what the OP was trying to achieve.
Martien
--
Martien Verbruggen |
Interactive Media Division |
Commercial Dynamics Pty. Ltd. | "Mr Kaplan. Paging Mr Kaplan..."
NSW, Australia |
------------------------------
Date: Wed, 23 Aug 2000 06:28:26 -0400
From: "Ryan & Treena Carrier" <ryanc@nci1.net>
Subject: Best/Easiest SQL Server friendly module?
Message-Id: <39a3a771_1@news.cybertours.com>
Which module should I use to interface with MS SQL Server 7.0? The
activestate perl installation comes with win32::ODBC. Will this work?
------------------------------
Date: 23 Aug 2000 13:00:38 -0000
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: creating an enviroment variable
Message-Id: <8o0htm$41u$1@lublin.zrz.tu-berlin.de>
Aitor Garcia <a58289@yahoo.com> wrote in comp.lang.perl.misc:
[jeopardy ordering corrected]
>In article <8nujdn$6qa$1@internal-news.uu.net>,
> Erik van Roode <newsposter@cthulhu.demon.nl> wrote:
>> Aitor Garcia <a58289@yahoo.com> wrote:
>> > Hello everybody;
>>
>> > I'm a Perl newbie and I've got a little
>> > question.
>> > I want to create a new enviroment variable
>> > and set a value to it.
>> > I have tried the following code but it does
>> > not work.
>>
>> > #!/usr/bin/perl
>> > $ENV{"USE_NC"} = "1";
>>
>> > Can anyone help me with this ?
>>
>> perlfaq8:
>> I {changed directory, modified my environment} in a perl
>> script. How come the change disappeared when I exited the
>> script? How do I get my changes to be visible?
>as you've told me I've read the Perl's faq
>and I've seen that the change is not visible
>to the system's shell because the shell
>opens a child process whenever a perl script
>is run.
>But at least the next commands I execute inside
>the perl script behind $ENV{"USE_NC"}=1 are
>executed with my enviroment variable set to 1?
You can test that yourself. It will come as no a surprise that
in Perl statements $ENV{ USE_NC} will be 1 once you've assigned it,
so I'll assume that by "command" you mean the execution of an
external program by system() and the like. This is really where
it matters; the program is run in a sub-process which puts the
environment to the test.
So just make a test script that contains
$ENV{ MY_VARIABLE} = 'blurfl';
system( 'echo $MY_VARIABLE'); # note single quotes
What does it print? What do you conclude?
Anno
------------------------------
Date: Wed, 23 Aug 2000 20:36:29 +1000
From: Realware Systems <dereknews@realware.com.au>
Subject: Creating new file and substituting data
Message-Id: <MPG.140e543a17c70de1989680@news.hutch.com.au>
Hi perlers,
I have not been using perl for a while, and have not used it a whole lot
anyway.
I have a little requirement, and I would really appriciate it if someone
could show me a clean way to do what I need to do.
I have a template file eg.
mytemplate.txt and it looks like this
some text
%%XXX%%
more text
%%XXX%%
more text etc.
I also have another file that contains names
fred
sue
bill
etc.
I need a script that will read the two files and for each name in the
name file I need to create a <name>.txt file with the %%XXX%% also
replaced with <name> so in the above example I would end up with 3 files:
fred.txt
sue.txt and
bill.txt
and each file would look like this (except with the appropriate name
substituted)
some text
fred
more text
fred
more text etc.
Thanks very much for any help you can provide.
Derek
------------------------------
Date: Wed, 23 Aug 2000 12:52:37 +0200
From: Ulrich Ackermann <uackermann@orga.com>
Subject: Re: Creating new file and substituting data
Message-Id: <39A3ACF5.4237D113@orga.com>
Realware Systems wrote:
>
> Hi perlers,
>
> I have not been using perl for a while, and have not used it a whole lot
> anyway.
>
> I have a little requirement, and I would really appriciate it if someone
> could show me a clean way to do what I need to do.
>
> I have a template file eg.
>
> mytemplate.txt and it looks like this
>
> some text
> %%XXX%%
> more text
> %%XXX%%
> more text etc.
>
> I also have another file that contains names
> fred
> sue
> bill
>
> etc.
>
> I need a script that will read the two files and for each name in the
> name file I need to create a <name>.txt file with the %%XXX%% also
> replaced with <name> so in the above example I would end up with 3 files:
>
> fred.txt
> sue.txt and
> bill.txt
>
> and each file would look like this (except with the appropriate name
> substituted)
>
> some text
> fred
> more text
> fred
> more text etc.
>
> Thanks very much for any help you can provide.
>
> Derek
Hi Derek,
my first try would lead in thefollowing direction:
1. Read the file with the names:
open NAMES, "file_with_names.txt";
my @names = <NAMES>;
2. After setting $/ to undef I would slurp in the complete template
file, presumed it isn't too big:
undef $/;
open TEMPLATE, "template_file.txt";
my $text = <TEMPLATE>;
3. Replace the %%XXX%% n a for(each) loop with the name and write it
into a new file
for (@names) {
$text =~ s/%%XXX%%/$_/g; # Maybe \%\%XXX\%\%
open OUT, ">$_.txt";
print OUT $text;
close OUT;
}
Just a thought. HTH
Ulrich
--
Ulrich Ackermann
ORGA Kartensysteme GmbH (SY-PEAT-STA)
Tel.:+49.5254.991-925
mailto:uackermann@orga.com
------------------------------
Date: 23 Aug 2000 10:05:41 -0000
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Hashref infix misunderstood?
Message-Id: <8o07ll$3pk$1@lublin.zrz.tu-berlin.de>
Soren Andersen <soren@spmfoiler.removethat.wonderstorm.com> wrote in comp.lang.perl.misc:
>kcivey@cpcug.org (Keith Calvert Ivey) wrote in
><39a88016.49085414@news.newsguy.com>:
[...]
>I am not even going to answer the pedant who wasted enormous bandwidth starting
>with ranting about "use strict".
You aren't? To me it looks like you are. I guess it's easier to make
up things when the text you are complaining about isn't in sight. The
"enormous bandwidth" I wasted is a single-line-rant about the lack of
use strict (and the presence of -w).
> I'll "use strict" if I want to.
Certainly. But if you post your code here because it doesn't work,
you will have to put up with critique if you don't use the available
means to make it work. It just takes so much more time to check a
non-strict source for errors.
> And I am not
>interested in anybody's "points" system. I code for love of it, not for esteem
>in the eyes of others (ego). There are a whole buncha attitudinal things that
>have gone incredibly too far in this Perl ng psuedo-world. Bunches of wannabee
>teachers who arrogantly pontificate instead of (if they see it) just pointing
>out what isn't working and why.
Have you even read my posting? I pointed out one gross inefficiency
in your program and an error that will make it fail, except when its
current directory is such that it mysteriously works, both with clear
explanations. I overlooked another serious error and disregarded two
dubious lines (a print statement with side effects, and a warning in
a "can't-happen" situation), pedant that I am. Dammit, I spent *time*
with your posting, probably more than you took preparing it.
> God, it takes all kinds I guess. But my advice
>to new participants: don't emulate what you see going on here. And
>fundamentally don't rely on a ng to learn how to code Perl. Mostly these fora
>are about people expressing their cramped neurotic personalities; good books or
>classes (stuff you pay for) are a better way to learn to program Perl.
Note that most authors of good Perl books, as well as some of the most
renowned teachers of Perl classes, are among the neurotic personalities
who, at least occasionally, express their thoughts here.
I love it when someone who has never contributed much, if anything,
barges in elaborating his opinion of what's wrong with the newsgroup.
Opinions are like assholes. Everybody has one, and they all stink.
Of course you are entitled to yours.
Anno
------------------------------
Date: 23 Aug 2000 10:16:53 -0000
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: help with simple regexp - does my head in
Message-Id: <8o08al$3qh$1@lublin.zrz.tu-berlin.de>
Tina Mueller <news@tinita.de> wrote in comp.lang.perl.misc:
[ @array[ -1] ]
>i don't know how that -1 is implemented, but I bet
>it's more work for perl to find out the last
>element.
Not really. Perl knows where its arrays begin and end.
Anno
------------------------------
Date: 23 Aug 2000 11:55:06 GMT
From: merijnb@iloquent.nl (Merijn Broeren)
Subject: Re: how to generate unreadable from readable perl code
Message-Id: <39a3bb9a$0$1692@heracles>
In article <slrn8q21et.sqb.mgjv@martien.heliotrope.home>,
Martien Verbruggen <mgjv@tradingpost.com.au> wrote:
>Besides, anyone who uses %, @ or $ as a separator for s///, tr///, m//
>or qq and related operators, should be taken outside behind the shed,
>and summarily shot :)
>
And what do you want done to someone that uses , as a separator in real
live production code whenever a / is looked for ? I find that quite
track stopping too...
--
Merijn Broeren | Bob's guide to high explosives for dummies:
Software Geek | Chapter One: When the pin is pulled and safety lever
| discarded, Mr. Grenade is no longer your friend.
------------------------------
Date: Wed, 23 Aug 2000 22:44:13 +1000
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: how to generate unreadable from readable perl code
Message-Id: <slrn8q7hot.5ap.mgjv@martien.heliotrope.home>
On 23 Aug 2000 11:55:06 GMT,
Merijn Broeren <merijnb@iloquent.nl> wrote:
> In article <slrn8q21et.sqb.mgjv@martien.heliotrope.home>,
> Martien Verbruggen <mgjv@tradingpost.com.au> wrote:
> >Besides, anyone who uses %, @ or $ as a separator for s///, tr///, m//
> >or qq and related operators, should be taken outside behind the shed,
> >and summarily shot :)
> >
> And what do you want done to someone that uses , as a separator in real
> live production code whenever a / is looked for ? I find that quite
> track stopping too...
hang them?
Seriously, there are good reasons to avoid / sometimes, particularly
when you're working with a regex that contains one itself. However,
choosing a separator that is one of the abovementioned characters, or as
low visibility, like ',' is silly. What's wrong with '#' (apart from it
breaking simple-minded code parsers)? What's wrong with '!'? What's
wrong with m[REGEXP] or m{REGEXP}? All of those provide very readable
alternatives that don't obscure what you're doing. And using anything
else than m// when not needed is just deliberate obfuscation (unless you
prefer m[] or m{}).
The regexp that makes the very limited set of m//, m!!, m[] not
sufficient to escape the leaning toothpick syndrome is rare enough to
put in an occasional backwhack.
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: Wed, 23 Aug 2000 12:46:35 GMT
From: tebrusca@my-deja.com
Subject: Re: looking for taint resources
Message-Id: <8o0h35$b1t$1@nnrp1.deja.com>
In article <8nts46$1dk$1@lublin.zrz.tu-berlin.de>,
anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) wrote:
> Thomas Brusca <tebrusca@oakland.edu> wrote in comp.lang.perl.misc:
> >Effective Perl book had something close but I want
> >more.
>
> Care to explain what the "something" from _Effective Perl Programming_
> does and where it falls short of your expectations? "Filter input
> on a character level" is hardly an adequate problem description.
Sorry, I want to be able to remove characters like
unprintables but I want to substitute others for something that
won't be interpreted by my app. If someone sends be `rm *`
I want the text but I don't want perl to run `rm *`.
page 145
$pat_in =~ tr/\0-\037\177-\377//d # remove uprintables
$pat_in =~ s/(['\\])/$1/g; # escape quote, backslash
$pat_in =~ /(.*)/; # untaint
$pat = $1;
> >Also would like a collection of regex's for untainting
> >the input. Common things like URL, e-mail, whatever.
>
> Any regex with catching parentheses launders tainted data. What
> you use depends entirely on your security requirements. No-one
> here can tell you what these are.
Your missing the point.
I'm not asking for security requirements.
I want a collection of common regex's (geared for taint).
Why would I reinvent the wheel if someone already has?
I don't want to start from scratch thinking about all possible
variations of a URL so I can match it, nor do I want to match just (.*).
> >Now I could do both things myself, it's not too hard,
> >but I want "The Best Practice"
>
> "It isn't hard, but I prefer someone else do it, you're so much
> better than I am". Pardon, but that sounds a little disingenuous.
>
> Anno
>
Missed the point again, I post to learn, not to get other people to do
my work. I know how I would do it, I want to know how other people
would do it, it makes me think and gives me ideas. I quess I meant
to say, this is a straight forward request and I'm looking for the
best answer. Like if I wanted to know the value of PI, I could
calculate myself or I could looking it up to as many digits as I need.
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Wed, 23 Aug 2000 10:03:08 GMT
From: matt@NOSPAMcipherdesign.com
Subject: Re: lwp post method
Message-Id: <39a3a0ed.7947668@news.ntlworld.com>
i should have also supplied some relevant details from the login page:
--snip--
<form method="post" action="session.asp" name="Login">
--snip--
<input name="username" size="16">
--snip--
<input type="password" name="password" size="16">
--snip--
matt
------------------------------
Date: Wed, 23 Aug 2000 10:15:04 GMT
From: marcel@codewerk.com (Marcel Grunauer)
Subject: Re: lwp post method
Message-Id: <slrn8q790k.7on.marcel@gandalf.local>
On Wed, 23 Aug 2000 09:53:03 GMT, matt@NOSPAMcipherdesign.com
<matt@NOSPAMcipherdesign.com> wrote:
>I have read LWP, LWP:useragent and lwpcook, but can't find why things
>are not working.
In lwpcook, there's a section called "ACCESS TO PROTECTED DOCUMENTS".
Based on that, I've used (some time ago):
$ua = new LWP::UserAgent;
$headers = new HTTP::Headers;
$headers->authorization_basic($uname, $password);
$request = new HTTP::Request("GET", $path, $headers);
$response = $ua->request($request);
--
Marcel Gr\"unauer - Codewerk plc . . . . . . . . . . . <http://www.codewerk.com>
Perl Consulting, Programming, Training, Code review . . . <marcel@codewerk.com>
mod_perl, XML solutions - email for consultancy availability
sub AUTOLOAD{($_=$AUTOLOAD)=~s;^.*::;;;y;_; ;;print} Just_Another_Perl_Hacker();
------------------------------
Date: Wed, 23 Aug 2000 10:21:53 GMT
From: matt@NOSPAMcipherdesign.com
Subject: Re: lwp post method
Message-Id: <39a3a580.9118341@news.ntlworld.com>
thanks,
i thought that section was for those popup boxes that ask for a name
and password. or are they the same thing?
matt
------------------------------
Date: Wed, 23 Aug 2000 10:54:14 GMT
From: Dermot McGahon <dmcgahon@iol.ie>
Subject: negative lookahead assertions in Perl Regex
Message-Id: <8o0agh$3sc$1@nnrp1.deja.com>
Hi,
I have a regex that strips out HTML comments from HTML documents.
It looks like this:
$document =~ s{<!--.*?-->}{}gm;
However, when a browser doesn't know how to process the <SCRIPT
LANGUAGE="Javascript"> tag it often tries to display the javascript as
text so a common ploy to avoid this is to wrap the javascript with
HTML comments so that the browser displays nothing rather than the
javascript. Maybe an example will help:
<script language="JavaScript">
<!--
imBanner1 = new Image ();
imBanner1.src = "images/banner_1.gif";
sBanner1Link = "http://www.forbes.com/asap/00/0403/84b.htm";
//-->
</script>
Non supporting browsers will now display nothing (well probably the
HTML below) rather than mistakingly displaying the javascript.
Anyway, I now need to modify the commment stripping regex so that it
only strips comments when they are not contained with <SCRIPT> and
</SCRIPT>. I thought that negative lookahead assertion might be the
way to go so I tried:
$document =~ s{(<!--.*?-->)(?!\s*</script>)}{}gim;
and
$document =~ s{<!--.*?-->\s*(?!</script>)}{}gim;
and a few other combinations but I can't get it to work as I'd
like. The first regex is matching past the </script> tag, it seems
to be matching until the next "-->" that doesn't have a </script>
tag after it. Of course, that's what I asked it to do :) but the
behaviour that I want is less greedy and I'm not sure how to get
that behaviour.
The second regex matches exactly the same as the original one. It
strips out anything between "<!--" and "-->" and doesn't seem to pay
a blind bit of notice to the </script> tag.
Can anyone edify me as to what I'm doing wrong ?
Dermot.
--
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: 23 Aug 2000 12:24:28 GMT
From: ebohlman@netcom.com (Eric Bohlman)
Subject: Re: negative lookahead assertions in Perl Regex
Message-Id: <8o0fps$mig$1@slb0.atl.mindspring.net>
Dermot McGahon (dmcgahon@iol.ie) wrote:
: Anyway, I now need to modify the commment stripping regex so that it
: only strips comments when they are not contained with <SCRIPT> and
: </SCRIPT>. I thought that negative lookahead assertion might be the
: way to go so I tried:
This will be *far* easier to do, and much more likely to get correct, if
you use HTML::Parser or one of its derivatives (HTML::Filter is a good
candidate) to do this. All you do is subclass it to automatically output
everything but comments, set a flag on seeing <SCRIPT>, clear the flag on
seeing </SCRIPT>, and have it output comments only when the flag is set.
As a bonus, you'll be able to properly handle all HTML comments (which
can contain multiple "--" pairs), rather than just the XML-style ones.
------------------------------
Date: Wed, 23 Aug 2000 12:49:29 GMT
From: zideon@my-deja.com
Subject: Perl and dates
Message-Id: <8o0h8i$b40$1@nnrp1.deja.com>
Hello,
How can I get the week of the year with a Perl script. My webhost
provider hasn't installed the CPAN DATE::CALC module.
Regards,
Zid
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Wed, 23 Aug 2000 10:44:59 GMT
From: af778@iname.com
Subject: Re: Perl/MySQL vs ASP/MS-SQL
Message-Id: <8o09v8$394$1@nnrp1.deja.com>
Thank you very much Malcom and Steve.
My hosting provider only support the "bundle" CGI-Perl/MySQL or
ASP/MSSQL, but I always loved the freedom and I feel that MS is
anything but freedom.
But the lack of subselects in MySQL is frustrating...
I hope it will be supported in next version of the engine. (I saw it
somewhere)...
Do you know of any "big-real-and-know" implementation using MySQL?
Thank you again
Claudio
--------------------------------------------------------------------
Registrá tu dominio .COM por solo $ 14.95 por año.
http://www.registrolibre.com
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: 23 Aug 2000 10:42:54 GMT
From: mgieseki@uos.de (Martin Gieseking)
Subject: problems with regex
Message-Id: <8F998A5CDmgieseki@130.75.2.1>
Hello!
I have to transform many text files with special control sequences into TeX
source files. My problem consists in the variable number of possible parameters
of the commands.
Example: The text files contain commands like this:
{ZT quotation text}{source of quote}
I already wrote a function that enumerates the depth of the curly brackets so
normally it shouldn't be a problem to find corresponding bracket pairs. The
above text is transformed to
{<1>ZT quotation text<1>}{<1>source of quote<1>}
Now alternatively the second bracket pair can be omitted so that my substitute
statement doesn't work:
s/{<(\d+)>ZT[ \n]+(.*?)<\1>}{<(\d+)>(.*?)<\3>}/\\zt{$2}{$4}/gs;
A second line like
s/{<(\d+)>ZT[ \n]+(.*?)<\1>}/\\az{$2}/gs;
doesn't always match because the first line wrongly handels text pieces like
{ZT first quotation} normal text {ZT second quotation}{source}
so that $2 contains parts of the first and second ZT-command.
Does anybody know how to avoid these problems?
Martin
------------------------------
Date: Wed, 23 Aug 2000 12:21:02 GMT
From: tim@degree.ath.cx (Tim Hammerquist)
Subject: Re: Programming Ethics
Message-Id: <slrn8q7h2b.66a.tim@degree.ath.cx>
Soren Andersen <soren@spmfoiler.removethat.wonderstorm.com> wrote:
> tim@degree.ath.cx (Tim Hammerquist) wrote:
>
> >Soren Andersen wrote:
> >> Ordinary people, "even
> >> programmers," need to *not* leave this sort of question up to the
> >> "experts." It is too important to leave up egomaniac talking heads
> >> and pundits.
> >
> >Doesn't that disqualify us en masse?
> Not sure if I take your meaning correctly.
My meaning is that, to some degree, all of us might me disqualified
due to the fact that we are all (at times) egomaniac talking heads
making philosophical speeches about the right and wrong of a purely
subjective field.
It was also a joke. =)
Sorry for any misunderstanding.
--
-Tim Hammerquist <timmy@cpan.org>
Love is the triumph of imagination over intelligence.
-- H. L. Mencken
------------------------------
Date: 23 Aug 2000 10:57:21 -0000
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Rationale Behind 'Use of Uninitialized Value' Warning
Message-Id: <8o0amh$3rv$1@lublin.zrz.tu-berlin.de>
Gabe <grichard@uci.edu> wrote in comp.lang.perl.misc:
>Craig Berry <cberry@cinenet.net> wrote in message
>news:sq5vtf3vt9159@corp.supernews.com...
>
>> This is a stylistic and debugging question. I have found that by
>> enforcing the discipline of insisting on explicit value assignments, I
>> both write more readable code and catch more bugs, more easily. YMMV.
>
>Hmmm. OK, how do you catch more bugs? Here's the situation. I want to assign
>the variable in a loop, but I want it's scope to be out of the loop so I can
>do something with it so my code is like:
>
>my $foo;
>
>while (condition) {
> if (condition) {$foo = 'foo'};
>}
>
>#do something with $foo...
>
>Now why would it be better to say
>
>my $foo = '';
>
>instead?
>
>That is the question.
No, that isn't the question at all. The idea isn't to avoid warnings
by blindly assigning an initial value to every variable. In fact,
yours is a good example where it might be detrimental to do so. If
you leave it undefined, you'll have a way to tell, after the loop,
whether or not a value has been assigned. And when you neglect to test
that and go ahead using it, there'll be a warning. You don't get
these when you assign a value first.
More generally, some actions are explicitly exempt from "uninitialized"
warnings. You can increment undef's just fine, so you don't have to
initialize counters and sum totals. You can also hand down undef's
by assignment, also without warning. In general, Perl does a good job
of warning you of inappropriate use of undef while allowing you
to use undef as 0 or '' where it's handy.
Anno
------------------------------
Date: Wed, 23 Aug 2000 12:10:51 GMT
From: tim@degree.ath.cx (Tim Hammerquist)
Subject: Re: would you recommend buying a book
Message-Id: <slrn8q7gf8.66a.tim@degree.ath.cx>
On Mon, 21 Aug 2000 12:54:25 GMT, Jan Heidbrink <jan.heidbrink@gmx.net> wrote:
> I'm planning to learn pearl. I'll mainly use it for CGI.
Sure. Fine. Perl is famous as a CGI language, but why limit yourself?
> Would you recommend to buy a book (if yes, where can I find an
> overview about some) or do you think, a free tutorial is enough? I'd
> prefer the last one as I don't have very much money. However, if you
> think that I should buy a good book, I'd do that.
Book advice: If it's published by O'Reilly and includes Perl in the
title, it's worth the money.
Online/Free doc advice: perldoc
> BTW: I'm already familiar with Pascal and C++.
C++ _might_ actually hold you back. It did me. I spent too long trying
to program Perl like I programmed C/C++. They're completely different
animals. Every day that I know perl, it gets harder to look at my C/C++
code and not say, "...and I was content with that?!"
--
-Tim Hammerquist <timmy@cpan.org>
Not all who wander are lost.
-- J.R.R. Tolkien
------------------------------
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 4104
**************************************