Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env perl
- use strict;
- use warnings;
- use utf8;
- use Test::More;
- sub camelize {
- my ($s) = @_;
- $s =~ s{(\w+)}{
- ($a = lc $1) =~ s<(^[a-z]|_[a-z])><
- ($b = uc $1) =~ s/^_//;
- $b;
- >eg;
- $a;
- }eg;
- $s;
- }
- sub decamelize {
- my ($s) = @_;
- $s =~ s{(\w+)}{
- ($a = $1) =~ s<(^[A-Z]|(?![a-z])[A-Z])><
- "_" . lc $1
- >eg;
- substr $a, 1;
- }eg;
- $s;
- }
- is camelize('snake_case'), 'SnakeCase';
- is decamelize('CamelCase'), 'camel_case';
- is decamelize(camelize('snake_case')), 'snake_case';
- is camelize(decamelize('CamelCase')), 'CamelCase';
- done_testing
- __END__
- =head1 NAME
- perl.pl - NO DESCRIPTION YET.
- =head1 SYNOPSIS
- =head1 OPTIONS
- =head1 AUTHOR
- tyru <tyru.exe@gmail.com>
Add Comment
Please, Sign In to add comment