YAPC::2004::Israel << Previous | Index | Next >> Copyright © 2004 Gaal Yahas

But wait! What if we already had $_ defined?


  • Nesting these expressions: dangerous?

     while (<>) {
        if (my ($trusted) = /trusted_users = (.*)/x) {
            foreach (split /,/, $trusted) {
                $current_user->register_trust($_);
            }
        }
        # some more handling: what happens to $_?
     }
  • This works well, because $_ was localized by the foreach and restored after it. So we're safe...

    • Implicitly:

     local $_;
     foreach $_ (split /,/ $trusted) {
            # ...