Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

help needed in File::Bom

by uva (Sexton)
on Apr 11, 2006 at 15:39 UTC ( [id://542568]=perlquestion: print w/replies, xml ) Need Help??

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

hai monks,
i like to find the encoding of the particular file and also the no of bytes occupied by the BOM.
so i used the below code, but it is giving error.
use File::BOM; open(IN,"< d:\\input.txt"); ($encoding, $spillage) = get_encoding_from_filehandle(HANDLE); close IN;
it is giving error as
"Undefined subroutine &main::get_encoding_from_filehandle called"
but open (IN, '<:via(file::BOM)',"d:\\input.txt") is working fine.
can any one tell me whats wrong with that one.

Replies are listed 'Best First'.
Re: help needed in File::Bom
by McDarren (Abbot) on Apr 11, 2006 at 15:48 UTC
    If you read the docs for File::BOM, you'll see that it exports nothing by default.

    Therefore, you need to specify the routine/s that you want in your use line; either:

    use File::BOM qw( :all );
    or..
    use File::BOM qw( get_encoding_from_filehandle );

    Cheers,
    Darren :)

      thanks for everyone replied me..
      Thaats working fine . but i couldnot find the no of bytes occupied by the BOM.any one help me in that.

        If you had read the docs as has already been suggested:

        After calling, the handle will be set to read at a point after the BOM (or at the beginning of the file if no BOM was found)

        So all you need to do is find out what your current position in the file is after you get the encoding:

        . . . ($encoding, $spillage) = get_encoding_from_filehandle(HANDLE); $bom_length = tell HANDLE; . . .

        The intelligent reader will judge for himself. Without examining the facts fully and fairly, there is no way of knowing whether vox populi is really vox dei, or merely vox asinorum. — Cyrus H. Gordon
Re: help needed in File::Bom
by davidrw (Prior) on Apr 11, 2006 at 15:44 UTC
    try use File::BOM qw( :all ) -- looks like the et_encoding_from_filehandle() function just isn't getting imported (the File::BOM docs state that nothing is exported by default).

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://542568]
Approved by kvale
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (5)
As of 2025-01-13 13:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Which URL do you most often use to access this site?












    Results (31 votes). Check out past polls.