From anotheranne at fables.co.za Mon Jul 27 04:59:39 2009 From: anotheranne at fables.co.za (Anne Wainwright) Date: Mon, 27 Jul 2009 13:59:39 +0200 Subject: [Za-pm] books on using mysql with perl Message-ID: <20090727135939.3d4df2c3@pandora.fables.co.za> Hi, Tielman & others, I was wondering if there was a 'best buy' that anyone could recommend. The O'Reilly books are always my first choice but I am not married to them. I am not a mysql (or perl) fundi, but need something to help me out. I am currently building up my app in Catalyst using DBIx::Class. From the O'Reilly current mysql list I saw the 'MySQL Cookbook', (love the Perl equivalent) but wondered if something more basic like 'MySQL In A Nutshell' would be better. Other titles I see are 'Learning MySQL', 'Managing & Using MySQL' My requirements are not likely to be too complex in that is a simple commercial app, & I need the perl aspect more than the MySQL one. any suggestions will be carefully looked at. bestest Anne From tvilliers at gmail.com Tue Jul 28 01:49:51 2009 From: tvilliers at gmail.com (Tielman de Villiers) Date: Tue, 28 Jul 2009 09:49:51 +0100 Subject: [Za-pm] books on using mysql with perl In-Reply-To: <20090727135939.3d4df2c3@pandora.fables.co.za> References: <20090727135939.3d4df2c3@pandora.fables.co.za> Message-ID: Hi Anne I'm not a big mysql user, so can't really recommend a mysql book. But you seem to be in good company with catalyst - it seems to get attention here in london.pm thanks to it's active maintainer. A brand new book (also available as an ebook) has just been published: http://www.apress.com/book/view/9781430223658 --tielman believe On 27 Jul 2009, at 12:59, Anne Wainwright wrote: > Hi, Tielman & others, > > I was wondering if there was a 'best buy' that anyone could recommend. > The O'Reilly books are always my first choice but I am not married to > them. > > I am not a mysql (or perl) fundi, but need something to help me out. I > am currently building up my app in Catalyst using DBIx::Class. > >> From the O'Reilly current mysql list I saw the 'MySQL Cookbook', >> (love > the Perl equivalent) but wondered if something more basic like 'MySQL > In A Nutshell' would be better. > > Other titles I see are 'Learning MySQL', 'Managing & Using MySQL' > > My requirements are not likely to be too complex in that is a simple > commercial app, & I need the perl aspect more than the MySQL one. > > any suggestions will be carefully looked at. > > bestest > Anne > _______________________________________________ > Za-pm mailing list > Za-pm at pm.org > http://mail.pm.org/mailman/listinfo/za-pm From anotheranne at fables.co.za Tue Jul 28 04:46:04 2009 From: anotheranne at fables.co.za (Anne Wainwright) Date: Tue, 28 Jul 2009 13:46:04 +0200 Subject: [Za-pm] books on using mysql with perl In-Reply-To: References: <20090727135939.3d4df2c3@pandora.fables.co.za> Message-ID: <20090728134604.440e1b54@pandora.fables.co.za> Hi, Tielmen & all, I have in fact got that one (Definitive Guide To Catalyst by Karen Dieman & Matt Trout) on order, so maybe I should wait a few weeks. bestest Anne On Tue, 28 Jul 2009 09:49:51 +0100 Tielman de Villiers wrote: > Hi Anne > > I'm not a big mysql user, so can't really recommend a mysql book. But > you seem to be in good company with catalyst - it seems to get > attention here in london.pm thanks to it's active maintainer. A brand > new book (also available as an ebook) has just been published: > http://www.apress.com/book/view/9781430223658 > > --tielman > > > > > > believe > > On 27 Jul 2009, at 12:59, Anne Wainwright > wrote: > > > Hi, Tielman & others, > > > > I was wondering if there was a 'best buy' that anyone could > > recommend. The O'Reilly books are always my first choice but I am > > not married to them. > > > > I am not a mysql (or perl) fundi, but need something to help me > > out. I am currently building up my app in Catalyst using > > DBIx::Class. > > > >> From the O'Reilly current mysql list I saw the 'MySQL Cookbook', > >> (love > > the Perl equivalent) but wondered if something more basic like > > 'MySQL In A Nutshell' would be better. > > > > Other titles I see are 'Learning MySQL', 'Managing & Using MySQL' > > > > My requirements are not likely to be too complex in that is a simple > > commercial app, & I need the perl aspect more than the MySQL one. > > > > any suggestions will be carefully looked at. > > > > bestest > > Anne > > _______________________________________________ > > Za-pm mailing list > > Za-pm at pm.org > > http://mail.pm.org/mailman/listinfo/za-pm From anotheranne at fables.co.za Tue Jul 28 04:59:28 2009 From: anotheranne at fables.co.za (Anne Wainwright) Date: Tue, 28 Jul 2009 13:59:28 +0200 Subject: [Za-pm] books on using mysql with perl In-Reply-To: References: <20090727135939.3d4df2c3@pandora.fables.co.za> Message-ID: <20090728135928.7cef0f87@pandora.fables.co.za> Walter, hi, Thanks for the tip. You will see how clueless I am from the following question. Is DBI the same as DBIx::Class (DBIC) format? - (I only copy words from my book) - which is the Catalyst way to go it seems. I have to follow the main track at present. I have the new Catalyst book en route in the mail and am looking forward to it. I have been working through the earlier Catalyst book by Jonathan Rockway. I liked that & the path that it followed, but it was flawed with too many typos, deprecated things like TTSite and Bindlex, and lack of support (downloadable code not complete and updated, disparate errata, apparent unwillingness of the community to support it further). Well I realise there must be issues behind the scenes, but looking on the positive side it has got me going and given me much exercise in getting the examples to work. I'm not complaining. regards & thanks Anne On Tue, 28 Jul 2009 10:56:02 +0200 Walter Kruse wrote: > > Anne, > > I was going to recommend O'Reilly's Programming the Perl DBI - I have > had to do lots of work with various databases. But I think that the > book that Tielman has since recommended is much more applicable to > your situation. > > krgds > Walter Kruse > > > Date: Mon, 27 Jul 2009 13:59:39 +0200 > > From: anotheranne at fables.co.za > > To: za-pm at pm.org > > Subject: [Za-pm] books on using mysql with perl > > > > Hi, Tielman & others, > > > > I was wondering if there was a 'best buy' that anyone could > > recommend. The O'Reilly books are always my first choice but I am > > not married to them. > > > > I am not a mysql (or perl) fundi, but need something to help me > > out. I am currently building up my app in Catalyst using > > DBIx::Class. > > > > >From the O'Reilly current mysql list I saw the 'MySQL Cookbook', > > >(love > > the Perl equivalent) but wondered if something more basic like > > 'MySQL In A Nutshell' would be better. > > > > Other titles I see are 'Learning MySQL', 'Managing & Using MySQL' > > > > My requirements are not likely to be too complex in that is a simple > > commercial app, & I need the perl aspect more than the MySQL one. > > > > any suggestions will be carefully looked at. > > > > bestest > > Anne > > _______________________________________________ > > Za-pm mailing list > > Za-pm at pm.org > > http://mail.pm.org/mailman/listinfo/za-pm > > _________________________________________________________________ > With Windows Live, you can organize, edit, and share your photos. > http://www.microsoft.com/southafrica/windows/windowslive/products/photo-gallery-edit.aspx From anotheranne at fables.co.za Sun Aug 9 05:39:32 2009 From: anotheranne at fables.co.za (Anne Wainwright) Date: Sun, 9 Aug 2009 14:39:32 +0200 Subject: [Za-pm] getting out of loop Message-ID: <20090809143932.692bd157@pandora.fables.co.za> Hi, all, (Am in fact referring to Exercise 2 Chapter 2 of Schwartz et al INTERMEDIATE PERL.) First, while realising that the official solution is a masterpiece of condensed perl code, I don't understand why the first line has the (1) ). ----------------------------------------------------------- while(1) { print "Enter a regular expression to match filenames> "; chomp(my $regex = ); last unless (defined $regex && length $regex); print map {" $_\n"} grep {eval{/$regex/}} glob(".* *"); } ----------------------------------------------------------- My own more primitive solution fails to get out of the input loop, albeit with simpler criteria. My code is: ------------------------------------------------------- opendir THISDIR, "." or die "serious braindamage: $!"; @allfiles = readdir THISDIR; closedir THISDIR; while (defined($regexpr = )) { # 1 chomp $regexpr; foreach $file(@allfiles) { # 2 if ($file =~ m/$regexpr/) { # 3 print "$file\n"; } # -3 } # -2 } # -1 ------------------------------------------------------- Essentially on no regex input it outputs all the files as if ".+" had been input. I thought the line marked #1 was a dead ringer for getting out of the input loop. (p.72 Chapter 6 of Schwartz et al LEARNING PERL). If I take "&& length $regex" out of their code then that also fails to exit. I don't understand :( Any one explaining this in small understandable words thanked in advance. bestest Anne From anotheranne at fables.co.za Sun Aug 9 05:47:23 2009 From: anotheranne at fables.co.za (Anne Wainwright) Date: Sun, 9 Aug 2009 14:47:23 +0200 Subject: [Za-pm] got my new Catalyst book by Diement & Trout Message-ID: <20090809144723.75ba83ad@pandora.fables.co.za> It arrived in the mail on Saturday (actually I went and begged the post office for it since i knew it was there). It looks much more structured than the other book by Rockway, so hope that I will get a lot out of it. Am committed to getting further thru INTERMEDIATE PERL before I plunge in too far. regards Anne From jkeen at verizon.net Sun Aug 9 07:07:00 2009 From: jkeen at verizon.net (James E Keenan) Date: Sun, 09 Aug 2009 10:07:00 -0400 Subject: [Za-pm] getting out of loop In-Reply-To: <20090809143932.692bd157@pandora.fables.co.za> References: <20090809143932.692bd157@pandora.fables.co.za> Message-ID: <7D8684C8-F010-43B1-86E9-EEAC9FB88118@verizon.net> On Aug 9, 2009, at 8:39 AM, Anne Wainwright wrote: > (Am in fact referring to Exercise 2 Chapter 2 of > Schwartz et al INTERMEDIATE PERL.) > > First, while realising that the official solution is a masterpiece of > condensed perl code, I don't understand why the first > line has the (1) ). > > ----------------------------------------------------------- > while(1) { > print "Enter a regular expression to match filenames> "; > chomp(my $regex = ); > last unless (defined $regex && length $regex); > print map {" $_\n"} grep {eval{/$regex/}} glob(".* *"); > } > ----------------------------------------------------------- > I don't have my copy of Intermediate Perl handy, but, in general, with an infinite loop such as that cited above the expectation is that at some point you will either compose a pattern that matches the filename and then automatically exit via 'last', or you will give up in frustration by hitting Ctrl-C (in *nix). From francois at busii.com Tue Aug 11 10:35:58 2009 From: francois at busii.com (Francois Marais) Date: Tue, 11 Aug 2009 19:35:58 +0200 Subject: [Za-pm] getting out of loop In-Reply-To: <20090809143932.692bd157@pandora.fables.co.za> References: <20090809143932.692bd157@pandora.fables.co.za> Message-ID: Hi Anne 2 reasons why your while loop does not terminate on empty input: First, the 'length' issue: Before chomping, length of regexpr when you just press Enter is 1 (Still has the newline character) , after chomping it is 0 So you need to check after chomping or say .... while (length($regexpr = )>1) { # 1 .... Secondly, after chomping, the empty string is still a defined value: perl -e 'print "defined" if defined "" ' The reason why presumably the defined test is part of the loop, is that it if you enter Ctrl-D (That is on *nix) and dont check for it, and you use warnings (which you should be doing), you will get a warning Ctrl-C is a *nix shell control character which terminates the command, so does not get to be processed in the while loop. The reason all the files are printed out with an empty string is that it matches all the filenames perl -e 'print "match" if "anyfilenameyoulike"=~//' perl -e 'print "match" if ""=~//' Regards On Sun, Aug 9, 2009 at 2:39 PM, Anne Wainwright wrote: > Hi, all, > > (Am in fact referring to Exercise 2 Chapter 2 of > Schwartz et al INTERMEDIATE PERL.) > > First, while realising that the official solution is a masterpiece of > condensed perl code, I don't understand why the first > line has the (1) ). > > ----------------------------------------------------------- > while(1) { > print "Enter a regular expression to match filenames> "; > chomp(my $regex = ); > last unless (defined $regex && length $regex); > print map {" $_\n"} grep {eval{/$regex/}} glob(".* *"); > } > ----------------------------------------------------------- > > My own more primitive solution fails to get out of the > input loop, albeit with simpler criteria. My code is: > > ------------------------------------------------------- > opendir THISDIR, "." or die "serious braindamage: $!"; > @allfiles = readdir THISDIR; > closedir THISDIR; > > while (defined($regexpr = )) { # 1 > chomp $regexpr; > foreach $file(@allfiles) { # 2 > if ($file =~ m/$regexpr/) { # 3 > print "$file\n"; > } # -3 > } # -2 > } # -1 > ------------------------------------------------------- > Essentially on no regex input it outputs all the files as if ".+" had > been input. > > I thought the line marked #1 was a dead ringer for getting out of the > input loop. (p.72 Chapter 6 of Schwartz et al LEARNING PERL). If I take > "&& length $regex" out of their code then that also fails to exit. I > don't understand :( > > Any one explaining this in small understandable words thanked > in advance. > > bestest > Anne > _______________________________________________ > Za-pm mailing list > Za-pm at pm.org > http://mail.pm.org/mailman/listinfo/za-pm > -------------- next part -------------- An HTML attachment was scrubbed... URL: From anotheranne at fables.co.za Tue Aug 11 12:44:00 2009 From: anotheranne at fables.co.za (Anne Wainwright) Date: Tue, 11 Aug 2009 21:44:00 +0200 Subject: [Za-pm] getting out of loop In-Reply-To: References: <20090809143932.692bd157@pandora.fables.co.za> Message-ID: <20090811214400.738178fd@pandora.fables.co.za> Francois, hi. You have explained "in small understandable words" very clearly, many thanks. Comments below. On Tue, 11 Aug 2009 19:35:58 +0200 Francois Marais wrote: > Hi Anne > > 2 reasons why your while loop does not terminate on empty input: > > First, the 'length' issue: Before chomping, length of regexpr when > you just press Enter is 1 (Still has the newline character) , after > chomping it is 0 So you need to check after chomping or say > > .... > while (length($regexpr = )>1) { # 1 > .... > > Secondly, after chomping, the empty string is still a defined value: > > perl -e 'print "defined" if defined "" ' yes, I put that in and it prints "defined". I believe. I am pasting here from a (bootleg?) online copy of "Learning Perl" (which reads the same as my actual book) p.72 2nd edn. http://docstore.mik.ua/orelly/perl/learn/ch06_01.htm my *** emphasis ----------------------------------- Typically, one thing you want to do is read all lines one at a time and do something with each line. One common way to do this is: while (defined($line = )) { # process $line here } *** As long as a line has been read in, evaluates to a defined *** value, so the loop continues to execute. When has no more *** lines to read, it returns undef, terminating the loop. ----------------------------------- 'no more lines to read' --> hit Enter??? so I put if (defined($regexpr)) {print "defined";} into my code, both before and after a chomp, and sure enough it prints "defined" in both cases. > > The reason why presumably the defined test is part of the loop, is > that it if you enter > Ctrl-D (That is on *nix) and dont check for it, and you use warnings > (which you should be doing), you will get a warning > > Ctrl-C is a *nix shell control character which terminates the > command, so does not get to be processed in the while loop. > > The reason all the files are printed out with an empty string is that > it matches all the filenames > > perl -e 'print "match" if "anyfilenameyoulike"=~//' > perl -e 'print "match" if ""=~//' I had concluded that a match must be the case but was at a loss to explain why it happened. You demonstrate it clearly. The only way I can put it into words is that // contains nothing that cannot be matched. Is this a bug or a feature? anyway that clearly explains the behavior observed there. end of comments many thanks Anne > > Regards > > On Sun, Aug 9, 2009 at 2:39 PM, Anne Wainwright > wrote: > > > Hi, all, > > > > (Am in fact referring to Exercise 2 Chapter 2 of > > Schwartz et al INTERMEDIATE PERL.) > > > > First, while realising that the official solution is a masterpiece > > of condensed perl code, I don't understand why the first > > line has the (1) ). > > > > ----------------------------------------------------------- > > while(1) { > > print "Enter a regular expression to match filenames> "; > > chomp(my $regex = ); > > last unless (defined $regex && length $regex); > > print map {" $_\n"} grep {eval{/$regex/}} glob(".* *"); > > } > > ----------------------------------------------------------- > > > > My own more primitive solution fails to get out of the > > input loop, albeit with simpler criteria. My code is: > > > > ------------------------------------------------------- > > opendir THISDIR, "." or die "serious braindamage: $!"; > > @allfiles = readdir THISDIR; > > closedir THISDIR; > > > > while (defined($regexpr = )) { # 1 > > chomp $regexpr; > > foreach $file(@allfiles) { # 2 > > if ($file =~ m/$regexpr/) { # 3 > > print "$file\n"; > > } # -3 > > } # -2 > > } # -1 > > ------------------------------------------------------- > > Essentially on no regex input it outputs all the files as if ".+" > > had been input. > > > > I thought the line marked #1 was a dead ringer for getting out of > > the input loop. (p.72 Chapter 6 of Schwartz et al LEARNING PERL). > > If I take "&& length $regex" out of their code then that also fails > > to exit. I don't understand :( > > > > Any one explaining this in small understandable words thanked > > in advance. > > > > bestest > > Anne > > _______________________________________________ > > Za-pm mailing list > > Za-pm at pm.org > > http://mail.pm.org/mailman/listinfo/za-pm > > From anotheranne at fables.co.za Tue Aug 11 12:57:42 2009 From: anotheranne at fables.co.za (Anne Wainwright) Date: Tue, 11 Aug 2009 21:57:42 +0200 Subject: [Za-pm] getting out of loop In-Reply-To: <6F376006-DECA-4FFE-9CC6-A1804C6AD67D@deckle.co.za> References: <20090809143932.692bd157@pandora.fables.co.za> <6F376006-DECA-4FFE-9CC6-A1804C6AD67D@deckle.co.za> Message-ID: <20090811215742.64f2860c@pandora.fables.co.za> Oskar, lotsa thanks, comment below at end. On Mon, 10 Aug 2009 02:44:54 +0100 Oskar Pearson wrote: > Hi > > > > Hi, all, > > > > (Am in fact referring to Exercise 2 Chapter 2 of > > Schwartz et al INTERMEDIATE PERL.) > > > > First, while realising that the official solution is a masterpiece > > of condensed perl code, I don't understand why the first > > line has the (1) ). > > > > ----------------------------------------------------------- > > while(1) { > > print "Enter a regular expression to match filenames> "; > > chomp(my $regex = ); > > last unless (defined $regex && length $regex); > > print map {" $_\n"} grep {eval{/$regex/}} glob(".* *"); > > } > > ----------------------------------------------------------- > > The while loop continues indefinitely - the value is always true, so > it'll loop until the "last" gets hit. > > There are two reasons that happens - the "end of file" (pressing > control-D will do that), or if the length of the input is 0 (when > someone inputs a blank line - assuming it's "chomped"). That's what > this line means: > > last unless (defined $regex && length $regex); > > > > > > My own more primitive solution fails to get out of the > > input loop, albeit with simpler criteria. My code is: > > > > ------------------------------------------------------- > > opendir THISDIR, "." or die "serious braindamage: $!"; > > @allfiles = readdir THISDIR; > > closedir THISDIR; > > > > while (defined($regexpr = )) { # 1 > > chomp $regexpr; > > foreach $file(@allfiles) { # 2 > > if ($file =~ m/$regexpr/) { # 3 > > print "$file\n"; > > } # -3 > > } # -2 > > } # -1 > > ------------------------------------------------------- > > Essentially on no regex input it outputs all the files as if ".+" > > had been input. > > First hint is that you should use "perl -w" and "use strict;" - > you'll need to declare your variables though. > > > I thought the line marked #1 was a dead ringer for getting out of > > the input loop. (p.72 Chapter 6 of Schwartz et al LEARNING PERL). > > If I take > > "&& length $regex" out of their code then that also fails to exit. I > > don't understand :( > > Pseudocode for their version: > > Loop forever (unless we hit the "last below, of course") { > print something > read something from stderr > Unless I got a valid input value, and that input value has a > valid length, then jump out of this loop > Do the regex stuff > } > > > > > > > opendir THISDIR, "." or die "serious braindamage: $!"; > > @allfiles = readdir THISDIR; > > closedir THISDIR; > > > > while (defined($regexpr = )) { # 1 > > chomp $regexpr; > > foreach $file(@allfiles) { # 2 > > if ($file =~ m/$regexpr/) { # 3 > > print "$file\n"; > > } # -3 > > } # -2 > > } # -1 > > > > I'd prefer to change this as follows. I'm using slightly different > structures here. > > #!/usr/bin/perl -w > use strict; > opendir THISDIR, "." or die "serious braindamage: $!"; > my @allfiles = readdir THISDIR; > closedir THISDIR; > > while (my $regexpr = ) { # If this is > undefined here, the "while" is a while of an undef value, and the > while will terminate chomp $regexpr; > last unless length($regexpr); #If I > got a blank line, jump out > foreach my $file (sort(@allfiles)) { # Sort > for consistency if ($file =~ m/$regexpr/i) { > # guessing you probably want /i heere all my filenames are in small print ;) > print "$file\n"; > } > } > } > > Hope that helps! Yes, bigly! Very clear and exactly how I would have written it if I could have ;) Along with the analysis of the why things did what they did from Francois I can now move on. Anne > > Oskar From anotheranne at fables.co.za Sat Sep 5 14:47:28 2009 From: anotheranne at fables.co.za (Anne Wainwright) Date: Sat, 5 Sep 2009 23:47:28 +0200 Subject: [Za-pm] being there Message-ID: <20090905234728.7fe30cc8@pandora.fables.co.za> Hi, I don't have a problem, well I did but in writing a post to za-pm this evening I came to the solution as I tried to put the problem into an unambiguous and clear form. So even I don't post my questions, you still help me. So this is a small thank you even though you did not have to do anything to be thanked for today. [I have now working thru Chapter 5 of Intermediate Perl, slowly advancing] bestest Anne