[23964] in Perl-Users-Digest
Perl-Users Digest, Issue: 6165 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Feb 19 14:05:38 2004
Date: Thu, 19 Feb 2004 11:05:08 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Thu, 19 Feb 2004 Volume: 10 Number: 6165
Today's topics:
Re: Beginner question on @INC <emschwar@pobox.com>
Re: can s/// return a new value, rather than modifying <nobull@mail.com>
Re: can s/// return a new value, rather than modifying (Randal L. Schwartz)
Re: can s/// return a new value, rather than modifying <uri@stemsystems.com>
Re: finding the last match before a first match (regex) <xx087@freenet.carleton.ca>
Re: finding the last match before a first match (regex) <nobull@mail.com>
Re: Listbox and passing entries <jwillmore@remove.adelphia.net>
Re: Listbox and passing entries <dha@panix.com>
Re: Listbox and passing entries <flavell@ph.gla.ac.uk>
Re: map, for, and while <noreply@gunnar.cc>
Re: map, for, and while <nobull@mail.com>
Re: method reference - repost <uri@stemsystems.com>
Re: method reference - repost <uri@stemsystems.com>
Re: method reference - repost <uri@stemsystems.com>
Re: method reference - repost <fifo@despammed.com>
Re: Multiple substitution in a complex RE <uri@stemsystems.com>
perl controlling samba permissions? (Anthony Boyd)
Re: perl <spamtrap@dot-app.org>
PerlSAX <ihatespam@hotmail.com>
Re: Replacing a text in multiple files with regular exp <tadmc@augustmail.com>
Re: Tie a file to a hash <usenet@morrow.me.uk>
Tie a large file to a Hash <gkincade1@austin.rr.com>
TMTOWTDI <graham@cs.man.ac.uk>
Re: TMTOWTDI <fifo@despammed.com>
Re: Unexpected chomp() results <xx087@freenet.carleton.ca>
Re: Unexpected chomp() results <exide@comcast.net>
Re: Unexpected chomp() results <uri@stemsystems.com>
what is ^K? <bdu@iastate.edu>
Re: what is ^K? <xx087@freenet.carleton.ca>
Re: what is ^K? <bdu@iastate.edu>
Re: what is ^K? <nobull@mail.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Thu, 19 Feb 2004 10:52:28 -0700
From: Eric Schwartz <emschwar@pobox.com>
Subject: Re: Beginner question on @INC
Message-Id: <etoeksrdkir.fsf@fc.hp.com>
"Geedunk" <root@nowhere.com> writes:
> However, I (respectfully) think that you are falling into the usual
> thought routine of someone familiar with the ground. While delivered
> documentation is invaluable to someone who is fairly familiar with what he
> is trying to do, some of the man pages and docs might as well be written
> in South Martian for all the good they do a beginner.
Then tell us what's wrong with them! But if you don't at least make
an effort to understand the docs, then people will increasingly assume
that you are only interested in having other people read them for you,
which is very strongly demotivating. Maybe it's not true, but that's
what it's going to appear.
> I suspect that if you yourself pick a topic that you know absolutely
> nothing about and try to get bootstrapped from the written-for-techie man
> pages, you will also wonder what the heck the writer was drinking when
> he/she wrote the stuff. You may have a different opinion.
You may be right, but when I ask a question, I will say, "I read the
docs for the Illudium Q-36 Explosive Space Modulator, and the section
on Coping with Earth-based Rabbits completely makes no sense. I don't
understand the directions to 'RUN AWAY'." I will not say, "How do I
use this thing again?", or even "I want to destroy the Earth, with
Perl. Pls advice."
-=Eric
--
Come to think of it, there are already a million monkeys on a million
typewriters, and Usenet is NOTHING like Shakespeare.
-- Blair Houghton.
------------------------------
Date: 19 Feb 2004 18:40:48 +0000
From: Brian McCauley <nobull@mail.com>
Subject: Re: can s/// return a new value, rather than modifying it's input argument?
Message-Id: <u98yiyewun.fsf@wcl-l.bham.ac.uk>
Uri Guttman <uri@stemsystems.com> writes:
> >>>>> "BM" == Brian McCauley <nobull@mail.com> writes:
> >> why do you return the last element of @values in scalar context?
> >> wouldn't the first be just as arbitrary?
> BM> One of the many possible behaviours is for scalar(EXPR) to be
> BM> equivalent to (EXPR)[0] and another is for it to be equivalent to
> BM> (EXPR)[-1].
>
> i know that. i was asking why you chose -1 and not the more 'normal'
> 0?
Well I answered that already (but for some reason you clipped it from
your quote).
I chose -1 because -1 is normal and 0 is not.
Here are a few EXPRs for which scalar(EXPR) is the same as (EXPR)[-1]
5,6
@a[1,2]
@a{'foo','bar'}
\(foo)
Can you list any EXPRs for which scalar(EXPR) is the same as
(EXPR)[0] and not (EXPR)[-1] ?
> in the typical case of a single value they do the same thing. now, it
> would be silly to call it with multiple values and use only one since
> the applied function works on copies that are thrown away.
Yes indeed, as a say below, apply() could carp() (or even croak()) if
called in a scalar context with a list of length other than one in
scalar context because it is nonsensical to do so.
But then again Perl doesn't warn if you use a slice in a scalar
context. IMNSHO it should. This would make far more sense than the
frequently annoying "Scalar value @%s{%s} better written as $%s{%s}"
warning.
> >> why not check for the number of arguments passed in as well?
>
> BM> Because conceptually the function takes two arguments, the second one
> BM> being a LIST. I considered thay I should carp() (or even croak()) if
> BM> called in a scalar context with a list of length other than one. But
> BM> I decided the cost was warranted. If and when I ever get a round tuit
> BM> the XS version of apply() will do so.
>
> you missed what i said.
No I didn't.
> of course there is a function as the first
> arg. i meant check the rest of @_ and change behavior according to
> that. a classic thing that does this are accessor methods (the kind
> without get/set). no args is get, one or more args is set. the $self
> arg is not counted.
No _you_ missed what I said. Please don't assume that every time I
disagree with you I've failed to understand what you've said. Many a
time I understand perfectly and I still disagree.
> >> return @values if wantarray ;
> >> return \@values if @_ > 1 ;
> >> return $values[0] ;
>
> BM> I think having the return value change type based on the length of
> BM> the list is conceptually ugly and more importantly a bug waiting
> BM> to happen.
>
> see my accessor example above. it is very common.
No, that's compeltely different. An accessor conceptually takes zero
or one scalar arguments. If methods could have prototypes the
accessor's would be (;$). apply() has the prototype (&@) so it's
arguments are a function and a LIST. The length of that list can
meaningfully be 0,1 or more but it's still conceptually a list in all
cases.
> BM> Consider:
>
> BM> my $foo = apply { s/this/that/ } @bar;
>
> BM> I'm either expecting $foo to contain an arrayref or I'm not. I
> BM> certainly don't expect it to be dependant on $#bar!
>
> you could force it to be an array ref by wrapping it in [] at the cost
> of an extra copy.
Yes indeed so there is no gain having apply return an array ref since
whenever you wanted an array ref you'd always have to put in the []
just in case $#bar==0.
> anyhow, i have never seemed to want this apply thing.
Diabetic? :-)
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: Thu, 19 Feb 2004 18:52:41 GMT
From: merlyn@stonehenge.com (Randal L. Schwartz)
To: Brian McCauley <nobull@mail.com>
Subject: Re: can s/// return a new value, rather than modifying it's input argument?
Message-Id: <11d00f2757335cc140e2556d2bd014c4@news.teranews.com>
>>>>> "Brian" == Brian McCauley <nobull@mail.com> writes:
Brian> Here are a few EXPRs for which scalar(EXPR) is the same as (EXPR)[-1]
Brian> 5,6
Brian> @a[1,2]
Brian> @a{'foo','bar'}
Brian> \(foo)
Brian> Can you list any EXPRs for which scalar(EXPR) is the same as
Brian> (EXPR)[0] and not (EXPR)[-1] ?
getpwuid($uid)
Brian> But then again Perl doesn't warn if you use a slice in a scalar
Brian> context. IMNSHO it should. This would make far more sense than the
Brian> frequently annoying "Scalar value @%s{%s} better written as $%s{%s}"
Brian> warning.
No, because then I couldn't do this:
my $result = 3 + (/(\d\d\d)/)[0];
And yes, there have been times where I needed the first return
from a list in a scalar context just like that, in real coding.
--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
------------------------------
Date: Thu, 19 Feb 2004 16:41:40 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: can s/// return a new value, rather than modifying it's input argument?
Message-Id: <x7n07fnhrw.fsf@mail.sysarch.com>
>>>>> "BM" == Brian McCauley <nobull@mail.com> writes:
BM> sub apply (&@) {
BM> my $action = shift;
BM> &$action for my @values = @_;
BM> wantarray ? @values : $values[-1];
BM> }
>>
>> why do you return the last element of @values in scalar context?
>> wouldn't the first be just as arbitrary?
BM> There is, as you know, no general way to infer from the behaviour of
BM> EXPR in a list context how EXPR will behave in a scalar context.
BM> One of the many possible behaviours is for scalar(EXPR) to be
BM> equivalent to (EXPR)[0] and another is for it to be equivalent to
BM> (EXPR)[-1].
i know that. i was asking why you chose -1 and not the more 'normal' 0?
in the typical case of a single value they do the same thing. now, it
would be silly to call it with multiple values and use only one since
the applied function works on copies that are thrown away.
>> why not check for the number of arguments passed in as well?
BM> Because conceptually the function takes two arguments, the second one
BM> being a LIST. I considered thay I should carp() (or even croak()) if
BM> called in a scalar context with a list of length other than one. But
BM> I decided the cost was warranted. If and when I ever get a round tuit
BM> the XS version of apply() will do so.
you missed what i said. of course there is a function as the first
arg. i meant check the rest of @_ and change behavior according to
that. a classic thing that does this are accessor methods (the kind
without get/set). no args is get, one or more args is set. the $self
arg is not counted.
>> $action->() for my @values = @_;
>> return @values if wantarray ;
>> return \@values if @_ > 1 ;
>> return $values[0] ;
BM> I think having the return value change type based on the length of
BM> the list is conceptually ugly and more importantly a bug waiting
BM> to happen.
see my accessor example above. it is very common.
BM> Consider:
BM> my $foo = apply { s/this/that/ } @bar;
BM> I'm either expecting $foo to contain an arrayref or I'm not. I
BM> certainly don't expect it to be dependant on $#bar!
you could force it to be an array ref by wrapping it in [] at the cost
of an extra copy.
anyhow, i have never seemed to want this apply thing. i just work on
data as needed. for those who like to use it, it is fine. i just do
direct for/map as i need.
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
------------------------------
Date: 19 Feb 2004 16:22:00 GMT
From: Glenn Jackman <xx087@freenet.carleton.ca>
Subject: Re: finding the last match before a first match (regex)
Message-Id: <slrnc39ol8.dm5.xx087@smeagol.ncf.ca>
Greg Carlson <gregfcarlson@hotmail.com> wrote:
[...]
> That makes sense. So how would I find the last 'a' before the _first_ 'foo'?
> My latest attempt is:
>
> $tmp = 'abcdefgabcdefgfooabcdefgfoo';
As Dave Cardwell posted earlier:
my ($stuff) = $tmp =~ /(a[^a]*foo)/;
--
Glenn Jackman
NCF Sysadmin
glennj@ncf.ca
------------------------------
Date: 19 Feb 2004 19:01:42 +0000
From: Brian McCauley <nobull@mail.com>
Subject: Re: finding the last match before a first match (regex)
Message-Id: <u94qtmevvt.fsf@wcl-l.bham.ac.uk>
"Greg Carlson" <gregfcarlson@hotmail.com> writes:
> "Brian McCauley" <nobull@mail.com> writes:
>
> > If 'a' really is a single character then see other response.
I shall assume that since you are still persuing this approach that in
your real problem 'a' is not a single character.
> > /(.*)(a.*foo)/
> >
> > Note this actually matches both everything before the desired target
> > and the desired target. Note also this finds the last 'a' before the
> > _last_ 'foo'.
>
> That makes sense. So how would I find the last 'a' before the _first_ 'foo'?
> My latest attempt is:
>
> $tmp = 'abcdefgabcdefgfooabcdefgfoo';
> $tmp =~ m/(foo)/ogcs;
Don't put qualifiers on m// that you don't understand. /os have no
effect in the above line so if you understood them you'd not have used
them. :-)
> [do stuff with $1] # this part works as I'd hoped
Don't ever do stuff with $1 without first checking that the match
succeded. If you are sure that the match will succeded always then
append "or die" to it. This serves a dual function. Firstly it acts
a comment to anyone who reads your program meaning "I don't think this
match can ever fail". Secondly if it turns out you were wrong Perl
will tell you.
> $tmp = substr($tmp, 0, pos($tmp));
> $tmp =~ m/.*(a).+?$/os;
> But that still got the first 'a'. Also, $tmp can be rather large so the
> substr is a bit distasteful. Is there any way to search backward from the
> current pos or something similar?
Yes, this is what \G is for - it anchors a regex at the current
pos()ition.
$_ = 'abcdefgabcde-FIRST-fooabcdefg-SECOND-foo';
# I assume pos()==0 initially
# Set pos() to be the end of first 'foo'
/foo/gc or die "no foo";
# Extract everything from the last 'a' before the current position
# to the current position.
/.*(a.*)\G/ or die "no a before first foo";
print "$1\n";
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: Thu, 19 Feb 2004 12:20:49 -0500
From: James Willmore <jwillmore@remove.adelphia.net>
Subject: Re: Listbox and passing entries
Message-Id: <pan.2004.02.19.17.20.47.226879@remove.adelphia.net>
On Thu, 19 Feb 2004 07:37:06 +0000, Old School wrote:
> Keith, I'm not "ignoring" anything. I simply had a few questions and the
> two responses have been troll-like encounters. If you don't know the
> answer. Fine. But, I don't need a lecture from a couple of abecedarians...
the cgi-lib.pl homepage: http://cgi-lib.berkeley.edu/
You will take notice to the CVS header that the LAST time it was updated
in 1999 (1999/02/23 to be exact). There have been MANY CGI security
advisories scine that time - which is why NO reputable or experienced Perl
programmer uses it.
To put it bluntly - you will find no help here, because ANY reputable and
experienced Perl programmer will use CGI.pm - period.
There are several resources on how to write *secure* CGI scripts - I
suggest you read them - because it sounds like you think writing a CGI
script is a trival process and it isn't.
--
Jim
Copyright notice: all code written by the author in this post is
released under the GPL. http://www.gnu.org/licenses/gpl.txt
for more information.
a fortune quote ...
"I do not fear computers. I fear the lack of them." -- Isaac
<Asimov
------------------------------
Date: Thu, 19 Feb 2004 17:27:49 +0000 (UTC)
From: "David H. Adler" <dha@panix.com>
Subject: Re: Listbox and passing entries
Message-Id: <slrnc39sgl.fks.dha@panix2.panix.com>
In article <c8p01c.v33.ln@goaway.wombat.san-francisco.ca.us>, Keith
Keller wrote:
> If you choose to ignore the advice you've been given, that's your
> prerogative. But cgi-lib.pl is not the Perl standard for CGI coding any
> longer, so if your hosting company can't provide CGI.pm perhaps you
> should switch hosting companies.
A lack of CGI.pm also makes me question just how old a perl distribution
his host has installed...
dha
--
David H. Adler - <dha@panix.com> - http://www.panix.com/~dha/
And if you are a real looney, you would read the manpage.
- Abigail in c.l.p.misc
------------------------------
Date: Thu, 19 Feb 2004 18:50:47 +0000
From: "Alan J. Flavell" <flavell@ph.gla.ac.uk>
Subject: Re: Listbox and passing entries
Message-Id: <Pine.LNX.4.53.0402191847350.31533@ppepc56.ph.gla.ac.uk>
On Thu, 19 Feb 2004, David H. Adler wrote:
> A lack of CGI.pm also makes me question just how old a perl distribution
> his host has installed...
Possibly so; but I've heard of a number of cases where web service
providers have deliberately removed components from an otherwise
fairly recent Perl installation - for whatever inscrutable reason they
might have had.
Without wanting to re-open old arguments, one _does_ have to wonder at
the thought processes of a provider who allows their customers access
to CGI facilities from Perl, but denies them the use of CGI.pm.
------------------------------
Date: Thu, 19 Feb 2004 17:43:01 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: map, for, and while
Message-Id: <c12pvk$1cs2k8$1@ID-184292.news.uni-berlin.de>
J Krugman wrote:
> With map, one can streamline for-loops like this one:
>
> my @array_2;
> push @array_2, some_sub($_) for @array_1;
>
> into a single assignment:
>
> my @array_2 = map some_sub($_), @array_1;
>
> Is there a way (not necessarily using map) to streamline
> while-loops like this one:
>
> my @array;
> push @array, some_other_sub() while some_condition();
>
> into a single assignment to @array?
How about using map()?
my @array = map some_sub($_), <FH>;
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: 19 Feb 2004 18:08:26 +0000
From: Brian McCauley <nobull@mail.com>
Subject: Re: map, for, and while
Message-Id: <u9hdxndjs5.fsf@wcl-l.bham.ac.uk>
J Krugman <jill_krugman@yahoo.com> writes:
> With map, one can streamline for-loops like this one:
>
> my @array_2;
> push @array_2, some_sub($_) for @array_1;
>
> into a single assignment:
>
> my @array_2 = map some_sub($_), @array_1;
>
> Is there a way (not necessarily using map) to streamline while-loops
> like this one:
>
> my @array;
> push @array, some_other_sub() while some_condition();
>
> into a single assignment to @array?
I don't think you'll find a way that's more efficient.
Anyhow, the subroutine-call overhead (let alone whatever's in the
subroutines) is likely to be the largest part of the time so there's
no point worrying about finding a better way to concatenate the return
values from some_other_sub().
#!/usr/bin/perl
use strict;
use warnings;
use Benchmark;
my $i;
sub some_other_sub { 1 }
sub some_condition { $i-- }
timethese(1000,{
subs => sub {
my @array;
$i = 1000;
push @array, some_other_sub() while some_condition();
},
nosubs => sub {
my @array;
$i = 1000;
push @array, 1 while $i--;
},
});
__END__
Benchmark: timing 1000 iterations of nosubs, subs...
nosubs: 1 wallclock secs ( 0.76 usr + 0.00 sys = 0.76 CPU) @ 1315.79/s (n=1000)
subs: 3 wallclock secs ( 2.88 usr + 0.00 sys = 2.88 CPU) @ 347.22/s (n=1000)
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: Thu, 19 Feb 2004 16:30:14 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: method reference - repost
Message-Id: <x7vfm3niax.fsf@mail.sysarch.com>
>>>>> "f" == fifo <fifo@despammed.com> writes:
f> Though if you really want to I believe you can cheat some somewhat. The
f> following should work:
f> $o->${ \$o->{lst}[0] }();
f> $o->${ \$t->[0] }();
have you tested that?
perl -e '$o=bless {}; $o->${'xyz'}()'
Can't locate object method "" via package "main" (perhaps you forgot to load "main"?) at -e line 1.
the problem is that perl parses that at $o->( ${'xyz'}() ).
like i said, the method has to be a bareword or a single scalar
VARIABLE. this is documented (but not worded strongly enough IMO) in
perlobj
Sometimes you want to call a method when you don't know the
method name ahead of time. You can use the arrow form,
replacing the method name with a simple scalar variable
containing the method name or a reference to the function.
$method = $fast ? "findfirst" : "findbest";
$fred->$method(@args); # call by name
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
------------------------------
Date: Thu, 19 Feb 2004 16:33:30 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: method reference - repost
Message-Id: <x7smh7ni5h.fsf@mail.sysarch.com>
>>>>> "BM" == Ben Morrow <usenet@morrow.me.uk> writes:
BM> Uri Guttman <uri@stemsystems.com> wrote:
NS> how could it be called without creating the intermediate $m ?
>>
>> can't be done. it has nothing to do with how you get the dynamic
>> method. the method slot of a call must be a single scalar variable or
>> bareword. it can't be an expression.
BM> Howsabout (not exactly clear, but...:)
BM> $obj->can($obj->{lst}[0])->($obj, 20);
BM> ?
that isn't selecting the method but getting back a code ref. not the
same thing. and i am not even sure that will be a method call there
since there is no method being used in the final call. try it out and i
bet it is just a sub call. you would need to store the result of can in
a var and call it like a normal method call with that var in the method
slot.
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
------------------------------
Date: Thu, 19 Feb 2004 16:35:00 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: method reference - repost
Message-Id: <x7ptcbni2z.fsf@mail.sysarch.com>
>>>>> "AS" == Anno Siegel <anno4000@lublin.zrz.tu-berlin.de> writes:
>> can't be done. it has nothing to do with how you get the dynamic
>> method. the method slot of a call must be a single scalar variable or
>> bareword. it can't be an expression.
AS> Well, it can, but the expression would have to return a coderef, not the
AS> method name. I don't think that is what the OP had in mind.
see my other posts on this. the syntax requires a literal method or a
scalar variable in the method slot. you can put a code ref value in
there but there can't be an expression in that slot.
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
------------------------------
Date: Thu, 19 Feb 2004 18:38:47 +0000
From: fifo <fifo@despammed.com>
Subject: Re: method reference - repost
Message-Id: <20040219183844.GC14410@fleece>
At 2004-02-19 16:30 +0000, Uri Guttman wrote:
> >>>>> "f" == fifo <fifo@despammed.com> writes:
>
> f> Though if you really want to I believe you can cheat some somewhat. The
> f> following should work:
>
> f> $o->${ \$o->{lst}[0] }();
> f> $o->${ \$t->[0] }();
>
> have you tested that?
>
> perl -e '$o=bless {}; $o->${'xyz'}()'
> Can't locate object method "" via package "main" (perhaps you forgot to load "main"?) at -e line 1.
>
I had in mind something like
perl -e '$o=bless{me=>"Hi"}; $t->[0]=sub{my $self = shift; print $self->{me}}; $o->${\$t->[0]}()'
which seems to work.
------------------------------
Date: Thu, 19 Feb 2004 16:07:56 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Multiple substitution in a complex RE
Message-Id: <x7y8qznjc3.fsf@mail.sysarch.com>
>>>>> "S" == SqlSlinger <vince.iacoboni@db.com> writes:
S> Uri Guttman <uri@stemsystems.com> wrote in message news:<x7vfm4utep.fsf@mail.sysarch.com>...
>> >>>>> "GJ" == Glenn Jackman <xx087@freenet.carleton.ca> writes:
>>
>>
GJ> my @vars = qw(VARIABLE_ONE VARIABLE_NUMBER_TWO
GJ> a_really_long_VARIABLE_name);
>>
GJ> foreach (@vars) {
GJ> my $var = ucfirst lc;
GJ> $var =~ s/_(.)/\U$1/g;
GJ> }
>>
>> s/_?(.)([^_]*)/\U$1\L$2/g ;
>>
>> uri
S> Nice and compact, but doesn't isolate only variables containing an
S> underscore. If run against a source file, would match any word,
S> right?
probably but that could be fixed with some guard regex stuff. and it
wasn't in the spec which showed a qw list of tokens. you need to code to
what is posted (unless it is obvious the OP is having an XY problem or
way off base).
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
------------------------------
Date: 19 Feb 2004 10:49:56 -0800
From: usenet@outshine.com (Anthony Boyd)
Subject: perl controlling samba permissions?
Message-Id: <cebfe83a.0402191049.5099e059@posting.google.com>
I have a Linux box that is going to share a directory via Samba.
People will be authorized to use the share via LDAP. They may change
the file permissions (on the Samba/Windows side, but the Linux
permissions should remain unchanged).
I wanted to have a PHP script read the Samba permissions set on each
file, and display that via a Web page. PHP doesn't appear up to the
task (but it can get/set Linux permissions OK).
Can Perl handle this? I thought Filesys::SmbClient might work, but
the docs imply Linux permissions can be changed, not the Windows side.
------------------------------
Date: Thu, 19 Feb 2004 13:16:09 -0500
From: Sherm Pendley <spamtrap@dot-app.org>
Subject: Re: perl
Message-Id: <IvGdnRJ74Jv0YKnd4p2dnA@adelphia.com>
prabs wrote:
> how to get a http request header in perl?
It depends on what end of the connection you're on.
Client: perldoc LWP
Server: perldoc CGI
sherm--
------------------------------
Date: Thu, 19 Feb 2004 10:47:30 -0800
From: BigDaDDY <ihatespam@hotmail.com>
Subject: PerlSAX
Message-Id: <103a14oqjtucuec@corp.supernews.com>
I'm relatively new at the XML parsing stuff, but I've been reading
O'Reilly's XML & Perl and I noticed that the SAX parsers use handles for
special events like start tag and character data. What would you do if you
wanted to capture the character data into a variable depending on what the
start tag is? In other words, in my particular application the tags and
the character data are not necessarily decoupled. Do I really have to use
XPath to do this, or can I use the SAX parser to get to the character data
based on the value of the tag?
Also, are the SAX and DOM parsers the best parsers available now or is
there something better that someone may be able to recommend?
Thanks,
Matt
------------------------------
Date: Thu, 19 Feb 2004 12:17:52 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Replacing a text in multiple files with regular expressions
Message-Id: <slrnc39veg.3uh.tadmc@magna.augustmail.com>
Angel <anichin@vip.bg> wrote:
> The problem is that wildcards does not work with my
> perl on Windows XP.
But you can make "wildcards" work yourself by using:
perldoc -f glob
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Thu, 19 Feb 2004 19:04:26 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: Tie a file to a hash
Message-Id: <c131bq$3po$1@wisteria.csv.warwick.ac.uk>
"SpecialK" <gkincade1@austin.rr.com> wrote:
> Does anyone know how to tie a large file to a hash without using shared
> memory?
> I know I can use Tie::File to tie the file to an array and from the array
> create a hash, but I need something that is much faster than that?
How do you want the file to be tied? In particular, what do you want to
be the keys and what the values of the hash?
Ben
--
Razors pain you / Rivers are damp
Acids stain you / And drugs cause cramp. [Dorothy Parker]
Guns aren't lawful / Nooses give
Gas smells awful / You might as well live. ben@morrow.me.uk
------------------------------
Date: Thu, 19 Feb 2004 17:28:20 GMT
From: "SpecialK" <gkincade1@austin.rr.com>
Subject: Tie a large file to a Hash
Message-Id: <Um6Zb.9848$jl.8784@fe2.texas.rr.com>
Does anyone know how to tie a large file to a Hash using IPC::Shareable?
Code fragments would be most helpful.
thanx,
greg
------------------------------
Date: 19 Feb 2004 17:02:15 +0000
From: Graham Gough <graham@cs.man.ac.uk>
Subject: TMTOWTDI
Message-Id: <ttlu11n9f54.fsf@sphere.cs.man.ac.uk>
I have been trying to solve a problem in which I wish to substitute
for *almost* all occurrences of a regular expression. For example all
occurrences of \d\d\d\d except some specific ones. I ended up with
using the e modifier and code like that given below, but had a nagging
felling that there was probably some more elegant method. Anyone any
suggestions?
Graham
$text =~ s/(\d\d\d\d)/&choose($1,"1234")/ge;
sub choose {
my $val = shift;
my $notpat = shift;
my $ret=$val;
if (!($val =~ /$notpat/)) {
$ret = "XX" . $ret . "XX";
}
return $ret;
}
------------------------------
Date: Thu, 19 Feb 2004 18:46:16 +0000
From: fifo <fifo@despammed.com>
Subject: Re: TMTOWTDI
Message-Id: <20040219184612.GD14410@fleece>
At 2004-02-19 17:02 +0000, Graham Gough wrote:
> I have been trying to solve a problem in which I wish to substitute
> for *almost* all occurrences of a regular expression. For example all
> occurrences of \d\d\d\d except some specific ones. I ended up with
> using the e modifier and code like that given below, but had a nagging
> felling that there was probably some more elegant method. Anyone any
> suggestions?
>
> Graham
>
> $text =~ s/(\d\d\d\d)/&choose($1,"1234")/ge;
>
> sub choose {
> my $val = shift;
> my $notpat = shift;
> my $ret=$val;
> if (!($val =~ /$notpat/)) {
> $ret = "XX" . $ret . "XX";
> }
> return $ret;
> }
>
How about
$text =~ s/(?!1234)(\d{4})/XX$1XX/g;
------------------------------
Date: 19 Feb 2004 16:17:58 GMT
From: Glenn Jackman <xx087@freenet.carleton.ca>
Subject: Re: Unexpected chomp() results
Message-Id: <slrnc39odm.dm5.xx087@smeagol.ncf.ca>
Exide Arabellan <exide@comcast.net> wrote:
[...]
> 4. use IO::Socket;
[...]
> 29. while (my $client = $server->accept()) {
> 30. $client->autoflush(1);
> 31. print $client "username: ";
> 32. while (<$client>) {
> 33. my $login_attempt;
> 34. $login_attempt = $_;
> 35. chomp($login_attempt);
[...]
> Returns:
> ' does not exist. Please try again.
> Instead of:
> Account 'foo' does not exist. Please try again.
Aren't lines sent over a TCP socket terminated with "\r\n"?
If so, chomp is insufficient with the default $/, because it won't
remove the \r.
Set $/="\r\n" before line 29, or wrap that while loop with:
{
local $/ = "\r\n";
while (my $client = $server->accept()) { ... }
}
--
Glenn Jackman
NCF Sysadmin
glennj@ncf.ca
------------------------------
Date: Thu, 19 Feb 2004 08:24:19 -0800
From: Exide Arabellan <exide@comcast.net>
Subject: Re: Unexpected chomp() results
Message-Id: <JOidnVhXNfiyfqndRVn-hA@comcast.com>
Glenn Jackman wrote:
> Aren't lines sent over a TCP socket terminated with "\r\n"?
> If so, chomp is insufficient with the default $/, because it won't
> remove the \r.
>
> Set $/="\r\n" before line 29, or wrap that while loop with:
> {
> local $/ = "\r\n";
> while (my $client = $server->accept()) { ... }
> }
That was it :) I figured it was something to do with 'print'ing over a
socket. Thanks for the help.
------------------------------
Date: Thu, 19 Feb 2004 16:48:16 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Unexpected chomp() results
Message-Id: <x7k72jnhgv.fsf@mail.sysarch.com>
>>>>> "EA" == Exide Arabellan <exide@comcast.net> writes:
EA> 32. while (<$client>) {
EA> 33. my $login_attempt;
EA> 34. $login_attempt = $_;
why all the copying and declaring?
while (my $login_attempt = <$client>) {
EA> 35. chomp($login_attempt);
EA> 36. print $client "Account '".$login_attempt."' does not
EA> exist. Please try again.";
EA> 37. }
EA> 38. }
EA> ---
EA> Returns:
EA> ' does not exist. Please try again.
EA> Instead of:
EA> Account 'foo' does not exist. Please try again.
you are probably reading a line with cr/lf ending from the server and
chomping away only the lf (\n). chomp uses $/ which had a platform
default. the symptom you see is the cr causing the line to overwrite
part of itself when printing on a screen. the data was output, but you
just don't see it all.
several solutions. the simplest is to do a real strip with a regex:
$login_attempt =~ s/[\r\n]+\z// ;
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
------------------------------
Date: Thu, 19 Feb 2004 10:14:01 -0600
From: Bing Du <bdu@iastate.edu>
Subject: what is ^K?
Message-Id: <c12ncf$o2l$1@news.iastate.edu>
Greetings,
Maybe this is not direcly Perl related...
I'm using Perl (v5.8.0) on Linux (RedHat 9) to process a text file
transferred from Windows to Unix. When I used 'vi' to open the text
file, I saw a lot ^K. In perl, how can I get rid of it? I know I can
use '$line =~ s/\r//g' to remove ^M. What about ^K?
Thanks in advance for any help,
Bing
------------------------------
Date: 19 Feb 2004 16:26:59 GMT
From: Glenn Jackman <xx087@freenet.carleton.ca>
Subject: Re: what is ^K?
Message-Id: <slrnc39ouj.dm5.xx087@smeagol.ncf.ca>
Bing Du <bdu@iastate.edu> wrote:
> file, I saw a lot ^K. In perl, how can I get rid of it? I know I can
> use '$line =~ s/\r//g' to remove ^M. What about ^K?
s/\013//g
--
Glenn Jackman
NCF Sysadmin
glennj@ncf.ca
------------------------------
Date: Thu, 19 Feb 2004 10:42:12 -0600
From: Bing Du <bdu@iastate.edu>
To: Glenn Jackman <xx087@freenet.carleton.ca>
Subject: Re: what is ^K?
Message-Id: <4034E764.6070203@iastate.edu>
Oh, great. Thanks a lot for your instant response!
Bing
Glenn Jackman wrote:
> Bing Du <bdu@iastate.edu> wrote:
>
>> file, I saw a lot ^K. In perl, how can I get rid of it? I know I can
>> use '$line =~ s/\r//g' to remove ^M. What about ^K?
>
>
> s/\013//g
>
>
------------------------------
Date: 19 Feb 2004 18:11:56 +0000
From: Brian McCauley <nobull@mail.com>
Subject: Re: what is ^K?
Message-Id: <u9d68bdjmb.fsf@wcl-l.bham.ac.uk>
Glenn Jackman <xx087@freenet.carleton.ca> writes:
> Bing Du <bdu@iastate.edu> wrote:
> > file, I saw a lot ^K. In perl, how can I get rid of it? I know I can
> > use '$line =~ s/\r//g' to remove ^M. What about ^K?
>
> s/\013//g
That removes character with octal encoding 013. This of course is
control-K. But there is a way in Perl to say control-K more directly.
s/\cK//g;
Also I'd probably favour tr///d
tr/\cK//d;
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
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 6165
***************************************