[19094] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 1289 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Jul 11 18:15:45 2001

Date: Wed, 11 Jul 2001 15:15:24 -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: <994889724-v10-i1289@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Wed, 11 Jul 2001     Volume: 10 Number: 1289

Today's topics:
    Re: Text variable containing '$' <tinamue@zedat.fu-berlin.de>
    Re: Text variable containing '$' <mjcarman@home.com>
    Re: Text variable containing '$' <krahnj@acm.org>
    Re: Text variable containing '$' (E.Chang)
    Re: Text variable containing '$' (Anno Siegel)
    Re: Text variable containing '$' <krahnj@acm.org>
    Re: Text variable containing '$' (E.Chang)
    Re: Text variable containing '$' (F. Xavier Noria)
    Re: time stamp  to a tenth of a second <pne-news-20010711@newton.digitalspace.net>
    Re: trimming blank <goldbb2@earthlink.net>
    Re: Very good regex question? <pne-news-20010611@newton.digitalspace.net>
    Re: Where is MD5 <gnarinn@hotmail.com>
    Re: Where is MD5 <iltzu@sci.invalid>
        Why doesn't this program work? <hammy@charter.net>
    Re: why is Vars an undefined subroutine? <pne-news-20010711@newton.digitalspace.net>
    Re: why is Vars an undefined subroutine? <bart.lateur@skynet.be>
    Re: Working with packed strings <pne-news-20010711@newton.digitalspace.net>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: 11 Jul 2001 18:33:39 GMT
From: Tina Mueller <tinamue@zedat.fu-berlin.de>
Subject: Re: Text variable containing '$'
Message-Id: <9ii663$j3m7k$1@fu-berlin.de>

Anno Siegel <anno4000@lublin.zrz.tu-berlin.de> wrote:
> According to E.Chang <echang@netstorm.net>:
>> "JJ" <jocke30_gbg@hotmail.com> wrote in
>> <9ihoul$o6v$1@vg170.it.volvo.se>: 
>> > 

> Perl lets you choose the delimiters in s/// expressions:

>     $in =~ s'\$'\$';

> Question: Why does the "$" in the left part still need an escape?

because otherwise perl assumes that $ means "the end of the line"...

tina

-- 
http://tinita.de    \  enter__| |__the___ _ _ ___
tina's moviedatabase \     / _` / _ \/ _ \ '_(_-< of
search & add comments \    \ _,_\ __/\ __/_| /__/ perception
please don't email unless offtopic or followup is set. thanx


------------------------------

Date: Wed, 11 Jul 2001 13:02:14 -0500
From: Michael Carman <mjcarman@home.com>
Subject: Re: Text variable containing '$'
Message-Id: <3B4C94A6.56ECBA2@home.com>

Anno Siegel wrote:
> 
>     $in =~ s'\$'\$';
> 
> Question: Why does the "$" in the left part still need an escape?

Is that an exercise for the reader, or are you having a mental lapse,
Anno?

Answer: $ has a special meaning (end of string) inside a regex.

But the replacement portion needs to be '\\\$' to force both the
backslash and $ to be literal.

-mjc


------------------------------

Date: Wed, 11 Jul 2001 18:44:03 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: Text variable containing '$'
Message-Id: <3B4C9EB6.B29C7954@acm.org>

Anno Siegel wrote:
> 
> Perl lets you choose the delimiters in s/// expressions:
> 
>     $in =~ s'\$'\$';
> 
> Question: Why does the "$" in the left part still need an escape?

Is that a rhetorical question Anno?



John
-- 
use Perl;
program
fulfillment


------------------------------

Date: Wed, 11 Jul 2001 19:01:36 GMT
From: echang@netstorm.net (E.Chang)
Subject: Re: Text variable containing '$'
Message-Id: <Xns90DB995D3594Cechangnetstormnet@207.106.93.86>

anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) wrote in
<9ii2jd$igj$2@mamenchi.zrz.TU-Berlin.DE>: 

>According to E.Chang <echang@netstorm.net>:
>> "JJ" <jocke30_gbg@hotmail.com> wrote in
>> <9ihoul$o6v$1@vg170.it.volvo.se>: 
>> 
>>> Hi,
>>> 
>>> I collect table names from a database and stores them in a array.
>>> The table names can contain the character '$' such as 'My$Table'.
>>> Before I store the value in the array I need to determine if it
>>> contains the character and replace '$' with '\$'.
>> 
>> The following example shows one way:
>> 
>> $in = 'My$Table';
>> $replace = '\$';
>> $in =~ s/\$/$replace/g;
>> print $in";

>Perl lets you choose the delimiters in s/// expressions:
>
>    $in =~ s'\$'\$';
>
>Question: Why does the "$" in the left part still need an escape?

The novice dutifully answers the master: Because the left part is still 
a regular expression, not a quoted string, so $ still is interpreted 
the usual way. 

I didn't realize that using a single quote for the delimiter changes 
the interplation behaviour of the right part of the substitution 
expression.  I've read the docs on quoting operators more than once, 
but some things don't seem to sink in until they are experienced. 
 Thanks very much for pointing that out.

Thanks, mjc, for showing the solution with \\\$.  I tried two 
backslashes, thinking the first would escape the second, and discovered 
it did not but didn't have the sense to keep going.  Can you point me 
to the section of documentation so I can read more on this?  

-- 
EBC


------------------------------

Date: 11 Jul 2001 19:12:43 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Text variable containing '$'
Message-Id: <9ii8fb$maa$2@mamenchi.zrz.TU-Berlin.DE>

According to John W. Krahn <krahnj@acm.org>:
> Anno Siegel wrote:
> > 
> > Perl lets you choose the delimiters in s/// expressions:
> > 
> >     $in =~ s'\$'\$';
> > 
> > Question: Why does the "$" in the left part still need an escape?
> 
> Is that a rhetorical question Anno?

I was obviously unclear.  I had the immediately preceding poster
in mind when I asked the question, and, come to think of it, it
probably wasn't a very good question to ask anyone.  Poor appreciation
of readership...

Time for a break, I think.

Anno


------------------------------

Date: Wed, 11 Jul 2001 19:11:58 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: Text variable containing '$'
Message-Id: <3B4CA545.62931279@acm.org>

Michael Carman wrote:
> 
> Anno Siegel wrote:
> >
> >     $in =~ s'\$'\$';
> >
> > Question: Why does the "$" in the left part still need an escape?
> 
> Is that an exercise for the reader, or are you having a mental lapse,
> Anno?
> 
> Answer: $ has a special meaning (end of string) inside a regex.
> 
> But the replacement portion needs to be '\\\$' to force both the
> backslash and $ to be literal.

Not in single quotes because perl doesn't interpolate in single quotes.



John
-- 
use Perl;
program
fulfillment


------------------------------

Date: Wed, 11 Jul 2001 19:19:04 GMT
From: echang@netstorm.net (E.Chang)
Subject: Re: Text variable containing '$'
Message-Id: <Xns90DB9C53F96F4echangnetstormnet@207.106.93.86>

anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) wrote in 
<9ii8fb$maa$2@mamenchi.zrz.TU-Berlin.DE>:

>According to John W. Krahn <krahnj@acm.org>:
>> Anno Siegel wrote:

[snip]

>>> Question: Why does the "$" in the left part still need an escape?
>> Is that a rhetorical question Anno?
>
>I was obviously unclear.  I had the immediately preceding poster
>in mind when I asked the question, and, come to think of it, it
>probably wasn't a very good question to ask anyone.  

Not at all. Questions that encourage thought are always appreciated, at 
least by some of us.

-- 
EBC


------------------------------

Date: 11 Jul 2001 20:24:14 GMT
From: fxn@retemail.es (F. Xavier Noria)
Subject: Re: Text variable containing '$'
Message-Id: <9iicle$3fp051@news1s.iddeo2.es>

Besides taking into account the given suggestions, you could have a look
at perldoc -f quotemeta.

-- fxn


------------------------------

Date: Wed, 11 Jul 2001 21:09:53 +0200
From: Philip Newton <pne-news-20010711@newton.digitalspace.net>
Subject: Re: time stamp  to a tenth of a second
Message-Id: <829pkto8f1n73r1nt93cb8psj63r9apfrj@4ax.com>

On 11 Jul 2001 17:35:38 GMT, anno4000@lublin.zrz.tu-berlin.de (Anno
Siegel) wrote:

> According to  <inna@raykhman.com>:
> > Hi,
> > 
> > am looking for smth in perl that would give me a timestamp to a tenth of
> > second, preferable in a single number.
> > 
> > if anyone knows of smth, please let me know.
> 
> Get Time::Hires from the cpan.

Or bleadperl :)

(It's Time::HiRes, by the way: High Resolution Timing, nothing to do
with hiring of time.)

Cheers,
Philip
-- 
Philip Newton <nospam.newton@gmx.li>
That really is my address; no need to remove anything to reply.
If you're not part of the solution, you're part of the precipitate.


------------------------------

Date: Wed, 11 Jul 2001 17:51:46 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: trimming blank
Message-Id: <3B4CCA72.91C9D743@earthlink.net>

Pascal wrote:
> 
> What is the best way to remove spaces before or after a sentence.
> 
> Example before: "             Hello World          "
> Example after: "Hello World"
> 
> I appreciate any help.  Thanks

my $string = "             Hello World          ";
$string =~ s/\A\s*(.*?)\s*\z/$1/s;
Or:
$string =~ s/\A\s*|\s*\z//gs;

It may be faster (I would benchmark if I were you) to do this:
$string =~ s/\A\s*//; $string =~ s/\s*\z//;

There's no harm in using ^ instead of \A (except in the /g case), but if
you use $ instead of \z, then you will end up leaving on a trailing \n,
if there is one.

-- 
The longer a man is wrong, the surer he is that he's right.


------------------------------

Date: Wed, 11 Jul 2001 21:08:32 +0200
From: Philip Newton <pne-news-20010611@newton.digitalspace.net>
Subject: Re: Very good regex question?
Message-Id: <ra8pkt47olgt5qmpc0h7uer5bjhinr1tnm@4ax.com>

On 11 Jul 2001 17:10:41 GMT, anno4000@lublin.zrz.tu-berlin.de (Anno
Siegel) wrote:

> According to Philip Newton  <nospam.newton@gmx.li>:
> > On Wed, 11 Jul 2001 07:42:21 +0000 (UTC), Ilya Zakharevich
> > <nospam-abuse@ilyaz.org> wrote:
> > 
> > > Unless //e, the second half *of the substitution* is in the same
> > > context wrt quoting of '.
> > 
> > Not like "? The right-hand side of a substitution interpolates
> > variables, and ' doesn't.
> 
> I feel presumptuous, let me speak for Ilya :)
> 
> Both sides of an s/// (normally) interpolate variables, that's
> not the point.  The status of "'" is the same on both sides in
> that it doesn't need to be backwhacked.

Ah. I had misunderstood. I thought he had said "the quoting context of
the second half of the substitution has the same rules as ' ' quoting".
Apparently, what he meant was "the rules for whether ' has to be quoted
are the same on the left-hand side of a substitution as on the
right-hand side, unless you have the /e flag". My apologies.

Cheers,
Philip
-- 
Philip Newton <nospam.newton@gmx.li>
That really is my address; no need to remove anything to reply.
If you're not part of the solution, you're part of the precipitate.


------------------------------

Date: Wed, 11 Jul 2001 18:28:39 +0000
From: gnari <gnarinn@hotmail.com>
Subject: Re: Where is MD5
Message-Id: <994876119.328511358704418.gnarinn@hotmail.com>

In article <1ewe4yb.18or3j9howa0yN%otto.wyss@bluewin.ch>,
Otto Wyss <otto.wyss@bluewin.ch> wrote:
>I've used module MD5 (on Debian testing) but since I upgraded to perl
>5.6.1 this module is gone! How do I find out where I have to look for
>it?
>
>I tried perldoc MD5 => nothing, I tried perldoc -q MD5 => nothing! How
>do I find out what modules where installed?
>

try locate MD5.pm

my guess is that you might find it under /usr/lib, but your 5.6.1
perl uses libraries in /usr/local/lib

it is probably best to reinstall the module.

gnari


------------------------------

Date: 11 Jul 2001 21:02:35 GMT
From: Ilmari Karonen <iltzu@sci.invalid>
Subject: Re: Where is MD5
Message-Id: <994884556.27308@itz.pp.sci.fi>

In article <994876119.328511358704418.gnarinn@hotmail.com>, gnari wrote:
>
>try locate MD5.pm
>
>my guess is that you might find it under /usr/lib, but your 5.6.1
>perl uses libraries in /usr/local/lib
>
>it is probably best to reinstall the module.

 ..and while you're at it, install Digest::MD5 instead.  The current MD5
module is just a wrapper around Digest::MD5.

The next stable relese of perl will have Digest::MD5 as part of the
standard distribution.

-- 
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: Wed, 11 Jul 2001 16:11:04 -0500
From: "Eric Schultz" <hammy@charter.net>
Subject: Why doesn't this program work?
Message-Id: <tkpgakh9ca2e4f@corp.supernews.com>

I'm having a problem with a program I made and I can't figure out what's
wrong with it. A form sends login email and password to this file and this
file checks the user flat-file database against it. (Below is the source
code, with notes) I'm having a problem in this area:

if ($realcustpass eq $form_pass){
&newlogincookie;
print "Location:$form_redir\n\n";
exit;
}

For some reason when $realcustpass does equal $form_pass that conditional
won't run. Its as if the two aren't equal but they are, I've checked a
number of times. I can't figure out the problem. The only time that this
program works is when the last user is taken from the database. If you need
more information to help,  please email me at hammy@charter.net Thanks in
advance for any help anyone can give.

Eric Schultz

#!/usr/local/bin/perl
push @INC,"/data1/hypermart.net/bwshop/";
require (common);

&form_read;
$form_email = $FORM{'email'};
$form_pass = $FORM{'password'};
$form_redir = $FORM{'redirect'};
&opener("userinfo");
$foundcust = "no";

#############
# @userinfo is in the format
#
# userid|useremail|userpass
# me|myemail|mypass
#
# right now only the line "me|myemail|mypass" works
##############

foreach $i (@userinfo){
chomp($i);
($testcustid,$testcustemail,$testcustpass) = split(/\|/,$i);
if ($testcustemail eq $form_email){
$foundcust = "yes";
$realcustid = $testcustid;
$realcustpass = $testcustpass;
}}

if ($realcustpass eq $form_pass){
&newlogincookie;
print "Location:$form_redir\n\n";
exit;
}
if ($realcustpass ne $form_pass){
$problem = "passfail";
&loginfail;
}
if ($foundcust eq "no"){
$problem = "nouser";
&loginfail;
}

sub loginfail {
print
"Location:http://www.bwshopping.com/login.cgi?redir=$form_redir&fail=$proble
m\n\n";
exit;
}




------------------------------

Date: Wed, 11 Jul 2001 20:55:56 +0200
From: Philip Newton <pne-news-20010711@newton.digitalspace.net>
Subject: Re: why is Vars an undefined subroutine?
Message-Id: <088pktcqkqj0e32p4pprpg4b9hdrhthf1e@4ax.com>

On Wed, 11 Jul 2001 08:59:56 GMT, Bart Lateur <bart.lateur@skynet.be>
wrote:

> Philip Newton wrote:
> 
> >> my %params = $q->Vars;
> >
> >Where did you get the method 'Vars' from? It's not in my copy of the
> >CGI.pm documentation. (Hint, hint[1].)
> 
> ???
> 
> Either you didn't look well, or you need an upgrade.

I have CGI.pm 2.46.

Cheers,
Philip
-- 
Philip Newton <nospam.newton@gmx.li>
That really is my address; no need to remove anything to reply.
If you're not part of the solution, you're part of the precipitate.


------------------------------

Date: Wed, 11 Jul 2001 21:40:02 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: why is Vars an undefined subroutine?
Message-Id: <dnhpkt0t29fph3jjq1quq79e3bf844v1du@4ax.com>

Philip Newton wrote:

>> Either you didn't look well, or you need an upgrade.
>
>I have CGI.pm 2.46.

Mine is 2.752. Question is: when did Vars() get added?

Fact is: the docs for CGI.pm included with 5.005_03, according to CPAN,
do not mention it at all. I can't sem to find it in the HTML page I had
with ActiveState perl 5.6.0.

So it seems like it's new for the CGI.pm included with 5.6.1?

-- 
	Bart.


------------------------------

Date: Wed, 11 Jul 2001 21:08:27 +0200
From: Philip Newton <pne-news-20010711@newton.digitalspace.net>
Subject: Re: Working with packed strings
Message-Id: <th8pkto6r0nchul1vkil35klag6obu4nvq@4ax.com>

On Wed, 11 Jul 2001 13:07:21 GMT, Tim Schmelter
<tschmelter@statesman.com> wrote:

> Philip Newton wrote:
> 
> > > i.e., will the following always put the first 15 bytes of $buffer into
> > > $subsetted, no matter what info $buffer contains?
> > >
> > > sysread(INFILE, $buffer, 8, 32);
> > > $subsetted=substr($buffer, 0, 15);
> >
> > Yes, as long as $buffer is at least 15 bytes long, of course.
> 
> perldoc -q multibyte says that Perl pretends that a byte and a character are
> synonymous, but didn't I read that there are plans to make Perl6 Unicode-aware?

Perl 5.6.0 and above are already Unicode-aware to some extent.

> If so, wouldn't scalars containing arbitrary binary data be interpreted as
> two-byte strings?

Not unless you tell Perl to. Internally, Perl uses UTF8 for Unicode
data, but it's meant to be transparent.

When you read data in from the outside and don't specially tell Perl
that you're reading UTF-8, then your program will see as characters the
values that were in the file as bytes. So if C3 B6 was in the file, Perl
will see two characters, not one. Perl won't collapse those into one
character "\x{C3B6}" (UTF-16) or "\x{f6}" (UTF-8). It may store them
internally as the bytes C3 83 C2 B6, but you shouldn't notice since
substr operates on characters, not bytes, in Unicode-aware Perls.

> Or am I just being paranoid? :-)

Yes. Perl should be able to handle byte-oriented data as before. If it
doesn't, it's a bug.

Cheers,
Philip
-- 
Philip Newton <nospam.newton@gmx.li>
That really is my address; no need to remove anything to reply.
If you're not part of the solution, you're part of the precipitate.


------------------------------

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 1289
***************************************


home help back first fref pref prev next nref lref last post