On 04/09/2013 03:58, Michael Rasmussen wrote:
On Wed, Sep 04, 2013 at 02:31:30AM +0100, Rob Dixon wrote:

John's solution:
     next if /[^[:lower:]_\d\-. ]/;


Doesn't work in this test environment:
     michael@bivy:~$ cat tpl && ./tpl
     #!/usr/bin/perl
     use strict;
     use warnings;

     print "\nJohn's solution\n";
     while(<DATA>) {
         print "Seen line: $_";
         next if /[^[:lower:]_\d\-. ]/;
         print;
     }

     __DATA__
     a good line
     Testing John code
     a #!! should not print line
     _ Should be OK line
     finish with a printing line

     John's solution
     Seen line: a good line
     Seen line: Testing John code
     Seen line: a #!! should not print line
     Seen line: _ Should be OK line
     Seen line: finish with a printing line

John's solution is to take this original program

    while (<IN>) {
      chomp;
      next if /^#/;
      # do stuff
    }

and correct it by altering the `next` statement to this

    next if /[^[:lower:]_\d\-. ]/;

The resulting program executes the line `# do stuff` with only

    a good line
    finish with a printing line

which is correct. Your line `_ Should be OK line` is excluded because it
contains capital letters.

Rob








--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to