From bke at bkecc.com Thu Oct 9 13:10:59 2003 From: bke at bkecc.com (Bradley K. Embree) Date: Mon Aug 2 21:30:58 2004 Subject: [kamloops-pm] Hello Message-ID: Well so far not much traffic eh? But what do you expect from a list with 5 people on it. I was wondering what we are all wanting to get out of Kamloops Perl Mongers. Is anyone interested in having meetings? Do we want to simply keep it to discussion of Perl on the mailing list? Thoughts? I am waiting to hear back from the pm.org people about an issue with the web space for http://kamloops.pm.org/ but hopefully soon there will be a basic informational page up there. I am not a Perl guru (I have been programming in Perl for a little over two years now) but I would be willing to give some talks/presentations on the basics of Perl OO programming (see http://www.manning.com/Conway/ for a great book on Perl OO), writing GUI applications with wxPerl (http://wxperl.sourceforge.net/), and some basic Perl programming tips (i.e. use strict and warnings, make effective use of the CPAN, know how to use perldoc). It would mostly be regurgitation of what I have learned from other sources filtered by my experiences programming in Perl (almost) daily for the last year and whenever I got the chance for the year before that. Anyways, I am just trying to start up a discussion about what the goals of Kamloops Perl Mongers could be. Brad From anthonyj at jonathan.abda.net Thu Oct 9 13:28:46 2003 From: anthonyj at jonathan.abda.net (Anthonyj) Date: Mon Aug 2 21:30:58 2004 Subject: [kamloops-pm] Hello Message-ID: <200310091828.h99ISkEI021051@parrot.silverservers.com> Well, here's one to discuss. I'm still fairly new to perl, and I ran into an odd problem. I haven't seen this in any other script, but it's happening here. When printed or returned, the variable, $post_data appears to contain nothing, but when I move the print statement (commented at the moment) or the return statement up a few lines, and inside the loop, they will work there, making it appear as if, the scope of the variable is limited to the loop, and that outside the loop it has no value. Doesn't make sense, but it works when I make that change. I have this code working with that one modification, but I'm really puzzled on the theory end. If anyone has any guesses or can enlighten me on why this might happen, I'd love to hear your thoughts. Jonathan (here's the code in question) All this function is doing is gather data from mysql, then processing an html file and filling it with the values we've grabbed from mysql, and $post_data is what is to be returned, holding all that html. (constants in the select statement are intended to be static for the moment, just for current testing) sub display_goal_posts { #get discussion for current goal our ($sth, $SQL); $SQL="SELECT * FROM goal_posts WHERE Project = '1' and Goal = '2'"; $sth=getRS($SQL, $dbh); my %goal_posts; while (my $row = $sth->fetchrow_hashref() ) { $goal_posts{ID} = $row->{ID}; $goal_posts{Goal} = $row->{Goal}; $goal_posts{Text} = $row->{Text}; open (HTML,"<" . $goal_post) or print "Cannot open $goal_post\n"; my @table_template = ; close (HTML); my %replace; $replace{POST_TEXT} = $goal_posts{Text}; my $post_data .= join("\n", @table_template); $post_data =~ s||$replace{$1}|gs; } #print $post_data; return $post_data; } ________________________________________________ MailServer powered by SilverServers Inc. Visit us at http://www.SilverServers.com From bke at bkecc.com Thu Oct 9 14:05:16 2003 From: bke at bkecc.com (Bradley K. Embree) Date: Mon Aug 2 21:30:58 2004 Subject: [kamloops-pm] Hello In-Reply-To: <200310091828.h99ISkEI021051@parrot.silverservers.com> Message-ID: > -----Original Message----- > From: kamloops-pm-bounces@mail.pm.org > [mailto:kamloops-pm-bounces@mail.pm.org]On Behalf Of Anthonyj > Sent: Thursday, October 09, 2003 11:29 AM > To: kamloops-pm@mail.pm.org > Subject: Re: [kamloops-pm] Hello > > > Well, here's one to discuss. I'm still fairly new to perl, and I ran into > an odd problem. > > > sub display_goal_posts > { > > #get discussion for current goal > our ($sth, $SQL); > > $SQL="SELECT * FROM goal_posts WHERE Project = '1' and Goal = '2'"; > $sth=getRS($SQL, $dbh); > > my %goal_posts; > while (my $row = $sth->fetchrow_hashref() ) > { > $goal_posts{ID} = $row->{ID}; > $goal_posts{Goal} = $row->{Goal}; > $goal_posts{Text} = $row->{Text}; > > open (HTML,"<" . $goal_post) or print "Cannot open $goal_post\n"; > my @table_template = ; > close (HTML); > > my %replace; > $replace{POST_TEXT} = $goal_posts{Text}; > > my $post_data .= join("\n", @table_template); > $post_data =~ s||$replace{$1}|gs; > } > > #print $post_data; > return $post_data; > > } > This is a scoping issue. Short answer: Declare $post_data before entering the while loop. I.E.: my %goal_posts; while (my $row = $sth->fetchrow_hashref() ) becomes my %goal_posts; my $post_data; while (my $row = $sth->fetchrow_hashref() ) Longer answer: put use strict; somewhere in the code it will help catch these types of errors (but you may find your code needs a lot of rewriting to get it working under strict). For a detailed explanation of scoping see: http://perl.plover.com/FAQs/Namespaces.html For a quick script to play with try this: #use strict; my @array = ( 1 .. 10 ); # my $i; while ( my $i = shift @array ) { print "$i\n"; } print "$i\n"; Run it and look at the output. Then uncomment use strict; and try to run it. Then uncomment my $i and run it again. For even more fun change my $1; to my $i = 42; and run again. Compare the output. And then change while ( my $i = ... to while ( $i = ... and see the difference. Bradley K. Embree, IT Support Excel Kitchens Email: bkembree@excelkitchens.ca Phone: 1.250.376.8713 Fax: 1.250.376.4511 From bkembree at excelkitchens.ca Thu Oct 9 14:09:12 2003 From: bkembree at excelkitchens.ca (Bradley K. Embree) Date: Mon Aug 2 21:30:58 2004 Subject: [kamloops-pm] test of reply headers... Message-ID: ignore me From bkembree at excelkitchens.ca Thu Oct 9 14:15:13 2003 From: bkembree at excelkitchens.ca (Bradley K. Embree) Date: Mon Aug 2 21:30:58 2004 Subject: [kamloops-pm] Test of reply-to header (again) Message-ID: foobar From smoky at flogged.net Thu Oct 9 14:16:33 2003 From: smoky at flogged.net (the only gay eskimo) Date: Mon Aug 2 21:30:58 2004 Subject: [kamloops-pm] Test of reply-to header (again) In-Reply-To: References: Message-ID: <20031009191633.GE11517@flogged.net> perfect On Thu, Oct 09, 2003 at 12:15:13PM -0700, Bradley K. Embree wrote: > foobar > _______________________________________________ > kamloops-pm mailing list > kamloops-pm@mail.pm.org > http://mail.pm.org/mailman/listinfo/kamloops-pm From bke at bkecc.com Thu Oct 9 14:22:26 2003 From: bke at bkecc.com (Bradley K. Embree) Date: Mon Aug 2 21:30:58 2004 Subject: [kamloops-pm] Test of reply-to header (again) In-Reply-To: <20031009191633.GE11517@flogged.net> Message-ID: can you tell it is my first time administering a mailing list? hopefully everyone feels free to speak up if they see something they think is not quite right. Brad > -----Original Message----- > From: kamloops-pm-bounces@mail.pm.org > [mailto:kamloops-pm-bounces@mail.pm.org]On Behalf Of the only gay eskimo > Sent: Thursday, October 09, 2003 12:17 PM > To: Kamloops Perl Mongers > Subject: Re: [kamloops-pm] Test of reply-to header (again) > > > perfect > > On Thu, Oct 09, 2003 at 12:15:13PM -0700, Bradley K. Embree wrote: > > foobar > > _______________________________________________ > > kamloops-pm mailing list > > kamloops-pm@mail.pm.org > > http://mail.pm.org/mailman/listinfo/kamloops-pm > _______________________________________________ > kamloops-pm mailing list > kamloops-pm@mail.pm.org > http://mail.pm.org/mailman/listinfo/kamloops-pm From anthonyj at jonathan.abda.net Thu Oct 9 14:20:14 2003 From: anthonyj at jonathan.abda.net (Anthonyj) Date: Mon Aug 2 21:30:58 2004 Subject: [kamloops-pm] Hello Message-ID: <200310091920.h99JKEAP024764@parrot.silverservers.com> Thankyou, I wasn't expecting such quick replies. Another list member had similar things to say, but sent them directly to me by accident, and asked me to bounce them to the list, so here it is. (in a moment) I'll take your advice, except in one place, the $post_data value, didn't need to have my in front of it in the first place. Guess I wasn't paying attention to what 'my' actually did. You are wise in the ways of perl, I am not, I shall join you. Thanks. The following origionally from a couple small changes. the 'my $row' is cool since it's only to be used in the while loop, but it's a good habit to delare/define your variables at the beginning of the function/sub. you should also 'use strict;', it helps tons. it'll complain about stuff like '$row->{ID}' and prefers "$row->{'ID'}", but it can save you debugging time. the -w option (if applicable), is great. or just set ^W. sub display_goal_posts { #get discussion for current goal our ($sth, $SQL); my (%goal_posts, @table_template, %replace, $post_data); $SQL="SELECT * FROM goal_posts WHERE Project = '1' and Goal = '2'"; $sth=getRS($SQL, $dbh); while (my $row = $sth->fetchrow_hashref() ) { $goal_posts{ID} = $row->{ID}; $goal_posts{Goal} = $row->{Goal}; $goal_posts{Text} = $row->{Text}; open (HTML,"<" . $goal_post) or print "Cannot open $goal_post\n"; @table_template = ; close (HTML); $replace{POST_TEXT} = $goal_posts{Text}; $post_data .= join("\n", @table_template); $post_data =~ s||$replace{$1}|gs; } #print $post_data; return $post_data; } ________________________________________________ MailServer powered by SilverServers Inc. Visit us at http://www.SilverServers.com From bke at bkecc.com Thu Oct 9 14:38:55 2003 From: bke at bkecc.com (Bradley K. Embree) Date: Mon Aug 2 21:30:58 2004 Subject: [kamloops-pm] Hello In-Reply-To: <200310091920.h99JKEAP024764@parrot.silverservers.com> Message-ID: > -----Original Message----- > From: kamloops-pm-bounces@mail.pm.org > [mailto:kamloops-pm-bounces@mail.pm.org]On Behalf Of Anthonyj > Sent: Thursday, October 09, 2003 12:20 PM > To: kamloops-pm@mail.pm.org > Subject: RE: [kamloops-pm] Hello > > > Thankyou, I wasn't expecting such quick replies. > Another list member had similar things to say, but sent them directly to me > by accident, and asked me to bounce them to the list, so here it is. > > > a couple small changes. the 'my $row' is cool since it's only to be used in > the while loop, but it's a good habit to delare/define your variables at the > beginning of the function/sub. you should also 'use strict;', it helps tons. > it'll complain about stuff like '$row->{ID}' and prefers "$row->{'ID'}", but > it can save you debugging time. the -w option (if applicable), is great. or > just set ^W. > I agree with using warnings (-w or setting ^W) but I usually do that via: use warnings; But of course TMTOWTDI. One nit is that strict does not complain about bare words in the context of hash keys (among others). I.E. $row->{ID} is acceptable although I prefer and use $row->{'ID'} as a form of defensive programming. Bare words are also acceptable when declaring hashes using the => notation: my %hash = ( foo => 'bar' ); # ok under strict my %hash = ( foo, 'bar' ); # not ok under strict my %hash = ( 'foo', 'bar' ); # ok under strict but once again TMTOWTDI. Brad From smoky at flogged.net Thu Oct 9 14:53:20 2003 From: smoky at flogged.net (the only gay eskimo) Date: Mon Aug 2 21:30:58 2004 Subject: [kamloops-pm] Hello In-Reply-To: References: <200310091920.h99JKEAP024764@parrot.silverservers.com> Message-ID: <20031009195320.GA58085@flogged.net> for some reason, i thought strict would complain about it, or at least i remember it did. i was thinking that if you had a sub called 'ID' it'd get confused, but i just tested, and it's not the case > > I.E. $row->{ID} is acceptable although I prefer and use $row->{'ID'} as a form > of defensive programming. > > Bare words are also acceptable when declaring hashes using the => notation: > > my %hash = ( foo => 'bar' ); # ok under strict > my %hash = ( foo, 'bar' ); # not ok under strict > my %hash = ( 'foo', 'bar' ); # ok under strict > > but once again TMTOWTDI. > > Brad > From bke at bkecc.com Thu Oct 9 15:11:21 2003 From: bke at bkecc.com (Bradley K. Embree) Date: Mon Aug 2 21:30:58 2004 Subject: [kamloops-pm] Hello In-Reply-To: <20031009195320.GA58085@flogged.net> Message-ID: use strict; use warnings; my %hash = ( foo => 'foo', bar => 'bar', zed => 'zed' ); my $foo = 'bar'; sub foo { return 'zed' } print $hash{ foo }, "\n"; print $hash{ $foo }, "\n"; print $hash{ &foo }, "\n"; # or $hash{ foo() } or $hash{ &foo() } Perl does make it very easy to write confusing code. ;) Brad > -----Original Message----- > From: kamloops-pm-bounces@mail.pm.org > [mailto:kamloops-pm-bounces@mail.pm.org]On Behalf Of the only gay eskimo > Sent: Thursday, October 09, 2003 12:53 PM > To: Kamloops Perl Mongers > Subject: Re: [kamloops-pm] Hello > > > > for some reason, i thought strict would complain about it, or at least i > remember it did. i was thinking that if you had a sub called 'ID' it'd get > confused, but i just tested, and it's not the case > > > > > > I.E. $row->{ID} is acceptable although I prefer and use > $row->{'ID'} as a form > > of defensive programming. > > > > Bare words are also acceptable when declaring hashes using the => > notation: > > > > my %hash = ( foo => 'bar' ); # ok under strict > > my %hash = ( foo, 'bar' ); # not ok under strict > > my %hash = ( 'foo', 'bar' ); # ok under strict > > > > but once again TMTOWTDI. > > > > Brad > > > _______________________________________________ > kamloops-pm mailing list > kamloops-pm@mail.pm.org > http://mail.pm.org/mailman/listinfo/kamloops-pm