[Israel.pm] A Perl 5 Gotcha

sawyer x xsawyerx at gmail.com
Fri Mar 6 08:18:17 PST 2009


I don't understand the problem. You made an error you got bitten. It's simple.
You shouldn't (in any language) run a function that uses a variable
and define the variable only later. It doesn't make any reason. It's
like trying to get child welfare and having the child only a year
later and complaining that the government won't pay for my child
welfare before I had the kid.

Beyond that, you're defining the subroutine at the end, which exposes
it to @_. I seriously don't understand why you're considering it a
problem. You're simply doing something wrong. Two things actually.

On Fri, Mar 6, 2009 at 9:41 AM, Gaal Yahas <gaal at forum2.org> wrote:
>
> Another is near the top of the file to say:
>
> main() if !caller;
> sub main {
>    # ...
>    exit 0;
> }
>
> On Fri, Mar 6, 2009 at 9:35 AM, Yitzchak Scott-Thoennes
> <sthoenna at efn.org> wrote:
> > On Thu, March 5, 2009 1:12 pm, Shlomi Fish wrote:
> >> my $filename = "hello.txt";
> >>
> >> sub print_filename {
> >>     print $filename, "\n";
> >> }
> >
> > One thing you can do is to do the initialization at compile time:
> >
> >    my $filename;
> >    BEGIN { $filename = "hello.txt" }
> >
> >
> > _______________________________________________
> > Perl mailing list
> > Perl at perl.org.il
> > http://perl.org.il/mailman/listinfo/perl
> >
>
>
>
> --
> Gaal Yahas <gaal at forum2.org>
> http://gaal.livejournal.com/
> _______________________________________________
> Perl mailing list
> Perl at perl.org.il
> http://perl.org.il/mailman/listinfo/perl



More information about the Perl mailing list