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

Re: Re: Adult learning problem

by Juerd (Abbot)
on Apr 05, 2002 at 08:06 UTC ( #156851=note: print w/ replies, xml ) Need Help??


in reply to Re: Adult learning problem
in thread Adult learning problem

A good way to get to know splice better is to re-implement push, pop, unshift and shift with it.
A good way to get to know substr better is to create push/pop/unshift/shift functions for strings.

Often, a good way to learn is re-inventing the wheel. I'd rather re-invent a wheel than greet the world.

U28geW91IGNhbiBhbGwgcm90MTMgY
W5kIHBhY2soKS4gQnV0IGRvIHlvdS
ByZWNvZ25pc2UgQmFzZTY0IHdoZW4
geW91IHNlZSBpdD8gIC0tIEp1ZXJk


Comment on Re: Re: Adult learning problem
Re: Re: Re: Adult learning problem
by demerphq (Chancellor) on Apr 05, 2002 at 09:02 UTC
    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.

Re: Re: Re: Adult learning problem
by pdcawley (Hermit) on Apr 07, 2002 at 15:52 UTC
    That certainly seems to be the standard teaching method in the scheme and lisp worlds. The number of such books I've seen that have you recoding length and the like. And it seems to work.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://156851]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (12)
As of 2014-09-30 12:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (368 votes), past polls