Pattern Matching in file with invisible char

M

M Pires

Hi there,

First of all, I am sorry if this is a FAQ. I couldn't find anything in the
PerlDoc, so if I missed something please be kind enough to redirect me to
it!

I am currently working on a Perl script that will parse out values from an
"almost" text file. The reason I say this is because there are "invisible"
chars in the file such as the ASCII SUB char ( 0x1A ). This chars confuse
the <HANDLE> and cause a premature EOF.

Is there a way around this?

Thx a lot!
 
T

Tad McClellan

M Pires said:
I am currently working on a Perl script that will parse out values from an
"almost" text file.


Then it is a binary file.

The reason I say this is because there are "invisible"
chars in the file such as the ASCII SUB char ( 0x1A ). This chars confuse
the <HANDLE> and cause a premature EOF.


Since we are concerned with files, it might be helpful to know what
OS is being used, as the operating system is what manages the filesystem.

Is there a way around this?


perldoc -f binmode
 
M

M Pires

perldoc -f binmode

Thank you very much! For reference the OS is W2K but your tip worked
like a charm. It's frustrating when the answer was in front of you all
along...!
 
T

Tad McClellan

M Pires said:
Thank you very much! For reference the OS is W2K but your tip worked
like a charm. It's frustrating when the answer was in front of you all
along...!


Often, all it takes is trying a bunch of different search terms.

perldoc -q binary

would have done it for you in this case...
 
B

Bart Lateur

M said:
I am currently working on a Perl script that will parse out values from an
"almost" text file. The reason I say this is because there are "invisible"
chars in the file such as the ASCII SUB char ( 0x1A ). This chars confuse
the <HANDLE> and cause a premature EOF.

It's not quite premature... On ancient systems (think DOS and earlier)
this was used as a end-of-file marker on text files. That's why
binmode() fixes this.

Don't forget you'll now have to delete unnecessary CR characters (=
"\r") yourself.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,014
Latest member
BiancaFix3

Latest Threads

Top