Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: Get record separator of a file

by RichardK (Priest)
on Nov 14, 2012 at 09:35 UTC ( #1003769=note: print w/ replies, xml ) Need Help??


in reply to Get record separator of a file

You could use the unix file command to determine the file type and then you'll know what you need to do for the file types you're handling.

Also file will try to guess the separator for text files.

I think there's a cpan module for this but I've never used it -- does anyone know anything about it?


Comment on Re: Get record separator of a file
Re^2: Get record separator of a file
by afoken (Parson) on Nov 14, 2012 at 10:02 UTC
    You could use the unix file command to determine the file type and then you'll know what you need to do for the file types you're handling.

    file(1) just guesses, based on some magic constants, and it often guesses wrong.

    Also file will try to guess the separator for text files.

    No. It detects line endings, but not record separators for CSV files:

    /tmp>echo "foo;bar;baz" > testme /tmp>echo "1;2;3" >> testme /tmp>cat testme foo;bar;baz 1;2;3 /tmp>file testme testme: ASCII text /tmp>
    I think there's a cpan module for this but I've never used it -- does anyone know anything about it?

    File::Type, mod:://File::MMagic, both share the guessing problem.

    Alexander

    --
    Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)

      No. It detects line endings, but not record separators for CSV files:

      /tmp>echo "foo;bar;baz" > testme /tmp>echo "1;2;3" >> testme

      You seem to be confusing record separators and field separators. The line ending is the record separator and the ';' is the field separator.

        You seem to be confusing record separators and field separators.

        Yes, unfortunately I did.

        Alexander

        --
        Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1003769]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (5)
As of 2014-08-21 04:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (127 votes), past polls