From doug.miles at ns2.phoenix.bowne.com Wed Jan 5 13:47:00 2000 From: doug.miles at ns2.phoenix.bowne.com (Douglas E. Miles) Date: Thu Aug 5 00:16:03 2004 Subject: Phoenix.pm: Meeting 01/11/2000 Message-ID: <38739FB4.60EA4E08@bpxinternet.com> We'll be having a Phoenix.pm meeting Tuesday, January 11th at 7:00PM. It will be held at Bowne, which is located at 1500 N. Central Avenue, which is on the Southwest corner of Central and McDowell. The parking lot is gated, so just press the button on the intercom, and tell the receptionist that you are there for the Perl meeting. Park in the lot that is straight ahead from the entrance on the South side of McDowell. Park in any uncovered, non-reserved space. Proceed to the main lobby, which is on the Northeast side of the parking lot. Topic is unknown. Volunteers are welcome. -- For a list of the ways which technology has failed to improve our quality of life, press 3. From doug.miles at ns2.phoenix.bowne.com Fri Jan 7 15:34:26 2000 From: doug.miles at ns2.phoenix.bowne.com (Douglas E. Miles) Date: Thu Aug 5 00:16:03 2004 Subject: Phoenix.pm: Meeting topic Message-ID: <38765BE2.4E03EC1A@bpxinternet.com> I haven't had any volunteers, and I also haven't had time to put anything together myself, so unless something changes soon, I think we'll just do a social get together here (at Bowne). Feel free to volunteer, or let me know how you feel about this. Thanks! -- For a list of the ways which technology has failed to improve our quality of life, press 3. From Beaves at aol.com Fri Jan 7 22:11:53 2000 From: Beaves at aol.com (Beaves@aol.com) Date: Thu Aug 5 00:16:03 2004 Subject: Phoenix.pm: Regular Expressions Message-ID: How about Regular Expressions as a topic... Nothing too heavy, just favorite samples. We could each bring a snippet or two with explanations of the logic. I bet it would make for some good learnin''. Just an idea... See yous Toozday (in my best Wichita-Boston accent...) Tim From doug.miles at ns2.phoenix.bowne.com Mon Jan 10 10:43:51 2000 From: doug.miles at ns2.phoenix.bowne.com (Douglas E. Miles) Date: Thu Aug 5 00:16:03 2004 Subject: Phoenix.pm: Regular Expressions References: Message-ID: <387A0C46.1C8509E5@bpxinternet.com> Beaves@aol.com wrote: > > How about Regular Expressions as a topic... Nothing too heavy, just favorite > samples. We could each bring a snippet or two with explanations of the > logic. I bet it would make for some good learnin''. > > Just an idea... > > See yous Toozday (in my best Wichita-Boston accent...) > > Tim Sounds good to me. I'll see what I can dig up. Anyone else interested? -- For a list of the ways which technology has failed to improve our quality of life, press 3. From coyotl at primenet.com Mon Jan 10 11:22:03 2000 From: coyotl at primenet.com (Glen G. Walker) Date: Thu Aug 5 00:16:03 2004 Subject: Phoenix.pm: Regular Expressions In-Reply-To: <387A0C46.1C8509E5@bpxinternet.com> Message-ID: Sorry to spam the list, but my primenet account got hacked and I lost all my email and addresses from before the 5th. Anything huge that I missed? (Also Shay- I need your email address again... ) From doug.miles at ns2.phoenix.bowne.com Mon Jan 10 13:26:18 2000 From: doug.miles at ns2.phoenix.bowne.com (Douglas E. Miles) Date: Thu Aug 5 00:16:03 2004 Subject: Meeting reminder was: (Re: Phoenix.pm: Regular Expressions) References: Message-ID: <387A325A.584EBC5@bpxinternet.com> "Glen G. Walker" wrote: > > Sorry to spam the list, but my primenet account got hacked and I lost all > my email and addresses from before the 5th. Anything huge that I missed? > (Also Shay- I need your email address again... ) We're having a meeting tomorrow night, so I guess I'll make this an official reminder. We'll be discussing regular expressions that anyone brings. Other than that, not much traffic recently. -- For a list of the ways which technology has failed to improve our quality of life, press 3. From Beaves at aol.com Tue Jan 11 13:13:54 2000 From: Beaves at aol.com (Beaves@aol.com) Date: Thu Aug 5 00:16:03 2004 Subject: Phoenix.pm: session package Message-ID: Is there a module that anyone can recommend for handling session implementation and data via CGI? I've been using my own system, but I suspect that there is better stuff out there... Tim From davewarner98 at yahoo.com Tue Jan 11 13:38:29 2000 From: davewarner98 at yahoo.com (Dave Warner) Date: Thu Aug 5 00:16:03 2004 Subject: Phoenix.pm: Meeting 01/11/2000 Message-ID: <20000111193829.13344.qmail@web204.mail.yahoo.com> #!/usr/bin/perl my $sons_wishes = "Pokemon League" my $own_wishes = "Perl Mongers Meeting" if ($sons_wishes gt $own_wishes) { print "See you next meeting!" } ===== Microsoft's technical skills in developing innovative and robust software do not strike fear into the hearts of anyone except its customers. --Eric Bender __________________________________________________ Do You Yahoo!? Talk to your friends online with Yahoo! Messenger. http://im.yahoo.com From doug.miles at ns2.phoenix.bowne.com Tue Jan 11 14:36:20 2000 From: doug.miles at ns2.phoenix.bowne.com (Douglas E. Miles) Date: Thu Aug 5 00:16:03 2004 Subject: Phoenix.pm: Meeting 01/11/2000 References: <20000111193829.13344.qmail@web204.mail.yahoo.com> Message-ID: <387B9444.631AF7C2@bpxinternet.com> Dave Warner wrote: > > #!/usr/bin/perl > > my $sons_wishes = "Pokemon League" > my $own_wishes = "Perl Mongers Meeting" > > if ($sons_wishes gt $own_wishes) { > > print "See you next meeting!" > > } #!/usr/bin/perl package Pokemon; sub new { return 1; } package main; POKEMONLEAGUE: tell(YOURSON); $pokemon = new Pokemon 'Camel'; goto PERLMONGERS; PERLMONGERS: dump POKEMONLEAGUE; Enjoy the Pokemon League! :) If you run this you get a nice core file. :) -- For a list of the ways which technology has failed to improve our quality of life, press 3. From Ron.Giffin at motorola.com Tue Jan 11 14:46:39 2000 From: Ron.Giffin at motorola.com (Giffin Ron-P08295) Date: Thu Aug 5 00:16:03 2004 Subject: Phoenix.pm: Meeting 01/11/2000 Message-ID: <01CA656A687ED211926B00805F779140035D4FBB@az25exm02.geg.mot.com> I like your code Dave. #!/usr/bin/perl my $sons_wishes = "Pokemon League" ^ However, if you change o to a, you could go to the meeting. my $own_wishes = "Perl Mongers Meeting" if ($sons_wishes gt $own_wishes) { print "See you next meeting!" } From davewarner98 at yahoo.com Tue Jan 11 15:10:08 2000 From: davewarner98 at yahoo.com (Dave Warner) Date: Thu Aug 5 00:16:03 2004 Subject: Phoenix.pm: Meeting 01/11/2000 Message-ID: <20000111211008.12449.qmail@web209.mail.yahoo.com> Well, I ran it by my son, RJ, and...he didn't fall for it. Just corrected my misspelling! Now...where was that EBDIC chart... --- Giffin Ron-P08295 wrote: > I like your code Dave. > > > #!/usr/bin/perl > > my $sons_wishes = "Pokemon League" > ^ > However, if you change o to a, you could go to the > meeting. > > my $own_wishes = "Perl Mongers Meeting" > > if ($sons_wishes gt $own_wishes) { > > print "See you next meeting!" > > } > > > > > ===== Microsoft's technical skills in developing innovative and robust software do not strike fear into the hearts of anyone except its customers. --Eric Bender __________________________________________________ Do You Yahoo!? Talk to your friends online with Yahoo! Messenger. http://im.yahoo.com From doug.miles at ns2.phoenix.bowne.com Wed Jan 12 11:36:48 2000 From: doug.miles at ns2.phoenix.bowne.com (Douglas E. Miles) Date: Thu Aug 5 00:16:03 2004 Subject: Phoenix.pm: Meeting last night Message-ID: <387CBBB0.B27496AD@bpxinternet.com> Thanks to all those who made it out last night. I think we had some great discussions. For the next meeting, Kurt might present a tool that he is working on, or I might present on Perl/XML. We'll see who gets their act together first. ;) -- For a list of the ways which technology has failed to improve our quality of life, press 3. From edelsys at edelsys.com Wed Jan 12 12:43:30 2000 From: edelsys at edelsys.com (EdelSys Consulting) Date: Thu Aug 5 00:16:03 2004 Subject: Phoenix.pm: AZIPA Message-ID: <3.0.6.32.20000112114330.00b0ac80@swlink.net> Arizona Internet Professionals Association (AZIPA): http://www.azipa.org/ AZIPA Mailing List: http://www.azipa.org/mail.html Tony -- -- Anthony R. Nemmer -- EdelSys Consulting -- http://www.edelsys.com/ -- edelsys@edelsys.com -- ICQ #14638605 -- EFNet IRC Nicks: Teratogen, PerlGod -- vCard: http://www.edelsys.com/edelsys.vcf -- (480) 968-6438 -- P.O. Box 1883, Tempe, Arizona 85280-1883 -- From forsythe at primenet.com Wed Jan 12 21:35:47 2000 From: forsythe at primenet.com (Tran Forsythe) Date: Thu Aug 5 00:16:03 2004 Subject: Phoenix.pm: Meeting last night References: <387CBBB0.B27496AD@bpxinternet.com> Message-ID: <003201bf5d77$494ae640$0100a8c0@tran> Doug E Miles said, > Thanks to all those who made it out last night. I think we had some > great discussions. For the next meeting, Kurt might present a tool that > he is working on, or I might present on Perl/XML. We'll see who gets > their act together first. ;) *grin* Mind if I bet on you? ;) -Kurt ------ "Push to test." "Release to detonate." -Brad Morrison From Bryan.Lane at VITALPS.COM Thu Jan 13 10:29:17 2000 From: Bryan.Lane at VITALPS.COM (Bryan Lane) Date: Thu Aug 5 00:16:03 2004 Subject: Phoenix.pm: AZIPA Message-ID: Thanks for posting that!!! -----Original Message----- From: EdelSys Consulting [mailto:edelsys@edelsys.com] Sent: Wednesday, January 12, 2000 11:44 AM To: phoenix-pm-list@happyfunball.pm.org Subject: Phoenix.pm: AZIPA Arizona Internet Professionals Association (AZIPA): http://www.azipa.org/ AZIPA Mailing List: http://www.azipa.org/mail.html Tony -- -- Anthony R. Nemmer -- EdelSys Consulting -- http://www.edelsys.com/ -- edelsys@edelsys.com -- ICQ #14638605 -- EFNet IRC Nicks: Teratogen, PerlGod -- vCard: http://www.edelsys.com/edelsys.vcf -- (480) 968-6438 -- P.O. Box 1883, Tempe, Arizona 85280-1883 -- From doug.miles at ns2.phoenix.bowne.com Thu Jan 13 14:22:43 2000 From: doug.miles at ns2.phoenix.bowne.com (Douglas E. Miles) Date: Thu Aug 5 00:16:03 2004 Subject: Phoenix.pm: Meeting last night References: <387CBBB0.B27496AD@bpxinternet.com> <003201bf5d77$494ae640$0100a8c0@tran> Message-ID: <387E3413.E9566227@bpxinternet.com> Tran Forsythe wrote: > > Doug E Miles said, > > > Thanks to all those who made it out last night. I think we had some > > great discussions. For the next meeting, Kurt might present a tool that > > he is working on, or I might present on Perl/XML. We'll see who gets > > their act together first. ;) > > *grin* Mind if I bet on you? ;) > -Kurt I don't know if I should let you. You might take a dive. :) -- For a list of the ways which technology has failed to improve our quality of life, press 3. From edelsys at edelsys.com Sat Jan 15 12:01:35 2000 From: edelsys at edelsys.com (EdelSys Consulting) Date: Thu Aug 5 00:16:03 2004 Subject: Phoenix.pm: AZIPA In-Reply-To: Message-ID: <3.0.6.32.20000115110135.007e3dc0@swlink.net> At 09:29 AM 01/13/2000 -0700, you wrote: >Thanks for posting that!!! > You're welcome! AZIPA is a lively group and also a lively mailing list. =) Tony From Beaves at aol.com Thu Jan 20 00:46:51 2000 From: Beaves at aol.com (Beaves@aol.com) Date: Thu Aug 5 00:16:03 2004 Subject: Phoenix.pm: has a sub been defined Message-ID: Do yous guys remember a while back when I had the need to determine where a subroutine was defined or not? We talked a bit about the Perl symbol tables, etc at one of the PM meetings. Well, can't say if the issue was ever resolved, but I finally found an easy solution. It was all staring me right in the face on page 281 of your pew bibles (The Camel Book). I looked at this code before, but for some reason didn't think that the statement 'defined &sym' would work because I thought it would run the subroutine. Well, it doesn't... I modified it somewhat to also take into account the package from which &is_sub was called, or to force the package an optional second argument. sub is_sub { my $symname = shift; my $package = shift || ${[caller(0)]}[0]; local *sym = *{"$package\::$symname"}; return 1 if defined &sym } ### Things can always be improved. ### After thinking about it, I realized I could test for a specific type sub defined_in_symtable { my $symname = shift; my $package = shift || ${[caller(0)]}[0]; my $type = shift || 'CODE'; # why not default to what started this crap... local *sym = *{"$package\::$symname"}; if ($type eq 'CODE') { return defined *sym{'CODE'} } # for some reason, the SCALAR one has to be de-referenced... elsif ($type eq 'SCALAR') { return defined ${*sym{'SCALAR'}} } elsif ($type eq 'HASH') { return defined *sym{'HASH'} } elsif ($type eq 'ARRAY') { return defined *sym{'ARRAY'} } elsif ($type eq 'FILEHANDLE') { return defined *sym{'FILEHANDLE'} } } This code above has not been extensively tested, but initial indications are that it works as expected. I hope this may partially demystify Perl symbol tables. I still don't feel like I know them that well, but I'm constantly adding stuff into my bag o' experience... If anyone has any questions about this code, let's get a little discussion going, and liven things up a little. Tim From forsythe at primenet.com Thu Jan 20 01:38:26 2000 From: forsythe at primenet.com (Tran Forsythe) Date: Thu Aug 5 00:16:03 2004 Subject: Phoenix.pm: has a sub been defined References: Message-ID: <009f01bf6319$578f3b00$0100a8c0@tran> All I can say is "Nice!".. okay, I can say a second thing: Dammit, why didn't I think of that?!? ;) Good job, man ;) -Kurt ------ "Push to test." "Release to detonate." -Brad Morrison From doug.miles at ns2.phoenix.bowne.com Thu Jan 20 12:18:42 2000 From: doug.miles at ns2.phoenix.bowne.com (Douglas E. Miles) Date: Thu Aug 5 00:16:03 2004 Subject: Phoenix.pm: Meeting 01/25/2000 Message-ID: <38875182.98AC64AC@bpxinternet.com> We'll be having a Phoenix.pm meeting Tuesday, January 25th at 7:00PM. It will be held at Bowne, which is located at 1500 N. Central Avenue, which is on the Southwest corner of Central and McDowell. The parking lot is gated, so just press the button on the intercom, and tell the receptionist that you are there for the Perl meeting. Park in the lot that is straight ahead from the entrance on the South side of McDowell. Park in any uncovered, non-reserved space. Proceed to the main lobby, which is on the Northeast side of the parking lot. I will be presenting on Perl and XML. Those of you who missed the Tk presentation: I might slip a little Tk in too. :) -- For a list of the ways which technology has failed to improve our quality of life, press 3. From doug.miles at ns2.phoenix.bowne.com Thu Jan 20 14:46:35 2000 From: doug.miles at ns2.phoenix.bowne.com (Douglas E. Miles) Date: Thu Aug 5 00:16:03 2004 Subject: Phoenix.pm: New perl site Message-ID: <3887742B.E9FBEE10@bpxinternet.com> Here's a perl site I just ran across: http://perlmonks.org/ I haven't really looked at it yet, but I thought you might be interested. -- For a list of the ways which technology has failed to improve our quality of life, press 3. From edelsys at edelsys.com Thu Jan 20 15:10:02 2000 From: edelsys at edelsys.com (EdelSys Consulting) Date: Thu Aug 5 00:16:03 2004 Subject: Phoenix.pm: New perl site In-Reply-To: <3887742B.E9FBEE10@bpxinternet.com> Message-ID: <3.0.6.32.20000120141002.009224c0@swlink.net> At 01:46 PM 01/20/2000 -0700, you wrote: >Here's a perl site I just ran across: > >http://perlmonks.org/ > >I haven't really looked at it yet, but I thought you might be >interested. > >-- >For a list of the ways which technology has failed >to improve our quality of life, press 3. > I've been giving some serious thought to registering churchofperl.org =P -- -- Anthony R. Nemmer -- EdelSys Consulting -- http://www.edelsys.com/ -- edelsys@edelsys.com -- ICQ #14638605 -- EFNet IRC Nicks: Teratogen, PerlGod -- vCard: http://www.edelsys.com/edelsys.vcf -- (480) 968-6438 -- P.O. Box 1883, Tempe, Arizona 85280-1883 -- "Even the safest course is fraught with peril." -- Anonymous From pablo at dosomething.org Fri Jan 21 00:14:22 2000 From: pablo at dosomething.org (Pablo Velasquez) Date: Thu Aug 5 00:16:03 2004 Subject: Phoenix.pm: New perl site In-Reply-To: <3887742B.E9FBEE10@bpxinternet.com> Message-ID: <4.2.0.58.20000120221144.00b9b420@mail.dosomething.org> Really good site, thanks. At 01:46 PM 1/20/00 -0700, you wrote: >Here's a perl site I just ran across: > >http://perlmonks.org/ > >I haven't really looked at it yet, but I thought you might be >interested. > >-- >For a list of the ways which technology has failed >to improve our quality of life, press 3. From Beaves at aol.com Fri Jan 21 17:14:36 2000 From: Beaves at aol.com (Beaves@aol.com) Date: Thu Aug 5 00:16:03 2004 Subject: Phoenix.pm: definedness and more symbol tables Message-ID: I just thought I'd share some stuff I learned with y'all during my symbol table excursion. Some of the testing on my little sub did not go as expected. I couldn't understand why, but I think I figured it out. If there is something that I say here that is in dispute, please bring it up. (I'm using package 'main' for all examples...) On initial parsing of a program, symbol table entries are made for each symbol (I'm guessing for efficiency). Even if there is no assigment, there will be a $main::{symname} entry made to the symbol table, and a reference to the variable created. For instance, just saying. @symname; creates $main::{symname} and a reference to the ARRAY for symname in the glob. *main::symname{ARRAY} Of course, the value it is pointing to is still undefined, but *main::symname{ARRAY} is itself defined. Hashes and Arrays are 'undefined' until the memory is allocated for them. This is an interesting point. See below @symname; #undefined @sumname = (); # still undefined; @symname = (1) # now its defined... # but if you say shift(@symname); # @symname is STILL DEFINED # even if you say @symname = undef; #@symname is STILL DEFINED (memory still allocated) # same is true for hashes The definedness of subroutines has to do if the code was successfully parsed. Saying defined $symname; will not create a symbol table entry. However, if this statement is made on parsing, it WILL create a symbol table. Consider... defined $symname; # symbol table entry created on parsing this code, not when running it delete( $main::{symname}); defined $symname; # does not create a symbol table entry. This stuff is not really that important, but I thought that I'd share what I discovered. Sorry for boring you'all to tears. See you round campus. Tim From doug.miles at ns2.phoenix.bowne.com Tue Jan 25 10:43:02 2000 From: doug.miles at ns2.phoenix.bowne.com (Douglas E. Miles) Date: Thu Aug 5 00:16:03 2004 Subject: Phoenix.pm: Meeting 01/25/2000 (Tonight) Reminder Message-ID: <388DD296.3498B6B5@bpxinternet.com> We'll be having a Phoenix.pm meeting Tuesday, January 25th at 7:00PM. It will be held at Bowne, which is located at 1500 N. Central Avenue, which is on the Southwest corner of Central and McDowell. The parking lot is gated, so just press the button on the intercom, and tell the receptionist that you are there for the Perl meeting. Park in the lot that is straight ahead from the entrance on the South side of McDowell. Park in any uncovered, non-reserved space. Proceed to the main lobby, which is on the Northeast side of the parking lot. I will be presenting on Perl and XML. Those of you who missed the Tk presentation: I might slip a little Tk in too. :) -- For a list of the ways which technology has failed to improve our quality of life, press 3. From Bryan.Lane at VITALPS.COM Tue Jan 25 11:45:33 2000 From: Bryan.Lane at VITALPS.COM (Bryan Lane) Date: Thu Aug 5 00:16:03 2004 Subject: Phoenix.pm: Meeting 01/25/2000 (Tonight) Reminder Message-ID: Sorry, I won't be able to come. Although it does sound very interesting! Bryan -----Original Message----- From: Douglas E. Miles [mailto:doug.miles@ns2.phoenix.bowne.com] Sent: Tuesday, January 25, 2000 9:43 AM To: Phoenix.pm Cc: Rose Keys Subject: Phoenix.pm: Meeting 01/25/2000 (Tonight) Reminder We'll be having a Phoenix.pm meeting Tuesday, January 25th at 7:00PM. It will be held at Bowne, which is located at 1500 N. Central Avenue, which is on the Southwest corner of Central and McDowell. The parking lot is gated, so just press the button on the intercom, and tell the receptionist that you are there for the Perl meeting. Park in the lot that is straight ahead from the entrance on the South side of McDowell. Park in any uncovered, non-reserved space. Proceed to the main lobby, which is on the Northeast side of the parking lot. I will be presenting on Perl and XML. Those of you who missed the Tk presentation: I might slip a little Tk in too. :) -- For a list of the ways which technology has failed to improve our quality of life, press 3. From Ron.Giffin at motorola.com Tue Jan 25 16:10:16 2000 From: Ron.Giffin at motorola.com (Giffin Ron-P08295) Date: Thu Aug 5 00:16:03 2004 Subject: Phoenix.pm: PLUG'ers on PM list. Message-ID: <01CA656A687ED211926B00805F779140035D4FCE@az25exm02.geg.mot.com> Sorry to use PM list this way. In subscribing to new PLUG address, I've locked myself out. Is new address plug-subscribe@lists.PLUG.phoenx.az.us ?? This is being returned. Thanks and again sorry for the intrusion. -- Ron From davewarner98 at yahoo.com Wed Jan 26 09:29:33 2000 From: davewarner98 at yahoo.com (Dave Warner) Date: Thu Aug 5 00:16:03 2004 Subject: Phoenix.pm: Meeting 01/25/2000 Message-ID: <20000126152933.17065.qmail@web216.mail.yahoo.com> Doug, Great meeting last night, thanks for the presentation on xml. On a tangential note, the link for invisible worlds is: http://www.invisibleworlds.net Invisible Worlds is a startup that is proposing a new internet protocol ("blocks") allowing for the fast transmission of large amounts of data over the internet. They also have a very interesting on-line magazine at: http://mappa.mundi.net that covers philosophical issues related to technology. Some of the folks involved with Invisible Worlds are Tim O'Reilly and Paul Vixie (responsible for DNS/BIND). ===== Microsoft's technical skills in developing innovative and robust software do not strike fear into the hearts of anyone except its customers. --Eric Bender __________________________________________________ Do You Yahoo!? Talk to your friends online with Yahoo! Messenger. http://im.yahoo.com From doug.miles at ns2.phoenix.bowne.com Wed Jan 26 16:25:56 2000 From: doug.miles at ns2.phoenix.bowne.com (Douglas E. Miles) Date: Thu Aug 5 00:16:03 2004 Subject: Next meeting was: (Re: Phoenix.pm: Meeting 01/25/2000) References: <20000126152933.17065.qmail@web216.mail.yahoo.com> Message-ID: <388F7474.36316290@bpxinternet.com> Dave Warner wrote: > > Doug, > > Great meeting last night, thanks for the > presentation on xml. On a tangential note, the link > for invisible worlds is: > > http://www.invisibleworlds.net > Thanks. Here is the list I have for topic ideas. Please let me know if you have any to add, or especialy if you want to volunteer for next time (hint, hint ;) ). David Warner: - mod_perl/apache (setup/overview/use). - CGI.pm - using databases with DBI. - perlisms (some things look different in Perl!) - object-oriented perl. - regular expressions in practical use. - using "pod" in your scripts. - Book reviews - the good, the bad, the necessary. - Web resources. - Diffs between Unix and NT Perl. Tim Beavers: - Symbol Table/Type Globs Scott Walters: - Perl/Tk I also had a request to re-do perl 101 again. -- For a list of the ways which technology has failed to improve our quality of life, press 3. From mekla at geocities.com Wed Jan 26 20:04:17 2000 From: mekla at geocities.com (Shay Harding) Date: Thu Aug 5 00:16:03 2004 Subject: Phoenix.pm: Please help, my brain is fried Message-ID: <00012619144900.32123@cx949622-b.poria1.az.home.com> Hello all, Sorry I missed the last X meetings (not even sure how many any more). I do keep up with them here though. OK, I have the code below, and can't figure out why it is misbehaving and I am figuring it is something simple but due to working 80+ hours a week, I can't see it. This is really not part of any program, just something I was messing with. It basically creates a variable length string (6-12 alphanumeric characters), except the string returned is not alphanumeric. #!/usr/bin/perl5 my $count = 0; print "\n\n", create_login_id(), "\n"; sub create_login_id(){ srand; my $temp = ''; my $length = int(rand(6))+6; for (my $x = 1; $x <= $length; $x++){ my $t = get_char(); $temp .= chr($t)."($t)"; } return $temp; } sub get_char(){ srand; $count++; my $char = int(rand(57))+65; print $count, " ", chr($char), "\n"; get_char() if ($char >= 91 && $char <= 96); return $char; } Sample output is: This is the loops through the routine 'get_char' 1 C 2 p 3 p 4 ] 5 W 6 [ 7 M 8 x 9 b Here when it hits loop 4 it should do another loop since I exclude ASCII 93, and it does this except below as you can see it keeps ASCII 93 and doesn't use loop 5 value which would be valid. Using the 'my' scoping the number 4 value should go out of scope on the recursive call or am I missing something here? C(67)p(112)p(112)](93)[(91)x(120)b(98) Thanks. Shay From mekla at geocities.com Wed Jan 26 20:14:56 2000 From: mekla at geocities.com (Shay Harding) Date: Thu Aug 5 00:16:03 2004 Subject: Phoenix.pm: On another note Message-ID: <00012619265801.32123@cx949622-b.poria1.az.home.com> Hello again, I remember last week sometime some more messages came across regarding symbol tables and since I read them at around 2 am I was in no condition to go there :) I don't remember the full scope of the messages but some instances where variables do not get symbol table entries is when used with the 'my' scoping. If you do: my $var = 9000; $var never gets a symbol table entry. So if I had some weird thing like: my $var = sub { return chr($_[0]) }; print &$var(65), "\n\n"; Also if something is declare non-my but never defined it still gets a symbol table entry. I thought someone had said the opposite but can't remember? So if I did: $TEMP; It still gets a symbol table entry even though it is not defined. This is all from memory (which isn't very good) so if this was totally non-related to that thread of messages just disregard me as a rambling fool :) Also if I made a mistake in anything above, please correct me. Shay From kev at primenet.com Wed Jan 26 20:18:30 2000 From: kev at primenet.com (Kevin Buettner) Date: Thu Aug 5 00:16:03 2004 Subject: Phoenix.pm: Please help, my brain is fried In-Reply-To: Shay Harding "Phoenix.pm: Please help, my brain is fried" (Jan 26, 7:04pm) References: <00012619144900.32123@cx949622-b.poria1.az.home.com> Message-ID: <1000127021830.ZM13194@saguaro.lan> On Jan 26, 7:04pm, Shay Harding wrote: > OK, I have the code below, and can't figure out why it is misbehaving and I am > figuring it is something simple but due to working 80+ hours a week, I can't > see it. This is really not part of any program, just something I was messing > with. It basically creates a variable length string (6-12 alphanumeric > characters), except the string returned is not alphanumeric. > > > #!/usr/bin/perl5 > > my $count = 0; > print "\n\n", create_login_id(), "\n"; > > > > sub create_login_id(){ > srand; > my $temp = ''; > > my $length = int(rand(6))+6; > > for (my $x = 1; $x <= $length; $x++){ > my $t = get_char(); > $temp .= chr($t)."($t)"; > } > > return $temp; > } > > > sub get_char(){ > srand; > $count++; > > my $char = int(rand(57))+65; > print $count, " ", chr($char), "\n"; > > get_char() if ($char >= 91 && $char <= 96); > return $char; > } > > > > Sample output is: > > > This is the loops through the routine 'get_char' > > 1 C > 2 p > 3 p > 4 ] > 5 W > 6 [ > 7 M > 8 x > 9 b > > > Here when it hits loop 4 it should do another loop since I exclude ASCII 93, > and it does this except below as you can see it keeps ASCII 93 and doesn't use > loop 5 value which would be valid. Using the 'my' scoping the number 4 value > should go out of scope on the recursive call or am I missing something here? > > > C(67)p(112)p(112)](93)[(91)x(120)b(98) You might try changing get_char() if ($char >= 91 && $char <= 96); to $char = get_char() if ($char >= 91 && $char <= 96); Kevin -- Kevin Buettner kev@primenet.com, kevinb@redhat.com From root at nebuchadnezzar.slowass.net Wed Jan 26 21:05:05 2000 From: root at nebuchadnezzar.slowass.net (Scott Walters) Date: Thu Aug 5 00:16:04 2004 Subject: Phoenix.pm: Please help, my brain is fried In-Reply-To: <00012619144900.32123@cx949622-b.poria1.az.home.com> Message-ID: > Hello all, > > Sorry I missed the last X meetings (not even sure how many any more). I do keep > up with them here though. NO FORGIVENESS!!!! > sub get_char(){ > srand; > $count++; > > my $char = int(rand(57))+65; > print $count, " ", chr($char), "\n"; > > get_char() if ($char >= 91 && $char <= 96); get_char() while ($char >= 91 && $char <=96); > return $char; > } > > Try that and tell me if it's better. -scott From root at nebuchadnezzar.slowass.net Wed Jan 26 21:07:33 2000 From: root at nebuchadnezzar.slowass.net (Scott Walters) Date: Thu Aug 5 00:16:04 2004 Subject: Phoenix.pm: Please help, my brain is fried In-Reply-To: <00012619144900.32123@cx949622-b.poria1.az.home.com> Message-ID: > > sub get_char(){ > srand; > $count++; > > my $char = int(rand(57))+65; > print $count, " ", chr($char), "\n"; > > get_char() if ($char >= 91 && $char <= 96); $char=get_char() while($char >= 91 && $char <=96); > return $char; > } > Sorry, I'm one of those people who edits, saves, realizes he wasnt thinking, edits again, saves, then runs the code... Yes, $char does go out of scope, and there is a respectable chance each that you will get two values, both of which are out of range, in a row, in which case you need a while, not an if. From kev at primenet.com Wed Jan 26 20:56:10 2000 From: kev at primenet.com (Kevin Buettner) Date: Thu Aug 5 00:16:04 2004 Subject: Phoenix.pm: Please help, my brain is fried In-Reply-To: Shay Harding "Phoenix.pm: Please help, my brain is fried" (Jan 26, 7:04pm) References: <00012619144900.32123@cx949622-b.poria1.az.home.com> Message-ID: <1000127025610.ZM13249@saguaro.lan> Shay, Below is another approach to solving the problem you posted about recently. I like it because it is concise and contains no explicit loops. #!/usr/bin/perl print create_login_id(), "\n"; sub create_login_id { return join('', map $_->[int(rand(52))], (['a'..'z','A'..'Z']) x int(rand(6)+6)); } -- Kevin Buettner kev@primenet.com, kevinb@redhat.com From kev at primenet.com Wed Jan 26 21:08:18 2000 From: kev at primenet.com (Kevin Buettner) Date: Thu Aug 5 00:16:04 2004 Subject: Phoenix.pm: Please help, my brain is fried In-Reply-To: Scott Walters "Re: Phoenix.pm: Please help, my brain is fried" (Jan 26, 7:07pm) References: Message-ID: <1000127030818.ZM13306@saguaro.lan> On Jan 26, 7:07pm, Scott Walters wrote: > > > > sub get_char(){ > > srand; > > $count++; > > > > my $char = int(rand(57))+65; > > print $count, " ", chr($char), "\n"; > > > > get_char() if ($char >= 91 && $char <= 96); > $char=get_char() while($char >= 91 && $char <=96); > > return $char; > > } > > > > Sorry, I'm one of those people who edits, saves, realizes he wasnt > thinking, edits again, saves, then runs the code... > Yes, $char does go out of scope, and there is a respectable chance each > that you will get two values, both of which are out of range, in a row, > in which case you need a while, not an if. The use of "while" in this case is unnecessary. "if" is sufficient because the recursion handles the case of two or more successive out of range characters. Note that if your programming language supports recursive functions, then it is possible to write all of your code without the use of "while" or other looping constructs. (You get very good at this sort of thing if you program in a (pure) functional language for a while.) Kevin -- Kevin Buettner kev@primenet.com, kevinb@redhat.com From root at nebuchadnezzar.slowass.net Wed Jan 26 21:49:32 2000 From: root at nebuchadnezzar.slowass.net (Scott Walters) Date: Thu Aug 5 00:16:04 2004 Subject: Phoenix.pm: Please help, my brain is fried, now GD In-Reply-To: <1000127030818.ZM13306@saguaro.lan> Message-ID: > Unrelated topic.. anyone ever have to use the GD library before? I'm finding that it likes to core dump, and the documentation isn't quite accurate... is this the general consensous of the thing, or am I just being a high arse? > The use of "while" in this case is unnecessary. "if" is sufficient > because the recursion handles the case of two or more successive out > of range characters. Your right. I gave that about 10 seconds ;) I like your solution much better. Infact, it made me giggle and think, "life is good". > > Note that if your programming language supports recursive functions, > then it is possible to write all of your code without the use of > "while" or other looping constructs. (You get very good at this > sort of thing if you program in a (pure) functional language for a > while.) On the same token, if you have while(), you don't need recursion. I always thought using the evaluation stack instead of an array accessed by a loop was just a bit of sillyness which is a side effect from most languages wonderful ability to handle nest code, but complete inability to handle the variable name space (excepting of course the Forth language)... so I'm not usualy in a recursive mindset ;) Ah well. TMTOWTDI. > > Kevin > > -- > Kevin Buettner > kev@primenet.com, kevinb@redhat.com > From doug.miles at ns2.phoenix.bowne.com Thu Jan 27 11:36:13 2000 From: doug.miles at ns2.phoenix.bowne.com (Douglas E. Miles) Date: Thu Aug 5 00:16:04 2004 Subject: Phoenix.pm: PLUG'ers on PM list. References: <01CA656A687ED211926B00805F779140035D4FCE@az25exm02.geg.mot.com> Message-ID: <3890820D.6D7E7ADE@bpxinternet.com> Giffin Ron-P08295 wrote: > > Sorry to use PM list this way. In subscribing to new PLUG address, I've > locked myself out. Is new address plug-subscribe@lists.PLUG.phoenx.az.us ?? > This is being returned. Thanks and again sorry for the intrusion. > > -- Ron Sorry you didn't get a reply earlier. I'm catching up on 3 days of email. :) This is the address that is listed on the PLUG website: discuss-subscribe@plug.phoenix.az.us I'm not sure if that is the address you're looking for, so here is the page that lists (I assume) all of the PLUG lists: http://plug.phoenix.az.us/mail-list.shtml I hope this helps. Let me know if I misunderstood the question. Good luck! -- For a list of the ways which technology has failed to improve our quality of life, press 3. From Beaves at aol.com Thu Jan 27 12:17:15 2000 From: Beaves at aol.com (Beaves@aol.com) Date: Thu Aug 5 00:16:04 2004 Subject: Phoenix.pm: On another note Message-ID: <4c.ea1be4.25c1e5ab@aol.com> In a message dated 1/26/00 7:17:20 PM US Mountain Standard Time, mekla@geocities.com writes: << Also if something is declare non-my but never defined it still gets a symbol table entry. I thought someone had said the opposite but can't remember? So if I did: $TEMP; It still gets a symbol table entry even though it is not defined. >> Yes in this case TEMP would appear in the symbol table, but only because of initial parsing and compiling. (I believe for efficiency's sake) If you deleted TEMP from the symbol table as a line of code, then saying $TEMP right after does not create an entry.. For example: print "TEMP exists\n\n" if exists $main::{TEMP}; # will print 'TEMP exists' # even though you havn't gotten to that line yet. $TEMP; delete $main::{TEMP}; print "TEMP exists\n\n" if exists $main::{TEMP}; # will not print anything. $TEMP; print "TEMP exists\n\n" if exists $main::{TEMP}; # will not print anything. $TEMP=undef; print "TEMP exists\n\n" if exists $main::{TEMP}; # will print 'TEMP exists' I discovered this by accident when my little symbol table sub did not work as I was expecting. Also, Shay, I didn't quite get the point of your code If you do: my $var = 9000; $var never gets a symbol table entry. So if I had some weird thing like: my $var = sub { return chr($_[0]) }; print &$var(65), "\n\n"; It seemed like you were missing a conclusionary sentence... That sub reference above seems like it would work OK, am I missing something? Tim From Beaves at aol.com Thu Jan 27 12:33:39 2000 From: Beaves at aol.com (Beaves@aol.com) Date: Thu Aug 5 00:16:04 2004 Subject: Phoenix.pm: Please help, my brain is fried Message-ID: In a message dated 1/26/00 7:57:43 PM US Mountain Standard Time, kev@primenet.com writes: << sub create_login_id { return join('', map $_->[int(rand(52))], (['a'..'z','A'..'Z']) x int(rand(6)+6)); } >> Could you expand this code and put in a few comments about what it is doing. I like the conciseness, but I'm not exactly following what each section is doing... (the classic 'brevity versus understandability' dillemma) Thanks.. Tim From kev at primenet.com Thu Jan 27 13:18:47 2000 From: kev at primenet.com (Kevin Buettner) Date: Thu Aug 5 00:16:04 2004 Subject: Phoenix.pm: Please help, my brain is fried In-Reply-To: Beaves@aol.com "Re: Phoenix.pm: Please help, my brain is fried" (Jan 27, 1:33pm) References: Message-ID: <1000127191847.ZM14856@saguaro.lan> On Jan 27, 1:33pm, Beaves@aol.com wrote: > In a message dated 1/26/00 7:57:43 PM US Mountain Standard Time, > kev@primenet.com writes: > > << sub create_login_id { > return join('', map $_->[int(rand(52))], > (['a'..'z','A'..'Z']) x int(rand(6)+6)); > } >> > > Could you expand this code and put in a few comments about what it is doing. > I like the conciseness, but I'm not exactly following what each section is > doing... > (the classic 'brevity versus understandability' dillemma) > > Thanks.. Okay. Let's break it into pieces. I'll start at the inside and work outwards. int(rand(6)+6) This evaluates to an integer, chosen pseudo-randomly between 6 and 11 inclusive. ['a'..'z','A'..'Z'] This creates a list reference. The list being referred to contains the lower case letters and the uppercase letters. The fact that it's a list reference is very important for use with the map. (It's important because a list reference is a scalar and map needs to operate on a list of scalars, not a list of lists.) (['a'..'z','A'..'Z']) x int(rand(6)+6)) The 'x' is the repetition operator. If you say something like "abc" x 3 this evaluates to the string "abcabcabc". The repetition operator also works on lists. By wrapping ['a'..'z','A'..'Z'] in parens, I created a list of one element. (The one element is the list reference that I talked about above). So the complete expression, (['a'..'z','A'..'Z']) x int(rand(6)+6)) will create a list of N hash references to a list containing our upper/lowercase alphabetic scalars, where N is an integer chosen pseudo-randomly between 6 and 11. To make this more concrete, suppose that int(rand(6)+6) evaluated to 6. Then the expression under consideration would evaluate to ( ['a','b','c','d',...,'z','A','B','C','D',...,'Z'], ['a','b','c','d',...,'z','A','B','C','D',...,'Z'], ['a','b','c','d',...,'z','A','B','C','D',...,'Z'], ['a','b','c','d',...,'z','A','B','C','D',...,'Z'], ['a','b','c','d',...,'z','A','B','C','D',...,'Z'], ['a','b','c','d',...,'z','A','B','C','D',...,'Z'] ) except that it would be represented much more efficiently in that it would contain six copies of the same list reference. map $_->[int(rand(52))], (['a'..'z','A'..'Z']) x int(rand(6)+6) We've just finished discussion on what the second argument of the map is. To recap, it'll be a list of list references. Each list reference will refer to a list of length 52 containing the upper and lower case letters. The map will construct a new list out of the list in the second argument (which is our list of list references). It will do this by considering each element in succesion and assign said element to $_. It will then evaluate the first argument to construct the list argument(s) corresponding to the argument under consideration. (If you've never seen map before, it might be instructive to write a few example programs to test it out for yourself.) So... in the context of doing the map, $_ will be set to one of the list references and $_->[int(rand(52))] will cause one of the 'a'..'z','A'..'Z' to be chosen. When the map is done, it will have constructed a list containing N elements where each element is one of our letters chosen at random. join('', map $_->[int(rand(52))], (['a'..'z','A'..'Z']) x int(rand(6)+6)) This simply turns the list that map created into a scalar. I.e, it concatenates the random letters chosen by the above map into a scalar suitable for returning from the function. Kevin -- Kevin Buettner kev@primenet.com, kevinb@redhat.com From Mark.Pease at motorola.com Thu Jan 27 13:43:51 2000 From: Mark.Pease at motorola.com (Mark Pease) Date: Thu Aug 5 00:16:04 2004 Subject: Phoenix.pm: Please help, my brain is fried References: Message-ID: <38909FF7.3D63420A@motorola.com> > Beaves@aol.com wrote: > << sub create_login_id { > return join('', map $_->[int(rand(52))], > (['a'..'z','A'..'Z']) x int(rand(6)+6)); > } >> > > Could you expand this code and put in a few comments about what it is doing. > I like the conciseness, but I'm not exactly following what each section is > doing... Let's split out the sections in the order that they are executed: # Pick the number of characters to have in the login id. It must have # at least 6 and no more than 12 elements. $id_length = int(rand(6)+6); # Build an array where each element is a reference to another array # that contains all of the upper and lower case letters (52 elements in each). # (The 'x' operator, in array context, will build an array where each # element is the same.) @passwd = (['a'..'z','A'..'Z']) x $id_length); # Now pick one letter from each array reference. # (Map will execute a chunck of code on each element of an array, # and return an array where each element contains the value returned # from the chunck of code.) @passwd = map $_->[int(rand(52)], @passwd; # The array now contains the login id, one character per element. # Join all of the character together into one string, and return. return join '', @passwd; > (the classic 'brevity versus understandability' dillemma) No dillemma, understandablility should always win over brevity. -- Mark Pease Mark.Pease@mototorola.com Motorola DigitalDNA(tm) Laboratories perl@perl.sps.mot.com 2100 E. Elliot Rd. Phone:(602)413-8191 Mail Stop: AZ34 EL701 Tempe, AZ 85284 Pager:(800)381-3304 FAX:(602)413-8183 Co-Author (with Carl Dichter) of "Software Engineering with Perl" From Ron.Giffin at motorola.com Thu Jan 27 14:21:00 2000 From: Ron.Giffin at motorola.com (Giffin Ron-P08295) Date: Thu Aug 5 00:16:04 2004 Subject: Phoenix.pm: PLUG'ers on PM list. Message-ID: <01CA656A687ED211926B00805F779140035D4FD2@az25exm02.geg.mot.com> Sorry you didn't get a reply earlier. I'm catching up on 3 days of email. :) This is the address that is listed on the PLUG website: discuss-subscribe@plug.phoenix.az.us I'm not sure if that is the address you're looking for, so here is the page that lists (I assume) all of the PLUG lists: http://plug.phoenix.az.us/mail-list.shtml I hope this helps. Let me know if I misunderstood the question. Good luck! Thanks Doug, They have a new list address. I think I have it right now. -- Ron From kev at primenet.com Thu Jan 27 14:49:02 2000 From: kev at primenet.com (Kevin Buettner) Date: Thu Aug 5 00:16:04 2004 Subject: Phoenix.pm: Please help, my brain is fried In-Reply-To: Mark Pease "Re: Phoenix.pm: Please help, my brain is fried" (Jan 27, 12:43pm) References: <38909FF7.3D63420A@motorola.com> Message-ID: <1000127204902.ZM15080@saguaro.lan> On Jan 27, 12:43pm, Mark Pease wrote: > # Pick the number of characters to have in the login id. It must have > # at least 6 and no more than 12 elements. > $id_length = int(rand(6)+6); > > # Build an array where each element is a reference to another array > # that contains all of the upper and lower case letters (52 elements in > each). > # (The 'x' operator, in array context, will build an array where each > # element is the same.) > @passwd = (['a'..'z','A'..'Z']) x $id_length); > > # Now pick one letter from each array reference. > # (Map will execute a chunck of code on each element of an array, > # and return an array where each element contains the value returned > # from the chunck of code.) > @passwd = map $_->[int(rand(52)], @passwd; > > # The array now contains the login id, one character per element. > # Join all of the character together into one string, and return. > return join '', @passwd; > > > > (the classic 'brevity versus understandability' dillemma) > > No dillemma, understandablility should always win over brevity. Yes, but which code is more understandable, code which is brief and to the point, or code which is heavily commented with lots of intermediate variables thrown in? I would probably comment the example under consideration as follows... # Create a string suitable for use as a login id. sub create_login_id { # Return a string consisting of random alphabetic characters # whose length (chosen randomly) is between 6 and 11 inclusive. return join('', map $_->[int(rand(52))], (['a'..'z','A'..'Z']) x int(rand(6)+6)); } I would not break the return expression up into pieces except for pedagogical purposes. Kevin -- Kevin Buettner kev@primenet.com, kevinb@redhat.com From Mark.Pease at motorola.com Thu Jan 27 15:27:59 2000 From: Mark.Pease at motorola.com (Mark Pease) Date: Thu Aug 5 00:16:04 2004 Subject: Phoenix.pm: Please help, my brain is fried References: <38909FF7.3D63420A@motorola.com> <1000127204902.ZM15080@saguaro.lan> Message-ID: <3890B85F.CCD55541@motorola.com> Kevin Buettner wrote: > >> > No dillemma, understandablility should always win over brevity. > > Yes, but which code is more understandable, code which is brief > and to the point, or code which is heavily commented with lots > of intermediate variables thrown in? > And I agree. I "code" that I use in the reply was not how I would normally write something. If a chunk of code is not easily self explanatory, I first try to re-write it, and then comment it if I can't. If I were to write this sub to use, it would have somewhat similar to the one you wrote with the comments that you used, but I might not have used the map, which seems to be the thing that confuses people. This example is a simple used of map, so I might have done it the same way. For the most part, I avoid map because I have spent to much time trying to decode what I wrote two, or more, months earlier! -- Mark Pease Mark.Pease@mototorola.com Motorola DigitalDNA(tm) Laboratories perl@perl.sps.mot.com 2100 E. Elliot Rd. Phone:(602)413-8191 Mail Stop: AZ34 EL701 Tempe, AZ 85284 Pager:(800)381-3304 FAX:(602)413-8183 Co-Author (with Carl Dichter) of "Software Engineering with Perl" From mekla at geocities.com Thu Jan 27 16:27:49 2000 From: mekla at geocities.com (Shay Harding) Date: Thu Aug 5 00:16:04 2004 Subject: Phoenix.pm: On another note In-Reply-To: <4c.ea1be4.25c1e5ab@aol.com> References: <4c.ea1be4.25c1e5ab@aol.com> Message-ID: <00012715323200.26776@cx949622-b.poria1.az.home.com> > print "TEMP exists\n\n" if exists $main::{TEMP}; # will print 'TEMP exists' > # even though you havn't gotten to that line yet. > $TEMP; > delete $main::{TEMP}; > print "TEMP exists\n\n" if exists $main::{TEMP}; # will not print anything. > $TEMP; > print "TEMP exists\n\n" if exists $main::{TEMP}; # will not print anything. > $TEMP=undef; > print "TEMP exists\n\n" if exists $main::{TEMP}; # will print 'TEMP exists' > > I discovered this by accident when my little symbol table sub did not work as > I was expecting. I see what you were saying now. The above example made it much clearer. Thanks. > Also, Shay, I didn't quite get the point of your code > If you do: > > my $var = 9000; > > $var never gets a symbol table entry. So if I had some weird thing like: > > my $var = sub { return chr($_[0]) }; > print &$var(65), "\n\n"; > > It seemed like you were missing a conclusionary sentence... > That sub reference above seems like it would work OK, am I missing something? > > Tim I thought the whole thing that started this was someone was trying to find if a particular sub-routine existed by accessing the symbol table? In the above instance the sub routine is anonymous and scoped via my so it has no symbol table entry. It's referenced via a SCALAR so to see if an anonymous sub routine was available would you have to look for the SCALAR which may not be there depending on scoping. Wish I could remember the whole purpose of finding the sub-routing in the first place :) Maybe the above example had nothing to do with it? Shay From mekla at geocities.com Thu Jan 27 20:39:19 2000 From: mekla at geocities.com (Shay Harding) Date: Thu Aug 5 00:16:04 2004 Subject: Phoenix.pm: Tried Perl debugger on this code (Was Please help, my brain is fried) In-Reply-To: <1000127191847.ZM14856@saguaro.lan> References: <1000127191847.ZM14856@saguaro.lan> Message-ID: <00012720083900.27559@cx949622-b.poria1.az.home.com> > > kev@primenet.com writes: > > > > << sub create_login_id { > > return join('', map $_->[int(rand(52))], > > (['a'..'z','A'..'Z']) x int(rand(6)+6)); > > } >> > > I like the above code, but I think my whole question was missed... I really didn't want to fix it since I could've done that, but I wanted to know what was wrong with it and why it was not acting as expected. I already had fixed it with much the same method, although not as cool as the one above :) Can anyone shed light as to why this code is not working. Has nothing to do with an 'if' statement or the use of 'while', which by the way will put it into an infinite loop the first pass through if I don't change: get_char while ($char >= 91 && $char <= 96); to $char = get_char while ($char >= 91 && $char <= 96); I'm not even sure why the above is also true? I don't know a lot of the compiler and how it works, etc. Maybe inside the parens of the first while loop it goes to 0 (false) or 1 (true) and then the value of $char doesn't matter, and never changes as in the second example. Just a guess. I stepped this thing through the perl debugger and I think I came out more confused than enlightened :) Basically everything works fine. If 'get_char' is called and it ends up with an ASCII 93, it correctly recurses and $char is empty. It goes and reassignes $char (say to ASCII 79) and then gets passed the 'if' block. This next part is strange in that the debugger tells me it is on the line 'return $char'. I execute that line and do 'p $char'. It tells me the value of the return is '93'?? Somehow it is returning the last value of $char. I can see this happening if I did something like 'local $char' since local just masks the old value with a new, temporary one. My understanding of 'my' is that the variable never gets a symbol table entry and thus is not saved anywhere, and is destroyed upon exit of the current block. Question about Perl recursion... did I ever exit the 'if' block? Does Perl 'anchor' me in the if block until I evaluate to false (thereby never destroying the old value of $char) then reassign the old value and overwrite the current, good value? Shay -------------------------------------------------------------- #!/usr/bin/perl5 my $count = 0; print "\n\n", create_login_id(), "\n"; sub create_login_id(){ srand; my $temp = ''; my $length = int(rand(6))+6; for (my $x = 1; $x <= $length; $x++){ my $t = get_char(); $temp .= chr($t)."($t)"; } return $temp; } sub get_char(){ srand; $count++; my $char = int(rand(57))+65; print $count, " ", chr($char), "\n"; get_char() if ($char >= 91 && $char <= 96); return $char; } From mgalyean at acm.org Thu Jan 27 21:53:20 2000 From: mgalyean at acm.org (Marty Galyean) Date: Thu Aug 5 00:16:04 2004 Subject: Phoenix.pm: Tried Perl debugger on this code (Was Please help, my brain is fried) References: <1000127191847.ZM14856@saguaro.lan> <00012720083900.27559@cx949622-b.poria1.az.home.com> Message-ID: <389112B0.5047B84F@acm.org> Hi, I'm mostly a lurker, being too busy shoveling myself out of debt, but this one got me thinking. It works fine for me with the below as the only alteration to the original (that someone else previously suggested): $char = get_char() if ($char >= 91 && $char <= 96); You were correct earlier when you wrote that with the recursion you shouldn't need the 'while'; the 'if' becomes a 'while' via recursion. Are you sure you have the '$char = getchar()' rather than just the 'getchar()' in what you are executing, I only ask because I notice the code you last posted doesn't have it. When I find myself circling a blind spot I give up and take a nap; pretend I'm giving up on it. Thats when it hits ya; or at least you get your life back for awhile. Rgds, Marty Shay Harding wrote: > > > > kev@primenet.com writes: > > > > > > << sub create_login_id { > > > return join('', map $_->[int(rand(52))], > > > (['a'..'z','A'..'Z']) x int(rand(6)+6)); > > > } >> > > > > > I like the above code, but I think my whole question was missed... > > I really didn't want to fix it since I could've done that, but I wanted to know > what was wrong with it and why it was not acting as expected. I already had > fixed it with much the same method, although not as cool as the one above :) > > Can anyone shed light as to why this code is not working. Has nothing to do > with an 'if' statement or the use of 'while', which by the way will put it into > an infinite loop the first pass through if I don't change: > > get_char while ($char >= 91 && $char <= 96); > > to > > $char = get_char while ($char >= 91 && $char <= 96); > > I'm not even sure why the above is also true? I don't know a lot of the > compiler and how it works, etc. Maybe inside the parens of the first while loop > it goes to 0 (false) or 1 (true) and then the value of $char doesn't matter, > and never changes as in the second example. Just a guess. > > I stepped this thing through the perl debugger and I think I came out more > confused than enlightened :) > > Basically everything works fine. If 'get_char' is called and it ends up with an > ASCII 93, it correctly recurses and $char is empty. It goes and reassignes > $char (say to ASCII 79) and then gets passed the 'if' block. This next part is > strange in that the debugger tells me it is on the line 'return $char'. I > execute that line and do 'p $char'. It tells me the value of the return is > '93'?? Somehow it is returning the last value of $char. I can see this > happening if I did something like 'local $char' since local just masks the old > value with a new, temporary one. My understanding of 'my' is that the variable > never gets a symbol table entry and thus is not saved anywhere, and is > destroyed upon exit of the current block. Question about Perl recursion... did > I ever exit the 'if' block? Does Perl 'anchor' me in the if block until I > evaluate to false (thereby never destroying the old value of $char) then > reassign the old value and overwrite the current, good value? > > Shay > > -------------------------------------------------------------- > > #!/usr/bin/perl5 > > my $count = 0; > print "\n\n", create_login_id(), "\n"; > > sub create_login_id(){ > srand; > my $temp = ''; > > my $length = int(rand(6))+6; > > for (my $x = 1; $x <= $length; $x++){ > my $t = get_char(); > $temp .= chr($t)."($t)"; > } > > return $temp; > } > > sub get_char(){ > srand; > $count++; > > my $char = int(rand(57))+65; > print $count, " ", chr($char), "\n"; > > get_char() if ($char >= 91 && $char <= 96); > return $char; > } From mekla at geocities.com Thu Jan 27 22:20:48 2000 From: mekla at geocities.com (Shay Harding) Date: Thu Aug 5 00:16:04 2004 Subject: Phoenix.pm: Tried Perl debugger on this code (Was Please help, my brain is fried) In-Reply-To: <389112B0.5047B84F@acm.org> References: <00012720083900.27559@cx949622-b.poria1.az.home.com> <389112B0.5047B84F@acm.org> Message-ID: <00012721305200.27913@cx949622-b.poria1.az.home.com> > Hi, I'm mostly a lurker, being too busy shoveling myself out of debt, > but this one got me thinking. > > It works fine for me with the below as the only alteration to the > original (that someone else previously suggested): > > $char = get_char() if ($char >= 91 && $char <= 96); > > You were correct earlier when you wrote that with the recursion you > shouldn't need the 'while'; the 'if' becomes a 'while' via recursion. > > Are you sure you have the '$char = getchar()' rather than just the > 'getchar()' in what you are executing, I only ask because I notice the > code you last posted doesn't have it. When I find myself circling a > blind spot I give up and take a nap; pretend I'm giving up on it. Thats > when it hits ya; or at least you get your life back for awhile. > > Rgds, > Marty Yeah it works fine with that modification, but *why* does it matter? This is what I truly want to know. Does it have to do with the 'if' block and recursion. Basically here is what happens when I look at it via the debugger: 1: get_char() is called 2: $char gets an initial ASCII 93 3: Hits the 'if' block and recurses 4: $char is now undefined (at this point anyway) 5: $char gets a value of 73 6: Passes if block 7: Is going to return $char 8: $char is set back to 93 just before return When it recurses, is this treated as another block of code so all variables declared via 'my' exist outside the original block that triggered the recursive call? I guess the best way I can describe what I think is going on is by the following code. This is basically what happens on this recursive call I believe. sub get_char(){ srand; $count++; # $char gets value of 93 my $char = int(rand(57))+65; print $count, " ", chr($char), "\n"; # evaluates to true, calls subroutine # This block's $char = 93 if ($char >= 91 && $char <= 96){ get_char_next(); #73 returned but no var to 'catch' it } # returns 93 since other $char went out of scope return $char; sub get_char_next(){ srand; $count++; # This block's $char = 73 my $char = int(rand(57))+65; print $count, " ", chr($char), "\n"; # Skips over this block $char = get_char_next() if ($char >= 91 && $char <= 96); #returns 73 return $char; } } From mgalyean at acm.org Thu Jan 27 23:01:13 2000 From: mgalyean at acm.org (Marty Galyean) Date: Thu Aug 5 00:16:04 2004 Subject: Phoenix.pm: Tried Perl debugger on this code (Was Please help, my brain is fried) References: <00012720083900.27559@cx949622-b.poria1.az.home.com> <389112B0.5047B84F@acm.org> <00012721305200.27913@cx949622-b.poria1.az.home.com> Message-ID: <38912299.848FB7BC@acm.org> Is your question - why does it matter that: $char = get_char() if ($char >= 91 && $char <= 96); works and: get_char() if ($char >= 91 && $char <= 96); doesn't? Because in the second case the value returned by get_char() isn't assigned to anything, that's why; and the '$char' within the recursive call is its own 'my' var within that recursive call and is totally unrelated to the higher level call because of the 'my' so it evaporates without passing on its value to the other $char a level up. In short, each level's $char is totally distinct and you are throwing away the returned value from the recursive call. You didn't take that nap, did you. Shay Harding wrote: > > > Hi, I'm mostly a lurker, being too busy shoveling myself out of debt, > > but this one got me thinking. > > > > It works fine for me with the below as the only alteration to the > > original (that someone else previously suggested): > > > > $char = get_char() if ($char >= 91 && $char <= 96); > > > > You were correct earlier when you wrote that with the recursion you > > shouldn't need the 'while'; the 'if' becomes a 'while' via recursion. > > > > Are you sure you have the '$char = getchar()' rather than just the > > 'getchar()' in what you are executing, I only ask because I notice the > > code you last posted doesn't have it. When I find myself circling a > > blind spot I give up and take a nap; pretend I'm giving up on it. Thats > > when it hits ya; or at least you get your life back for awhile. > > > > Rgds, > > Marty > > Yeah it works fine with that modification, but *why* does it matter? This is > what I truly want to know. Does it have to do with the 'if' block and > recursion. Basically here is what happens when I look at it via the debugger: > > 1: get_char() is called > 2: $char gets an initial ASCII 93 > 3: Hits the 'if' block and recurses > 4: $char is now undefined (at this point anyway) > 5: $char gets a value of 73 > 6: Passes if block > 7: Is going to return $char > 8: $char is set back to 93 just before return > > When it recurses, is this treated as another block of code so all variables > declared via 'my' exist outside the original block that triggered the > recursive call? > > I guess the best way I can describe what I think is going on is by the > following code. This is basically what happens on this recursive call I believe. > > sub get_char(){ > srand; > $count++; > > # $char gets value of 93 > > my $char = int(rand(57))+65; > > print $count, " ", chr($char), "\n"; > > > # evaluates to true, calls subroutine > # This block's $char = 93 > > if ($char >= 91 && $char <= 96){ > get_char_next(); > > #73 returned but no var to 'catch' it > > } > > # returns 93 since other $char went out of scope > > return $char; > > sub get_char_next(){ > srand; > $count++; > > # This block's $char = 73 > > my $char = int(rand(57))+65; > print $count, " ", chr($char), "\n"; > > # Skips over this block > > $char = get_char_next() if ($char >= 91 && $char <= 96); > > #returns 73 > > return $char; > } > > } From kev at primenet.com Thu Jan 27 23:14:25 2000 From: kev at primenet.com (Kevin Buettner) Date: Thu Aug 5 00:16:04 2004 Subject: Phoenix.pm: Tried Perl debugger on this code (Was Please help, my brain is fried) In-Reply-To: Shay Harding "Phoenix.pm: Tried Perl debugger on this code (Was Please help, my brain is fried)" (Jan 27, 7:39pm) References: <1000127191847.ZM14856@saguaro.lan> <00012720083900.27559@cx949622-b.poria1.az.home.com> Message-ID: <1000128051425.ZM16079@saguaro.lan> On Jan 27, 7:39pm, Shay Harding wrote: > I like the above code, but I think my whole question was missed... [...] > sub get_char(){ > srand; > $count++; > > my $char = int(rand(57))+65; > print $count, " ", chr($char), "\n"; > > get_char() if ($char >= 91 && $char <= 96); > return $char; > } There were a number of questions in the section I snipped. I'll attempt to answer what I think are the relevant ones. (I'll skip the ones regarding the perl debugger since I rarely use it. It confuses me too.) Before I get into a discussion of why the above code doesn't work and the reasons why, I hope you'll permit me to simplify it somewhat by removing code which I suspect was added for debugging purposes. My rewrite (with line numbers added to make discussion easier) looks like this: 1 sub get_char { 2 my $char = int(rand(57))+65; 3 4 get_char() if ($char >= 91 && $char <= 96); 5 return $char; 6 } The intent of the above code is to return the ASCII code for a randomly chosen alphabetic character, i.e, one of 'A'..'Z','a'..'z'. Let us begin our discussion with line 2. We would like line 2 to set $char to an integer between 65 ('A') and 122 ('z') inclusive. As written, this line will fail to ever set $char to 122. It should be changed to read as follows: 2a my $char = int(rand(58))+65; In order to verify that this is correct, remember that int(rand(58)) will evaluate to an integer between 0 and 57 inclusive. This means that the lowest value achievable by $char will be 65 and the greatest is 65+57=122, which is precisely what we want. Now let's turn our attention to the 'my' declaration. The 'my' declaration declares a statically scoped local variable. The scope extends from the point of the declaration to the ending right curly brace on line 6. This means that when get_char is invoked, $char is only visible between lines 2 and 6 for that invocation. (Go back and read "for that invocation" again; it's important. Let's consider an example. Suppose you enter get_char and were unfortunate enough to have $char set to 91 ('['). Once you get down to line 4, perl will invoke get_char again because it happens to fall between 91 and 96 inclusive. Now the next bit is *very* important. When you enter get_char again, you get a brand spanking new $char that is only visible between lines 2 and 6 (for this invocation). The $char in the calling invocation is *not* visible to the current one. Let's suppose in this invocation that you get $char set to 65 ('A'). That means that line 4 will *NOT* cause get_char to be invoked yet again. Line 5 will cause 65 to be returned. So now we're back in the original invocation of get_char. What happened to our 65 returned by the recursive call? It is discarded because the code, as written, doesn't do anything with it. $char in this invocation is still set to 91 and that is what is returned. Let's consider what happens with one attempt to "fix" this code: 4a get_char() while ($char >= 91 && $char <= 96); In the above line (4a), the 'if' has been replaced by a 'while'. This is quite possibly worse than the original version because (as you observed), it is prone to hanging. Reread my above example. The only difference here is that when get_char returns, the while statement will check again to see if $char has changed so that it is no longer in the indicated range. Well, it *can't* have changed. There's no way it could have changed since the recursive invocation of get_char has no way to affect the instance of $char in the frame under consideration. Thus, line 4a will continue to call get_char() over and over again in the vain hope that $char will somehow get changed. Finally, let's consider a correct fix: 4b $char = get_char() if ($char >= 91 && $char <= 96); This version does two things that the original version did not. First, it actually does something with the return value of get_char. If you have a subroutine which returns a value and you also have instances of calls to that subroutine that do nothing with the return value, that should be a red flag that something is likely wrong. Second, and more importantly, line 4b sets $char to the return value of the recursive call to get_char. This means that $char in the outermost invocation of get_char will be set to a non out-of-range character. Here is the final corrected version of get_char: 1 sub get_char { 2a my $char = int(rand(58))+65; 3 4b $char = get_char() if ($char >= 91 && $char <= 96); 5 return $char; 6 } You might wonder if this version is susceptible to infinite recursion. It is not, so long as the pseudo-random number generator doesn't get stuck in a cycle of generating only out-of-range characters. Eventually, there will be a recursive invocation which will pick an in-range character. When this happens, the in-range character will propogate back to the outermost invocation due to the assignment statement added to 4b. I suspect that much of your confusion stems from the difference between 'my' and 'local'. I took a look at the perlfaq7 man page in hopes that it would contain a cogent discussion of the issues that I could refer you to, but after reading it I concluded that you may well have been misled by the cursory treatment that it gives to the matter. (It says nothing about what happens when you have recursive subroutines. In fact, it does give the impression that there's only one copy which is certainly not the case.) So, instead, I'll direct your attention to the perlsub man page. See the section called "Private Variables via my()". In particular, the following section is especially relevant... Unlike dynamic variables created by the "local" operator, lexical variables declared with "my" are totally hidden from the outside world, including any called subroutines (even if it's the same subroutine called from itself or elsewhere--every call gets its own copy). Note that last parenthesized bit, "every call gets its own copy". Kevin -- Kevin Buettner kev@primenet.com, kevinb@redhat.com From Beaves at aol.com Thu Jan 27 23:48:20 2000 From: Beaves at aol.com (Beaves@aol.com) Date: Thu Aug 5 00:16:04 2004 Subject: Phoenix.pm: Reason for finding defined sub Message-ID: <22.145a30b.25c287a4@aol.com> Here is the situation I had in which I wanted to know if a sub was defined or not. Just in case anyone else runs into anything similar... In this program, I have allowed two techniques for building a 'stored' FormVar object: You can either define a sub by the name of 'load_' or put the object in a file named .fv which will return the desired object. The 'load...' way would take priority. The flow would be: Use a sub by the name of 'load_' if it exists, otherwise, require the file .fv, otherwise, fatal error, "object not found". Obviously, you can't just call the sub, or you'll croak if it doesn't exist. You could put it in an eval, and check the $@ for errors. But it turns out that it isn't really all that difficult to check the symbol table. The simple line below will suffice. &load_ if defined &load_; In fact, this example was there for me all the while in the explanation of the function 'defined' in the Camel Book. That's it really. Tim From Beaves at aol.com Thu Jan 27 23:52:00 2000 From: Beaves at aol.com (Beaves@aol.com) Date: Thu Aug 5 00:16:04 2004 Subject: Phoenix.pm: Please help, my brain is fried Message-ID: Thanks to Kevin and Mark. Two excellent explanations, and I appreciate the time you took to spell the code out for me. Hopefully, I wasn't the only one who benefitted... I'll be saving these gems in my snippets file for future reference. Tim From mekla at geocities.com Sun Jan 30 10:08:10 2000 From: mekla at geocities.com (Shay Harding) Date: Thu Aug 5 00:16:04 2004 Subject: Phoenix.pm: Tried Perl debugger on this code (Was Please help, my brain is fried) In-Reply-To: <1000128051425.ZM16079@saguaro.lan> References: <00012720083900.27559@cx949622-b.poria1.az.home.com> <1000128051425.ZM16079@saguaro.lan> Message-ID: <00013009091401.07586@cx949622-b.poria1.az.home.com> That's what I thought, but wanted to verify. Thanks. Shay > > > I like the above code, but I think my whole question was missed... > > [...] > > > sub get_char(){ > > srand; > > $count++; > > > > my $char = int(rand(57))+65; > > print $count, " ", chr($char), "\n"; > > > > get_char() if ($char >= 91 && $char <= 96); > > return $char; > > } > > There were a number of questions in the section I snipped. I'll attempt > to answer what I think are the relevant ones. (I'll skip the ones > regarding the perl debugger since I rarely use it. It confuses me > too.) > > Before I get into a discussion of why the above code doesn't work and > the reasons why, I hope you'll permit me to simplify it somewhat by > removing code which I suspect was added for debugging purposes. My > rewrite (with line numbers added to make discussion easier) looks like > this: > > 1 sub get_char { > 2 my $char = int(rand(57))+65; > 3 > 4 get_char() if ($char >= 91 && $char <= 96); > 5 return $char; > 6 } > > The intent of the above code is to return the ASCII code for a > randomly chosen alphabetic character, i.e, one of 'A'..'Z','a'..'z'. > > Let us begin our discussion with line 2. We would like line 2 to > set $char to an integer between 65 ('A') and 122 ('z') inclusive. > As written, this line will fail to ever set $char to 122. It > should be changed to read as follows: > > 2a my $char = int(rand(58))+65; > > In order to verify that this is correct, remember that int(rand(58)) > will evaluate to an integer between 0 and 57 inclusive. This means > that the lowest value achievable by $char will be 65 and the greatest > is 65+57=122, which is precisely what we want. > > Now let's turn our attention to the 'my' declaration. The 'my' > declaration declares a statically scoped local variable. The > scope extends from the point of the declaration to the ending > right curly brace on line 6. This means that when get_char > is invoked, $char is only visible between lines 2 and 6 for that > invocation. (Go back and read "for that invocation" again; it's > important. > > Let's consider an example. Suppose you enter get_char and were > unfortunate enough to have $char set to 91 ('['). Once you get down > to line 4, perl will invoke get_char again because it happens to fall > between 91 and 96 inclusive. > > Now the next bit is *very* important. When you enter get_char again, > you get a brand spanking new $char that is only visible between > lines 2 and 6 (for this invocation). The $char in the calling > invocation is *not* visible to the current one. Let's suppose in > this invocation that you get $char set to 65 ('A'). That means that > line 4 will *NOT* cause get_char to be invoked yet again. Line 5 > will cause 65 to be returned. > > So now we're back in the original invocation of get_char. What > happened to our 65 returned by the recursive call? It is discarded > because the code, as written, doesn't do anything with it. $char > in this invocation is still set to 91 and that is what is returned. > > Let's consider what happens with one attempt to "fix" this code: > > 4a get_char() while ($char >= 91 && $char <= 96); > > In the above line (4a), the 'if' has been replaced by a 'while'. This > is quite possibly worse than the original version because (as you > observed), it is prone to hanging. Reread my above example. The only > difference here is that when get_char returns, the while statement > will check again to see if $char has changed so that it is no longer > in the indicated range. Well, it *can't* have changed. There's no > way it could have changed since the recursive invocation of get_char > has no way to affect the instance of $char in the frame under > consideration. Thus, line 4a will continue to call get_char() over > and over again in the vain hope that $char will somehow get changed. > > Finally, let's consider a correct fix: > > 4b $char = get_char() if ($char >= 91 && $char <= 96); > > This version does two things that the original version did not. > > First, it actually does something with the return value of get_char. > If you have a subroutine which returns a value and you also have > instances of calls to that subroutine that do nothing with the return > value, that should be a red flag that something is likely wrong. > > Second, and more importantly, line 4b sets $char to the return value > of the recursive call to get_char. This means that $char in the > outermost invocation of get_char will be set to a non out-of-range > character. > > Here is the final corrected version of get_char: > > 1 sub get_char { > 2a my $char = int(rand(58))+65; > 3 > 4b $char = get_char() if ($char >= 91 && $char <= 96); > 5 return $char; > 6 } > > You might wonder if this version is susceptible to infinite recursion. > It is not, so long as the pseudo-random number generator doesn't get > stuck in a cycle of generating only out-of-range characters. Eventually, > there will be a recursive invocation which will pick an in-range > character. When this happens, the in-range character will propogate > back to the outermost invocation due to the assignment statement > added to 4b. > > I suspect that much of your confusion stems from the difference between > 'my' and 'local'. I took a look at the perlfaq7 man page in hopes > that it would contain a cogent discussion of the issues that I could > refer you to, but after reading it I concluded that you may well have > been misled by the cursory treatment that it gives to the matter. (It > says nothing about what happens when you have recursive subroutines. > In fact, it does give the impression that there's only one copy which > is certainly not the case.) > > So, instead, I'll direct your attention to the perlsub man page. See > the section called "Private Variables via my()". In particular, the > following section is especially relevant... > > Unlike dynamic variables created by the "local" operator, > lexical variables declared with "my" are totally hidden > from the outside world, including any called subroutines > (even if it's the same subroutine called from itself or > elsewhere--every call gets its own copy). > > Note that last parenthesized bit, "every call gets its own copy". > > Kevin > > -- > Kevin Buettner > kev@primenet.com, kevinb@redhat.com