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
scoping u perl-u (main vs package)
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  6 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Dobrica Pavlinusic  
View profile  
 More options Oct 30 2009, 9:57 am
From: Dobrica Pavlinusic <dpav...@gmail.com>
Date: Fri, 30 Oct 2009 14:57:02 +0100
Local: Fri, Oct 30 2009 9:57 am
Subject: scoping u perl-u (main vs package)
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


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Dobrica Pavlinusic  
View profile   Translate to Translated (View Original)
 More options Oct 30 2009, 10:14 am
From: Dobrica Pavlinusic <dpav...@gmail.com>
Date: Fri, 30 Oct 2009 15:14:53 +0100
Local: Fri, Oct 30 2009 10:14 am
Subject: Re: scoping u perl-u (main vs package)

On Fri, Oct 30, 2009 at 02:57:02PM +0100, Dobrica Pavlinusic wrote:

> 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?

Da odgovorim na svoje pitanje: zato jer perl ima file scope...

Kada to podjelim na dva file-a radi jedino:

--- main.pl ---

#!/usr/bin/perl

use warnings;
use strict;
use Data::Dump qw(dump);

use foobar;

foobar::run( qw/ foo bar baz foo/ );

warn dump $foobar::out;

--- foobar.pm ---

package foobar;

use warnings;
use strict;

my $out;        # XXX this doesn't work!

sub run {

        my $code = eval q|
                sub {
                        my $name = shift;
                        $foobar::out->{$name}++;
                }
        |;

        $code->( $_ ) foreach @_;

}

1;

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


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Igor Rumiha  
View profile   Translate to Translated (View Original)
 More options Oct 30 2009, 10:42 am
From: Igor Rumiha <igorrum...@gmail.com>
Date: Fri, 30 Oct 2009 15:42:55 +0100
Local: Fri, Oct 30 2009 10:42 am
Subject: Re: scoping u perl-u (main vs package)
2009/10/30 Dobrica Pavlinusic <dpav...@gmail.com>:

> On Fri, Oct 30, 2009 at 02:57:02PM +0100, Dobrica Pavlinusic wrote:

>> 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?

> Da odgovorim na svoje pitanje: zato jer perl ima file scope...

Bezobrazni copy-paste sa http://perldoc.perl.org/functions/my.html:

A my declares the listed variables to be local (lexically) to the
enclosing block, file, or eval.

Viđao sam da ljudi rade ovakve stvari:

package main;

{

my $var; # Vidljivo samo unutar ovog bloka

... kod koji koristi $var...

}

--
IgorR

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Boris Shomodjvarac  
View profile   Translate to Translated (View Original)
 More options Oct 30 2009, 10:51 am
From: Boris Shomodjvarac <shom...@gmail.com>
Date: Fri, 30 Oct 2009 15:51:11 +0100
Local: Fri, Oct 30 2009 10:51 am
Subject: Re: scoping u perl-u (main vs package)

Damian Conway je to stalno koristio za njegov Class::Std, inace stara
knjiga Object Oriented Perl :)

http://search.cpan.org/~dconway/Class-Std-v0.0.8/lib/Class/Std.pm#Aut...

Boris.

  signature.asc
< 1K Download

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Dobrica Pavlinusic  
View profile   Translate to Translated (View Original)
 More options Oct 30 2009, 10:58 am
From: Dobrica Pavlinusic <dpav...@gmail.com>
Date: Fri, 30 Oct 2009 15:58:41 +0100
Local: Fri, Oct 30 2009 10:58 am
Subject: Re: scoping u perl-u (main vs package)

Ma, da... taj implicitni { scope } je cool i čak ga i sam koristim
(povremeno) ali nekako uvijek zaboravim na taj file scope...

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


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Igor Rumiha  
View profile   Translate to Translated (View Original)
 More options Oct 30 2009, 11:32 am
From: Igor Rumiha <igorrum...@gmail.com>
Date: Fri, 30 Oct 2009 16:32:09 +0100
Local: Fri, Oct 30 2009 11:32 am
Subject: Re: scoping u perl-u (main vs package)
2009/10/30 Dobrica Pavlinusic <dpav...@gmail.com>:

> Ma, da... taj implicitni { scope } je cool i čak ga i sam koristim
> (povremeno) ali nekako uvijek zaboravim na taj file scope...

Mala škola Enterprise Perla, lekcija br. 114:

Jedan package, jedan file. I obratno.

;)

--
IgorR


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »