[19823] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 2018 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Oct 26 14:10:52 2001

Date: Fri, 26 Oct 2001 11:10:14 -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: <1004119814-v10-i2018@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Fri, 26 Oct 2001     Volume: 10 Number: 2018

Today's topics:
        set value of scalar <jens@irs-net.com>
    Re: set value of scalar (Malcolm Dew-Jones)
    Re: set value of scalar <Tassilo.Parseval@post.rwth-aachen.de>
    Re: set value of scalar <jeff@vpservices.com>
    Re: String Substitution (Urgent) <usenet@diefenba.ch>
    Re: Tracing ["non-interactive debugging"] like in REXX? <nospam-abuse@ilyaz.org>
        variable replacement (Nils Rosehr)
    Re: variable replacement <dtweed@acm.org>
    Re: variable replacement (Rafael Garcia-Suarez)
    Re: variable replacement (Tad McClellan)
    Re: variable replacement (Tad McClellan)
    Re: variable replacement (Tad McClellan)
    Re: variable replacement <uri@sysarch.com>
        which module for controling repeating... <Robert.Lopez@abq.sc.philips.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Fri, 26 Oct 2001 19:09:20 +0200
From: Jens Luedicke <jens@irs-net.com>
Subject: set value of scalar
Message-Id: <9rc5gk$1fk$01$1@news.t-online.com>

hi ...

I want to improve this code ... Comments?

$text = $from if $type eq "From";
$text = $to if $type eq "To";
$text = $cc if $type eq "Cc";
$text = $subject if $type eq "Subject";

The string in $type should 
define the scalar that should be used. 

-- 
Jens Luedicke
jens@irs-net.com


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

Date: 26 Oct 2001 10:32:41 -0800
From: yf110@vtn1.victoria.tc.ca (Malcolm Dew-Jones)
Subject: Re: set value of scalar
Message-Id: <3bd99e39@news.victoria.tc.ca>

Jens Luedicke (jens@irs-net.com) wrote:
: hi ...

: I want to improve this code ... Comments?

: $text = $from if $type eq "From";
: $text = $to if $type eq "To";
: $text = $cc if $type eq "Cc";
: $text = $subject if $type eq "Subject";

It seems straight forward, why change it?  Me, I like to align things so
they're easy to read... 

 $text = $from    if $type eq "From";
 $text = $to      if $type eq "To";
 $text = $cc      if $type eq "Cc";
 $text = $subject if $type eq "Subject";





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

Date: Fri, 26 Oct 2001 19:53:59 +0200
From: Tassilo von Parseval <Tassilo.Parseval@post.rwth-aachen.de>
Subject: Re: set value of scalar
Message-Id: <3BD9A337.7070201@post.rwth-aachen.de>

Malcolm Dew-Jones wrote:

> Jens Luedicke (jens@irs-net.com) wrote:
> : hi ...
> 
> : I want to improve this code ... Comments?
> 
> : $text = $from if $type eq "From";
> : $text = $to if $type eq "To";
> : $text = $cc if $type eq "Cc";
> : $text = $subject if $type eq "Subject";
> 
> It seems straight forward, why change it?  Me, I like to align things so
> they're easy to read... 


But wouldn't a hash be better for that? Like:

$text = $data{$type};

Of course, this assumes that $from, $to etc are stored in this hash 
which shouldn't be a problem.


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: Fri, 26 Oct 2001 10:53:34 -0700
From: Jeff Zucker <jeff@vpservices.com>
Subject: Re: set value of scalar
Message-Id: <3BD9A31E.F2591284@vpservices.com>

Jens Luedicke wrote:
> 
> hi ...
> 
> I want to improve this code ... Comments?
> 
> $text = $from if $type eq "From";
> $text = $to if $type eq "To";
> $text = $cc if $type eq "Cc";
> $text = $subject if $type eq "Subject";

How about:

  my $header = ( From    => $from,
                 To      => $to,
                 Cc      => $cc,    
                 Subject => $subject,
               );
  $text = $header{$type};

Or eliminate the named variables completely and just use a hash to begin
with.  I.e. instead of assigning to $from, just assign to $header{From}
to begin with.

-- 
Jeff



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

Date: 26 Oct 2001 19:14:26 +0200
From: Kai Diefenbach <usenet@diefenba.ch>
Subject: Re: String Substitution (Urgent)
Message-Id: <gmhesmmih9.fsf@diefenba.ch>

Hi, 

>>>>> "Saurabh" == Saurabh Goyal <sgoyal@proplus.com> writes:

 Saurabh> I have an string having alpha and numberic characters, I just want to
 Saurabh> replace all _ (underscore) (prefix and suffix to numbers) with .
 Saurabh> my $str = "A_D_3_B_1_2_3_4_C";

	my $str=~ s/(?<=\d)_(?=\d)/./g;

Regards Kai



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

Date: Fri, 26 Oct 2001 17:00:15 +0000 (UTC)
From: Ilya Zakharevich <nospam-abuse@ilyaz.org>
Subject: Re: Tracing ["non-interactive debugging"] like in REXX?
Message-Id: <9rc4qv$7b2$1@agate.berkeley.edu>

[A complimentary Cc of this posting was sent to
Edwin =?iso-8859-1?Q?G=FCnthner?= 
<edgue@web.de>], who wrote in article <3BD958FB.BE2AE271@web.de>:
> So setting PERLDB_OPTS to NonStop=1 LineInfo=db.out AutoTrace
> is close, but not close enough. It printes out the 
> lines, but not what is actually executed ...

Hmm???  What is the difference?

Ilya


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

Date: 26 Oct 2001 07:50:10 -0700
From: rosehr@epost.de (Nils Rosehr)
Subject: variable replacement
Message-Id: <5c0f3651.0110260650.23cea379@posting.google.com>

I want to do a search and replace.
But the search- and replace patterns are
not known in advance. Furthermore the replacement
text contains $1, $2, ..., but it is also not known
how many of those. Everything I tried did not work.
Here is a little script to show the problem:

#!/usr/bin/perl -w
$_ = "abcdef\n";
$a = qr/([cd])/;
$b = q/$1$1/;
print;
s/$a/$b/egs;
print;

I expected the letters c and d to be doubled,
instead they are replaced by $1's.
Does anybody know a solution to the problem?
Nils Rosehr


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

Date: Fri, 26 Oct 2001 15:18:57 GMT
From: Dave Tweed <dtweed@acm.org>
Subject: Re: variable replacement
Message-Id: <3BD97D7A.9F9E94EE@acm.org>

Nils Rosehr wrote:
> #!/usr/bin/perl -w
> $_ = "abcdef\n";
> $a = qr/([cd])/;
> $b = q/$1$1/;
> print;
> s/$a/$b/egs;
> print;
> 
> I expected the letters c and d to be doubled,
> instead they are replaced by $1's.
> Does anybody know a solution to the problem?

I got this to work, but I'm not sure if it's the right way to go about it:

#!/usr/bin/perl -w
$_ = "abcdef\n";
$a = qr/([cd])/;
$b = q/$1$1/;
$b = qq/"$b"/;
print;
s/$a/$b/eegs;
print;

For some reason, this does not work:

#!/usr/bin/perl -w
$_ = "abcdef\n";
$a = qr/([cd])/;
$b = q/$1$1/;
print;
s/$a/"$b"/eegs;
print;

I'm really not clear on when the interpolation happens relative to the
eval(s).

-- Dave Tweed


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

Date: 26 Oct 2001 15:13:13 GMT
From: rgarciasuarez@free.fr (Rafael Garcia-Suarez)
Subject: Re: variable replacement
Message-Id: <slrn9tivcl.duu.rgarciasuarez@rafael.kazibao.net>

Nils Rosehr wrote in comp.lang.perl.misc:
> I want to do a search and replace.
> But the search- and replace patterns are
> not known in advance. Furthermore the replacement
> text contains $1, $2, ..., but it is also not known
> how many of those. Everything I tried did not work.
> Here is a little script to show the problem:
> 
> #!/usr/bin/perl -w
> $_ = "abcdef\n";
> $a = qr/([cd])/;
> $b = q/$1$1/;
> print;
> s/$a/$b/egs;
> print;
> 
> I expected the letters c and d to be doubled,
> instead they are replaced by $1's.

Yes : $b is interpolated, but the result of this interpolation is not
interpolated. You want something like :o

    $_ = "abcdef\n";
    $a = qr/([cd])/;
    $b = q/$1.$1/; # Note the dot : this is a Perl expression !
    print;
    s/$a/$b/eegs; # double the 'e' !
    print;

See also the perlop documentation about doubling the 'e' flag :

    ...A second "e" modifier will cause the replacement portion to be
    "eval"ed before being run as a Perl expression....

-- 
Rafael Garcia-Suarez / http://rgarciasuarez.free.fr/


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

Date: Fri, 26 Oct 2001 15:31:31 GMT
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: variable replacement
Message-Id: <slrn9titoh.71j.tadmc@tadmc26.august.net>

Nils Rosehr <rosehr@epost.de> wrote:

>I want to do a search and replace.
>But the search- and replace patterns are
>not known in advance. Furthermore the replacement
>text contains $1, $2, 


>$_ = "abcdef\n";
>$a = qr/([cd])/;
>$b = q/$1$1/;


Don't use $a and $b in "real programs" though, unless you are
using them for sort()ing.


>print;
>s/$a/$b/egs;


You have one "round" of "e"valuation. After one eval you have:

   s/$a/$1$1/gs;

When you use 'e' options, you do not get interpolation.

You need another round to replace the variable names with
their values. You also need to change your replacement to
be legal Perl code.

>I expected the letters c and d to be doubled,
>instead they are replaced by $1's.
>Does anybody know a solution to the problem?


   $b = q/$1 . $1/;   # or $b = q/"$1$1"/;

   s/$a/$b/eegs;


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


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

Date: Fri, 26 Oct 2001 15:53:15 GMT
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: variable replacement
Message-Id: <slrn9tiunn.77e.tadmc@tadmc26.august.net>

Dave Tweed <dtweed@acm.org> wrote:

>For some reason, this does not work:
>
>#!/usr/bin/perl -w
>$_ = "abcdef\n";
>$a = qr/([cd])/;
>$b = q/$1$1/;
>print;
>s/$a/"$b"/eegs;


Because the first 'e' sees (and consumes) the quotes. All the
second 'e' sees is:   $1$1    syntax error.


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


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

Date: Fri, 26 Oct 2001 15:53:16 GMT
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: variable replacement
Message-Id: <slrn9tiv23.77e.tadmc@tadmc26.august.net>

Rafael Garcia-Suarez <rgarciasuarez@free.fr> wrote:
>Nils Rosehr wrote in comp.lang.perl.misc:
>> I want to do a search and replace.
>> But the search- and replace patterns are
>> not known in advance. Furthermore the replacement
>> text contains $1, $2

>> $b = q/$1$1/;

>> s/$a/$b/egs;

>Yes : $b is interpolated, 


No, $b is _evaluated_, not interpolated.

A variable's name evaluates to the variable's value.


>but the result of this interpolation is not
>interpolated.


There is no interpolation happening with either the s/// above
nor the one below.


>    s/$a/$b/eegs; # double the 'e' !


Two evals, zero interpolations.


(my other followup OTOH has 2 evals and 1 interpolation, 'cause
 the code for the 2nd eval is a double quoted string.)

-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


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

Date: Fri, 26 Oct 2001 16:22:06 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: variable replacement
Message-Id: <x7bsiu1ick.fsf@home.sysarch.com>

>>>>> "TM" == Tad McClellan <tadmc@augustmail.com> writes:

  >>> $b = q/$1$1/;

  >>> s/$a/$b/egs;

  >> Yes : $b is interpolated, 


  TM> No, $b is _evaluated_, not interpolated.

debatable. ilya has pointed out that the replacement side of s/// is
just a double quotish string. so it really is interpolation. internally
there is an implicit "" put around it.

  TM> A variable's name evaluates to the variable's value.

true, but in the replacement part it is interpolated into a string. 

  >> s/$a/$b/eegs; # double the 'e' !


  TM> Two evals, zero interpolations.

again, the first eval effectively removes the implied "" so there was an
interpolation before that.


  TM> (my other followup OTOH has 2 evals and 1 interpolation, 'cause
  TM>  the code for the 2nd eval is a double quoted string.)

s/foo/$b/ is the same as s/foo/"$b"/e.

uri

-- 
Uri Guttman  ---------  uri@sysarch.com  ----------  http://www.sysarch.com
SYStems ARCHitecture and Stem Development ------ http://www.stemsystems.com
Search or Offer Perl Jobs  --------------------------  http://jobs.perl.org


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

Date: 26 Oct 2001 09:49:20 -0600
From: Robert Lopez <Robert.Lopez@abq.sc.philips.com>
Subject: which module for controling repeating...
Message-Id: <jc6itd2v1tr.fsf@abqb1k.abq.sc.philips.com>

Some time this summer or fall I read the release announcement for a
module that allowed one to do such things as keep a queue of sent
email notices which could be checked to prevent the sending of too
many repeating email notices which might all say the same thing.

Now that I want to use it I can not rememember the name.  I have
searched CPAN but can not find it. Anyone remember what it was?
-- 
Robert.Lopez@Philips.com



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

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


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