My end goal is to make changes to the file and then upload it back to the tools so that all 65+ tools do not have to be manualy updated.

If your goal is specifically to change the user name and/or password for one or more records, where the existing username and password are already known before you read the file, then you have a reasonable chance of success -- so long as you follow the advice in the 2nd reply above -- because it looks like those are fixed-width fields.

Even if you don't have a clear idea of where the record boundaries are, the fact that a known username and password can be found at a specific distance from each other in the input data makes it pretty simple to splice in a new username and/or password -- unless (as suggested in the first reply) this change needs to be incorporated into some sort of checksum value elsewhere in the record.

If some simple experiments with valid tools (to apply edits that create valid/usable versions of the file) show that you can just change the username and password without further ado, you could slurp the whole file into a scalar, and apply s/// based on the known old and new username/password:

# assuming INFILE and OUTFILE are already open, # and string variables are already set... my $match = $old_username . "\x00"x(84-length($old_username)) . $old_password . "\x00"x(84-length($old_password)); my $replace = $new_username . "\x00"x(84-length($new_username)) . $new_password . "\x00"x(84-length($new_password)); $/ = undef; my $filedata = <INFILE>; $filedata =~ s/$match/$replace/; print OUTFILE $filedata;
(updated to use the correct field width (84); actually, the password field width might be different -- no way to tell for sure, but 84 is probably a safe bet).

If you're trying to change something else in the data besides user name and/or password, well, so far there just isn't enough information available to handle that. You need to get real documentation about the file format to build your own editor for it.


In reply to Re: Reading encoded file with Perl by graff
in thread Reading encoded file with Perl by a115764m

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.