Hello fellow Monks!
I am in a conundrum again (yes again!). I am parsing a file that has specific parameters inside of it. I have completed the script and it does work on most files in question. What the problem is, is sometimes in these files there are parameters like "parameter_00" and "parameter_01" and "parameter_02" ect ect. I, however, will never know how many (could be hundereds of these entries in any given file). In the hash i predeclare the parameter and the read length. So if you're wondering what those values are, thats what they are

So, my question is, do i need to go ahead and add all these into the hash manually, or is there a way i can do it on the fly?
-attached files for testing at the bottom-
use strict; use warnings; my %hash = ( ACCOUNT_ID => '16', ACCOUNTID => '16', ANALOG_MODE => '4', APP_VER => '8', ATTRIBUTE => '4', BOOTABLE => '4', CATEGORY => '4', CONTENT_ID => '48', DETAIL => '1024', GAMEDATA_ID => '32', ITEM_PRIORITY => '4', LANG => '4', LICENSE => '512', NP_COMMUNICATION_ID => '16', NPCOMMID => '16', PADDING => '8', PARAMS => '1024', PARAMS2 => '12', PARENTAL_LEVEL => '4', PARENTAL_LEVEL_A => '4', PARENTAL_LEVEL_B => '4', PARENTAL_LEVEL_C => '4', PARENTAL_LEVEL_D => '4', PARENTAL_LEVEL_E => '4', PARENTAL_LEVEL_F => '4', PARENTAL_LEVEL_G => '4', PARENTAL_LEVEL_H => '4', PARENTAL_LEVEL_I => '4', PARENTAL_LEVEL_J => '4', PARENTAL_LEVEL_K => '4', PARENTAL_LEVEL_L => '4', PARENTAL_LEVEL_M => '4', PARENTAL_LEVEL_N => '4', PARENTAL_LEVEL_O => '4', PARENTAL_LEVEL_P => '4', PARENTAL_LEVEL_Q => '4', PARENTAL_LEVEL_R => '4', PARENTAL_LEVEL_S => '4', PARENTAL_LEVEL_T => '4', PARENTAL_LEVEL_U => '4', PARENTAL_LEVEL_V => '4', PARENTAL_LEVEL_W => '4', PARENTAL_LEVEL_X => '4', PARENTAL_LEVEL_Y => '4', PARENTAL_LEVEL_ => '4', PARENTALLEVEL => '4', PATCH_FILE => '32', PS3_SYSTEM_VER => '8', REGION_DENY => '4', RESOLUTION => '4', SAVEDATA_DETAIL => '1024', SAVEDATA_DIRECTORY => '64', SAVEDATA_FILE_LIST => '3168', SAVEDATA_LIST_PARAM => '8', SAVEDATA_PARAMS => '128', SAVEDATA_TITLE => '128', SOUND_FORMAT => '4', SOURCE => '4', SUB_TITLE => '128', TARGET_APP_VER => '8', TITLE => '128', TITLE_ID => '16', TITLE_00 => '128', TITLE_01 => '128', TITLE_02 => '128', TITLE_03 => '128', TITLE_04 => '128', TITLE_04 => '128', TITLE_05 => '128', TITLE_06 => '128', TITLE_07 => '128', TITLE_08 => '128', TITLE_09 => '128', TITLE_10 => '128', TITLE_11 => '128', TITLE_12 => '128', TITLE_13 => '128', TITLE_14 => '128', TITLE_15 => '128', TITLEID001 => '16', TITLEID002 => '16', TITLEID003 => '16', TITLEID004 => '16', TITLEID005 => '16', TITLEID006 => '16', TITLEID007 => '16', TITLEID008 => '16', TITLEID009 => '16', TITLEID010 => '16', TITLEID011 => '16', TITLEID012 => '16', TITLEID013 => '16', TITLEID014 => '16', TITLEID015 => '16', TITLEID016 => '16', VERSION => '8', XMB_APPS => '4' ); open my $param, '<', shift; binmode($param); my @params; my @array; my @other_array; my @split; my @read_array; seek $param, 0x08, 0; read $param, my $buf, 0x02; seek $param, 0x0C, 0; read $param, my $rev, 0x02; my $temp1 = pack( "v*", unpack( "n*", $buf ) ); my $param_loc = unpack( 'H*', $temp1 ); my $temp2 = pack( "v*", unpack( "n*", $rev ) ); my $key_table = unpack( 'H*', $temp2 ); seek $param, hex($param_loc), 0 or die; while ( $buf !~ /\x00{2}/ ) { read $param, $buf, 2; push @array, $buf; } for (@array) { @other_array = join( '', @array ); } for (@other_array) { @params = split( /\x0/, $_ ); } while ( my ( $temp_parameter, $max ) = each %hash ) { for my $elem (@params) { if ( $temp_parameter =~ /^$elem$/ ) { push( @split, "$temp_parameter $max" ); } } } for ( sort @split ) { my ( $temp, $read_length ) = split( / /, $_ ); push( @read_array, "$temp $read_length" ); } seek( $param, hex($key_table), 0 ); for my $value (@read_array) { my ( $parameter, $read ) = split( /\s/, $value ); chomp($read); read( $param, my $value, $read ); print "=============\n$parameter : $value\n=============\n"; }
Please never mind the syntax, i know i could have named stuff better, but if you look inside of the working and non working files, you will see what i mean. It is the entries "title_00" "title_01" ect ect(same as the ones in the hash that end with "x" or "xx" or "_xx".

The main question is, do i have to go ahead and declare abunch of them inside my hash?
Test files

In reply to Declaring Hash entries by james28909

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.