[19266] in Perl-Users-Digest
Perl-Users Digest, Issue: 1461 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Aug 8 06:05:31 2001
Date: Wed, 8 Aug 2001 03:05:09 -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: <997265109-v10-i1461@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Wed, 8 Aug 2001 Volume: 10 Number: 1461
Today's topics:
Re: $ENV{'HTTP_REFERER'} slash@dot.c.o.m.org
Re: $ENV{'REMOTE_ADDR'} <jeff_haralson@qwest.net>
Easy array question ? <philippe.perrin@sxb.bsf.alcatel.fr>
Re: Easy array question ? <brentdax1@earthlink.net>
Re: Engineering vs. Hacking (was Re: How to supply modu slash@dot.c.o.m.org
Re: For loop aliasing?? <krahnj@acm.org>
Re: For loop aliasing?? (Eric Bohlman)
Re: get rid of these leading zeros in Perl <brentdax1@earthlink.net>
getting the name of a sub <peter@t-online.de>
Re: getting the name of a sub <Tassilo.Parseval@post.rwth-aachen.de>
Re: How to print a binary string as picture to web page slash@dot.c.o.m.org
installing modules (xml::sablotron) on win32/activestat <kmojar@bmjgroup.com>
Re: Line counting in a file (Anno Siegel)
my final word - i'll listen, though [Re: Pattern Matchi <gimi@psico.ch>
Re: Passing scalar by reference?? <brentdax1@earthlink.net>
Re: Pattern Matching: Which subpattern (rather than sub (Cussar)
Re: perldoc is like Greek to a beginner?? <Tassilo.Parseval@post.rwth-aachen.de>
Re: perldoc is like Greek to a beginner?? (Eric Bohlman)
Re: Print outputs despite no value to print out?? <brentdax1@earthlink.net>
Re: Print outputs despite no value to print out?? <ilya@martynov.org>
Re: Q: csh together with perl (wade)
Re: Search statments -> SQL -> DBI (Eric Bohlman)
Re: Strange behavior? <iltzu@sci.invalid>
String manipulation (Micheal Hue)
Re: String manipulation <brentdax1@earthlink.net>
Re: String version of += assignment operator?? <brentdax1@earthlink.net>
Re: Using a http proxy <Thomas@Baetzler.de>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 08 Aug 2001 07:32:41 GMT
From: slash@dot.c.o.m.org
Subject: Re: $ENV{'HTTP_REFERER'}
Message-Id: <3b70e8a6.48647218@news.freeserve.co.uk>
On 7 Aug 2001 17:10:31 GMT, dkcombs@panix.com (David Combs) wrote:
[...]
>>print "\n\n
>> </FONT><P><HR><BR><BR>
>> </BODY></HTML>";
>>
>>exit;
>
>Question: why the double BR? Even after a P?
>
>First, I use LYNX, which does NOT treat a
>double-BR as a P -- even though netscrape and
>presumably IE do.
>
>Can someone EXPLAIN this a bit (even though this
>is not an html group)?
It's simply amateurish HTML tagging. There's never a reason for using double <br>
tags (which should actually now be written <br />, BTW) The gap they cause is
inconsistant across browsers, and relies on the previous line not stretching to the
right edge of the browser canvas.
You'll also notice the lack of closing </p> tags, deprecated <center> tag and
incorrect nesting. Use of the <font> tag is also deprecated (also only one font was
defined, presuming everyone on Earth uses one OS). If web site authors are not using
stylesheets to define the style of HTML pages these days they really should should
consider changing careers.
Basically, forget everything you saw there and move along :-)
------------------------------
Date: Wed, 8 Aug 2001 00:35:18 -0700
From: "Jeff" <jeff_haralson@qwest.net>
Subject: Re: $ENV{'REMOTE_ADDR'}
Message-Id: <hY5c7.3200$87.462759@news.uswest.net>
didn't spend the time to run you example but if you want to negate an if try
using "unless" instead of "if".
Jeff
"jtjohnston" <jtjohnston@courrier.usherb.ca> wrote in message
news:3B705720.CF80D704@courrier.usherb.ca...
> ############################
> ##### Why does this work: #####
> ############################
>
> if(($ENV{'REMOTE_ADDR'} =~ /\b(127\.0)/) || ($ENV{'REMOTE_ADDR'} =~
> /\b(132\.210)/))
> {
> print "Allowed<BR>\n";
> print "$ENV{'REMOTE_ADDR'}\n";
> exit;
> }else{
> print "Not Allowed<BR>\n";
> print "$ENV{'REMOTE_ADDR'}\n";
> exit;
> }
>
> ############################
> ##### But Not this? ######
> ############################
> if(!($ENV{'REMOTE_ADDR'} =~ /\b(127\.0)/) || ($ENV{'REMOTE_ADDR'} =~
> /\b(132\.210)/))
> {
> print "Allowed<BR>\n";
> print "$ENV{'REMOTE_ADDR'}\n";
> exit;
> }else{
> print "Not Allowed<BR>\n";
> print "$ENV{'REMOTE_ADDR'}\n";
> exit;
> }
> ############################
> ##### Or Not this? ######
> ############################
> if(!(($ENV{'REMOTE_ADDR'} =~ /\b(127\.0)/) || ($ENV{'REMOTE_ADDR'} =~
> /\b(132\.210)/)))
> {
> print "Allowed<BR>\n";
> print "$ENV{'REMOTE_ADDR'}\n";
> exit;
> }else{
> print "Not Allowed<BR>\n";
> print "$ENV{'REMOTE_ADDR'}\n";
> exit;
> }
>
>
------------------------------
Date: Wed, 08 Aug 2001 10:57:58 +0200
From: Philippe PERRIN <philippe.perrin@sxb.bsf.alcatel.fr>
Subject: Easy array question ?
Message-Id: <3B70FF16.788DDDD@sxb.bsf.alcatel.fr>
Hi
This is certainly easy for some of you, but I can't figure out how to
remove the FIRST element of an array (in the same way as pop() removes
the LAST)...
Of course, I'd like to avoid using reverse+pop+reverse :-)
Thnx
--
PhP
------------------------------
Date: Wed, 08 Aug 2001 09:38:00 GMT
From: "Brent Dax" <brentdax1@earthlink.net>
Subject: Re: Easy array question ?
Message-Id: <YL7c7.2$_I2.426@newsread2.prod.itd.earthlink.net>
"Philippe PERRIN" <philippe.perrin@sxb.bsf.alcatel.fr> wrote in message
news:3B70FF16.788DDDD@sxb.bsf.alcatel.fr...
> Hi
>
> This is certainly easy for some of you, but I can't figure out how to
> remove the FIRST element of an array (in the same way as pop() removes
> the LAST)...
> Of course, I'd like to avoid using reverse+pop+reverse :-)
shift is the 'opposite' of pop. See perlfunc/shift for more details.
--Brent Dax
brentdax1@earthlink.net
------------------------------
Date: Wed, 08 Aug 2001 07:36:10 GMT
From: slash@dot.c.o.m.org
Subject: Re: Engineering vs. Hacking (was Re: How to supply modules with your software.)
Message-Id: <3b70eb8c.49388812@news.freeserve.co.uk>
On Fri, 03 Aug 2001 15:13:22 -0700, "Godzilla!" <godzilla@stomp.stomp.tokyo> wrote:
>David H. Adler AKA The CLPM Troll
>deliberately trolled using an article nearly a month old:
>
>> Godzilla! wrote:
>> > David Coppit wrote:
>> >> Godzilla! wrote:
>> >> > David Coppit wrote:
>
>> > (snipped)
>
>> >> <sigh> Not everyone is here to burn you at the stake. Let me reiterate
>> >> that I'm trying to change your mind, not tell you how to think. And I'm
>> >> providing an alternative view to your "just code up every module you
>> >> need" view.
>
>> > You are practicing deceit as usual. You clearly stated,
>
>> > "...do not advocate this position."
>
>> You have omitted the beginning of that statement. It started with the
>> word "please", which, in normal english parlance makes it a request,
>> rather than a demand.
>
>(snipped remaining troll)
>
>
>Are you the loving mouthpiece for the originating author?
>
>
>Clear to me as a long time English teacher and English professor,
>your reading comprehension skills do not surpass those of typical
>middle school students... drone... drone... drone...
Were you teased/beated badly as a child? You sound as though you don't have much
contact with normal people.
------------------------------
Date: Wed, 08 Aug 2001 07:11:45 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: For loop aliasing??
Message-Id: <3B70E62E.C28D33D2@acm.org>
Jeff wrote:
>
> "Carlos C. Gonzalez" <miscellaneousemail@yahoo.com> wrote in message
> news:MPG.15da70323bf95606989717@news.edmonton.telusplanet.net...
> >
> > I have been reading through various documents online including perldoc
> > stuff and am having a hard time finding what I need to know. Can someone
> > explain something to me.
> >
> > Given the code snippet below...
> >
> > for ($string) {
> > s/^\s+//; # ^ anchor to beginning, \s space, + multiple spaces, replace
> > with nothing.
> > s/\s+$//; # $ anchor to end, replace with nothing.
> > }
> >
> > I believe I can rewrite it like this...
> >
> > $string =~ s/^\s+//;
> > $string =~ s/\s+$//;
> >
> > What I don't understand is the aliasing that is occuring inside the for
> > loop. Does the scalar $string get assigned to the $_ implied variable
> > and then does this $_ variable become the target of each regular
> > expression?
> >
> > Can someone recommend a good link somewhere on aliasing and what happens
> > and when underneath code like above. I have been looking and reading and
> > searching and searching but it's like looking for a needle in a haystack.
>
> the construct ( ) is an array like ( 1,2,3,4 ) is an array containing 4
^^^^^^^^ ^^^^^^^^
a _list_ a _list_
> items. In your example you have an array with one item ($string)
^^^^^^^^
a _list_
perldoc -q "difference between a list and an array"
> Typically you see a for loop written
>
> for $string (@strings)
> {
> $string =~ s/^\s+//;
> $string =~ s/\s+$//;
> }
>
> In this case $string gets a reference to each item in @strings
>
> In the absence of "$string" in my loop the for loop would assign $_ a
> reference to each item in the array. References are something like pointers
> in C. They allow you to directly manipulate the items in the array without
> doing the reassignment suffle you describe above. Unlike C pointers,
> references have some loose rule especially when you have not set the pragma
> 'use strict ref'. Perl will attempt to use the value stored in a scalar
> "$variable" as the name of a real variable if you have not set 'use strict
> ref'. If you search for references and read up you'll get the picture.
John
--
use Perl;
program
fulfillment
------------------------------
Date: 8 Aug 2001 08:42:09 GMT
From: ebohlman@omsdev.com (Eric Bohlman)
Subject: Re: For loop aliasing??
Message-Id: <9kqu11$dje$2@bob.news.rcn.net>
Carlos C. Gonzalez <miscellaneousemail@yahoo.com> wrote:
> Given the code snippet below...
> for ($string) {
> s/^\s+//; # ^ anchor to beginning, \s space, + multiple spaces, replace
> with nothing.
> s/\s+$//; # $ anchor to end, replace with nothing.
> }
> I believe I can rewrite it like this...
> $string =~ s/^\s+//;
> $string =~ s/\s+$//;
> What I don't understand is the aliasing that is occuring inside the for
> loop. Does the scalar $string get assigned to the $_ implied variable
^^^^^^^^^^^^^^^
Not in the ordinary sense. In Perl, every scalar value (e.g. the value of
a scalar variable like $string, an individual element of an array or list,
etc.) is stored in an internal data structure called an SV (which, rather
amazingly, stands for "scalar value"). Variable names "point" to the
associated SV, rather than directly to the value inside the SV. So before
the for "loop," the symbol-table entry for $string (we'll assume for
simplicity that $string is a package variable) points to an SV that
holds the actual variable. When you enter the loop, $_ (or a loop
variable if you used one) is simply made to point to the same SV as
$string, so they're both accessing the place where the value is stored.
> and then does this $_ variable become the target of each regular
> expression?
Yep, the match and substitution operators default to working on $_.
> Can someone recommend a good link somewhere on aliasing and what happens
> and when underneath code like above. I have been looking and reading and
> searching and searching but it's like looking for a needle in a haystack.
You really have to understand a little bit of Perl's internals to fully
appreciate how aliasing works; try perldoc perlguts.
------------------------------
Date: Wed, 08 Aug 2001 08:58:36 GMT
From: "Brent Dax" <brentdax1@earthlink.net>
Subject: Re: get rid of these leading zeros in Perl
Message-Id: <0b7c7.5144$nb4.467883@newsread1.prod.itd.earthlink.net>
"Jim Monty" <monty@primenet.com> wrote in message
news:9kq3im$sv8$1@nnrp2.phx.gblx.net...
> Abigail <abigail@foad.org> wrote:
> > Jim Monty <monty@primenet.com> wrote:
> > >
> > > my $id1 = ...;
> > > $id1 =~ s/^0+//; # Safest general solution
> >
> > my $id1 = "0000000";
>
> Ok.
>
> $id1 =~ s/^0+(?=\d)//; # Safest general solution?
Or avoid the lookahead:
$id1 =~ s/^0+(\d+)$/$1/; #actually, the end anchor is redundant, but
whatever...
Or avoid either the lookahead or the $1 (but with /e):
$id =~ s/^0+/length($&) == length($id) ? 0 : ''/e;
TMTWODI...
--Brent Dax
brentdax1@earthlink.net
------------------------------
Date: Wed, 8 Aug 2001 09:58:57 +0200
From: "Peter Enzenberger" <peter@t-online.de>
Subject: getting the name of a sub
Message-Id: <9kqrd4$hpa$05$2@news.t-online.com>
I am writing protokoll data into a textfile.
How can I get the name of the sub to write it to the file?
Or even better:
When in the protokoll-sub, can I get the name of the sub which called &protokoll?
sub thisisasub {
$nicevalue = 123;
&protokoll ("thisiaaaub - $nicevalue");
}
Thanks for your help,
Peter
------------------------------
Date: Wed, 08 Aug 2001 10:09:45 +0200
From: Tassilo von Parseval <Tassilo.Parseval@post.rwth-aachen.de>
Subject: Re: getting the name of a sub
Message-Id: <3B70F3C9.7040704@post.rwth-aachen.de>
Peter Enzenberger wrote:
> I am writing protokoll data into a textfile.
> How can I get the name of the sub to write it to the file?
>
> Or even better:
> When in the protokoll-sub, can I get the name of the sub which called &protokoll?
This sounds like a job for caller. See perldoc -f caller.
Tassilo
--
$a=[(74,116)];$b=[($a->[1]-1,$a->[1]++,0x20)];$c=[(97,110)];$d=[($c->
[1]+1,$b->[1],"her")];for(@{[$a,$b,$c,$d]}){for(@{$_}){$_=~/\d+/?print
(chr($_)):print;}}$c=sub{$l=shift;[(0x20+$l-1,0x50,0x65,0x73-0x01,108
),(0x20,0x68,0x61,)]};print(map{chr($_)}@{($c->(1))});$h={a=>33*3,b=>
10**2+7,c=>"1"."0"."1",d=>0162};@h=sort(keys(%$h));for(@h){print(chr(
ord(chr($h->{$_}))))};
------------------------------
Date: Wed, 08 Aug 2001 07:24:03 GMT
From: slash@dot.c.o.m.org
Subject: Re: How to print a binary string as picture to web page
Message-Id: <3b70e7f4.48469390@news.freeserve.co.uk>
On Mon, 06 Aug 2001 00:52:29 GMT, "Ryan Gralinski" <ryan@bong.net> wrote:
>I made a perl program to display a picture
>it is very simple
>
>#!/usr/local/bin/perl
>print "Content-type:image/gif\n\n";
>print `cat /dirname/$ENV{'QUERY_STRING'}`;
># end code -------------------------------------
>
>
>thats is, then if you do like http://.../image.cgi?car.gif
>it will in fact show up as /dirname/car.gif
>
>Ryan
What if someone entered
http://.../image.cgi?../../../../../../../../../../../../etc/passwd
(or the escaped version) - not very secure, huh?
------------------------------
Date: Wed, 08 Aug 2001 10:41:57 +0100
From: Kourosh A Mojar <kmojar@bmjgroup.com>
Subject: installing modules (xml::sablotron) on win32/activestate...
Message-Id: <3B710965.C3D01E2B@bmjgroup.com>
hi all,
im a novice perl user on win32 (95) using active state perl. i need to
set-up and install sablotron to run some scripts that have been given to
me. i have followed all the instructions and installed expat
(http://sourceforge.net/projects/expat) and sablotron (gingerall.com)
and included in my environment path and seem to be executable. i cant
seem to make heads or tails of installing the perl module
xml::sablotron. i have downloaded the perl make files but have not had
experience (at least not successful experience) in installing modules
manually via make maker etc. as i have been used to updating my common
modules via ppm interface with win32 perl. it seems that when running
make file i get various unsuccessful and bad command errors. i have also
tried to make more sense of this by downloading nmake (or some microsoft
equivalent) as suggested by readme files.
if any one has any previous experience or could guide me (how stupid i
may be) on how to install sablotron on my windows machine.
thanking you in advance and for your kind attention,
kourosh
------------------------------
Date: 8 Aug 2001 08:01:08 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Line counting in a file
Message-Id: <9kqrk4$pth$1@mamenchi.zrz.TU-Berlin.DE>
According to Yves Orton <demerphq@hotmail.com>:
> anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) wrote in message
> news:<9kos74$fjn$2@mamenchi.zrz.TU-Berlin.DE>...
> > According to John Imrie <john.imrie@pa.press.net>:
> > > >
> > > > open FILE, $filename or die "Error: Can't open $filename: $!";
> > > > my $lines;
> > > > while (<FILE>) { $lines++ }
> > > >
> > > >
> > > You could reduce this to
> > >
> > > open FILE, $filename or die "Error: Can't open $filename: $!";
> > > my $lines = () = <FILE>;
> >
> > Yes, but at a price: you're reading the whole file into memory.
> > Tassilo's method works for files (though not lines) of any size.
> >
> > Anno
>
> Just curious as to why even bother with lines.
>
> select FILE;
Select doesn't do what you think it does. It only influences output.
> while (<>) {}
> print $.;
>
> Doesnt that work as well?
What happened when you tried it?
Anno
------------------------------
Date: Wed, 08 Aug 2001 10:20:26 +0200
From: gimi <gimi@psico.ch>
Subject: my final word - i'll listen, though [Re: Pattern Matching: Which subpattern (rather than substring) was matched?]
Message-Id: <3B70F64A.42DEFC8B@psico.ch>
hi again
Simon Best wrote:
> For example, I could have:
> $STRING =~ m/($SUBPATTERN1)|($SUBPATTERN2)|($SUBPATTERN3)/;
> and, if $STRING eq "Blah blah blah $SOMETHING_MATCHING_SUBPATTERN2 blah
> blah.", I'd want to know that it was $SUBPATTERN2 that matched. I'd
> like something like backreferences, but where it's $SUBPATTERN2 that's
> given, not $SOMETHING_MATCHING_SUBPATTERN2.
[zap]
> Anyway, the reason I wish to do this is because I wish to find the
> earliest match (the one furthest to the left in the string) out of a
> number of alternatives, and know which alternative it was that matched.
> (I intend to use the patterns as hash keys, so as to access stuff, in a
> hash, that's relevant to each kind of string.)
ok, i reconsidered it, and made this:
__CODE__ [left.plx]
#!/perl
use strict;
use warnings;
my %subpattern = ( # pattern => position in string
'match', 1e99,
'no', 1e99,
'pattern', 1e99
);
my $string = "match any pattern?";
foreach my $pat (keys %subpattern) {
$string =~ /$pat/ and $subpattern{$pat} = $-[0] # match offset
# pos() seems to only return undef, even if i use /g or /cg ??
}
# sort to lowest (leftmost) position first
my @sorted = sort { $subpattern{$a} <=> $subpattern{$b} } keys
%subpattern;
foreach (@sorted) {
print "found '$_' at pos $subpattern{$_}\n"
}
__END__
__DOES_
perldos % perl left.plx
found 'match' at pos 0
found 'pattern' at pos 10
found 'no' at pos 1e+099
__THATSIT__
gimi
--
going to bed now real soon. 10:16 am. ;D
http://www.psico.ch/
------------------------------
Date: Wed, 08 Aug 2001 09:35:40 GMT
From: "Brent Dax" <brentdax1@earthlink.net>
Subject: Re: Passing scalar by reference??
Message-Id: <MJ7c7.1$_I2.96@newsread2.prod.itd.earthlink.net>
"Carlos C. Gonzalez" <miscellaneousemail@yahoo.com> wrote in message
news:MPG.15d94f24b7034d9298970e@news.edmonton.telusplanet.net...
> Hi everyone,
>
> In the following code why does global scalar, $string, not get changed to
> "goodbye!"?
>
...
> my $string = "Hello there";
> change(\$string);
> print $string;
>
> sub change
> {
> my $string = @_;
> $string = "goodbye!";
> }
...
*puts on teacher's hat*
There are several problems with this code. We'll start with the first line
of change():
my $string=@_;
This is a mistake, as @_ is being evaluated in scalar context. (In
non-tech-ese, $string is expecting one thing, so @_ is being considered as
if it was one thing and not a list of things.) This means that $string is
set to the length of @_, which is 1. The correct code is either:
my($string)=@_;
or
my $string=shift;
Now, let's assume that error has been fixed. There's still the matter of
the assignment in change().
Some languages have references where they automagically change into the
thing they're referencing when you mess with them. Java and C# are both
like this. Perl, however is not. Perl references are more like C
pointers--you have to tell Perl to turn them into the thing they're pointing
to, or else it won't work. So, what you really need is
$$string="goodbye!";
One more thing I'd like to mention. It's an advanced topic, so you don't
have to pay attention if you don't want to.
There's a way to let change be called like
change($string)
but still have change receive a reference as its argument. It's called
"prototypes". Basically, if you define a subroutine before it's used and
you put certain line noise in parenthesis after the name of the function in
the sub call, you can cause Perl to do magical things to the arguments. In
this case, we could do this:
sub change(\$) { #turns the first parameter into a reference
automagically
my $string=shift;
$$string="goodbye!";
}
my $string="Hello there!";
change($string); #notice the lack of a backslash
print $string;
This would do exactly what you would expect--it changes $string. The \$
means that the first parameter should become a reference to a scalar.
*takes off the teacher's hat*
(Note: Yes, most of this has already been covered in other posts. However,
sometimes it's useful to explain things in different ways.)
--Brent Dax
brentdax1@earthlink.net
------------------------------
Date: 8 Aug 2001 00:24:57 -0700
From: cussar@yahoo.com (Cussar)
Subject: Re: Pattern Matching: Which subpattern (rather than substring) was matched?
Message-Id: <e48078d6.0108072324.50e8ce93@posting.google.com>
Extending the "definedness of $1, $2..variables"(as said by Bart) you
can try this also
$STRING =~ m/($SUBPATTERN1)|($SUBPATTERN2)|($SUBPATTERN3)/;
$arr="|$1|$2|$3|$4...";
Assuming "|" character will not occur in the matched pattern,
then "index" of the "|" followed by a "non-|" character in $arr will
give
the pattern matched.
(No better appoach, but probably no: of lines less)
-Cussar
Simon Best <barsticus@earthling.net> wrote in message news:<3B70A83B.59E698C4@earthling.net>...
> Bart Lateur wrote:
> >
> > Simon Best wrote:
> >
> > >For example, I could have:
> > >
> > > $STRING =~ m/($SUBPATTERN1)|($SUBPATTERN2)|($SUBPATTERN3)/;
> > >
> > >and, if $STRING eq "Blah blah blah $SOMETHING_MATCHING_SUBPATTERN2 blah
> > >blah.", I'd want to know that it was $SUBPATTERN2 that matched. I'd
> > >like something like backreferences, but where it's $SUBPATTERN2 that's
> > >given, not $SOMETHING_MATCHING_SUBPATTERN2.
> >
> > If there are no capturing parens inside the subpatterns, you can check
> > the definedness of the submatches. In your example, $1 would be undef,
> > but $2 would be defined.
> >
> > In order to be able to loop through the submatches, check the special
> > array @+ and/or @-, which indicate where the submatches start and end.
> > If the second subpattern did match, $+[2] and $-[2] will be defined, but
> > $+[1] and $-[1] will not.
> >
> > --
> > Bart.
>
> Thanks! Alas, I don't seem to have @+ and @- (I'm using Perl
> 5.005_03). But I can search through the backreference variables using
> symbolic links instead. @+ and @- would be very handy, though. I take
> it that $#- would be a quick and direct way of finding the relevant
> backreference number? That's exactly the sort of thing I need! :-)
>
> Thanks again!
>
> Simon
------------------------------
Date: Wed, 08 Aug 2001 09:11:35 +0200
From: Tassilo von Parseval <Tassilo.Parseval@post.rwth-aachen.de>
Subject: Re: perldoc is like Greek to a beginner??
Message-Id: <3B70E627.6010002@post.rwth-aachen.de>
Carlos C. Gonzalez wrote:
> Hi everyone,
>
> A lot of the perldoc documentation is very thorough and people have
> graciously put a lot of time into it. For this I am grateful but a lot
> of it for someone like me who is a beginner is like Greek.
> Interpolation, unary operator, lexical scope, expected semantics, extent
> of a string... These are just some of the "Greek" terms in perldoc
> perlop that I saw. Now I have some idea of what some of these are but
> the point I am making is that it seems to me that another version of the
> documentation needs to be rewritten in common English. Without so much
> computereese in it. Especially for us new beginners.
Yes, the terminology and diction used in the docs are not very
newbie-friendly. It took me a while to figure out what
list/scalar-context and the lot meant in first instance.
I recommend you keep on reading them nonetheless and make a mental
collection of the terms you can't yet figure out and just post them to
this group. A lot of very competent people are watching the threads and
happily pop in to explain.
Just note that no one is frowning upon people not yet fully
understanding the perl documentations. Just disregarding them at all is
considered a major sin in this newsgroup. ;-)
Tassilo
--
$a=[(74,116)];$b=[($a->[1]-1,$a->[1]++,0x20)];$c=[(97,110)];$d=[($c->
[1]+1,$b->[1],"her")];for(@{[$a,$b,$c,$d]}){for(@{$_}){$_=~/\d+/?print
(chr($_)):print;}}$c=sub{$l=shift;[(0x20+$l-1,0x50,0x65,0x73-0x01,108
),(0x20,0x68,0x61,)]};print(map{chr($_)}@{($c->(1))});$h={a=>33*3,b=>
10**2+7,c=>"1"."0"."1",d=>0162};@h=sort(keys(%$h));for(@h){print(chr(
ord(chr($h->{$_}))))};
------------------------------
Date: 8 Aug 2001 08:29:08 GMT
From: ebohlman@omsdev.com (Eric Bohlman)
Subject: Re: perldoc is like Greek to a beginner??
Message-Id: <9kqt8k$dje$1@bob.news.rcn.net>
Carlos C. Gonzalez <miscellaneousemail@yahoo.com> wrote:
> A lot of the perldoc documentation is very thorough and people have
> graciously put a lot of time into it. For this I am grateful but a lot
> of it for someone like me who is a beginner is like Greek.
> Interpolation, unary operator, lexical scope, expected semantics, extent
> of a string... These are just some of the "Greek" terms in perldoc
> perlop that I saw. Now I have some idea of what some of these are but
> the point I am making is that it seems to me that another version of the
> documentation needs to be rewritten in common English. Without so much
> computereese in it. Especially for us new beginners.
The problem here is that most of these aren't Perl-specific terms.
They're terms that represent general programming concepts. Perl's
documentation does assume that you're familiar with *programming* in
general. It would be a very tall order indeed to ask that the
documentation that comes with a programming language should teach
programming in general as well as the specific language.
It *is* reasonable, though, to expect a published book to be able to teach
programming concepts and teach a particular programming language at the
same time, and Andrew Johnson's book, to which other posters have referred
you, does just that.
> It is very frustrating sometimes to be told to go read this or that perl
> documentation only to go to the documentation and to find myself reading
> something that has a bunch of terms that I don't even understand. I need
> a simple answer to a simple and pointed question and I end up being
> confronted with a volume of information which ends up throwing terms at
> me that are even more confusing.
Unfortunately, asking questions on Usenet is not an efficient or even
reasonable way to learn general programming concepts. You need the
concepts to understand what questions you should be asking and to
understand the answers. Without this conceptual learning, you're
essentially reduced to asking "what magical incantation do I type to make
this happen" which ultimately boils down to asking other people to write
your code for you, and results in "cargo-cult" code which is often buggy
and hard to maintain.
> Please don't get me wrong. It's good to read through the documentation
> and I appreciate every tid bit and insight that is given me on this
> newsgroup and every suggestion as to which docomentation I should read.
> I truly do. But I guess I am just wondering if it might not be good to
> have a new perldoc added devoted to giving the common meaning to as many
> computereese terms as can be found?
Once again, the authors of the standard Perl documentation have a big
enough task on their hands trying to document how Perl works; expecting
them to write tutorials on how to program in general is really asking too
much. Such tutorials are available elsewhere; why re-invent the wheel?
------------------------------
Date: Wed, 08 Aug 2001 08:27:49 GMT
From: "Brent Dax" <brentdax1@earthlink.net>
Subject: Re: Print outputs despite no value to print out??
Message-Id: <9K6c7.5116$nb4.464863@newsread1.prod.itd.earthlink.net>
"Ilya Martynov" <ilya@martynov.org> wrote in message
news:87itfzhwu2.fsf@abra.ru...
>
> >> No it doesn tryies to print to filehandle HTML. It looks for me like a
> >> Perl bug.
>
> MC> Not a bug, really, but a result of how Perl determines the return
value
> MC> of a subroutine. In the absence of a return() statement, Perl uses the
> MC> result of the last evaluation as the return value. That is, these are
> MC> equivilant:
>
> MC> sub answer {
> MC> return 42;
> MC> }
>
> MC> sub answer {
> MC> 42;
> MC> }
>
> MC> With nothing else in the sub, the return value becomes @_. That is, it
> MC> returns whatever you passed in.
>
> But why it doesn't work under perl debugger?
I suspect *that* is a bug in the debugger. If it really matters much to
you, you can use perlbug to report it--although I don't know if it matters,
since there's no real use for sub {} eq sub {@_}.
--Brent Dax
brentdax1@earthlink.net
------------------------------
Date: 08 Aug 2001 13:25:16 +0400
From: Ilya Martynov <ilya@martynov.org>
Subject: Re: Print outputs despite no value to print out??
Message-Id: <87u1zihpj7.fsf@abra.ru>
>> But why it doesn't work under perl debugger?
BD> I suspect *that* is a bug in the debugger. If it really matters much to
BD> you, you can use perlbug to report it--although I don't know if it matters,
BD> since there's no real use for sub {} eq sub {@_}.
I'll bugreport it. I think it matters. Empty subs as stubs are not
uncommon during program development. It always kills me (and I think
not only me) when program behave differently under Perl debugger.
--
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
| Ilya Martynov (http://martynov.org/) |
| GnuPG 1024D/323BDEE6 D7F7 561E 4C1D 8A15 8E80 E4AE BE1A 53EB 323B DEE6 |
| AGAVA Software Company (http://www.agava.com/) |
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
------------------------------
Date: 8 Aug 2001 03:01:39 -0700
From: jjchen@alumni.ice.ntnu.edu.tw (wade)
Subject: Re: Q: csh together with perl
Message-Id: <4259465b.0108080201.adbbfd1@posting.google.com>
Rainer Theuer <Rainer.Theuer@sci-worx.com> wrote in message news:<3B67E68F.33004255@sci-worx.com>...
> Hi all,
>
> i try to write a script which should replace a string in a given file .
>
> The perl call has a problem with ENV variables , because the perl
> call don't know the content.
>
> Does anyone know whats wrong or how to solve my problem ?
>
> Thanks
>
> /Rainer
>
> #!/bin/csh -f
>
> setenv new $2
> setenv old $1
> setenv files $3
>
> echo "replacing : $old --> $new in file $files "
>
> perl -p -i.bak -e 's/$ENV{"old"}/$ENV{"new"}/g' $files
>
>
>
>
>
> --
I tried, it run well..
or you can try this:
#!/bin/sh
export new $2
export old $1
export files $3
.....
------------------------------
Date: 8 Aug 2001 07:33:16 GMT
From: ebohlman@omsdev.com (Eric Bohlman)
Subject: Re: Search statments -> SQL -> DBI
Message-Id: <9kqpvs$3md$1@bob.news.rcn.net>
MrBoom <andy_isherwood@hotmail.com> wrote:
> The next task I've been given is to produce a web search facility for
> the database. A number of the fields in the database are free text
> fields, these are the ones I'll want to be searching. What I'd like to
> do is take a search statement, eg:
> +"the phantom menace" +maul -"jar jar"
> and convert that into a form which could be inserted into my SQL
> statement.
> Does anyone know of the best way of doing this?
> Also, I'd like to rank the results in order of relevance. What is the
> best way of doing this?
> This seems to me to be the sort of thing that there should be a module
> for, does anyone know if there is?
Take a look at Text::Query; Loic Dachary has written some extensions that
generate SQL from it.
------------------------------
Date: 8 Aug 2001 09:38:48 GMT
From: Ilmari Karonen <iltzu@sci.invalid>
Subject: Re: Strange behavior?
Message-Id: <997263369.2998@itz.pp.sci.fi>
In article <9kepnm$hj8$2@mamenchi.zrz.TU-Berlin.DE>, Anno Siegel wrote:
>According to Yves Orton <demerphq@hotmail.com>:
>>
>> print $hash{key} ."\n"; # standard
>> print $r_hash->{key}."\n"; # standard reference
>> print %hash->{key} ."\n"; # should not work but does
>
>Damn! I thought I'd tested that.
>It's still nonsense :)
One could start arguing that it's actually an intentional feature meant
to provide a smoother migration path to Perl 6.. ;-)
--
Ilmari Karonen -- http://www.sci.fi/~iltzu/
"Get real! This is a discussion group, not a helpdesk. You post something,
we discuss its implications. If the discussion happens to answer a question
you've asked, that's incidental." -- nobull in comp.lang.perl.misc
------------------------------
Date: 8 Aug 2001 01:59:05 -0700
From: huem@mailandnews.com (Micheal Hue)
Subject: String manipulation
Message-Id: <ed2010db.0108080059.737c3c7c@posting.google.com>
Hi,
I want to convert a string with the format YYYYMMDDHHMMSS into an
array, first item contains 4 digits, the rest 2 digits.
my @dstr = $my_string =~ /^(\d\d\d\d)(\d\d)(\d\d)(\d\d)(\d\d)(\d\d)$/;
Is there better way ?
Thanks.
Micheal H.
------------------------------
Date: Wed, 08 Aug 2001 09:18:21 GMT
From: "Brent Dax" <brentdax1@earthlink.net>
Subject: Re: String manipulation
Message-Id: <xt7c7.12$%o4.3137@newsread1.prod.itd.earthlink.net>
"Micheal Hue" <huem@mailandnews.com> wrote in message
news:ed2010db.0108080059.737c3c7c@posting.google.com...
> Hi,
>
> I want to convert a string with the format YYYYMMDDHHMMSS into an
> array, first item contains 4 digits, the rest 2 digits.
>
> my @dstr = $my_string =~ /^(\d\d\d\d)(\d\d)(\d\d)(\d\d)(\d\d)(\d\d)$/;
You could be exceedingly clever with substr(), but that isn't really
necessary here. However, this is shorter:
my @dstr=$my_string=~/^(\d{4})(\d\d)(\d\d)(\d\d)(\d\d)(\d\d)$/;
There's also this, although it could lead to more elements than you want in
@dstr:
push @dstr, /(\d{4})/g;
push @dstr, $1 while(/(\d\d)/g);
It all comes down to TMTOWTDI.
--Brent Dax
brentdax1@earthlink.net
(who will be going to sleep soon, as he almost put his password in a usenet
post by mistake..)
------------------------------
Date: Wed, 08 Aug 2001 08:31:31 GMT
From: "Brent Dax" <brentdax1@earthlink.net>
Subject: Re: String version of += assignment operator??
Message-Id: <DN6c7.5120$nb4.465576@newsread1.prod.itd.earthlink.net>
"Tad McClellan" <tadmc@augustmail.com> wrote in message
news:slrn9n0qpo.kas.tadmc@tadmc26.august.net...
...
> perl -ne "print if /^=/" perlfaq[1-9].pod >faq.heads
Not on Windows. For some odd reason, DOS leaves the globbing to the
program, and for some other odd reason, p5p (well, win32-p5p) can't agree
that Perl should do the globbing for you. *sigh*
--Brent Dax
brentdax1@earthlink.net
------------------------------
Date: Wed, 08 Aug 2001 09:06:28 +0200
From: =?ISO-8859-1?Q?Thomas_B=E4tzler?= <Thomas@Baetzler.de>
Subject: Re: Using a http proxy
Message-Id: <ako1ntoh63ubo5c90e6h2ls53cm550ql3j@4ax.com>
Hi,
On Wed, 08 Aug 2001, Matthew Braid <nc@uq.net.au> wrote:
>Hi all,
>
>I need to write a program that will fetch webpages via a proxy.
[...]
Is there any particular reason why you don't use LWP? It can be set up
to use a HTTP proxy, too:
----8<--------( cut here )--------8<----
#!/usr/bin/perl -w
use strict;
use LWP::UserAgent;
use HTTP::Request;
sub get_url {
my( $url, $referer ) = @_;
# set up a UserAgent object to handle our request
my $ua = new LWP::UserAgent;
# Masquerade as a real browser
$ua->agent('Mozilla/4.5');
# use web proxy
$ua->proxy('http', 'http://127.0.0.1:8080/');
# create an HTTP request
my $request = new HTTP::Request('GET', $url );
# add Referer: header to request if present
$request->header( Referer => $referer ) if defined $referer;
# send the request and grab the response
my $response = $ua->request($request);
#print $response->status_line(), "\n";
if( $response->is_success ){
return( $response->content, $response->header("Content-Type") );
} else {
return();
}
}
my( $page, $type ) = get_url( "http://baetzler.de/perl/" );
print $page;
----8<--------( cut here )--------8<----
HTH,
--
Thomas Baetzler - http://baetzler.de/ - Clan LoL - http://lavabackflips.de/
I am the "ILOVEGNU" signature virus. Just copy me to your signature.
This post was infected under the terms of the GNU General Public License.
------------------------------
Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>
Administrivia:
The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc. For subscription or unsubscription requests, send
the single line:
subscribe perl-users
or:
unsubscribe perl-users
to almanac@ruby.oce.orst.edu.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.
For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V10 Issue 1461
***************************************