Monday, February 18, 2013
Just add a space
All we have to do is add a space.
Just add a space to Perl 5.X.X to get Perl 5 X.X. Our language is Perl 5. We should own that fact. Yeah, there is another language named Perl 6 that might be better (if it is every finished) and one named Perl 4 that is worse. We are currently on version 16.2 of Perl 5. Our version number is now significantly more than 6, which lets the people who want to rename Perl to get people to stop paying attention to the fact the Perl 6 is still not production ready to have a version greater than 6 while not confusing the issue.
And while we are at it, let's sit down with Ubuntu and Red Hat and come up with a way to package Perl 5 that suits both us and them. Something that makes their life easier and encourages them to release newer versions of Perl 5, while, at the same time, fits our needs as developers.
Thursday, September 2, 2010
I need a few lines of nasty Perl 5 code.
maps with complex bodies would be good. If you have one or more such beasts, would you leave a comment with them?The talk will be given at The Pittsburgh Perl Workshop.
Wednesday, July 14, 2010
Adventures in Ignorance: Autovivification for fun and profit
Perl 5 autovivifies hashes and arrays when an undef is used as a hashref or arrayref. Normally you see this when using multidimensional data structures like this:
my %hash;
$hash{foo}{bar} = 1;
The value in $hash{foo} is undefined, so Perl 5 turns it into a hashref so it can lookup the key "bar" in it. This is somewhat dangerous because you can create keys without meaning to:
if ($hash{bar}{baz} == 1) {
say "found "bar/baz";
}Here the key "bar" will be added to the %hash if it doesn't already exist. To prevent this we must check every level but the last with exists:
if (exists $hash{bar} and $hash{bar}{baz} == 1) {
say "found "bar/baz";
}When I think of autovivification, that is all I normally think of, but today I realized you can use it for more than that. I have a couple of hashrefs I want to set the initial size of with keys. I was saying
my $hashref = {};
keys(%$hashref) = 1024;As I wrote that I wondered if autovivification would turn an undef in $hashref into a hashref for me, and sure enough it will:
#!/usr/bin/perl
use 5.012;
use warnings;
use Scalar::Util qw/reftype/;
my $hashref; #not really a hashref yet
keys(%$hashref) = 1024; #but now it is
say reftype $hashref;
Friday, July 9, 2010
Adventures in Ignorance: when both Perl and the Developer are too smart for their own good.
So, split returns the number of fields it would have split into when called in scalar context, but it also throws a warning in Perl 5.10: "Use of implicit split to @_ is deprecated". In an attempt to placate the warning I wrote
my $count =()= split $delim, $string;
but was surprised to find that every string returned 1. This is due to a nice little optimization that split does for you:
When assigning to a list, if LIMIT is omitted, or zero, PerlTo get around this you must specify your own limit of
supplies a LIMIT one larger than the number of variables in the
list, to avoid unnecessary work. For the list above LIMIT
would have been 4 by default. In time critical applications it
behooves you not to split into more fields than you really
need.
-1:my $count =()= split $delim, $string, -1;
Of course, -1 doesn't have the same behavior as no limit or a limit of 0 (a limit of -1 preserves empty trailing fields), so this is not necessarily what you want. This leaves us with the last line of defense, turning off warnings (and it isn't pretty):
my $count = do {
no warnings "deprecated";
split $delim, $second;
};
Thursday, July 1, 2010
Announcing the Perl 5 Documentation Team
I am excited to announce the formation of the Perl 5 Documentation Team. Our goal is to have the best, most current, and easiest to use and understand documentation of any programming language. Why settle for small goals?
Since the success of this team will depend on having both expert and novice points of view, membership is open to all, regardless of experience level with Perl. This is an excellent opportunity for people who would like to make a contribution back to the Perl community to do so in a way that doesn't require expert programming abilities.
If you are interested in being part of the team, please subscribe to the Perl Documentation mailing list, as future discussion will occur there (look for the thread named "I want to sign up"). If you know of other people who may be interested in being part of this effort, please pass this message on to them.
Areas where the team will be active include:
- Reviewing and updating documentation to ensure that it is friendly to new users
- Updating examples in documentation to a style compatible with Modern Perl practices
- Updating the documentation so that all examples longer than one line contain a
usestatement indicating the minimum version of Perl 5 required to run the example - Monitoring p5p for incoming documentation patches, ensuring they contain a patch against the current delta, and forwarding them to committers as needed
- Monitoring p5p for patches that will require modification of documentation, and ensuring that the documentation is modified appropriately
- Verifying that perlglossary contains current accurate definitions for all jargon terms
Goals to be met for the Perl 5.14.0 release include:
- Recruit novice and experienced Perl programmers to the team, and create a Perl module (a la Perl::Staff) and a Perl 5 wiki entry listing the team members
- Finalize perlopquick as a replacement for perlop and modify the new perlop so that perlop and a shorter perlopref can be generated from a single source document
- Extend perldoc to use the new perlop to provide documentation on operators (tenative proposal: perldoc -O "^=")
- Create a perlfuncref, a series of short summaries of information in perlfunc, analogous to perlopref (Again, both of these will be generated from a single source document for ease of maintenance)
- Define a policy for documenting documentation changes in the Perl deltas (e.g. perl5133delta.pod)
- Define a set of documentation style guidelines, covering structure, style, and content
- Formally define the Perl 5 Documentation Team functions
- Set deadlines for the defining of longer term goals
- Create a logo for the Perl 5 Documentation Team
- Find a better name or nickname for the Perl 5 Documentation Team
Potential longer term (post-5.14.0) goals:
- Clean up perlre
- Extensive review and Modernization of all examples
- Develop a plan to integrate with the Pod2 translation project
Wednesday, March 3, 2010
Parts of Perl you never knew existed
- Prototypes
- what happens when you add a & to the start of a function call (aka why you shouldn't)
- split in void context
- goto function
- values vs variables (a superset of lists vs arrays)
- wantarray and contexts (void, scalar, list)
- pseudohashes
- tie
- typeglobs
- PadWalker
- source filters
- adding methods to existing classes
- interpolating things that aren't scalars or arrays
- when to use each vs keys
- warnings
- how to disable certain warnings without affecting other warnings
- how to add categories
- B::Deparse, showing the magic Perl does for you
- while (<>), while (readline), and while(readdir)
- default values for split, print, etc.
- do file
- weird operators
- special variables
- %main::
- $]
- $"
- $,
- $/ and $\
- %SIG
- what strict does and why
- symbolic references
- barewords
- regex magic
- \k
- \g
- \G
- \Q
- differences between scalar and list context
- recursion
Tuesday, October 20, 2009
Day six with Google Wave
On the browser side, it seems to work best with Google Chrome. This is not a big shock. It doesn't seem as memory hungry with Google Chrome (63 MB vs 200 MB in Safari or Firefox on the first page), but it does seem to grow in size over time as I access waves (102 MB after accessing 10 waves). Another nice thing about Chrome is its model for tabs. Each runs in its own process, so killing a tab frees all of the memory associated with it. This means that when it starts eating too much memory, I can simply start a new Google Wave tab and close the old one instead of having to shutdown the whole application (which is what I have resorted to with Firefox and Safari). The downside is that Google Chrome has not been released for OS X. Luckily there is a developer version available for Linux and OS X (which is what I have been running).
Thursday, October 15, 2009
Google Wave day two
The idea of flames brings up another thought. What will flames look like when you can edit not only your own messages, but other's messages as well? Google Wave needs a reputation system of some form. One that weights a person's reputation based on the opinion's of people you already trust. It also needs a way to control who can see a wave vs who can edit it. There are already read-only waves, but only the system can create them. I think it might become important for blips to be marked read-only, or writable only by a specific subset of the wave participants.
As for the memory issue I mentioned yesterday, it isn't so bad if I stay away from Waves that have many blips. Firefox (on OS X) is eating about 300 MB, which is up from the 100 MB it normally eats, but it has not yet exploded to the 1 GB mark like it did yesterday.
Wednesday, October 14, 2009
Day one with Google Wave
If have mostly used it like email so far, I haven't had a chance to play with the IM like features. I have used the wiki-like editing feature though, replayed the history of a couple of waves, and used the map gadget and everything worked pretty much the way I expected it to. I played a little with the kasyntaxy bot and it was interesting, but its Perl syntax highlighting leaves a lot to be desired.
If you are on Google Wave as well, drop me a line at chas.owens.
Monday, October 12, 2009
A blogger gadget for Ironman
- Click "Customize"
- Click "Add a Gadget"
- Click "Add your own"
- enter the URL
http://wonkden.net/ironman_perl_gadget.xml - Click "ADD BY URL"
- Set the background color
- Set the name you registered with the Ironman competition
- Set the sex of your badge
- And, finally, click "Save"
<?xml version="1.0" encoding="UTF-8" ?>
<Module>
<ModulePrefs
title = "Ironman Perl Gadget"
title_url = "http://wonkden.net/ironman_perl_gadget.xml"
height = "80"
author = "Chas. Owens"
author_email = "chas.owens@gmail.com"
/>
<UserPref
name = "bg"
display_name = "Background Color"
datatype = "string"
required = "true"
/>
<UserPref
name = "ironman-name"
display_name = "Ironman Perl name"
datatype = "string"
required = "true"
/>
<UserPref
name = "ironman-sex"
display_name = "Sex"
datatype = "enum"
required = "true"
>
<EnumValue value="male" display_value="Male"/>
<EnumValue value="female" display_value="Female"/>
</UserPref>
<Content type="html">
<![CDATA[
<script type="text/javascript">
var prefs = new _IG_Prefs();
var name = prefs.getString("ironman-name");
var sex = prefs.getString("ironman-sex");
var color = prefs.getString("bg");
var html = '<div align="center" style="background-color: ' + color + '"><img src="http://ironman.enlightenedperl.org/munger/mybadge/' + sex + '/' + name + '.png" alt="Ironman Perl badge for ' + name + '"></div>'
document.write(html);
</script>
]]>
</Content>
</Module>
Should PERL_UNICODE be considered harmful?
PERL_UNICODE to "SDL" as a matter of course when setting up my environment. This means that all of my filehandles will use the UTF-8 PerlIO layer unless the locale says otherwise or a specific layer is chosen explicitly. I do this because I don't want to have to worry about calling binmode or explicitly setting the PerlIO layer when opening a file:open my $fh, "<:utf8", $filenameThis has worked fine for me for years; however, recently I have noticed a few problems with it:
or die "could not open $filename: $!"
- You cannot compile Perl will it set
- Many modules fail their tests when it is set
- Scripts that work just fine in your environment fail in other environments
- since it affects all filehandles, it could cause bugs in modules (I have never actually seen this)
Does anyone know of any arguments to keep using it, or, conversely, more arguments to stop using it?
Monday, October 5, 2009
Yay! my badge works, Boo! no time for Perl
Monday, September 28, 2009
perlopref needs you
I am also thinking about changing the name to perlopquick since it isn't really a reference (it doesn't contain everything about the operators).
Sunday, September 20, 2009
giving some love to do
do {} construct does not get much love in most of the code I see. Besides do {} while loops, it is very useful for combining steps and limiting the scope of variables:my $contents = do {
local $/;
open my $fh, "<", $filename
or die "could not open $filename: $!";
<$fh>;
};The snippet above keeps the change to $/ and the $fh variable local to the section that needs it.
Sunday, September 13, 2009
adventures in ignorance: what I have learned from perlopref so far
Only the plain assignment operator (
=) can do list assignment. I found this out when I expected @a x= 5 to do something (besides throw an error that is). This makes sense for most of the assignment operators. For instance, @x += 2 makes very little sense, but I think @a x= 3 makes some sense, but alas it is an error.The bitwise and operator (
&) has different behavior with respect to strings than the bitwise or and xor operators (| and ^ respectively). Bitwise and truncates to the length of the shorter string, but bitwise or and xor extend the shorter string to the length of the longer one with nul characters.The arrow operator has surprising behavior with respect to coderefs. This code throws an error as I would expect:
#!/usr/bin/perlBut this code prints
use strict;
use warnings;
sub func {
return [qw/a b c/];
}
print func()[0], "\n";
"a\n":#!/usr/bin/perlThis seems to be an extension of the rule that lets you pretend that an AoA is really a multi-dimensional array. I knew this rule allowed you to say
use strict;
use warnings;
sub func {
return [qw/a b c/];
}
my $ref = \&func;
print $ref->()[0], "\n";
$aoa->[0][1]("arg1", "arg2"), but I had never tried it with the function call first.Some people use
~~X (i.e. ~(~X)) to force scalar context on X, boy are they going to be annoyed by the smartmatch operator.I go through bouts of knowing and forgetting this, but the flip-flop operators (
.. and ...) actually return useful information, not just true or false:#!/usr/bin/perlThe code above prints
use strict;
use warnings;
for my $i (1 .. 10) {
my $range = ($i == 2 or $i == 6) .. ($i == 4 or $i == 8);
print "$range: $i\n" if $range;
}
1: 2
2: 3
3E0: 4
1: 6
2: 7
3E0: 8
The comparison operators (
<=> and cmp) return -1, 0, and 1 not negative, zero, and positive. I had always though it wasn't guaranteed what the return value was, but apparently it is.Perl 5.10.1 does not have the
err operator (i.e. the low precedence version of //. I could have sworn it did, but it is not there. It looks like I am not the only one confused by its non-existence though, perlop has a section titled "Logical or, Defined or, and Exclusive Or" that only describes or and xor.The left bit shift operator (
<<) is not defined if you you shift past the boundary of your native integer. I had always assumed that it dropped those bits, but apparently that is just the behavior of the versions of C I have used in the past (ANSI/ISO C does not define the behavior of overflow due to shifting, so it is a crap shoot).The
and and or operators have different precedence levels. The and operator binds more tightly than or, so$x == 5 and $y == 6 or $x == 6 and $y == 5is the same as
(($x == 5) and ($y == 6)) or (($x == 6) and ($y == 5))
Saturday, September 12, 2009
Adding house policies to Perl::Critic.
Perl::Critic policy to warn him of the style violation was the way to go. I spent about fifteen minutes looking at the docs and writing code and I came up with this:package Perl::Critic::Policy::CodeLayout::NoSideComments;I was surprised at just how easy
use strict;
use warnings;
use Readonly;
use Perl::Critic::Utils qw{ :severities :classification :ppi };
use parent 'Perl::Critic::Policy';
our $VERSION = 20090904;
Readonly::Scalar my $DESC => "side comments are not allowed";
Readonly::Scalar my $EXPL => "put the comment above the line, not next to it";
sub supported_parameters { return }
sub default_severity { return 5 }
sub default_themes { return qw( custom ) }
sub applies_to { return 'PPI::Token::Comment' }
sub violates {
my ($self, $elem) = @_;
#look backwards until you find whitespace that contains a
#newline (good) or something other than whitespace (error)
my $prev = $elem->previous_sibling;
while ($prev) {
return $self->violation( $DESC, $EXPL, $elem )
unless $prev->isa("PPI::Token::Whitespace");
return if $prev->content =~ /\n/;
$prev = $prev->previous_sibling;
}
#catch # after a block start, but leave the #! line alone
return $self->violation( $DESC, $EXPL, $elem )
unless $elem->parent->isa("PPI::Document");
return;
}
1;
PPI and Perl::Critic makes this.
Announcing perlcolor
Perldoc is somewhat hard to get into...but it's the manual for a programming language, so that's expected; I don't think having pages to color and draw on would be a feasible idea for the next update. :-)I immediately disagreed. I think it is a fine idea and began work on such a document. At first it was simply a joke, but I am beginning to think that it might actually be a very good, light-hearted, introduction to Perl concepts such as CPAN, reporting bugs, etc. As with just about everything I do, I have put it up on GitHub. Fork it and add to it.
=head1 NAME
perlcolor - coloring book for new perlers
=head1 IMAGES
=head2 Camels and Llamas
Camels in connection with Perl are a trademark of O'Reilly Media. O'Reilly
publishes many of the most important Perl books such as Programming Perl (aka the Camel) and Learning Perl (aka the Llama). Have you read them?
_
.--' |
/___^ | .--.
) | / \
/ | /` '.
| '-' / \
\ | |\
\ / \ /\|
\ /'----`\ /
|| \ |
(| (|
|| ||
jgs /_( /_(
_ _
( \__//)
.' )
__/b d . )
(_Y_`, .)
`--'-,-' )
(. )
( )
( )
( . ) .---.
( ) ( )
( . ) ( . )
( ) ( . ),
( . `"'` . `)\
( . .)\
(( . . ( . )\\
(( . ( ) \\
(( ) _( . . ) \\
( ( . )"'"`(.( ) ( ;
( ( ) ( ( . ) \'
|~( ) |~( )
| ||~| | ||~|
jgs | || | | || |
_| || | _| || |
/___(| | /___(| |
/___( /___(
=head2 Monkeys
In the end we are all code monkeys. Code, code monkeys, code!
.="=.
_/.-.-.\_ _
( ( o o ) ) ))
|/ " \| //
.-------. \'---'/ //
_|~~ ~~ |_ /`"""`\\ ((
=(_|_______|_)= / /_,_\ \\ \\
|:::::::::| \_\\_'__/ \ ))
|:::::::[]| /` /`~\ |//
|o=======.| / / \ /
jgs `"""""""""` ,--`,--'\/\ /
'-- "--' '--'
=head2 Butterflies
Camelia is a butterfly. She is the Perl 6 mascot. Can you find the hidden
P6?
_ _
/ `._ _.' \
( @ : `. .' : @ )
\ `. `. ._ _. .' .' /
\;' P. `. \ / .' 6' `;/
\`. `. \ \_/ / .' .'/
) :-._`. \ (:) / .'_.-: (
(`.....,`.\/:\/.',.....')
>------._|:::|_.------<
/ .'._>_.-|:::|-._<_.'. \
|o _.-'_.-^|:|^-._`-._ o|
|`' ;_.-'|:|`-._; `'|
jgs ".o_.-' ;."|:|".; `-._o."
".__." \:/ ".__."
^
=head2 Bugs
Bugs are errors in code. Sometimes the bug is in Perl, but most of the time
the bug is your code. If you think the bug is in someone else's code, you
should report it to them. CPAN has a link for reporting bugs on each
module's page. Have you ever found a bug?
,_ _,
'.__.'
'-, (__) ,-'
'._ .::. _.'
_'(^^)'_
_,` `>\/<` `,_
` ,-` )( `-, `
| /==\ |
,-' |=-| '-,
)-=(
jgs \__/
=head2 Penguins
This is Tux. He is the Linux mascot. Linux is an important platform for
Perl. Linux comes in many flavors: Redhat, Ubuntu, SUSE, and many others.
Do you run Linux?
___
,-' '-.
/ _ _ \
| (o)_(o) |
\ .-""-. /
//`._.-'`\\
// : ; \
//. - '' -.| |
/: : | |
| | : ,/ /,
jgs _;'`-, ' |`.-' `\
) `\.___./; .'
'.__ )----'\__.-'
`""`
=head2 Daemons
This is the BSD Daemon. His name is Beastie. BSD is an important platform
for Perl. FreeBSD, NetBSD, OS X, and others are all variants of BSD. Do
you run a BSD variant?
, ,
/( )`
\ \___ / |
/- _ `-/ '
(/\/ \ \ /\
/ / | ` \
O O ) / |
`-^--'`< '
(_.) _ ) /
`.___/` /
`-----' /
<----. __ / __ \
<----|====O)))==) \) /====
<----' `--' `.__,' \
| |
\ / /\
______( (_ / \______/
,' ,-----' |
`--{__________)
=head2 Strawberries
Strawberry Perl is a version of Perl for Microsoft Windows. It comes with
its own build environment to make installing Perl modules from CPAN easy.
Have you every installed a Perl module from CPAN?
VVVVVVVV
'oOOOOOOOOo'
'ooOOOOOOoo'
'oooOOooo'
'oooooo'
'oooo'
=head2 Shebang
The shebang line is what tells the OS the path to Perl. What is the path to
your Perl?
# # # # !! !!
# # # # !! !!
# # # # !! !!
#### #### #### !! !!
!! !!
#### #### #### !! !!
# # # # !! !!
# # # # !! !!
# # # # !! !!
#### #### #### !! !!
#### #### ####
# # # # !! !!
# # # # !! !!
# # # # !! !!
=head1 TODO
We need a good ASCII art version of Hexley (the Darwin Mascot).
My strawberry is terrible.
=head1 LICENSE
The BSD Daemon appears to be public domain. The strawberry and the #! are
released under the same terms as Perl. The rest of the ASCII art came from
L<http://www.geocities.com/soho/7373/index.html>.
Monday, September 7, 2009
What to call the ... operator?
... operator? In list context it is identical to the range operator (..) and in scalar context it is almost identical to the flip-flop operator (also ..). The Camel and perlop are strangely silent on this. I am currently calling it the alternate range/flip-flop operator for lack of a better term. What do you call it?
Sunday, August 30, 2009
meta: no time to write what I want! badges! brokeness!
- simple parsing
- shared memory (IPC and persistence)
- dealing with Unicode combining characters (needs more research)
Saturday, August 22, 2009
Projects in progress as of 2009-08-22
"42", "𝟜𝟚", or "᠔᠒"), but I am still not certain how the interface should work. For instance, should it only allow single digits (forcing the user to build more complicated regexes?my $one = digit_one();Should it take a string and replace the digits and character classes with the expanded character classes?
my $re = digit_regex "This matches 42";Should it be OO based and let you chose specific sets of digits?
my $ud = Unicode::Digit->new(I am leaning toward the last one. And I am leaning toward only allowing a small subset of regex-like syntax (basically numbers and character classes containing numbers or ranges only).
"ASCII", #special case, "" looks stupid
"MATHEMATICAL DOUBLE-STRUCK",
"MONGOLIAN"
);
my $re = $ud->digit_regex("[1-3]");
autobox::dump (GitHub, CPAN)
YAML and Data::Dump::Streamer.Term::Throbber (not published anywhere)
perlopref (GitHub)
warnin's (GitHub)
warnin's is going to die an ignoble death. The talk of removing ' as a package separator combined with my own apathy means it is unlikely for anything new to be done with it.