Concatenation: $i.$j different from "$i$j"

Concatenation: $i.$j different from "$i$j"

am 21.09.2007 00:22:48 von Occidental

{
my $i = "TT";
my $j = "AT";

if ("$i$j" =~ /X/)
{
print "$i$j matched\n";
}
else
{
print "$i$j not matched\n";
}
}

{
my $i = "TT";
my $j = "AT";

if ($i.$j =~ /X/)
{
print $i.$j . " matched\n";
}
else
{
print $i.$j . " not matched\n";
}
}

gives

TTAT not matched
TTAT matched

Can anyone explain?

Re: Concatenation: $i.$j different from "$i$j"

am 21.09.2007 00:37:50 von xhoster

Occidental wrote:

>
> if ($i.$j =~ /X/)

> Can anyone explain?

Precedence can. =~ is two lines above . in the perlop list of
precedences.

$ perl -MO=Deparse,-p -e ' "x"."y" =~ /f/'
('x' . ('y' =~ /f/));
-e syntax OK

Xho

--
-------------------- http://NewsReader.Com/ --------------------
The costs of publication of this article were defrayed in part by the
payment of page charges. This article must therefore be hereby marked
advertisement in accordance with 18 U.S.C. Section 1734 solely to indicate
this fact.

Re: Concatenation: $i.$j different from "$i$j"

am 21.09.2007 05:11:28 von Dummy

Occidental wrote:
> {
> my $i = "TT";
> my $j = "AT";
>
> if ("$i$j" =~ /X/)
> {
> print "$i$j matched\n";
> }
> else
> {
> print "$i$j not matched\n";
> }
> }
>
> {
> my $i = "TT";
> my $j = "AT";
>
> if ($i.$j =~ /X/)
> {
> print $i.$j . " matched\n";
> }
> else
> {
> print $i.$j . " not matched\n";
> }
> }
>
> gives
>
> TTAT not matched
> TTAT matched
>
> Can anyone explain?

Yes, perl can:

$ perl -MO=Deparse,-p -e'
{
my $i = "TT";
my $j = "AT";

if ("$i$j" =~ /X/)
{
print "$i$j matched\n";
}
else
{
print "$i$j not matched\n";
}
}

{
my $i = "TT";
my $j = "AT";

if ($i.$j =~ /X/)
{
print $i.$j . " matched\n";
}
else
{
print $i.$j . " not matched\n";
}
}
'
{
(my $i = 'TT');
(my $j = 'AT');
if (("$i$j" =~ /X/)) {
print("$i$j matched\n");
}
else {
print("$i$j not matched\n");
}
}
{
(my $i = 'TT');
(my $j = 'AT');
if (($i . ($j =~ /X/))) {
print((($i . $j) . " matched\n"));
}
else {
print((($i . $j) . " not matched\n"));
}
}
-e syntax OK


if (("$i$j" =~ /X/)) {

Is false because there is no 'X' in 'TTAT'.

if (($i . ($j =~ /X/))) {

Is true because the string from the expression ($i . ($j =~ /X/)) is true.



John
--
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order. -- Larry Wall

Re: Concatenation: $i.$j different from "$i$j"

am 21.09.2007 19:29:43 von rvtol+news

Occidental schreef:

> if ("$i$j" =~ /X/)
> if ($i.$j =~ /X/)

I heard somewhere that the next version of Python will make

1+2 * 3

behave differently from

1 + 2*3

;)

--
Affijn, Ruud

"Gewoon is een tijger."

Re: Concatenation: $i.$j different from "$i$j"

am 21.09.2007 20:59:03 von Abigail

_
Dr.Ruud (rvtol+news@isolution.nl) wrote on VCXXXIV September MCMXCIII in
:
%% Occidental schreef:
%%
%% > if ("$i$j" =~ /X/)
%% > if ($i.$j =~ /X/)
%%
%% I heard somewhere that the next version of Python will make
%%
%% 1+2 * 3
%%
%% behave differently from
%%
%% 1 + 2*3
%%


If you had written 'Perl6' instead of 'Python', I would have assumed
you were serieus.


Abigail
--
map{${+chr}=chr}map{$_=>$_^ord$"}$=+$]..3*$=/2;
print "$J$u$s$t $a$n$o$t$h$e$r $P$e$r$l $H$a$c$k$e$r\n";

Re: Concatenation: $i.$j different from "$i$j"

am 22.09.2007 13:07:47 von rvtol+news

Abigail schreef:
> Dr.Ruud:
>> Occidental:

>>> if ("$i$j" =~ /X/)
>>> if ($i.$j =~ /X/)
>>
>> I heard somewhere that the next version of Python will make
>>
>> 1+2 * 3
>>
>> behave differently from
>>
>> 1 + 2*3
>
> If you had written 'Perl6' instead of 'Python', I would have assumed
> you were serieus.

Hey, I was just aiming for a bigger publiek.

--
Affijn, Ruud (actually likes Perl6)

"Gewoon is een tijger."