[11356] in Perl-Users-Digest
Perl-Users Digest, Issue: 4956 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Feb 22 06:07:35 1999
Date: Mon, 22 Feb 99 03:00:10 -0800
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Mon, 22 Feb 1999 Volume: 8 Number: 4956
Today's topics:
Re: Escaping characters <john.napiorkowski@bms.com>
FAQ 4.24: How can I access/change the first N letters o <perlfaq-suggestions@perl.com>
FAQ 4.25: How do I change the Nth occurrence of somethi <perlfaq-suggestions@perl.com>
Re: Printing all environment variables <Allan@Due.net>
Re: Printing all environment variables (Andre L.)
Special: Digest Administrivia (Last modified: 12 Dec 98 (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Thu, 18 Feb 1999 13:46:38 -0500
From: John Napiorkowski <john.napiorkowski@bms.com>
Subject: Re: Escaping characters
Message-Id: <36CC600E.A113C176@bms.com>
Patrick Fong wrote:
>
> Hi
>
> Was wondering if someone could tell me more about escaping characters.
> Well I think that is related to my problem
>
> the following line gives me errors..
>
> print FIND " <TR VALIGN=top ALIGN=center><TD
> BGCOLOR=#cccc99>$FORM{'filename'}<\/TD><TD
> BGCOLOR=#cccc99>$shortdate<\/TD>";
Can you give us the error message, a bit more of the code before
and after and some samples of what the variables might contain?
This should work... you dont need the \ before the /td> but that
shouldn't hurt. Also the perl version (do perl -v from the
commandline) would help --john napiorkowski
>
> all of them are on one line of course. We have to escape things like
> forward/backward slashes... fullstops... commas... what else?? And why?
>
> P.
------------------------------
Date: 21 Feb 1999 12:06:10 -0700
From: Tom Christiansen <perlfaq-suggestions@perl.com>
Subject: FAQ 4.24: How can I access/change the first N letters of a string?
Message-Id: <36d05922@csnews>
(This excerpt from perlfaq4 - Data Manipulation
($Revision: 1.43 $, $Date: 1999/01/26 09:57:23 $)
part of the standard set of documentation included with every
valid Perl distribution, like the one on your system.
See also http://language.perl.com/newdocs/pod/perlfaq4.html
if your negligent system adminstrator has been remiss in his duties.)
How can I access/change the first N letters of a string?
There are many ways. If you just want to grab a copy, use substr():
$first_byte = substr($a, 0, 1);
If you want to modify part of a string, the simplest way is often to use
substr() as an lvalue:
substr($a, 0, 3) = "Tom";
Although those with a pattern matching kind of thought process will
likely prefer:
$a =~ s/^.../Tom/;
--
echo "ICK, NOTHING WORKED!!! You may have to diddle the includes.";;
--Larry Wall in Configure from the perl distribution
------------------------------
Date: 21 Feb 1999 12:50:58 -0700
From: Tom Christiansen <perlfaq-suggestions@perl.com>
Subject: FAQ 4.25: How do I change the Nth occurrence of something?
Message-Id: <36d063a2@csnews>
(This excerpt from perlfaq4 - Data Manipulation
($Revision: 1.43 $, $Date: 1999/01/26 09:57:23 $)
part of the standard set of documentation included with every
valid Perl distribution, like the one on your system.
See also http://language.perl.com/newdocs/pod/perlfaq4.html
if your negligent system adminstrator has been remiss in his duties.)
How do I change the Nth occurrence of something?
You have to keep track of N yourself. For example, let's say you want to
change the fifth occurrence of `"whoever"' or `"whomever"' into
`"whosoever"' or `"whomsoever"', case insensitively.
$count = 0;
s{((whom?)ever)}{
++$count == 5 # is it the 5th?
? "${2}soever" # yes, swap
: $1 # renege and leave it there
}igex;
In the more general case, you can use the `/g' modifier in a `while'
loop, keeping count of matches.
$WANT = 3;
$count = 0;
while (/(\w+)\s+fish\b/gi) {
if (++$count == $WANT) {
print "The third fish is a $1 one.\n";
# Warning: don't `last' out of this loop
}
}
That prints out: `"The third fish is a red one."' You can also use a
repetition count and repeated pattern like this:
/(?:\w+\s+fish\s+){2}(\w+)\s+fish/i;
--
"Twisted cleverness is my only skill as a programmer." --Elizabeth Zwicky
------------------------------
Date: Sun, 21 Feb 1999 14:15:02 -0500
From: "Allan M. Due" <Allan@Due.net>
Subject: Re: Printing all environment variables
Message-Id: <dXYz2.383$986.7863@nntp1.nac.net>
Andre L. wrote in message ...
:In article <m3k8xclts2.fsf@joshua.panix.com>, Jonathan Feinberg
:<jdf@pobox.com> wrote:
:> mwoog@gmx.net (Marc-A. Woog) writes:
:>
:> > >Andre L. wrote in message ...
:> > >
:> > >print map{"$_\t$ENV{$_}\n"} (sort keys %ENV);
:> >
:> > Just yesterday I was trying to learn more about the map function and
:> > red in the Camel Book something like "do not use map in a void
:> > context, use foreach or system instead" Aren't you doing exactly
:> > that (or do I misunderstand "void context")?
:
:First point, there is a misquote here, I did not post the example above
:using map, this was from Allan M. Due. Credit where credit is Due[1]. :-)
:
:Second point, as Jonathan stated, map() is not being used in a void
:context here, since the result of the map is used by print(). However, it
:is not very appropriate to produce a list of strings like that before
:printing it.
Well, I did say it was just for fun.
:Now, this one below is a use of map() in a void context:
: map { print } ( some_list );
:This particular example is not really a sin, though, because print() does
:not return any value, so the list returned by map() is empty. IMO, this is
:the one exception where using map solely for its side-effect may be
:considered legitimate by a pragmatic programmer.
Well, to my way of thinking we do have a return value, you are building up a
list of success and failures are you not?
print @hmm = map{print "$_\t$ENV{$_}\n"} (sort keys %ENV);
Gives the $ENV and a final
1111111111...
:
:Andre
:[1] Sorry Allan, I know it's bad taste to play on people's names.
No problem at all. Trust me, with a name like Due I am very used to it.
Making puns on my last name is a small cottage industry. Creating inventive
middle names for me was very popular among my friends in high school and
college. I will leave it to your imagination to deduce what some of them
might be. <g>
AmD
------------------------------
Date: Sun, 21 Feb 1999 13:55:26 -0500
From: alecler@cam.org (Andre L.)
Subject: Re: Printing all environment variables
Message-Id: <alecler-2102991355260001@dialup-717.hip.cam.org>
In article <36D05485.FEF3B0ED@home.com>, Rick Delaney
<rick.delaney@home.com> wrote:
> Andre L. wrote:
> >
> > Now, this one below is a use of map() in a void context:
> >
> > map { print } ( some_list );
> >
> > This particular example is not really a sin, though, because print()
> > does not return any value, so the list returned by map() is empty.
>
> print() doesn't return a value?
>
> $ perl -le 'print map { print } qw(a b c)'
> a
> b
> c
> 111
Oh well. Wrong again. La di da.
Andre
------------------------------
Date: 12 Dec 98 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Special: Digest Administrivia (Last modified: 12 Dec 98)
Message-Id: <null>
Administrivia:
Well, after 6 months, here's the answer to the quiz: what do we do about
comp.lang.perl.moderated. Answer: nothing.
]From: Russ Allbery <rra@stanford.edu>
]Date: 21 Sep 1998 19:53:43 -0700
]Subject: comp.lang.perl.moderated available via e-mail
]
]It is possible to subscribe to comp.lang.perl.moderated as a mailing list.
]To do so, send mail to majordomo@eyrie.org with "subscribe clpm" in the
]body. Majordomo will then send you instructions on how to confirm your
]subscription. This is provided as a general service for those people who
]cannot receive the newsgroup for whatever reason or who just prefer to
]receive messages via e-mail.
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.misc (and this Digest), send your
article to perl-users@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.
The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq". The real FAQ, as it
appeared last in the newsgroup, can be retrieved with the request "send
perl-users FAQ". Due to their sizes, neither the Meta-FAQ nor the FAQ
are included in the digest.
The "mini-FAQ", which is an updated version of the Meta-FAQ, is
available by requesting "send perl-users mini-faq". It appears twice
weekly in the group, but is not distributed in the digest.
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 V8 Issue 4956
**************************************