[Edinburgh-pm] parallel semantics in perl
Aaron Crane
perl at aaroncrane.co.uk
Tue Dec 14 02:49:41 PST 2010
Wim Vanderbauwhede <wim.vanderbauwhede at gmail.com> wrote:
> Maybe I could have a pragma "seq"
> instead, as the default would be to try parallel evaluation.
> Pragmas are lexically scoped, aren't they?
Yes; `perldoc perlpragma`. (Technically, you can write pragma-like
modules which have a non-lexical effect; but I don't think that's what
you were asking.)
> So I could write
>
> { use seq qw<foreach>;
> foreach my $i (1..$n) {
>
> }
> }
>
> and only the foreach in that block will be sequential, right?
Yes.
> This is not quite the same as I have in my current language, I would
> need attribute support on blocks for that -- anyone ever mentioned
> something like that? That would be ideal:
>
> foreach my $i (1..$n) :seq {
>
> }
>
> would be neat, but AFAICT these are only supported on subs...
I don't think I've ever seen a proposal for that. It looks initially
tempting; there's certainly a syntactic slot available where an
attribute-like thing could go. It's hard to see how you'd make it
work for statement-modifier `for`, though.
> I didn't know about qw<:all>. Are there others apart from :all, (I
> just came across a mention of ":default") or can I implement my own?
If you implement your own `import` routine, you can treat the
arguments to `use` in any way that makes sense for your module; see
`perldoc perlmod`. Colon-prefixed words are treated by Exporter as
identifying "tags" for arbitrary sets of names; `:all` is
conventionally a tag identifying everything you're willing to export.
--
Aaron Crane ** http://aaroncrane.co.uk/
More information about the Edinburgh-pm
mailing list