user-pic

Gábor Szabó - גאבור סבו

  • Posted YAPC::EU - over 200 participants to Gábor Szabó - גאבור סבו

    YAPC::EU Granada has just passed 200 confirmed participants already passing two previous YAPC::EUs and there is still more than a month to go.

    YAPC::NA in Salt Lake City gained mo…

  • Posted Has YAPC::NA 2016 been announced? to Gábor Szabó - גאבור סבו

    I don't seem to remember any blog post here or on TPF. Has the location, time or the organizers of YAPC::NA been announced?

  • Subscribe to feed Recent Actions from Gábor Szabó - גאבור סבו

    • BooK commented on A widespread and broken Perl idiom

      This is explained in the last section, and the linked patch shows an example. The first code excerpt became:

      my $content = do { local ( *ARGV, $/ ); @ARGV = ("$file"); <> };

    • BooK commented on A widespread and broken Perl idiom

      To be conviced of how widespread the technique is, just check: https://grep.metacpan.org/search?q=local.*@ARGV

    • Aristotle commented on A widespread and broken Perl idiom

      I became aware of this as far back as my PerlMonks days, so at least 15 years ago. Namely, I memorised that I should be writing the idiom like this:

      my $content = do { local ( *ARGV, $/ ) = [ ... ]; <> };

      This differs from the incorrect version by exactly 3 character swaps.

    • Damian Conway commented on A widespread and broken Perl idiom

      Sadly, this elegant approach doesn't solve the original problem.

      typeglob only localizes the slot being assigned to. The rest of the typeglob remains unlocalized, which means the magic <> still messes up the global $ARGV and the global *ARGV{IO} filehandle.

      For example:

      sub report_ARGV {
          use Data::Dump 'pp';
          say shift;
          say '  $ARGV       = ', pp $ARGV;
          say '  @ARGV       = ', pp @ARGV;
          say '  %ARGV       = ', pp %ARGV;
          say '  *ARGV->tell = ', *ARGV->tell;
      }
      …
    • Aristotle commented on A widespread and broken Perl idiom

      Oh, wow.

      I had to go all the way to

      $_ = [ __FILE__ ] for local *ARGV;

      to make it work in a single statement. Even something like

      *{ \local *ARGV } = [ __FILE__ ];

      wouldn’t work, despite the fact that circumfix deref is effectively a do { } block with a whole separate inner scope (e.g. *{ my $x = 'hi'; local \*ARGV } = [ __FILE__ ]; say $x; is a strict vars violation).

      I don’t think local is that super-intelligent, which means what’s going on must be something like …

    Subscribe to feed Responses to Comments from Gábor Szabó - גאבור סבו

    About blogs.perl.org

    blogs.perl.org is a common blogging platform for the Perl community. Written in Perl and offering the modern features you’ve come to expect in blog platforms, the site is hosted by Dave Cross and Aaron Crane, with a design donated by Six Apart, Ltd.