in reply to Stripping non alphanumeric characters and leaving punctuation characters from a file

Whilst $line =~ tr[\x00-\x1f][]d; will strip ascii chars less than space from your input, I don't think that will do you any good if your input is terminating before the end.

If you can't read it, how can you fix it?

Have you tried using binmode on the file?

Does it make any difference?

Am I misreading your post?


Examine what is said, not who speaks.
"Efficiency is intelligent laziness." -David Dunham
"When I'm working on a problem, I never think about beauty. I think only how to solve the problem. But when I have finished, if the solution is not beautiful, I know it is wrong." -Richard Buckminster Fuller


  • Comment on Re: Stripping non alphanumeric characters and leaving punctuation characters from a file
  • Download Code

Replies are listed 'Best First'.
Re: Re: Stripping non alphanumeric characters and leaving punctuation characters from a file
by Popcorn Dave (Abbot) on Jun 06, 2003 at 19:40 UTC
    Well I could read it, but only to a certain point. I could read the first 231 lines in text mode.

    I thought that since it was a text file, or at least I thought it was that I shouldn't go in to binmode.

    However, since then svsingh helped me to get this working. I've modified his code to this:

    #!/usr/bin/perl -w use strict; open FH, 'pub71.html'; binmode FH; $\ = "<BR>"; while (<FH>) { next if $_ =~ /\,/; next if $_ =~ /^[a-z]/; if ( m/(.+)\s(\d{1,2}\.\d{2})%\s(.+)\s*<BR>/ ) { print "City:$1\tCounty:$3\tTax$2\n"; } } close FH;

    and it now reads all the information that I want.

    There is no emoticon for what I'm feeling now.