Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
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; }

🦛


In reply to Re^4: remove first and last character of string (updated) by hippo
in thread remove first and last character of string by flieckster

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • 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.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (7)
As of 2024-04-19 11:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found