The value of a role’s required attribute is only checked on object creation. This article provides one way of enforcing it when applying the role to an object on the fly.
Reflections on learning a new language, and the technology behind it.
Sunday, 17 December 2017
Moo: One approach to terminating the process when attributes of a dynamically assigned role are missing
Labels:
Dynamic Role Assignment,
Moo,
OO Perl,
required attribute,
Role
Saturday, 28 October 2017
Perl course in London
On Saturday November 25, 2017 I'll be running a 2 hour Introduction to Perl for developers of other languages
http://act.yapc.eu/lpw2017/talk/7224
Please make sure you register so that I can set you up with a free 2 week enrolment at Geekuni.
Where?
http://act.yapc.eu/lpw2017/talk/7224
Please make sure you register so that I can set you up with a free 2 week enrolment at Geekuni.
Where?
Cavendish Campus, University of Westminster
115 New Cavendish Street London W1W 6UW
https://www.westminster.ac.uk/about-us/visit-us/directions/cavendish
115 New Cavendish Street London W1W 6UW
https://www.westminster.ac.uk/about-us/visit-us/directions/cavendish
Perl string concatenation and repetition
One of the first Perl operators to learn is the "dot" concatenation operator (.) for strings. For example:
my $string = 'foo' . 'bar'; # $string is 'foobar'.
On the other hand, if you have an array of strings @arr, then you can concatenate them by joining them with an empty string in-between:
my $string = join('', @arr);
But what if you just want 10 "foo"s in a line? You might try the Python approach with 'foo' * 10 but Perl with its type conversion on the fly will try to convert 'foo' into a number and say something like:Argument "foo" isn't numeric in multiplication (*) at...
Instead you should use the repetition operator (x) which takes a string on the left and a number on the right:
my $string = 'foo' x 10;and $string is then
foofoofoofoofoofoofoofoofoofooNote that even if you have integers on both sides, the 'x' repetition operator will cast the left operand into a string so that:
my $str = 20 x 10; # $str is "2020202020202020202020"
('x','y','z') x 10
evaluates as:
('x','y','z','x','y','z','x','y', ...)
But be warned: if the left operand is not enclosed in parentheses it is treated as a scalar.
my @arr = ('x', 'y', 'z');
my @bar = @arr x 10;
is equivalent to
my @bar = scalar(@arr) x 10; # @bar is an array of a single integer (3333333333)while, turning the array into a list of its elements by enclosing it in parentheses:
my @foo = ( (@arr) x 10 );
# then @foo is ('x','y','z','x','y','z','x','y', ...)
In summary, if you remember that 'x' is different to '*' and lists are treated differently to scalars, it's less likely your code will give you an unpleasant surprise!
Saturday, 16 April 2016
Interview - Perl’s Pumpking Ricardo Signes
Perl’s pumpking is the person who manages the core Perl 5 language. Having worn that mantle for almost five years, Ricardo Signes (rjbs) has set the next major release to mark the end of his reign. Over this period Perl has moved forward in leaps and bounds in terms of features, stability and popularity. I’ve taken Signes’ reflective mood as an opportunity to understand the person and processes behind Perl’s golden age.
Sunday, 6 March 2016
The Perl flip-flop operator
Have you ever wondered where fashion and software development overlap? If so, look no further than the flip-flop. It's a feature available in Sed, Awk, Ruby and Perl which - akin to its namesake - is short, revealing and can raise a few eyebrows.
![]() |
| Robot Gear flip-flops by Cafepress |
Sunday, 31 January 2016
How To Grow a Development Team
For the manager of a technology shop, "Hotel California" has the ideal spin on staffing. As the Eagles so bluntly put it "You can check-out any time you like/But you can never leave!". In modern business speak - Hotel California has zero "churn", where churn is the portion of recruits each year who are hired to replace employees who've left.
| No Churn |
Labels:
agile,
churn,
code review,
hr,
pair programming,
recruitment,
training software development
Wednesday, 20 January 2016
Quick and Dirty: Vim highlighting and tag matching for HTML and Perl's Template Toolkit
If you're a Vim connoisseur you're probably using vim-perl for getting all the Perl goodies you can cram into Vim. On the other hand if, like me, you're building and trashing virtual machines left, right and centre to develop different widgets you don't have the patience to achieve a perfect Vim environment on each box. This is the quick and dirty solution which gets you 80% of the solution in a matter of seconds.
Labels:
perl,
syntax highlighting,
tag matching,
template toolkit,
tt,
vim
Subscribe to:
Posts (Atom)
