Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number


by coyocanid (Sexton)
on May 24, 2013 at 16:31 UTC ( #1035171=user: print w/replies, xml ) Need Help??

I am a Perl Tinker in the Bay Area. I love writing code and creating stuff with it. I like tricky perl riddles though I'm not very good at them. I support Open Source because it changes the world; the heart of the internet beats because of it. Big Companies come and go, but the spirit of our technology lives on. I have one project of note : Yote, which currently lives at

Posts by coyocanid
scalar reference and length in Seekers of Perl Wisdom
2 direct replies — Read more / Contribute
by coyocanid
on Oct 29, 2019 at 18:20
    If I have a scalar ref holding on to a big string, and take its length, will dereferencing it into length cause the string to be copied? I'm hoping since length is a builtin, it would not.
    my $x = \" VERY VERY BIG STRING ....."; my $len = length( $$x );
    If it were a sub, however, it would be
    sub foo { my $s = shift; my $r = \$s; print "FOO ($r)\n" } my $X = "SOMESTRING"; my $O = \$X; my $R = \$X; print "NOTFOO ($R,$O)\n"; + foo( $$R );
    NOTFOO (SCALAR(0x9393f8),SCALAR(0x9393f8)) FOO (SCALAR(0x9394a0))
    EDIT, after some help from my friends One delightful thing I learned is that the @_ elements are _not_ copies. A sub does not have to copy.
    sub foo { my $r = \$_[0]; print "FOO ($r)\n" } my $X = "SOMESTRING"; my $O = \$X; my $R = \$X; print "NOTFOO ($R,$O)\n"; + foo( $$R );
    NOTFOO (SCALAR(0x1ac23e8),SCALAR(0x1ac23e8)) FOO (SCALAR(0x1ac23e8))

    Original content restored below by GrandFather for reference.

    If I have a scalar ref holding on to a big string, and take its length, will dereferencing it into length cause the string to be copied?

     my $x = \" VERY VERY BIG STRING ....."; my $len = length( $$x );
XS unpackstring, flags and useage in Seekers of Perl Wisdom
1 direct reply — Read more / Contribute
by coyocanid
on May 24, 2018 at 19:09
    Hello Honored Geschwistern,

    I am working on a perl XS project and would like to use unpack in the XS/C portion of the code. (Using pack in the perl portion seems to do what I want).

    I'm reading the API documents for unpackstring and have some questions questions

    • What are the flags that are allowed? I've been searching in vain
    • The documentation says that the results are put on the perl stack automatically. I don't see much explaining the perl stack in detail
    • How to get the return values from the unpacklist to the perl caller, possibly using the perl stack as a middleman.

    The engine implementing the unpack() Perl function.

    Using the template pat..patend, this function unpacks the string s..strend into a number of mortal SVs, which it pushes onto the perl argument (@_) stack (so you will need to issue a "PUTBACK" before and "SPAGAIN" after the call to this function). It returns the number of pushed elements.

    The strend and patend pointers should point to the byte following the last character of each string.

    Although this function returns its values on the perl argument stack, it doesn't take any parameters from that stack (and thus in particular there's no need to do a PUSHMARK before calling it, unlike "call_pv" for example).

    I32 unpackstring(const char *pat, const char *patend, const char *s, const char *strend, U32 flags)
seek harsh critique in Seekers of Perl Wisdom
3 direct replies — Read more / Contribute
by coyocanid
on Dec 08, 2017 at 11:00

    I've been working on a project for some years and want to release it to CPAN and I'm not yet happy with the POD I've written.

    I'm looking for a harsh critique of the POD below. I want to make sure it communicates the purpose and use of the module. Critique of the module is also welcome.

multi process advice in Seekers of Perl Wisdom
No replies — Read more | Post response
by coyocanid
on Jun 09, 2013 at 02:50
    Dear Perl Monks,

    I come soliciting opinions, for I have a design decision to make for my Yote project. This is a server that takes requests, processes data and returns a result. The data is statefull and the calls are atomic. The data is object based.

    Given the atomic requirements and the fact that the server side data tends to be shared by different users, different server processess must coordinate their activities. I have devised two schemes to handle this : a master process model and a coordinating processes model.

    # ------------------

    Coordinating Process Model -

    In this model, each server process runs the command issued by the client. Each process loads up the objects from the database and coordinates with other processes by locking the objects. This is the model that I've seen other web servers use. If a process fails to exit, a watcher process may be able to reap it and unlock all objects attached to it. Unfortunately this is slow and memory intensive. It's not exactly the same level of atomicity that I would like, either, as objects could be locked out of order by two processes so deadlocking is a possibility. The implementation for this is rather new and has not yet been put through the paces.

    Master Process Model -

    In this model, the server processes take incoming requests and puts those requests on a queue. A master process checks the queue and invokes the commands, one by one. It then takes the return values and stores them in a shared data structure. The server process checks this shared data structure using coordinated locking signals to detect if the master process is done executing the command. This model is over twice as fast as the coordinating model because the master thread easily caches object values and does not always need to load from the data store. The big drawback of this model is that a particular command could take a long time and one with an infinite loop could potentially strangle the system. The system does set a timeout that a particular command may run. I've been able to run this model months without any crash under light loads. There may be times a long running process must be run. This model doesn't directly address that.

    Some other unthought of way

    There is always an other way to do it. Maybe a model with multiple queues, one slow and one fast, that coordinate object locking. I guess this would be a bit of a hybrid method. <.blockquote>

Connecting Javascript to Perl in Cool Uses for Perl
1 direct reply — Read more / Contribute
by coyocanid
on May 24, 2013 at 14:42

    I've put together a new perl module on CPAN called Yote. It directly and automatically binds javascript client objects to perl server objects. The objects are container objects that live in an object database. The objects are lazily loaded as needed and are automatically stored with their contents automatically. The following example works out of the box as long as the Hello package is in the Yote server's perl classpath. The hello count will be preserved in Yote's data store.

    Server Side Perl
    package Hello; use base 'Yote::AppRoot'; sub hello { my( $self, $input ) = @_; $self->set_hello_count( $self->get_hello_count( 0 ) + 1 ); return "Hello $input, I have said hello ". $self->get_hello_count() . " times"; } 1;
    Client Side Javascript
    $.yote.init(); var hello_app = $.yote.fetch_app( 'Hello' ); alert( hello_app.hello( prompt( "What is your name?" ) ) );
map grep and sort in Meditations
6 direct replies — Read more / Contribute
by coyocanid
on May 24, 2013 at 13:49

    I want to meditate on some of the most useful perl-isms that, while easy, are oft misunderstood for beginners. I say that, and am possibly projecting, since when I was a beginner, I had not grokked them and had misused them. I also want to give kudos to the comments below as they have greatly helped refine this posting.

    Map, Grep and Sort are not the same thing, but are often used together. Flowing from right to left, they act like shell pipelining in reverse. They build something new, like a tiny little factory. While the original data structure is untouched, it should feel like a list is being transformed every step of the way.

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (3)
As of 2022-05-19 05:02 GMT
Find Nodes?
    Voting Booth?
    Do you prefer to work remotely?

    Results (71 votes). Check out past polls.