I tried your solution. Here is my code which seems to work.

#!/usr/bin/perl use strict; use warnings; my $in_file_name = "D:/temp.s3"; my $data = ""; &extractDataFromSrecFile($in_file_name, \$data); print($data,"\n"); sub extractDataFromSrecFile { my ($file_name, $ref_data) = @_; my @in_data; # read file into memory open(my $fh, "<", $file_name) || die "Could not open \"$file_name\ +""; while( my $srec = <$fh> ) { chomp($srec); my $id = substr($srec,0,2); my $address = substr($srec, 4, 8); if( ($id eq "S3") && ($address ne "FC000000") ) { push(@in_data, $srec); } } close( $fh ); # store sorted data and check if it is complete $$ref_data = ""; my $next_address = 0xFC000018; # start address for( sort{ hex(substr($a, 4, 8)) <=> hex(substr($b, 4, 8)) } @in_d +ata ) { my $srec = $_; my $address = hex(substr($srec, 4, 8)); my $nb_data_bytes = hex(substr($srec,2,2)) - 4 - 1; # completeness check if( $address != $next_address ) { $$ref_data = ""; print "ERROR: S3-Record with address " . sprintf("%08X", $ +next_address) . " is missing in input file!\n"; return; } $$ref_data .= substr($srec, 12, ($nb_data_bytes * 2)); $next_address = $address + $nb_data_bytes; } }

Because I want to learn feel free to improve the code and give hints what I could do better.

Thank you

Dirk


In reply to Re^2: Storing unordered data from file in memory by Dirk80
in thread Storing unordered data from file in memory by Dirk80

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.