#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2011
    Location
    Strathmore, AB, Canada
    Posts
    14
    Rep Power
    0

    Making data 'safe' for writing to a flat file?


    The search function is throwing a 500 error, so apologies if this is covered elsewhere.

    I'm writing a small file that holds some user data and I want to ensure that I encode it so that I can read it back reliably.

    A few pieces of data could contain ANY character that could be stored in a Perl string. Also, some of these strings could be very long.

    Some example items that I would write to a file:

    NAME=Natália Braga
    CITY=São Paulo
    AGE=25
    MEMO=This is some text. It might contain newlines, quotation marks, diacritic marks, or any other "characters" that are legal to store in a perl string.\nHow can I safely convert these data items so that I can later read them back?
  2. #2
  3. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2009
    Posts
    335
    Rep Power
    246
    Have you looked at the encoding module?

    http://perldoc.perl.org/Encode.html

    As you are storing personal information in a text file, it will also enable obfuscation!

    Edit-> taken from the CPAN docs
    ------------------------------------------------------
    Encoding via PerlIO

    If your perl supports PerlIO (which is the default), you can use a PerlIO layer to decode and encode directly via a filehandle.
    Last edited by 1DMF; October 22nd, 2012 at 10:12 AM.
    Free MP3 Dance Music Downloads

    To err is human; To really balls things up you need Microsoft!
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    71
    Rep Power
    2
    I would look at the functionality of the Storable module or the pack/unpack function.

IMN logo majestic logo threadwatch logo seochat tools logo