From webmaster at cosmicperl.com Tue Sep 1 23:38:02 2009 From: webmaster at cosmicperl.com (Lyle) Date: Tue, 01 Sep 2009 23:38:02 +0100 Subject: [BristolBathPM] Perl course chapters 1 & 2, reviews please :) Message-ID: <4A9DA24A.1080900@cosmicperl.com> Hi All, School term is almost upon us. That means I need to get my act together again on the free Perl course for schools. I'll be posting the chapters I used at the first school ready for you all to correct me :) All constructive feedback much appreciated. Remember this is aimed at secondary school kids so I didn't want to go into to much detail... I'm really not happy with the paragraph for chapter 2, but as most of you know by now, English has never been my strong point :-[ Chapter 1: Getting Started with Perl - Computer set up Windows: ActivePerl can be downloaded from http://www.activestate.com/activeperl/ ensure that you select the right edition for your operating system. The installation should automatically associate .pl files with the Perl interpreter. Linux: Perl is included in most distributions of Linux. If you do not have the Perl package installed for your distro there will be one available, you can also download ActivePerl from the link above. Setting up a web server Windows: If you do not have windows IIS you can download Apache from http://httpd.apache.org/download.cgi If you download the msi version you'll have a nice wizard to take you through the install. Providing you follow the defaults Apache will be displayed locally at http://localhost . Linux: Apache is also already included with most distributions and is available at http://localhost also. You may need to install your distro's package for this. Chapter 2: Programming and Computers A basic computer consists of CPU, RAM and a HDD with input devices such as keyboard and mouse, output devices such as VDU and printers. The CPU processes requests based on the 86 instruction set. Early computers were programmed in binary a series of 0?s and 1?s. 1 byte = 8 bits of binary i.e 01001010. This made programming a lengthy process so assembly language evolved and then on to C programming. C is the foundation for most programming languages we have today. Higher level languages such as Perl, Java and Python use richer syntax making it easier to code larger more detailed programs. A program that's hundreds of lines of C could be just tens of lines of Perl. Lyle From dave at dave.org.uk Wed Sep 2 06:45:36 2009 From: dave at dave.org.uk (Dave Cross) Date: Wed, 02 Sep 2009 06:45:36 +0100 Subject: [BristolBathPM] Perl course chapters 1 & 2, reviews please :) In-Reply-To: <4A9DA24A.1080900@cosmicperl.com> References: <4A9DA24A.1080900@cosmicperl.com> Message-ID: <4A9E0680.7020209@dave.org.uk> On 01/09/09 23:38, Lyle wrote: > Windows: > ActivePerl can be downloaded from http://www.activestate.com/activeperl/ > ensure that you select the right edition for your operating system. The > installation should automatically associate .pl files with the Perl > interpreter. I know little or nothing about running Perl (or, indeed, anything) on Windows, but I understand that you should be recommending Strawberry Perl over ActivePerl. http://strawberryperl.com/ Dave... From gseviour at btinternet.com Wed Sep 2 10:50:39 2009 From: gseviour at btinternet.com (GARY SEVIOUR) Date: Wed, 2 Sep 2009 09:50:39 +0000 (GMT) Subject: [BristolBathPM] Perl course chapters 1 & 2, reviews please :) In-Reply-To: <4A9DA24A.1080900@cosmicperl.com> Message-ID: <510613.92967.qm@web87114.mail.ird.yahoo.com> the stuff about programming in 'binary': kids might not understand that the binary numbers are the instructions, of which an instruction manual would have been available to relate each 8 bit binary code to human language/ assembler. When I was about 15 years old I bought a book on z80 machine language for the ZX spectrum. All the stuff at the begining about binary arithmetic left me bewildered as how simpleaddition and subtraction could possibly create a computer program (of course thats not the way it works, Turing had difficulty in conving people of this point though) (should have kept reading though as it was a very good book). I stopped reading it and got back to my beloved BASIC and longed to get into Pascal and C. If only id known that the binary numbers were the instructions (and how writing data to vdu ram would display stuff) I could have had so much fun. Some may think that I was a bit dim, but in my defence I was also entirely self taught. I'm really pleased that someone is teaching the kids how to code, this is very valuable work. --- On Tue, 1/9/09, Lyle wrote: From: Lyle Subject: [BristolBathPM] Perl course chapters 1 & 2, reviews please :) To: "Bristol and Bath Perl M[ou]ngers" Date: Tuesday, 1 September, 2009, 11:38 PM Hi All, School term is almost upon us. That means I need to get my act together again on the free Perl course for schools. I'll be posting the chapters I used at the first school ready for you all to correct me :) All constructive feedback much appreciated. Remember this is aimed at secondary school kids so I didn't want to go into to much detail... I'm really not happy with the paragraph for chapter 2, but as most of you know by now, English has never been my strong point :-[ Chapter 1: Getting Started with Perl - Computer set up Windows: ActivePerl can be downloaded from http://www.activestate.com/activeperl/ ensure that you select the right edition for your operating system. The installation should automatically associate .pl files with the Perl interpreter. Linux:erl (or, indeed, anything) on Windows, but I understand that you should be recommending Strawberry Perl over Activ Perl is included in most distributions of Linux. If you do not have the Perl package installed for your distro there will be one available, you can also download ActivePerl from the link above. Setting up a web server Windows: If you do not have windows IIS you can download Apache from http://httpd.apache.org/download.cgi If you download the msi version you'll have a nice wizard to take you through the install. Providing you follow the defaults Apache will be displayed locally at http://localhost . Linux: Apache is also already included with most distributions and is available at http://localhost also. You may need to install your distro's package for this. Chapter 2: Programming and Computers A basic computer consists of CPU, RAM and a HDD with input devices such as keyboard and mouse, output devices such as VDU and printers. The CPU processes requests based on the 86 instruction set. Early computers were programmed in binary a series of 0?s and 1?s.. 1 byte = 8 bits of binary i.e 01001010. This made programming a lengthy process so assembly language evolved and then on to C programming. C is the foundation for most programming languages we have today. Higher level languages such as Perl, Java and Python use richer syntax making it easier to code larger more detailed programs. A program that's hundreds of lines of C could be just tens of lines of Perl. Lyle _______________________________________________ BristolBathPM mailing list BristolBathPM at bristolbath.org http://mailman.bristolbath.org/mailman/listinfo/bristolbathpm -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mailman.bristolbath.org/pipermail/bristolbathpm/attachments/20090902/936895ea/attachment-0001.html From webmaster at cosmicperl.com Wed Sep 2 11:38:47 2009 From: webmaster at cosmicperl.com (Lyle) Date: Wed, 02 Sep 2009 11:38:47 +0100 Subject: [BristolBathPM] Perl course chapters 1 & 2, reviews please :) In-Reply-To: <4A9E0680.7020209@dave.org.uk> References: <4A9DA24A.1080900@cosmicperl.com> <4A9E0680.7020209@dave.org.uk> Message-ID: <4A9E4B37.2050107@cosmicperl.com> Dave Cross wrote: > On 01/09/09 23:38, Lyle wrote: > > >> Windows: >> ActivePerl can be downloaded from http://www.activestate.com/activeperl/ >> ensure that you select the right edition for your operating system. The >> installation should automatically associate .pl files with the Perl >> interpreter. >> > > I know little or nothing about running Perl (or, indeed, anything) on > Windows, but I understand that you should be recommending Strawberry > Perl over ActivePerl. > > http://strawberryperl.com/ > I've always liked ActivePerl. The selling point of Strawberry Perl is that you can compile Perl modules like you do on Linux. But you've been able to do that with ActivePerl for years, you just need to install MinGW... ActiveState made huge contributions to getting Perl running well on Windows and they deserve much credit. But granted it wouldn't harm to mention both of them and give the reader a choice, although I'll likely recommend ActivePerl for ease of use. Lyle From andy at mentalist.co.uk Wed Sep 2 11:48:32 2009 From: andy at mentalist.co.uk (Andy Gale) Date: Wed, 2 Sep 2009 11:48:32 +0100 Subject: [BristolBathPM] Perl course chapters 1 & 2, reviews please :) In-Reply-To: <4A9E4B37.2050107@cosmicperl.com> References: <4A9DA24A.1080900@cosmicperl.com> <4A9E0680.7020209@dave.org.uk> <4A9E4B37.2050107@cosmicperl.com> Message-ID: On Wed, Sep 2, 2009 at 11:38 AM, Lyle wrote: > > I've always liked ActivePerl. The selling point of Strawberry Perl is > that you can compile Perl modules like you do on Linux. But you've been > able to do that with ActivePerl for years, you just need to install > MinGW... ActiveState made huge contributions to getting Perl running > well on Windows and they deserve much credit. But granted it wouldn't > harm to mention both of them and give the reader a choice, although I'll > likely recommend ActivePerl for ease of use. If you mention both, please ensure any examples you provide work in both. Nothing more annoying than trying to learn a language when the examples don't work. -- Andy Gale W: www.andy-gale.com T: http://twitter.com/andygale From webmaster at cosmicperl.com Wed Sep 2 11:57:15 2009 From: webmaster at cosmicperl.com (Lyle) Date: Wed, 02 Sep 2009 11:57:15 +0100 Subject: [BristolBathPM] Perl course chapters 1 & 2, reviews please :) In-Reply-To: <510613.92967.qm@web87114.mail.ird.yahoo.com> References: <510613.92967.qm@web87114.mail.ird.yahoo.com> Message-ID: <4A9E4F8B.6030907@cosmicperl.com> GARY SEVIOUR wrote: > the stuff about programming in 'binary': kids might not understand > that the binary numbers are the instructions, of which an instruction > manual would have been available to relate each 8 bit binary code to > human language/ assembler. > That's a good point. I remember wondering for ages how simple 1's and 0's could make programs. "How does it know which 1 or 0 goes where?" Eventually one night I realised it work on groups of 1's and 0's, and these were the instructions. It's certainly worth conveying this message :) > > When I was about 15 years old I bought a book on z80 machine language > for the ZX spectrum. > I remember getting a book on assembler at roughly the same age.. Left me quite confused all the talk of registers. Plus I didn't realise you needed an assembler such as TASM or MASM, which by the time I'd got hold of I was already playing with C. Soon after I found Perl and the love affair began ;-) > I'm really pleased that someone is teaching the kids how to code, this > is very valuable work. > And most importantly, teaching them Perl :-D I need to refine this a bit more, then get some of the other groups doing it. I'm sure that LPM will get on board with their usual kind words, support and enthusiasm that they are so well known for :-P Lyle From webmaster at cosmicperl.com Wed Sep 2 13:46:39 2009 From: webmaster at cosmicperl.com (Lyle) Date: Wed, 02 Sep 2009 13:46:39 +0100 Subject: [BristolBathPM] Perl course Chapter 3 Message-ID: <4A9E692F.3000600@cosmicperl.com> Here is where it starts getting interesting. One thing I overlooked that turned out to be a problem was teaching them how to use the command prompt. The IT teachers didn't know either. Seems Windows has prevailed in restricting command prompt knowledge to us IT pros :( Remember I'm trying to keep this simple, some of the kids will only be 13. Although saying that I'm currently working on a follow on course. So notes on all the things/changes you think should be in this version and all the things you think I should teach in the next would be ideal ;) The formatting used to make this easier to read is of course lost in plain text. Each Chapter from herein roughly fits into an hour of teaching. I got them typing things in for each section after hello world. Next time I'll be more diligent to make sure they are actually understanding and playing with the code rather than solitaire (why is that still on the school pc's????). Some of the kids were treating it as quickly copy what I've put on the board then start messing about, where they should have been messing with the code and trying to understand it. Chapter 3: Programming in Perl This course is short so it's structured to be as hands on as possible. But before we can write any code, you need to understand a few basics. Comments To make the examples clearer we use comment tags. Anything on a line after a #, is a comment and ignored by Perl (this isn't always true). #This is a comment Outputting data At this point we'll cover basic data output using print, so that you can get hands on a writing some working code. The print statement is used in many programming languages as the means of outputting data to a variety of devices, such as your HD in the form of a file, or text onto your screen. print 'Hello world!'; Line endings So that long lines of code can be easily broken over several lines, or short lines of code can be put on the same line, lines of Perl code must end with a semi colon ';'. As with comments there are of course exceptions. Running Perl scripts Perl scripts are just text files that contain Perl code. They are most commonly saved with the file extension ?.pl?. These scripts can be ran along the command line, using the Perl interpreter. Let's use the above print example as our first program. Open a text editor such as notepad, word processors such as Word and WordPad are not suitable as they try to format the text. Perl scripts should always start with the path to Perl. This is known as the shebang line. In these exercises we'll be invoking Perl directly so it's not technically needed, but it is good practice to put it in anyway. In your text editor type:- #!c:/perl/bin/perl.exe print 'Hello world!'; Save this as hello.pl within a suitable folder (such as ?c:\perlscripts?). You'll see that the path to Perl uses forward slashes / as opposed to backslashes \. That is because Perl was originally developed for Unix based systems which use the forward slash for directory paths. Now open a command prompt (usually Start->Accessories->Command Prompt), navigate to the folder where you saved the hello.pl script (?cd \perlscripts?) and run the script with the Perl interpreter (?perl hello.pl?). You should get the output ?Hello World!?. Variables Data that you are currently working with is stored in variables. Think of variables as labelled containers. There are different kinds of variables for storing different kinds of data. For example to define a variable in C you need to declare what type it is e.g. Number = int Letter = char Word = varchar Luckily Perl's variables aren't as strictly typed. Scalars In Perl integers, strings, etc, do not have to be defined separately and are more simply defined as Scalars e.g. $number = 10; $char = 'c'; $huge = 'pages of information'; Scalars are denoted by the $ sigil. Perl has variables that can be global; allowing all parts of the program to access them, or local; allowing only certain blocks of code access them. A global variable is defined as our $name = 'xyx'; Whereas a local variable is my $name = 'xyz'; It's good practice to have all or most your variables as local variables. Scalars that have been initialized but not assigned a value have a special value known as NULL. Perl calls NULL undef, for undefined. undef is not the same as an empty string. my $scalar; # $scalar will contain undef my $empty = ''; # $empty will contain an empty string my $undef = undef; # $undef will contain undef ? The 'our' syntax for defining global variables was introduced with Perl v5.6. Some people still prefer the old method of declaring globals with: use vars qw( $LIST @OF %GLOBALS ); Using Scalars Let's update our hello.pl script to use a scalar to contain the message:- #!c:/perl/bin/perl.exe my $message = 'Hello world!'; print $message; Working with Scalars There are different ways of working with Scalars. Perl is well known for TIMTOWTDO (There is more than one way to do it). Here are some examples of common things you'll want to do with Scalars. Interpolation Our previous hello.pl example uses single quotes '. Single quotes do not interpolate Scalars. Such that the code my $name = 'Lyle'; print 'Hello $name'; Would output the text ?Hello $name?. Double quotes do interpolate, such that the same code with double quotes my $name = 'Lyle'; print ?Hello $name?; Would give you ?Hello Lyle?. Joining strings Strings can be joined with double quotes, the join function, or by using the dot '.' operator. my $start = 'Hello'; my $end = 'World'; my $joined = ?$start $end?; # Same $joined = join( ' ', $start, $end ); # Same $joined = $start . ' ' . $end; # Same Repeating strings You can also repeat strings with the x operator. print 'Hi!' x 5; Would display ?Hi!Hi!Hi!Hi!Hi!?. Working with numbers You have all the normal math operators. Examples:- print 1 + 1; # Displays 2 my $multi = 5 * 5; # $multi contains 25 my $div = 5 / 5; # $div contains 1 Lyle From dave at dave.org.uk Wed Sep 2 15:37:56 2009 From: dave at dave.org.uk (Dave Cross) Date: Wed, 02 Sep 2009 15:37:56 +0100 Subject: [BristolBathPM] Perl course Chapter 3 In-Reply-To: <4A9E692F.3000600@cosmicperl.com> References: <4A9E692F.3000600@cosmicperl.com> Message-ID: <4A9E8344.6040208@dave.org.uk> On 02/09/2009 13:46, Lyle wrote: > Here is where it starts getting interesting. One thing I overlooked that > turned out to be a problem was teaching them how to use the command > prompt. The IT teachers didn't know either. Seems Windows has prevailed > in restricting command prompt knowledge to us IT pros :( Have you looked at something like Padre? http://padre.perlide.org/ It might be closer to the program development environment that they are expecting. No command line required. Dave... From dave at dave.org.uk Wed Sep 2 15:42:44 2009 From: dave at dave.org.uk (Dave Cross) Date: Wed, 02 Sep 2009 15:42:44 +0100 Subject: [BristolBathPM] Perl course Chapter 3 In-Reply-To: <4A9E692F.3000600@cosmicperl.com> References: <4A9E692F.3000600@cosmicperl.com> Message-ID: <4A9E8464.1050006@dave.org.uk> On 02/09/2009 13:46, Lyle wrote: > For example to define a variable in C you need to declare what type it > is e.g. > > Number = int > Letter = char > Word = varchar It's been a while since I looked at C, but I don't think it has a 'varchar' datatype. Are you confusing C with SQL :-) [ snip ] > my $name = 'Lyle'; > print ?Hello $name?; A common problem with producing programming tutorials using software aimed at word processing is that you end up with code which contains "smart quotes" as above - which then won't compile. That's potentially confusing to newcomers. [ snip ] > You have all the normal math operators. Grr! It's "maths" on this side of the Atlantic :-) Cheers, Dave... From paulm at paulm.com Wed Sep 2 15:46:42 2009 From: paulm at paulm.com (Paul Makepeace) Date: Wed, 2 Sep 2009 15:46:42 +0100 Subject: [BristolBathPM] Perl course Chapter 3 In-Reply-To: <4A9E8464.1050006@dave.org.uk> References: <4A9E692F.3000600@cosmicperl.com> <4A9E8464.1050006@dave.org.uk> Message-ID: On Wed, Sep 2, 2009 at 3:42 PM, Dave Cross wrote: > On 02/09/2009 13:46, Lyle wrote: > > > For example to define a variable in C you need to declare what type it > > is e.g. > > > > Number = int > > Letter = char > > Word = varchar > > It's been a while since I looked at C, but I don't think it has a > 'varchar' datatype. Are you confusing C with SQL :-) > > [ snip ] > > > my $name = 'Lyle'; > > print ?Hello $name?; > > A common problem with producing programming tutorials using software > aimed at word processing is that you end up with code which contains > "smart quotes" as above - which then won't compile. That's potentially > confusing to newcomers. > If only Perl had some kind of built-in format for producing documentation... ;-) > > [ snip ] > > > You have all the normal math operators. > > Grr! It's "maths" on this side of the Atlantic :-) > > Cheers, > > Dave... > _______________________________________________ > BristolBathPM mailing list > BristolBathPM at bristolbath.org > http://mailman.bristolbath.org/mailman/listinfo/bristolbathpm > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mailman.bristolbath.org/pipermail/bristolbathpm/attachments/20090902/407208fe/attachment.html From webmaster at cosmicperl.com Wed Sep 2 17:28:44 2009 From: webmaster at cosmicperl.com (Lyle) Date: Wed, 02 Sep 2009 17:28:44 +0100 Subject: [BristolBathPM] Perl course Chapter 3 In-Reply-To: <4A9E8344.6040208@dave.org.uk> References: <4A9E692F.3000600@cosmicperl.com> <4A9E8344.6040208@dave.org.uk> Message-ID: <4A9E9D3C.5040606@cosmicperl.com> Dave Cross wrote: > On 02/09/2009 13:46, Lyle wrote: > >> Here is where it starts getting interesting. One thing I overlooked that >> turned out to be a problem was teaching them how to use the command >> prompt. The IT teachers didn't know either. Seems Windows has prevailed >> in restricting command prompt knowledge to us IT pros :( >> > > Have you looked at something like Padre? > > http://padre.perlide.org/ > > It might be closer to the program development environment that they are > expecting. No command line required. > I've been meaning to have a play with it. Although it was hard enough getting the last school to install Perl... >> For example to define a variable in C you need to declare what type it >> is e.g. >> >> Number = int >> Letter = char >> Word = varchar >> > > It's been a while since I looked at C, but I don't think it has a > 'varchar' datatype. Are you confusing C with SQL :-) > I think your right, should be Word = char[11] (for a word that's 10 letters long). >> my $name = 'Lyle'; >> print ?Hello $name?; >> > > A common problem with producing programming tutorials using software > aimed at word processing is that you end up with code which contains > "smart quotes" as above - which then won't compile. That's potentially > confusing to newcomers. > Yes that's pretty damn annoying. Although when typing up the examples they are only using a text editor so they use normal quotes. >> You have all the normal math operators. >> > > Grr! It's "maths" on this side of the Atlantic :-) > Damn my English :( Paul Makepeace wrote: > If only Perl had some kind of built-in format for producing > documentation... > > ;-) Good point Lyle From alex.francis at gmail.com Fri Sep 4 08:17:22 2009 From: alex.francis at gmail.com (Alex Francis) Date: Fri, 4 Sep 2009 08:17:22 +0100 Subject: [BristolBathPM] The Programming Language with the Happiest Users ? Message-ID: <16afc9550909040017l3a25d081h72d645e3012c9590@mail.gmail.com> Fun, but far from scientific! http://blog.doloreslabs.com/2009/05/the-programming-language-with-the-happiest-users/ extract: "I decided to do a little market research. I scraped the top 150 most recent tweets on Twitter for the query ?X language? where X was one of {COBOL, Ruby, Fortran, Python, Visual Basic, Perl, Java, Haskell, Lisp, C}. "Then I asked three people on Amazon Mechanical Turk to verify that the tweet was on the topic. If so, I asked if the tweet seemed positive, negative or neutral" ... "I am not surprised that COBOL was the least favorite, but I am somewhat surprised that Perl was the favorite. Sifting through the data, unlike other languages, there seem to be a surprising number of people that just felt like giving Perl shoutouts." Alex From david at cantrell.org.uk Fri Sep 4 14:45:38 2009 From: david at cantrell.org.uk (David Cantrell) Date: Fri, 4 Sep 2009 14:45:38 +0100 Subject: [BristolBathPM] Perl course Chapter 3 In-Reply-To: <4A9E692F.3000600@cosmicperl.com> References: <4A9E692F.3000600@cosmicperl.com> Message-ID: <20090904134538.GC7262@bytemark.barnyard.co.uk> On Wed, Sep 02, 2009 at 01:46:39PM +0100, Lyle wrote: > Line endings > > So that long lines of code can be easily broken over several lines, or > short lines of code can be put on the same line, lines of Perl code must > end with a semi colon ';'. As with comments there are of course exceptions. That would mean that if I write this: print "Hello World"; like this: print "Hello World"; it shouldn't work, as lines need to end with a semi-colon and there should be one after the print. Better to rephrase it as *statements* must end with a semi-colon. > Variables > > ... > > Luckily Perl's variables aren't as strictly typed. > Scalars > In Perl integers, strings, etc, do not have to be defined separately and > are more simply defined as Scalars e.g. > > $number = 10; > $char = 'c'; > $huge = 'pages of information'; Worth pointing out that a scalar is a variable that can hold a single value. > It's good practice to have all or most your variables as local variables. Why? Also, say lexical or scoped, not local. local means something subtlely different in perl (see the local keyword). > Scalars that have been initialized but not assigned a value have a > special value known as NULL. Perl calls NULL undef, for undefined. undef > is not the same as an empty string. Instead of confusing them by talking about NULL and then say that perl calls NULL undef, just talk about undef. You can talk about NULL later if you have a chapter on databases. > ? The 'our' syntax for defining global variables was introduced with > Perl v5.6. Some people still prefer the old method of declaring globals > with: use vars qw( $LIST @OF %GLOBALS ); You only need to declare them if you use strict. If you don't use strict, then anything that isn't lexical is assumed to be global. A good way to show why they should always use strict and warnings is, once you've shown them subroutines, write some nice buggy code where subroutines accidentally trample on each others' variables, and to try to append an undef variable to a string. > my $div = 5 / 5; # $div contains 1 May be worth mentioning operator precedence (eg 1+2*3 == 7, not 9), and if people have a C-ish background point out how cool it is to not have to cast between float and int. -- David Cantrell | Minister for Arbitrary Justice Deck of Cards: $1.29. "101 Solitaire Variations" book: $6.59. Cheap replacement for the one thing Windows is good at: priceless -- Shane Lazarus From david at cantrell.org.uk Fri Sep 4 15:03:09 2009 From: david at cantrell.org.uk (David Cantrell) Date: Fri, 4 Sep 2009 15:03:09 +0100 Subject: [BristolBathPM] Perl course Chapter 3 In-Reply-To: <4A9E9D3C.5040606@cosmicperl.com> References: <4A9E692F.3000600@cosmicperl.com> <4A9E8344.6040208@dave.org.uk> <4A9E9D3C.5040606@cosmicperl.com> Message-ID: <20090904140309.GE7262@bytemark.barnyard.co.uk> On Wed, Sep 02, 2009 at 05:28:44PM +0100, Lyle wrote: > I've been meaning to have a play with [Padre]. Although it was hard enough > getting the last school to install Perl... How about just showing up with Padre (and perl, and ...) on a bunch of USB keys? And for bonus points, the kids get to take them home afterwards so they don't have to set up their own development environment. > > It's been a while since I looked at C, but I don't think it has a > > 'varchar' datatype. Are you confusing C with SQL :-) > I think your right, should be Word = char[11] (for a word that's 10 > letters long). Yes. Strictly speaking, of course, char[11] isn't a variable, it's a memory allocation and a pointer, and the pointer can be made to go all over the place, not just within the word you want to store. -- David Cantrell | Cake Smuggler Extraordinaire All praise the Sun God For He is a Fun God Ra Ra Ra! From webmaster at cosmicperl.com Fri Sep 4 15:19:27 2009 From: webmaster at cosmicperl.com (Lyle) Date: Fri, 04 Sep 2009 15:19:27 +0100 Subject: [BristolBathPM] The Programming Language with the Happiest Users ? In-Reply-To: <16afc9550909040017l3a25d081h72d645e3012c9590@mail.gmail.com> References: <16afc9550909040017l3a25d081h72d645e3012c9590@mail.gmail.com> Message-ID: <4AA121EF.8080406@cosmicperl.com> Alex Francis wrote: > Fun, but far from scientific! > > http://blog.doloreslabs.com/2009/05/the-programming-language-with-the-happiest-users/ > > extract: > > "I decided to do a little market research. I scraped the top 150 most > recent tweets on Twitter for the query ?X language? where X was one of > {COBOL, Ruby, Fortran, Python, Visual Basic, Perl, Java, Haskell, > Lisp, C}. > > "Then I asked three people on Amazon Mechanical Turk to verify that > the tweet was on the topic. If so, I asked if the tweet seemed > positive, negative or neutral" > > ... > > "I am not surprised that COBOL was the least favorite, but I am > somewhat surprised that Perl was the favorite. Sifting through the > data, unlike other languages, there seem to be a surprising number of > people that just felt like giving Perl shoutouts." > Maybe we should put this on the front page? Wait a minute... Does the date correspond with that blogging challenge? Lyle From paulm at paulm.com Fri Sep 4 15:34:50 2009 From: paulm at paulm.com (Paul Makepeace) Date: Fri, 4 Sep 2009 15:34:50 +0100 Subject: [BristolBathPM] Perl course Chapter 3 In-Reply-To: <20090904140309.GE7262@bytemark.barnyard.co.uk> References: <4A9E692F.3000600@cosmicperl.com> <4A9E8344.6040208@dave.org.uk> <4A9E9D3C.5040606@cosmicperl.com> <20090904140309.GE7262@bytemark.barnyard.co.uk> Message-ID: On Fri, Sep 4, 2009 at 3:03 PM, David Cantrell wrote: > On Wed, Sep 02, 2009 at 05:28:44PM +0100, Lyle wrote: > > > I've been meaning to have a play with [Padre]. Although it was hard > enough > > getting the last school to install Perl... > > How about just showing up with Padre (and perl, and ...) on a bunch of > USB keys? And for bonus points, the kids get to take them home > afterwards so they don't have to set up their own development > environment. > > > > It's been a while since I looked at C, but I don't think it has a > > > 'varchar' datatype. Are you confusing C with SQL :-) > > I think your right, should be Word = char[11] (for a word that's 10 > > letters long). > > Yes. Strictly speaking, of course, char[11] isn't a variable, it's a > memory allocation and a pointer, and the pointer can be made to go all > over the place, not just within the word you want to store. > Off-topic pedantry... If you define a char[11] in C you can't change it; it's not a pointer. char foo[11]; /* can't change foo */ char *bar = foo; /* can change bar */ P > > -- > David Cantrell | Cake Smuggler Extraordinaire > > All praise the Sun God > For He is a Fun God > Ra Ra Ra! > _______________________________________________ > BristolBathPM mailing list > BristolBathPM at bristolbath.org > http://mailman.bristolbath.org/mailman/listinfo/bristolbathpm > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mailman.bristolbath.org/pipermail/bristolbathpm/attachments/20090904/647a7e20/attachment.html From gseviour at btinternet.com Fri Sep 4 15:49:57 2009 From: gseviour at btinternet.com (GARY SEVIOUR) Date: Fri, 4 Sep 2009 14:49:57 +0000 (GMT) Subject: [BristolBathPM] The Programming Language with the Happiest Users ? In-Reply-To: <4AA121EF.8080406@cosmicperl.com> Message-ID: <717344.24507.qm@web87105.mail.ird.yahoo.com> old style VB might make the happiest coders, puts me in the mind of blissful naive days of coding without being in search of The Right Way. BASIC programmers get stuff done. I suspect that there is more stuff done everyday in some variant of VB than by all of the "non-programmers" (accountants, small buisness owners, teachers) than all of the real programmers out there. Java programmers are probably the least happy next to COBOL i would suspect.. C programers might be really quite happy. I'm noodling with Python, it it seems to fit my personality and ideals. Perl seems to have much more of a cool factor though I will admit that. I challenge you try to find a coder who has used Delphi and did not like it.. --- On Fri, 4/9/09, Lyle wrote: From: Lyle Subject: Re: [BristolBathPM] The Programming Language with the Happiest Users ? To: "Bristol and Bath Perl M[ou]ngers" Date: Friday, 4 September, 2009, 3:19 PM Alex Francis wrote: > Fun, but far from scientific! > > http://blog.doloreslabs.com/2009/05/the-programming-language-with-the-happiest-users/ > > extract: > > "I decided to do a little market research. I scraped the top 150 most > recent tweets on Twitter for the query ?X language? where X was one of > {COBOL, Ruby, Fortran, Python, Visual Basic, Perl, Java, Haskell, > Lisp, C}. > > "Then I asked three people on Amazon Mechanical Turk to verify that > the tweet was on the topic. If so, I asked if the tweet seemed > positive, negative or neutral" > > ... > > "I am not surprised that COBOL was the least favorite, but I am > somewhat surprised that Perl was the favorite. Sifting through the > data, unlike other languages, there seem to be a surprising number of > people that just felt like giving Perl shoutouts." >??? Maybe we should put this on the front page? Wait a minute... Does the date correspond with that blogging challenge? Lyle _______________________________________________ BristolBathPM mailing list BristolBathPM at bristolbath.org http://mailman.bristolbath.org/mailman/listinfo/bristolbathpm -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mailman.bristolbath.org/pipermail/bristolbathpm/attachments/20090904/b5c6552d/attachment.html From gseviour at btinternet.com Fri Sep 4 16:04:36 2009 From: gseviour at btinternet.com (GARY SEVIOUR) Date: Fri, 4 Sep 2009 15:04:36 +0000 (GMT) Subject: [BristolBathPM] The Programming Language with the Happiest Users ? In-Reply-To: <717344.24507.qm@web87105.mail.ird.yahoo.com> Message-ID: <586817.17509.qm@web87108.mail.ird.yahoo.com> >>>BASIC programmers get stuff done. I suspect that there is more stuff done everyday in >>>some variant of VB than(deleted) by all of the "non-programmers" (accountants, small buisness >>>owners, teachers) than all of the real programmers out there. oh dear another typo and ive made a complete are of myself again, oh well --- On Fri, 4/9/09, GARY SEVIOUR wrote: From: GARY SEVIOUR Subject: Re: [BristolBathPM] The Programming Language with the Happiest Users ? To: "Bristol and Bath Perl M[ou]ngers" Date: Friday, 4 September, 2009, 3:49 PM old style VB might make the happiest coders, puts me in the mind of blissful naive days of coding without being in search of The Right Way. BASIC programmers get stuff done. I suspect that there is more stuff done everyday in some variant of VB than by all of the "non-programmers" (accountants, small buisness owners, teachers) than all of the real programmers out there. Java programmers are probably the least happy next to COBOL i would suspect.. C programers might be really quite happy. I'm noodling with Python, it it seems to fit my personality and ideals. Perl seems to have much more of a cool factor though I will admit that. I challenge you try to find a coder who has used Delphi and did not like it.. --- On Fri, 4/9/09, Lyle wrote: From: Lyle Subject: Re: [BristolBathPM] The Programming Language with the Happiest Users ? To: "Bristol and Bath Perl M[ou]ngers" Date: Friday, 4 September, 2009, 3:19 PM Alex Francis wrote: > Fun, but far from scientific! > > http://blog.doloreslabs.com/2009/05/the-programming-language-with-the-happiest-users/ > > extract: > > "I decided to do a little market research. I scraped the top 150 most > recent tweets on Twitter for the query ?X language? where X was one of > {COBOL, Ruby, Fortran, Python, Visual Basic, Perl, Java, Haskell, > Lisp, C}. > > "Then I asked three people on Amazon Mechanical Turk to verify that > the tweet was on the topic. If so, I asked if the tweet seemed > positive, negative or neutral" > > ... > > "I am not surprised that COBOL was the least favorite, but I am > somewhat surprised that Perl was the favorite. Sifting through the > data, unlike other languages, there seem to be a surprising number of > people that just felt like giving Perl shoutouts." >??? Maybe we should put this on the front page? Wait a minute... Does the date correspond with that blogging challenge? Lyle _______________________________________________ BristolBathPM mailing list BristolBathPM at bristolbath.org http://mailman.bristolbath.org/mailman/listinfo/bristolbathpm -----Inline Attachment Follows----- _______________________________________________ BristolBathPM mailing list BristolBathPM at bristolbath.org http://mailman.bristolbath.org/mailman/listinfo/bristolbathpm -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mailman.bristolbath.org/pipermail/bristolbathpm/attachments/20090904/5db7d5f8/attachment-0001.html From webmaster at cosmicperl.com Fri Sep 4 16:07:56 2009 From: webmaster at cosmicperl.com (Lyle) Date: Fri, 04 Sep 2009 16:07:56 +0100 Subject: [BristolBathPM] The Programming Language with the Happiest Users ? In-Reply-To: <717344.24507.qm@web87105.mail.ird.yahoo.com> References: <717344.24507.qm@web87105.mail.ird.yahoo.com> Message-ID: <4AA12D4C.8050401@cosmicperl.com> GARY SEVIOUR wrote: > > I challenge you try to find a coder who has used Delphi and did not > like it. > I didn't. Reminded me far to much a Pascal syntax. But then I only used it one night, I was doing it to help a friends (who I hadn't heard from in years) brother do some uni work. When I got there (the day before it had to be in) he hadn't written a single piece of code! When I tried to explain what he needed to do, he clearly expected me to do it all for him. Even when I aksed him thngs like "What's the syntax for an if statement". Needless to say I didn't help him again. Quite annoyingly he was given top marks for it! Well, not annoying my work go top marks, but that he's tricked/brided me into doing it. Still, I wish I was there to see the lectures face when he handed in the next piece of work... Lyle From mjr at phonecoop.coop Sun Sep 6 11:58:19 2009 From: mjr at phonecoop.coop (MJ Ray) Date: Sun, 6 Sep 2009 11:58:19 +0100 (BST) Subject: [BristolBathPM] The Programming Language with the Happiest Users ? In-Reply-To: <4AA121EF.8080406@cosmicperl.com> Message-ID: <20090906105819.54ACDF704F@nail.towers.org.uk> Lyle wrote: > Alex Francis wrote: > > "Then I asked three people on Amazon Mechanical Turk to verify that > > the tweet was on the topic. If so, I asked if the tweet seemed > > positive, negative or neutral" [...] > > Maybe we should put this on the front page? [...] I'd be hesitant because of the use of the minimum-wage-busting Amazon Mechanical Turk. There's also the pay-peanuts-get-monkeys aspect of the analysis reliablity there and that the data doesn't seem to be provided for verification. Interesting talking points, but not a great news item IMO. Hope that explains, -- MJ Ray (slef) LMS developer and webmaster at | software www.software.coop http://mjr.towers.org.uk | .... co IMO only: see http://mjr.towers.org.uk/email.html | .... op From nigel at turbo10.com Mon Sep 7 09:40:50 2009 From: nigel at turbo10.com (Nigel Hamilton) Date: Mon, 7 Sep 2009 09:40:50 +0100 Subject: [BristolBathPM] Bath social meeting - 2 for 1 offer Message-ID: <50fec4060909070140g308cb6d4t98b2aacc57311559@mail.gmail.com> Hi, The next social meeting is scheduled in Bath but I was thinking it might be good to have 2 meetings in Bristol for every 1 meeting in Bath - which I think is a bit fairer given the number of Bristolians vs Bathonians currently attending social meetings. Hopefully if/when more Bathonians attend - we could return to alternate months. What do you think? NIge -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mailman.bristolbath.org/pipermail/bristolbathpm/attachments/20090907/77dcb46a/attachment.html From pmh at edison.ioppublishing.com Wed Sep 9 17:48:12 2009 From: pmh at edison.ioppublishing.com (Peter Haworth) Date: Wed, 9 Sep 2009 17:48:12 +0100 Subject: [BristolBathPM] ANNOUNCE Bristol social (Re: Bath social meeting - 2 for 1 offer) References: <50fec4060909070140g308cb6d4t98b2aacc57311559@mail.gmail.com> Message-ID: On Mon, 7 Sep 2009 09:40:50 +0100, Nigel Hamilton wrote: > The next social meeting is scheduled in Bath but I was thinking > it might be good to have 2 meetings in Bristol for every 1 > meeting in Bath - which I think is a bit fairer given the > number of Bristolians vs Bathonians currently attending social > meetings. Hopefully if/when more Bathonians attend - we could > return to alternate months. While I'm not convinced that this is a good way to encourage more Bathonians, given the proximity of the next meeting and the current lack of venue, the pragmatic approach would seem to be to agree. Therefore, the next meeting will be at the Tinto Lounge again, at 7pm next Tuesday. -- Peter Haworth pmh at edison.ioppublishing.com "These accounting systems are written entirely in Perl, mostly because commercial packages are not available to deal in the currency (sherry, biscuits and carrots) of Santa's environs." -- http://www.perl.com/pub/a/2002/12/18/hohoho.html This email (and attachments) are confidential and intended for the addressee(s) only. If you are not the intended recipient please notify the sender, delete any copies and do not take action in reliance on it. Any views expressed are the author's and do not represent those of IOP, except where specifically stated. IOP takes reasonable precautions to protect against viruses but accepts no responsibility for loss or damage arising from virus infection. For the protection of IOP's systems and staff emails are scanned automatically.? Institute of Physics Registered in England under Registration No 293851 Registered Office: 76/78 Portland Place, London W1B 1NT -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mailman.bristolbath.org/pipermail/bristolbathpm/attachments/20090909/5a797032/attachment.html From webmaster at cosmicperl.com Sat Sep 12 18:03:44 2009 From: webmaster at cosmicperl.com (Lyle) Date: Sat, 12 Sep 2009 18:03:44 +0100 Subject: [BristolBathPM] Perl course Chapter 4 Message-ID: <4AABD470.6020609@cosmicperl.com> Hi All, Here is the next chapter. Once again all feedback greatly appreciated. Arrays Defined using the @ symbol in front of the array name, arrays store a list variables with numbered locations starting at 0. e.g my @array = (?one?, ?two?); stores ?one? at location 0 and ?two? at location 1. This is an important thing to note with a lot of computer arithmetic, numbering generally starts at 0. To add a variable to the end of any array you can use the push command. push( @array, ?three? ); or simply use: @array = ( @array, ?three? ); To join an array my @join = ( @array1, @array2 ); To take an item off the end of an array, use pop. my $item = pop( @array ); So push and pop are a pair of functions that deal with adding/removing from the end of an array. Their counterparts are unshift and shift, that deal with adding/removing from the start of an array. shift takes the first item off of an array. my $item = shift( @array ); and unshift puts it back on unshift( @array, 'zero' ); To access a value in an array you need to reference its location e.g my @array = (?one?, ?two?,?three?); my $item = $array[1]; $item will contain 'two', if no value is returned you get undef. Note that when obtaining an arrays value you use $ rather than @ and square brackets []. This is because you are accessing a single Scalar value form the array, not the whole array. To sort an array @array = sort @array; The default sort is an ASCII one, so A-Z goes before a-z. We'll cover more on sorting later. Getting input from the user There are different ways of getting input from a user. From command line arguments to sockets. Here are a couple of common methods. Command line arguments Perl has a special variable named @ARGV. It's an array containing all of the parameters passed into the script when it's been called from the command line. For instance the script:- #!c:/perl/bin/perl.exe print $ARGV[0]; Would print the first parameter passed in. So if called with ?perl script.pl Hello? it would display ?Hello?. If called with ?perl script.pl Hello Lyle? it would still only display ?Hello?. This is because it's only printing the first parameter passed. You could use parenthesis to make the first parameter contain both Hello and Lyle, such as 'perl script.pl ?Hello Lyle?' would print ?Hello Lyle?. STDIN file handle STDIN stands for 'Standard Input?. Generally speaking, all Unix derived languages will have a STDIN, STDOUT 'Standard Output' and STDERR 'Standard Error'. They are treated as file handles that you can either read from, or write to. You've already used STDOUT, by default print goes to STDOUT, so the following lines are the same:- print ?Hello?; print STDOUT ?Hello?; # Same You can read from STDIN using the readline command, although Perl provides shorthand in the form of , such that:- my $name = readline(*STDIN); my $name = ; # Same It's uncommon to use readline, so stick with . You'll notice that in the readline example, STDIN has a * sigil, this is because to pass file handles into functions you must pass the whole GLOB. I'm not covering GLOBs here, for now think of them as another kind of variable. The example code above will pause the program and wait for user input, once the user hits enter the program will continue and $name will contain whatever they typed. Conditionals Things would be pretty boring if programs just went in a straight line all the time. Conditionals allow the software to make decisions based on variables, often ones that have been input. Perl offers if, elsif, else and for convenience unless. if The if statement allows you to run a block of code if a condition is true. They are in the format:- if ( CONDITION ) { CODE }#if You'll notice the use of curly brackets again. This time they surround the block of code that is to be run if the condition is true. The small comment on the end #if is a personal touch and not required. In larger programs you can have many code blocks within code blocks, a simple comment on the end bracket can help you keep track of where they started. In singular context, Perl sees anything that isn't undef, 0, 0.0 or '' (empty string), '0' (string containing 0) or an empty list as true. Examples:- if ( 0 ) { } # False if ( 1 ) { } # True if ( 0.0 ) { } # False if ( '' ) { } # False if ( 'text' ) { } # True if ( undef ) { } # False You can also reverse this with not or !, such as:- if ( ! 0 ) { } # True if ( not 1 ) { } # False You can also make comparisons or check if an operation or function returns a true value:- if ( 0 == 0 ) { } # True if ( 1 == 0 ) { } # False Note that for comparisons you need to use == rather than just =. This is because = is used for an assignment. Example:- # Correct way my $value = 1; if ( $value == 1 ) { } # True # Wrong way if ( $value = 0 ) { } # True Both examples return true. This is because the second one assigns 0 to the scalar $value which is a successful operation returning true. !, >, < can also be used:- if ( 0 != 0 ) { } # False if ( 1 > 0 ) { } # True if ( 0 <= 0 ) { } # True When comparing strings you use the eq and ne syntax instead (equals, not equals respectively):- if ( 'a' eq 'b' ) { } # False if ( 'a' ne 'b' ) { } # True You also have OR, ||, AND, &&. OR and || do basically the same thing, as do AND and &&. There are subtle differences in preference, but I won't be covering them as the vast majority of the time they are interchangeable. if ( 'a' eq 'b' || 1 > 0 ) { } # True if ( 'a' ne 'b' && 1 < 0 ) { } # False else You may also use the else statement with if, allowing to to do one thing or the other. Such as:- if ( $name eq 'Lyle' ) { print 'Thanks for teaching us Lyle'; }#if else { print ?Hello $name?; }#else elsif Often 'else if' or 'elseif' in other languages, shortened to elsif in Perl. It allows you to run another condition only if the original if is false. You can have many elsif statements as you want, often you end with a else. Such as:- if ( $name eq 'Lyle' ) { print 'Thanks for teaching us Lyle'; }#if elsif ( $name eq '' ) { print ?Please input your name?; }#elsif else { print ?Hello $name?; }#else unless For general convenience and to make things read easier, unless is provided as an alternative to if not. if ( not( 9 > 10 ) ) { } # True unless ( 9 > 10 ) { } # Same Lyle From dave at dave.org.uk Sun Sep 13 08:18:33 2009 From: dave at dave.org.uk (Dave Cross) Date: Sun, 13 Sep 2009 08:18:33 +0100 Subject: [BristolBathPM] Perl course Chapter 4 In-Reply-To: <4AABD470.6020609@cosmicperl.com> References: <4AABD470.6020609@cosmicperl.com> Message-ID: <4AAC9CC9.7040008@dave.org.uk> On 09/12/2009 06:03 PM, Lyle wrote: > Arrays > > Defined using the @ symbol in front of the array name, arrays store a > list variables with numbered locations starting at 0. e.g I think that should be. "arrays store a list of values at numbered locations ..." Dave... From david at cantrell.org.uk Mon Sep 14 11:40:09 2009 From: david at cantrell.org.uk (David Cantrell) Date: Mon, 14 Sep 2009 11:40:09 +0100 Subject: [BristolBathPM] Perl course Chapter 4 In-Reply-To: <4AABD470.6020609@cosmicperl.com> References: <4AABD470.6020609@cosmicperl.com> Message-ID: <20090914104009.GA16739@bytemark.barnyard.co.uk> On Sat, Sep 12, 2009 at 06:03:44PM +0100, Lyle wrote: > Here is the next chapter. Once again all feedback greatly appreciated. > > Defined using the @ symbol in front of the array name, arrays store a > list variables with numbered locations starting at 0. e.g > > my @array = (?one?, ?two?); > > stores ?one? at location 0 and ?two? at location 1. This is an important > thing to note with a lot of computer arithmetic, numbering generally > starts at 0. To avoid confusion between one and 1, I suggest putting other data into The array - aardvark, bat, coelocanth etc > The default sort is an ASCII one, so A-Z goes before a-z. We'll cover > more on sorting later. Isn't cmp locale-sensitive? > The if statement allows you to run a block of code if a condition is > true. They are in the format:- > > if ( CONDITION ) { > CODE > }#if Twitch twitch indentation twitch > # Wrong way > if ( $value = 0 ) { } # True False. $ perl -e 'if($v = 0) { print "true" }' $ > Both examples return true. This is because the second one assigns 0 to > the scalar $value which is a successful operation returning true. The result of $foo = whatever is the resultiong value of $foo, which in this case is zero, which is false. > You also have OR, ||, AND, &&. OR and || do basically the same thing, as > do AND and &&. There are subtle differences in preference, but I won't > be covering them as the vast majority of the time they are interchangeable. or and || are only subtlely different from and and &&? Errm. HELL NO. I presume you're trying to make the point that or and || are roughly the same and that and and && are also, but this needs re-writing. Also note that capitalisation is significant. OR is a user-defined function, or is a built-in operator. > For general convenience and to make things read easier, unless is > provided as an alternative to if not. > > if ( not( 9 > 10 ) ) { } # True > unless ( 9 > 10 ) { } # Same You may want to make the point that no-one in their right mind does this ... unless(...) { ... } else { ... } Because it's incredibly hard to parse in English. On an unrelated note, it seems that you're doing things in a bit of a weird order. I think aggregate data-types (arrays and hashes) should be treated together, so move the section about comparisons and conditionals to between scalars and arrays/hashes. -- David Cantrell | Godless Liberal Elitist More people are driven insane through religious hysteria than by drinking alcohol. -- W C Fields From pmh at edison.ioppublishing.com Tue Sep 15 11:04:52 2009 From: pmh at edison.ioppublishing.com (Peter Haworth) Date: Tue, 15 Sep 2009 11:04:52 +0100 Subject: [BristolBathPM] Reminder: Bristol social tonight Message-ID: Don't forget to come to the social meeting tonight. Since the last one was so successful there, we're going back to the Tinto Lounge. 7pm, September 15 The Tinto Lounge 344-346 Gloucester Road Bristol BS7 8TP The camels will be attending again, so look out for them if you don't know what the humans in the group look like. -- Peter Haworth pmh at edison.ioppublishing.com "Life is too long to be an expert at harmful things, including such evilness as C++ and perl." -- Erik Naggum This email (and attachments) are confidential and intended for the addressee(s) only. If you are not the intended recipient please notify the sender, delete any copies and do not take action in reliance on it. Any views expressed are the author's and do not represent those of IOP, except where specifically stated. IOP takes reasonable precautions to protect against viruses but accepts no responsibility for loss or damage arising from virus infection. For the protection of IOP's systems and staff emails are scanned automatically.? Institute of Physics Registered in England under Registration No 293851 Registered Office: 76/78 Portland Place, London W1B 1NT -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mailman.bristolbath.org/pipermail/bristolbathpm/attachments/20090915/1d3a1965/attachment-0001.html From pmh at edison.ioppublishing.com Tue Sep 15 14:07:38 2009 From: pmh at edison.ioppublishing.com (Peter Haworth) Date: Tue, 15 Sep 2009 14:07:38 +0100 Subject: [BristolBathPM] Perl course chapters 1 & 2, reviews please :) References: <4A9DA24A.1080900@cosmicperl.com> Message-ID: On Tue, 01 Sep 2009 23:38:02 +0100, Lyle wrote: > Chapter 2: Programming and Computers > > A basic computer consists of CPU, RAM and a HDD with input devices > such as keyboard and mouse, output devices such as VDU and > printers. The CPU processes requests based on the 86 instruction > set. Early computers were programmed in binary a series of 0?s and > 1?s. 1 byte = 8 bits of binary i.e 01001010. This made programming > a lengthy process so assembly language evolved and then on to C > programming. C is the foundation for most programming languages we > have today. Higher level languages such as Perl, Java and Python > use richer syntax making it easier to code larger more detailed > programs. A program that's hundreds of lines of C could be just > tens of lines of Perl. This bugs me in a similar way to how Nell was taught programming in The Diamond Age. A lot of potentially useful and interesting stuff was presented as if it was required preliminary reading, but didn't really contribute to the complete understanding of the subject, so was at best an unnecessary distraction, and at worst a confusing contradiction. All that allegorised guff about binary, Turing machines and lisp was quite amusing and entertaining, but would have been better presented to Nell as a comparison or supplement. I'd write it more like this, which isn't necessarily any better, but gets me off this particular hobby horse: Although computers can process information very rapidly, they need to be given explicit instructions to tell them exactly which kind of processing is required. These instructions are supplied in the form of programs, which may be written in any of a multitude of different programming languages. Most of these languages are designed to be relatively easy for humans to understand, at least in comparison to the "machine code" which is all the computer can directly understand, and to which all such programs are translated to before being acted on by the computer. A very broad spectrum of programming languages is available to choose from. At the very low-level, the machine language for each type of processor has a corresponding "assembly language", which is an almost direct one-to-one mapping from the computer's machine code instructions (10110000 01100001) to mildly human-readable mnemonic codes (mov AL, #61h). Most programming languages used nowadays are at a much higher level than this, with each line of code being translated into a sequence of many machine code instructions. Thus, a given program might consist of thousands of machine code instructions, but would only be many hundred of lines if written in C, but would only be a few lines if written in a high level language like Python, Java, or indeed Perl. -- Peter Haworth pmh at edison.ioppublishing.com ``Even if the word "pity" is in a Dalek's vocabulary banks, it may be listed as a synonym for "errorcode 7 (failure to exterminate caused by temporary targeting failure or neural dysfunction)".'' -- http://www.xibalba.demon.co.uk/jbr/lingo.html This email (and attachments) are confidential and intended for the addressee(s) only. If you are not the intended recipient please notify the sender, delete any copies and do not take action in reliance on it. Any views expressed are the author's and do not represent those of IOP, except where specifically stated. IOP takes reasonable precautions to protect against viruses but accepts no responsibility for loss or damage arising from virus infection. For the protection of IOP's systems and staff emails are scanned automatically.? Institute of Physics Registered in England under Registration No 293851 Registered Office: 76/78 Portland Place, London W1B 1NT -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mailman.bristolbath.org/pipermail/bristolbathpm/attachments/20090915/f2989c35/attachment.html From alex.francis at gmail.com Mon Sep 21 11:58:30 2009 From: alex.francis at gmail.com (Alex Francis) Date: Mon, 21 Sep 2009 11:58:30 +0100 Subject: [BristolBathPM] Scalar::Util::reftype vs. CORE::ref Message-ID: <16afc9550909210358m4c60c51dgc7605c7b029d1c0e@mail.gmail.com> Hi The other day, I confidently told a colleague that it was better to use Scalar::Util::reftype to check e.g. whether a scalar holds a reference to an array: if ( reftype( $param ) && reftype( $param ) eq 'ARRAY' ) { instead of using CORE::ref if ( ref( $param ) eq 'ARRAY' ) { I mentioned this was what PBP recommended. He asked me what the reasoning was, which was the point where I thought "err....." All I can come up with is that reftype is easier to read because it returns what it sounds like it returns, whatever you give it, whereas ref returns the class of an object, or if it's not an object then the type of a reference. Are there any other reasons? We also noted that CORE::ref returns an empty string if there is no return value, whereas reftype returns undef, which seems like an extra pain.. Alex From david at cantrell.org.uk Mon Sep 21 16:38:09 2009 From: david at cantrell.org.uk (David Cantrell) Date: Mon, 21 Sep 2009 16:38:09 +0100 Subject: [BristolBathPM] Scalar::Util::reftype vs. CORE::ref In-Reply-To: <16afc9550909210358m4c60c51dgc7605c7b029d1c0e@mail.gmail.com> References: <16afc9550909210358m4c60c51dgc7605c7b029d1c0e@mail.gmail.com> Message-ID: <20090921153809.GC14686@bytemark.barnyard.co.uk> On Mon, Sep 21, 2009 at 11:58:30AM +0100, Alex Francis wrote: > The other day, I confidently told a colleague that it was better to > use Scalar::Util::reftype to check e.g. whether a scalar holds a > reference to an array: > if ( reftype( $param ) && reftype( $param ) eq 'ARRAY' ) { > > instead of using CORE::ref > if ( ref( $param ) eq 'ARRAY' ) { > > I mentioned this was what PBP recommended. He asked me what the > reasoning was, which was the point where I thought "err....." > > All I can come up with is that reftype is easier to read because it > returns what it sounds like it returns, whatever you give it, whereas > ref returns the class of an object, or if it's not an object then the > type of a reference. That's a good enough reason for me. It's syntactic sugar, as there are all kinds of other ways of doing this, but it's *good* sugar. Other ways of doing it, all of which require some care ... $foo->isa('ARRAY') # if $foo is known to be an object UNIVERSAL::isa($foo, 'ARRAY') # if it might not be. This will ignore # any isa() defined in an object or any # of its superclasses eval { @{$foo}; 1 } && !$@ # but beware operator overloading For the last of those, you can get around the operator overloading problem using Acme::Damn to get an unblessed version of the reference. But really, why would you bother when you can just use reftype ;-) -- David Cantrell | top google result for "topless karaoke murders" You can't spell "slaughter" without "laughter" From cms at beatworm.co.uk Mon Sep 21 21:14:45 2009 From: cms at beatworm.co.uk (Colin M. Strickland) Date: Mon, 21 Sep 2009 21:14:45 +0100 Subject: [BristolBathPM] Scalar::Util::reftype vs. CORE::ref In-Reply-To: <16afc9550909210358m4c60c51dgc7605c7b029d1c0e@mail.gmail.com> References: <16afc9550909210358m4c60c51dgc7605c7b029d1c0e@mail.gmail.com> Message-ID: <89A974D9-526C-42A2-8617-F0E1397179C0@beatworm.co.uk> On 21 Sep 2009, at 11:58, Alex Francis wrote: > if ( reftype( $param ) && reftype( $param ) eq 'ARRAY' ) { > > instead of using CORE::ref > > if ( ref( $param ) eq 'ARRAY' ) { > > I mentioned this was what PBP recommended. He asked me what the > reasoning was, which was the point where I thought "err....." > > All I can come up with is that reftype is easier to read because it > returns what it sounds like it returns, whatever you give it, whereas > ref returns the class of an object, or if it's not an object then the > type of a reference. I have reservations about this, and this would make the second time this month where some citation of best practice / perl critic has given me pause for thought. (I can't remember the first, off-hand). I'm always a little paranoid about dogma. Perhaps it's just because I'm a fossil, but I can't really see that reftype is so much easier to read. The name 'reftype' perhaps describes it's purpose more precisely, to an english speaker, but look at the samples; it's obvious from context what both routines are returning, because of the comparison. Sample B is half the horizontal width, contains half as much punctuation, and 50% less function calls. Version A requires that you to understand where 'reftype' is declared, whereas ref, responds helpfully to a 'perldoc -f', like any built-in. Unconvinced. Still, it managed to inspire me enough to make me post to the list. (/me waves) -- Regards, Colin M. Strickland From robin.ge at gmail.com Thu Sep 24 12:12:57 2009 From: robin.ge at gmail.com (Robin Edwards) Date: Thu, 24 Sep 2009 12:12:57 +0100 Subject: [BristolBathPM] IPW2009 Message-ID: <303603130909240412v60f757a4xa7407386673cad0b@mail.gmail.com> Hi, Anyone feel like coming to the Italian Perl Workshop? Just got plane tickets from bristol to pisa for ?80, works given me the time off :) http://conferences.yapceurope.org/ipw2009/ Rob From webmaster at cosmicperl.com Thu Sep 24 23:18:52 2009 From: webmaster at cosmicperl.com (Lyle) Date: Thu, 24 Sep 2009 23:18:52 +0100 Subject: [BristolBathPM] IPW2009 In-Reply-To: <303603130909240412v60f757a4xa7407386673cad0b@mail.gmail.com> References: <303603130909240412v60f757a4xa7407386673cad0b@mail.gmail.com> Message-ID: <4ABBF04C.2010707@cosmicperl.com> Robin Edwards wrote: > Hi, > > Anyone feel like coming to the Italian Perl Workshop? > > Just got plane tickets from bristol to pisa for ?80, works given me > the time off :) > > http://conferences.yapceurope.org/ipw2009/ > Are the talks in Italian? I think I read somewhere that they are doing a Perl 6 hack... Lyle From pmh at edison.ioppublishing.com Fri Sep 25 10:29:11 2009 From: pmh at edison.ioppublishing.com (Peter Haworth) Date: Fri, 25 Sep 2009 10:29:11 +0100 Subject: [BristolBathPM] London Perl Workshop Message-ID: The IPW is a bit much for my wallet at the moment, but I will almost certainly be going to the London Perl Workshop, which is at the University of Westminster on 5th December. This year's theme is Beginning Perl, but there's usually a wide range of interesting topics being discussed, sometimes making it hard to choose which of several concurrent talks to attend. I highly recommend attending, and presenting if you can, especially if you drive and want to offer me a lift :-) http://conferences.yapceurope.org/lpw2009/ -- Peter Haworth pmh at edison.ioppublishing.com "Any idiot can mumble a few words and end up with a pentagram full of tentacles" -- http://tcow.keenspace.com/d/20021010.html This email (and attachments) are confidential and intended for the addressee(s) only. If you are not the intended recipient please notify the sender, delete any copies and do not take action in reliance on it. Any views expressed are the author's and do not represent those of IOP, except where specifically stated. IOP takes reasonable precautions to protect against viruses but accepts no responsibility for loss or damage arising from virus infection. For the protection of IOP's systems and staff emails are scanned automatically.? Institute of Physics Registered in England under Registration No 293851 Registered Office: 76/78 Portland Place, London W1B 1NT -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mailman.bristolbath.org/pipermail/bristolbathpm/attachments/20090925/4d60ede0/attachment.html