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

Hello,

I have inherited a Perl script that opens a base64 encoded, pipe delimited flat file, I need to decode it. Here's how the file is slurped up:
my $record = do { local( @ARGV, $/ ) = $file ; <> };

Then it splits $record into a TON of variables, so I would like to know if I could decode this in a simple fashion before the split.

Thanks,
Anono

Replies are listed 'Best First'.
Re: decode a file
by Codon (Friar) on May 13, 2005 at 22:12 UTC
    Is the data delimited, then encoded or encoded, then delimited. In otherwords, do you need to do the decode before the split or the decode before the variable assignment?

    If you need to the latter, shove a map {} in the middle.

    ($one, $two, ... $n) = map { decode_base64($_) } split m/\|/, $record;
    Note: I don't have the decode function in front of me, but I know others have provided a function for that.

    Ivan Heffner
    Sr. Software Engineer, DAS Lead
    WhitePages.com, Inc.
      This my good fellow is EXACTLY what I needed. Thank you very much.
Re: decode a file
by mifflin (Curate) on May 13, 2005 at 21:10 UTC
    use MIME::Base64; $decoded = decode_base64($record);
Re: decode a file
by jpeg (Chaplain) on May 13, 2005 at 21:13 UTC
    Are you aware of Gisle Aas' MIME::Base64?

    perldoc MIME::Base64 gives some examples that might look familiar (to you or the original programmer). You can decode the slurped file or decode by chunks. It's very simple.

    --
    jpg
Re: decode a file
by Anonymous Monk on May 13, 2005 at 21:24 UTC
    In fact I am trying to use it, but things aren't working as expected. I needd to find out if i could decode the whole file at one time, by simple decoding $record, if that's the case then I'll keep searching for the problem.
    Thanks