Skip to content

Instantly share code, notes, and snippets.

@pdl
Created July 17, 2013 14:20
Show Gist options
  • Save pdl/6020967 to your computer and use it in GitHub Desktop.
Save pdl/6020967 to your computer and use it in GitHub Desktop.
Demonstrate simple function to return the first item in an array if called in scalar context.
#!perl
use strict;
use warnings;
use Test::More;
sub first_or_all {
return @_ if wantarray;
return shift;
}
sub lowercase {
return first_or_all ( map { lc } @_ );
}
is (lowercase('Jim'), 'jim' );
is_deeply ([lowercase('Jim', 'Angela')], ['jim','angela'] );
done_testing;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment