Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
Ť Groups Home
Message from discussion scoping u perl-u (main vs package)

Received: by 10.204.19.131 with SMTP id a3mr28974bkb.23.1256911024004;
        Fri, 30 Oct 2009 06:57:04 -0700 (PDT)
Received: by 10.204.19.131 with SMTP id a3mr28973bkb.23.1256911023958;
        Fri, 30 Oct 2009 06:57:03 -0700 (PDT)
Return-Path: <dpav...@rot13.org>
Received: from mjesec.ffzg.hr (mjesec.ffzg.hr [193.198.212.4])
        by gmr-mx.google.com with ESMTP id 18si349072bwz.1.2009.10.30.06.57.03;
        Fri, 30 Oct 2009 06:57:03 -0700 (PDT)
Received-SPF: neutral (google.com: 193.198.212.4 is neither permitted nor denied by best guess record for domain of dpav...@rot13.org) client-ip=193.198.212.4;
Authentication-Results: gmr-mx.google.com; spf=neutral (google.com: 193.198.212.4 is neither permitted nor denied by best guess record for domain of dpav...@rot13.org) smtp.mail=dpav...@rot13.org
Received: from llin.rot13.org (localhost [127.0.0.1])
	by mjesec.ffzg.hr (Postfix) with ESMTP id 6941414573
	for <zagrebpm@googlegroups.com>; Fri, 30 Oct 2009 14:57:00 +0100 (CET)
Received: by llin.rot13.org (Postfix, from userid 1000)
	id A7A35877B1; Fri, 30 Oct 2009 14:57:02 +0100 (CET)
Date: Fri, 30 Oct 2009 14:57:02 +0100
From: Dobrica Pavlinusic <dpav...@gmail.com>
To: zagrebpm@googlegroups.com
Subject: scoping u perl-u (main vs package)
Message-ID: <20091030135702.GB20225@rot13.org>
MIME-Version: 1.0
Content-Type: text/plain; charset=iso-8859-2
Content-Disposition: inline
Content-Transfer-Encoding: 8bit
User-Agent: Mutt/1.5.20 (2009-06-14)

Prije nego što postam na perlmonks i ispadnem papak, da pitam vas:

zašto $out radi kada je u main scope-u, tj. zašto zapravo nije
$foobar::out?


  #!/usr/bin/perl
  
  use warnings;
  use strict;
  use Data::Dump qw(dump);
  
  my $out;	# this works
  
  foobar::run( qw/ foo bar baz foo/ );
  
  warn dump $out;
  
  package foobar;
  
  use warnings;
  use strict;
  
  #my $out;	# XXX this doesn't work!
  
  sub run {
  
  	my $code = eval q|
  		sub {
  			my $name = shift;
  			$out->{$name}++;
  		}
  	|;
  
  	$code->( $_ ) foreach @_;
  }

-- 
Dobrica Pavlinusic               2share!2flame            dpav...@rot13.org
Unix addict. Internet consultant.             http://www.rot13.org/~dpavlin