[26750] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 8832 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Jan 6 00:05:49 2006

Date: Thu, 5 Jan 2006 21:05:06 -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, 5 Jan 2006     Volume: 10 Number: 8832

Today's topics:
    Re: Are there alternatives to exec and system <jurgenex@hotmail.com>
        calling subroutine , name derived from variable <madhuram@nortel.com>
    Re: calling subroutine , name derived from variable <noreply@gunnar.cc>
    Re: calling subroutine , name derived from variable <matthew.garrish@sympatico.ca>
    Re: calling subroutine , name derived from variable robic0
    Re: calling subroutine , name derived from variable <noreply@gunnar.cc>
    Re: calling subroutine , name derived from variable <jurgenex@hotmail.com>
    Re: calling subroutine , name derived from variable robic0
    Re: calling subroutine , name derived from variable <tadmc@augustmail.com>
    Re: calling subroutine , name derived from variable <noreply@gunnar.cc>
    Re: calling subroutine , name derived from variable robic0
    Re: calling subroutine , name derived from variable robic0
    Re: IO::Pipe and loss of data <nospam-abuse@ilyaz.org>
    Re: Line gives syntax error (Anno Siegel)
    Re: Line gives syntax error <mdudley@king-cart.com>
    Re: Line gives syntax error (Anno Siegel)
        The Question headers vs. the Answer content robic0
    Re: Want metachars escaped so they are not interpreted  robic0
    Re: Want metachars escaped so they are not interpreted  robic0
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Fri, 06 Jan 2006 04:08:54 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: Are there alternatives to exec and system
Message-Id: <q3mvf.8258$QI6.6250@trnddc07>

Joe Smith wrote:
> Correct.  Using system() without "&" says to wait as long as it takes
> for the other process to finish before continuing.  Using system()
> with "&" causes the other process to run independently, in which
> case you lose control over it.

Not quite. Using system() with the ampersand "&" will cause system to fork a 
new process, start a shell in that process, and hand over the argument to 
that shell.
What happens then, i.e. how the ampersand is interpreted, depends solely 
upon what the shell is doing with it and will vary between different shells.

jue




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

Date: Thu, 5 Jan 2006 19:11:45 -0500
From: "Madhu Ramachandran" <madhuram@nortel.com>
Subject: calling subroutine , name derived from variable
Message-Id: <dpkck1$g8b$1@zcars129.ca.nortel.com>

all:

I want to call subroutine, but the name of the subroutine itself is in a 
variable. I was able to do this. However, i also want to pass arguments .. 
not able to do this.
eg: if $sub has the subroutine name, and $arg has the arg to the subroutine. 
How can i call this from my perl main program? i tried eval() and it worked 
if i dont have any arguments.

#!/usr/local/bin/perl

$method="aSub";
$aa="\"bla\"";
$mm = "$method" . "($aa)";
print ("mm = $mm\n");
$ret = eval($mm);
print ("ret = $ret\n");
$ret=eval($method);
print ("ret = $ret\n");

sub aSub()
{
  my ($arg1) = @_;
  print ("inside aSub, arg1=$arg1\n");
  return 1;
}
##### Output ######
mm = aSub("bla")
ret =
inside aSub, arg1=
ret = 1
##################

My perl version: This is perl, v5.6.0 built for sun4-solaris

any pointers?

Thanks in advance.

Madhu 




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

Date: Fri, 06 Jan 2006 01:44:36 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: calling subroutine , name derived from variable
Message-Id: <425snrF1hgsjaU1@individual.net>

Madhu Ramachandran wrote:
> I want to call subroutine, but the name of the subroutine itself is in a 
> variable. I was able to do this. However, i also want to pass arguments ..

     my $method = 'aSub';
     my $aa = 'bla';
     my $subref = \&$method;
     my $ret = $subref->($aa);
     print "ret = $ret\n";

     sub aSub {
         my ($arg1) = @_;
         print "inside aSub, arg1=$arg1\n";
         return 1;
     }

-- 
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl


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

Date: Thu, 5 Jan 2006 19:42:03 -0500
From: "Matt Garrish" <matthew.garrish@sympatico.ca>
Subject: Re: calling subroutine , name derived from variable
Message-Id: <n1jvf.41090$X25.916828@news20.bellglobal.com>


"Madhu Ramachandran" <madhuram@nortel.com> wrote in message 
news:dpkck1$g8b$1@zcars129.ca.nortel.com...
> all:
>
> I want to call subroutine, but the name of the subroutine itself is in a 
> variable. I was able to do this. However, i also want to pass arguments .. 
> not able to do this.

You're looking for symbolic references, but it's not good practice to use 
them. For example:

$subRef = 'this_sub';
$arg1 = 'first argument';
$arg2 = 'second argument';

&{$subRef}($arg1, $arg2);

sub this_sub {
   print "$_[0] : $_[1]\n";
}


It's better practice to use a hash as you won't break the strictures pragma 
that way, which should make your code easier to maintain:

my %subRefs = ( this_sub => \&this_sub );

my $subRef = 'this_sub';

my $arg1 = 'first argument';
my $arg2 = 'second argument';

$subRefs{$subRef}($arg1, $arg2);

sub this_sub {
   print "$_[0] : $_[1]\n";
}

Matt 




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

Date: Thu, 05 Jan 2006 19:27:14 -0800
From: robic0
Subject: Re: calling subroutine , name derived from variable
Message-Id: <mjorr1h9dul5om9rf6af5occqs1qob32fc@4ax.com>

On Thu, 5 Jan 2006 19:42:03 -0500, "Matt Garrish" <matthew.garrish@sympatico.ca> wrote:

>
>"Madhu Ramachandran" <madhuram@nortel.com> wrote in message 
>news:dpkck1$g8b$1@zcars129.ca.nortel.com...
>> all:
>>
>> I want to call subroutine, but the name of the subroutine itself is in a 
>> variable. I was able to do this. However, i also want to pass arguments .. 
>> not able to do this.
>
>You're looking for symbolic references, but it's not good practice to use 
>them. For example:
>
>$subRef = 'this_sub';
>$arg1 = 'first argument';
>$arg2 = 'second argument';
>
>&{$subRef}($arg1, $arg2);
>
>sub this_sub {
>   print "$_[0] : $_[1]\n";
>}
>
>
>It's better practice to use a hash as you won't break the strictures pragma 
>that way, which should make your code easier to maintain:
>
>my %subRefs = ( this_sub => \&this_sub );
>
>my $subRef = 'this_sub';
>
>my $arg1 = 'first argument';
>my $arg2 = 'second argument';
>
>$subRefs{$subRef}($arg1, $arg2);
>
>sub this_sub {
>   print "$_[0] : $_[1]\n";
>}
>
>Matt 
>

This is bizzar, why would you use a hash of references to subs to call a subroutine?
Any use for that at all? Somebody gonna pass you the name of a subroutine in a packet?

The only "logical" use for an array of subroutines (or function pointers) is the "index",
into it, which means the "name" of the handler is hidden. 

-robic0-
actual subroutine reference can be called.



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

Date: Fri, 06 Jan 2006 05:12:31 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: calling subroutine , name derived from variable
Message-Id: <4268tmF1gt0mbU1@individual.net>

Gunnar Hjalmarsson wrote:
> Madhu Ramachandran wrote:
>> I want to call subroutine, but the name of the subroutine itself is in 
>> a variable. I was able to do this. However, i also want to pass 
>> arguments ..
> 
>     my $method = 'aSub';
>     my $aa = 'bla';
>     my $subref = \&$method;
>     my $ret = $subref->($aa);
>     print "ret = $ret\n";
> 
>     sub aSub {
>         my ($arg1) = @_;
>         print "inside aSub, arg1=$arg1\n";
>         return 1;
>     }

The above solution 'works', but I'd better admit that it's actually a 
symref, even if it passes strict. Matt's solution was criticized by that 
robic0 character, which proves that Matt provided a better answer.

Please disregard my code above.

-- 
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl


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

Date: Fri, 06 Jan 2006 04:16:28 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: calling subroutine , name derived from variable
Message-Id: <wamvf.8262$QI6.282@trnddc07>

robic0 wrote:
> This is bizzar, why would you use a hash of references to subs to
> call a subroutine? Any use for that at all?

Oh yes, very common scenario in jump tables.

Like in (pseudo-code)
    if ($op eq "add) then return $left + $right;
    if ($op eq "minus") then return $left - $right;
    if ($op eq "div") then return $left / $right;
    ...
    return "Unknown op $op";

This can be written much better as

    if (exists($op, %optable)) {
        $optable->$op ($left, $right);
    } else {
        throw_error "Unknown op $op";
    }

jue 




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

Date: Thu, 05 Jan 2006 20:28:39 -0800
From: robic0
Subject: Re: calling subroutine , name derived from variable
Message-Id: <j6srr15ililu8mndits4ut51o1999t6lu1@4ax.com>

On Fri, 06 Jan 2006 04:16:28 GMT, "Jürgen Exner" <jurgenex@hotmail.com> wrote:

>robic0 wrote:
>> This is bizzar, why would you use a hash of references to subs to
>> call a subroutine? Any use for that at all?
>
>Oh yes, very common scenario in jump tables.
>
>Like in (pseudo-code)
>    if ($op eq "add) then return $left + $right;
>    if ($op eq "minus") then return $left - $right;
>    if ($op eq "div") then return $left / $right;
>    ...
>    return "Unknown op $op";
>
>This can be written much better as
>
>    if (exists($op, %optable)) {
>        $optable->$op ($left, $right);
>    } else {
>        throw_error "Unknown op $op";
>    }
>
>jue 
>

Whats a "jump" table? Whats pesuedo-code?
$i = 0
$i = 1-$i
How far does extrapolation go (down)?
Is there logic I'm unaware of?
Can I be fooled?
Do I have time for un-paid thought?
Have I done almose everything?
Can a resume save me?
-robic0-


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

Date: Thu, 5 Jan 2006 22:32:33 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: calling subroutine , name derived from variable
Message-Id: <slrndrrsn1.c5h.tadmc@magna.augustmail.com>

Madhu Ramachandran <madhuram@nortel.com> wrote:

> I want to call subroutine, but the name of the subroutine itself is in a 
> variable. 


That is called a "symbolic reference".

Use a real reference instead:

   perldoc perlreftut

   perldoc perlref



> sub aSub()
          ^^
          ^^

Why did you put that there?

Do you know what it does?

Is what it does what you want to have done?


> {
>   my ($arg1) = @_;


I think not.


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


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

Date: Fri, 06 Jan 2006 05:48:32 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: calling subroutine , name derived from variable
Message-Id: <426b17F1h3125U1@individual.net>

Tad McClellan wrote:
> Madhu Ramachandran wrote:
>>{
>>  my ($arg1) = @_;
> 
> I think not.

Why not?

-- 
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl


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

Date: Thu, 05 Jan 2006 20:55:37 -0800
From: robic0
Subject: Re: calling subroutine , name derived from variable
Message-Id: <1ttrr1dn4lhunfsu8nvpve6gkqesur5jjf@4ax.com>

On Thu, 5 Jan 2006 22:32:33 -0600, Tad McClellan <tadmc@augustmail.com> wrote:

>Madhu Ramachandran <madhuram@nortel.com> wrote:
>
>> I want to call subroutine, but the name of the subroutine itself is in a 
>> variable. 
>
>
>That is called a "symbolic reference".
>
Why in hell would you use it in the context of a hash of "subroutines" ?
Get off your micro-analysis and look at it from a design point of reference.
Don't ever, ever take any class I teach...

>Use a real reference instead:
>
>   perldoc perlreftut
>
>   perldoc perlref
>
>
>
>> sub aSub()
>          ^^
>          ^^
>
>Why did you put that there?
>
>Do you know what it does?
>
>Is what it does what you want to have done?
>
>
>> {
>>   my ($arg1) = @_;
>
>
>I think not.



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

Date: Thu, 05 Jan 2006 21:05:00 -0800
From: robic0
Subject: Re: calling subroutine , name derived from variable
Message-Id: <1furr1pfrcac8cde5jt77uuaq4rrtpt781@4ax.com>

On Thu, 05 Jan 2006 20:28:39 -0800, robic0 wrote:

>On Fri, 06 Jan 2006 04:16:28 GMT, "Jürgen Exner" <jurgenex@hotmail.com> wrote:
>
>>robic0 wrote:
>>> This is bizzar, why would you use a hash of references to subs to
>>> call a subroutine? Any use for that at all?
>>
>>Oh yes, very common scenario in jump tables.
>>
>>Like in (pseudo-code)
>>    if ($op eq "add) then return $left + $right;
>>    if ($op eq "minus") then return $left - $right;
>>    if ($op eq "div") then return $left / $right;
>>    ...
>>    return "Unknown op $op";
>>
"jump tables" are an assembly acronymn.
Do you purport to parse assembly pseudonyms?
-robic-


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

Date: Thu, 5 Jan 2006 23:24:29 +0000 (UTC)
From:  Ilya Zakharevich <nospam-abuse@ilyaz.org>
Subject: Re: IO::Pipe and loss of data
Message-Id: <dpk9rd$2e9t$1@agate.berkeley.edu>

[A complimentary Cc of this posting was sent to
Genevieve S.
<none@here.com>], who wrote in article <dpgj3q$7u3$1@news.sap-ag.de>:
> Hello,
> 
> I use the module IO::Pipe to have many process-childen communicate to their 
> father. As they are all sending the same kind of information (and the father 
> has not the time to listen to a pipe for each of the processes), only one 
> pipe-object is used for it. Everything seemed to be ok, but then I noticed a 
> loss of data - a small one but at least a loss.

Are the reports self-delimited?  I assume they are...

It looks like you assume that writing to a pipe is atomic; in other
words, if you syswrite() a chunk to a pipe, then this chunk is
appearing "connected" when read from the pipe, even if multiple childs
write these chunks "simultaneously".

  a) I can't recall any OS claiming this a guaranteed behaviour; but I
     did not ever try looking hard ;-);

  b) this is definitely not true if you use buffered output to write
     to the pipe (i.e., print() from Perl).

So the first thing is to change print() to syswrite().  The second one
is to find what POSIX says about "a".

Hope this helps,
Ilya


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

Date: 5 Jan 2006 23:06:10 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Line gives syntax error
Message-Id: <dpk8p2$1kj$2@mamenchi.zrz.TU-Berlin.DE>

Marshall Dudley  <mdudley@king-cart.com> wrote in comp.lang.perl.misc:
> I have a script that I wrote and debugged on a Windows machine, but it
> fails on the UNIX machine.  The line is:
> 
>  $error =   `echo $passcode | gpg $options $filename`;

$error is a strange name for the result of the operation.

Also, echoing the passcode is a big security hole.  Any user can see it
while the program is running.  There must be better ways to get the
passcode into gpg.

> 
> The Windows machine brings up gpg, with the command line options of
> $options and $filename, but the Unix machine gives me the following
> error:
> 
> Syntax error: "|" unexpected.

That is a shell error message.

> Since I am printing out $error, and it is blank, the error appears to be
> coming from Perl, although it does not abort or give a line number, so
> maybe not.  I have tried putting a "\" in front of the pipe, but get the
> same result.

I bet $passcode contains a trailing linefeed that makes the shell
unhappy.  But you shouldn't echo it all over the place anyway.

Anno
-- 
If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article.  Click on 
"show options" at the top of the article, then click on the 
"Reply" at the bottom of the article headers.


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

Date: Thu, 05 Jan 2006 18:23:50 -0500
From: Marshall Dudley <mdudley@king-cart.com>
Subject: Re: Line gives syntax error
Message-Id: <43BDAA86.DB2F9279@king-cart.com>

Anno Siegel wrote:

> Marshall Dudley  <mdudley@king-cart.com> wrote in comp.lang.perl.misc:
> > I have a script that I wrote and debugged on a Windows machine, but it
> > fails on the UNIX machine.  The line is:
> >
> >  $error =   `echo $passcode | gpg $options $filename`;
>
> $error is a strange name for the result of the operation.

gnupg does not return anything if it is successful, it writes it's output to a
file.  Only if it encounters an error does it print out the error, so $error
is correct.

>
>
> Also, echoing the passcode is a big security hole.  Any user can see it
> while the program is running.  There must be better ways to get the
> passcode into gpg.

Nope, that is the only way you can get it to PGP, or if you do not pass it
that way, it will ask you for it each loop (which when I am billing would
require me to enter it about 500 times).  But it is not a security issue at
all, the machine it is on is secure and not a server, the only person who will
be there will be me at the local terminal, and the program asks for the
passcode when it comes up, so if anyone sees it, it will be me, and I am who
entered it in the first place.

>
>
> >
> > The Windows machine brings up gpg, with the command line options of
> > $options and $filename, but the Unix machine gives me the following
> > error:
> >
> > Syntax error: "|" unexpected.
>
> That is a shell error message.
>
> > Since I am printing out $error, and it is blank, the error appears to be
> > coming from Perl, although it does not abort or give a line number, so
> > maybe not.  I have tried putting a "\" in front of the pipe, but get the
> > same result.
>
> I bet $passcode contains a trailing linefeed that makes the shell
> unhappy.  But you shouldn't echo it all over the place anyway.

Bingo! That was the problem. When I entered the passcode, the return was being
stuck on the end of it as a \n. A simple chomp $passcode after the $passcode =
<STDIN> fixed it.  And dos was ignoring it and working because it ignores \n,
looking for a \r instead.

Thanks, I was looking for bug in all the wrong places.

Marshall

>
>
> Anno
> --
> If you want to post a followup via groups.google.com, don't use
> the broken "Reply" link at the bottom of the article.  Click on
> "show options" at the top of the article, then click on the
> "Reply" at the bottom of the article headers.



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

Date: 6 Jan 2006 00:21:27 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Line gives syntax error
Message-Id: <dpkd67$513$1@mamenchi.zrz.TU-Berlin.DE>

Marshall Dudley  <mdudley@king-cart.com> wrote in comp.lang.perl.misc:
> Anno Siegel wrote:
> 
> > Marshall Dudley  <mdudley@king-cart.com> wrote in comp.lang.perl.misc:
> > > I have a script that I wrote and debugged on a Windows machine, but it
> > > fails on the UNIX machine.  The line is:
> > >
> > >  $error =   `echo $passcode | gpg $options $filename`;
> >
> > $error is a strange name for the result of the operation.
> 
> gnupg does not return anything if it is successful, it writes it's output to a
> file.  Only if it encounters an error does it print out the error, so $error
> is correct.

It prints its errors to stdout?  I doubt that.  You won't see error messages
in $error.  You might as well use system() instead, but see below.

> > Also, echoing the passcode is a big security hole.  Any user can see it
> > while the program is running.  There must be better ways to get the
> > passcode into gpg.
> 
> Nope, that is the only way you can get it to PGP, or if you do not pass it
> that way, it will ask you for it each loop (which when I am billing would
> require me to enter it about 500 times).  But it is not a security issue at
> all, the machine it is on is secure and not a server, the only person who will
> be there will be me at the local terminal, and the program asks for the
> passcode when it comes up, so if anyone sees it, it will be me, and I am who
> entered it in the first place.

That's a pretty relaxed attitude towards security.  Why bother at all?

You don't have to *echo* the passcode to get it into gpg's stdin. Untested:

    open my $gpg, "| gpg $options $filename" or die;
    print $gpg $passcode;
    close $gpg or die;

is much safer.

<mumble>And here someone was painting me as an advocate for the use of
external commands</mumble>

[snip]

Anno
-- 
If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article.  Click on 
"show options" at the top of the article, then click on the 
"Reply" at the bottom of the article headers.


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

Date: Thu, 05 Jan 2006 19:58:26 -0800
From: robic0
Subject: The Question headers vs. the Answer content
Message-Id: <euprr112ejtcoqfcmmbpgitg070vfcq18a@4ax.com>

Lately, I've been intrigued by the posted headers that show up here.
Upon expansion of threads, I've noticed that only the simplest
education industry questions get real answers. AND those answers
are accompanied with vile rehtoric aimed at the poster, at some
pseudo "educational" janra, as if some here think they are the 
"teachers" of the Perl introductory class talking to starried
eyed newbies. The "should I use [] or {} ?" gets a hundred responses
from these morons. For the questions over thier heads, I mean just
intermediate ones, the response is "Have you got your head up ur ass?
I'm not here to write code for you dipshit. Read the Perldocs.....
er ah... > perldoc -{} your question.

IS THIS ALL THIS NEWSGROUP IS? Shouldn't there be a FAQ as to what
not to post here. I mean the "category" and "complexity". 
I wish this will get cleared up. I'm so tired of the 
QUESTIONS being a hell of alot better than the ANSWERS!!!!!
It would make someone searching usenet topics that they 
might actually find answers here.. which is a load of shit!
-robic0-



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

Date: Thu, 05 Jan 2006 18:56:46 -0800
From: robic0
Subject: Re: Want metachars escaped so they are not interpreted in regexp
Message-Id: <5mmrr1djn6ahu4un4muctvgl9aj73tim7j@4ax.com>

On Thu, 05 Jan 2006 01:13:48 -0500, Markus Dehmann <markus.dehmann@gmail.com> wrote:

>I have a pattern that I want to match against some text. The pattern may 
>contain some chars that happen to be metachars, but I don't want them to 
>be interpreted as metachars:
>
>my $pattern = 'Hello...?';
>$_ = 'Oh Hello x';
>if(m/$pattern/){
>   print "Oh no, it matches!\n"; # it matches indeed!
>}
>
>How do I prepare the $pattern properly before using it in the regexp?
>
>I used something like this:
>
>sub encode {
>   my $s = $_[0];
>   $s =~ s/(.)/sprintf "\\x%x",ord($1)/ge;
>   return $s;
>}
>
>to encode the pattern before using it in the regexp, but I think it's 
>inefficient and inelegant...?
>
>Does anyone have a better escape function?
>
>Thanks!
>Markus
>
>P.S.: I'm sorry if this is a FAQ (it should be!), but I googled and 
>didn't find anything.

Be carefull how you use strings mixed with escape characters when they 
are called out as declared constants in your program. For the most part
you don't want to fight the expression parser of your interpreter.
After digesting your constant string, I call it "in-solution" like in
Chemistry. When "in-solution" it is safe from mangling of editors and
parsers. Typically, the string you want to match against would be data
read in by your program from a file. In that case it is always "in-solution".
-robic0-


use strict;
use warnings;

my ($pat_convert);

$pat_convert  = convertPatternMeta ( 'Hello...?' );
showMatchResult ($pat_convert, 'Hello...? this is a big string x');
showMatchResult ($pat_convert, 'Oh Hello x');

$pat_convert  = convertPatternMeta ( '*?+' );
showMatchResult ($pat_convert, 'Hello...? this (*?+) is a big string x');
showMatchResult ($pat_convert, '*?+ and so is this');

## ------------------------------------
## Helpers
##
sub convertPatternMeta
{
    my ($pattern) = shift;
    my @regx_esc_codes =
    (
    "\\", '/', '(', ')', '[', ']', '?', '|',
    '+', '.', '*', '$', '^', '{', '}', '@'
    );
    foreach my $tc (@regx_esc_codes) {
        # code template for regex
        my $xxx = "\$pattern =~ s/\\$tc/\\\\\\$tc/g;";
        eval $xxx;
        if ($@) {
            # the compiler will show the escape char, add
            # it char to @regx_esc_codes
            $@ =~ s/^[\s]+//s; $@ =~ s/[\s]+$//s;
            die "$@";
        }
    }
    return $pattern;
}
##
sub showMatchResult
{
    my ($pattern, $string) = @_;
    my $result_txt = '';
    my ($result) = $string =~ /$pattern/;
    if ($result) { $result_txt = 'DOES match'}
    else { $result_txt = 'Does NOT match' }
    print "\nString:      $string\n$result_txt\nPattern:     $pattern\n";
}
__DATA__

String:      Hello...? this is a big string x
DOES match
Pattern:     Hello\.\.\.\?

String:      Oh Hello x
Does NOT match
Pattern:     Hello\.\.\.\?

String:      Hello...? this (*?+) is a big string x
DOES match
Pattern:     \*\?\+

String:      *?+ and so is this
DOES match
Pattern:     \*\?\+



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

Date: Thu, 05 Jan 2006 19:06:24 -0800
From: robic0
Subject: Re: Want metachars escaped so they are not interpreted in regexp
Message-Id: <dknrr1l42fjeerbqis2uri1rjikgrb7e81@4ax.com>

On 5 Jan 2006 08:27:58 GMT, anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) wrote:

>Markus Dehmann  <markus.dehmann@gmail.com> wrote in comp.lang.perl.misc:
>> I have a pattern that I want to match against some text. The pattern may 
>> contain some chars that happen to be metachars, but I don't want them to 
>> be interpreted as metachars:
>
>perldoc -f quotemeta
>
>Anno

Your an absurd example of a lump of lard
-robic0-


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

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


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