Hi! Please consider following me on twitter: @hanekomu.
2008年05月30日
SQL-style Perl
Some syntacting sugar to make grep() and map()
look more like SQL:
#!/usr/bin/env perl use warnings; use strict; my @students = ( { id => 1234, marks => 20 }, { id => 4711, marks => 85 }, { id => 3000, marks => 86 }, { id => 9999, marks => 99 }, ); sub SELECT (&@) { my $code = shift; map { $code->() } @_ } sub WHERE (&@) { my $code = shift; grep { $code->() } @_ } sub FROM (@) { @_ } sub id () { $_->{id} } sub marks () { $_->{marks} } my @cleverlies = SELECT { id } WHERE { marks > 85 } FROM @students;
posted at: 18:59 | path: /dev | permalink | 0 comments | 0 trackbacks
Comments are closed for this story.
Trackbacks are closed for this story.