I have a 30 kb "keys" file in which is readable as a text document and would probably be best suited to read as plaintext. I have three variables I assign values from a "searchfile" then i use these values to search the keys file for the right keys. In the keys file the layout is identical for every key revision... like this:
revision=something <--newline at end of line
version=something <--newline at end of line
type=something <--newline at end of line
key1=64 characters <--newline at end of line
key2=32 character <--search will stop before going to newline
In $var we will assign revision from values read from searchfile
In $var1 we will assing version from values read from searchfile
In $var2 we will assign type from values in a searchfile
Now what I am doing here is searching a "searchfile" to get the values for the variables so I can search a keys file for the correct keyset :)
Now for the question... what would be the best way to search for these three values in the key file? would a simple
if ($string =~ "$var $var1 $var2"){
seek ( $keys, 4, 0 );
read ( $keys, $temp1, 64 );
seek ( $keys, 4, 0 );
read ( $keys, $temp2, 32 );
Please understand there are newline characters after each string in the keys file. Im not sure if need to
$string =~ "$var $var1 $var2"
Or if I need to allow for the newline characters like:
$string =~ "$var\n $var1\n $var2"
Also I am not sure if doing a regex match will allow me to search the keys file from the end of the last match as per my example above. is there a way to return the very last rightmost position of the regex match?(as in the last character in the matched pattern $var2 ( type=somethin|g <-- as in last character " I need to retun the position of the very very last character g or whatever character it may be, letter or number)) EDIT
I could instead just get leftmost position of match then skip down 3 lines in the keys file. I think that would be more beneficial.
If i need to be any more specific please let me know.
Do you think this code will work for what i need?
Thanks for any input as it is appreciated :)
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.