From: Phred Phungus on
Sherm Pendley wrote:
> Willem <willem(a)turtle.stack.nl> writes:
>
>> Phred Phungus wrote:
>> ) $ perl1.pl
>> ) bash: perl1.pl: command not found
>>
>> chmod +x perl1.pl
>
> That's not the error being reported above.

Sorry, newsgroup. I forgot the technique. It was in my own log for me
to read. :-(

$ chmod 700 perl1.pl
$ ./perl1.pl
Placido P. Octopus
Polypacido P. Octopus
Placido P. Octopus
Polypacido Polyp Octopus
$

Thanks all for replies.
--
fred
From: Phred Phungus on
Ben Morrow wrote:
> Quoth Phred Phungus <Phred(a)example.invalid>:

>> my $string2 = "Placido P. Octopus\n";
>> print $string2;
>> $string =~ s/$regex/Polyp/g;
> ^^^^^^^
>> print $string2;
> ^^^^^^^^
>
> One of these things is not like the other.

Yeah. It's funny the things a person thinks when he can't see an error
like this, which is, of course, no error at all. You spend a minute
thinking the output might be right, but then not only is Juergen wrong,
but no one else in c.l.p.misc calls him on it. That seemed unlikely.

Hence the need to post. A different set of eyes makes all the
difference. I don't know how it runs with other people, but I tend to
see what I'm looking for and could miss Lady Godiva riding right next to it.

One thing I like about this ng are the frequently-posted faq's.
--
fred
From: sln on
On Wed, 31 Mar 2010 16:00:46 -0600, Phred Phungus <Phred(a)example.invalid> wrote:

>Ben Morrow wrote:
>> Quoth Phred Phungus <Phred(a)example.invalid>:
>
>>> my $string2 = "Placido P. Octopus\n";
>>> print $string2;
>>> $string =~ s/$regex/Polyp/g;
>> ^^^^^^^
>>> print $string2;
>> ^^^^^^^^
>>
>> One of these things is not like the other.
>
>Yeah. It's funny the things a person thinks when he can't see an error
>like this, which is, of course, no error at all. You spend a minute
>thinking the output might be right, but then not only is Juergen wrong,
>but no one else in c.l.p.misc calls him on it. That seemed unlikely.
>
>Hence the need to post. A different set of eyes makes all the
>difference. I don't know how it runs with other people, but I tend to
>see what I'm looking for and could miss Lady Godiva riding right next to it.
>
>One thing I like about this ng are the frequently-posted faq's.


How did you jump to the regular expression variables and s///
form substitutions without knowing what meta-chars and modifiers are?
From: Phred Phungus on
Peter J. Holzer wrote:
> On 2010-03-28 08:47, Phred Phungus <Phred(a)example.invalid> wrote:
>> PerlFAQ Server wrote:
>>> $string = "Placido P. Octopus";
>>> $regex = "P.";
>>>
>>> $string =~ s/$regex/Polyp/;
>>> # $string is now "Polypacido P. Octopus"
>>>
>>> Because "." is special in regular expressions, and can match any single
>>> character, the regex "P." here has matched the <Pl> in the original
>>> string.
>>>
>> Am I then correct that a period is not a character?
>
> No. Why do you think so?

Because I forgot one needed the g the modifier, but that's covered ground.

I'm really close to understanding all the dusty corners of this faq, but
I'm having trouble with the first 2 sentences:

The Perl parser will expand $variable and @variable references in
regular expressions unless the delimiter is a single quote. Remember,
too, that the right-hand side of a "s///" substitution is considered a
double-quoted string (see perlop for more details). Remember also that
any regex special characters will be acted on unless you precede the
substitution with \Q. Here's an example:

# end excerpt

I like the latest version of the script:

$ ./perl1.pl
Placido P. Octopus
Polypacido P. Octopus

Placido P. Octopus
Polypacido Polyp Octopus

Placido P. Octopus
Placido Polyp Octopus

$ cat perl1.pl
#!/usr/bin/perl

use strict;
use warnings;

my $string = "Placido P. Octopus\n";
my $regex = "P.";

my $string1 = $string;
print $string1;
$string1 =~ s/$regex/Polyp/;
print $string1;
print "\n";

my $string2 = $string;
print $string2;
$string2 =~ s/$regex/Polyp/g;
print $string2;
print "\n";

my $string3 = $string;
print $string3;
$string3 =~ s/\Q$regex/Polyp/;
print $string3;
print "\n";

$

What "expansion" occured in the perl parser?

Gruss,
--
fred
From: Tad McClellan on
Phred Phungus <Phred(a)example.invalid> wrote:

> I'm really close to understanding all the dusty corners of this faq, but
> I'm having trouble with the first 2 sentences:
>
> The Perl parser will expand $variable and @variable references in
> regular expressions unless the delimiter is a single quote. Remember,
> too, that the right-hand side of a "s///" substitution is considered a
> double-quoted string (see perlop for more details). Remember also that
> any regex special characters will be acted on unless you precede the
> substitution with \Q. Here's an example:
>
> # end excerpt
>
> I like the latest version of the script:

> my $regex = "P.";

> $string1 =~ s/$regex/Polyp/;


$regex gets expanded:

$string1 =~ s/P./Polyp/;

> $string3 =~ s/\Q$regex/Polyp/;


$regex gets expanded and special chars are escaped:

$string3 =~ s/P\./Polyp/;


> What "expansion" occured in the perl parser?


See above.


--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.liamg\100cm.j.dat/"
The above message is a Usenet post.
I don't recall having given anyone permission to use it on a Web site.