Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Locked thread
German Joey
Dec 18, 2004

yaoi prophet posted:

I wrote that and mentioned it in one of the earlier perl threads, but I don't think I ever posted it. Let me see if I can dig it up.

Edit: Found it. In Pirate.pm:

Just so you know, it absolutely breaks the poo poo out of just about any real script. ALL string literals get filtered, so it makes a mess of all sorts of things (the first thing that broke when I tried it on some existing scripts as a joke was it broke the Getopt::Long specifications for arguments). Still a funny prank.

you could fix that if you were so inclined. instead of doing a substitution in the overload method, you could instead return a tie::scalar'd variable (of, say, a new Tie::Pirate). the FETCH method of Tie:Pirate could then be overloaded to something like this:

code:
# untested but you get the idea
sub FETCH {
    my ($self) = @_;

    my $sub = (caller(1))[3];
    if ($sub eq 'print') { # or any output function
        my $string = $$self;

        # i think it might be more effective to join your list with |
        # and then feed that into the substitution, perl's regex engine
        # is optimized for poo poo like that
        foreach my $word (keys %filter) {
            my $target = $filter{$word};
            $string =~ s/$word/$target/gi; # by the way pirate talk is gay
         }
         return $string;
     }

     return $$self;
}
and so your substitutions only happen when the variable is output, and all of your other poo poo remains intact.

you can actually do some extremely goofy poo poo this way, as you can effectively modify any runtime behavior of perl you could possibly dream of. i wrote an example of some of this using an early version of PadWalker (which is even more powerful now, it looks like!) a long time ago: http://www.perlmonks.org/?node_id=316345

Adbot
ADBOT LOVES YOU

German Joey
Dec 18, 2004

yaoi prophet posted:

Of course, although tied hashes are actually a sane way to accomplish this sort of thing, whereas I was trying to come up with a hilariously inappropriate prank abusing one of the most wtf aspects of perl (being able to overload string literals).

nono, you misunderstand. you overload AND tie. so your overload constructor looks like this:

code:
# all code written and tested within this reply window
package Pirate;

sub import {
    overload::constant( 
        q => sub {
            my $newstr;
            tie $newstr, 'Tie::Pirate';
            return $newstr;
        },
    );
} 

package Tie::Pirate;
require Tie::Scalar;
our @ISA = qw(Tie::StdScalar);

my %filter = ... #

sub FETCH {
    ... # previous post
}
so, same transparency as before without any weird runtime errors :)

quote:

Edit: Sub::Sealed is pretty funny. Somewhere I have a module I wrote that will set UNIVERSAL::AUTOLOAD to a routine that will search for any semi-close matches for undefined subroutines that get called, including pawing through local directories for .pm files. Prank perl is the best.

http://search.cpan.org/~davecross/Symbol-Approx-Sub-2.06/

German Joey
Dec 18, 2004

Sartak posted:

It'll be my first YAPC, so I can't say for sure. But I am very excited about it. There are so many talks I want to see and people I want to meet. You should definitely come by. It's only $100. I think you'll get your money's worth.

i noticed that they still have a few Perl6 sessions in the program. i mean, for christs sake, who the gently caress still cares about it? its been 8 years now!

German Joey
Dec 18, 2004

ashgromnies posted:

One of my coworkers was on the original Topaz Perl 6 project and said that development changed a lot since then - they were making good progress and had a team that fit well together, but other influences changed things and I guess they scrapped a lot of work.

I unfortunately don't know any specifics.

oh man, topaz, i remember that. that was chip salzenburg's thing, wasn't it? last i heard he was locked up in jail or somesuch. i guess the bigshots in perl community have never had much luck with the law.

if i remember right, topaz was just a rewrite of the perl 5 core in C++. the motivation was that new language features were too hard to implement due to the immense complexity of the perl 5 core. i just looked it up and that was NINE years ago. yeesh! i was just talking about the rewrite done with parrot. topaz was scrapped for parrot because larry and the community wanted a language rewrite in addition to an implementation rewrite. i remember working quite a bit on the first implementation of perl 6 on parrot for a few years - the one written in perl 5 that started after a half a dozen apocalypses or so had come out. it, unfortunately, collapsed due to its immense weight and the lack of developers holding it together. oh well.

i also remember this book: Perl 6 and Parrot Essentials. i tech-reviewed both editions. i remember being so excited when it first came out! i thought that the book would drum up enough excitement and momentum in the community to finish the project within two years!

the second edition came out four years ago. :(

German Joey
Dec 18, 2004

KillerTwinkie posted:

Slight derail.

The one thing I'm looking forward to the most is the complete revamp of the Regular Expression syntax, which is radically different in a lot of ways than the current Perl 5 Regular Expression syntax: http://dev.perl.org/perl6/doc/design/apo/A05.html. For example, '(...)' still denotes a capturing group, however, '[...]' is for non-capturing instead of the ungainly '(?:...)'. This change means that character classes are a completely different beast altogether. :)

the new regular expressions were definitely one of my favorite planned features of Perl 6 too. but minor syntactical changes aren't even the half of it! the best feature by far were "rules", which allow the programmer to build up complicated expressions in an object oriented way (inspired by Parse::RecDescent of course).

i wrote up an article about em a few weeks after Apocalypse 5 came out (i.e. 6 years ago, LOL) that compares perl5 to perl6 in an example of parsing javascript code, if you're interested in learning more. http://www.perlmonks.org/?node_id=179555

German Joey
Dec 18, 2004

magimix posted:

That's just a syntactic nicety. Same with how you usually don't need to include the quotes around a literal hash-key (e.g. $test->{'key'} vs $test->{key}). However, I've always preferred to keep dereferences 'explicit' by using '->'. I like the arrows :3:

Edit: How the gently caress did I not spot I'd been 100%, thoroughly beaten?! Ninja Rope :argh:

syntactic niceties go a long way to keep your code from looking like line noise, especially when you're working with a structure thats more than a few levels deep.

German Joey
Dec 18, 2004

Cheesus posted:

I don't share his sentiment.

In fact, I'm suspicious and will be evalating the performance against some of these modules. The module that Ninja Rope mentions itself mentions performance concerns in the reviews (however one of them mentioned modifying another package to act nearly the same and possibly with better performance).

i've used Parse::RecDescent for a few projects in the past and it certainly is true that it is has significant performance drawbacks. as a good example: the grammar we used for the perl6 prototype involved a 1000-line BNF grammar that needed plenty of embedded code. when using it to compile a program there was a 30 second startup delay penalty during which Parse::RecDescent converted the BNF into an executable format (that internally used regexes to tokenize the input). that was reasonable for us since our prototype was not aimed at performance but at greatly simplifying the process of parsing a phenomally complex input files. for simple files, such as a logfile, you should be fine using more ordinary methods. BNF parsing will be, in general, much slower than a regular expression (which will be in turn much slower than unpack). the more complicated a parsing method can handle, the slower it'll be.

the main question i have for your coworker then is: why do you need something more powerful than a regex for parsing a loving log file? and why do you need something more efficient? how big is this file, in the gigabytes?

German Joey
Dec 18, 2004

Cheesus posted:

What's the best way to interface with a C++ library from Perl?

And once I'm there, what's the best way to return a C++ map as a hash?

I've been reading up on swig and while it seems pretty easy to call functions, I'm having a difficult time understanding how to return complex, dynamic structures.

depends what you're doing. Win32::Api, Inline::C (and Inline::CPP), and XS all offer different ways to interface with C++ with varying degrees of ease. if you don't want to do any post-processing, XS is probably your best bet of returning your data back to perl DIRECTLY as a hash, but if i were you i'd take a look at Win32::Api and Inline first. you can also use XS with Inline if you like what you see.

German Joey
Dec 18, 2004

Triple Tech posted:

Is there anything inherently good/bad/better/wrong with passing things by reference and modifying them? I almost never do it, I always use return values.

code:
my @stack = something_that_returns_a_list();

# versus
my @stack2;
something_that_modifies_by_ref(\@stack2);
I like to write my code semi functionally using map and whatnot, but sometimes I just need to accumulate and I think saying something like fill_er_up(\@stack, \%lookup, $items) would actually be the most concise way.

it depends how big your stack is, obviously! returning a new variable (essentially a copy of the data) is code-cleaner but more inefficent. its not too bad if your list is only a few thousand elements, but once you get into the millions and billions you won't really have that option. besides, indirect modification (either through references or pointers) is a pretty standard way to do things in many programming languages.

German Joey
Dec 18, 2004

checkeredshawn posted:

Well, this isn't why I want to do it, but imagine I'd like to do something like printing "[array name] has contents: [array contents]". Why I really want to do it has something to do with the GetOpt::Long, I'll explain in more detail later if you want.

you should be able to do something like what you want with a combination of Padwalker (http://search.cpan.org/dist/PadWalker/PadWalker.pm) and caller. just promise me you won't do something retarded with this! padwalker and the B modules are the perl equivalent of nuclear weapons. watch where you tread.

German Joey
Dec 18, 2004

German Joey posted:

you should be able to do something like what you want with a combination of Padwalker (http://search.cpan.org/dist/PadWalker/PadWalker.pm) and caller. just promise me you won't do something retarded with this! padwalker and the B modules are the perl equivalent of nuclear weapons. watch where you tread.

actually, looks like there's a new module that does EXACTLY what you want already called Devel::Caller (http://search.cpan.org/~rclamp/Devel-Caller-2.03/lib/Devel/Caller.pm) that uses Padwalker. how convenient. also, Padwalker has a new function called closed_over since i last saw it and i think those chumps borrowed from code that i wrote without giving me credit!!

Adbot
ADBOT LOVES YOU

German Joey
Dec 18, 2004

Sartak posted:

There's going to be another Frozen Perl in Minneapolis on February 7th. I'll be there. I've submitted a talk for Devel::REPL and Carp::REPL that will probably be accepted (though I won't find out until November 20th).

Anyone else planning on going?

i just looked at this and it seems like Carp::REPL owns. is there any chance that its pure perl?

  • Locked thread