Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
What would be the Moose version of this (a queue that maintains a fixed size by evicting the oldest items) ?
class FixedSizeQueue def initialize(size) @max_size = size @items = [] end def pop @items.shift end def push(item) @items.push item if @items.size > @max_size pop end end end
With usage
2:16% irb -r ./fsq.rb irb(main):001:0> q = FixedSizeQueue.new(3) => #<FixedSizeQueue:0x9317c6c @max_size=3, @items=[]> irb(main):002:0> q.push 2 => nil irb(main):003:0> q.push 3 => nil irb(main):004:0> q.push 5 => nil irb(main):005:0> q => #<FixedSizeQueue:0x9317c6c @max_size=3, @items=[2, 3, 5]> irb(main):006:0> q.push 7 => 2 irb(main):007:0> q => #<FixedSizeQueue:0x9317c6c @max_size=3, @items=[3, 5, 7]> irb(main):009:0> FixedSizeQueue.instance_methods(false) => [:pop, :push]


In reply to Re^5: The future of Perl? by Arunbear
in thread The future of Perl? by BrowserUk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (6)
As of 2024-03-29 09:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found