Hi Tachyon,

I did indeed realise this, however in the code as you have written it the declaration of %opcodes is in a different scope to that of the subroutine and hence, all you get returned is an error. I am not sure exactly how to access the hash from the subroutine's scope - %main::opcodes ???

I did also originally run the program without the encode routines as a separate sub and it didn't appear to run any faster.

Thanks,

Elgon

Update: I tried running the program as a simple loop, without the sub as before, and it took about 1 second instead of 36 or so to run. Must have declared the hash inside the loop the first time. Oops. Time to go back to the Blue Camel and re-read the sections on scoping and packages :-)

Update^2: I've been trying to do what you suggest by passing a reference to %opcodes to the subroutine along with the line and then saying local *hash = shift; a la blue camel page 294 but this isn't liked either. FYI I'm using Perl 5.005 so use of our is right out.

Update^3: See root node.

"What this book tells me is that goose-stepping morons, such as yourself, should read books instead of burning them."
       - Dr. Jones Snr, Indiana Jones and the Last Crusade


In reply to Re: Re: Z80 Assembler -> Hex Opcode by Elgon
in thread Z80 Assembler -> Hex Opcode by Elgon

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.