Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?

Categorized Questions and Answers: tips and tricks

by GrandFather (Sage)
on Jun 14, 2005 at 04:14 UTC ( #466373=monkdiscuss: print w/replies, xml ) Need Help??

Is there somewhere suitable for posting "Tips and Tricks" for the edification of newbie Perl programmers?

My first guess would be in Categorized Questions and Answers, but there doesn't seem to be a suitable place for tricks like using shift/unshift and $Array[0] for implementing a really easy local stack. Is it worth creating a new topic there for this sort of thing?

Perl is Huffman encoded by design.
  • Comment on Categorized Questions and Answers: tips and tricks

Replies are listed 'Best First'.
Re: Categorized Questions and Answers: tips and tricks
by davido (Cardinal) on Jun 14, 2005 at 04:23 UTC

    Find the category under Categorized Questions and Answers under which your particular tip or trick belongs, and post a question and answer there. For example:

    Category: Arrays
    Question: How do I create a simple stack?
    Answer: Use shift, unshift, and $array[0]
    And here is a simple example...........


      I considered arrays and decided it didn't quite fit. If I knew that a simple stack implementation used an array then I most likely wouldn't need to look to find out how. Even if I did know that and needed a refresher, I'd still look first in Data Structures (if it were there) or Tips and Tricks if it were there.

      Perl is Huffman encoded by design.
Re: Categorized Questions and Answers: tips and tricks
by davidrw (Prior) on Jun 14, 2005 at 12:34 UTC
    The Perl Idioms Explained section of the tutorials immediately came to mind. Some of the "tips and tricks" (though not sure about the specific stack example) might be appropriate for that section.
    (if you write one up, also mention $Array[-1] amd $Array[$#Array] in addition to $Array[0])

      Good answer. I will do as you suggest. If a Tips and Tricks or Data Structures section springs into being in C Q&A then perhaps it could be moved.

      A link from C Q&A to the tutorials may be a usefull thing. As in Also take a look in Tutorials.

      Perl is Huffman encoded by design.
Re: Categorized Questions and Answers: tips and tricks
by demerphq (Chancellor) on Jun 23, 2005 at 08:06 UTC

    Actually iirc you are better off using push/pop and $array[-1] instead of shift/unshift and $array[0] From what i remember (i should recheck the source) perls arrays are written with a slight bias towards adding things to the end over sticking them on the front.

    Also why stop at a stack? You can implement a queue with unshift/push, and a deque with unshift/shift and push/pop.


Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: monkdiscuss [id://466373]
Approved by davido
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (5)
As of 2020-06-05 01:21 GMT
Find Nodes?
    Voting Booth?
    Do you really want to know if there is extraterrestrial life?

    Results (35 votes). Check out past polls.