Slash Boxes
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
More | Login | Reply
Loading... please wait.
  • That's really useful. But having to use coderefs is a bit ugly. So I've added support for a :Shortcut attribute. The code is in my svn repository: Attribute-Shortcut/ [].

      sub basename :Shortcut { s!.*/!! for @_ }

      for ( '/path/to/foo', '/some/path/to/bar' ) {
          print "Munging " . basename . "\n";
          open my $fh, '<', $_ or die $!;
          # note how $_ still contains the full pathname
          # ...


    • I wish I'd thought of that. Very clever!

    • Nice. I guess it’s worthy of being put on CPAN, after all. I’ll steal the attribute idea as that makes it much easier to use with named subs, but I still want the subref interface available for building anonymous ones.

      Now I just need to think of a good name – shortcutted is fine for an off-the-cuff function, but it doesn’t meet my standards for something on CPAN…

      • Feel free to steal the code as you see fit.

        As to still wanting to do Subrefs, I think that you should be able to use Attributes with them as well. But I have no idea how, I'll need to play with that.