If you've discovered something amazing about Perl that you just need to share with everyone,
this is the right place.
This section is also used for non-question discussions about Perl, and for any discussions that are not specifically programming related. For example, if you want to share or discuss opinions on hacker culture, the job market, or Perl6 development, this is the place. (Note, however, that discussions about PerlMonks belong in Perl Monks Discussion.)
Meditations is sometimes used as a sounding-board — a place to post initial drafts of perl tutorials, code modules, book reviews, articles, quizzes, etc. — so that the author can benefit from the collective insight of the monks before publishing the finished item to its proper place (be it Tutorials, Code Catacombs, Reviews, or whatever). If you do this, it is generally considered appropriate to prefix your node title with "RFC:" (for "request for comments").
When I first learned Perl, it was Perl 4. Perl 5 was available, but it was new, and the company I was working for didn't trust it yet. That was many years ago, at the first job I had after college. In the time since, I've used Perl to varying degrees at every job I've ever had. I still work with Perl 5 today, and I expect this will be how I continue to make my living for years to come.
Some months ago, I shifted my free time expenditures from the Monastery to contributing to Perl 6. At the time, I'd heard there were some Perl 5 folks none too happy with Perl 6, but I was really only dimly aware of this and even further oblivious to the reasons involved.
I found the Perl 6 community to be friendly, welcoming, helpful, and all the other wonderful things I'd come to expect from my experience here at the Monastery. I basically forgot about any rift between the Perl 5 and Perl 6 communities. As I had experienced them, I saw no reason for them not to get along.
My eyes have been opened by masak and mst, who had a long private conversation on this topic and revealed the results of it in two articles.
I think the Perl community would benefit from taking these to heart. If you find yourself lacking the time to read the illuminations within them, mst has prepared a very brief summary, which I will summarize further.
Perl 5 and Perl 6 are two separate languages in the same family. I can tell you from my own experience that the fine folks working on Perl 6 do not plot the demise of Perl 5. I can also tell you that Perl 6 is clearly a different language from Perl 5 and just as clearly came from the same place. They were made with the same ideas in mind. Long may they live with our love and dedication.
i was trying http://gearman.org and i've therefor got from cpan Gearman::Client and Gearman::Client::Async but, for what i need, i felt like they weren't designed as i need, and i've tried to write another which suits best my needs.
Having not wrote any documentation, i'll just show you the usage:
use Gearman::OO::Client;
my $client = Gearman::OO::Client->new(
servers => ['127.0.0.1:4730'],
max_queue => 4,
);
logit("connected");
foreach my $id (1..8) {
$client->submit(
func=>'test',
req=>"Data for $id",
complete => sub { logit("completed #$id: @_"); },
error => sub { logit("ERROR #$id! @_"); },
);
logit("added #$id");
}
logit("sync...");
$client->sync();
logit("done.");
But then, after having to add more array properties (datatypes, lengths, decimals, allownull, default) and copypasting the accessor subs, something itched.
So I revised it to..
package DataTable;
sub new {
my $class = shift;
my $self = {};
$self->{tablename} = undef;
$self->{columns} = [];
$self->{indices} = {};
$self->{datatypes} = [];
$self->{lengths} = [];
$self->{decimals} = [];
$self->{signed} = [];
$self->{allownull} = [];
$self->{default} = [];
$self->{usequote} = [];
}
bless($self, $class);
return $self;
}
# Accessor methods
sub ArrayAccessor {
my $arrayname = shift;
my $self = shift;
if (@_) { @{$self->{$arrayname}} = @_; }
return @{$self->{$arrayname}};
}
sub HashAccessor {
my $hashname = shift;
my $self = shift;
if (@_) { %{$self->{$hashname}} = @_; }
return %{$self->{$hashname}};
}
sub ScalarAccessor {
my $scalarname = shift;
my $self = shift;
if (@_) { $self->{$scalarname} = shift; }
return $self->{$scalarname};
}
sub tablename { return ScalarAccessor("tablename", @_); }
sub columns { return ArrayAccessor("columns", @_); }
sub indices { return HashAccessor("indices", @_); }
sub datatypes { return ArrayAccessor("datatypes", @_); }
sub lengths { return ArrayAccessor("lengths", @_); }
sub decimals { return ArrayAccessor("decimals", @_); }
sub signed { return ArrayAccessor("signed", @_); }
sub allownull { return ArrayAccessor("allownull", @_); }
sub default { return ArrayAccessor("default", @_); }
sub usequote { return ArrayAccessor("usequote", @_); }
1;
Google announced a new programming language called "Go" see http://golang.org/
It is described as "expressive, concurrent, garbage-collected," which, to me, not only doesn't say much, but whatever it does say, sounds like a language that you and I already know.
Since languages are cultural, and are always evolving (and those that are not busy evolving are busy dying, to paraphrase our national bard), I seek your comments, musings, rants on this new language. Maybe we will even see an Inline::Go sooner or later.
Today I thought I'd implement a way to compute pi using continued fractions
I was trying to get 1000 decimals for codegolf.com , but I was only able to get 10 correct
decimals(yes, I know..pathetic) in 6 seconds(codegolf limits this to 4 seconds).
Anyone care to divulge their (partial) solution to this ?
Maybe they treat the problem as one of compressing those 1000 digits rather than computing them? And if so, I think there were some theoretical bounds to compressing data, I do not remember what those were ... I'm pretty sure codegolf doesn't allow use of modules and implementing your own compression algo would jump over 54bytes for sure , or not ?
As I see, with knowledge of Perl and CPAN Modules and some sort of expertness, solving any problem is just an engineering problem, where you just have to put the pieces together and create a flow. But often times, I see some hard problems. What are those according to you?
All started a week ago when I saw a unicursal hexagram and I started wondering the logic behind drawing a n-points unicursal star, so I gone thorough some wikipedia articles and finally created a method that can draw a unicursalstar polygon of n points for any natural* number.
For those wondering, any non-convex polygon in star form could be considered a star polygon, but only those where the lines can be draw starting and ending at the same point, passing through all the other points exactly one time are unicursal star polygons
Although my code works like I wanted, I still don't like how it does it, so I would like to hear what the perlmonks have to say about it.
As you can see, it actually outputs a SVG image, you can run it like: $perl draw_star.pl N > img.svg ,where N is the points number
and open the result in your favorite browser/image viewer.
The main problem is finding the $mod number, this is how much points it will 'jump' from the current point to draw the next line.
Notice that this is where things get dirty, calcMagic was called this ways because I failed in understand the logic(if any) behind it.
There is also a side problem, take a look again in the unicursal hexagram and you will notice that it's irregular, which means the $mod number changes depending on the current point.
..and, although I was a Anonymous Monk for quite a time, I sill not sure if this is the right place for this, even after reading Where should I post X?, so I'm sorry if it isn't.
Of course there is nothing surprising here after all. It should just serve as a reminder that floating point numbers are nasty beasts. It is dangerous to have certain assumptions about them. Also, when you write code that processes a lot of numbers then forms decisions based on comparisons ofthem, it is important to check that the code really does what you think it does. Extreme cases, loss of accuracy and so on.
I find new things constantly on this website and other websites and books related to Perl. I enjoy learning from it. When I discover new things, that may be a fundamental to possibly large number of people, my confidence level drops. It means that I have to update myself tremendously to bring myself to the par level. It is sort of knowledge race, that I am trying to run constantly.
So, dear monks, how do you see yourself in reference to the race I mentioned, now and in forthcoming years? I am somewhat exhausted, but my enthusiasm continues. I am worrying about the confidence level, because when I am looking for job, I need higher confidence.
I am using a Linux system (Ubuntu 9.10).
It took me several hours of frustration to realise something about $0. This built-in variable is defined in perlvar as "the name of the program being executed". Perlvar doesn't mention that its meaning can change, even inside the same program running under the same system, according to the way the program is run.
You have this code:
#!/usr/bin/perl -w
use UI::Dialog; # sudo apt-get install libui-dialog-perl
my $statement = "My name is $0...\n";
my $d1 = new UI::Dialog(title => 'I know my name');
$d1->msgbox(text => $statement);
print $statement;
exit;
You save it into a file named "knowthyself" in your Desktop.
You give the file executable permissions (chmod 755 knowthyname).
Then you run the program 3 times:
The first time you open a terminal and type "perl knowthyself". You get this output: "My name is knowthyself..."
Then you use the terminal and type "./knowthyself". You get this output: "My name is ./knowthyself..."
Finally you go to your file manager (Nautilus) and click on the file. You are asked what to do: Do you want to run it in a terminal, do you want to show its contents, do you want to cancel the action, or do you want to just run it? Of course you choose this last action (run the program without opening a terminal). You get this output (in a window): My name is /home/user/Desktop/knowthyself...
Moral: even if you are running your program under one and the same system, even if it supports $0, you have to be very careful before relying on what $0 returns.
This is more of a quick note than comprehensive overview. I've looked over the various offerings for creating libraries of SQL and one new one hit CPAN today - DBIx::QueryByName.
In looking at it, the one thing I notice about the XML File Syntax is that there is no way for parameters to have default values if not specified.
Another thing is that XML File Syntax makes it difficult for a SQL mode in emacs to highlight and indent the code unless you do something with mixed mode so that it handles the XML and SQL gracefully.
The final thing is that the session management features of this module appear to be a violation of orthogonal integration of concerns.
This post answers a few common questions and misconceptions about Perl's memory management.
Lexical variables don't get freed at end of scope
Lexical variables don't get freed at end of scope. They are cleared on scope exit to give you the apperance of a fresh variable. This is an optimisation that should be transparent to you.
On scope exit, if anything prevents the variable from being resused (e.g. if there are remaining references to the variable), the existing variable becomes anonymous and a new variable is allocated.
Clearing a variable does not free the memory it uses
It was previously mentioned that variables on cleared on scope exit. Variables can also be cleared as follows:
Clearing a variable frees no memory directly. The buffer of a string is marked as being unused, but it remains allocated for later use. The underlying array of pointers in arrays and hashes is cleared, but it remains allocated for later use. This is an optimisation that should be transparent to you.
As a result of a variable being cleared, referenced variables (incl array elements) have their refcount lowered, and that may free those variables. But not the variable being cleared.
However, undef will never free a variable. Clearing the variable may result in the reduction of the ref counts of other variables, which may free those variables. But not the variable that was passed to undef.
Freeing variables may result in no change in available system memory
You can't rely on memory being returned to the system, but it can happen.
If and when memory is returned to the OS is dependant on the memory allocation mechanism perl was compiled to use. You may also see differences between system using the same memory allocation mechanism. It's also possible that a mechanism will only ever release the large blocks it allocated.
The default memory allocation mechanism varies by OS. You are more likely to see memory being released to the OS on Windows.
Yesterday I was caught in a fix, a dreadful situation that I am certain many have come across but my certainty doesn't provide for ways to get out of or alleviate its impact nor doest it tell me of individual ways to see-it-coming and halt it right there, neither. I may sound alarmed, but justification is what follows and a requirement for useful tips and directions is what I seek.
This particularly involves the monks among you who use more than one programming languages in their work. I was introduced to SAS sometime before Perl, I reached a nice level of understanding its different language structures and concepts and used to work my way through the many procedures it had to achieve something purposeful, it was nice and fun. Today I don't know if it is mastery anymore that I thought I possessed, I haven't used SAS, however, for ~4 months. Back to yesterday again, I heard of a new SAS community that holds the sort of interactions the likes of StackOverFlow, I happily joined in, and then tried to answer a simple post, to my consternation, my fingers just couldn't type and my mind stayed blank,and dude(tte) I wasn't caught in the moment and it seems like I forgot the syntax!.
What betook me then was enormous to describe, and in the inside of my mind I have been thinking about this; All the love I have for Perl, every time I check a Monk's node and find that that Monk hasn't been around here for 2 or 5 or 7 years and I'd sadly wonder, where they are and what has become of their Perl programming skills and if I would get to walk down that path ever would I forget the syntax, would it rust with length of unuse, and I feel while I am in the middle of such thoughts that it would be a darn world outside the confines of the Monastery, so I stop thinking and haste back to try to reply to a freshly submitted post or get to contemplate the Monastery.
It is a frustration to not be able to retain information after all the dedication and enthusiasm spent picking it, I don't wanna say I forgot SAS (Retrograde Forgetfulness), but I would wanna know how do you manage to transit between two disparate programming languages and how do you strive to keep abreast without sacrificing one for the other.
Would ye revered monks be caught in such a situation at times?, how would you cope to retain and compartmentalize your programming tools and how would you push the refresh button on a programming language you haven't probably used in a while in response to an immediate stimulus like the one I had yesterday and not fail like I did?
Excellence is an Endeavor of Persistence.
Chance Favors a Prepared Mind.
I decided to post this question here since this section is for discussions of non-programming related issues. But to tell you the truth, I really dont know if this is the right place to post this question but here it goes.
I was tasked by my superior to check the knowledge level of our developers on Perl. Previously, the developers were asked to learn Perl by self-study. Time was the only thing provided (no training). After 3 months, the developers are saying that they have learned a lot and have used it on their work. But we dont have any idea on how to gauge their knowledge gained.
Will you guys suggest on how to do this? how to gauge/check their knowledge so that we can have an idea which of our developers has potential or whom needs more training or time to learn.
We noticed that they are using perl on their work and most of their scripts are working. But how are we going to know if what they did is the best practice or the best way to do that. Note that we dont have a senior level or an experience developer to check their code.
Any suggestion, comments are welcome. And if you think that this question is not for this section, you can remove it but please tell me the section where I should post this.