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;
}
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.