Simon Proctor – Writing Perl6 Command Line Scripts



[Applause] yes six of us in the shop everybody's been telling these thoughts in like eurozone because I really like it and I figure I just think he talked about it music we've actually written so much we got paid for it really rains yes so slender comes from self magazine permit some online similarities between here and par-5 and also differences and things you can do so like yeah I'm sorry mater you can find in most places that Simon I opportunity to close the are hiring rule always time and I also have the learning POSIX like right for you with me today let's take a look at it see if it's like straight in if you're running POSIX on the command line there's a few come on my switches that are very similar to the past like ones there's also a huge amount that you can't use they don't do anything so and there's some others that are there they're not actually that useful come on my stuff they're more useful for if you're going to test performance all this time so top we have minus e which is the same as minus capital e impel fight in the name strict and you can use site the annoying thing is that minus capital e doesn't work to go six so if you do like I do in flip between Perl 5 and Perl 6 come online stuff on a regular basis you keep having class like throw bit errors because you didn't use might actually but there you go yeah POSIX has strips and warnings on by default my sin works pretty much the same as a PowerPoint one the only thing to bear in mind is that when it's really from this file it automatically charts the new line at the end of the line so + and minus P similar except for it also use occurs just on the family's own oh just say now this is a new experiment for me actually doing colored slides of people to tell me off what they thought of it feel free yeah so just is not a family that any object has that basically produces a human readable string of white question so most people call gist on your thing and using say something means it puts the new line back on it so effectively if you're using – everyone's P it will just loop through all the lines ruining the new I couldn't back against England at the same time you will notice that there isn't – i for in place editing's you can't do in place every mother father with it and like having the automatic to add it once hats white is passed so you can like to find parts for a library there and – em you can be much learning in a bar – rather having to you do uses at the beginning yeah so they've likes a big list of ones that aren't there but then most of them are feeding through does anybody use any of your favorite come on – which is not listed here chances are you can out start writing there's also the coastal environment variable which you can set again instead of using – I that can be useful if you're running proves you can be proven then rather pel 6 and be executable and possibly if you so we've been running a script on the come online you have two dynamic variables called args and our fault so ours is a rate of all the arguments passed the program they are strings but the original types that can be important if you're passing the arcs file to another function if the other function expecting it typed array it will error because you also have thoughts that are closed now this is quite interesting you don't see me when I have a panel and what that does is it basically you give it a list of parts which can be the strings or they can be or open file handles that can be a few different objects and what it can do is when you cool things like the lines on it or read or any of the various pass functions on it it will open the first one do that to the first part and then when that files time to move on to sex it'll basically just slow every single one of the files that you possibly in one go so when you call your come on my script all of your arguments passed are to our finals which if you then call me will then try and leave them as files so it won't attempt to so if you like cool with my mind you pass it about two numbers because you've written scripts and use the multiplication to do some sometimes it won't open files of those numbers and likes remember and this effect but it's quite easy you know so what you've got by all fibers which is the original object but then they decided this was such a cool idea they made the oil cap and I have our files is now just up and sort of a wrapper around it doesn't have any additional functionality well yes but yeah let's you bunch of things lazy evaluation because if you don't pass in any argument then our files is set to auto sorry so you can pipe to it from our life script if you don't pass any father arguments he'll read from standard input cool tell are they still pretty standard ish with your post-op I mean you you buy a script you beach from ours you do some stuff with whisper sir now we go on to the bits where Perl 6 gets really different mean so if your function or if your script has and subroutine can remain in it then that will be called as your starting point in the function now you'll notice here at the 5/3 using multi something it's perfectly allowed to do that and I haven't thrown any demonstrates all different ways you can do so in this first case I'm beating all of the arguments and put them into an array of silence now I'm level to do this instead using art files because I perhaps want to check that they actually exist before I crossed into our fastest archives really doesn't like it if you give it parts that don't exist in this case I'm expecting to positional arguments and if that was the only main sub then this was thrown out wouldn't turn a little dim intercepts all the way to do is if you pass two arguments it was I want apply one one far too then finally we've got the name document there so this would accept either an A – yes or – – yes well that's that sizing them as name documents and assign the value you put to it to that variable that you can then access from in the main function so what it does is it takes the the arcs object and maps it into the signature and there's a few rules that it applies to do that what it doesn't mean you're allowed to modify your arcs values before your suck your main settings so if you can basically change some of the odds if you want so for instance if you were done going to do something files you could maybe check the odds this to make sure that they're only exists in your throw away and either art so you only work on the existing files that are all the inputs go to extremely except if they if you're if you look matches either int rational complex number or floating-point number then you will be maximal cornellà north which is a thing that looks like opposed to a string and these things are like an integer or a string and anything that's expecting a string will we find there anything that's expecting an integer we'll be fine with it and the type system will just be happy so that's one thing to look out for is name parameters if you find a name parameter there's nothing stopping someone calling it multiple times and if they call multiple times then the variable you get will be an array object whereas if they're equal it once you'll get a state object so a single thing now the annoying thing have a little discussion about this the other day of VRC is if you assign a name and run to a name document so if that was access instead Donna race it will error unless you give it at least two arguments because it won't accept one argument for Ana right I think that's a bug I'm going to try and enough it because I think that's me crazy arrays should have woman there waiting around are covering it Elena you can also if you want grab any many documents that you haven't touched already or you can't mention already and just stick them all into the slowly hash which anybody who's at one previous talk so yes that's so if you call your function and you've got main self but the arguments you pass don't maps the main cell then it will generate an author what first thing to do is it'll tell to call service in computer usage doesn't exist then it will generate a string course are you Suzanne that's my Nana very little generate that automatically based on your signatures so look all of your maintenance and it'll go this practical now hit the public in pulsates you have pork rinds he's basically comments that are also pulled and attached to the car so hash pipe you put mana I've got demonstration second hash might be put before the thing to comment new it we're documenting actually calls but after thinking document and the place that you pull out those publications and use them to make your usage one thing you can do is you can also flag a main subroutine with the is hidden from usage saying which as far as I've done right now it's not documented anywhere and I've no idea white because you using because what that will do is it will just skip that main stuff about us or show you that in the demonstration while attribute so here I've got three main cells so this one here is there is the important one sets up some numbers sorry it's also number there's multi some main it's expecting a bunch of things I'm saying numbers I'm not doing any testing there anything and another about pass equals a list of numbers I've also got up here multi sub matin H question mark so that's saying if I get called and all I'm past is either an attribute called H or a or nothing then call the usage function and this will say if I pass actually could go and anything else and the usage function says gives me a little string and then says that you also created usage scroll straight and I've been here that is the output that this file creates if you call it with no arguments or with minus eight as an argument prints out that you see it really quick and easy to write self documenting c'mon come let's track this last one so here's a few other little tips Egyptian quite useful in politics you've got your beginning your bunch of other things that called faces and they're very similar five might begin and end blocks and stuff they work slightly different you don't actually have to do the box for instance but you can use I you can use a thing we combined state variables and end allows you to use – aim – like loops where everything put some data into a state variable and then in and end things that print out the state variable at the end so that's why I said okay keep the value all the way through some may not only has one it's if this is another dynamic like variable you can say Peter arranging or hashing them it's only got one key you can set in it which is called named anyway if you set that to true then it allows you to put named arguments any way you like in the otherwise the main documents have to appear in the place that they're pointing at the signature so that can be quite helpful identify main whatever this is a nice soft light if you know say about if you want to have a name parameter because sure there's only one this subtype single we're doing this up of any city saying it can be any value but it's not positional so anything that's oppositional positional being array list so in this case if you defined a main variants in its signal then it would error if somebody tried to put multiple put ones of that in on the c'mon subsets I am whatever you look at this is a module that includes a bunch of predefined subsets for pretty much any file path test that you want to match so if you want to check test this main path is a writable directory then you just stick I hope rtw up onto the path and it will basically use the type system whether or not that's true and to find a bit I would say is if you are doing anything else it's one our scripting you want to as soon as possible take over the Kodak come on my scripts ticket the module and then use the module and then just call the function module because modules seumas poison are precompiled so you don't have that

One Reply to “Simon Proctor – Writing Perl6 Command Line Scripts”

Leave a Reply

Your email address will not be published. Required fields are marked *