| 1 | package DBI::ProfileSubs; | ||
| 2 | |||
| 3 | 2 | our $VERSION = "0.009396"; | |
| 4 | |||
| 5 | =head1 NAME | ||
| 6 | |||
| 7 | DBI::ProfileSubs - Subroutines for dynamic profile Path | ||
| 8 | |||
| 9 | =head1 SYNOPSIS | ||
| 10 | |||
| 11 | DBI_PROFILE='&norm_std_n3' prog.pl | ||
| 12 | |||
| 13 | This is new and still experimental. | ||
| 14 | |||
| 15 | =head1 TO DO | ||
| 16 | |||
| 17 | Define come kind of naming convention for the subs. | ||
| 18 | |||
| 19 | =cut | ||
| 20 | |||
| 21 | 2 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 22 | 2 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 23 | |||
| 24 | |||
| 25 | # would be good to refactor these regex into separate subs and find some | ||
| 26 | # way to compose them in various combinations into multiple subs. | ||
| 27 | # Perhaps via AUTOLOAD where \&auto_X_Y_Z creates a sub that does X, Y, and Z. | ||
| 28 | # The final subs always need to be very fast. | ||
| 29 | # | ||
| 30 | |||
| 31 | 8 | ▶ | sub norm_std_n3 { |
|
Subroutine
norm_std_n3: called CC=1 SCAR=0.0
Pod
undocumented
| |||
| 32 | # my ($h, $method_name) = @_; | ||
| 33 | 8 | local $_ = $_; | |
| 34 | |||
| 35 | 8 | s/\b\d+\b/<N>/g; # 42 -> <N> | |
| 36 | 8 | s/\b0x[0-9A-Fa-f]+\b/<N>/g; # 0xFE -> <N> | |
| 37 | |||
| 38 | 8 | s/'.*?'/'<S>'/g; # single quoted strings (doesn't handle escapes) | |
| 39 | 8 | s/".*?"/"<S>"/g; # double quoted strings (doesn't handle escapes) | |
| 40 | |||
| 41 | # convert names like log20001231 into log<N> | ||
| 42 | 8 | s/([a-z_]+)(\d{3,})\b/${1}<N>/ig; | |
| 43 | |||
| 44 | # abbreviate massive "in (...)" statements and similar | ||
| 45 | 0 | s!((\s*<[NS]>\s*,\s*){100,})!sprintf("$2,<repeated %d times>",length($1)/2)!eg; | |
| 46 | |||
| 47 | 8 | return $_; | |
| 48 | } | ||
| 49 | |||
| 50 | 2 | 1; | |