From tyler.slijboom at gmail.com Mon Feb 7 09:50:41 2011 From: tyler.slijboom at gmail.com (Tyler Slijboom) Date: Mon, 7 Feb 2011 12:50:41 -0500 Subject: [kw-pm] What resources will we have available to us Feb. 17? Message-ID: I am preparing sample code and a Open Office Impress power point presentation on my laptop. Will a projector be available? -- Sincerely, Tyler Slijboom -------------- next part -------------- An HTML attachment was scrubbed... URL: From roberthpike at yahoo.com Wed Feb 9 08:02:57 2011 From: roberthpike at yahoo.com (Robert Pike) Date: Wed, 9 Feb 2011 08:02:57 -0800 (PST) Subject: [kw-pm] Seeding srand Message-ID: <657431.51672.qm@web120514.mail.ne1.yahoo.com> Trying to get a good seed value for an app I'm working on. The app will be running on both windows and linux. The rand function will only be looking at numbers between 0 and 3 (inclusive). Right now I'm using time ^ $$. The funny thing is when I run on one server the results skew "greatly" towards the extremes (i.e. 0 or 3 - slighly more than 75% of the random numbers generated are 0 or 3). On another server the number 3 has never gotten hit after over 200 trial runs. Both servers are Windows machines. Appreciate any feedback anyone can give. Thanks. From max at alleged.net Wed Feb 9 08:07:01 2011 From: max at alleged.net (Max) Date: Wed, 09 Feb 2011 11:07:01 -0500 Subject: [kw-pm] Seeding srand In-Reply-To: <657431.51672.qm@web120514.mail.ne1.yahoo.com> References: <657431.51672.qm@web120514.mail.ne1.yahoo.com> Message-ID: <4D52BBA5.6000907@alleged.net> Changing the seed won't really affect the output distribution. That would seem to be a limitation in rand(). On 2/9/2011 11:02 AM, Robert Pike wrote: > Trying to get a good seed value for an app I'm working on. The app will be running on both windows and linux. The rand function will only be looking at numbers between 0 and 3 (inclusive). > Right now I'm using time ^ $$. The funny thing is when I run on one server the results skew "greatly" towards the extremes (i.e. 0 or 3 - slighly more than 75% of the random numbers generated are 0 or 3). On another server the number 3 has never gotten hit after over 200 trial runs. Both servers are Windows machines. > Appreciate any feedback anyone can give. Thanks. > > > _______________________________________________ > kw-pm mailing list > kw-pm at pm.org > http://mail.pm.org/mailman/listinfo/kw-pm From abram.hindle at softwareprocess.es Wed Feb 9 09:38:00 2011 From: abram.hindle at softwareprocess.es (Abram Hindle) Date: Wed, 09 Feb 2011 09:38:00 -0800 Subject: [kw-pm] Seeding srand In-Reply-To: <4D52BBA5.6000907@alleged.net> (sfid-20110209_111907_580741_FA681D18) References: <657431.51672.qm@web120514.mail.ne1.yahoo.com> <4D52BBA5.6000907@alleged.net> (sfid-20110209_111907_580741_FA681D18) Message-ID: <4D52D0F8.1000505@softwareprocess.es> On 02/09/2011 08:07 AM, Max wrote: > Changing the seed won't really affect the output distribution. That > would seem to be a limitation in rand(). IMHO, the problem here is that you are xoring a large 32bit value by a small 16 bit value. So you're reducing the likely seeds rather than creating more varied seeds. Check out these plots of likely seeds: time() ^ $$ http://softwareprocess.es/z/hist-time-xor-pid.pdf http://softwareprocess.es/z/plot-time-xor-pid.pdf ( that pattern should bother you) time() * $$ http://softwareprocess.es/z/hist-time-mult-pid.pdf http://softwareprocess.es/z/plot-time-mult-pid.pdf ( that pattern should give you a little more confidence ) Note how the histogram table for the 2nd one is spread across many values, while the xor concentrates into certain buckets. This means many of the srand bits are the same and some of the values are the same. The limitation here is how often one calls srand and how many calls calls to rand you make. $$ doesn't have great range and is probably very deterministic. If you call this script many times in the same seconds the distribution of the pids. I'd argue that you are reducing the likely seeds by xoring by the pid. XOR is not a good operation for this, it doesn't have any magic to it either. If you look at naive random functions they usually use something like multiplies and shifts to distribute the bits about. Generate the table: perl -e '$start=1297271306;$pid=$$;for($start..($start+3600)){ print $_^$pid," ",0xFFFFFFFF & $_*$pid,$/; $pid++; }' > k Using R: v <- read.table("k") v$Xor <- v$V1 v$Mult <- v$V2 plot(v$Xor,v$Mult) plot(v$Xor) plot(v$Mult) pdf("plot-time-xor-pid.pdf") plot(v$Xor) dev.off() pdf("plot-time-mult-pid.pdf") plot(v$Mult) dev.off() pdf("hist-time-mult-pid.pdf") hist(v$Mult) dev.off() pdf("hist-time-xor-pid.pdf") hist(v$Xor) dev.off() > stem(v$V1) The decimal point is 3 digit(s) to the right of the | 1297257 | 11111111111111111111111111111111111111111111111111111111111111111111+407 1297258 | 00000000000000000000000001111111111111111111111111111111111111111111+294 1297259 | 1297260 | 1297261 | 1297262 | 1297263 | 1297264 | 00000000000000000000000000000000000000000000000000000000000000000000+585 1297265 | 33333333333333333333333333333333333333333333333333333333333333333333+665 1297266 | 00000000000000000000000000000000000000000000000000000000000000000000+585 1297267 | 1297268 | 11111111111111111111111111111111111111111111111111111111111111111111+585 > stem(v$V2) The decimal point is 8 digit(s) to the right of the | 0 | 00011111111122222222333333334444444445555555556666666677777777788888+83 2 | 00000000001111111222222223333333344444444455555555566666666777777788+88 4 | 00000000011111122222222333333333344444444455555555666666667777777788+88 6 | 00000000111111112222222233333333344444444455555555666666677777777788+88 8 | 00000001111111122222222233333333344444444555555556666666677777777788+87 10 | 00000000011111111222222222333333333444444555555556666666667777777778+88 12 | 00000000111111112222222223333333344444444555555556666666667777777778+87 14 | 00000000111111111122222222233333334444444455555555566666666777777778+89 16 | 00000000111111111222222222333333334444444555555555666666666777777888+87 18 | 00000000111111111122222222333333334444444455555555566666666677777788+88 20 | 00000000011111111122222223333333344444444455555555566666667777777888+87 22 | 00000000011111111222222222333333334444444445555555566666666677777778+89 24 | 00000000011111112222222223333333344444444455555555666666667777777788+87 26 | 00000001111111112222222223333333334444444445555555666666667777777778+88 28 | 00000000111111111222222223333333334444444455555555666666667777777778+85 30 | 00000000011111111122222222233333333344444445555555556666666677777777+88 32 | 00000000001111111122222222233333334444444445555555556666666677777777+88 34 | 00000000011111111222222222333333334444444445555555566666666677777777+88 36 | 00000000001111111122222223333333334444444445555555566666666677777778+88 38 | 00000000111111112222222233333333334444444455555555566666667777777778+88 40 | 00000000111111112222222223333333334444444455555555566666667777777778+87 42 | 00000000111111112222222223333333333444444445555555666666666777777777+5 > > > On 2/9/2011 11:02 AM, Robert Pike wrote: >> Trying to get a good seed value for an app I'm working on. The app >> will be running on both windows and linux. The rand function will only >> be looking at numbers between 0 and 3 (inclusive). >> Right now I'm using time ^ $$. The funny thing is when I run on one >> server the results skew "greatly" towards the extremes (i.e. 0 or 3 - >> slighly more than 75% of the random numbers generated are 0 or 3). On >> another server the number 3 has never gotten hit after over 200 trial >> runs. Both servers are Windows machines. >> Appreciate any feedback anyone can give. Thanks. >> >> >> _______________________________________________ >> kw-pm mailing list >> kw-pm at pm.org >> http://mail.pm.org/mailman/listinfo/kw-pm > > _______________________________________________ > kw-pm mailing list > kw-pm at pm.org > http://mail.pm.org/mailman/listinfo/kw-pm -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 262 bytes Desc: OpenPGP digital signature URL: From trizor at gmail.com Wed Feb 9 11:42:47 2011 From: trizor at gmail.com (Edgar Bering) Date: Wed, 9 Feb 2011 14:42:47 -0500 Subject: [kw-pm] What resources will we have available to us Feb. 17? In-Reply-To: References: Message-ID: Hi Tyler, you might have meant to send this to the CSC's Progcom, I've CC'd us. A projector can be made available. 2011/2/7 Tyler Slijboom : > > I am preparing sample code and a Open Office Impress power point > presentation on my laptop.? Will a projector be available? > > -- > Sincerely, > Tyler Slijboom > > _______________________________________________ > kw-pm mailing list > kw-pm at pm.org > http://mail.pm.org/mailman/listinfo/kw-pm > From daniel at coder.com Wed Feb 9 11:43:22 2011 From: daniel at coder.com (Daniel R. Allen) Date: Wed, 9 Feb 2011 14:43:22 -0500 (EST) Subject: [kw-pm] What resources will we have available to us Feb. 17? In-Reply-To: Message-ID: I replied to Tyler off-list. I've been talking with Elana and the exec at csclub; they have made arrangements for the room and projector. Hey Mongers! Guess what! We have a special meeting coming up next week! Proper announcement coming as soon as I can paste in the details... -Daniel On Wed, 9 Feb 2011, Edgar Bering wrote: > Hi Tyler, you might have meant to send this to the CSC's Progcom, I've > CC'd us. A projector can be made available. > > 2011/2/7 Tyler Slijboom : > > > > I am preparing sample code and a Open Office Impress power point > > presentation on my laptop.? Will a projector be available? > > > > -- > > Sincerely, > > Tyler Slijboom > > > > _______________________________________________ > > kw-pm mailing list > > kw-pm at pm.org > > http://mail.pm.org/mailman/listinfo/kw-pm > > > _______________________________________________ > kw-pm mailing list > kw-pm at pm.org > http://mail.pm.org/mailman/listinfo/kw-pm > From daniel at coder.com Wed Feb 9 11:50:48 2011 From: daniel at coder.com (Daniel R. Allen) Date: Wed, 9 Feb 2011 14:50:48 -0500 (EST) Subject: [kw-pm] February Perl Mongers: A Smorgasbord of Intro Talks. NOTE DIFFERENT LOCATION Message-ID: This month is specially hosted by the University of Waterloo CS Club. (www.csclub.uwaterloo.ca). Note the room change to MC2017, in the Math building. Perl Mongers will present a smorgasbord of talks particularly for non-perl programmers. There will be food. And, hopefully, a crowd of curious club members! Tyler Slijboom will present: * Prototyping in Perl, * Perl Default Variables, * HOWTO on OO Programming, and * HOWTO on Installing and Using Modules from CPAN Daniel Allen will present: * Coping with Other Peoples' Code Justin Wheeler will present: * Moose: a Modern Perl Framework Hope you can come out and support the 'Mongers supporting the CS Club. :) From daniel at coder.com Wed Feb 9 13:12:26 2011 From: daniel at coder.com (Daniel R. Allen) Date: Wed, 9 Feb 2011 16:12:26 -0500 (EST) Subject: [kw-pm] February Perl Mongers: A Smorgasbord of Intro Talks. NOTE DIFFERENT LOCATION and OVERLY SPECIFIC MAPS In-Reply-To: Message-ID: On Wed, 9 Feb 2011, Daniel R. Allen wrote: > Note the room change [this month] to MC2017, the Math building. http://kw.pm.org/maps/finding-math-building.png MC is labeled, and for comparison, DC, the building we usually meet in. Parking: N-lot is $3 prepaid. There is construction directly between N-lot and MC. Avoid the two areas of the map marked by a hardhat. Once you're inside MC, room 2017 is a large room in the dead centre of the building. Consult the maps near the entrance. Or, you can try putting this into Google Maps: MC 2017 @43.47202103850661,-80.54393112659454 ...sorry, I don't have elevation. ;) From daniel at coder.com Wed Feb 16 12:06:52 2011 From: daniel at coder.com (Daniel R. Allen) Date: Wed, 16 Feb 2011 15:06:52 -0500 (EST) Subject: [kw-pm] Tomorrow: A Smorgasbord of Intro Talks Message-ID: A reminder of tomorrow evening's meeting! Pizza will be provided; no need for RSVP this month, as the CS club is planning for 'n' where n > (cs-club avg attendance) >> (kw-pm avg attendance). ---------- Forwarded message ---------- Date: Wed, 9 Feb 2011 14:50:48 -0500 (EST) From: Daniel R. Allen To: kw-pm at mail.pm.org Subject: [kw-pm] February Perl Mongers: A Smorgasbord of Intro Talks. NOTE DIFFERENT LOCATION This month is specially hosted by the University of Waterloo CS Club. (www.csclub.uwaterloo.ca). Note the room change to MC2017, in the Math building. [*] Perl Mongers will present a smorgasbord of talks particularly for non-perl programmers. There will be food. And, hopefully, a crowd of curious club members! Tyler Slijboom will present: * Prototyping in Perl, * Perl Default Variables, * HOWTO on OO Programming, and * HOWTO on Installing and Using Modules from CPAN Daniel Allen will present: * Coping with Other Peoples' Code Justin Wheeler will present: * Moose: a Modern Perl Framework Hope you can come out and support the 'Mongers supporting the CS Club. :) _______________________________________________ [1] http://kw.pm.org/maps/finding-math-building.png MC is labeled, and for comparison, DC, the building we usually meet in. Parking: N-lot is $3 prepaid. There is construction directly between N-lot and MC. Avoid the two areas of the map marked by a hardhat. Once you're inside MC, room 2017 is a large room in the dead centre of the building. Consult the maps near the entrance. Or, you can try putting this into Google Maps: MC 2017 @43.47202103850661,-80.54393112659454 From zixiekat at gmail.com Wed Feb 16 18:52:16 2011 From: zixiekat at gmail.com (Colin Mackay) Date: Wed, 16 Feb 2011 21:52:16 -0500 Subject: [kw-pm] Learning Perl in K/W region Message-ID: Good day, I have been a silent member of the list for a little while now. I am wondering where abouts in the K/W area I could go to get some Perl training? I am not a programmer by any means, but I have the opportunity to take some classes through work and a number of the scripts used are written in Perl. I have some scripting experience with Bash shell, but that's really about it. Can anyone on the list give me some ideas? I'd prefer instructor led programs, preferably a fast track. Thanks. -------------- next part -------------- An HTML attachment was scrubbed... URL: From wmat at naoi.ca Wed Feb 16 19:13:09 2011 From: wmat at naoi.ca (Bill Traynor) Date: Wed, 16 Feb 2011 22:13:09 -0500 Subject: [kw-pm] Learning Perl in K/W region In-Reply-To: References: Message-ID: <4D5C9245.10504@naoi.ca> On 11-02-16 09:52 PM, Colin Mackay wrote: > Good day, > > I have been a silent member of the list for a little while now. I am > wondering where abouts in the K/W area I could go to get some Perl > training? Conestoga College offers OLRN1253 - PERL Introduction. It begins May 13th at the Doon campus. See http://bit.ly/g9SSGw > > I am not a programmer by any means, but I have the opportunity to take > some classes through work and a number of the scripts used are written > in Perl. I have some scripting experience with Bash shell, but that's > really about it. > > > Can anyone on the list give me some ideas? I'd prefer instructor led > programs, preferably a fast track. > > > > Thanks. > > > _______________________________________________ > kw-pm mailing list > kw-pm at pm.org > http://mail.pm.org/mailman/listinfo/kw-pm From wmat at naoi.ca Wed Feb 16 19:14:15 2011 From: wmat at naoi.ca (Bill Traynor) Date: Wed, 16 Feb 2011 22:14:15 -0500 Subject: [kw-pm] Learning Perl in K/W region In-Reply-To: <4D5C9245.10504@naoi.ca> References: <4D5C9245.10504@naoi.ca> Message-ID: <4D5C9287.70906@naoi.ca> On 11-02-16 10:13 PM, Bill Traynor wrote: > On 11-02-16 09:52 PM, Colin Mackay wrote: >> Good day, >> >> I have been a silent member of the list for a little while now. I am >> wondering where abouts in the K/W area I could go to get some Perl >> training? > > Conestoga College offers OLRN1253 - PERL Introduction. It begins May > 13th at the Doon campus. My bad, this is a Distance Education course. > > See http://bit.ly/g9SSGw > > >> >> I am not a programmer by any means, but I have the opportunity to >> take some classes through work and a number of the scripts used are >> written in Perl. I have some scripting experience with Bash shell, >> but that's really about it. >> >> >> Can anyone on the list give me some ideas? I'd prefer instructor led >> programs, preferably a fast track. >> >> >> >> Thanks. >> >> >> _______________________________________________ >> kw-pm mailing list >> kw-pm at pm.org >> http://mail.pm.org/mailman/listinfo/kw-pm > > _______________________________________________ > kw-pm mailing list > kw-pm at pm.org > http://mail.pm.org/mailman/listinfo/kw-pm From rpjday at crashcourse.ca Thu Feb 24 10:44:48 2011 From: rpjday at crashcourse.ca (Robert P. J. Day) Date: Thu, 24 Feb 2011 13:44:48 -0500 (EST) Subject: [kw-pm] part 1, question about dereferencing Message-ID: on short notice, i'm reviewing my dereferencing so let me ask if i have a grip on the following. here's the code: ===== board ===== # How can I print the middle element (22)? my @board = ( [11, 12, 13], [21, 22, 23], [31, 32, 33] ); print "@board.\n"; # entire board (list of refs) print "$board[1].\n"; # second elt (anonymous array) print "@{$board[1]}.\n"; # actual second row print "$board[1]->[1].\n"; # middle element print "$board[1][1].\n"; # middle element using shortcut ===== end board ===== long story short, "@board" is obviously an array of three array references, and i just wanted to print various ways of dereferencing things to get to the middle element (22). does all of the above look sane? just from the comments, it should be clear what i'm trying to demonstrate, one step at a time. does all of the above make sense? rday -- ======================================================================== Robert P. J. Day Waterloo, Ontario, CANADA http://crashcourse.ca Twitter: http://twitter.com/rpjday LinkedIn: http://ca.linkedin.com/in/rpjday ======================================================================== From rpjday at crashcourse.ca Fri Feb 25 03:34:55 2011 From: rpjday at crashcourse.ca (Robert P. J. Day) Date: Fri, 25 Feb 2011 06:34:55 -0500 (EST) Subject: [kw-pm] just checking ... is this list still active? Message-ID: i'm going to have some perl questions over the next few days, just want to make sure i have a perl-savvy audience. :-) rday -- ======================================================================== Robert P. J. Day Waterloo, Ontario, CANADA http://crashcourse.ca Twitter: http://twitter.com/rpjday LinkedIn: http://ca.linkedin.com/in/rpjday ======================================================================== From rpjday at crashcourse.ca Fri Feb 25 06:27:55 2011 From: rpjday at crashcourse.ca (Robert P. J. Day) Date: Fri, 25 Feb 2011 09:27:55 -0500 (EST) Subject: [kw-pm] how to request perl 5.10 features? and other stuff Message-ID: first, a specific question: is there any difference between the following two statements in a perl script? use 5.010; use feature ':5.10'; do they both just pull in all features of version 5.10? and second, more general question -- i'm actually *teaching* an intro perl class in toronto next week (that should frighten you but it's just intro so it's not that mind-numbing), and i can tell from the manual i've been given that i'll have spare time left over at the end to play. anyone here have not overly complicated examples of cool perl programs that the students would enjoy seeing, and that wouldn't cause their brains to melt? there are already *numerous* examples of perl scripts that come with the course but i'm definitely going to have time to add extra content at the end, so if you have neat examples (or can point me at web sites that have), i'd appreciate that. again, it's an *intro* class so let's not get carried away. thanks. rday -- ======================================================================== Robert P. J. Day Waterloo, Ontario, CANADA http://crashcourse.ca Twitter: http://twitter.com/rpjday LinkedIn: http://ca.linkedin.com/in/rpjday ======================================================================== From dada.da at gmail.com Fri Feb 25 07:51:20 2011 From: dada.da at gmail.com (Daniel Allen) Date: Fri, 25 Feb 2011 10:51:20 -0500 Subject: [kw-pm] just checking ... is this list still active? In-Reply-To: References: Message-ID: I won't speak for all ~100 souls on the list. I didn't have inclination to answer because it looked right, but I didn't have time to go look at 'man perlreftut' myself to make sure it was idiomatic. I'd recommend going there, if you haven't already. To answer your second question about whether our list is active- since you are working to a short deadline, I highly recommend perlmonks; there are a few orders of magnitude more eyes. -Daniel On Fri, Feb 25, 2011 at 6:34 AM, Robert P. J. Day wrote: > > i'm going to have some perl questions over the next few days, just > want to make sure i have a perl-savvy audience. :-) > > rday > > -- > > ======================================================================== > Robert P. J. Day Waterloo, Ontario, CANADA > http://crashcourse.ca > > Twitter: http://twitter.com/rpjday > LinkedIn: http://ca.linkedin.com/in/rpjday > ======================================================================== > _______________________________________________ > kw-pm mailing list > kw-pm at pm.org > http://mail.pm.org/mailman/listinfo/kw-pm > -------------- next part -------------- An HTML attachment was scrubbed... URL: From rpjday at crashcourse.ca Fri Feb 25 10:52:09 2011 From: rpjday at crashcourse.ca (Robert P. J. Day) Date: Fri, 25 Feb 2011 13:52:09 -0500 (EST) Subject: [kw-pm] picking a random list element, the hard way Message-ID: for your entertainment value, here's an optional exercise i'm going to give out in next week's perl class. it's not so much a perl question as it is an algorithmic analysis question that's actually quite simple to code once you figure it out. JOB: pick a random element from a list, such that each element in the list is equally likely to be selected. sounds trivial, yes? except here's the extra condition. you're given the list elements only *one at a time*. you're not allowed to store them, and you have no idea how many are coming. and yet, you still need to pick a random element out of that list. thoughts? rday From abram.hindle at softwareprocess.es Fri Feb 25 11:00:59 2011 From: abram.hindle at softwareprocess.es (Abram Hindle) Date: Fri, 25 Feb 2011 11:00:59 -0800 Subject: [kw-pm] UNS: picking a random list element, the hard way In-Reply-To: (sfid-20110225_135605_801715_EB1E5AB4) References: (sfid-20110225_135605_801715_EB1E5AB4) Message-ID: <4D67FC6B.9000407@softwareprocess.es> We golfed about this problem a while back. See the first challenge: http://kw.pm.org/wiki/index.cgi?GolfChallenge abram On 02/25/2011 10:52 AM, Robert P. J. Day wrote: > > for your entertainment value, here's an optional exercise i'm going > to give out in next week's perl class. it's not so much a perl > question as it is an algorithmic analysis question that's actually > quite simple to code once you figure it out. > > JOB: pick a random element from a list, such that each element in > the list is equally likely to be selected. > > sounds trivial, yes? except here's the extra condition. you're > given the list elements only *one at a time*. you're not allowed to > store them, and you have no idea how many are coming. and yet, you > still need to pick a random element out of that list. > > thoughts? > > rday > _______________________________________________ > kw-pm mailing list > kw-pm at pm.org > http://mail.pm.org/mailman/listinfo/kw-pm -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 262 bytes Desc: OpenPGP digital signature URL: From rpjday at crashcourse.ca Fri Feb 25 11:09:28 2011 From: rpjday at crashcourse.ca (Robert P. J. Day) Date: Fri, 25 Feb 2011 14:09:28 -0500 (EST) Subject: [kw-pm] UNS: picking a random list element, the hard way In-Reply-To: <4D67FC6B.9000407@softwareprocess.es> References: (sfid-20110225_135605_801715_EB1E5AB4) <4D67FC6B.9000407@softwareprocess.es> Message-ID: On Fri, 25 Feb 2011, Abram Hindle wrote: > We golfed about this problem a while back. > > See the first challenge: > > http://kw.pm.org/wiki/index.cgi?GolfChallenge yes, i should have figured this would be old news. rday From rpjday at crashcourse.ca Sat Feb 26 03:23:04 2011 From: rpjday at crashcourse.ca (Robert P. J. Day) Date: Sat, 26 Feb 2011 06:23:04 -0500 (EST) Subject: [kw-pm] how to tell how much space an array really takes? Message-ID: not sure if this is a meaningful question but can i tell how much space a sparse array really takes? say i do the following: $arr[0] = 10; $arr[10000] = 20; i realize that perl won't allocate all those intermediate entries so the actual "space" (can i use that word here?) is just two entries. if i refer to, say, $arr[1], since that entry doesn't "exist", i get back the value "undef". so far, so good. however, if i assign: $arr[1] = undef; then that entry really *does* have a value now, correct? the value "undef", not to be confused with not existing at all. is there a way of distinguishing between those two situations, such that i could tell the difference? and how much space the array actually occupies? or is all this meaningless? rday -- ======================================================================== Robert P. J. Day Waterloo, Ontario, CANADA http://crashcourse.ca Twitter: http://twitter.com/rpjday LinkedIn: http://ca.linkedin.com/in/rpjday ======================================================================== From ceeshek at gmail.com Sun Feb 27 18:23:31 2011 From: ceeshek at gmail.com (Cees Hek) Date: Mon, 28 Feb 2011 13:23:31 +1100 Subject: [kw-pm] picking a random list element, the hard way In-Reply-To: References: Message-ID: I hate it when people dangle exercises like this in front of my face because i always get sucked into trying them out when i should be doing more productive work ;) Here is a (very ugly) golfed solution which is most likely of no use to you in your intro class :) seq 1 10 | perl -pe '$v=$_ if rand()<1/$.}{$_=$v' I agree with you though, the algorithm is interesting and yet it is still trivial enough to implement, which makes it a great example for a beginner class. Cheers, Cees Hek On Sat, Feb 26, 2011 at 5:52 AM, Robert P. J. Day wrote: > > ?for your entertainment value, here's an optional exercise i'm going > to give out in next week's perl class. ?it's not so much a perl > question as it is an algorithmic analysis question that's actually > quite simple to code once you figure it out. > > ?JOB: pick a random element from a list, such that each element in > the list is equally likely to be selected. > > ?sounds trivial, yes? ?except here's the extra condition. ?you're > given the list elements only *one at a time*. ?you're not allowed to > store them, and you have no idea how many are coming. ?and yet, you > still need to pick a random element out of that list. > > ?thoughts? > > rday > _______________________________________________ > kw-pm mailing list > kw-pm at pm.org > http://mail.pm.org/mailman/listinfo/kw-pm > From ceeshek at gmail.com Sun Feb 27 18:29:00 2011 From: ceeshek at gmail.com (Cees Hek) Date: Mon, 28 Feb 2011 13:29:00 +1100 Subject: [kw-pm] UNS: picking a random list element, the hard way In-Reply-To: References: <4D67FC6B.9000407@softwareprocess.es> Message-ID: Looks like I should have read all my emails before responding :) This message came through in a different thread which is why I missed it initially. Nice to see solutions in other languages on that page as well. Thanks for the pointer. Cheers, Cees Hek On Sat, Feb 26, 2011 at 6:09 AM, Robert P. J. Day wrote: > On Fri, 25 Feb 2011, Abram Hindle wrote: > >> We golfed about this problem a while back. >> >> See the first challenge: >> >> http://kw.pm.org/wiki/index.cgi?GolfChallenge > > ?yes, i should have figured this would be old news. > > rday > _______________________________________________ > kw-pm mailing list > kw-pm at pm.org > http://mail.pm.org/mailman/listinfo/kw-pm > From abram.hindle at softwareprocess.es Sun Feb 27 18:42:56 2011 From: abram.hindle at softwareprocess.es (Abram Hindle) Date: Sun, 27 Feb 2011 18:42:56 -0800 Subject: [kw-pm] picking a random list element, the hard way In-Reply-To: (sfid-20110227_212805_496066_3410EFB1) References: (sfid-20110227_212805_496066_3410EFB1) Message-ID: <4D6B0BB0.4060503@softwareprocess.es> Well you did golf better than Daniel's. I've got an extension to the puzzle ;) Now you want N elements picked uniformly from the stream without duplicates (don't choose the same element twice). All the elements must be uniformly randomly chosen. You don't know the size of the stream, but we'll guarantee it is of size N or longer. You're allowed to store N elements in memory + any meta data. An example run: $ seq 1 100 | perl chooser.pl 10 51 63 100 58 12 23 90 11 69 7 The format doesn't have to be the same, but you want to choose N elements from a stream without storing the entire stream and the output should not be biased, the choices should be uniformly random. abram On 02/27/2011 06:23 PM, Cees Hek wrote: > I hate it when people dangle exercises like this in front of my face > because i always get sucked into trying them out when i should be > doing more productive work ;) > > Here is a (very ugly) golfed solution which is most likely of no use > to you in your intro class :) > > seq 1 10 | perl -pe '$v=$_ if rand()<1/$.}{$_=$v' > > I agree with you though, the algorithm is interesting and yet it is > still trivial enough to implement, which makes it a great example for > a beginner class. > > Cheers, > > Cees Hek > > On Sat, Feb 26, 2011 at 5:52 AM, Robert P. J. Day wrote: >> >> for your entertainment value, here's an optional exercise i'm going >> to give out in next week's perl class. it's not so much a perl >> question as it is an algorithmic analysis question that's actually >> quite simple to code once you figure it out. >> >> JOB: pick a random element from a list, such that each element in >> the list is equally likely to be selected. >> >> sounds trivial, yes? except here's the extra condition. you're >> given the list elements only *one at a time*. you're not allowed to >> store them, and you have no idea how many are coming. and yet, you >> still need to pick a random element out of that list. >> >> thoughts? >> >> rday >> _______________________________________________ >> kw-pm mailing list >> kw-pm at pm.org >> http://mail.pm.org/mailman/listinfo/kw-pm >> > _______________________________________________ > kw-pm mailing list > kw-pm at pm.org > http://mail.pm.org/mailman/listinfo/kw-pm -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 262 bytes Desc: OpenPGP digital signature URL: From matt at sergeant.org Mon Feb 28 08:03:05 2011 From: matt at sergeant.org (Matt Sergeant) Date: Mon, 28 Feb 2011 11:03:05 -0500 Subject: [kw-pm] how to tell how much space an array really takes? In-Reply-To: References: Message-ID: <4D6BC739.6000707@sergeant.org> Robert P. J. Day wrote: > or is all this meaningless? > It's all meaningless. Arrays in perl aren't sparse like hashes are. From roberthpike at yahoo.com Mon Feb 28 13:41:26 2011 From: roberthpike at yahoo.com (Robert Pike) Date: Mon, 28 Feb 2011 13:41:26 -0800 (PST) Subject: [kw-pm] Hash Question Message-ID: <468197.14980.qm@web120509.mail.ne1.yahoo.com> I have a complex hash that I want to make a "copy" of before manipulating the original hash. Here is what I have : my %tmpData = %{$aDATA}; If I make changes to %{%aDATA} the changes are reflected in %tmpData. How can I copy the hash without having to loop through each element and assigning to the backup copy? Thanks. From foxryan at gmail.com Mon Feb 28 14:01:33 2011 From: foxryan at gmail.com (Ryan Fox) Date: Mon, 28 Feb 2011 17:01:33 -0500 Subject: [kw-pm] Hash Question In-Reply-To: <468197.14980.qm@web120509.mail.ne1.yahoo.com> References: <468197.14980.qm@web120509.mail.ne1.yahoo.com> Message-ID: I believe the standard solution is to use Storable http://search.cpan.org/perldoc?Storable (I think it's a standard module?) Look at freeze() and thaw() or dclone() in the perldoc there. On Mon, Feb 28, 2011 at 4:41 PM, Robert Pike wrote: > I have a complex hash that I want to make a "copy" of before manipulating > the original hash. > Here is what I have : > my %tmpData = %{$aDATA}; > If I make changes to %{%aDATA} the changes are reflected in %tmpData. How > can I copy the hash without having to loop through each element and > assigning to the backup copy? Thanks. > > > _______________________________________________ > kw-pm mailing list > kw-pm at pm.org > http://mail.pm.org/mailman/listinfo/kw-pm > -------------- next part -------------- An HTML attachment was scrubbed... URL: