Re: behavior of m// operator



Nathan <user@xxxxxxxxxxxx> writes:

According to the documentation this program should print nothing since
m// uses the last successful pattern match from m//, split, etc. However
on my linux box it prints 1:

#!/usr/bin/perl -w

$a = "a";
$b = "b";
split /a/,$a;
print $b =~ m//;

Is the documentation wrong?

No, it is correct. `print' emits 1 because the succeeding match
operation ($b =~ m//) succeeded (m// essentially matches a `null'
string, which $b has:

,----[ perl -de 0 ]
| Loading DB routines from perl5db.pl version 1.28
| Editor support available.
|
| Enter h or `h h' for help, or `man perldebug' for more help.
|
| main::(-e:1): 0
| DB<1> ($a, $b) = ( qw(a b) )
|
| DB<2> x split /a/ => $a
| empty array
| DB<3> print $b =~ m//
| 1
| DB<4> x $b =~ m//
| 0 1
| DB<5>
`----

Because you used `=~', m// tries to match from $b, not from $a (really
$_) as you would expect.

--
I like the idea of 256 bits, though: 32 for the (Unicode) character leaves
room for 224 Bucky bits, which ought to be enough for anyone.
-- Roland Hutchinson, in alt.folklore.computers
.



Relevant Pages

  • Re: Programming PowerPC on Mac
    ... The documentation about how to program Windows with assembly language was, ... Linux and X and such with LuxAsm...because, over on Linux, it's the same ... There's nothing "official" only what ordinary developers (like ...
    (alt.lang.asm)
  • Linux Frequently Asked Questions with Answers (Part 6 of 6)
    ... stable kernel) you have discovered a bug in GCC. ... Refer to: ("The Machine Runs ... Linux is a very good memory tester--much better than MS-DOS based ... documentation that comes with util-linux to find out how to do this. ...
    (comp.os.linux.misc)
  • Linux Frequently Asked Questions with Answers (Part 6 of 6)
    ... stable kernel) you have discovered a bug in GCC. ... Refer to: ("The Machine Runs ... Linux is a very good memory tester--much better than MS-DOS based ... documentation that comes with util-linux to find out how to do this. ...
    (comp.os.linux.misc)
  • Linux Frequently Asked Questions with Answers (Part 6 of 6)
    ... stable kernel) you have discovered a bug in GCC. ... Refer to: ("The Machine Runs ... Linux is a very good memory tester--much better than MS-DOS based ... documentation that comes with util-linux to find out how to do this. ...
    (comp.os.linux.misc)
  • Linux Frequently Asked Questions with Answers (Part 6 of 6)
    ... stable kernel) you have discovered a bug in GCC. ... Refer to: ("The Machine Runs ... Linux is a very good memory tester--much better than MS-DOS based ... documentation that comes with util-linux to find out how to do this. ...
    (comp.os.linux.misc)