in reply to Another use bytes and length issue

(use bytes went beyond scope).
Huh?
$ cat /tmp/p #!/usr/bin/perl -wl my $s = "\x{100}"; print length $s; { use bytes; print length $s; } print length $s; $ perl588 /tmp/p 1 2 1 $

Dave.

Replies are listed 'Best First'.
Re^2: Another use bytes and length issue
by Burak (Chaplain) on Nov 06, 2006 at 21:56 UTC
    If he/she is doing:
    SCOPE: { use bytes; $l = length $foo; do_something(); }
    Then the scope becomes wider :) bytes will affect anything in do_something()
      Not so.
      sub print_length { my ($s) = @_; print(length($s), "\n"); } my $s = "\x{100}"; print_length($s); # 1 { use bytes; print_length($s); # 1 print(length($s), "\n"); # 2 } print_length($s); # 1

      Use a do block to limit the scope:

      $s = "\x{100}";; print do{ use bytes; length $s } . ' : ' . length $s;; 2 : 1

      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.
      well, duh.
      use bytes; my $s = "\x{100}"; print length $s; { no bytes; print length $s; } print length $s; 2 1 2