Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot

Re^4: remove first and last character of string (updated)

by hippo (Chancellor)
on Oct 14, 2020 at 09:09 UTC ( #11122818=note: print w/replies, xml ) Need Help??

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; }


Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://11122818]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (7)
As of 2021-01-25 09:03 GMT
Find Nodes?
    Voting Booth?