Stories
Slash Boxes
Comments
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

use Perl Log In

Log In

[ Create a new account ]

ChrisDolan (2855)

ChrisDolan
  (email not shown publicly)
http://www.chrisdolan.net/

Journal of ChrisDolan (2855)

Tuesday July 29, 2008
12:26 AM

Attributes::Handler in 5.8 vs. 5.10

[ #37040 ]

If you use attributes with multiple arguments like so:
        sub foo : myattr(one, two) { }

then it's important to realize that the attribute arguments are parsed differently under Perl 5.8 vs. Perl 5.10. In 5.8, you get a string like "one, two" passed to your :ATTR sub. Under 5.10, you instead get an arrayref like ['one', 'two'].

I had some 5.8 code that parsed the attribute args like so:
        my @args = split /\s*,\s*/, $args
which resulted in @args containing 'ARRAY[0x123456]' under 5.10! My new workaround that is compatible with 5.8 and 5.10 is:
        my @args = ref $args ? @{$args} : split /\s*,\s*/, $args;

If anyone sees flaws in this workaround, or has a better explanation, please comment.

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.