From martin_jacobs at optusnet.com.au Thu Feb 1 15:07:00 2007 From: martin_jacobs at optusnet.com.au (Martin Jacobs) Date: Fri, 2 Feb 2007 09:07:00 +1000 Subject: [Brisbane-pm] Double-click to launch Perl program in Mac OSX Message-ID: <0C31989E-06B3-4EB3-8CCB-DC47EADE912F@optusnet.com.au> Hi folks, How do I execute/launch a Perl program in Mac OSX with a double-click? I'm developing a program called PERRMOSS.pl and it runs fine on WinXP and MacOSX. In WinXP I have told WinXP to open .pl files with Perl.exe through windows explorer. Now, when I double-click on PERRMOSS.pl, it executes the program as it should. MacOSX has a similar 'open with' protocol. The problem is that I cant find 'Perl' as a file or folder anywhere in Finder - the Mac equivalent of windows explorer (probably because MacOSX ships with Perl and it is embedded somewhere in the system). Up to now I have been launching PERRMOSS.pl from the command prompt in Terminal. Thanks in advance. Regards, Martin Visit my website... http://web.mac.com/martin_jacobs1 -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.pm.org/pipermail/brisbane-pm/attachments/20070202/409aae66/attachment.html From martin_jacobs at optusnet.com.au Wed Feb 21 14:45:36 2007 From: martin_jacobs at optusnet.com.au (Martin Jacobs) Date: Thu, 22 Feb 2007 08:45:36 +1000 Subject: [Brisbane-pm] Passing a Two-Dimensional Array to a sub in Perl 5.8.6 Message-ID: <26A1C2AA-D658-41D4-86E4-2503DA5E4487@optusnet.com.au> Hi folks, Can you pass a two-dimensional array to a sub via a reference in Perl 5.8.6? I'm operating under use strict. I have populated a 2D array called @Rain_series, like this... $array[0][0] = n $array[1][0] = m etc I checked that it has the right values in the right places by printing off a few of them. I then compile all the arguments for the subroutine in a further array called @Timestep_arguments, in which the sixth element is a reference to my 2D array ( \@Rain_series ). I then passed @Timestep_arguments into a sub via a reference. The sub looks like this... sub Rain_calculation (\@) {...} Inside the sub, I define another array like this... my $a = @_ my @Rain_series = @$a[5] Where @Rain_series refers to the values in my 2D array. The funny thing is that when I print $Rain_series[0][i] from inside the sub (and after it), I get the right value. When I print $Rain_series[1][i], I get 'undefined'. It appears that the second 'column' in the array is not getting passed into the sub. Any help would be appreciated. Thanks in advance. Regards, Martin Visit my website... http://web.mac.com/martin_jacobs1 -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.pm.org/pipermail/brisbane-pm/attachments/20070222/57e6bcb5/attachment.html From robertl at apnic.net Wed Feb 21 17:58:50 2007 From: robertl at apnic.net (Robert Loomans) Date: Thu, 22 Feb 2007 11:58:50 +1000 Subject: [Brisbane-pm] Passing a Two-Dimensional Array to a sub in Perl 5.8.6 In-Reply-To: <26A1C2AA-D658-41D4-86E4-2503DA5E4487@optusnet.com.au> References: <26A1C2AA-D658-41D4-86E4-2503DA5E4487@optusnet.com.au> Message-ID: <45DCF8DA.9080902@apnic.net> > Any help would be appreciated. Thanks in advance. If you could supply a minimal running version of code that displays this behaviour it would be easier both to understand and to help you fix the problem.... Cheers, Rob -- Robert Loomans Email: robertl at apnic.net Programmer/Analyst, APNIC Phone: +61 7 3858 3100 http://www.apnic.net Fax: +61 7 3858 3199 -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/x-pkcs7-signature Size: 3818 bytes Desc: S/MIME Cryptographic Signature Url : http://mail.pm.org/pipermail/brisbane-pm/attachments/20070222/978c14bd/attachment.bin From fof at brainstorm.net.au Wed Feb 21 18:07:48 2007 From: fof at brainstorm.net.au (Geoff Toogood) Date: Thu, 22 Feb 2007 12:07:48 +1000 Subject: [Brisbane-pm] Passing a Two-Dimensional Array to a sub in Perl 5.8.6 In-Reply-To: <45DCF8DA.9080902@apnic.net> Message-ID: <003401c75626$4065ae20$6800a8c0@geoff> I agree some code would help us with your problem.. For starters make sure you are dereferencing the array in your subroutine correctly when you are assigning it to your array in the subroutine. Anyway.. Send code :o) Geoff -----Original Message----- From: brisbane-pm-bounces+fof=brainstorm.net.au at pm.org [mailto:brisbane-pm-bounces+fof=brainstorm.net.au at pm.org] On Behalf Of Robert Loomans Sent: Thursday, 22 February 2007 11:59 AM To: Martin Jacobs Cc: Brisbane Perl Group Subject: Re: [Brisbane-pm] Passing a Two-Dimensional Array to a sub in Perl 5.8.6 > Any help would be appreciated. Thanks in advance. If you could supply a minimal running version of code that displays this behaviour it would be easier both to understand and to help you fix the problem.... Cheers, Rob -- Robert Loomans Email: robertl at apnic.net Programmer/Analyst, APNIC Phone: +61 7 3858 3100 http://www.apnic.net Fax: +61 7 3858 3199 From djames at thehub.com.au Wed Feb 21 18:40:10 2007 From: djames at thehub.com.au (Damian James) Date: Thu, 22 Feb 2007 12:40:10 +1000 Subject: [Brisbane-pm] Passing a Two-Dimensional Array to a sub in Perl 5.8.6 In-Reply-To: <26A1C2AA-D658-41D4-86E4-2503DA5E4487@optusnet.com.au> References: <26A1C2AA-D658-41D4-86E4-2503DA5E4487@optusnet.com.au> Message-ID: On 22/02/2007, at 8:45 AM, Martin Jacobs wrote: > Can you pass a two-dimensional array to a sub via a reference in > Perl 5.8.6? Yes, the same way as any other reference. > I'm operating under use strict. > > I have populated a 2D array called @Rain_series, like this... > > $array[0][0] = n > $array[1][0] = m > > etc I prefer to make every reference/dereference operation explicit, otherwise it's too easy to get confused. Therefore, this is: $array[0]->[0] = $n; etc > > I checked that it has the right values in the right places by > printing off a few of them. > > I then compile all the arguments for the subroutine in a further > array called @Timestep_arguments, in which the sixth element is a > reference to my 2D array ( \@Rain_series ). > > I then passed @Timestep_arguments into a sub via a reference. The > sub looks like this... > > sub Rain_calculation (\@) {...} > my $a = @_ > my @Rain_series = @$a[5] This would be: my @Rain_series = @{ $a->[5] }; However, I strongly suggest that even though Perl has a prototype mechanism that can be used to enforce passing by reference, not using it. Seriously, it's probably what's causing your confusion here. Make all your refecence/dereference operations explicit. Also, $a is special, though not reserved in Perl. It's used by the sort() function, see the perldoc in perlfunc (perldoc -f sort). So: sub Rain_calculation { my @stuff = @_; my @Rain_series = @{ $stuff[5] }; Cheers, Damian From robertl at apnic.net Wed Feb 21 18:59:13 2007 From: robertl at apnic.net (Robert Loomans) Date: Thu, 22 Feb 2007 12:59:13 +1000 Subject: [Brisbane-pm] Passing a Two-Dimensional Array to a sub in Perl 5.8.6 In-Reply-To: References: <26A1C2AA-D658-41D4-86E4-2503DA5E4487@optusnet.com.au> Message-ID: <45DD0701.2010004@apnic.net> > However, I strongly suggest that even though Perl has a prototype > mechanism that can be used to enforce passing by reference, not using > it. Seconded. Unless you have a strong reason, don't use prototypes at all, and only use the array ref prototype under duress. > So: > > sub Rain_calculation { > my @stuff = @_; > my @Rain_series = @{ $stuff[5] }; Personally, if I'm using multiple args in a sub, I do something like: sub Rain_calculation { my ($zero, $one, $two, $three, $four, $five) = @_; do_something($five->[0]); foreach my $elem (@$five) { (where $zero ... $five would have more meaningful names). That way you aren't dealing with meaningless references to $_[x] that make the code really difficult to read, and the array you passed in via $five is not copied.... If you really must use $five as a real array you can just do: my @big_five = @$five; ... but realise that @big_five is then only a copy of the first level of your structure; the elements will be references to the same arrays you created in @Rain_series. Cheers, Rob -- Robert Loomans Email: robertl at apnic.net Programmer/Analyst, APNIC Phone: +61 7 3858 3100 http://www.apnic.net Fax: +61 7 3858 3199 -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/x-pkcs7-signature Size: 3818 bytes Desc: S/MIME Cryptographic Signature Url : http://mail.pm.org/pipermail/brisbane-pm/attachments/20070222/a3d9d525/attachment-0001.bin From djames at thehub.com.au Wed Feb 21 23:54:59 2007 From: djames at thehub.com.au (Damian James) Date: Thu, 22 Feb 2007 17:54:59 +1000 Subject: [Brisbane-pm] Passing a Two-Dimensional Array to a sub in Perl 5.8.6 In-Reply-To: <45DD0701.2010004@apnic.net> References: <26A1C2AA-D658-41D4-86E4-2503DA5E4487@optusnet.com.au> <45DD0701.2010004@apnic.net> Message-ID: <0D5B55A9-1CBC-4EEF-A842-D35A02FE2017@thehub.com.au> On 22/02/2007, at 12:59 PM, Robert Loomans wrote: > > Personally, if I'm using multiple args in a sub, I do something like: > > sub Rain_calculation { > my ($zero, $one, $two, $three, $four, $five) = @_; > > do_something($five->[0]); > > foreach my $elem (@$five) { > > (where $zero ... $five would have more meaningful names). I'm more likely to use a hash, for the same reasons. Sending the args just as a plain hash would look like this: my %foo = ( bar => 42, baz => [ [1,2],[2,2],[2,1],[1,1]] ); do_stuff(%foo); sub do_stuff { my %stuff = @_; print "$_ = $stuff{$_}\n" for qw/ bar /; print "@{ $_ }\n" for @{ $stuff{baz} }; } Of course, it's possible to pass the hash by reference too: do_stuff( \%foo ); sub do_stuff { #the either: my %stuff = %{ $_[0] }; #or just refer to the elements by reference: print "@{$_}\n" for @{ $stuff->{baz} }; } > That way you aren't dealing with meaningless references to $_[x] that > make the code really difficult to read, and the array you passed in > via > $five is not copied.... Sometimes you just want the reference and sometimes, of course, you want the copy. It's worth pointing out for the OP's benefit what the difference is: my $x = [ 0..99 ]; # If that's unfamiliar syntax, imagine it was "my @w = ( 0..99 ); my $x = \@w;" my $y = $x; my @z = @$x; $x is a reference to an anonymous array, containing 0 to 99. $y gets the value of $x, which is the reference, so $y is actually a reference to the same array. Doing, eg, $y->[50]++, means that $x-> [50] is now 51. @z is a copy of the data in the array referred to in $x and $y, so you can do stuff to @z without affecting $x. Generally in subs that do some manipulation of data and then return the result, you want to make a copy. In subs that return a result, but don't need to do any manipulation to the input data, you use a reference to avoid any (usually quite insignificant anyway) memory overhead. You are best advised to avoid the third case, subs that take a reference and change the data through it. There's a whole realm of obscure bugs that you invite into your system when you do this so called "long distance" data manipulation. Sure, half the Win32 API works like that, but those aren't people you want to emulate... Anyway, there's a bunch of helpful material about references in the perl documentation, see perlreftut for instance. Cheers, Damian From ajsavige at yahoo.com.au Thu Feb 22 12:58:09 2007 From: ajsavige at yahoo.com.au (Andrew Savige) Date: Fri, 23 Feb 2007 07:58:09 +1100 (EST) Subject: [Brisbane-pm] Passing a Two-Dimensional Array to a sub in Perl 5.8.6 In-Reply-To: <26A1C2AA-D658-41D4-86E4-2503DA5E4487@optusnet.com.au> Message-ID: <134396.47469.qm@web56406.mail.re3.yahoo.com> --- Martin Jacobs wrote: > Can you pass a two-dimensional array to a sub via a reference in > Perl 5.8.6? Yes. Maybe Data::Dumper can help clarify what's going on? A simple example: use strict; use Data::Dumper; my @x; $x[2][3] = "elt23"; print Dumper(\@x); Notice that two dimensional arrays in Perl are essentially just a one dimensional array of list references. HTH, /-\ Send instant messages to your online friends http://au.messenger.yahoo.com From ajsavige at yahoo.com.au Thu Feb 22 13:31:30 2007 From: ajsavige at yahoo.com.au (Andrew Savige) Date: Fri, 23 Feb 2007 08:31:30 +1100 (EST) Subject: [Brisbane-pm] Passing a Two-Dimensional Array to a sub in Perl 5.8.6 In-Reply-To: Message-ID: <978715.37236.qm@web56402.mail.re3.yahoo.com> --- Damian James wrote: > However, I strongly suggest that even though Perl has a prototype > mechanism that can be used to enforce passing by reference, not using > it. Seriously, it's probably what's causing your confusion here. Agreed. Quoting from Chapter 9 of Perl Best Practices: "Don't use subroutine prototypes" As for why, you can read all about it even if you don't own the book because Chapter 9 is the freely available sample chapter at: http://www.oreilly.com/catalog/perlbp/chapter/index.html Cheers, /-\ Send instant messages to your online friends http://au.messenger.yahoo.com From jarich at perltraining.com.au Thu Feb 22 18:19:46 2007 From: jarich at perltraining.com.au (Jacinta Richardson) Date: Fri, 23 Feb 2007 13:19:46 +1100 Subject: [Brisbane-pm] Passing a Two-Dimensional Array to a sub in Perl 5.8.6 In-Reply-To: <26A1C2AA-D658-41D4-86E4-2503DA5E4487@optusnet.com.au> References: <26A1C2AA-D658-41D4-86E4-2503DA5E4487@optusnet.com.au> Message-ID: <45DE4F42.5020603@perltraining.com.au> As many people have said, subroutine prototypes are a bad idea. However I'm not sure what's causing your problem. I've tried to duplicate your code from what you've written (with some minor changes to make it compile) and I've come up with the following: #!/usr/bin/perl -w use strict; use Data::Dumper; # Some input data my @array; $array[0] = [ 1 .. 10 ]; $array[1] = [ 'a' .. 'g' ]; # Define my subroutine (I have to do it up here to avoid prototype warning) sub test (\@) { my ($a) = @_; my @rain = @{$a->[5]}; print '-' x 50, "\n"; print "rain[0][1]: ", $rain[0][1], "\n"; # prints '2' print "rain[1][1]: ", $rain[1][1], "\n"; # prints 'b' print '-' x 50, "\n"; print "a: ", Dumper $a; print '-' x 50, "\n"; print "rain: ", Dumper \@rain; print '-' x 50, "\n"; } # Create list of arguments and call test sub my @args = (11 .. 15, \@array); test(@args); Unfortunately this works perfectly. @rain appears to be getting full access to what we defined in @array as expected. So I must have missed something from what you wrote. The same effect can be achieved without prototypes as follows: #!/usr/bin/perl #use strict; use Data::Dumper; my @array; $array[0] = [ 1 .. 10 ]; $array[1] = [ 'a' .. 'g' ]; my @args = (11 .. 15, \@array); test(\@args); sub test { my ($a) = @_; my @rain = @{$a->[5]}; print '-' x 50, "\n"; print "rain[0][1]: ", $rain[0][1], "\n"; print "rain[1][1]: ", $rain[1][1], "\n"; print '-' x 50, "\n"; print "a: ", Dumper $a; print '-' x 50, "\n"; print "rain: ", Dumper \@rain; print '-' x 50, "\n"; } Alternately, depending on what you're doing, you can pass test() the array directly rather than as a reference: test(@args); sub test { # Must use better variable names my ($a, $b, $c, $d, $e, $rain) = @_; my @rain = @$rain; ... } Be aware that with all of these methods, if you manipulate the sub-arrays in @rain you are changing that data for your whole program. If the above doesn't help you, please feel free to modify what I've written to more accurately reflect your problem so we can play around with it a bit. All the best, Jacinta -- ("`-''-/").___..--''"`-._ | Jacinta Richardson | `6_ 6 ) `-. ( ).`-.__.`) | Perl Training Australia | (_Y_.)' ._ ) `._ `. ``-..-' | +61 3 9354 6001 | _..`--'_..-_/ /--'_.' ,' | contact at perltraining.com.au | (il),-'' (li),' ((!.-' | www.perltraining.com.au | From martin_jacobs at optusnet.com.au Thu Feb 22 18:23:39 2007 From: martin_jacobs at optusnet.com.au (Martin Jacobs) Date: Fri, 23 Feb 2007 12:23:39 +1000 Subject: [Brisbane-pm] Passing 2d Arrays ctd... Message-ID: <8AF3ECB1-155F-49F4-AD7E-755D7D9CAF4A@optusnet.com.au> Hi Folks, Thanks to everyone who replied to my earlier email. I have not resolved the problem fully , but here's an interim response... Thanks to Andrew Savage for pointing me to http://www.oreilly.com/ catalog/perlbp/chapter/index.html . Being new to Perl (in fact to any modern programming language), this is the kind of thing I need to get acquainted with. Indeed, establishing a 'best practice', or 'this is how we do it' approach is very important to my project because I want it to be 'hackable' by other engineers in my profession, and they have even less understanding of Perl than me ( I had better add that I want to make the calculations explicit for future interrogation and reference, rather than hiding them away in a compiled program, so even if my colleagues will not understand subs, refs and the like, they can at least see that 1 + 1 = 2). Thanks to the tip about $a. I was trying to avoid $variables_with_really_long_names, but at least $variables_with_really_long_names tell you what they are, and there's little likelihood of confusing them with something that refers to something else. Some of you suggested I include some of the code. In future I will but, to be honest, it looks pretty horrible at the moment because of my rudimentary (but improving) knowledge of Perl. If I told you I am only just beginning to understand references and regexes, you will probably understand what I mean. With regard to prototypes, I had started using them on the advice of a friend of mine, who is a Perl geek. I don't have the experience to argue the pros and cons, but I am willing to follow the advice in Perl Best Practice (which is what I need to get to grips with in any case). Back to the drawing board... Regards, Martin Visit my website... http://web.mac.com/martin_jacobs1 -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.pm.org/pipermail/brisbane-pm/attachments/20070223/dead56f7/attachment.html From djames at thehub.com.au Thu Feb 22 18:31:48 2007 From: djames at thehub.com.au (Damian James) Date: Fri, 23 Feb 2007 12:31:48 +1000 Subject: [Brisbane-pm] Passing a Two-Dimensional Array to a sub in Perl 5.8.6 In-Reply-To: <45DE4F42.5020603@perltraining.com.au> References: <26A1C2AA-D658-41D4-86E4-2503DA5E4487@optusnet.com.au> <45DE4F42.5020603@perltraining.com.au> Message-ID: <8EA3B54B-1345-42BF-970F-EE295E128AC8@thehub.com.au> On 23/02/2007, at 12:19 PM, Jacinta Richardson wrote: > sub test (\@) { > my ($a) = @_; > my @rain = @{$a->[5]}; > ... > Unfortunately this works perfectly. @rain appears to be getting > full access to > what we defined in @array as expected. So I must have missed > something from > what you wrote. The same effect can be achieved without prototypes > as follows: What you missed was that Martin didn't dereference $a correctly: On 22/02/2007, at 8:45 AM, Martin Jacobs wrote: > my @Rain_series = @$a[5] It's not needing the explicit @{}, it's that the -> is missing Cheers, Damian From ajsavige at yahoo.com.au Thu Feb 22 21:58:47 2007 From: ajsavige at yahoo.com.au (Andrew Savige) Date: Fri, 23 Feb 2007 16:58:47 +1100 (EST) Subject: [Brisbane-pm] Passing 2d Arrays ctd... In-Reply-To: <8AF3ECB1-155F-49F4-AD7E-755D7D9CAF4A@optusnet.com.au> Message-ID: <631711.77491.qm@web56413.mail.re3.yahoo.com> --- Martin Jacobs wrote: > Thanks to the tip about $a. I was trying to avoid > $variables_with_really_long_names, but at least > $variables_with_really_long_names tell you what they are, > and there's little likelihood of confusing them with > something that refers to something else. Chapter 1 of "The Practice of Programming" by Kernighan and Pike: http://cm.bell-labs.com/cm/cs/tpop/ has some sound naming advice: use short names for short scopes, longer names for larger scopes. In particular, globals are dangerous and ugly and so usually warrant very long names (also making it easier to search for all occurrences of their use). For example, $i may be appropriate for a loop containing only one statement, such as: for my $i (0 .. $some_magic_number) { # one statement only } whereas it's probably too short if the loop body consists of 20 or more statements. In addition to that, Damian discusses Naming Conventions at length is his "Perl Best Practices" book in Chapter 3 (you'll need to buy the book for that chapter). One example he gives is on forming effective abbreviations: for example, "maximum length" is better abbreviated as $max_len rather than $mx_lngth. Cheers, /-\ Send instant messages to your online friends http://au.messenger.yahoo.com From martin_jacobs at optusnet.com.au Fri Feb 23 20:20:26 2007 From: martin_jacobs at optusnet.com.au (Martin Jacobs) Date: Sat, 24 Feb 2007 14:20:26 +1000 Subject: [Brisbane-pm] Passing references into Arrays Message-ID: Hi folks, Having read through the relevant parts of 'Programming Perl', 'Perl Best Practices' and PerlRefTut, I am still getting to grips with referencing and dereferencing, and I'm trying to formulate some conventions to make my code readable (or at least internally consistent). With this in mind, I've been trying to establish a 'one size fits all' way to pass variables into subs. I know that this might be inefficient for subs with only a couple of variables, but some of my subs need a dozen or so variables. Furthermore, I need to pass references. I'm going to be dealing with some arrays that are 7 million lines long, so I don't want to copy the arrays if I can help it. The data structures of the arrays are simple, its just that they are big. In following 'Perl Best Practices', I have set up the attached two versions of a 'conventional' program, which I intend to use as a kind of template for my 'real' program (its called PERRMOSS). They actually do what they are supposed to do, though I don't have the experience to fully explain why. I would be grateful for some sanity checking here. If you've been reading my earlier posts, you will note that I'm not trying to use prototypes in these programs. A couple of questions; Perl Best Practices says 'Use a hash of named arguments for any subroutine that has more than three parameters'. OK, that's PERRMOSS. I have varied the advice, though, in that I have set up a hash of references to the variables (because some of the arrays will be very big). This does seem rather convoluted because you've got to set up a hash with all the keys, then pass the hash to the sub, then look in all the keys in the sub to find what you're looking for. Does this approach make more defensive programming, or less? If the keys are to make sense, then they should have long names, like the names of the values, but then there's the danger of mixing up the key with the value. Version 1 works well, but the syntax is cluttered because each operation has to derefence each variable at every step. Version 2 attempts to get round this by dereferencing everything at the start of the sub. Does this mean it copies the variables in the sub? Oddly, and I don't know why, if you hash out line 31, the sub applies the operation to the referent outside the sub, @k. I thought that the referent would not change until you get to the end of the sub, which is what happens for $i, @j or %l. I take this as signifying that the code is not robust, so it is possibly not a good strategy to pursue. Thanks in advance for any help. (Yes, I know the testprint line numbers in Version 2 are not accurate) Regards, Martin Visit my website... http://web.mac.com/martin_jacobs1 ? ? -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.pm.org/pipermail/brisbane-pm/attachments/20070224/f49bcb52/attachment.html -------------- next part -------------- A non-text attachment was scrubbed... Name: Perrmoss_Conventions_version01.pl Type: text/x-perl-script Size: 3014 bytes Desc: not available Url : http://mail.pm.org/pipermail/brisbane-pm/attachments/20070224/f49bcb52/attachment.bin -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.pm.org/pipermail/brisbane-pm/attachments/20070224/f49bcb52/attachment-0001.html -------------- next part -------------- A non-text attachment was scrubbed... Name: Perrmoss_Conventions_version02.pl Type: text/x-perl-script Size: 3224 bytes Desc: not available Url : http://mail.pm.org/pipermail/brisbane-pm/attachments/20070224/f49bcb52/attachment-0001.bin -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.pm.org/pipermail/brisbane-pm/attachments/20070224/f49bcb52/attachment-0002.html From martin_jacobs at optusnet.com.au Fri Feb 23 20:23:46 2007 From: martin_jacobs at optusnet.com.au (Martin Jacobs) Date: Sat, 24 Feb 2007 14:23:46 +1000 Subject: [Brisbane-pm] Doh! Message-ID: <64320DB1-6E3F-4B4A-8B2A-2345C5D41097@optusnet.com.au> Folks, I meant to head my last email 'Passing references into Subs' Regards, Martin Visit my website... http://web.mac.com/martin_jacobs1 -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.pm.org/pipermail/brisbane-pm/attachments/20070224/15e0f53c/attachment.html From jarich at perltraining.com.au Fri Feb 23 21:21:13 2007 From: jarich at perltraining.com.au (Jacinta Richardson) Date: Sat, 24 Feb 2007 16:21:13 +1100 Subject: [Brisbane-pm] Passing references into Arrays In-Reply-To: References: Message-ID: <45DFCB49.2030407@perltraining.com.au> Martin Jacobs wrote: > Perl Best Practices says 'Use a hash of named arguments for any > subroutine that has more than three parameters'. OK, that's PERRMOSS. I > have varied the advice, though, in that I have set up a hash of > references to the variables (because some of the arrays will be very > big). I think you're making this too hard. You should be able to do the following: do_something_cool( count => 2, list => \@some_list, defaults => \%defaults, otherthing => 10, somestring => 'dfasdfasdfsdf', scalar => $something, ); sub do_something_cool { my %args = @_; my $count = $args{count} || 0; my $list = $args{list}; # just using the scalar avoids copying my $hash = $args{defaults}; .... foreach my $value (@$list) { ... } } You do not need to create a hash of references per se. What I have done above will still ensure that only scalars will be passed around. Unless your simple scalars contain very large strings in them, or you _really_ need to change their contents, I'd suggest that you don't pass them as references, but instead pass them by value. > If the keys are to make sense, > then they should have long names, like the names of the values, but then > there's the danger of mixing up the key with the value. Use good layout and => to help reduce this confusion. Glancing at my code above you should be able to tell instantly which are keys and which are values. > Version 1 works well, but the syntax is cluttered because each operation > has to derefence each variable at every step. It's worse than cluttered, it hurts my eyes! > Version 2 attempts to get round this by dereferencing everything at the > start of the sub. Does this mean it copies the variables in the sub? Yes these dereferences are doing copying. Ideally you pass references and then use the references - dereferencing only where you need to: as in my foreach loop above. > Oddly, and I don't know why, if you hash out line 31, the sub applies > the operation to the referent outside the sub, @k You code does this: my @k = @{$arg_ref->{arg3}}; $k[0][0] = "$k[1][1]"."$k[1][2]"; @{$arg_ref->{arg3}} = @k; Let's look at what this does. On the first time we dereference $arg_ref->{arg3} to get an array. If we previously had had: $arg_ref->{arg3} = ['a' .. 'e']; then we would now have: @k = ('a'..'e'); However, we previously had: $arg_ref->{arg3} = [ref1, ref2, ref3...] so we now have: @k = (ref1, ref2, ref3, ...] The second line then changes the data structure pointed at by that first reference. So instead of saying: $k[0] = x which would have changed only @k, what we are instead doing is the same as: ref1->[0] = x So we're changing the data structure pointed to from @k[0] Thus whether or not we re-assign @k to @{$arg_ref->{arg3}} the under-lying data structure has been changed. The third line just involves a little more copying. If you want true copying so that you can change parts of a data structure without repercussions, look at Storable's "clone" method. I hope that helps. Now.... some comments on your included code: > #!/usr/local/bin/perl > use warnings; > use strict; > use Time::Local; > > #The following is provided as a 'template' for the conventions used in PERRMOSS. > #It is based on Perl Best Practices by Damian Conway, in particular Chapter 9. > #Chapter 9 can be found at www.oreilly.com/catalog/perlbp/chapter/ch09.pdf. > > &Some_block_of_code; Subroutines really are best called with parens and no &. Some_block_of_code(); > sub Some_sub { ... > #Then, do some operations > $$i = $$i + 100; > print 'Testprint line 22 $$i = '."$$i\n"; I know this works, but that's not necessarily a good reason for doing it. > $$j[0] = $$j[1]*$$j[2]; Much better written as: $j->[0] = $j->[1] * $j->[2]; > my $arguments = Some_sub ({ > arg1 => \$i, > arg2 => \@j, > arg3 => \@k, > arg4 => \%l, > }); There are two good reasons for passing references to a subroutine: 1. The data structures are large and thus you don't want to copy them 2. The subroutine needs to be able to edit those data structures. If you have a variable that doesn't fall into either of the above, don't pass that variable as a reference. It is a very good idea to make sure that any subroutine which changes its arguments has a name that reflects that. You don't want to call a subroutine called: print_data only to find that it completely corrupts the data structures sent to it. I've attached a slightly modified version of your code to show another alternative. In it I return the change to $i (because I don't like references to scalars), but if you really need to use the reference to scalar then of course you should. J -- ("`-''-/").___..--''"`-._ | Jacinta Richardson | `6_ 6 ) `-. ( ).`-.__.`) | Perl Training Australia | (_Y_.)' ._ ) `._ `. ``-..-' | +61 3 9354 6001 | _..`--'_..-_/ /--'_.' ,' | contact at perltraining.com.au | (il),-'' (li),' ((!.-' | www.perltraining.com.au | -------------- next part -------------- A non-text attachment was scrubbed... Name: test1.pl Type: text/x-perl Size: 2611 bytes Desc: not available Url : http://mail.pm.org/pipermail/brisbane-pm/attachments/20070224/02ebed98/attachment-0001.bin From martin_jacobs at optusnet.com.au Sun Feb 25 17:18:13 2007 From: martin_jacobs at optusnet.com.au (Martin Jacobs) Date: Mon, 26 Feb 2007 11:18:13 +1000 Subject: [Brisbane-pm] Passing Refs into a Sub ctd... Message-ID: Folks, Thanks to Jacinta for her comments and suggestions. Jacinta tells me that my previous attempts that hurt her eyes, and that I am making it far more difficult than it needs to be. I fully sympathize. I feel like someone who is learning a foreign language, and when I try to say "bonjour", it comes across as "may the seed of your loins be fruitful in the belly of your woman". It is embarrassing; its not appropriate, not elegant and not robust. Finding a strategy that is succinct, elegant and robust has given me a three-month headache, which is why I have asked for your help. I have revised my trial code according to Jacinta's comments, as attached. I have included some comments in the code in an attempt to explain to myself what I have done. I note Jacinta's preference to pass scalars into subs as values, not as references. Again, I would appreciate any comments. Regards, Martin Visit my website... http://web.mac.com/martin_jacobs1 ? -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.pm.org/pipermail/brisbane-pm/attachments/20070226/34630b2d/attachment.html -------------- next part -------------- A non-text attachment was scrubbed... Name: Perrmoss_Conventions_version03.pl Type: text/x-perl-script Size: 3081 bytes Desc: not available Url : http://mail.pm.org/pipermail/brisbane-pm/attachments/20070226/34630b2d/attachment.bin -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.pm.org/pipermail/brisbane-pm/attachments/20070226/34630b2d/attachment-0001.html From martin_jacobs at optusnet.com.au Sun Feb 25 19:28:01 2007 From: martin_jacobs at optusnet.com.au (Martin Jacobs) Date: Mon, 26 Feb 2007 13:28:01 +1000 Subject: [Brisbane-pm] Did my last email get through? Message-ID: Don't reply to this, its just a test. Regards, Martin Visit my website... http://web.mac.com/martin_jacobs1 -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.pm.org/pipermail/brisbane-pm/attachments/20070226/23791df2/attachment.html From jarich at perltraining.com.au Mon Feb 26 16:18:02 2007 From: jarich at perltraining.com.au (Jacinta Richardson) Date: Tue, 27 Feb 2007 11:18:02 +1100 Subject: [Brisbane-pm] Passing Refs into a Sub ctd... In-Reply-To: References: Message-ID: <45E378BA.6050304@perltraining.com.au> I know that it's hard. It looks like you're almost there at least. :) > Again, I would appreciate any comments. Looks good to me. Just one little thing. Remember that instead of this: my $new_i = change_everything ( arg1 => $i, #$i is a variable (which is a scalar in this case) arg2 => \@j, #\@j is a reference to @j arg3 => \@k, #\@k is a reference to @k arg4 => \%l, #\%l is a reference to %l ); #Take a look at the output print 'Testprint line 68 $new_i = ' . "$new_i\n"; You can instead re-assign to $i if you want to: $i = change_everything ( arg1 => $i, #$i is a variable (which is a scalar in this case) arg2 => \@j, #\@j is a reference to @j arg3 => \@k, #\@k is a reference to @k arg4 => \%l, #\%l is a reference to %l ); #Take a look at the output print 'Testprint line 68 $i = ' . "$i\n"; If you have any questions about how this is working, or if you want me/us to review any code you take from this, please feel free to speak up. J -- ("`-''-/").___..--''"`-._ | Jacinta Richardson | `6_ 6 ) `-. ( ).`-.__.`) | Perl Training Australia | (_Y_.)' ._ ) `._ `. ``-..-' | +61 3 9354 6001 | _..`--'_..-_/ /--'_.' ,' | contact at perltraining.com.au | (il),-'' (li),' ((!.-' | www.perltraining.com.au | From jarich at perltraining.com.au Mon Feb 26 18:52:35 2007 From: jarich at perltraining.com.au (Jacinta Richardson) Date: Tue, 27 Feb 2007 13:52:35 +1100 Subject: [Brisbane-pm] OSDC 2007 in Brisbane! Message-ID: <45E39CF3.3080800@perltraining.com.au> G'day Happy Perl People, You would have heard a lot about the Open Source Developers' Conference from me in 2004, 2005 and 2006. But just in case you don't know, it's a community based conference for developers who use or write open source. The conference website can be found at http://www.osdc.com.au/ with lots of general information at: http://www.osdc.com.au/faq/index.html If you didn't manage to get down to Melbourne to join in the fun in the last three years, you now have an opportunity to go to it at home! That's right, a team from Brisbane lead by Arjen Lentz is running OSDC in Brisbane and I'm sure he'd love your help. OSDC was originally run by Melbourne Perl Mongers and has had a strong Perl presence every year, I encourage you to keep up this trend and help keep it a rocking conference. If you're interested in being involved in any sense perhaps by helping organise of if you have any good contacts for sponsors etc, please contact Arjen. This can be done by sending email to his first name at lentz.com.au. All the best, Jacinta -- ("`-''-/").___..--''"`-._ | Jacinta Richardson | `6_ 6 ) `-. ( ).`-.__.`) | Perl Training Australia | (_Y_.)' ._ ) `._ `. ``-..-' | +61 3 9354 6001 | _..`--'_..-_/ /--'_.' ,' | contact at perltraining.com.au | (il),-'' (li),' ((!.-' | www.perltraining.com.au | From martin_jacobs at optusnet.com.au Mon Feb 26 23:32:33 2007 From: martin_jacobs at optusnet.com.au (Martin Jacobs) Date: Tue, 27 Feb 2007 17:32:33 +1000 Subject: [Brisbane-pm] To Chomp or not to Chomp Message-ID: <7D49F29F-5603-4E6B-AE6B-14B6D2B82DC3@optusnet.com.au> Hi folks, Here's another one of those 'it should be easy' scenarios. Again, I would appreciate your help. This time, I've got a borrowed 'chomp' regex (chomp behaves in exactly the same way). But, instead of chopping off the last character in the string, it returns the value '1'. I can only guess that this is because Perl is working in 'list mode', not in 'paragraph mode' (see here), which makes sense because the file it is reading from is a list. And its chopping off 1 character (the new line character). Please tell me how to get Perl doing the right thing here. I am going to need to get it right for my 7 million line long arrays in future. I could resort to substr, but that's not as efficient (apparently), and I've got to get to grips with regexes anyway. I enclose the relevant code. PERRMOSS_Control_File.txt needs to be in the same directory as Input_file_chomp.pl. Regards, Martin Visit my website... http://web.mac.com/martin_jacobs1 ?? -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.pm.org/pipermail/brisbane-pm/attachments/20070227/5025092d/attachment-0003.html -------------- next part -------------- A non-text attachment was scrubbed... Name: Input_file_chomp.pl Type: text/x-perl-script Size: 265 bytes Desc: not available Url : http://mail.pm.org/pipermail/brisbane-pm/attachments/20070227/5025092d/attachment-0001.bin -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.pm.org/pipermail/brisbane-pm/attachments/20070227/5025092d/attachment-0004.html -------------- next part -------------- An embedded and charset-unspecified text was scrubbed... Name: PERRMOSS_Control_File.txt Url: http://mail.pm.org/pipermail/brisbane-pm/attachments/20070227/5025092d/attachment-0001.txt -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.pm.org/pipermail/brisbane-pm/attachments/20070227/5025092d/attachment-0005.html From Sarah.Smith at trolltech.com Tue Feb 27 00:47:59 2007 From: Sarah.Smith at trolltech.com (Sarah Smith) Date: Tue, 27 Feb 2007 18:47:59 +1000 Subject: [Brisbane-pm] To Chomp or not to Chomp In-Reply-To: <7D49F29F-5603-4E6B-AE6B-14B6D2B82DC3@optusnet.com.au> References: <7D49F29F-5603-4E6B-AE6B-14B6D2B82DC3@optusnet.com.au> Message-ID: <200702271847.59730.Sarah.Smith@trolltech.com> On Tuesday 27 February 2007 17:32, Martin Jacobs wrote: > Hi folks, > > Here's another one of those 'it should be easy' scenarios. Again, I > would appreciate your help. See the attached - it is untested and will likely eat your harddrive, so take it and use it as an example. Don't run it, or accept as gospel. Probably you want to process your file line by line. The fact that you called your variable "$file" indicates that maybe you thought you were slurping in the whole file. (See "perldoc perlvar" and search for "slurp" to see how to slurp a whole file into a scalar). Slurping is OK if you know for sure your file is small, but line by line often works the best. When the code did "$file = ;" it only go the first line of the file, not the whole file. You'll also see "@file = ;" which does get the whole file, but again, what if the file is very big? Why not just process it line by line as in the attached. > This time, I've got a borrowed 'chomp' regex (chomp behaves in > exactly the same way). Why exactly? Why not use chomp? "perldoc -f chomp" Or if you need to extract information from each line, why bother chomping? > But, instead of chopping off the last > character in the string, it returns the value '1'. The s/// is the substitution operator. Look at "perldoc -q space" for how to remove spaces from a line like this using regex. Below is the "why" for the "1". > > I can only guess that this is because Perl is working in 'list mode', > not in 'paragraph mode' (see here), which makes sense because the > file it is reading from is a list. And its chopping off 1 character > (the new line character). The bind operator =~ causes the regex to operate on what you bind it to. Here you bind s/// which modifies things its bound to. When you assign to the *result of a bind* in *list context* you get back a list of all the match capture values: # $line (and $line_too) contains "Job Number: J2700" # some regex my $field_regex = qr/^([^:]+):\s+(.*?)$/ ; # assign a list to the result of the bind my ( $field, $value ) = $line =~ m/$field_regex/ ; # so now $field and $value are equal to the capture values (in round brackets) # from the above regex, eg "Job Number" and "J2700" # assign a scalar and get the count of elements my $count_of_matches = $line_too =~ m/$field_regex/ ; In your code you actually altered $file and threw the alteration away: $num_of_matches = $file =~ s/[\r\n]+$//; # not recommended, use chomp # $file is now altered by the s/// substitution operator $file = $num_of_matches; # you overwrote your alteration > Please tell me how to get Perl doing the right thing here. I am going > to need to get it right for my 7 million line long arrays in future. > I could resort to substr, but that's not as efficient (apparently), > and I've got to get to grips with regexes anyway. Can I suggest getting hold of a copy of the "Perl Cookbook" which has lots of good recipes for doing stuff, and also the context of how to use them. The attached might get you started. > > I enclose the relevant code. PERRMOSS_Control_File.txt needs to be in > the same directory as Input_file_chomp.pl. > > Regards, > Martin > Visit my website... > http://web.mac.com/martin_jacobs1 > > ?? -- Sarah Smith BSc MACS Senior Software Engineer Ph +61 7 321 999 06 x109 Trolltech (Australia) Pty Ltd -------------- next part -------------- A non-text attachment was scrubbed... Name: Input_file_chomp2.pl Type: application/x-perl Size: 554 bytes Desc: not available Url : http://mail.pm.org/pipermail/brisbane-pm/attachments/20070227/7e2a7089/attachment.bin From jarich at perltraining.com.au Tue Feb 27 01:24:09 2007 From: jarich at perltraining.com.au (Jacinta Richardson) Date: Tue, 27 Feb 2007 20:24:09 +1100 Subject: [Brisbane-pm] To Chomp or not to Chomp In-Reply-To: <7D49F29F-5603-4E6B-AE6B-14B6D2B82DC3@optusnet.com.au> References: <7D49F29F-5603-4E6B-AE6B-14B6D2B82DC3@optusnet.com.au> Message-ID: <45E3F8B9.6060204@perltraining.com.au> G'day Martin, I'm glad you're persevering with this, it's nice to see some life on this list. Martin Jacobs wrote: > This time, I've got a borrowed 'chomp' regex (chomp behaves in exactly > the same way). But, instead of chopping off the last character in the > string, it returns the value '1'. chomp does not behave in exactly the same way at all. chomp is much better behaved. Chomp (by default) will remove your file system's newline, which may be LF - *nix, CR-LF - Win 32, CR - Mac OS 9.... Further, you can change $/ (or $INPUT_RECORD_SEPARATOR) and have chomp adjust itself appropriately. > #!/usr/local/bin/perl > use warnings; > use strict; > > open (PCF, "PERRMOSS_Control_File.txt") or die "couldn't open the file!"; > my $file = ; > print 'Testprint line 07 $file = '."$file\n"; > $file = $file =~ s/[\r\n]+$//; > print 'Testprint line 09 $file = '."$file\n"; As Sarah has said, this only reads a single line in from your file. It then removes one or more carriage returns and line feeds (in any order) at the end of line. Once it's done that it returns the number of substitutions made (1) and puts that into $file. Oops! To fix this all you need to do is: $file =~ s/[\r\n]+$//; without the assignment. Alternatively chomp $file; is easy-to-maintain and known to be correct. If you plan to read the whole file into memory, and chomp it all then you can write: #!/usr/local/bin/perl use warnings; use strict; open (PCF, "<", "PERRMOSS_Control_File.txt") or die "couldn't open the file!"; my @file = ; print 'Testprint line 07 $file = '."$file\n"; chomp @file; print 'Testprint line 09 $file = '."$file\n"; This will read the whole file into memory (one line per array element) and chomp each line. The return value of chomp(), if you cared, would be the number of newlines removed. If eventually you find that your file contents have multiple jobs per file separated by some easily identifiable string Perl can make that easy too. For example imagine your text looks like: ... parts from previous record Catchment02.txt Catchment03.txt ---- Job Number: J2700 Job Name: Capalaba Scenario: Scenario 1 Author: Rob Ot Input Results PERRMOSS_Results_Summary.txt 24/02/1990 23:54:00 25/02/1990 01:54:30 360 1 Catchment11.txt Catchment12.txt Catchment13.txt ---- such that each record is separated by "\n----\n" then you can do the following: open(PCF, "<", "PERRMOSS_Control_File.txt") or die "couldn't open the file!"; # Change our record separator to represent end of record local $/ = "\n---\n"; while( my $record = ) { chomp $record; # removes \n---\n # process record, } Finally, please, pretty please, specify a mode when opening your files. I know that naked two argument open works, but it's a bad habit to get into due to the possible security implications. Please either use non-naked 2-arg: open (PCF, "< PERRMOSS_Control_File.txt") ^ or 3-arg open(PCF, "<", "PERRMOSS_Control_File.txt") If you want reference material on any of the above, please let me know. All the best, Jacinta -- ("`-''-/").___..--''"`-._ | Jacinta Richardson | `6_ 6 ) `-. ( ).`-.__.`) | Perl Training Australia | (_Y_.)' ._ ) `._ `. ``-..-' | +61 3 9354 6001 | _..`--'_..-_/ /--'_.' ,' | contact at perltraining.com.au | (il),-'' (li),' ((!.-' | www.perltraining.com.au | From martin_jacobs at optusnet.com.au Tue Feb 27 03:07:32 2007 From: martin_jacobs at optusnet.com.au (Martin Jacobs) Date: Tue, 27 Feb 2007 21:07:32 +1000 Subject: [Brisbane-pm] To Chomp or Not To Chomp - sorted Message-ID: <53DFA672-2F08-47D0-AA7F-36E1F00438B8@optusnet.com.au> Hi folks, Thanks Jacinta and Sarah. It should have been simple, and it was. See attached. Regards, Martin Visit my website... http://web.mac.com/martin_jacobs1 ? -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.pm.org/pipermail/brisbane-pm/attachments/20070227/a8345607/attachment.html -------------- next part -------------- A non-text attachment was scrubbed... Name: Input_file_chomp_whole_array.pl Type: text/x-perl-script Size: 257 bytes Desc: not available Url : http://mail.pm.org/pipermail/brisbane-pm/attachments/20070227/a8345607/attachment.bin -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.pm.org/pipermail/brisbane-pm/attachments/20070227/a8345607/attachment-0001.html From Sarah.Smith at trolltech.com Tue Feb 27 03:31:23 2007 From: Sarah.Smith at trolltech.com (Sarah Smith) Date: Tue, 27 Feb 2007 21:31:23 +1000 Subject: [Brisbane-pm] To Chomp or Not To Chomp - sorted In-Reply-To: <53DFA672-2F08-47D0-AA7F-36E1F00438B8@optusnet.com.au> References: <53DFA672-2F08-47D0-AA7F-36E1F00438B8@optusnet.com.au> Message-ID: <200702272131.23769.Sarah.Smith@trolltech.com> On Tuesday 27 February 2007 21:07, Martin Jacobs wrote: > Hi folks, > > Thanks Jacinta and Sarah. > > It should have been simple, and it was. See attached. > > Regards, > Martin > Visit my website... > http://web.mac.com/martin_jacobs1 > > ? Great! @lines = ; (as you have here) is perfect for your small configuration files. You mention however that you are also processing some very large files. For those you probably want to do your processing line by line (like in the example I sent before) otherwise the array assignment will read the whole thing into memory. Rgds, -- Sarah Smith BSc MACS Senior Software Engineer Ph +61 7 321 999 06 x109 Trolltech (Australia) Pty Ltd From robertl at apnic.net Tue Feb 27 04:02:31 2007 From: robertl at apnic.net (Robert Loomans) Date: Tue, 27 Feb 2007 22:02:31 +1000 Subject: [Brisbane-pm] To Chomp or not to Chomp In-Reply-To: <200702271847.59730.Sarah.Smith@trolltech.com> References: <7D49F29F-5603-4E6B-AE6B-14B6D2B82DC3@optusnet.com.au> <200702271847.59730.Sarah.Smith@trolltech.com> Message-ID: <45E41DD7.3020901@apnic.net> > When you assign to the *result of a bind* in *list context* you get back a > list of all the match capture values: Minor nit: m// and s/// differ in this respect. m// works as you describe (from the perlop man page): > m/PATTERN/cgimosx > /PATTERN/cgimosx > Searches a string for a pattern match, and in scalar context > returns true if it succeeds, false if it fails. > ... > If the "/g" option is not used, "m//" in list context returns a > list consisting of the subexpressions matched by the parenthe- > ses in the pattern, i.e., ($1, $2, $3...). (Note that here $1 > etc. are also set, and that this differs from Perl 4's behav- > ior.) When there are no parentheses in the pattern, the return > value is the list "(1)" for success. With or without parenthe- > ses, an empty list is returned upon failure. s/// *always* returns the number of matches (from the perlop man page): > s/PATTERN/REPLACEMENT/egimosx > Searches a string for a pattern, and if found, replaces that > pattern with the replacement text and returns the number of > substitutions made. Otherwise it returns false (specifically, > the empty string). Rob -- Robert Loomans Email: robertl at apnic.net Programmer/Analyst, APNIC Phone: +61 7 3858 3100 http://www.apnic.net Fax: +61 7 3858 3199 -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/x-pkcs7-signature Size: 3818 bytes Desc: S/MIME Cryptographic Signature Url : http://mail.pm.org/pipermail/brisbane-pm/attachments/20070227/5b28b726/attachment-0001.bin