sowraaj has asked for the wisdom of the Perl Monks concerning the following question:

friends,

I need to read/view a .chr file by using perl script. I tried this code but the file handler shows unrecognized word format. i got output like this 'Start(...bM-i<^DM-KNp2^D...)end'. This is my code

#!/usr/bin/perl use strict; use POSIX; use warnings; open (NEWFILE, "C:\\cygwin\\home\\Administrator\\test.chr"); print "Start"; while(<NEWFILE>) { print $_; } print "end";

I need all your support to view this file. Thanks in Advance

Regards,

Raj

Replies are listed 'Best First'.
Re: .CHR file read
by toolic (Bishop) on Dec 08, 2011 at 14:31 UTC
    I need to read/view a .chr file by using perl script. I tried this code but the file handler is empty while executing the script. i got 'Startend' as output. This is my code
    Did you get any warnings? If so, tell us what they are.

    You could check the status of open:

    open( NEWFILE, "C:\\cygwin\\home\\Administrator\\test.chr" ) or die $! +;
    Are you sure your input file isn't empty?

    Updated to show OP's original statement.

      Dear friend,

      I can view a file data but the data can't able understand the data format(i.e. it looks like binary data)

      Thanks

        file file

        head file |od -tacx1

        head file | hexdump

Re: .CHR file read
by keszler (Priest) on Dec 08, 2011 at 14:53 UTC

    From the lines #!/usr/bin/perl and open (NEWFILE, "C:\\cygwin\\home\\Administrator\\test.chr"); I'm guessing you're running this in a cygwin shell on a Windows box. Does cygwin recognize "C:\\cygwin\\..." as a path, or should it be something like "/home/Administrator/test.chr"?

      The path should probably be /cygdrive/c/cygwin/home/Administrator/test.chr if the OP's Cygwin installation is anything like mine.

      Cheers,

      JohnGG

        Now that I'm home, with a box that runs cygwin:
        Windows cmd shell

        C:\cygwin\home\Keszler>dir Directory of C:\cygwin\home\Keszler 12/08/2011 07:33 PM 12 test.chr 12/08/2011 07:35 PM <DIR> x C:\cygwin\home\Keszler>cd x C:\cygwin\home\Keszler\x>dir Directory of C:\cygwin\home\Keszler\x 12/08/2011 07:35 PM 155 test.pl C:\cygwin\home\Keszler\x>type test.pl #!/usr/bin/perl use strict; use POSIX; use warnings; open (NEWFILE, "/home/Keszler/test.chr"); print "Start"; while(<NEWFILE>) { print $_; } print "end"; C:\cygwin\home\Keszler\x>test.pl readline() on closed filehandle NEWFILE at C:\cygwin\home\Keszler\x\te +st.pl line 7. Startend C:\cygwin\home\Keszler\x>
        cygwin shell
        $ pwd /home/Keszler/x $ ls -l total 1 -rwxr-xr-x 1 Keszler None 155 Dec 8 19:35 test.pl $ ls -l .. total 1 -rw-r--r-- 1 Keszler None 12 Dec 8 19:33 test.chr drwxr-xr-x+ 1 Keszler None 0 Dec 8 19:35 x $ cat test.pl #!/usr/bin/perl use strict; use POSIX; use warnings; open (NEWFILE, "/home/Keszler/test.chr"); print "Start"; while(<NEWFILE>) { print $_; } print "end"; $ ./test.pl Start1,2,3 a,b,c end $

Re: .CHR file read
by sumeetgrover (Monk) on Dec 08, 2011 at 14:51 UTC

    Your code is syntactically correct.

    You need to try out the suggestions made to you in the first comment posted by toolic.

    Hope this helps.