Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > How to read from a file with both text and binary

Reply
Thread Tools

How to read from a file with both text and binary

 
 
Brian
Guest
Posts: n/a
 
      06-26-2006
I am processing print job files. They all contain a Start banner with plain
text then following the banner comes the data to be printed. This data can
either be plain text or PCL (binary). I need to be able to determine what
format the data is in because the processing is different. I tried using -T
and -B on the file, but Perl returns -T as TRUE, I guess becuase of the
plain text header. The PCL always starts with the string ^[E^[... so I
tried searching for that, but to no avail with the following code:

while ( <SRCFILE> ) {
if ( $_ =~ /\^\[E\^\[/ ) { # Does this line contain ^[E^[
$pclFlag = 1;
print " PCL File detected\n";
}
}

Here is an example of part of a print job file containing PCL data:

* PRINT TIME: 13:30:38
*
* PRINT DATE: 23 JUN 2006
*
* PRINT NAME: TA104002
*
* SYSTEM: MVSA
*
*
*
**START*****START*****START*****START*****START*** **START*****START*****START**
^[E^[&u300D^[*v1O^[*v0N^[*c00001D^[)s64W@^B)$7^A^^^U^B^[*c0E^[(s17W^D^N^A^A^Ax^[*c1E^[(s17W^D^N^A^A^Ax^[*c2E^[(s17W^D
^N^A^A^Ax^[*c3E^[(s17W^D^N^A^A^Ax^[*c4E^[(s17W^D^N^A^A^Ax^[*c5E^[(s17W^D^N^A^A^Ax^[*c6E^[(s17W^D^N^A^A^Ax^[*c7E^[(s17W^D^N^A^A^Ax^[*c8E^[
(s17W^D^N^A^A^Ax^[*c9E^[(s17W^D^N^A^A^Ax^[*c10E^[


 
Reply With Quote
 
 
 
 
tuser
Guest
Posts: n/a
 
      06-26-2006
Brian wrote:
> I am processing print job files. They all contain a Start banner with plain
> text then following the banner comes the data to be printed. This data can
> either be plain text or PCL (binary). I need to be able to determine what
> format the data is in because the processing is different. I tried using-T
> and -B on the file, but Perl returns -T as TRUE, I guess becuase of the
> plain text header. The PCL always starts with the string ^[E^[... so I
> tried searching for that, but to no avail with the following code:
>
> while ( <SRCFILE> ) {
> if ( $_ =~ /\^\[E\^\[/ ) { # Does this line contain ^[E^[
> $pclFlag = 1;
> print " PCL File detected\n";
> }
> }
>
> Here is an example of part of a print job file containing PCL data:
>
> * PRINT TIME: 13:30:38
> *
> * PRINT DATE: 23 JUN 2006
> *
> * PRINT NAME: TA104002
> *
> * SYSTEM: MVSA
> *
> *
> *
> **START*****START*****START*****START*****START*** **START*****START*****START**
> ^[E^[&u300D^[*v1O^[*v0N^[*c00001D^[)s64W@^B)$7^A^^^U^B^[*c0E^[(s17W^D^N^A^A^Ax^[*c1E^[(s17W^D^N^A^A^Ax^[*c2E^[(s17W^D
> ^N^A^A^Ax^[*c3E^[(s17W^D^N^A^A^Ax^[*c4E^[(s17W^D^N^A^A^Ax^[*c5E^[(s17W^D^N^A^A^Ax^[*c6E^[(s17W^D^N^A^A^Ax^[*c7E^[(s17W^D^N^A^A^Ax^[*c8E^[
> (s17W^D^N^A^A^Ax^[*c9E^[(s17W^D^N^A^A^Ax^[*c10E^[


I have taken your print job file literally, i.e. the sequence "^[E^["
literally means 5 characters:
character "^", followed by another character "[", followed by "E", then
followed by another "^", and a final "["

....and, no surprise, the match "...if ( $_ =~ /\^\[E\^\[/ )..." works
fine.

However, I suspect that the 2-character sequence "^[" is not to be
taken literally, but really stands for one single control character
(possibly an octal "\033").

You could try the following instead:
if ( $_ =~ /\033E\033/ )

 
Reply With Quote
 
 
 
 
A. Sinan Unur
Guest
Posts: n/a
 
      06-26-2006
"tuser" <(E-Mail Removed)> wrote in
news:(E-Mail Removed) ups.com:

> Brian wrote:
>> I am processing print job files.


....

>> Here is an example of part of a print job file containing PCL data:
>>
>> * PRINT TIME: 13:30:38
>> *
>> * PRINT DATE: 23 JUN 2006
>> *
>> * PRINT NAME: TA104002
>> *
>> * SYSTEM: MVSA
>> *
>> *
>> *
>>**START*****START*****START*****START*****START* ****START*****START***
>> **START**
>> ^[E^[&u300D^[*v1O^[*v0N^[*c00001D^[)s64W@^B)$7^A^^^U^B


....

> However, I suspect that the 2-character sequence "^[" is not to be
> taken literally, but really stands for one single control character
> (possibly an octal "\033").
>
> You could try the following instead:
> if ( $_ =~ /\033E\033/ )


You are most likely correct that ^[ stands for the escape character. In
that case, you can also use \e instead of the octal code.

Sinan
--
A. Sinan Unur <(E-Mail Removed)>
(remove .invalid and reverse each component for email address)

comp.lang.perl.misc guidelines on the WWW:
http://augustmail.com/~tadmc/clpmisc...uidelines.html

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
compilation error: file exists in both in both 'c:\WINNT\Microsoft.NET\Framework\v2.0.50727 ABCL ASP .Net 0 05-29-2008 04:59 PM
2 computers, both online, both invisible to each other ? b Computer Support 9 04-21-2006 04:06 AM
Read Text File and split them to individual text file Krish ASP .Net 1 10-20-2005 03:39 PM
How to Put Both Left-Justified Text and Right-Justified Text on the Same Line? jaykchan@hotmail.com HTML 5 06-29-2005 07:01 PM



Advertisments