Beefy Boxes and Bandwidth Generously Provided by pair Networks Frank
There's more than one way to do things
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??
A good way to get to know splice better is to re-implement push, pop, unshift and shift with it.

Uhm, or you could just read the docs :-)

D:\Development>perldoc -f splice splice ARRAY,OFFSET,LENGTH,LIST ..... The following equivalences hold (assuming "$[ == 0"): push(@a,$x,$y) splice(@a,@a,0,$x,$y) pop(@a) splice(@a,-1) shift(@a) splice(@a,0,1) unshift(@a,$x,$y) splice(@a,0,0,$x,$y) $a[$x] = $y splice(@a,$x,1,$y)
A good way to get to know substr better is to create push/pop/unshift/shift functions for strings.

Well.... Once you know how to implement splice using susbtr you dont need to implement push/pop/unshift or shift, but its true it might be a good exercise. Personally would suggest taking that thought a step further and reimplement Tie::CharArray, by the time you are done if you dont understand Tie's, Array implementation, Splice Implementation and Substr implementation then I would say theres something very wrong... (either with the individual or the code ;-) Oh and it probably is a good idea because you can use the CPAN module for a proper code comparison and review afterward.

Thats what I did to learn Tie the first time anyway... :-)

Yves / DeMerphq
---
Writing a good benchmark isnt as easy as it might look.


In reply to Re: Re: Re: Adult learning problem by demerphq
in thread Adult learning problem by jepri

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!
  • 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, 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, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            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.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others cooling their heels in the Monastery: (19)
    As of 2014-04-16 11:51 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      April first is:







      Results (424 votes), past polls