http://qs321.pair.com?node_id=11122818


in reply to Re^3: remove first and last character of string (updated)
in thread remove first and last character of string

It's a question of exactly what you want.

Precisely so. This is why (IMHO) How to ask better questions using Test::More and sample data should be one of the first posts read by all wisdom seekers. Here's a fuller set of tests building on the example of BillKSmith. It's up to flieckster to flesh out the @tests array with more exhaustive data sets.

use strict; use warnings; use Test::More; my @tests = ( { have => '"654321_1111"', want => '654321_1111' }, ); plan tests => 5 * @tests; for my $t (@tests) { is billksmith ($t->{have}), $t->{want}, 'BillKSmith'; is syphilis ($t->{have}), $t->{want}, 'syphilis'; is grandfather ($t->{have}), $t->{want}, 'GrandFather'; is rsfalse ($t->{have}), $t->{want}, 'rsFalse'; is hippo ($t->{have}), $t->{want}, 'hippo'; } sub billksmith { my $string = shift; my $regex = qr/^\"(.+)\"$/; my ($got) = $string =~ m/$regex/; return $got; } sub syphilis { my $str = shift; substr ($str, 0, 1, ''); chop $str; return $str; } sub grandfather { my $str = shift; $str =~ s/^"|"$//g; return $str; } sub rsfalse { my $string = shift; for (1 .. 2) { $string = reverse $string; chop $string; } return $string; } sub hippo { my $str = shift; $str =~ tr/"//d; return $str; }

🦛