On Fri, Jun 19, 2009 at 07:01:40PM -0400, MK wrote: > > Why in this component: > > <%perl> > > my $this= "hello world"; > > sub one { > print $this; > } > > one(); > > </%perl> > > is $this not available to one()?
Components are compiled to anonymous subroutines by Mason. Named subs inside anonymous subs do not share lexical variables with those anonymous subs. If you're using warnings (which you should be), you will get a "lexical variable $this will not stay shared at ..." If you want named subs, use Perl modules. Otherwise, use anonymous coderefs: my $this = "hello world"; my $one = sub { print $this }; $one->(); > Also, I notice that by using "our", a > variable becomes subsequently available to any component. However, I > recall from rails that using a global that way was a bad idea because > in a production environment, two users accessing the system at the same > time could end up affecting the same variable, and the solution was > either to use cookies or to write session variables to a per user > database. Is this true here as well? Ie, if I suddenly decide using > "our" is a nifty way to save passing parameters, will I lose my head > when this gets put on the net? I don't know anything about the Rails problem you're describing, but yes, you will, because using globals are a good way to produce massively interdependent and unmaintainable spaghetti code. Action at a distance always bites you. hdp. ------------------------------------------------------------------------------ Are you an open source citizen? Join us for the Open Source Bridge conference! Portland, OR, June 17-19. Two days of sessions, one day of unconference: $250. Need another reason to go? 24-hour hacker lounge. Register today! http://ad.doubleclick.net/clk;215844324;13503038;v?http://opensourcebridge.org _______________________________________________ Mason-users mailing list Mason-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/mason-users