[perl]代码库
#!/user/bin/perl
use Data::SearchReplace ( 'sr' );
sr ( { SEARCH => 'searching', REPLACE => 'replacing'}, \$complex_var );
# or OO
use Data::SearchReplace;
$sr = Data::SearchReplace->new ( { SEARCH => 'search for this',
REPLACE => 'replace with this'
} );
$sr->sr ( \$complex_var );
$sr->sr ( \$new_complex_var );
# if you want more control over your search/replace pattern you
# can pass an entire regex instead complete with attributes
sr ( { REGEX => 's/nice/great/gi' }, \$complex_var );
# you can even use a subroutine if you'd like
# the input variable is the value and the return sets the new
# value.
sr({ CODE => sub { uc($_[0]) } }, \$complex_var);
QUOTE:use Data::SearchReplace qw(sr);
sr({SEARCH => 'find', REPLACE => 'replace'}, \@data);
sr({REGEX => 's/find/replace/g'}, \%data);
sr({CODE => sub {uc($_[0])} }, \@data);
by: 发表于:2017-09-11 11:51:54 顶(0) | 踩(0) 回复
??
回复评论