Saturday, October 15, 2011
Collaborators in an algorithm are like those tools, having them readily available lets you concentrate on the problem.
Friday, October 14, 2011
my $w3c = DateTime::Format::W3CDTF->new;
my $dt = $w3c->parse_datetime( $date_string );
I wish it was:
my $dt = DateTime::Format::W3CDTF->parse_datetime( $date_string );
and that the library created the parser on the fly as needed. It's not only less typing - but also much simpler mental model. This simpler model is sometimes too simple - for example if you parse a lot of dates then sparing the parser creation each time can make a difference.
I think the optimal thing to do is provide two APIs - like JSON - a functional one:
$perl_hash_or_arrayref = decode_json $utf8_encoded_json_text;
and an object oriented one:
$json = JSON->new->allow_nonref;
$perl_scalar = $json->decode( $json_text );
for those that need that extra control.
Monday, October 03, 2011
my $a = HTML::Entities::decode( 'ñ' );
open(my $fh, '>', $a );
print $fh "Without encoding\n";
open(my $fh1, '>', encode( 'UTF-8', $a ) );
print $fh1 "With encoding\n";
And here is the result when run on an system with UTF8 locales:
? a.pl ñ
zby@zby:~/myopera/tmp$ cat ñ
'a.pl' is the name of the script itself, the mark '?' hides the F1 hexadecimal code and that file contains 'Without encoding'.