From enkidu at cliffp.com Tue Nov 5 21:59:25 2002 From: enkidu at cliffp.com (Enkidu) Date: Thu Aug 5 00:24:15 2004 Subject: What's a quick and real neat way of.... Message-ID: .....extracting the abcd and the string "This is abcd" from the following: $var = "blah/blah/blah/abcd.jpg, This is abcd" ; What I've come up with so far is: $var = /.*\/(.*).jpg,(.*)$/ ; Of course, I'm going to try it out when I get a chance, but what are my chances of success? abcd varies as does the string. Cheers, Clif -- The Nats held a Party and no one came. From StephenJ at web.co.nz Tue Nov 5 22:53:17 2002 From: StephenJ at web.co.nz (Stephen Judd) Date: Thu Aug 5 00:24:15 2004 Subject: What's a quick and real neat way of.... Message-ID: <5FA042F680739D44951B00FED8BE1A7D1FD99B@dasher.webdom1.web.co.nz> Your regex as written is going to snag the leading space after the comma. What I think you want is: m{.*/(.*)\.jpg,\s(.*)$/} (I like using m{} to avoid leaning toothpick syndrome). Also, greedy matching could lead to undesitable things in $1. Possibly something like: m{.*/([^/]*)\.jpg,\s([^/]*)$/} would be better? Stephen > -----Original Message----- > From: Enkidu [mailto:enkidu@cliffp.com] > Sent: Wednesday, 6 November 2002 4:59 p.m. > To: wellington-pm-list@pm.org > Subject: What's a quick and real neat way of.... > > > .....extracting the abcd and the string "This is abcd" from the > following: > > $var = "blah/blah/blah/abcd.jpg, This is abcd" ; > > What I've come up with so far is: > > $var = /.*\/(.*).jpg,(.*)$/ ; > > Of course, I'm going to try it out when I get a chance, but what are > my chances of success? abcd varies as does the string. > > Cheers, > > Clif > -- > > The Nats held a Party and no one came. > From piers at ompa.net Wed Nov 6 00:55:54 2002 From: piers at ompa.net (Piers Harding) Date: Thu Aug 5 00:24:15 2004 Subject: What's a quick and real neat way of.... In-Reply-To: ; from enkidu@cliffp.com on Wed, Nov 06, 2002 at 04:59:25PM +1300 References: Message-ID: <20021106065554.A20455@gnu> just a little tweaking - but there is mtowtdi.... my ($abcd, $thisisabcd) = $var =~ /.*\/([^\/]*)\.jpg[,\s]+(.*)$/; Cheers. On Wed, Nov 06, 2002 at 04:59:25PM +1300, Enkidu wrote: > .....extracting the abcd and the string "This is abcd" from the > following: > > $var = "blah/blah/blah/abcd.jpg, This is abcd" ; > > What I've come up with so far is: > > $var = /.*\/(.*).jpg,(.*)$/ ; > > Of course, I'm going to try it out when I get a chance, but what are > my chances of success? abcd varies as does the string. > > Cheers, > > Clif > -- > > The Nats held a Party and no one came. From enkidu at cliffp.com Wed Nov 6 03:05:03 2002 From: enkidu at cliffp.com (Enkidu) Date: Thu Aug 5 00:24:15 2004 Subject: What's a quick and real neat way of.... In-Reply-To: <5FA042F680739D44951B00FED8BE1A7D1FD99B@dasher.webdom1.web.co.nz> References: <5FA042F680739D44951B00FED8BE1A7D1FD99B@dasher.webdom1.web.co.nz> Message-ID: OK, thanks. What does the "[]" constract do? Cheers, Cliff On Wed, 6 Nov 2002 17:53:17 +1300, you wrote: >Your regex as written is going to snag the leading space after the comma. > >What I think you want is: > >m{.*/(.*)\.jpg,\s(.*)$/} > >(I like using m{} to avoid leaning toothpick syndrome). > >Also, greedy matching could lead to undesitable things in $1. Possibly something like: > >m{.*/([^/]*)\.jpg,\s([^/]*)$/} > >would be better? > >Stephen > >> -----Original Message----- >> From: Enkidu [mailto:enkidu@cliffp.com] >> Sent: Wednesday, 6 November 2002 4:59 p.m. >> To: wellington-pm-list@pm.org >> Subject: What's a quick and real neat way of.... >> >> >> .....extracting the abcd and the string "This is abcd" from the >> following: >> >> $var = "blah/blah/blah/abcd.jpg, This is abcd" ; >> >> What I've come up with so far is: >> >> $var = /.*\/(.*).jpg,(.*)$/ ; >> >> Of course, I'm going to try it out when I get a chance, but what are >> my chances of success? abcd varies as does the string. >> >> Cheers, >> >> Clif >> -- >> >> The Nats held a Party and no one came. >> -- The Nats held a Party and no one came. From enkidu at cliffp.com Wed Nov 6 03:09:19 2002 From: enkidu at cliffp.com (Enkidu) Date: Thu Aug 5 00:24:15 2004 Subject: What's a quick and real neat way of.... In-Reply-To: <20021106065554.A20455@gnu> References: <20021106065554.A20455@gnu> Message-ID: Thanks Piers, I like the way that you avoid the use of $1, $2. I didn't know you could do that, but then I am a beginner... Cheers, Cliff On Wed, 6 Nov 2002 06:55:54 +0000, you wrote: > >just a little tweaking - but there is mtowtdi.... > > my ($abcd, $thisisabcd) = $var =~ /.*\/([^\/]*)\.jpg[,\s]+(.*)$/; > >Cheers. > >On Wed, Nov 06, 2002 at 04:59:25PM +1300, Enkidu wrote: >> .....extracting the abcd and the string "This is abcd" from the >> following: >> >> $var = "blah/blah/blah/abcd.jpg, This is abcd" ; >> >> What I've come up with so far is: >> >> $var = /.*\/(.*).jpg,(.*)$/ ; >> >> Of course, I'm going to try it out when I get a chance, but what are >> my chances of success? abcd varies as does the string. >> >> Cheers, >> >> Clif >> -- >> >> The Nats held a Party and no one came. -- The Nats held a Party and no one came. From StephenJ at web.co.nz Wed Nov 6 14:14:31 2002 From: StephenJ at web.co.nz (Stephen Judd) Date: Thu Aug 5 00:24:15 2004 Subject: What's a quick and real neat way of.... Message-ID: <5FA042F680739D44951B00FED8BE1A7D1FD99C@dasher.webdom1.web.co.nz> > -----Original Message----- > From: Enkidu [mailto:enkidu@cliffp.com] > Sent: Wednesday, 6 November 2002 10:05 p.m. > To: wellington-pm-list@pm.org > Subject: Re: What's a quick and real neat way of.... > > > OK, thanks. What does the "[]" constract do? It defines a "character class". Eg: [0123456789] matches any digit. You could think of it as (0|1|2|3|4|5|6|7|8|9). [clif] matches c, f, i or l. You can append a quantifier like * or + just as you can with any other character. A caret at the beginning of a character class negates the whole thing. Thus: [^abcd] will not match a, b, c or d. Stephen From rhector at actrix.gen.nz Fri Nov 8 03:00:56 2002 From: rhector at actrix.gen.nz (Richard Hector) Date: Thu Aug 5 00:24:15 2004 Subject: undef Message-ID: <1036746056.1059.3.camel@diamond> How do I detect that a function call has returned undef? Some functions seem to return zero or another number as a valid result, and undef to indicate failure. But if I try to compare it with anything, it complains of using an uninitialised value, or something like that. Unless it's some other bug in my code ... Thanks, Richard From piers at ompa.net Fri Nov 8 03:46:33 2002 From: piers at ompa.net (Piers Harding) Date: Thu Aug 5 00:24:15 2004 Subject: undef In-Reply-To: <1036746056.1059.3.camel@diamond>; from rhector@actrix.gen.nz on Fri, Nov 08, 2002 at 10:00:56PM +1300 References: <1036746056.1059.3.camel@diamond> Message-ID: <20021108094633.A19348@gnu> Wont this do the trick? if (! defined(some_func()){ .... Cheers. On Fri, Nov 08, 2002 at 10:00:56PM +1300, Richard Hector wrote: > How do I detect that a function call has returned undef? > > Some functions seem to return zero or another number as a valid result, > and undef to indicate failure. But if I try to compare it with anything, > it complains of using an uninitialised value, or something like that. > > Unless it's some other bug in my code ... > > Thanks, > > Richard From rhector at actrix.gen.nz Fri Nov 8 03:51:51 2002 From: rhector at actrix.gen.nz (Richard Hector) Date: Thu Aug 5 00:24:15 2004 Subject: undef In-Reply-To: <20021108094633.A19348@gnu> References: <1036746056.1059.3.camel@diamond> <20021108094633.A19348@gnu> Message-ID: <1036749112.1407.6.camel@diamond> On Fri, 2002-11-08 at 22:46, Piers Harding wrote: > > On Fri, Nov 08, 2002 at 10:00:56PM +1300, Richard Hector wrote: > > How do I detect that a function call has returned undef? > > Wont this do the trick? > > if (! defined(some_func()){ > .... Ah, yes, thanks. I was looking under undef; didn't think of defined :-) I guess I can just as happily do $result = some_func() if (! defined($result)){ .... Or possibly even if (! defined($result = somefunc())){ ... Or do perl assignments not have C-style side-effects? Richard From piers at ompa.net Fri Nov 8 04:16:47 2002 From: piers at ompa.net (Piers Harding) Date: Thu Aug 5 00:24:15 2004 Subject: undef In-Reply-To: <1036749112.1407.6.camel@diamond>; from rhector@actrix.gen.nz on Fri, Nov 08, 2002 at 10:51:51PM +1300 References: <1036746056.1059.3.camel@diamond> <20021108094633.A19348@gnu> <1036749112.1407.6.camel@diamond> Message-ID: <20021108101647.A19580@gnu> Both will do. CHeers. On Fri, Nov 08, 2002 at 10:51:51PM +1300, Richard Hector wrote: > On Fri, 2002-11-08 at 22:46, Piers Harding wrote: > > > > On Fri, Nov 08, 2002 at 10:00:56PM +1300, Richard Hector wrote: > > > How do I detect that a function call has returned undef? > > > > Wont this do the trick? > > > > if (! defined(some_func()){ > > .... > > Ah, yes, thanks. I was looking under undef; didn't think of defined :-) > > I guess I can just as happily do > > $result = some_func() > > if (! defined($result)){ > .... > > Or possibly even > > if (! defined($result = somefunc())){ > ... > > Or do perl assignments not have C-style side-effects? > > Richard > From enkidu at cliffp.com Thu Nov 14 04:06:14 2002 From: enkidu at cliffp.com (Enkidu) Date: Thu Aug 5 00:24:15 2004 Subject: Here's another "What's a quick and real neat way of...." type question In-Reply-To: <5FA042F680739D44951B00FED8BE1A7D1FD99C@dasher.webdom1.web.co.nz> References: <5FA042F680739D44951B00FED8BE1A7D1FD99C@dasher.webdom1.web.co.nz> Message-ID: <3vs6tuodg7cbkfm9hbhr3o3i2qqek7pn6n@4ax.com> Say you have two arrays @a and @b. You can loop through one array by using foreach: for my $file (@a) { ; } Is there a neat way of looping through *both arrays* at the same time? Something like: for my ($file, $desc) (@a, @b) { ; } Cheers, Cliff -- The Nats held a Party and no one came. From piers at ompa.net Thu Nov 14 04:46:19 2002 From: piers at ompa.net (Piers Harding) Date: Thu Aug 5 00:24:15 2004 Subject: Here's another "What's a quick and real neat way of...." type question In-Reply-To: <3vs6tuodg7cbkfm9hbhr3o3i2qqek7pn6n@4ax.com>; from enkidu@cliffp.com on Thu, Nov 14, 2002 at 11:06:14PM +1300 References: <5FA042F680739D44951B00FED8BE1A7D1FD99C@dasher.webdom1.web.co.nz> <3vs6tuodg7cbkfm9hbhr3o3i2qqek7pn6n@4ax.com> Message-ID: <20021114104619.C14838@gnu> how about this: while (my ($a, $b) = (shift @a, shift @b)){ do the funky thing with $a and $b .... } Cheers. On Thu, Nov 14, 2002 at 11:06:14PM +1300, Enkidu wrote: > Say you have two arrays @a and @b. > > You can loop through one array by using foreach: > > for my $file (@a) { > ; > } > > Is there a neat way of looping through *both arrays* at the same time? > Something like: > > for my ($file, $desc) (@a, @b) { > ; > } > > Cheers, > > Cliff > -- > > The Nats held a Party and no one came. From Grantm at web.co.nz Thu Nov 14 14:40:56 2002 From: Grantm at web.co.nz (Grant McLean) Date: Thu Aug 5 00:24:15 2004 Subject: Here's another "What's a quick and real neat way of...." type question Message-ID: <5FA042F680739D44951B00FED8BE1A7D05DBF8@dasher.webdom1.web.co.nz> Piers Harding wrote: > On Thu, Nov 14, 2002 at 11:06:14PM +1300, Enkidu wrote: > > Is there a neat way of looping through *both arrays* at > > the same time? > > how about this: > > while (my ($a, $b) = (shift @a, shift @b)){ > > do the funky thing with $a and $b .... > > } Interesting suggestion, I wouldn't have expected that to work, since when @a and @b are empty, the right hand side of the expression (shift @a, shift @b) evaluates to (undef, undef) which is a two element list which in boolean terms is 'true', so the while loop should never exit. My curiosity was piqued, so I tried it. The bad news is it doesn't work :-( The good news is I was right ;-/ One approach is to add a line to explicitly break out of the loop when the arrays are empty: while (my ($a, $b) = (shift @a, shift @b)){ # do the funky thing with $a and $b .... last unless(@a); } At first, I made the mistake of adding this check as the first line of the loop. This meant the loop skipped the last element of each array since when the last element was successfully shifted off, there was nothing left in the array. So, the test needs to go either at the end of the loop. (I also tried putting it in a continue block but it didn't work - I guess 'last' won't break out of the main block when you call it from another block). It is possible to combine the test with the assignment in such a way that the right hand side evaluates to an empty list when the arrays are empty: while(my($a, $b) = (@a ? (shift @a, shift @b) : ()) ){ # do the funky thing with $a and $b .... } Anyone have a more elegant solution? Grant PS: I'm assuming @a and @b are the same length. =============================================================== Grant McLean BearingPoint Inc - formerly The Web Limited +64 4 495 9026 Level 6, 20 Customhouse Quay, Box 1195 gmclean@bearingpoint.biz Wellington, New Zealand From shaunm at web.co.nz Thu Nov 14 15:03:55 2002 From: shaunm at web.co.nz (Shaun McCarthy) Date: Thu Aug 5 00:24:15 2004 Subject: Here's another "What's a quick and real neat way of...." type question Message-ID: <5FA042F680739D44951B00FED8BE1A7D06A090@dasher.webdom1.web.co.nz> I think that perl has C side effects, so (my($a, $b) = (shift @a, shift @b)) will return the array assigned to the if statement, so if you go: (my($a, $b) = (shift @a, shift @b))[0] you will get the value assigned to a, which will be undef when they arrays runs out (assuming the same length thing), which equates to false. so: while ((my($a,$b) = (shift @a, shift @b))[0]) { } should do the trick... Unfortunately I am off site and don't have access to a perl instance, but I think it should work quite well. A comment above the while loop will help who ever comes across it next understand it though :P Shaun -----Original Message----- From: Grant McLean Sent: Fri 15/11/2002 7:40 a.m. To: Piers Harding; Enkidu Cc: wellington-pm-list@pm.org Subject: RE: Here's another "What's a quick and real neat way of...." type question Piers Harding wrote: > On Thu, Nov 14, 2002 at 11:06:14PM +1300, Enkidu wrote: > > Is there a neat way of looping through *both arrays* at > > the same time? > > how about this: > > while (my ($a, $b) = (shift @a, shift @b)){ > > do the funky thing with $a and $b .... > > } Interesting suggestion, I wouldn't have expected that to work, since when @a and @b are empty, the right hand side of the expression (shift @a, shift @b) evaluates to (undef, undef) which is a two element list which in boolean terms is 'true', so the while loop should never exit. My curiosity was piqued, so I tried it. The bad news is it doesn't work :-( The good news is I was right ;-/ One approach is to add a line to explicitly break out of the loop when the arrays are empty: while (my ($a, $b) = (shift @a, shift @b)){ # do the funky thing with $a and $b .... last unless(@a); } At first, I made the mistake of adding this check as the first line of the loop. This meant the loop skipped the last element of each array since when the last element was successfully shifted off, there was nothing left in the array. So, the test needs to go either at the end of the loop. (I also tried putting it in a continue block but it didn't work - I guess 'last' won't break out of the main block when you call it from another block). It is possible to combine the test with the assignment in such a way that the right hand side evaluates to an empty list when the arrays are empty: while(my($a, $b) = (@a ? (shift @a, shift @b) : ()) ){ # do the funky thing with $a and $b .... } Anyone have a more elegant solution? Grant PS: I'm assuming @a and @b are the same length. =============================================================== Grant McLean BearingPoint Inc - formerly The Web Limited +64 4 495 9026 Level 6, 20 Customhouse Quay, Box 1195 gmclean@bearingpoint.biz Wellington, New Zealand From Grantm at web.co.nz Thu Nov 14 15:07:29 2002 From: Grantm at web.co.nz (Grant McLean) Date: Thu Aug 5 00:24:15 2004 Subject: Here's another "What's a quick and real neat way of...." type question Message-ID: <5FA042F680739D44951B00FED8BE1A7D05DF34@dasher.webdom1.web.co.nz> Shaun McCarthy wrote: > so if you go: (my($a, $b) = (shift @a, shift @b))[0] you > will get the value assigned to a, which will be undef when > they arrays runs out (assuming the same length thing), which > equates to false. Which could be quite a cool trick assuming the arrays could never contain undef, or 0, or '0', or ''. Grant =============================================================== Grant McLean BearingPoint Inc - formerly The Web Limited +64 4 495 9026 Level 6, 20 Customhouse Quay, Box 1195 gmclean@bearingpoint.biz Wellington, New Zealand From douglas at katipo.co.nz Thu Nov 14 15:21:29 2002 From: douglas at katipo.co.nz (Douglas Bagnall) Date: Thu Aug 5 00:24:15 2004 Subject: Here's another "What's a quick and real neat way of...." type question References: <5FA042F680739D44951B00FED8BE1A7D05DBF8@dasher.webdom1.web.co.nz> Message-ID: <3DD413D9.3020702@katipo.co.nz> Grant McLean wrote: > > Anyone have a more elegant solution? > use python. for c,d in zip(a,b): #do stuff zip is coming in perl 6 I believe. douglas From shaunm at web.co.nz Thu Nov 14 15:32:03 2002 From: shaunm at web.co.nz (Shaun McCarthy) Date: Thu Aug 5 00:24:15 2004 Subject: Here's another "What's a quick and real neat way of...." type question Message-ID: <5FA042F680739D44951B00FED8BE1A7D06A091@dasher.webdom1.web.co.nz> Good point - you can get around the 0, '0', '' with undef(my($a, $b) = (shift @a, shift @b))[0]) but yeah having an undef in an array will be bad... In which case I think: while (@a && my($a, $b) = (shift @a, shift @b)) { } is prolly slightly better as it is easier to read than while(my($a, $b) = (@a ? (shift @a, shift @b) : ()) ){ } And to get rid of the equal length assumption: while (@a && @b && my($a, $b) = (shift @a, shift @b)) { } which will end as soon as one of the arrays is finished... Shaun -----Original Message----- From: Grant McLean Sent: Fri 15/11/2002 8:07 a.m. To: Shaun McCarthy; Piers Harding; Enkidu Cc: wellington-pm-list@pm.org Subject: RE: Here's another "What's a quick and real neat way of...." type question Shaun McCarthy wrote: > so if you go: (my($a, $b) = (shift @a, shift @b))[0] you > will get the value assigned to a, which will be undef when > they arrays runs out (assuming the same length thing), which > equates to false. Which could be quite a cool trick assuming the arrays could never contain undef, or 0, or '0', or ''. Grant =============================================================== Grant McLean BearingPoint Inc - formerly The Web Limited +64 4 495 9026 Level 6, 20 Customhouse Quay, Box 1195 gmclean@bearingpoint.biz Wellington, New Zealand From worik at noggon.co.nz Thu Nov 14 15:47:06 2002 From: worik at noggon.co.nz (Worik) Date: Thu Aug 5 00:24:15 2004 Subject: Here's another "What's a quick and real neat way of...." type question In-Reply-To: <20021114104619.C14838@gnu> References: <5FA042F680739D44951B00FED8BE1A7D1FD99C@dasher.webdom1.web.co.nz> <3vs6tuodg7cbkfm9hbhr3o3i2qqek7pn6n@4ax.com> <20021114104619.C14838@gnu> Message-ID: <1037310426.19357.119.camel@stolberg> On Thu, 2002-11-14 at 23:46, Piers Harding wrote: > > how about this: > > while (my ($a, $b) = (shift @a, shift @b)){ > > do the funky thing with $a and $b .... > > } > > Cheers. The problen is that the loop never finishes. I implemented this and tested it (I was supprised it was an infinite loop). Check this out... if((undef, undef)){ print "Dual undef is true\n"; } if(my($a, $b) = (undef, undef)){ print "Dual undef assignment is true\n"; } The first one fails the second one succeeds.... My solution is to not get too cute. #!/usr/bin/perl -w use strict; my @a = qw(a b c d e f g); my @b = qw(1 2 3 4 5 6 7 8); my $max = $#a < $#b ? $#a : $#b; for my $i (0..$max){ print "\$a $a[$i]\t\$b\t$b[$i]\n"; } Worik > > > On Thu, Nov 14, 2002 at 11:06:14PM +1300, Enkidu wrote: > > Say you have two arrays @a and @b. > > > > You can loop through one array by using foreach: > > > > for my $file (@a) { > > ; > > } > > > > Is there a neat way of looping through *both arrays* at the same time? > > Something like: > > > > for my ($file, $desc) (@a, @b) { > > ; > > } > > > > Cheers, > > > > Cliff > > -- > > > > The Nats held a Party and no one came. > From ewen at naos.co.nz Thu Nov 14 16:25:09 2002 From: ewen at naos.co.nz (Ewen McNeill) Date: Thu Aug 5 00:24:15 2004 Subject: Here's another "What's a quick and real neat way of...." type question In-Reply-To: Message from "Shaun McCarthy" of "Fri, 15 Nov 2002 10:32:03 +1300." <5FA042F680739D44951B00FED8BE1A7D06A091@dasher.webdom1.web.co.nz> Message-ID: <20021114222509.5867DADFC6@basilica.la.naos.co.nz> In message <5FA042F680739D44951B00FED8BE1A7D06A091@dasher.webdom1.web.co.nz>, "S haun McCarthy" writes: >In which case I think: > >while (@a && my($a, $b) = (shift @a, shift @b)) { >} my $len = ((scalar @a) <= (scalar @a) ? (scalar @a) : (scalar @b)); for (my $i = 0; $i < $len; ++$i) { my ($a, $b) = (@a[$i], @b[$i]); } or if you're willing to destroy @a and @b in the process (it seems everyone is): while ((scalar @a) > 0 && (scalar @b) > 0) { my ($a, $b) = (shift @a, shift @b); } (This second one will be expensive if scalar(@array) is O(n); ISTR that perl uses an array structure that means that scalar(@array) is O(1).) Just because you can somehow cram everything onto one line doesn't mean that you _have_ to do so :-) But if you feel you really must... while ((scalar @a) > 0 && (scalar @b) > 0 && (($a, $b) = (shift @a,shift @b))) { # body goes here } And so I don't get left out of the "bizzare ways to do this" competition: @c = map { print "$a[$_], $b[$_]\n" } (0..((scalar @a)-1)); Ewen From Grantm at web.co.nz Thu Nov 14 16:25:03 2002 From: Grantm at web.co.nz (Grant McLean) Date: Thu Aug 5 00:24:15 2004 Subject: Here's another "What's a quick and real neat way of...." type question Message-ID: <5FA042F680739D44951B00FED8BE1A7D05DBFA@dasher.webdom1.web.co.nz> > -----Original Message----- Shaun McCarthy wrote: > while (@a && my($a, $b) = (shift @a, shift @b)) { > } Actually, you need to use either the lower priority 'and': while (@a and my($a, $b) = (shift @a, shift @b)) { } or use parentheses to stop the && binding to the my($a, $b) and causing the remainder of the line to be a syntax error ("assignment to a logical &&"). Grant =============================================================== Grant McLean BearingPoint Inc - formerly The Web Limited +64 4 495 9026 Level 6, 20 Customhouse Quay, Box 1195 gmclean@bearingpoint.biz Wellington, New Zealand From shaunm at web.co.nz Thu Nov 14 16:28:40 2002 From: shaunm at web.co.nz (Shaun McCarthy) Date: Thu Aug 5 00:24:15 2004 Subject: Here's another "What's a quick and real neat way of...." type question Message-ID: <5FA042F680739D44951B00FED8BE1A7D06A093@dasher.webdom1.web.co.nz> yup :) Or ()'s around the assignment... Shaun -----Original Message----- From: Grant McLean Sent: Fri 15/11/2002 9:25 a.m. To: Shaun McCarthy Cc: wellington-pm-list@pm.org Subject: RE: Here's another "What's a quick and real neat way of...." type question > -----Original Message----- Shaun McCarthy wrote: > while (@a && my($a, $b) = (shift @a, shift @b)) { > } Actually, you need to use either the lower priority 'and': while (@a and my($a, $b) = (shift @a, shift @b)) { } or use parentheses to stop the && binding to the my($a, $b) and causing the remainder of the line to be a syntax error ("assignment to a logical &&"). Grant =============================================================== Grant McLean BearingPoint Inc - formerly The Web Limited +64 4 495 9026 Level 6, 20 Customhouse Quay, Box 1195 gmclean@bearingpoint.biz Wellington, New Zealand From Grantm at web.co.nz Thu Nov 14 16:34:20 2002 From: Grantm at web.co.nz (Grant McLean) Date: Thu Aug 5 00:24:15 2004 Subject: Here's another "What's a quick and real neat way of...." type question Message-ID: <5FA042F680739D44951B00FED8BE1A7D05DF36@dasher.webdom1.web.co.nz> Ewen McNeill wrote" > In message > <5FA042F680739D44951B00FED8BE1A7D06A091@dasher.webdom1.web.co.nz>, "S > haun McCarthy" writes: > >In which case I think: > > > >while (@a && my($a, $b) = (shift @a, shift @b)) { > >} > > my $len = ((scalar @a) <= (scalar @a) ? (scalar @a) : (scalar @b)); > for (my $i = 0; $i < $len; ++$i) > { > my ($a, $b) = (@a[$i], @b[$i]); > } I absolutely agree that this is the way I would do it in 'real life' (tm). That teensy little side affect of both arrays being destroyed would usually be a problem. I'd think twice before using @a and $a in such close proximity. An argument could be made that it is actually clearer in this case. > while ((scalar @a) > 0 && (scalar @b) > 0) > { > my ($a, $b) = (shift @a, shift @b); > } you can avoid using the 'scalar' function by simply using its arguments in a scalar or a boolean context: while (@a > 0 and @b > 0) { or more simply while (@a and @b) { Although in this case 'or' might be better than 'and'. Regards Grant =============================================================== Grant McLean BearingPoint Inc - formerly The Web Limited +64 4 495 9026 Level 6, 20 Customhouse Quay, Box 1195 gmclean@bearingpoint.biz Wellington, New Zealand From piers at ompa.net Thu Nov 14 23:33:24 2002 From: piers at ompa.net (Piers Harding) Date: Thu Aug 5 00:24:15 2004 Subject: Here's another "What's a quick and real neat way of...." type question In-Reply-To: <5FA042F680739D44951B00FED8BE1A7D05DBF8@dasher.webdom1.web.co.nz>; from Grantm@web.co.nz on Fri, Nov 15, 2002 at 09:40:56AM +1300 References: <5FA042F680739D44951B00FED8BE1A7D05DBF8@dasher.webdom1.web.co.nz> Message-ID: <20021115053324.A23206@gnu> Excellent - I wondered if there was atrap in it, because I just rattled it off the top of my so to speak. Cool. On Fri, Nov 15, 2002 at 09:40:56AM +1300, Grant McLean wrote: > Piers Harding wrote: > > On Thu, Nov 14, 2002 at 11:06:14PM +1300, Enkidu wrote: > > > Is there a neat way of looping through *both arrays* at > > > the same time? > > > > how about this: > > > > while (my ($a, $b) = (shift @a, shift @b)){ > > > > do the funky thing with $a and $b .... > > > > } > > Interesting suggestion, I wouldn't have expected that to > work, since when @a and @b are empty, the right hand > side of the expression (shift @a, shift @b) evaluates to > (undef, undef) which is a two element list which in boolean > terms is 'true', so the while loop should never exit. > > My curiosity was piqued, so I tried it. The bad news is it > doesn't work :-( The good news is I was right ;-/ > > One approach is to add a line to explicitly break out of > the loop when the arrays are empty: > > while (my ($a, $b) = (shift @a, shift @b)){ > # do the funky thing with $a and $b .... > last unless(@a); > } > > At first, I made the mistake of adding this check as the > first line of the loop. This meant the loop skipped the > last element of each array since when the last element was > successfully shifted off, there was nothing left in the > array. So, the test needs to go either at the end of the > loop. (I also tried putting it in a continue block but it > didn't work - I guess 'last' won't break out of the main > block when you call it from another block). > > It is possible to combine the test with the assignment in > such a way that the right hand side evaluates to an empty > list when the arrays are empty: > > while(my($a, $b) = (@a ? (shift @a, shift @b) : ()) ){ > # do the funky thing with $a and $b .... > } > > Anyone have a more elegant solution? > > Grant > > PS: I'm assuming @a and @b are the same length. > > > > =============================================================== > Grant McLean BearingPoint Inc - formerly The Web Limited > +64 4 495 9026 Level 6, 20 Customhouse Quay, Box 1195 > gmclean@bearingpoint.biz Wellington, New Zealand > From piers at ompa.net Thu Nov 14 23:47:24 2002 From: piers at ompa.net (Piers Harding) Date: Thu Aug 5 00:24:15 2004 Subject: Here's another "What's a quick and real neat way of...." type question In-Reply-To: <5FA042F680739D44951B00FED8BE1A7D05DF36@dasher.webdom1.web.co.nz>; from Grantm@web.co.nz on Fri, Nov 15, 2002 at 11:34:20AM +1300 References: <5FA042F680739D44951B00FED8BE1A7D05DF36@dasher.webdom1.web.co.nz> Message-ID: <20021115054724.B23206@gnu> Well I'm impressed. The nicest thing about all this, is it is the most traffic on the list in ages :-) Cheers. On Fri, Nov 15, 2002 at 11:34:20AM +1300, Grant McLean wrote: > Ewen McNeill wrote" > > In message > > <5FA042F680739D44951B00FED8BE1A7D06A091@dasher.webdom1.web.co.nz>, "S > > haun McCarthy" writes: > > >In which case I think: > > > > > >while (@a && my($a, $b) = (shift @a, shift @b)) { > > >} > > > > my $len = ((scalar @a) <= (scalar @a) ? (scalar @a) : (scalar @b)); > > for (my $i = 0; $i < $len; ++$i) > > { > > my ($a, $b) = (@a[$i], @b[$i]); > > } > > I absolutely agree that this is the way I would do it in > 'real life' (tm). That teensy little side affect of both > arrays being destroyed would usually be a problem. > > I'd think twice before using @a and $a in such close > proximity. An argument could be made that it is actually > clearer in this case. > > > while ((scalar @a) > 0 && (scalar @b) > 0) > > { > > my ($a, $b) = (shift @a, shift @b); > > } > > you can avoid using the 'scalar' function by simply using > its arguments in a scalar or a boolean context: > > while (@a > 0 and @b > 0) { > > or more simply > > while (@a and @b) { > > Although in this case 'or' might be better than 'and'. > > Regards > Grant > > =============================================================== > Grant McLean BearingPoint Inc - formerly The Web Limited > +64 4 495 9026 Level 6, 20 Customhouse Quay, Box 1195 > gmclean@bearingpoint.biz Wellington, New Zealand From Grantm at web.co.nz Sun Nov 17 14:28:26 2002 From: Grantm at web.co.nz (Grant McLean) Date: Thu Aug 5 00:24:15 2004 Subject: Here's another "What's a quick and real neat way of...." type question Message-ID: <5FA042F680739D44951B00FED8BE1A7D05DBFC@dasher.webdom1.web.co.nz> Hi Piers I note that you've released a module allowing access to GNOME VFS from Perl. Is there any possibility that this will develop in the opposite direction; ie: allow the development of a VFS driver in Perl that is accessible from any process on the box? On my GNOME desktop, I use Nautilus to access man and info pages with URIs like man:ls or info:cvs. I'd like to extend this to support perldoc:... URIs. Regards Grant =============================================================== Grant McLean BearingPoint Inc - formerly The Web Limited +64 4 495 9026 Level 6, 20 Customhouse Quay, Box 1195 gmclean@bearingpoint.biz Wellington, New Zealand From piers at ompa.net Sun Nov 17 14:48:05 2002 From: piers at ompa.net (Piers Harding) Date: Thu Aug 5 00:24:15 2004 Subject: Here's another "What's a quick and real neat way of...." type question In-Reply-To: <5FA042F680739D44951B00FED8BE1A7D05DBFC@dasher.webdom1.web.co.nz>; from Grantm@web.co.nz on Mon, Nov 18, 2002 at 09:28:26AM +1300 References: <5FA042F680739D44951B00FED8BE1A7D05DBFC@dasher.webdom1.web.co.nz> Message-ID: <20021117204805.A1250@gnu> Hmmm - that is an interesting thought! creating an embedded perl module as a plugin for gnome-vfs. There is only one downside to that, and that is that you would have to compile the gnome-vfs library for your desktop to make it work for you ( and your particular Perl installation ). But - imagine - not just things like perldoc: but what about dbi: - the mind boggles! Cheers. On Mon, Nov 18, 2002 at 09:28:26AM +1300, Grant McLean wrote: > Hi Piers > > I note that you've released a module allowing access to > GNOME VFS from Perl. Is there any possibility that this > will develop in the opposite direction; ie: allow the > development of a VFS driver in Perl that is accessible > from any process on the box? > > On my GNOME desktop, I use Nautilus to access man and info > pages with URIs like man:ls or info:cvs. I'd like to > extend this to support perldoc:... URIs. > > Regards > Grant > > =============================================================== > Grant McLean BearingPoint Inc - formerly The Web Limited > +64 4 495 9026 Level 6, 20 Customhouse Quay, Box 1195 > gmclean@bearingpoint.biz Wellington, New Zealand From Grantm at web.co.nz Wed Nov 20 15:38:57 2002 From: Grantm at web.co.nz (Grant McLean) Date: Thu Aug 5 00:24:15 2004 Subject: Any contractors looking for work? Message-ID: <5FA042F680739D44951B00FED8BE1A7D05DBFF@dasher.webdom1.web.co.nz> I've had an enquiry through the contact address for Perl Mongers in Wellington relating to this ad: http://jobs.perl.org/job/526 It's a US company that gets Perl development work done in Lithuania. They are looking for someone in NZ or Australia to do both development and project support, dealing with US-based clients. From talking to the guy, they're looking to engage someone on a monthly rather than hourly basis. It's unlikely to be a goldmine but the steady income stream could be an advantage. Contact: Mark@dwebsite.com Cheers Grant =============================================================== Grant McLean BearingPoint Inc - formerly The Web Limited +64 4 495 9026 Level 6, 20 Customhouse Quay, Box 1195 gmclean@bearingpoint.biz Wellington, New Zealand From enkidu at cliffp.com Sat Nov 23 16:56:06 2002 From: enkidu at cliffp.com (Enkidu) Date: Thu Aug 5 00:24:15 2004 Subject: CPAN - how to tidy it up. Message-ID: Are there any CPAN experts out there? CPAN seems to leave heaps of stuff in .cpan, and I'd like to tidy it up a bit to release some space. How does one go about doing that? Cheers, Cliff -- The Nats held a Party and no one came. From piers at ompa.net Sun Nov 24 01:30:18 2002 From: piers at ompa.net (Piers Harding) Date: Thu Aug 5 00:24:15 2004 Subject: CPAN - how to tidy it up. In-Reply-To: ; from enkidu@cliffp.com on Sun, Nov 24, 2002 at 11:56:06AM +1300 References: Message-ID: <20021124073018.C15493@gnu> You can modify your build_cache size ( default 10 ), using "o conf build_cache blah" and "o conf commit" - should set it. There is probably no harm in whacking the contents of the build and sources direcotries, if you want to do it immediately. Cheers. On Sun, Nov 24, 2002 at 11:56:06AM +1300, Enkidu wrote: > Are there any CPAN experts out there? > > CPAN seems to leave heaps of stuff in .cpan, and I'd like to tidy it > up a bit to release some space. How does one go about doing that? > > Cheers, > > Cliff > -- > > The Nats held a Party and no one came. From enkidu at cliffp.com Sun Nov 24 01:35:47 2002 From: enkidu at cliffp.com (Enkidu) Date: Thu Aug 5 00:24:15 2004 Subject: CPAN - how to tidy it up. In-Reply-To: <20021124073018.C15493@gnu> References: <20021124073018.C15493@gnu> Message-ID: <2801uu0oo9iv9f11a4tp6o8iirgrs864se@4ax.com> Thanks Piers. Hm, yeah I was considering blatting the build and sources but I wasn't sure of the implications. Cheers, Cliff On Sun, 24 Nov 2002 07:30:18 +0000, you wrote: > >You can modify your build_cache size ( default 10 ), using "o conf >build_cache blah" and "o conf commit" - should set it. > >There is probably no harm in whacking the contents of the build and >sources direcotries, if you want to do it immediately. > >Cheers. > >On Sun, Nov 24, 2002 at 11:56:06AM +1300, Enkidu wrote: >> Are there any CPAN experts out there? >> >> CPAN seems to leave heaps of stuff in .cpan, and I'd like to tidy it >> up a bit to release some space. How does one go about doing that? >> >> Cheers, >> >> Cliff -- The Nats held a Party and no one came.