[Purdue-pm] challenge snippet

Mark Senn mark at ecn.purdue.edu
Sat Aug 15 20:32:16 PDT 2015


Mark Senn <mark at purdue.edu> wrote on 2015-08-15 at 21:03 -04:
|  In Perl 5 and Perl 6, given the scalar $t, show how to delete
|  all ASCII space characters at the beginning and end of that string.
|  Only use statements built in to the version of Perl you are using.

Rick Westerman <westerman at purdue.edu> wrote on 2015-08-15 at 21:19 -04:
|  Isn’t that just a simple regex?  Here is a two liner.
|
|  $t =~ s/^\s+//; 
|  $t =~ s/\s+$//;

This program
    $t = "\ttesting";
    $t =~ s/^\s+//;
    $t =~ s/\s+$//;
    ($t eq 'testing')  and  print "ASCII tab character was deleted\n";
printed
    ASCII tab character was deleted

IMPROVED CHALLENGE SNIPPET STATEMENT
    In Perl 5 and Perl 6, given the scalar $t---which doesn't contain
    any "\n" characters---show how to delete all ASCII space characters
    (ASCII 32 decimal) at the beginning and end of that string.  Only
    use statements built in to the version of Perl you are using.

-mark


More information about the Purdue-pm mailing list