From fifteen3 at gmail.com Mon Oct 1 05:24:06 2012 From: fifteen3 at gmail.com (Carlo Costantini) Date: Mon, 1 Oct 2012 08:24:06 -0400 Subject: [tpm] toronto-pm Digest, Vol 66, Issue 9 In-Reply-To: References: Message-ID: I would like to hear about: why table inheritance is a good idea (best practices) proper use of schemas (best practices) upgrading from 8.x to 9.x and the benefits of 9.x replication in 9.x examples of foreign data wrappers examples and benefits of using pl/perl vs pl/pgsql (is there a performance penalty) tips for helping n00bs ramp up When is this talk going to be? October meeting or another date in the future? On Sun, Sep 30, 2012 at 3:00 PM, wrote: > Send toronto-pm mailing list submissions to > toronto-pm at pm.org > > To subscribe or unsubscribe via the World Wide Web, visit > http://mail.pm.org/mailman/listinfo/toronto-pm > or, via email, send a message with subject or body 'help' to > toronto-pm-request at pm.org > > You can reach the person managing the list at > toronto-pm-owner at pm.org > > When replying, please edit your Subject line so it is more specific > than "Re: Contents of toronto-pm digest..." > > > Today's Topics: > > 1. Re: RFC: Postgres talk coming up. Top ten questions please. > (William Muriithi) > 2. Re: RFC: Postgres talk coming up. Top ten questions please. > (James E Keenan) > > > ---------------------------------------------------------------------- > > Message: 1 > Date: Sat, 29 Sep 2012 16:08:46 -0400 > From: William Muriithi > To: arocker at vex.net > Cc: Toronto PerlMongers > Subject: Re: [tpm] RFC: Postgres talk coming up. Top ten questions > please. > Message-ID: > > Content-Type: text/plain; charset="iso-8859-1" > >> >> Who's using PG? (Names that we would recognise.) > > Why is postgres not as widely used as MySQL despite being equally capable? > > Does postgres support master master setup for redundancy? > > How does postgres instrumentation infrastructure compare to those of oracle > and MySQL? > > William >> >> Assuming that your problem requires a relational database, why Postgres vs >> >> a) MySQl >> b) Oracle >> c) SQLServer >> d) Any other competitor I've forgotten? >> >> (Capabilities/strengths/weaknesses)? >> >> Which OS support PG? >> >> How would Perl fit in a PG environments? Invoking PG, querying, stored >> procedures? >> >> Which is the definitive book on PG? What other documentation is available? >> >> Where do you get PG. How complex is it to install? >> >> _______________________________________________ >> toronto-pm mailing list >> toronto-pm at pm.org >> http://mail.pm.org/mailman/listinfo/toronto-pm > -------------- next part -------------- > An HTML attachment was scrubbed... > URL: > > ------------------------------ > > Message: 2 > Date: Sat, 29 Sep 2012 20:29:51 -0400 > From: James E Keenan > To: toronto-pm at pm.org > Subject: Re: [tpm] RFC: Postgres talk coming up. Top ten questions > please. > Message-ID: <5067927F.2070600 at verizon.net> > Content-Type: text/plain; charset=ISO-8859-1; format=flowed > > On 9/29/12 1:37 PM, arocker at Vex.Net wrote: >> Some random suggestions to provoke debate: >> >> Who's using PG? (Names that we would recognise.) >> > > Jim Keenan! > > Which occurs because my somewhat recently new day job in NYC uses > Postgres. I have no prior experience with it, but colleagues in the > Parrot project speak well of it. > >> Assuming that your problem requires a relational database, why Postgres vs >> >> a) MySQl >> b) Oracle > > $$$ > >> c) SQLServer > > $$$ > >> d) Any other competitor I've forgotten? >> >> (Capabilities/strengths/weaknesses)? >> >> Which OS support PG? >> > > I suspect the riposte would be: Which doesn't? > >> How would Perl fit in a PG environments? Invoking PG, querying, stored >> procedures? >> > > DBI -- I finally have a chance to learn it in a practical way. > >> Which is the definitive book on PG? What other documentation is available? >> > > I consult the online documentation every day. It is considerably better > than that of most OS projects. > >> Where do you get PG. How complex is it to install? >> > > You download it :-) But I'll let others speak to whether installation > is complex or not. > > > ------------------------------ > > Subject: Digest Footer > > _______________________________________________ > toronto-pm mailing list > toronto-pm at pm.org > http://mail.pm.org/mailman/listinfo/toronto-pm > > > ------------------------------ > > End of toronto-pm Digest, Vol 66, Issue 9 > ***************************************** From jztam at yahoo.com Thu Oct 4 07:13:24 2012 From: jztam at yahoo.com (J Z Tam) Date: Thu, 4 Oct 2012 07:13:24 -0700 (PDT) Subject: [tpm] Fw: APL@50 at York U Message-ID: <1349360004.56692.YahooMailClassic@web120904.mail.ne1.yahoo.com> Hey Mongeren, ? I'm partial to APL, so I filtered this IN.?? Hopefully someone will join me and carpool; I have 4 empty seats in the Civic Coupe, or 3 larger humans. ;-) It's the Thursday AFTER our October gig.? /jordan --- On Wed, 10/3/12, Zbigniew Stachniak wrote: From: Zbigniew Stachniak Subject: APL at 50 at York U To: toronto-pm-owner at pm.org Received: Wednesday, October 3, 2012, 10:23 PM Dear Toronto Perl Mongers, I'm writing to let you know about a special computer event that York University and the York University Computer Museum is organizing on Nov. 1, 2012, and which could be of interest to at least some of you. The APL at 50 will celebrate the 50th anniversary of one of the most influential early programming languages--APL--with? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ???invited lectures, exhibits, movies, and demos, etc. Yes, I know, APL is not Perl but I'm sure that many of you did program in this exciting language invented by a Canadian. During the event, there will be an opportunity to meet computer pioneers and industry leaders. The attendance is free. Would you be so kind and bring our event to the attention of the members of the Toronto Perl Mongers-- thanks! I have attached the event's announcement; more information can be found at ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? http://www.cse.yorku.ca/museum/apl50/ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ???Thanks and all the best Zbigniew Stachniak --Zbigniew Stachniak Associate Professor Department of Computer Science and Engineering York University 4700 Keele Street Toronto, Ontario, M3J 1P3 Canada http://www.cse.yorku.ca/~zbigniew/ -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: invite.pdf Type: application/pdf Size: 130274 bytes Desc: not available URL: From jztam at yahoo.com Thu Oct 4 07:36:38 2012 From: jztam at yahoo.com (J Z Tam) Date: Thu, 4 Oct 2012 07:36:38 -0700 (PDT) Subject: [tpm] Fw: APL@50 at York U In-Reply-To: <1349360004.56692.YahooMailClassic@web120904.mail.ne1.yahoo.com> Message-ID: <1349361398.28065.YahooMailClassic@web120903.mail.ne1.yahoo.com> WHERE:? APL at 50 Travel information The APL at 50 meeting will take please on November 1, 2012, at York University, Toronto. All events are scheduled to take place in the Lecture Hall B of the Lassonde Building. Please consult the York University maps for the public transit and driving directions as well as for the location of the Lassonde Building. --- On Thu, 10/4/12, J Z Tam wrote: From: J Z Tam Subject: [tpm] Fw: APL at 50 at York U To: "Toronto PerlMongers" Received: Thursday, October 4, 2012, 10:13 AM Hey Mongeren, ? I'm partial to APL, so I filtered this IN.?? Hopefully someone will join me and carpool; I have 4 empty seats in the Civic Coupe, or 3 larger humans. ;-) It's the Thursday AFTER our October gig.? /jordan --- On Wed, 10/3/12, Zbigniew Stachniak wrote: From: Zbigniew Stachniak Subject: APL at 50 at York U To: toronto-pm-owner at pm.org Received: Wednesday, October 3, 2012, 10:23 PM Dear Toronto Perl Mongers, I'm writing to let you know about a special computer event that York University and the York University Computer Museum is organizing on Nov. 1, 2012, and which could be of interest to at least some of you. The APL at 50 will celebrate the 50th anniversary of one of the most influential early programming languages--APL--with? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ???invited lectures, exhibits, movies, and demos, etc. Yes, I know, APL is not Perl but I'm sure that many of you did program in this exciting language invented by a Canadian. During the event, there will be an opportunity to meet computer pioneers and industry leaders. The attendance is free. Would you be so kind and bring our event to the attention of the members of the Toronto Perl Mongers-- thanks! I have attached the event's announcement; more information can be found at ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? http://www.cse.yorku.ca/museum/apl50/ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ???Thanks and all the best Zbigniew Stachniak --Zbigniew Stachniak Associate Professor Department of Computer Science and Engineering York University 4700 Keele Street Toronto, Ontario, M3J 1P3 Canada http://www.cse.yorku.ca/~zbigniew/ -----Inline Attachment Follows----- _______________________________________________ toronto-pm mailing list toronto-pm at pm.org http://mail.pm.org/mailman/listinfo/toronto-pm -------------- next part -------------- An HTML attachment was scrubbed... URL: From cj at enersave.ca Fri Oct 5 05:42:30 2012 From: cj at enersave.ca (Chris Jones) Date: Fri, 05 Oct 2012 08:42:30 -0400 Subject: [tpm] Exporting Access files to .csv Message-ID: <20121005124231.ACE4511FE10@xx1.develooper.com> I am working on a project that uses Access to store the rule sets. It is hard to explain but a rule is a programming statement. A statement can do one of two things: return a variable or do an action. Then the rules compiler sifts through all the access files and "compiles" the rules to a binary library. I find it helpful to export all the tables to .csv so I can do "search in files" to track the logic of the others on project. It's a nightmare but that's another story. So I am wondering if anyone has any ideas as to the simplest way to automate the exporting of access files to .csv? Thank you! >> Christopher Jones, P.Eng. Suite 1801, 1 Yonge Street Toronto, ON M5E1W7 Tel. 416-203-7465 Fax. 416-946-1005 email cj at enersave.ca From shlomif at shlomifish.org Fri Oct 5 07:04:42 2012 From: shlomif at shlomifish.org (Shlomi Fish) Date: Fri, 5 Oct 2012 16:04:42 +0200 Subject: [tpm] Exporting Access files to .csv In-Reply-To: <20121005124231.ACE4511FE10@xx1.develooper.com> References: <20121005124231.ACE4511FE10@xx1.develooper.com> Message-ID: <20121005160442.212e0e0d@lap.shlomifish.org> Hi Chris, On Fri, 05 Oct 2012 08:42:30 -0400 Chris Jones wrote: > I am working on a project that uses Access to store the rule > sets. It is hard to explain but a rule is a programming > statement. A statement can do one of two things: return a variable > or do an action. Then the rules compiler sifts through all the > access files and "compiles" the rules to a binary library. > > I find it helpful to export all the tables to .csv so I can do > "search in files" to track the logic of the others on project. It's > a nightmare but that's another story. > > So I am wondering if anyone has any ideas as to the simplest way to > automate the exporting of access files to .csv? > See the replies here: http://stackoverflow.com/questions/280894/automatically-convert-access-db Regards, Shlomi Fish -- ----------------------------------------------------------------- Shlomi Fish http://www.shlomifish.org/ What Makes Software Apps High Quality - http://shlom.in/sw-quality An apple a day keeps the doctor away. Two apples a day will keep two doctors away. ? one of Shlomi Fish?s relatives Please reply to list if it's a mailing list post - http://shlom.in/reply . From antoniosun at lavabit.com Tue Oct 9 14:48:56 2012 From: antoniosun at lavabit.com (Antonio Sun) Date: Tue, 9 Oct 2012 17:48:56 -0400 Subject: [tpm] [OT] Javascript to watch for certain KW from a web page Message-ID: Hi, I know it's kind of OT, but since we have a lot of web experts here, let me try my luck here first. I have zero knowledge of Javascript, I'm wondering if you could give me a big favor to show me how to watch for certain keyword from a web page using Javascript. Basically, I have a slow updating web page, and I need a client side Javascript to watch for a specific keyword in that page and pop up an window if the keyword is found. As I have zero knowledge of Javascript, I hope that your answer is as complete as possible. Thanks a lot in advance Antonio -------------- next part -------------- An HTML attachment was scrubbed... URL: From antoniosun at lavabit.com Wed Oct 10 06:51:35 2012 From: antoniosun at lavabit.com (Antonio Sun) Date: Wed, 10 Oct 2012 09:51:35 -0400 Subject: [tpm] [OT] Javascript to watch for certain KW from a web page In-Reply-To: References: Message-ID: Hi, thanks a lot for your offer Shaun. That was actually what I thought the solution to be. Now let's forget what I said and focus on what I need to accomplish. Yes, I totally control the page content. The situation is, I am designing a web portal that can launch back-end server side processes. The problem is that the process can finish in seconds, or it might need hours to finish, depending how much work the process has. So my design is to spawn a sub process, and capture all its outputs to a log text file, then return immediately to the user, in a web notice page saying, your job is queued; here is the log url; please check manually if is finished or not. But my all my fellow coworkers said they don't want to check themselves. Instead, they want my web portal to check for them. I couldn't think of any solution from the server side to capture the end of the sub process, then informed the already submitted web notice page. Hence, I'm turning to the javascript front-end for solutions. Because I have zero knowledge of Javascript, it might not be feasible at all. But I know the best solution is that if I can have a desktop notification mechanism just like gmail does, that should solve the problem, because my sub process control task does know when the sub process ends, and write a specific ending tag to the end of the log file, which is what I was planning to watch/search for. Every page of my portal does include a standard master template (except the log text file), so if I can send a signal at the end of my sub process and capture that by the master template, then pop up a javascript window, that will do as well. Sorry for the lengthy gibberish, hope that you can figure something out from it. Thanks On Wed, Oct 10, 2012 at 3:01 AM, Shaun Fryer wrote: > Hi Antonio, > > I might be able to help you, but first I need to know a bit more > detail about what you're trying to do. When you say watch for certain > keywords from a webpage, what do you mean exactly? If you mean > searching through a static html document looking for a give word or > words, that's fairly trivial. However, if you can add javascript to > the page in question, then you probably control the page, and > therefore should already know it's content. So question is, why would > you need front-end code in JavaScript to do it? If you mean doing an > HTTP request from within a web-page, or even a Cross Origin request, > in order to receive info from a 3rd-party website, then things could > become considerably more complicated. > > Cheers, > -- > Shaun Fryer > ---------------------------------------------------------- > perl -e 'print chr for map{$_+=22}($ARGV[0])=~/(\d\d)/g' \ > 52959394107588899482799210587992861082757785799222 > ---------------------------------------------------------- > > > On Tue, Oct 9, 2012 at 5:48 PM, Antonio Sun > wrote: > > Hi, > > > > I know it's kind of OT, but since we have a lot of web experts here, let > me > > try my luck here first. > > > > I have zero knowledge of Javascript, I'm wondering if you could give me a > > big favor to show me how to watch for certain keyword from a web page > using > > Javascript. > > > > Basically, I have a slow updating web page, and I need a client side > > Javascript to watch for a specific keyword in that page and pop up an > window > > if the keyword is found. > > > > As I have zero knowledge of Javascript, I hope that your answer is as > > complete as possible. > > > > Thanks a lot in advance > > > > Antonio > > > > > > _______________________________________________ > > toronto-pm mailing list > > toronto-pm at pm.org > > http://mail.pm.org/mailman/listinfo/toronto-pm > > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From arocker at Vex.Net Wed Oct 10 06:54:55 2012 From: arocker at Vex.Net (arocker at Vex.Net) Date: Wed, 10 Oct 2012 09:54:55 -0400 Subject: [tpm] [OT] Javascript to watch for certain KW from a web page In-Reply-To: References: Message-ID: <26dd1dcdbc7e2ced44b8ce60df252385.squirrel@mail.vex.net> > But my all my fellow coworkers said they don't want to check > themselves. Instead, they want my web portal to check for them. Have the process send mail when it finishes? From indy at indigostar.com Wed Oct 10 07:12:24 2012 From: indy at indigostar.com (Indy Singh) Date: Wed, 10 Oct 2012 10:12:24 -0400 Subject: [tpm] [OT] Javascript to watch for certain KW from a web page In-Reply-To: References: Message-ID: <00CEBBF459BD49E2ABEEC8DA8ACDB66C@indy> Hi Antonio, >From your follow on description I think AJAX likely meets your needs. Ajax allows you application or web page to retrieve data from, a server asynchronously (in the background) without interfering with the display and then altering the display later when the data is retrieved. Indy Singh IndigoSTAR Software -- www.indigostar.com From: Antonio Sun Sent: Tuesday, October 09, 2012 5:48 PM To: TPM Subject: [tpm] [OT] Javascript to watch for certain KW from a web page Hi, I know it's kind of OT, but since we have a lot of web experts here, let me try my luck here first. I have zero knowledge of Javascript, I'm wondering if you could give me a big favor to show me how to watch for certain keyword from a web page using Javascript. Basically, I have a slow updating web page, and I need a client side Javascript to watch for a specific keyword in that page and pop up an window if the keyword is found. As I have zero knowledge of Javascript, I hope that your answer is as complete as possible. Thanks a lot in advance Antonio -------------------------------------------------------------------------------- _______________________________________________ toronto-pm mailing list toronto-pm at pm.org http://mail.pm.org/mailman/listinfo/toronto-pm -------------- next part -------------- An HTML attachment was scrubbed... URL: From sfryer at sourcery.ca Wed Oct 10 07:27:45 2012 From: sfryer at sourcery.ca (Shaun Fryer) Date: Wed, 10 Oct 2012 10:27:45 -0400 Subject: [tpm] [OT] Javascript to watch for certain KW from a web page In-Reply-To: References: Message-ID: Hi Antonio, That makes sense. Unfortunately it's a little beyond the scope of a simple email to provide a complete solution for your situation. However, you might try something like the following. You'll need two things. #1. an ajax function of some kind. Given that you aren't interested in learning JS, I'd recommend using a cross-browser abstraction library which has an ajax method, such as jQuery. #2. You'll need a popup dialogue of some kind. There are plenty to choose from. For the purposes of providing an example, I've [arbitrarily] chosen the facybox jQuery plugin. I have no direct experience with it, but the API seems simple enough, so it should work fine. Add a script tag including the jQuery library, followed by one for the plugin for your popup ( http://bitbonsai.com/facybox/ ). Now in a separate script tag below this, add code similar to that below (modified accordingly). var nMilliseconds = 60*1000; // frequency of server check in milliseconds var checkServerStatus = function () { $.ajax({ url: "/path/to/your/log/file/script" }).done(function (jqXHR, textStatus) { if (/a regexp matching text in your log file/.test(jqXHR.responseText)) $.facybox("The text you wish the user to see in the popup dialogue."); else setTimeout( checkServerStatus, nMilliseconds ); }); }; setTimeout( checkServerStatus, nMilliseconds ); The above is just pseudo-code, but it *should* work with very little modification, assuming you're using the indicated JS libraries. Hope this helps. -- Shaun Fryer ---------------------------------------------------------- perl -e 'print chr for map{$_+=22}($ARGV[0])=~/(\d\d)/g' \ 52959394107588899482799210587992861082757785799222 ---------------------------------------------------------- On Wed, Oct 10, 2012 at 9:51 AM, Antonio Sun wrote: > Hi, thanks a lot for your offer Shaun. > > That was actually what I thought the solution to be. Now let's forget what I > said and focus on what I need to accomplish. > > Yes, I totally control the page content. The situation is, > > I am designing a web portal that can launch back-end server side processes. > The problem is that the process can finish in seconds, or it might need > hours to finish, depending how much work the process has. So my design is to > spawn a sub process, and capture all its outputs to a log text file, then > return immediately to the user, in a web notice page saying, your job is > queued; here is the log url; please check manually if is finished or not. > > But my all my fellow coworkers said they don't want to check themselves. > Instead, they want my web portal to check for them. I couldn't think of any > solution from the server side to capture the end of the sub process, then > informed the already submitted web notice page. Hence, I'm turning to the > javascript front-end for solutions. Because I have zero knowledge of > Javascript, it might not be feasible at all. But I know the best solution is > that if I can have a desktop notification mechanism just like gmail does, > that should solve the problem, because my sub process control task does know > when the sub process ends, and write a specific ending tag to the end of the > log file, which is what I was planning to watch/search for. Every page of my > portal does include a standard master template (except the log text file), > so if I can send a signal at the end of my sub process and capture that by > the master template, then pop up a javascript window, that will do as well. > > Sorry for the lengthy gibberish, hope that you can figure something out from > it. > > Thanks > > On Wed, Oct 10, 2012 at 3:01 AM, Shaun Fryer wrote: >> >> Hi Antonio, >> >> I might be able to help you, but first I need to know a bit more >> detail about what you're trying to do. When you say watch for certain >> keywords from a webpage, what do you mean exactly? If you mean >> searching through a static html document looking for a give word or >> words, that's fairly trivial. However, if you can add javascript to >> the page in question, then you probably control the page, and >> therefore should already know it's content. So question is, why would >> you need front-end code in JavaScript to do it? If you mean doing an >> HTTP request from within a web-page, or even a Cross Origin request, >> in order to receive info from a 3rd-party website, then things could >> become considerably more complicated. >> >> Cheers, >> -- >> Shaun Fryer >> ---------------------------------------------------------- >> perl -e 'print chr for map{$_+=22}($ARGV[0])=~/(\d\d)/g' \ >> 52959394107588899482799210587992861082757785799222 >> ---------------------------------------------------------- >> >> >> On Tue, Oct 9, 2012 at 5:48 PM, Antonio Sun >> wrote: >> > Hi, >> > >> > I know it's kind of OT, but since we have a lot of web experts here, let >> > me >> > try my luck here first. >> > >> > I have zero knowledge of Javascript, I'm wondering if you could give me >> > a >> > big favor to show me how to watch for certain keyword from a web page >> > using >> > Javascript. >> > >> > Basically, I have a slow updating web page, and I need a client side >> > Javascript to watch for a specific keyword in that page and pop up an >> > window >> > if the keyword is found. >> > >> > As I have zero knowledge of Javascript, I hope that your answer is as >> > complete as possible. >> > >> > Thanks a lot in advance >> > >> > Antonio >> > >> > >> > _______________________________________________ >> > toronto-pm mailing list >> > toronto-pm at pm.org >> > http://mail.pm.org/mailman/listinfo/toronto-pm >> > > > From antoniosun at lavabit.com Wed Oct 10 07:33:43 2012 From: antoniosun at lavabit.com (Antonio Sun) Date: Wed, 10 Oct 2012 10:33:43 -0400 Subject: [tpm] [OT] Javascript to watch for certain KW from a web page In-Reply-To: <26dd1dcdbc7e2ced44b8ce60df252385.squirrel@mail.vex.net> References: <26dd1dcdbc7e2ced44b8ce60df252385.squirrel@mail.vex.net> Message-ID: On Wed, Oct 10, 2012 at 9:54 AM, wrote: > > > But my all my fellow coworkers said they don't want to check > > themselves. Instead, they want my web portal to check for them. > > Have the process send mail when it finishes? > It's an in-house quick app, sending email was too complicated to me so I didn't even include the email address in their account info. @Indy, I sure know that AJAX meets my needs, but that'll be a bigger beast than Javascript to me. And the problem is how. If the overhead is too big, or the solution too complicated, I'll turn back to my fellow coworkers and tell them, too bad, I can't do it. That's a solution to me as well. :-) cheers -------------- next part -------------- An HTML attachment was scrubbed... URL: From antoniosun at lavabit.com Wed Oct 10 08:27:30 2012 From: antoniosun at lavabit.com (Antonio Sun) Date: Wed, 10 Oct 2012 11:27:30 -0400 Subject: [tpm] [OT] Javascript to watch for certain KW from a web page In-Reply-To: References: Message-ID: Thanks a lot Shaun. That sure will pave my way to the right direction. I'll start playing. Thanks everyone! On Wed, Oct 10, 2012 at 10:27 AM, Shaun Fryer wrote: > Hi Antonio, > > That makes sense. Unfortunately it's a little beyond the scope of a > simple email to provide a complete solution for your situation. > However, you might try something like the following. > > You'll need two things. #1. an ajax function of some kind. Given that > you aren't interested in learning JS, I'd recommend using a > cross-browser abstraction library which has an ajax method, such as > jQuery. #2. You'll need a popup dialogue of some kind. There are > plenty to choose from. For the purposes of providing an example, I've > [arbitrarily] chosen the facybox jQuery plugin. I have no direct > experience with it, but the API seems simple enough, so it should work > fine. > > Add a script tag including the jQuery library, followed by one for the > plugin for your popup ( http://bitbonsai.com/facybox/ ). Now in a > separate script tag below this, add code similar to that below > (modified accordingly). > > var nMilliseconds = 60*1000; // frequency of server check in milliseconds > var checkServerStatus = function () { > $.ajax({ url: "/path/to/your/log/file/script" }).done(function > (jqXHR, textStatus) { > if (/a regexp matching text in your log file/.test(jqXHR.responseText)) > $.facybox("The text you wish the user to see in the popup > dialogue."); > else setTimeout( checkServerStatus, nMilliseconds ); > }); > }; > setTimeout( checkServerStatus, nMilliseconds ); > > The above is just pseudo-code, but it *should* work with very little > modification, assuming you're using the indicated JS libraries. > > Hope this helps. > -- > Shaun Fryer > ---------------------------------------------------------- > perl -e 'print chr for map{$_+=22}($ARGV[0])=~/(\d\d)/g' \ > 52959394107588899482799210587992861082757785799222 > ---------------------------------------------------------- > > > On Wed, Oct 10, 2012 at 9:51 AM, Antonio Sun > wrote: > > Hi, thanks a lot for your offer Shaun. > > > > That was actually what I thought the solution to be. Now let's forget > what I > > said and focus on what I need to accomplish. > > > > Yes, I totally control the page content. The situation is, > > > > I am designing a web portal that can launch back-end server side > processes. > > The problem is that the process can finish in seconds, or it might need > > hours to finish, depending how much work the process has. So my design > is to > > spawn a sub process, and capture all its outputs to a log text file, then > > return immediately to the user, in a web notice page saying, your job is > > queued; here is the log url; please check manually if is finished or not. > > > > But my all my fellow coworkers said they don't want to check themselves. > > Instead, they want my web portal to check for them. I couldn't think of > any > > solution from the server side to capture the end of the sub process, then > > informed the already submitted web notice page. Hence, I'm turning to the > > javascript front-end for solutions. Because I have zero knowledge of > > Javascript, it might not be feasible at all. But I know the best > solution is > > that if I can have a desktop notification mechanism just like gmail does, > > that should solve the problem, because my sub process control task does > know > > when the sub process ends, and write a specific ending tag to the end of > the > > log file, which is what I was planning to watch/search for. Every page > of my > > portal does include a standard master template (except the log text > file), > > so if I can send a signal at the end of my sub process and capture that > by > > the master template, then pop up a javascript window, that will do as > well. > > > > Sorry for the lengthy gibberish, hope that you can figure something out > from > > it. > > > > Thanks > > > > On Wed, Oct 10, 2012 at 3:01 AM, Shaun Fryer wrote: > >> > >> Hi Antonio, > >> > >> I might be able to help you, but first I need to know a bit more > >> detail about what you're trying to do. When you say watch for certain > >> keywords from a webpage, what do you mean exactly? If you mean > >> searching through a static html document looking for a give word or > >> words, that's fairly trivial. However, if you can add javascript to > >> the page in question, then you probably control the page, and > >> therefore should already know it's content. So question is, why would > >> you need front-end code in JavaScript to do it? If you mean doing an > >> HTTP request from within a web-page, or even a Cross Origin request, > >> in order to receive info from a 3rd-party website, then things could > >> become considerably more complicated. > >> > >> Cheers, > >> -- > >> Shaun Fryer > >> ---------------------------------------------------------- > >> perl -e 'print chr for map{$_+=22}($ARGV[0])=~/(\d\d)/g' \ > >> 52959394107588899482799210587992861082757785799222 > >> ---------------------------------------------------------- > >> > >> > >> On Tue, Oct 9, 2012 at 5:48 PM, Antonio Sun > >> wrote: > >> > Hi, > >> > > >> > I know it's kind of OT, but since we have a lot of web experts here, > let > >> > me > >> > try my luck here first. > >> > > >> > I have zero knowledge of Javascript, I'm wondering if you could give > me > >> > a > >> > big favor to show me how to watch for certain keyword from a web page > >> > using > >> > Javascript. > >> > > >> > Basically, I have a slow updating web page, and I need a client side > >> > Javascript to watch for a specific keyword in that page and pop up an > >> > window > >> > if the keyword is found. > >> > > >> > As I have zero knowledge of Javascript, I hope that your answer is as > >> > complete as possible. > >> > > >> > Thanks a lot in advance > >> > > >> > Antonio > >> > > >> > > >> > _______________________________________________ > >> > toronto-pm mailing list > >> > toronto-pm at pm.org > >> > http://mail.pm.org/mailman/listinfo/toronto-pm > >> > > > > > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From ioncache at gmail.com Wed Oct 10 08:40:48 2012 From: ioncache at gmail.com (Mark Jubenville) Date: Wed, 10 Oct 2012 11:40:48 -0400 Subject: [tpm] [OT] Javascript to watch for certain KW from a web page In-Reply-To: References: Message-ID: <50759700.1050900@gmail.com> I'd use setInerval instead of setTimeout though: var page_check; var nMilliseconds = 60*1000; // frequency of server check in milliseconds var checkServerStatus = function () { $.ajax({ url: "/path/to/your/log/file/script" }).done(function (jqXHR, textStatus) { if (/a regexp matching text in your log file/.test(jqXHR.responseText)){ $.facybox("The text you wish the user to see in the popup dialogue."); clearInterval(page_check); } }); }; page_check = setInterval( checkServerStatus, nMilliseconds ); On 2012-10-10 11:27 AM, Antonio Sun wrote: > Thanks a lot Shaun. > > That sure will pave my way to the right direction. > I'll start playing. > > Thanks everyone! > > On Wed, Oct 10, 2012 at 10:27 AM, Shaun Fryer > wrote: > > Hi Antonio, > > That makes sense. Unfortunately it's a little beyond the scope of a > simple email to provide a complete solution for your situation. > However, you might try something like the following. > > You'll need two things. #1. an ajax function of some kind. Given that > you aren't interested in learning JS, I'd recommend using a > cross-browser abstraction library which has an ajax method, such as > jQuery. #2. You'll need a popup dialogue of some kind. There are > plenty to choose from. For the purposes of providing an example, I've > [arbitrarily] chosen the facybox jQuery plugin. I have no direct > experience with it, but the API seems simple enough, so it should work > fine. > > Add a script tag including the jQuery library, followed by one for the > plugin for your popup ( http://bitbonsai.com/facybox/ ). Now in a > separate script tag below this, add code similar to that below > (modified accordingly). > > var nMilliseconds = 60*1000; // frequency of server check in > milliseconds > var checkServerStatus = function () { > $.ajax({ url: "/path/to/your/log/file/script" }).done(function > (jqXHR, textStatus) { > if (/a regexp matching text in your log > file/.test(jqXHR.responseText)) > $.facybox("The text you wish the user to see in the popup > dialogue."); > else setTimeout( checkServerStatus, nMilliseconds ); > }); > }; > setTimeout( checkServerStatus, nMilliseconds ); > > The above is just pseudo-code, but it *should* work with very little > modification, assuming you're using the indicated JS libraries. > > Hope this helps. > -- > Shaun Fryer > ---------------------------------------------------------- > perl -e 'print chr for map{$_+=22}($ARGV[0])=~/(\d\d)/g' \ > 52959394107588899482799210587992861082757785799222 > ---------------------------------------------------------- > > > On Wed, Oct 10, 2012 at 9:51 AM, Antonio Sun > > wrote: > > Hi, thanks a lot for your offer Shaun. > > > > That was actually what I thought the solution to be. Now let's > forget what I > > said and focus on what I need to accomplish. > > > > Yes, I totally control the page content. The situation is, > > > > I am designing a web portal that can launch back-end server side > processes. > > The problem is that the process can finish in seconds, or it > might need > > hours to finish, depending how much work the process has. So my > design is to > > spawn a sub process, and capture all its outputs to a log text > file, then > > return immediately to the user, in a web notice page saying, > your job is > > queued; here is the log url; please check manually if is > finished or not. > > > > But my all my fellow coworkers said they don't want to check > themselves. > > Instead, they want my web portal to check for them. I couldn't > think of any > > solution from the server side to capture the end of the sub > process, then > > informed the already submitted web notice page. Hence, I'm > turning to the > > javascript front-end for solutions. Because I have zero knowledge of > > Javascript, it might not be feasible at all. But I know the best > solution is > > that if I can have a desktop notification mechanism just like > gmail does, > > that should solve the problem, because my sub process control > task does know > > when the sub process ends, and write a specific ending tag to > the end of the > > log file, which is what I was planning to watch/search for. > Every page of my > > portal does include a standard master template (except the log > text file), > > so if I can send a signal at the end of my sub process and > capture that by > > the master template, then pop up a javascript window, that will > do as well. > > > > Sorry for the lengthy gibberish, hope that you can figure > something out from > > it. > > > > Thanks > > > > On Wed, Oct 10, 2012 at 3:01 AM, Shaun Fryer > wrote: > >> > >> Hi Antonio, > >> > >> I might be able to help you, but first I need to know a bit more > >> detail about what you're trying to do. When you say watch for > certain > >> keywords from a webpage, what do you mean exactly? If you mean > >> searching through a static html document looking for a give word or > >> words, that's fairly trivial. However, if you can add javascript to > >> the page in question, then you probably control the page, and > >> therefore should already know it's content. So question is, why > would > >> you need front-end code in JavaScript to do it? If you mean > doing an > >> HTTP request from within a web-page, or even a Cross Origin > request, > >> in order to receive info from a 3rd-party website, then things > could > >> become considerably more complicated. > >> > >> Cheers, > >> -- > >> Shaun Fryer > >> ---------------------------------------------------------- > >> perl -e 'print chr for map{$_+=22}($ARGV[0])=~/(\d\d)/g' \ > >> 52959394107588899482799210587992861082757785799222 > >> ---------------------------------------------------------- > >> > >> > >> On Tue, Oct 9, 2012 at 5:48 PM, Antonio Sun > > > >> wrote: > >> > Hi, > >> > > >> > I know it's kind of OT, but since we have a lot of web > experts here, let > >> > me > >> > try my luck here first. > >> > > >> > I have zero knowledge of Javascript, I'm wondering if you > could give me > >> > a > >> > big favor to show me how to watch for certain keyword from a > web page > >> > using > >> > Javascript. > >> > > >> > Basically, I have a slow updating web page, and I need a > client side > >> > Javascript to watch for a specific keyword in that page and > pop up an > >> > window > >> > if the keyword is found. > >> > > >> > As I have zero knowledge of Javascript, I hope that your > answer is as > >> > complete as possible. > >> > > >> > Thanks a lot in advance > >> > > >> > Antonio > >> > > >> > > >> > _______________________________________________ > >> > toronto-pm mailing list > >> > toronto-pm at pm.org > >> > http://mail.pm.org/mailman/listinfo/toronto-pm > >> > > > > > > > > > > _______________________________________________ > toronto-pm mailing list > toronto-pm at pm.org > http://mail.pm.org/mailman/listinfo/toronto-pm -- Mark Jubenville | ioncache at gmail.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From ioncache at gmail.com Wed Oct 10 09:12:24 2012 From: ioncache at gmail.com (Mark Jubenville) Date: Wed, 10 Oct 2012 12:12:24 -0400 Subject: [tpm] [OT] Javascript to watch for certain KW from a web page In-Reply-To: <50759700.1050900@gmail.com> References: <50759700.1050900@gmail.com> Message-ID: <50759E68.6050109@gmail.com> Alternatively if you don't want to do the whole ajax thing, you can do something similar just checking the text of the body: That doesn't require jQuery either. I put in examples of opening an actual window or just showing an alert box. On 2012-10-10 11:40 AM, Mark Jubenville wrote: > I'd use setInerval instead of setTimeout though: > > var page_check; > > var nMilliseconds = 60*1000; // frequency of server check in milliseconds > var checkServerStatus = function () { > $.ajax({ url: "/path/to/your/log/file/script" }).done(function > (jqXHR, textStatus) { > if (/a regexp matching text in your log > file/.test(jqXHR.responseText)){ > $.facybox("The text you wish the user to see in the popup > dialogue."); > clearInterval(page_check); > } > }); > }; > page_check = setInterval( checkServerStatus, nMilliseconds ); > > > > On 2012-10-10 11:27 AM, Antonio Sun wrote: >> Thanks a lot Shaun. >> >> That sure will pave my way to the right direction. >> I'll start playing. >> >> Thanks everyone! >> >> On Wed, Oct 10, 2012 at 10:27 AM, Shaun Fryer > > wrote: >> >> Hi Antonio, >> >> That makes sense. Unfortunately it's a little beyond the scope of a >> simple email to provide a complete solution for your situation. >> However, you might try something like the following. >> >> You'll need two things. #1. an ajax function of some kind. Given that >> you aren't interested in learning JS, I'd recommend using a >> cross-browser abstraction library which has an ajax method, such as >> jQuery. #2. You'll need a popup dialogue of some kind. There are >> plenty to choose from. For the purposes of providing an example, I've >> [arbitrarily] chosen the facybox jQuery plugin. I have no direct >> experience with it, but the API seems simple enough, so it should >> work >> fine. >> >> Add a script tag including the jQuery library, followed by one >> for the >> plugin for your popup ( http://bitbonsai.com/facybox/ ). Now in a >> separate script tag below this, add code similar to that below >> (modified accordingly). >> >> var nMilliseconds = 60*1000; // frequency of server check in >> milliseconds >> var checkServerStatus = function () { >> $.ajax({ url: "/path/to/your/log/file/script" }).done(function >> (jqXHR, textStatus) { >> if (/a regexp matching text in your log >> file/.test(jqXHR.responseText)) >> $.facybox("The text you wish the user to see in the popup >> dialogue."); >> else setTimeout( checkServerStatus, nMilliseconds ); >> }); >> }; >> setTimeout( checkServerStatus, nMilliseconds ); >> >> The above is just pseudo-code, but it *should* work with very little >> modification, assuming you're using the indicated JS libraries. >> >> Hope this helps. >> -- >> Shaun Fryer >> ---------------------------------------------------------- >> perl -e 'print chr for map{$_+=22}($ARGV[0])=~/(\d\d)/g' \ >> 52959394107588899482799210587992861082757785799222 >> ---------------------------------------------------------- >> >> >> On Wed, Oct 10, 2012 at 9:51 AM, Antonio Sun >> > wrote: >> > Hi, thanks a lot for your offer Shaun. >> > >> > That was actually what I thought the solution to be. Now let's >> forget what I >> > said and focus on what I need to accomplish. >> > >> > Yes, I totally control the page content. The situation is, >> > >> > I am designing a web portal that can launch back-end server >> side processes. >> > The problem is that the process can finish in seconds, or it >> might need >> > hours to finish, depending how much work the process has. So my >> design is to >> > spawn a sub process, and capture all its outputs to a log text >> file, then >> > return immediately to the user, in a web notice page saying, >> your job is >> > queued; here is the log url; please check manually if is >> finished or not. >> > >> > But my all my fellow coworkers said they don't want to check >> themselves. >> > Instead, they want my web portal to check for them. I couldn't >> think of any >> > solution from the server side to capture the end of the sub >> process, then >> > informed the already submitted web notice page. Hence, I'm >> turning to the >> > javascript front-end for solutions. Because I have zero >> knowledge of >> > Javascript, it might not be feasible at all. But I know the >> best solution is >> > that if I can have a desktop notification mechanism just like >> gmail does, >> > that should solve the problem, because my sub process control >> task does know >> > when the sub process ends, and write a specific ending tag to >> the end of the >> > log file, which is what I was planning to watch/search for. >> Every page of my >> > portal does include a standard master template (except the log >> text file), >> > so if I can send a signal at the end of my sub process and >> capture that by >> > the master template, then pop up a javascript window, that will >> do as well. >> > >> > Sorry for the lengthy gibberish, hope that you can figure >> something out from >> > it. >> > >> > Thanks >> > >> > On Wed, Oct 10, 2012 at 3:01 AM, Shaun Fryer >> > wrote: >> >> >> >> Hi Antonio, >> >> >> >> I might be able to help you, but first I need to know a bit more >> >> detail about what you're trying to do. When you say watch for >> certain >> >> keywords from a webpage, what do you mean exactly? If you mean >> >> searching through a static html document looking for a give >> word or >> >> words, that's fairly trivial. However, if you can add >> javascript to >> >> the page in question, then you probably control the page, and >> >> therefore should already know it's content. So question is, >> why would >> >> you need front-end code in JavaScript to do it? If you mean >> doing an >> >> HTTP request from within a web-page, or even a Cross Origin >> request, >> >> in order to receive info from a 3rd-party website, then things >> could >> >> become considerably more complicated. >> >> >> >> Cheers, >> >> -- >> >> Shaun Fryer >> >> ---------------------------------------------------------- >> >> perl -e 'print chr for map{$_+=22}($ARGV[0])=~/(\d\d)/g' \ >> >> 52959394107588899482799210587992861082757785799222 >> >> ---------------------------------------------------------- >> >> >> >> >> >> On Tue, Oct 9, 2012 at 5:48 PM, Antonio Sun >> > >> >> wrote: >> >> > Hi, >> >> > >> >> > I know it's kind of OT, but since we have a lot of web >> experts here, let >> >> > me >> >> > try my luck here first. >> >> > >> >> > I have zero knowledge of Javascript, I'm wondering if you >> could give me >> >> > a >> >> > big favor to show me how to watch for certain keyword from a >> web page >> >> > using >> >> > Javascript. >> >> > >> >> > Basically, I have a slow updating web page, and I need a >> client side >> >> > Javascript to watch for a specific keyword in that page and >> pop up an >> >> > window >> >> > if the keyword is found. >> >> > >> >> > As I have zero knowledge of Javascript, I hope that your >> answer is as >> >> > complete as possible. >> >> > >> >> > Thanks a lot in advance >> >> > >> >> > Antonio >> >> > >> >> > >> >> > _______________________________________________ >> >> > toronto-pm mailing list >> >> > toronto-pm at pm.org >> >> > http://mail.pm.org/mailman/listinfo/toronto-pm >> >> > >> > >> > >> >> >> >> >> _______________________________________________ >> toronto-pm mailing list >> toronto-pm at pm.org >> http://mail.pm.org/mailman/listinfo/toronto-pm > > -- > > Mark Jubenville |ioncache at gmail.com -- Mark Jubenville | ioncache at gmail.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From william.muriithi at gmail.com Wed Oct 10 09:23:14 2012 From: william.muriithi at gmail.com (William Muriithi) Date: Wed, 10 Oct 2012 12:23:14 -0400 Subject: [tpm] Alpaca book Message-ID: Hello, Would there be anybody willing to lead Intermediate Perl book for a couple of weeks. I would appreciate your assistance. Would be fine too if you want to dispose it inexpensively Regard, William From sfryer at sourcery.ca Wed Oct 10 11:01:05 2012 From: sfryer at sourcery.ca (Shaun Fryer) Date: Wed, 10 Oct 2012 14:01:05 -0400 Subject: [tpm] [OT] Javascript to watch for certain KW from a web page In-Reply-To: References: Message-ID: Took a google search and a few secs of cut/paste. But if you don't know what to search for/do, I know... So, no problem. Btw, setInterval works too. Keep in mind that timer resolution however is rarely accurate, and certainly not across browsers. If you use setTimeout with a 1 millisec interval, it just punts the process to the end of the current execution stack. You rarely get better than that without creating a log jam. Not necessary info for your task, but good to know stuff if you care to. -- Shaun Fryer 647-709-6509 ---------------------------------------------------------- perl -e 'print chr for map{$_+=22}($ARGV[0])=~/(\d\d)/g' \ 52959394107588899482799210587992861082757785799222 ---------------------------------------------------------- On Wed, Oct 10, 2012 at 11:27 AM, Antonio Sun wrote: > Thanks a lot Shaun. > > That sure will pave my way to the right direction. > I'll start playing. > > Thanks everyone! > > > On Wed, Oct 10, 2012 at 10:27 AM, Shaun Fryer wrote: >> >> Hi Antonio, >> >> That makes sense. Unfortunately it's a little beyond the scope of a >> simple email to provide a complete solution for your situation. >> However, you might try something like the following. >> >> You'll need two things. #1. an ajax function of some kind. Given that >> you aren't interested in learning JS, I'd recommend using a >> cross-browser abstraction library which has an ajax method, such as >> jQuery. #2. You'll need a popup dialogue of some kind. There are >> plenty to choose from. For the purposes of providing an example, I've >> [arbitrarily] chosen the facybox jQuery plugin. I have no direct >> experience with it, but the API seems simple enough, so it should work >> fine. >> >> Add a script tag including the jQuery library, followed by one for the >> plugin for your popup ( http://bitbonsai.com/facybox/ ). Now in a >> separate script tag below this, add code similar to that below >> (modified accordingly). >> >> var nMilliseconds = 60*1000; // frequency of server check in milliseconds >> var checkServerStatus = function () { >> $.ajax({ url: "/path/to/your/log/file/script" }).done(function >> (jqXHR, textStatus) { >> if (/a regexp matching text in your log >> file/.test(jqXHR.responseText)) >> $.facybox("The text you wish the user to see in the popup >> dialogue."); >> else setTimeout( checkServerStatus, nMilliseconds ); >> }); >> }; >> setTimeout( checkServerStatus, nMilliseconds ); >> >> The above is just pseudo-code, but it *should* work with very little >> modification, assuming you're using the indicated JS libraries. >> >> Hope this helps. >> -- >> Shaun Fryer >> ---------------------------------------------------------- >> perl -e 'print chr for map{$_+=22}($ARGV[0])=~/(\d\d)/g' \ >> 52959394107588899482799210587992861082757785799222 >> ---------------------------------------------------------- >> >> >> On Wed, Oct 10, 2012 at 9:51 AM, Antonio Sun >> wrote: >> > Hi, thanks a lot for your offer Shaun. >> > >> > That was actually what I thought the solution to be. Now let's forget >> > what I >> > said and focus on what I need to accomplish. >> > >> > Yes, I totally control the page content. The situation is, >> > >> > I am designing a web portal that can launch back-end server side >> > processes. >> > The problem is that the process can finish in seconds, or it might need >> > hours to finish, depending how much work the process has. So my design >> > is to >> > spawn a sub process, and capture all its outputs to a log text file, >> > then >> > return immediately to the user, in a web notice page saying, your job is >> > queued; here is the log url; please check manually if is finished or >> > not. >> > >> > But my all my fellow coworkers said they don't want to check themselves. >> > Instead, they want my web portal to check for them. I couldn't think of >> > any >> > solution from the server side to capture the end of the sub process, >> > then >> > informed the already submitted web notice page. Hence, I'm turning to >> > the >> > javascript front-end for solutions. Because I have zero knowledge of >> > Javascript, it might not be feasible at all. But I know the best >> > solution is >> > that if I can have a desktop notification mechanism just like gmail >> > does, >> > that should solve the problem, because my sub process control task does >> > know >> > when the sub process ends, and write a specific ending tag to the end of >> > the >> > log file, which is what I was planning to watch/search for. Every page >> > of my >> > portal does include a standard master template (except the log text >> > file), >> > so if I can send a signal at the end of my sub process and capture that >> > by >> > the master template, then pop up a javascript window, that will do as >> > well. >> > >> > Sorry for the lengthy gibberish, hope that you can figure something out >> > from >> > it. >> > >> > Thanks >> > >> > On Wed, Oct 10, 2012 at 3:01 AM, Shaun Fryer wrote: >> >> >> >> Hi Antonio, >> >> >> >> I might be able to help you, but first I need to know a bit more >> >> detail about what you're trying to do. When you say watch for certain >> >> keywords from a webpage, what do you mean exactly? If you mean >> >> searching through a static html document looking for a give word or >> >> words, that's fairly trivial. However, if you can add javascript to >> >> the page in question, then you probably control the page, and >> >> therefore should already know it's content. So question is, why would >> >> you need front-end code in JavaScript to do it? If you mean doing an >> >> HTTP request from within a web-page, or even a Cross Origin request, >> >> in order to receive info from a 3rd-party website, then things could >> >> become considerably more complicated. >> >> >> >> Cheers, >> >> -- >> >> Shaun Fryer >> >> ---------------------------------------------------------- >> >> perl -e 'print chr for map{$_+=22}($ARGV[0])=~/(\d\d)/g' \ >> >> 52959394107588899482799210587992861082757785799222 >> >> ---------------------------------------------------------- >> >> >> >> >> >> On Tue, Oct 9, 2012 at 5:48 PM, Antonio Sun >> >> wrote: >> >> > Hi, >> >> > >> >> > I know it's kind of OT, but since we have a lot of web experts here, >> >> > let >> >> > me >> >> > try my luck here first. >> >> > >> >> > I have zero knowledge of Javascript, I'm wondering if you could give >> >> > me >> >> > a >> >> > big favor to show me how to watch for certain keyword from a web page >> >> > using >> >> > Javascript. >> >> > >> >> > Basically, I have a slow updating web page, and I need a client side >> >> > Javascript to watch for a specific keyword in that page and pop up an >> >> > window >> >> > if the keyword is found. >> >> > >> >> > As I have zero knowledge of Javascript, I hope that your answer is as >> >> > complete as possible. >> >> > >> >> > Thanks a lot in advance >> >> > >> >> > Antonio >> >> > >> >> > >> >> > _______________________________________________ >> >> > toronto-pm mailing list >> >> > toronto-pm at pm.org >> >> > http://mail.pm.org/mailman/listinfo/toronto-pm >> >> > >> > >> > > > From levp at lev.ca Wed Oct 10 11:18:56 2012 From: levp at lev.ca (Lev Piaseckyj) Date: Wed, 10 Oct 2012 14:18:56 -0400 Subject: [tpm] Safari Books Online through TPL (Re: Alpaca book) Message-ID: <6986942D-C80C-4282-BEDC-362122BCD839@lev.ca> On 2012-10-10, at 12:23 PM, William Muriithi wrote: > Would there be anybody willing to le[n]d Intermediate Perl book for a > couple of weeks. [...] If you have a Toronto Public Library card you can read the Alpaca book (and over 7000 others) online for free, "paid for and licensed by your public library". http://bit.ly/tpl-safari HTH, Lev From antoniosun at lavabit.com Thu Oct 11 08:05:09 2012 From: antoniosun at lavabit.com (Antonio Sun) Date: Thu, 11 Oct 2012 11:05:09 -0400 Subject: [tpm] [OT] Javascript to watch for certain KW from a web page In-Reply-To: <50759E68.6050109@gmail.com> References: <50759700.1050900@gmail.com> <50759E68.6050109@gmail.com> Message-ID: Thanks a lot Mark, That works like a charm. I really appreciate your simplified solution sample code. Thanks again everyone for your helps. On Wed, Oct 10, 2012 at 12:12 PM, Mark Jubenville wrote: > Alternatively if you don't want to do the whole ajax thing, you can do > something similar just checking the text of the body: > > > > That doesn't require jQuery either. > > I put in examples of opening an actual window or just showing an alert box. > > > On 2012-10-10 11:40 AM, Mark Jubenville wrote: > > I'd use setInerval instead of setTimeout though: > > var page_check; > > var nMilliseconds = 60*1000; // frequency of server check in milliseconds > var checkServerStatus = function () { > $.ajax({ url: "/path/to/your/log/file/script" }).done(function > (jqXHR, textStatus) { > if (/a regexp matching text in your log > file/.test(jqXHR.responseText)) { > $.facybox("The text you wish the user to see in the popup > dialogue."); > clearInterval(page_check); > } > }); > }; > page_check = setInterval( checkServerStatus, nMilliseconds ); > > > > On 2012-10-10 11:27 AM, Antonio Sun wrote: > > Thanks a lot Shaun. > > That sure will pave my way to the right direction. > I'll start playing. > > Thanks everyone! > > On Wed, Oct 10, 2012 at 10:27 AM, Shaun Fryer wrote: > >> Hi Antonio, >> >> That makes sense. Unfortunately it's a little beyond the scope of a >> simple email to provide a complete solution for your situation. >> However, you might try something like the following. >> >> You'll need two things. #1. an ajax function of some kind. Given that >> you aren't interested in learning JS, I'd recommend using a >> cross-browser abstraction library which has an ajax method, such as >> jQuery. #2. You'll need a popup dialogue of some kind. There are >> plenty to choose from. For the purposes of providing an example, I've >> [arbitrarily] chosen the facybox jQuery plugin. I have no direct >> experience with it, but the API seems simple enough, so it should work >> fine. >> >> Add a script tag including the jQuery library, followed by one for the >> plugin for your popup ( http://bitbonsai.com/facybox/ ). Now in a >> separate script tag below this, add code similar to that below >> (modified accordingly). >> >> var nMilliseconds = 60*1000; // frequency of server check in milliseconds >> var checkServerStatus = function () { >> $.ajax({ url: "/path/to/your/log/file/script" }).done(function >> (jqXHR, textStatus) { >> if (/a regexp matching text in your log >> file/.test(jqXHR.responseText)) >> $.facybox("The text you wish the user to see in the popup >> dialogue."); >> else setTimeout( checkServerStatus, nMilliseconds ); >> }); >> }; >> setTimeout( checkServerStatus, nMilliseconds ); >> >> The above is just pseudo-code, but it *should* work with very little >> modification, assuming you're using the indicated JS libraries. >> >> Hope this helps. >> -- >> Shaun Fryer >> ---------------------------------------------------------- >> perl -e 'print chr for map{$_+=22}($ARGV[0])=~/(\d\d)/g' \ >> 52959394107588899482799210587992861082757785799222 >> ---------------------------------------------------------- >> >> >> On Wed, Oct 10, 2012 at 9:51 AM, Antonio Sun >> wrote: >> > Hi, thanks a lot for your offer Shaun. >> > >> > That was actually what I thought the solution to be. Now let's forget >> what I >> > said and focus on what I need to accomplish. >> > >> > Yes, I totally control the page content. The situation is, >> > >> > I am designing a web portal that can launch back-end server side >> processes. >> > The problem is that the process can finish in seconds, or it might need >> > hours to finish, depending how much work the process has. So my design >> is to >> > spawn a sub process, and capture all its outputs to a log text file, >> then >> > return immediately to the user, in a web notice page saying, your job is >> > queued; here is the log url; please check manually if is finished or >> not. >> > >> > But my all my fellow coworkers said they don't want to check themselves. >> > Instead, they want my web portal to check for them. I couldn't think of >> any >> > solution from the server side to capture the end of the sub process, >> then >> > informed the already submitted web notice page. Hence, I'm turning to >> the >> > javascript front-end for solutions. Because I have zero knowledge of >> > Javascript, it might not be feasible at all. But I know the best >> solution is >> > that if I can have a desktop notification mechanism just like gmail >> does, >> > that should solve the problem, because my sub process control task does >> know >> > when the sub process ends, and write a specific ending tag to the end >> of the >> > log file, which is what I was planning to watch/search for. Every page >> of my >> > portal does include a standard master template (except the log text >> file), >> > so if I can send a signal at the end of my sub process and capture that >> by >> > the master template, then pop up a javascript window, that will do as >> well. >> > >> > Sorry for the lengthy gibberish, hope that you can figure something out >> from >> > it. >> > >> > Thanks >> > -- > > Mark Jubenville | ioncache at gmail.com > > > _______________________________________________ > toronto-pm mailing list > toronto-pm at pm.org > http://mail.pm.org/mailman/listinfo/toronto-pm > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From sfryer at sourcery.ca Fri Oct 12 01:31:45 2012 From: sfryer at sourcery.ca (Shaun Fryer) Date: Fri, 12 Oct 2012 04:31:45 -0400 Subject: [tpm] [OT] Javascript to watch for certain KW from a web page In-Reply-To: References: <50759700.1050900@gmail.com> <50759E68.6050109@gmail.com> Message-ID: Or for yet another way, also sans jquery... var iframe = document.createElement("iframe"); var o = {display:"none", height:0, width:0}; for (var attr in o) iframe.style[attr] = o[attr]; // append a timestamp below to bypass cache var getServerStatus = function () { iframe.src = "/url/to/your/log/output?" + (new Date ()).getTime() }; iframe.onload = function() { var win = iframe.contentWindow || iframe.contentDocument; if (/your regexp/.test(win.document.body.innerHTML)) alert("your process completed"); else setTimeout( getServerStatus, 60*1000 ); // ~1 minute }; getServerStatus(); document.body.appendChild(iframe); -- Shaun Fryer 647-709-6509 ---------------------------------------------------------- perl -e 'print chr for map{$_+=22}($ARGV[0])=~/(\d\d)/g' \ 52959394107588899482799210587992861082757785799222 ---------------------------------------------------------- On Thu, Oct 11, 2012 at 11:05 AM, Antonio Sun wrote: > Thanks a lot Mark, > That works like a charm. I really appreciate your simplified solution sample > code. > > Thanks again everyone for your helps. > > On Wed, Oct 10, 2012 at 12:12 PM, Mark Jubenville > wrote: >> >> Alternatively if you don't want to do the whole ajax thing, you can do >> something similar just checking the text of the body: >> >> >> >> That doesn't require jQuery either. >> >> I put in examples of opening an actual window or just showing an alert >> box. >> >> >> On 2012-10-10 11:40 AM, Mark Jubenville wrote: >> >> I'd use setInerval instead of setTimeout though: >> >> var page_check; >> >> var nMilliseconds = 60*1000; // frequency of server check in milliseconds >> var checkServerStatus = function () { >> $.ajax({ url: "/path/to/your/log/file/script" }).done(function >> (jqXHR, textStatus) { >> if (/a regexp matching text in your log >> file/.test(jqXHR.responseText)) { >> $.facybox("The text you wish the user to see in the popup >> dialogue."); >> clearInterval(page_check); >> } >> }); >> }; >> page_check = setInterval( checkServerStatus, nMilliseconds ); >> >> >> >> On 2012-10-10 11:27 AM, Antonio Sun wrote: >> >> Thanks a lot Shaun. >> >> That sure will pave my way to the right direction. >> I'll start playing. >> >> Thanks everyone! >> >> On Wed, Oct 10, 2012 at 10:27 AM, Shaun Fryer wrote: >>> >>> Hi Antonio, >>> >>> That makes sense. Unfortunately it's a little beyond the scope of a >>> simple email to provide a complete solution for your situation. >>> However, you might try something like the following. >>> >>> You'll need two things. #1. an ajax function of some kind. Given that >>> you aren't interested in learning JS, I'd recommend using a >>> cross-browser abstraction library which has an ajax method, such as >>> jQuery. #2. You'll need a popup dialogue of some kind. There are >>> plenty to choose from. For the purposes of providing an example, I've >>> [arbitrarily] chosen the facybox jQuery plugin. I have no direct >>> experience with it, but the API seems simple enough, so it should work >>> fine. >>> >>> Add a script tag including the jQuery library, followed by one for the >>> plugin for your popup ( http://bitbonsai.com/facybox/ ). Now in a >>> separate script tag below this, add code similar to that below >>> (modified accordingly). >>> >>> var nMilliseconds = 60*1000; // frequency of server check in milliseconds >>> var checkServerStatus = function () { >>> $.ajax({ url: "/path/to/your/log/file/script" }).done(function >>> (jqXHR, textStatus) { >>> if (/a regexp matching text in your log >>> file/.test(jqXHR.responseText)) >>> $.facybox("The text you wish the user to see in the popup >>> dialogue."); >>> else setTimeout( checkServerStatus, nMilliseconds ); >>> }); >>> }; >>> setTimeout( checkServerStatus, nMilliseconds ); >>> >>> The above is just pseudo-code, but it *should* work with very little >>> modification, assuming you're using the indicated JS libraries. >>> >>> Hope this helps. >>> -- >>> Shaun Fryer >>> ---------------------------------------------------------- >>> perl -e 'print chr for map{$_+=22}($ARGV[0])=~/(\d\d)/g' \ >>> 52959394107588899482799210587992861082757785799222 >>> ---------------------------------------------------------- >>> >>> >>> On Wed, Oct 10, 2012 at 9:51 AM, Antonio Sun >>> wrote: >>> > Hi, thanks a lot for your offer Shaun. >>> > >>> > That was actually what I thought the solution to be. Now let's forget >>> > what I >>> > said and focus on what I need to accomplish. >>> > >>> > Yes, I totally control the page content. The situation is, >>> > >>> > I am designing a web portal that can launch back-end server side >>> > processes. >>> > The problem is that the process can finish in seconds, or it might need >>> > hours to finish, depending how much work the process has. So my design >>> > is to >>> > spawn a sub process, and capture all its outputs to a log text file, >>> > then >>> > return immediately to the user, in a web notice page saying, your job >>> > is >>> > queued; here is the log url; please check manually if is finished or >>> > not. >>> > >>> > But my all my fellow coworkers said they don't want to check >>> > themselves. >>> > Instead, they want my web portal to check for them. I couldn't think of >>> > any >>> > solution from the server side to capture the end of the sub process, >>> > then >>> > informed the already submitted web notice page. Hence, I'm turning to >>> > the >>> > javascript front-end for solutions. Because I have zero knowledge of >>> > Javascript, it might not be feasible at all. But I know the best >>> > solution is >>> > that if I can have a desktop notification mechanism just like gmail >>> > does, >>> > that should solve the problem, because my sub process control task does >>> > know >>> > when the sub process ends, and write a specific ending tag to the end >>> > of the >>> > log file, which is what I was planning to watch/search for. Every page >>> > of my >>> > portal does include a standard master template (except the log text >>> > file), >>> > so if I can send a signal at the end of my sub process and capture that >>> > by >>> > the master template, then pop up a javascript window, that will do as >>> > well. >>> > >>> > Sorry for the lengthy gibberish, hope that you can figure something out >>> > from >>> > it. >>> > >>> > Thanks >> >> -- >> >> Mark Jubenville | ioncache at gmail.com >> >> >> _______________________________________________ >> toronto-pm mailing list >> toronto-pm at pm.org >> http://mail.pm.org/mailman/listinfo/toronto-pm >> > > > _______________________________________________ > toronto-pm mailing list > toronto-pm at pm.org > http://mail.pm.org/mailman/listinfo/toronto-pm > From sfryer at sourcery.ca Fri Oct 12 01:38:24 2012 From: sfryer at sourcery.ca (Shaun Fryer) Date: Fri, 12 Oct 2012 04:38:24 -0400 Subject: [tpm] [OT] Javascript to watch for certain KW from a web page In-Reply-To: References: <50759700.1050900@gmail.com> <50759E68.6050109@gmail.com> Message-ID: The reason jquery is a good idea, is you probably want to add it as an onclick to a button or something. It's worth it to take the 10 minutes to rtfm, and avoid yourself alot of headache with cross-browser events. -- Shaun Fryer 647-709-6509 ---------------------------------------------------------- perl -e 'print chr for map{$_+=22}($ARGV[0])=~/(\d\d)/g' \ 52959394107588899482799210587992861082757785799222 ---------------------------------------------------------- On Fri, Oct 12, 2012 at 4:31 AM, Shaun Fryer wrote: > Or for yet another way, also sans jquery... > > var iframe = document.createElement("iframe"); > var o = {display:"none", height:0, width:0}; > for (var attr in o) iframe.style[attr] = o[attr]; // append a > timestamp below to bypass cache > var getServerStatus = function () { iframe.src = > "/url/to/your/log/output?" + (new Date ()).getTime() }; > iframe.onload = function() { > > var win = iframe.contentWindow || iframe.contentDocument; > if (/your regexp/.test(win.document.body.innerHTML)) > alert("your process completed"); > else setTimeout( getServerStatus, 60*1000 ); // ~1 minute > > }; > getServerStatus(); > document.body.appendChild(iframe); > -- > Shaun Fryer > 647-709-6509 > ---------------------------------------------------------- > perl -e 'print chr for map{$_+=22}($ARGV[0])=~/(\d\d)/g' \ > 52959394107588899482799210587992861082757785799222 > ---------------------------------------------------------- > > > On Thu, Oct 11, 2012 at 11:05 AM, Antonio Sun wrote: >> Thanks a lot Mark, >> That works like a charm. I really appreciate your simplified solution sample >> code. >> >> Thanks again everyone for your helps. >> >> On Wed, Oct 10, 2012 at 12:12 PM, Mark Jubenville >> wrote: >>> >>> Alternatively if you don't want to do the whole ajax thing, you can do >>> something similar just checking the text of the body: >>> >>> >>> >>> That doesn't require jQuery either. >>> >>> I put in examples of opening an actual window or just showing an alert >>> box. >>> >>> >>> On 2012-10-10 11:40 AM, Mark Jubenville wrote: >>> >>> I'd use setInerval instead of setTimeout though: >>> >>> var page_check; >>> >>> var nMilliseconds = 60*1000; // frequency of server check in milliseconds >>> var checkServerStatus = function () { >>> $.ajax({ url: "/path/to/your/log/file/script" }).done(function >>> (jqXHR, textStatus) { >>> if (/a regexp matching text in your log >>> file/.test(jqXHR.responseText)) { >>> $.facybox("The text you wish the user to see in the popup >>> dialogue."); >>> clearInterval(page_check); >>> } >>> }); >>> }; >>> page_check = setInterval( checkServerStatus, nMilliseconds ); >>> >>> >>> >>> On 2012-10-10 11:27 AM, Antonio Sun wrote: >>> >>> Thanks a lot Shaun. >>> >>> That sure will pave my way to the right direction. >>> I'll start playing. >>> >>> Thanks everyone! >>> >>> On Wed, Oct 10, 2012 at 10:27 AM, Shaun Fryer wrote: >>>> >>>> Hi Antonio, >>>> >>>> That makes sense. Unfortunately it's a little beyond the scope of a >>>> simple email to provide a complete solution for your situation. >>>> However, you might try something like the following. >>>> >>>> You'll need two things. #1. an ajax function of some kind. Given that >>>> you aren't interested in learning JS, I'd recommend using a >>>> cross-browser abstraction library which has an ajax method, such as >>>> jQuery. #2. You'll need a popup dialogue of some kind. There are >>>> plenty to choose from. For the purposes of providing an example, I've >>>> [arbitrarily] chosen the facybox jQuery plugin. I have no direct >>>> experience with it, but the API seems simple enough, so it should work >>>> fine. >>>> >>>> Add a script tag including the jQuery library, followed by one for the >>>> plugin for your popup ( http://bitbonsai.com/facybox/ ). Now in a >>>> separate script tag below this, add code similar to that below >>>> (modified accordingly). >>>> >>>> var nMilliseconds = 60*1000; // frequency of server check in milliseconds >>>> var checkServerStatus = function () { >>>> $.ajax({ url: "/path/to/your/log/file/script" }).done(function >>>> (jqXHR, textStatus) { >>>> if (/a regexp matching text in your log >>>> file/.test(jqXHR.responseText)) >>>> $.facybox("The text you wish the user to see in the popup >>>> dialogue."); >>>> else setTimeout( checkServerStatus, nMilliseconds ); >>>> }); >>>> }; >>>> setTimeout( checkServerStatus, nMilliseconds ); >>>> >>>> The above is just pseudo-code, but it *should* work with very little >>>> modification, assuming you're using the indicated JS libraries. >>>> >>>> Hope this helps. >>>> -- >>>> Shaun Fryer >>>> ---------------------------------------------------------- >>>> perl -e 'print chr for map{$_+=22}($ARGV[0])=~/(\d\d)/g' \ >>>> 52959394107588899482799210587992861082757785799222 >>>> ---------------------------------------------------------- >>>> >>>> >>>> On Wed, Oct 10, 2012 at 9:51 AM, Antonio Sun >>>> wrote: >>>> > Hi, thanks a lot for your offer Shaun. >>>> > >>>> > That was actually what I thought the solution to be. Now let's forget >>>> > what I >>>> > said and focus on what I need to accomplish. >>>> > >>>> > Yes, I totally control the page content. The situation is, >>>> > >>>> > I am designing a web portal that can launch back-end server side >>>> > processes. >>>> > The problem is that the process can finish in seconds, or it might need >>>> > hours to finish, depending how much work the process has. So my design >>>> > is to >>>> > spawn a sub process, and capture all its outputs to a log text file, >>>> > then >>>> > return immediately to the user, in a web notice page saying, your job >>>> > is >>>> > queued; here is the log url; please check manually if is finished or >>>> > not. >>>> > >>>> > But my all my fellow coworkers said they don't want to check >>>> > themselves. >>>> > Instead, they want my web portal to check for them. I couldn't think of >>>> > any >>>> > solution from the server side to capture the end of the sub process, >>>> > then >>>> > informed the already submitted web notice page. Hence, I'm turning to >>>> > the >>>> > javascript front-end for solutions. Because I have zero knowledge of >>>> > Javascript, it might not be feasible at all. But I know the best >>>> > solution is >>>> > that if I can have a desktop notification mechanism just like gmail >>>> > does, >>>> > that should solve the problem, because my sub process control task does >>>> > know >>>> > when the sub process ends, and write a specific ending tag to the end >>>> > of the >>>> > log file, which is what I was planning to watch/search for. Every page >>>> > of my >>>> > portal does include a standard master template (except the log text >>>> > file), >>>> > so if I can send a signal at the end of my sub process and capture that >>>> > by >>>> > the master template, then pop up a javascript window, that will do as >>>> > well. >>>> > >>>> > Sorry for the lengthy gibberish, hope that you can figure something out >>>> > from >>>> > it. >>>> > >>>> > Thanks >>> >>> -- >>> >>> Mark Jubenville | ioncache at gmail.com >>> >>> >>> _______________________________________________ >>> toronto-pm mailing list >>> toronto-pm at pm.org >>> http://mail.pm.org/mailman/listinfo/toronto-pm >>> >> >> >> _______________________________________________ >> toronto-pm mailing list >> toronto-pm at pm.org >> http://mail.pm.org/mailman/listinfo/toronto-pm >> From antoniosun at lavabit.com Fri Oct 12 06:45:56 2012 From: antoniosun at lavabit.com (Antonio Sun) Date: Fri, 12 Oct 2012 09:45:56 -0400 Subject: [tpm] [OT] Javascript to watch for certain KW from a web page In-Reply-To: References: <50759700.1050900@gmail.com> <50759E68.6050109@gmail.com> Message-ID: Thanks Shaun. Yes I did use jQuery eventually. As I have zero knowledge of Javascript, I started easy with Mark's code on a static page, once successful, I moved on to jQuery. Thanks for your recommendation. jQuery is really powerful and well commented. I was able to get my job done with only the knowledge from the following two tutorials: The load() method http://www.jquery-tutorial.net/ajax/the-load-method/ Showing progress http://www.jquery-tutorial.net/ajax/showing-progress/ Thanks On Fri, Oct 12, 2012 at 4:38 AM, Shaun Fryer wrote: > The reason jquery is a good idea, is you probably want to add it as an > onclick to a button or something. It's worth it to take the 10 minutes > to rtfm, and avoid yourself alot of headache with cross-browser > events. > -- > Shaun Fryer > 647-709-6509 > ---------------------------------------------------------- > perl -e 'print chr for map{$_+=22}($ARGV[0])=~/(\d\d)/g' \ > 52959394107588899482799210587992861082757785799222 > ---------------------------------------------------------- > > > On Fri, Oct 12, 2012 at 4:31 AM, Shaun Fryer wrote: > > Or for yet another way, also sans jquery... > > > > var iframe = document.createElement("iframe"); > > var o = {display:"none", height:0, width:0}; > > for (var attr in o) iframe.style[attr] = o[attr]; // append a > > timestamp below to bypass cache > > var getServerStatus = function () { iframe.src = > > "/url/to/your/log/output?" + (new Date ()).getTime() }; > > iframe.onload = function() { > > > > var win = iframe.contentWindow || iframe.contentDocument; > > if (/your regexp/.test(win.document.body.innerHTML)) > > alert("your process completed"); > > else setTimeout( getServerStatus, 60*1000 ); // ~1 minute > > > > }; > > getServerStatus(); > > document.body.appendChild(iframe); > > -- > > Shaun Fryer > > 647-709-6509 > > ---------------------------------------------------------- > > perl -e 'print chr for map{$_+=22}($ARGV[0])=~/(\d\d)/g' \ > > 52959394107588899482799210587992861082757785799222 > > ---------------------------------------------------------- > > > > > > On Thu, Oct 11, 2012 at 11:05 AM, Antonio Sun > wrote: > >> Thanks a lot Mark, > >> That works like a charm. I really appreciate your simplified solution > sample > >> code. > >> > >> Thanks again everyone for your helps. > -------------- next part -------------- An HTML attachment was scrubbed... URL: From sfryer at sourcery.ca Fri Oct 12 21:00:47 2012 From: sfryer at sourcery.ca (Shaun Fryer) Date: Sat, 13 Oct 2012 00:00:47 -0400 Subject: [tpm] [OT] Javascript to watch for certain KW from a web page In-Reply-To: References: <50759700.1050900@gmail.com> <50759E68.6050109@gmail.com> Message-ID: If any of you are interested, I have a little Javascript project of my own on the go, geared towards Perl developers in terms of some general design patterns. I borrowed some initial starting pointers from JSAN.org Test.Simple and built a loosely TAP based test framework. It also implements a basic swiss inheritance system similar to Perl's via an importer() function and use(qw("the properties you want")) roughly speaking. Anyway, I'm not widely circulating it yet, because it's still a bit rough around the edges, but if this kind of thing appeals to you, please check it out. https://github.com/sfryer/sunflower -- Shaun Fryer 647-709-6509 ---------------------------------------------------------- perl -e 'print chr for map{$_+=22}($ARGV[0])=~/(\d\d)/g' \ 52959394107588899482799210587992861082757785799222 ---------------------------------------------------------- On Fri, Oct 12, 2012 at 9:45 AM, Antonio Sun wrote: > Thanks Shaun. > > Yes I did use jQuery eventually. As I have zero knowledge of Javascript, I > started easy with Mark's code on a static page, once successful, I moved on > to jQuery. > > Thanks for your recommendation. jQuery is really powerful and well > commented. > I was able to get my job done with only the knowledge from the following two > tutorials: > > The load() method > http://www.jquery-tutorial.net/ajax/the-load-method/ > > Showing progress > http://www.jquery-tutorial.net/ajax/showing-progress/ > > Thanks > > On Fri, Oct 12, 2012 at 4:38 AM, Shaun Fryer wrote: >> >> The reason jquery is a good idea, is you probably want to add it as an >> onclick to a button or something. It's worth it to take the 10 minutes >> to rtfm, and avoid yourself alot of headache with cross-browser >> events. >> -- >> Shaun Fryer >> 647-709-6509 >> ---------------------------------------------------------- >> perl -e 'print chr for map{$_+=22}($ARGV[0])=~/(\d\d)/g' \ >> 52959394107588899482799210587992861082757785799222 >> ---------------------------------------------------------- >> >> >> On Fri, Oct 12, 2012 at 4:31 AM, Shaun Fryer wrote: >> > Or for yet another way, also sans jquery... >> > >> > var iframe = document.createElement("iframe"); >> > var o = {display:"none", height:0, width:0}; >> > for (var attr in o) iframe.style[attr] = o[attr]; // append a >> > timestamp below to bypass cache >> > var getServerStatus = function () { iframe.src = >> > "/url/to/your/log/output?" + (new Date ()).getTime() }; >> > iframe.onload = function() { >> > >> > var win = iframe.contentWindow || iframe.contentDocument; >> > if (/your regexp/.test(win.document.body.innerHTML)) >> > alert("your process completed"); >> > else setTimeout( getServerStatus, 60*1000 ); // ~1 minute >> > >> > }; >> > getServerStatus(); >> > document.body.appendChild(iframe); >> > -- >> > Shaun Fryer >> > 647-709-6509 >> > ---------------------------------------------------------- >> > perl -e 'print chr for map{$_+=22}($ARGV[0])=~/(\d\d)/g' \ >> > 52959394107588899482799210587992861082757785799222 >> > ---------------------------------------------------------- >> > >> > >> > On Thu, Oct 11, 2012 at 11:05 AM, Antonio Sun >> > wrote: >> >> Thanks a lot Mark, >> >> That works like a charm. I really appreciate your simplified solution >> >> sample >> >> code. >> >> >> >> Thanks again everyone for your helps. From shlomif at shlomifish.org Sat Oct 13 02:32:50 2012 From: shlomif at shlomifish.org (Shlomi Fish) Date: Sat, 13 Oct 2012 11:32:50 +0200 Subject: [tpm] [OT] Javascript to watch for certain KW from a web page In-Reply-To: References: <50759700.1050900@gmail.com> <50759E68.6050109@gmail.com> Message-ID: <20121013113250.06e50a66@lap.shlomifish.org> Hi Shaun, On Sat, 13 Oct 2012 00:00:47 -0400 Shaun Fryer wrote: > If any of you are interested, I have a little Javascript project of my > own on the go, geared towards Perl developers in terms of some general > design patterns. I borrowed some initial starting pointers from > JSAN.org Test.Simple and built a loosely TAP based test framework. It > also implements a basic swiss inheritance system similar to Perl's via > an importer() function and use(qw("the properties you want")) roughly > speaking. Anyway, I'm not widely circulating it yet, because it's > still a bit rough around the edges, but if this kind of thing appeals > to you, please check it out. > > https://github.com/sfryer/sunflower A few notes off-the-top-of-my-head: 1. This web-toolkit seems to lack any documentation. Please add some. 2. The description ?A powerful JavaScript web-toolkit for dirt simple HTML DOM creation and manipulation.? reminded me of http://weblibs.herokuapp.com/ . Maybe lose some of the adjectives. Regards, Shlomi Fish -- ----------------------------------------------------------------- Shlomi Fish http://www.shlomifish.org/ What Makes Software Apps High Quality - http://shlom.in/sw-quality Learn Perl from ?Learning Perl in 24 Minutes Unleashed, in a Nutshell for Dummies.? ? based on Shlomi Fish and f00li5h on #perl Please reply to list if it's a mailing list post - http://shlom.in/reply . From sfryer at sourcery.ca Sat Oct 13 09:08:32 2012 From: sfryer at sourcery.ca (Shaun Fryer) Date: Sat, 13 Oct 2012 12:08:32 -0400 Subject: [tpm] [OT] Javascript to watch for certain KW from a web page In-Reply-To: <20121013113250.06e50a66@lap.shlomifish.org> References: <50759700.1050900@gmail.com> <50759E68.6050109@gmail.com> <20121013113250.06e50a66@lap.shlomifish.org> Message-ID: Thanks Shlomi, Docs are on the way. Just need to finish the outstanding unit tests first. For now the tests sort of double as rough documentation. As to the adjectives ... lol. I'll definitely give that some thought. As I said, it's a bit rough around the edges yet. Just me working on it (in my spare time) for now. If anyone else wants to help with docs, unit tests, qa, or whatnot, feel free to get in touch back-channel and I'll be happy to explain any additional details. Cheers, -- Shaun Fryer 647-709-6509 ---------------------------------------------------------- perl -e 'print chr for map{$_+=22}($ARGV[0])=~/(\d\d)/g' \ 52959394107588899482799210587992861082757785799222 ---------------------------------------------------------- On Sat, Oct 13, 2012 at 5:32 AM, Shlomi Fish wrote: > Hi Shaun, > > On Sat, 13 Oct 2012 00:00:47 -0400 > Shaun Fryer wrote: > >> If any of you are interested, I have a little Javascript project of my >> own on the go, geared towards Perl developers in terms of some general >> design patterns. I borrowed some initial starting pointers from >> JSAN.org Test.Simple and built a loosely TAP based test framework. It >> also implements a basic swiss inheritance system similar to Perl's via >> an importer() function and use(qw("the properties you want")) roughly >> speaking. Anyway, I'm not widely circulating it yet, because it's >> still a bit rough around the edges, but if this kind of thing appeals >> to you, please check it out. >> >> https://github.com/sfryer/sunflower > > A few notes off-the-top-of-my-head: > > 1. This web-toolkit seems to lack any documentation. Please add some. > > 2. The description ?A powerful JavaScript web-toolkit for dirt simple > HTML DOM creation and manipulation.? reminded me of > http://weblibs.herokuapp.com/ . Maybe lose some of the adjectives. > > Regards, > > Shlomi Fish > > -- > ----------------------------------------------------------------- > Shlomi Fish http://www.shlomifish.org/ > What Makes Software Apps High Quality - http://shlom.in/sw-quality > > Learn Perl from ?Learning Perl in 24 Minutes Unleashed, in a Nutshell for > Dummies.? > ? based on Shlomi Fish and f00li5h on #perl > > Please reply to list if it's a mailing list post - http://shlom.in/reply . From cj at enersave.ca Mon Oct 15 06:07:39 2012 From: cj at enersave.ca (Chris Jones) Date: Mon, 15 Oct 2012 09:07:39 -0400 Subject: [tpm] Exporting Access files to .csv In-Reply-To: <20121005160442.212e0e0d@lap.shlomifish.org> References: <20121005124231.ACE4511FE10@xx1.develooper.com> <20121005160442.212e0e0d@lap.shlomifish.org> Message-ID: <20121015130747.BD71711DDFE@xx1.develooper.com> Thank you. I have written a perl script using DBI ADO. The select and print statements work. I am using the join statement to separate the fields by ',' but I can't figure out a way to get the text fields quoted so the output resembles the CSV output by msaccess. Example output from access: 240,10,"SPACE:LGT-W/A[1]","if( Local( ZONE-TYPE ) == 1 then 1 endif","Set lighting power","8.4.4.6","db 2012-04-19 - added",1,0 The field types: number, number, text, memo, text, text, memo, integer, integer. The output from my script: 240,10,SPACE:LGT-W/A[1],if( Local( ZONE-TYPE ) == 1 then 1 endif,Set lighting power,8.4.4.6,db 2012-04-19 - added,1,0 Thanks for any insight! At 10:04 AM 05/10/2012, Shlomi Fish wrote: >Hi Chris, > >On Fri, 05 Oct 2012 08:42:30 -0400 >Chris Jones wrote: > > > I am working on a project that uses Access to store the rule > > sets. It is hard to explain but a rule is a programming > > statement. A statement can do one of two things: return a variable > > or do an action. Then the rules compiler sifts through all the > > access files and "compiles" the rules to a binary library. > > > > I find it helpful to export all the tables to .csv so I can do > > "search in files" to track the logic of the others on project. It's > > a nightmare but that's another story. > > > > So I am wondering if anyone has any ideas as to the simplest way to > > automate the exporting of access files to .csv? > > > >See the replies here: > >http://stackoverflow.com/questions/280894/automatically-convert-access-db > >Regards, > > Shlomi Fish > >-- >----------------------------------------------------------------- >Shlomi Fish http://www.shlomifish.org/ >What Makes Software Apps High Quality - http://shlom.in/sw-quality > >An apple a day keeps the doctor away. >Two apples a day will keep two doctors away. > ? one of Shlomi Fish???s relatives >Please reply to list if it's a mailing list post - http://shlom.in/reply . >> Christopher Jones, P.Eng. Suite 1801, 1 Yonge Street Toronto, ON M5E1W7 Tel. 416-203-7465 Fax. 416-946-1005 email cj at enersave.ca From shlomif at shlomifish.org Mon Oct 15 06:21:38 2012 From: shlomif at shlomifish.org (Shlomi Fish) Date: Mon, 15 Oct 2012 15:21:38 +0200 Subject: [tpm] Exporting Access files to .csv In-Reply-To: <20121015130747.BD71711DDFE@xx1.develooper.com> References: <20121005124231.ACE4511FE10@xx1.develooper.com> <20121005160442.212e0e0d@lap.shlomifish.org> <20121015130747.BD71711DDFE@xx1.develooper.com> Message-ID: <20121015152138.4ac4edfd@lap.shlomifish.org> Hi Chris, On Mon, 15 Oct 2012 09:07:39 -0400 Chris Jones wrote: > Thank you. > > I have written a perl script using DBI ADO. The > select and print statements work. I am using the > join statement to separate the fields by ',' but > I can't figure out a way to get the text fields > quoted so the output resembles the CSV output by msaccess. > > Example output from access: > 240,10,"SPACE:LGT-W/A[1]","if( Local( ZONE-TYPE ) > == 1 then 1 endif","Set lighting power","8.4.4.6","db 2012-04-19 - > added",1,0 > > The field types: > number, number, text, memo, text, text, memo, integer, integer. > > The output from my script: > > 240,10,SPACE:LGT-W/A[1],if( Local( ZONE-TYPE ) == > 1 then 1 endif,Set lighting power,8.4.4.6,db 2012-04-19 - added,1,0 > > Thanks for any insight! Please use https://metacpan.org/module/Text::CSV to output CSV (as well as read it). Read its documentation for configurations options that control the resultant output. Regards, Shlomi Fish -- ----------------------------------------------------------------- Shlomi Fish http://www.shlomifish.org/ My Aphorisms - http://www.shlomifish.org/humour.html ?My only boss is God. And Chuck Norris who is his boss.? Please reply to list if it's a mailing list post - http://shlom.in/reply . From fulko.hew at gmail.com Mon Oct 15 10:59:53 2012 From: fulko.hew at gmail.com (Fulko Hew) Date: Mon, 15 Oct 2012 13:59:53 -0400 Subject: [tpm] trouble with unicode versus octets Message-ID: I have a problem (so what else is new!) that I haven't yet found a solution to ... In my app, I receive strings, massage them, and 'push_write" them to an AnyEvent socket. Occasionaly, my app receives a unicoded string... so when the write happens, Perl (inside the AnyEvent module) dies with the error: Wide character in subroutine entry at ... What I haven't figured out yet is, how to coerce the character string into an octet string (for the rest of its life, ie. in subsequent modules) so the warning/dying goes away. TIA Fulko -------------- next part -------------- An HTML attachment was scrubbed... URL: From stuart at morungos.com Mon Oct 15 12:23:36 2012 From: stuart at morungos.com (Stuart Watt) Date: Mon, 15 Oct 2012 15:23:36 -0400 Subject: [tpm] trouble with unicode versus octets In-Reply-To: References: Message-ID: <8BA74001-30A5-4564-89A9-954C871AF489@morungos.com> It's not an uncommon problem, but it's a messy one. And it's basically an application decision. The module you need is Encode, and what you probably need is my $encoded = Encode::encode('utf8', $utf8_string); which translates the string that's in UTF8 and which you can't print, into a set of bytes in UTF8, which you can. That stops the print error. However, this is for printing or writing over a network connection, and you might need a different encoding depending on your protocol. The Encode module can do most any encoding you like or need, and many that seem ridiculous. In the case of UTF8, and only because internally Perl uses UTF8, that sets a special flag that effectively stops Perl from giving wide character errors. But this is highly confusing special behaviour, and it's often worth testing Perl with non-UTF8 data printing/communications to flush out these issues. The problems are worse if you don't know what your strings are to begin with. It's best to help your app by making everything UTF8 (internally) as soon as possible, assuming it isn't already. There is no way to tell. reliably, whether a piece of random data really is UTF8 text as that's really down to how it is supposed to be interpreted. --S On 2012-10-15, at 1:59 PM, Fulko Hew wrote: > I have a problem (so what else is new!) that I haven't yet found a solution to ... > > In my app, I receive strings, massage them, and 'push_write" them to an AnyEvent socket. > > Occasionaly, my app receives a unicoded string... > so when the write happens, Perl (inside the AnyEvent module) > dies with the error: > > Wide character in subroutine entry at ... > > What I haven't figured out yet is, how to coerce the character string into > an octet string (for the rest of its life, ie. in subsequent modules) > so the warning/dying goes away. > > TIA > Fulko > > _______________________________________________ > toronto-pm mailing list > toronto-pm at pm.org > http://mail.pm.org/mailman/listinfo/toronto-pm -------------- next part -------------- An HTML attachment was scrubbed... URL: From cj at enersave.ca Mon Oct 15 13:49:50 2012 From: cj at enersave.ca (Chris Jones) Date: Mon, 15 Oct 2012 16:49:50 -0400 Subject: [tpm] Exporting Access files to .csv In-Reply-To: <20121015152138.4ac4edfd@lap.shlomifish.org> References: <20121005124231.ACE4511FE10@xx1.develooper.com> <20121005160442.212e0e0d@lap.shlomifish.org> <20121015130747.BD71711DDFE@xx1.develooper.com> <20121015152138.4ac4edfd@lap.shlomifish.org> Message-ID: <20121015205004.E80801222D6@xx1.develooper.com> Thank you! It works well except I can't get quotes around Text fields. I am using: my $csv = Text::CSV->new ( { binary => 1 } ) # should set binary attribute. or die "Cannot use CSV: ".Text::CSV->error_diag (); $csv->types ([Text::CSV::IV (), Text::CSV::IV (), Text::CSV::PV (), Text::CSV::PV (), Text::CSV::PV (), Text::CSV::PV (), Text::CSV::IV (), Text::CSV::IV ()]); #output database results while (my @row=$sth->fetchrow_array) { #my $line = join( ",", @row ); print "@row\n"; my $status = $csv->combine(@row); my $line = $csv->string(); print "$line\n" } The output has quotes around the memo fields but the text fields are not quoted? At 09:21 AM 15/10/2012, Shlomi Fish wrote: >Hi Chris, > >On Mon, 15 Oct 2012 09:07:39 -0400 >Chris Jones wrote: > > > Thank you. > > > > I have written a perl script using DBI ADO. The > > select and print statements work. I am using the > > join statement to separate the fields by ',' but > > I can't figure out a way to get the text fields > > quoted so the output resembles the CSV output by msaccess. > > > > Example output from access: > > 240,10,"SPACE:LGT-W/A[1]","if( Local( ZONE-TYPE ) > > == 1 then 1 endif","Set lighting power","8.4.4.6","db 2012-04-19 - > > added",1,0 > > > > The field types: > > number, number, text, memo, text, text, memo, integer, integer. > > > > The output from my script: > > > > 240,10,SPACE:LGT-W/A[1],if( Local( ZONE-TYPE ) == > > 1 then 1 endif,Set lighting power,8.4.4.6,db 2012-04-19 - added,1,0 > > > > Thanks for any insight! > >Please use https://metacpan.org/module/Text::CSV to output CSV (as well >as read it). Read its documentation for configurations options that control >the resultant output. > >Regards, > > Shlomi Fish > >-- >----------------------------------------------------------------- >Shlomi Fish http://www.shlomifish.org/ >My Aphorisms - http://www.shlomifish.org/humour.html > >???My only boss is God. And Chuck Norris who is his boss.??? > >Please reply to list if it's a mailing list post - http://shlom.in/reply . >> Christopher Jones, P.Eng. Suite 1801, 1 Yonge Street Toronto, ON M5E1W7 Tel. 416-203-7465 Fax. 416-946-1005 email cj at enersave.ca From stuart at morungos.com Mon Oct 15 14:08:47 2012 From: stuart at morungos.com (Stuart Watt) Date: Mon, 15 Oct 2012 17:08:47 -0400 Subject: [tpm] Exporting Access files to .csv In-Reply-To: <20121015205004.E80801222D6@xx1.develooper.com> References: <20121005124231.ACE4511FE10@xx1.develooper.com> <20121005160442.212e0e0d@lap.shlomifish.org> <20121015130747.BD71711DDFE@xx1.develooper.com> <20121015152138.4ac4edfd@lap.shlomifish.org> <20121015205004.E80801222D6@xx1.develooper.com> Message-ID: <9583469B-6578-4EBA-815C-0C832CFA0E1C@morungos.com> I'm surprised if there's an issue with the underlying data. I use Text::CSV without problems. And I use it a lot. But Text::CSV does default a lot of odd settings. Two thoughts: (1) the types method apparently does nothing for encoding data, only for decoding, and (2) quotes are only added when 'necessary', which will be (by default) strings with commas or newlines in them (or spaces, even though they aren't actually necessary in all cases). I don't have Access (only Excel) so I can't be sure what it's quoting rules are. However, Access looks like it is more zealous and quotes virtually everything. So (a) the data will probably be fine for import to, e.g., Excel, or (b) Text::CSV settings like always_quote may be more like the Access output. --S On 2012-10-15, at 4:49 PM, Chris Jones wrote: > Thank you! It works well except I can't get quotes around Text fields. > > I am using: > my $csv = Text::CSV->new ( { binary => 1 } ) # should set binary attribute. > or die "Cannot use CSV: ".Text::CSV->error_diag (); > > $csv->types ([Text::CSV::IV (), > Text::CSV::IV (), > Text::CSV::PV (), > Text::CSV::PV (), > Text::CSV::PV (), > Text::CSV::PV (), > Text::CSV::IV (), > Text::CSV::IV ()]); > > #output database results > while (my @row=$sth->fetchrow_array) > { > #my $line = join( ",", @row ); > print "@row\n"; > my $status = $csv->combine(@row); > my $line = $csv->string(); > print "$line\n" > > } > > The output has quotes around the memo fields but the text fields are not quoted? > > At 09:21 AM 15/10/2012, Shlomi Fish wrote: >> Hi Chris, >> >> On Mon, 15 Oct 2012 09:07:39 -0400 >> Chris Jones wrote: >> >> > Thank you. >> > >> > I have written a perl script using DBI ADO. The >> > select and print statements work. I am using the >> > join statement to separate the fields by ',' but >> > I can't figure out a way to get the text fields >> > quoted so the output resembles the CSV output by msaccess. >> > >> > Example output from access: >> > 240,10,"SPACE:LGT-W/A[1]","if( Local( ZONE-TYPE ) >> > == 1 then 1 endif","Set lighting power","8.4.4.6","db 2012-04-19 - >> > added",1,0 >> > >> > The field types: >> > number, number, text, memo, text, text, memo, integer, integer. >> > >> > The output from my script: >> > >> > 240,10,SPACE:LGT-W/A[1],if( Local( ZONE-TYPE ) == >> > 1 then 1 endif,Set lighting power,8.4.4.6,db 2012-04-19 - added,1,0 >> > >> > Thanks for any insight! >> >> Please use https://metacpan.org/module/Text::CSV to output CSV (as well >> as read it). Read its documentation for configurations options that control >> the resultant output. >> >> Regards, >> >> Shlomi Fish >> >> -- >> ----------------------------------------------------------------- >> Shlomi Fish http://www.shlomifish.org/ >> My Aphorisms - http://www.shlomifish.org/humour.html >> >> ?My only boss is God. And Chuck Norris who is his boss.? >> >> Please reply to list if it's a mailing list post - http://shlom.in/reply . > > >> > Christopher Jones, P.Eng. > Suite 1801, 1 Yonge Street > Toronto, ON M5E1W7 > Tel. 416-203-7465 > Fax. 416-946-1005 > email cj at enersave.ca > > _______________________________________________ > toronto-pm mailing list > toronto-pm at pm.org > http://mail.pm.org/mailman/listinfo/toronto-pm From cj at enersave.ca Mon Oct 15 17:14:32 2012 From: cj at enersave.ca (Chris Jones) Date: Mon, 15 Oct 2012 20:14:32 -0400 Subject: [tpm] Exporting Access files to .csv In-Reply-To: <20121015205004.E80801222D6@xx1.develooper.com> References: <20121005124231.ACE4511FE10@xx1.develooper.com> <20121005160442.212e0e0d@lap.shlomifish.org> <20121015130747.BD71711DDFE@xx1.develooper.com> <20121015152138.4ac4edfd@lap.shlomifish.org> <20121015205004.E80801222D6@xx1.develooper.com> Message-ID: <20121016001433.A3A4D11EFB5@xx1.develooper.com> It is all working great. Thanks for your help! I am using DBI ADO and Text::CSV. Text::CSV adds quotes where needed. I was trying to get the same output as ms access which quotes all text fields whether they contain white space or not. For reading in to excel, the quotes on text fields are not necessary unless there is a white space, new line, etc. in the field. It works slick. Much better than opening each file in Access and exporting to csv. At 04:49 PM 15/10/2012, Chris Jones wrote: >Thank you! It works well except I can't get quotes around Text fields. > >I am using: >my $csv = Text::CSV->new ( { binary => 1 } ) # should set binary attribute. > or die "Cannot use CSV: ".Text::CSV->error_diag (); > >$csv->types ([Text::CSV::IV (), > Text::CSV::IV (), > Text::CSV::PV (), > Text::CSV::PV (), > Text::CSV::PV (), > Text::CSV::PV (), > Text::CSV::IV (), > Text::CSV::IV ()]); > >#output database results > while (my @row=$sth->fetchrow_array) > { > #my $line = join( ",", @row ); > print "@row\n"; > my $status = $csv->combine(@row); > my $line = $csv->string(); > print "$line\n" > > } > >The output has quotes around the memo fields but >the text fields are not quoted? > >At 09:21 AM 15/10/2012, Shlomi Fish wrote: >>Hi Chris, >> >>On Mon, 15 Oct 2012 09:07:39 -0400 >>Chris Jones wrote: >> >> > Thank you. >> > >> > I have written a perl script using DBI ADO. The >> > select and print statements work. I am using the >> > join statement to separate the fields by ',' but >> > I can't figure out a way to get the text fields >> > quoted so the output resembles the CSV output by msaccess. >> > >> > Example output from access: >> > 240,10,"SPACE:LGT-W/A[1]","if( Local( ZONE-TYPE ) >> > == 1 then 1 endif","Set lighting power","8.4.4.6","db 2012-04-19 - >> > added",1,0 >> > >> > The field types: >> > number, number, text, memo, text, text, memo, integer, integer. >> > >> > The output from my script: >> > >> > 240,10,SPACE:LGT-W/A[1],if( Local( ZONE-TYPE ) == >> > 1 then 1 endif,Set lighting power,8.4.4.6,db 2012-04-19 - added,1,0 >> > >> > Thanks for any insight! >> >>Please use https://metacpan.org/module/Text::CSV to output CSV (as well >>as read it). Read its documentation for configurations options that control >>the resultant output. >> >>Regards, >> >> Shlomi Fish >> >>-- >>----------------------------------------------------------------- >>Shlomi Fish http://www.shlomifish.org/ >>My Aphorisms - http://www.shlomifish.org/humour.html >> >>???My only boss is God. And Chuck Norris who is his boss.??? >> >>Please reply to list if it's a mailing list post - http://shlom.in/reply . > > >> >Christopher Jones, P.Eng. >Suite 1801, 1 Yonge Street >Toronto, ON M5E1W7 >Tel. 416-203-7465 >Fax. 416-946-1005 >email cj at enersave.ca > >_______________________________________________ >toronto-pm mailing list >toronto-pm at pm.org >http://mail.pm.org/mailman/listinfo/toronto-pm >> Christopher Jones, P.Eng. Suite 1801, 1 Yonge Street Toronto, ON M5E1W7 Tel. 416-203-7465 Fax. 416-946-1005 email cj at enersave.ca From ioncache at gmail.com Tue Oct 16 05:27:17 2012 From: ioncache at gmail.com (Mark Jubenville) Date: Tue, 16 Oct 2012 08:27:17 -0400 Subject: [tpm] Exporting Access files to .csv In-Reply-To: <20121016001433.A3A4D11EFB5@xx1.develooper.com> References: <20121005124231.ACE4511FE10@xx1.develooper.com> <20121005160442.212e0e0d@lap.shlomifish.org> <20121015130747.BD71711DDFE@xx1.develooper.com> <20121015152138.4ac4edfd@lap.shlomifish.org> <20121015205004.E80801222D6@xx1.develooper.com> <20121016001433.A3A4D11EFB5@xx1.develooper.com> Message-ID: <507D52A5.4030806@gmail.com> For future reference you can force Text::CSV to always quote every field by setting 'always_quote' to true: my $csv = Text::CSV->new({ always_quote => 1}); or for an already instantiated csv object: $csv->always_quote(1); Cheers, Mark On 10/15/2012 8:14 PM, Chris Jones wrote: > It is all working great. Thanks for your help! > I am using DBI ADO and Text::CSV. > > Text::CSV adds quotes where needed. I was trying to get the same > output as ms access which quotes all text fields whether they contain > white space or not. For reading in to excel, the quotes on text > fields are not necessary unless there is a white space, new line, etc. > in the field. > > It works slick. Much better than opening each file in Access and > exporting to csv. > > > > At 04:49 PM 15/10/2012, Chris Jones wrote: >> Thank you! It works well except I can't get quotes around Text fields. >> >> I am using: >> my $csv = Text::CSV->new ( { binary => 1 } ) # should set binary >> attribute. >> or die "Cannot use CSV: >> ".Text::CSV->error_diag (); >> >> $csv->types ([Text::CSV::IV (), >> Text::CSV::IV (), >> Text::CSV::PV (), >> Text::CSV::PV (), >> Text::CSV::PV (), >> Text::CSV::PV (), >> Text::CSV::IV (), >> Text::CSV::IV ()]); >> >> #output database results >> while (my @row=$sth->fetchrow_array) >> { >> #my $line = join( ",", @row ); >> print "@row\n"; >> my $status = $csv->combine(@row); >> my $line = $csv->string(); >> print "$line\n" >> >> } >> >> The output has quotes around the memo fields but the text fields are >> not quoted? >> >> At 09:21 AM 15/10/2012, Shlomi Fish wrote: >>> Hi Chris, >>> >>> On Mon, 15 Oct 2012 09:07:39 -0400 >>> Chris Jones wrote: >>> >>> > Thank you. >>> > >>> > I have written a perl script using DBI ADO. The >>> > select and print statements work. I am using the >>> > join statement to separate the fields by ',' but >>> > I can't figure out a way to get the text fields >>> > quoted so the output resembles the CSV output by msaccess. >>> > >>> > Example output from access: >>> > 240,10,"SPACE:LGT-W/A[1]","if( Local( ZONE-TYPE ) >>> > == 1 then 1 endif","Set lighting power","8.4.4.6","db 2012-04-19 - >>> > added",1,0 >>> > >>> > The field types: >>> > number, number, text, memo, text, text, memo, integer, integer. >>> > >>> > The output from my script: >>> > >>> > 240,10,SPACE:LGT-W/A[1],if( Local( ZONE-TYPE ) == >>> > 1 then 1 endif,Set lighting power,8.4.4.6,db 2012-04-19 - added,1,0 >>> > >>> > Thanks for any insight! >>> >>> Please use https://metacpan.org/module/Text::CSV to output CSV (as well >>> as read it). Read its documentation for configurations options that >>> control >>> the resultant output. >>> >>> Regards, >>> >>> Shlomi Fish >>> >>> -- >>> ----------------------------------------------------------------- >>> Shlomi Fish http://www.shlomifish.org/ >>> My Aphorisms - http://www.shlomifish.org/humour.html >>> >>> ?EURoeMy only boss is God. And Chuck Norris who is his boss.?EUR? >>> >>> Please reply to list if it's a mailing list post - >>> http://shlom.in/reply . >> >> >> >> Christopher Jones, P.Eng. >> Suite 1801, 1 Yonge Street >> Toronto, ON M5E1W7 >> Tel. 416-203-7465 >> Fax. 416-946-1005 >> email cj at enersave.ca >> >> _______________________________________________ >> toronto-pm mailing list >> toronto-pm at pm.org >> http://mail.pm.org/mailman/listinfo/toronto-pm > > >> > Christopher Jones, P.Eng. > Suite 1801, 1 Yonge Street > Toronto, ON M5E1W7 > Tel. 416-203-7465 > Fax. 416-946-1005 > email cj at enersave.ca > > _______________________________________________ > toronto-pm mailing list > toronto-pm at pm.org > http://mail.pm.org/mailman/listinfo/toronto-pm -- Mark Jubenville ioncache at gmail.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From fulko.hew at gmail.com Tue Oct 16 06:18:19 2012 From: fulko.hew at gmail.com (Fulko Hew) Date: Tue, 16 Oct 2012 09:18:19 -0400 Subject: [tpm] trouble with unicode versus octets In-Reply-To: <8BA74001-30A5-4564-89A9-954C871AF489@morungos.com> References: <8BA74001-30A5-4564-89A9-954C871AF489@morungos.com> Message-ID: On Mon, Oct 15, 2012 at 3:23 PM, Stuart Watt wrote: > It's not an uncommon problem, but it's a messy one. And it's basically an > application decision. > > The module you need is Encode, and what you probably need is > > my $encoded = Encode::encode('utf8', $utf8_string); > Yes, I've been reading all this stuff, but it still doesn't make sense to me (as I see also to many others... http://www.perlmonks.org/?node_id=906373) All of the responses I've read so far, assume you are processing textual strings and not octet strings. Reading the'perlunitut', I see: * * Encoding (as a verb) is the conversion from *text* to *binary*. To encode, you have to supply the target encoding, for example iso-8859-1 or UTF-8. Some encodings, like the iso-8859 ("latin") range, do not support the full Unicode standard; characters that can't be represented are lost in the conversion. The scary part is that I don't really know what the original format is. (In this case it happens to be text that contains MS Windows file names that is causing me grief.) ... another day passes since I wrote the above part ... Trying to patch my original program made me wander in my attempts to fix the problem, so once I created a simple test program, I discovered that indeed, utf8::encode($msg); would address the problem [ just as described :-) ]. Then once I found the appropriate spot in my code, it had 'compensated' for the issue. [ But what happens if I don't feed it a text string (wide or narrow) but my octet string instead? What comes out the other end? I guess it passes it through transparently (knowing that it no longer contains a UTF string) ] which translates the string that's in UTF8 and which you can't print, into > a set of bytes in UTF8, which you can. That stops the print error. However, > this is for printing or writing over a network connection, and you might > need a different encoding depending on your protocol. The Encode module can > do most any encoding you like or need, and many that seem ridiculous. > > In the case of UTF8, and only because internally Perl uses UTF8, that sets > a special flag that effectively stops Perl from giving wide character > errors. But this is highly confusing special behaviour, and it's often > worth testing Perl with non-UTF8 data printing/communications to flush out > these issues. > > The problems are worse if you don't know what your strings are to begin > with. It's best to help your app by making everything UTF8 (internally) as > soon as possible, assuming it isn't already. There is no way to tell. > reliably, whether a piece of random data really is UTF8 text as that's > really down to how it is supposed to be interpreted. > > --S > > On 2012-10-15, at 1:59 PM, Fulko Hew wrote: > > I have a problem (so what else is new!) that I haven't yet found a > solution to ... > > In my app, I receive strings, massage them, and 'push_write" them to an AnyEvent > socket. > > Occasionaly, my app receives a unicoded string... > so when the write happens, Perl (inside the AnyEvent module) > dies with the error: > > Wide character in subroutine entry at ... > > What I haven't figured out yet is, how to coerce the character string into > an octet string (for the rest of its life, ie. in subsequent modules) > so the warning/dying goes away. > > TIA > Fulko > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From antoniosun at lavabit.com Tue Oct 16 06:35:08 2012 From: antoniosun at lavabit.com (Antonio Sun) Date: Tue, 16 Oct 2012 09:35:08 -0400 Subject: [tpm] Hacking Health In-Reply-To: References: <7F2F1933-A29B-456B-8DCA-20EB36A4F19D@morungos.com> Message-ID: On Fri, Sep 28, 2012 at 10:25 AM, Antonio Sun wrote: > > On Fri, Sep 28, 2012 at 9:49 AM, Stuart Watt wrote: > >> I mentioned to a few folks last night, the "Hacking Health" event in >> Toronto, October 19th-21st (yes, it's a weekend hackathon). >> >> URL: http://hackinghealth.ca/events/toronto >> >> They are looking for technology experts: >> http://hackinghealth.ca/events/toronto/why-hacker who might be >> interested in getting involved. >> >> I've signed up, maybe see some of you there? >> > > Looks interesting and fun to me. I've signed up just now. Thanks Stuart! > October 19th-21st is coming close. I'll be there. Just wonder how many of you will be there too. Thanks -------------- next part -------------- An HTML attachment was scrubbed... URL: From stuart at morungos.com Tue Oct 16 06:54:25 2012 From: stuart at morungos.com (Stuart Watt) Date: Tue, 16 Oct 2012 09:54:25 -0400 Subject: [tpm] trouble with unicode versus octets In-Reply-To: References: <8BA74001-30A5-4564-89A9-954C871AF489@morungos.com> Message-ID: <5F3A909E-D8C8-4066-A0FF-845D0C1C2658@morungos.com> Hmmm. You should really use Encode, not utf8::encode. They ought to be equivalent, i.e., $foo = utf8::encode($bar); $foo = Encode::encode('utf8', $bar); ought to be identical. And the same is true for decode. Now to the interesting bit -- not knowing about the original format. I had that issue, and there is no real solution to it in the general case. Windows is supposed to store file names as UTF16LE underneath, but the API for Perl won't give you that directly. You might try Encode::Guess as a start. The Encode functions do include a check parameter which you can use to get the Encode functions to tell you when the data doesn't match the encoding expected, this allows you to try decode, and if it doesn't match, try something else. I've done this for a Windows app where I was expecting one of a small number of encodings, but you need to try them in order, or write a (byte level) heuristic to make a guess. On files you fairly often have a byte order mark (for non-8 bit encodings) and File::BOM will help there. That doesn't help with filenames. printing does transparently pass through octets in all cases. That's why the ::encode functions stop the errors. It might look like all that happens is the utf8 is sent directly through, but that is not actually the case. Perl just treats the string as a set of octets and tries to print. If it ever finds one >7 bits (i.e., non ASCII), it moans. Strict utf8 makes this impossible without an octet >127. Sloppy utf8 allows zeros to be used to pad, and it is technically (maybe) possible for these to be encoded to <= 127 bit values and print just fine. Or it might not happen. But conceptually it could. The only safe thing to do is to build the code so that incoming data is correctly encoded as soon as possible (or assumed to be). You still need to be careful. Even on Windows + Perl, you can easily double encode utf8. If you call Encode::encode more than once on the same string, you garble it. That's why it's really down to the application to maintain integrity. In retrospect, Perl hides unicode so well that it is really hard to find where an issue lies when all goes wrong. Finally, if the problem is in the Windows file functions, things might simply be bad. I struggled with that area for a good long time. I may be able to dig out code that reduces the issue, but on my ever-expanding to-do list was a rewrite of the Perl core Windows API to finally handle filenames > 250 characters and handle unicode file names. Neither are, as far as I could tell from looking at the C code, completely correct. Certainly, my app would garble file names in these areas of Perl. Your best bet may be some controlled testing to pin down the problems, e.g., a known file name with an accented character. If you do this, I'd be very grateful for the test cases, which might prod me into doing something about it in a cold winter night. --S On 2012-10-16, at 9:18 AM, Fulko Hew wrote: > > > On Mon, Oct 15, 2012 at 3:23 PM, Stuart Watt wrote: > It's not an uncommon problem, but it's a messy one. And it's basically an application decision. > > The module you need is Encode, and what you probably need is > > my $encoded = Encode::encode('utf8', $utf8_string); > > Yes, I've been reading all this stuff, but it still doesn't make sense to me > (as I see also to many others... http://www.perlmonks.org/?node_id=906373) > > All of the responses I've read so far, assume you are processing textual strings > and not octet strings. > > Reading the'perlunitut', I see: > > Encoding (as a verb) is the conversion from text to binary. To encode, you have > to supply the target encoding, for example iso-8859-1 or UTF-8. Some encodings, > like the iso-8859 ("latin") range, do not support the full Unicode standard; > characters that can't be represented are lost in the conversion. > > The scary part is that I don't really know what the original format is. > (In this case it happens to be text that contains MS Windows file names that > is causing me grief.) > > ... another day passes since I wrote the above part ... > > Trying to patch my original program made me wander in my attempts to fix the > problem, so once I created a simple test program, I discovered that indeed, > utf8::encode($msg); > would address the problem [ just as described :-) ]. > Then once I found the appropriate spot in my code, it had 'compensated' for the issue. > > [ But what happens if I don't feed it a text string (wide or narrow) > but my octet string instead? What comes out the other end? > > I guess it passes it through transparently > (knowing that it no longer contains a UTF string) > ] > > which translates the string that's in UTF8 and which you can't print, into a set of bytes in UTF8, which you can. That stops the print error. However, this is for printing or writing over a network connection, and you might need a different encoding depending on your protocol. The Encode module can do most any encoding you like or need, and many that seem ridiculous. > > In the case of UTF8, and only because internally Perl uses UTF8, that sets a special flag that effectively stops Perl from giving wide character errors. But this is highly confusing special behaviour, and it's often worth testing Perl with non-UTF8 data printing/communications to flush out these issues. > > The problems are worse if you don't know what your strings are to begin with. It's best to help your app by making everything UTF8 (internally) as soon as possible, assuming it isn't already. There is no way to tell. reliably, whether a piece of random data really is UTF8 text as that's really down to how it is supposed to be interpreted. > > --S > > On 2012-10-15, at 1:59 PM, Fulko Hew wrote: > >> I have a problem (so what else is new!) that I haven't yet found a solution to ... >> >> In my app, I receive strings, massage them, and 'push_write" them to an AnyEvent socket. >> >> Occasionaly, my app receives a unicoded string... >> so when the write happens, Perl (inside the AnyEvent module) >> dies with the error: >> >> Wide character in subroutine entry at ... >> >> What I haven't figured out yet is, how to coerce the character string into >> an octet string (for the rest of its life, ie. in subsequent modules) >> so the warning/dying goes away. >> >> TIA >> Fulko -------------- next part -------------- An HTML attachment was scrubbed... URL: From cj at enersave.ca Fri Oct 19 12:22:20 2012 From: cj at enersave.ca (Chris Jones) Date: Fri, 19 Oct 2012 15:22:20 -0400 Subject: [tpm] Exporting Access files to .csv In-Reply-To: <507D52A5.4030806@gmail.com> References: <20121005124231.ACE4511FE10@xx1.develooper.com> <20121005160442.212e0e0d@lap.shlomifish.org> <20121015130747.BD71711DDFE@xx1.develooper.com> <20121015152138.4ac4edfd@lap.shlomifish.org> <20121015205004.E80801222D6@xx1.develooper.com> <20121016001433.A3A4D11EFB5@xx1.develooper.com> <507D52A5.4030806@gmail.com> Message-ID: <20121019192233.5E41511DE41@xx1.develooper.com> Thanks Mark! I tried both ways. my $csv = Text::CSV->new ( { binary => 1, always_quote => 1, } ) # should set binary attribute. or die "Cannot use CSV: ".Text::CSV->error_diag (); And with out alway_quote. Always quote put quotes around interger and number fields and Excel displayed them as strings, not numbers so turned always_quote off. At 08:27 AM 16/10/2012, Mark Jubenville wrote: >For future reference you can force Text::CSV to >always quote every field by setting 'always_quote' to true: > >my $csv = Text::CSV->new({ always_quote => 1}); > >or for an already instantiated csv object: > >$csv->always_quote(1); > >Cheers, > >Mark > >On 10/15/2012 8:14 PM, Chris Jones wrote: >>It is all working great. Thanks for your help! >>I am using DBI ADO and Text::CSV. >> >>Text::CSV adds quotes where needed. I was >>trying to get the same output as ms access >>which quotes all text fields whether they >>contain white space or not. For reading in to >>excel, the quotes on text fields are not >>necessary unless there is a white space, new line, etc. in the field. >> >>It works slick. Much better than opening each >>file in Access and exporting to csv. >> >> >> >>At 04:49 PM 15/10/2012, Chris Jones wrote: >>>Thank you! It works well except I can't get quotes around Text fields. >>> >>>I am using: >>>my $csv = Text::CSV->new ( { binary => 1 } >>>) # should set binary attribute. >>> or die "Cannot use >>> CSV: ".Text::CSV->error_diag (); >>> >>>$csv->types ([Text::CSV::IV (), >>> Text::CSV::IV (), >>> Text::CSV::PV (), >>> Text::CSV::PV (), >>> Text::CSV::PV (), >>> Text::CSV::PV (), >>> Text::CSV::IV (), >>> Text::CSV::IV ()]); >>> >>>#output database results >>> while (my @row=$sth->fetchrow_array) >>> { >>> #my $line = join( ",", @row ); >>> print "@row\n"; >>> my $status = $csv->combine(@row); >>> my $line = $csv->string(); >>> print "$line\n" >>> >>> } >>> >>>The output has quotes around the memo fields >>>but the text fields are not quoted? >>> >>>At 09:21 AM 15/10/2012, Shlomi Fish wrote: >>>>Hi Chris, >>>> >>>>On Mon, 15 Oct 2012 09:07:39 -0400 >>>>Chris Jones wrote: >>>> >>>> > Thank you. >>>> > >>>> > I have written a perl script using DBI ADO. The >>>> > select and print statements work. I am using the >>>> > join statement to separate the fields by ',' but >>>> > I can't figure out a way to get the text fields >>>> > quoted so the output resembles the CSV output by msaccess. >>>> > >>>> > Example output from access: >>>> > 240,10,"SPACE:LGT-W/A[1]","if( Local( ZONE-TYPE ) >>>> > == 1 then 1 endif","Set lighting power","8.4.4.6","db 2012-04-19 - >>>> > added",1,0 >>>> > >>>> > The field types: >>>> > number, number, text, memo, text, text, memo, integer, integer. >>>> > >>>> > The output from my script: >>>> > >>>> > 240,10,SPACE:LGT-W/A[1],if( Local( ZONE-TYPE ) == >>>> > 1 then 1 endif,Set lighting power,8.4.4.6,db 2012-04-19 - added,1,0 >>>> > >>>> > Thanks for any insight! >>>> >>>>Please use >>>>https://metacpan.org/module/Text::CSV >>>>to output CSV (as well >>>>as read it). Read its documentation for >>>>configurations options that control >>>>the resultant output. >>>> >>>>Regards, >>>> >>>> Shlomi Fish >>>> >>>>-- >>>>----------------------------------------------------------------- >>>>Shlomi Fish http://www.shlomifish.org/ >>>>My Aphorisms - >>>>http://www.shlomifish.org/humour.html >>>> >>>>???My only boss is God. And Chuck Norris who is his boss.??? >>>> >>>>Please reply to list if it's a mailing list >>>>post - http://shlom.in/reply . >>> >>> >> >>>Christopher Jones, P.Eng. >>>Suite 1801, 1 Yonge Street >>>Toronto, ON M5E1W7 >>>Tel. 416-203-7465 >>>Fax. 416-946-1005 >>>email cj at enersave.ca >>> >>>_______________________________________________ >>>toronto-pm mailing list >>>toronto-pm at pm.org >>>http://mail.pm.org/mailman/listinfo/toronto-pm >> >> >> >>Christopher Jones, P.Eng. >>Suite 1801, 1 Yonge Street >>Toronto, ON M5E1W7 >>Tel. 416-203-7465 >>Fax. 416-946-1005 >>email cj at enersave.ca >> >>_______________________________________________ >>toronto-pm mailing list >>toronto-pm at pm.org >>http://mail.pm.org/mailman/listinfo/toronto-pm > >-- > >Mark Jubenville ioncache at gmail.com >_______________________________________________ >toronto-pm mailing list >toronto-pm at pm.org >http://mail.pm.org/mailman/listinfo/toronto-pm >> Christopher Jones, P.Eng. Suite 1801, 1 Yonge Street Toronto, ON M5E1W7 Tel. 416-203-7465 Fax. 416-946-1005 email cj at enersave.ca -------------- next part -------------- An HTML attachment was scrubbed... URL: From cj at enersave.ca Fri Oct 19 18:43:47 2012 From: cj at enersave.ca (Chris Jones) Date: Fri, 19 Oct 2012 21:43:47 -0400 Subject: [tpm] Regex question In-Reply-To: <5F3A909E-D8C8-4066-A0FF-845D0C1C2658@morungos.com> References: <8BA74001-30A5-4564-89A9-954C871AF489@morungos.com> <5F3A909E-D8C8-4066-A0FF-845D0C1C2658@morungos.com> Message-ID: <20121020014349.322DB11FB21@xx1.develooper.com> I pull data from long files in that are in a fixed format, ascii report. For example: SUPPLY EXHAUST MINIMUM ZONE FLOW FLOW FAN FLOW NAME (CFM ) (CFM ) (KW) (FRAC) Kitchen Area 1C Spc zn 2750. 1400. 0.249 1.000 Kitchen Area 1C Pl zn 0. 0. 0.000 0.000 The Zone names are a max a maximum of 25 characters - spaces allowed. I want to split the lines into the zone name field and the 4 number fields: I am hoping the first pattern will leave the last character and remove the trailing spaces up to the maximum of 25 characters (assuming the user would have at least one character in the zone name.). I am hoping the following does the trick but I think the first pattern will end up removing the last character in the zone name: my @zoneLine = split /[\w\s{0,25)$]/+\w{4}/, $inLine; At any rate, the above gives me a compile error: Search pattern not terminated at Test-Split-1.pl line 5. Any help appreciated! >> Christopher Jones, P.Eng. Suite 1801, 1 Yonge Street Toronto, ON M5E1W7 Tel. 416-203-7465 Fax. 416-946-1005 email cj at enersave.ca -------------- next part -------------- An HTML attachment was scrubbed... URL: From fulko.hew at gmail.com Fri Oct 19 19:04:15 2012 From: fulko.hew at gmail.com (Fulko Hew) Date: Fri, 19 Oct 2012 22:04:15 -0400 Subject: [tpm] Regex question In-Reply-To: <20121020014349.322DB11FB21@xx1.develooper.com> References: <8BA74001-30A5-4564-89A9-954C871AF489@morungos.com> <5F3A909E-D8C8-4066-A0FF-845D0C1C2658@morungos.com> <20121020014349.322DB11FB21@xx1.develooper.com> Message-ID: On Fri, Oct 19, 2012 at 9:43 PM, Chris Jones wrote: > I pull data from long files in that are in a fixed format, ascii report. > > For example: > SUPPLY EXHAUST MINIMUM > ZONE FLOW FLOW FAN FLOW > NAME (CFM ) (CFM ) (KW) (FRAC) > > Kitchen Area 1C Spc zn 2750. 1400. 0.249 1.000 > Kitchen Area 1C Pl zn 0. 0. 0.000 0.000 > > The Zone names are a max a maximum of 25 characters - spaces allowed. I > want to split the lines into the zone name field and the 4 number fields: > I am hoping the first pattern will leave the last character and remove the > trailing spaces up to the maximum of 25 characters (assuming the user would > have at least one character in the zone name.). > > I am hoping the following does the trick but I think the first pattern > will end up removing the last character in the zone name: > > my @zoneLine = split /[\w\s{0,25)$]/+\w{4}/, $inLine; > my guess would be that this slash ^ shouldn't be there -------------- next part -------------- An HTML attachment was scrubbed... URL: From legrady at gmail.com Fri Oct 19 20:07:49 2012 From: legrady at gmail.com (Tom Legrady) Date: Fri, 19 Oct 2012 23:07:49 -0400 Subject: [tpm] Regex question In-Reply-To: References: <8BA74001-30A5-4564-89A9-954C871AF489@morungos.com> <5F3A909E-D8C8-4066-A0FF-845D0C1C2658@morungos.com> <20121020014349.322DB11FB21@xx1.develooper.com> Message-ID: Since it's a fixed format, I would go with unpack (inventing appropriate widths) my ( $zone, $supply, $exhaust, $fan, $flow ) = unpack "A25A10A10A10A10" $line; $supply += 0; # convert strings to numbers $exhaust += 0; $fan += 0; $flow += 0; and work from there On Fri, Oct 19, 2012 at 9:43 PM, Chris Jones wrote: > I pull data from long files in that are in a fixed format, ascii report. > > For example: > SUPPLY EXHAUST MINIMUM > ZONE FLOW FLOW FAN FLOW > NAME (CFM ) (CFM ) (KW) (FRAC) > > Kitchen Area 1C Spc zn 2750. 1400. 0.249 1.000 > Kitchen Area 1C Pl zn 0. 0. 0.000 0.000 > > The Zone names are a max a maximum of 25 characters - spaces allowed. I > want to split the lines into the zone name field and the 4 number fields: > I am hoping the first pattern will leave the last character and remove the > trailing spaces up to the maximum of 25 characters (assuming the user would > have at least one character in the zone name.). > > I am hoping the following does the trick but I think the first pattern > will end up removing the last character in the zone name: > > my @zoneLine = split /[\w\s{0,25)$]/+\w{4}/, $inLine; > > At any rate, the above gives me a compile error: > > Search pattern not terminated at Test-Split-1.pl line 5. > > Any help appreciated! > > > ** > > ** >> > Christopher Jones, P.Eng. > Suite 1801, 1 Yonge Street > Toronto, ON M5E1W7 > Tel. 416-203-7465 > Fax. 416-946-1005 > email cj at enersave.ca > > _______________________________________________ > toronto-pm mailing list > toronto-pm at pm.org > http://mail.pm.org/mailman/listinfo/toronto-pm > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From liam at holoweb.net Fri Oct 19 21:02:57 2012 From: liam at holoweb.net (Liam R E Quin) Date: Sat, 20 Oct 2012 00:02:57 -0400 Subject: [tpm] Regex question In-Reply-To: <20121020014349.322DB11FB21@xx1.develooper.com> References: <8BA74001-30A5-4564-89A9-954C871AF489@morungos.com> <5F3A909E-D8C8-4066-A0FF-845D0C1C2658@morungos.com> <20121020014349.322DB11FB21@xx1.develooper.com> Message-ID: <1350705777.13689.218.camel@localhost.localdomain> [resending from the right account - I hate the Evolution mailer sometimes. I should switch to Inteligent Design] On Fri, 2012-10-19 at 21:43 -0400, Chris Jones wrote: > Kitchen Area 1C Spc zn 2750. 1400. 0.249 1.000 > Kitchen Area 1C Pl zn 0. 0. 0.000 0.000 > my @zoneLine = split /[\w\s{0,25)$]/+\w{4}/, $inLine; This is muddled thinking. Take off your shoes, drink a cup of tea, and try again :-) Someone else suggested using unpack but I'd probably stick with regular expressions if you can take the time to get used to them, because they're really really useful an powerful once you have tamed them. [...] is a character class. A character class with one space in it matches the same as a character class with 25 spaces in it. [abc] matches an "a", a "b" or a "c" in the input. [a{0,25}] matches an "a", a "{", a "0", a ",", a "2", a "5" or a "}". [\w\s]{0,25} matches between 0 and 25 characters, each of which is a word or space character. It's also not what you want, but it's closer. Note also that split takes a regular expression that *separates* fields, and does not return the part of the input that matched the pattern. my @zoneLine = ($inLIne =~ m{ ^(.{25}) # the zone name \s*([\d.]+) # supply flow \s+([\d.]+) # exhaust flow \s+([\d.]+) # fan kw \s*([\d.]+) # minimum flow \s* $}); if (@zoneLine = 5) { # matched OK $zoneLine[0] =~ s/\s+$//; # remove trailing whitespace etc_etc_go_crazy)(; } else { print "unmatched: $_\n"; } Liam -- Liam Quin - XML Activity Lead, W3C, http://www.w3.org/People/Quin/ Pictures from old books: http://fromoldbooks.org/ Ankh: irc.sorcery.net irc.gnome.org freenode/#xml -- Liam Quin - XML Activity Lead, W3C, http://www.w3.org/People/Quin/ Pictures from old books: http://fromoldbooks.org/ Ankh: irc.sorcery.net irc.gnome.org freenode/#xml From olaf.alders at gmail.com Fri Oct 19 22:46:52 2012 From: olaf.alders at gmail.com (Olaf Alders) Date: Sat, 20 Oct 2012 01:46:52 -0400 Subject: [tpm] Regex question In-Reply-To: <1350705777.13689.218.camel@localhost.localdomain> References: <8BA74001-30A5-4564-89A9-954C871AF489@morungos.com> <5F3A909E-D8C8-4066-A0FF-845D0C1C2658@morungos.com> <20121020014349.322DB11FB21@xx1.develooper.com> <1350705777.13689.218.camel@localhost.localdomain> Message-ID: On 2012-10-20, at 12:02 AM, Liam R E Quin wrote: > [resending from the right account - I hate the Evolution mailer sometimes. I should switch to Inteligent Design] > > On Fri, 2012-10-19 at 21:43 -0400, Chris Jones wrote: > >> Kitchen Area 1C Spc zn 2750. 1400. 0.249 1.000 >> Kitchen Area 1C Pl zn 0. 0. 0.000 0.000 > >> my @zoneLine = split /[\w\s{0,25)$]/+\w{4}/, $inLine; > > This is muddled thinking. Take off your shoes, drink a cup of tea, and > try again :-) > > Someone else suggested using unpack but I'd probably stick with regular > expressions if you can take the time to get used to them, because > they're really really useful an powerful once you have tamed them. In the long run the experience with regexes may be more useful day to day, but I think unpack is actually quite well suited to this problem. "perldoc perlpacktut" expands nicely on the example Tom gave. In this case, at least, unpack is probably less noisy. Olaf -- Olaf Alders olaf.alders at gmail.com http://www.wundercounter.com http://twitter.com/wundercounter 866 503 2204 (Toll free - North America) 416 944 8306 (direct) From cj at enersave.ca Fri Oct 19 22:54:02 2012 From: cj at enersave.ca (Chris Jones) Date: Sat, 20 Oct 2012 01:54:02 -0400 Subject: [tpm] Regex question In-Reply-To: <1350705777.13689.218.camel@localhost.localdomain> References: <8BA74001-30A5-4564-89A9-954C871AF489@morungos.com> <5F3A909E-D8C8-4066-A0FF-845D0C1C2658@morungos.com> <20121020014349.322DB11FB21@xx1.develooper.com> <1350705777.13689.218.camel@localhost.localdomain> Message-ID: <20121020055407.0F88D1200A9@xx1.develooper.com> Thanks Liam, we are getting closer but no cigar just yet: #!/usr/local/bin/perl use strict; my $inLine = "Kitchen Area 1C Spc zn 2750. 1400. 0.249 1.000"; my @zoneLine = ($inLine =~ m{ ^(.{25}) # the zone name \s*([\d.]+) # supply flow \s+([\d.]+) # exhaust flow \s+([\d.]+) # fan kw \s*([\d.]+) # minimum flow \s* $}); if (@zoneLine == 5) { # matched OK $zoneLine[0] =~ s/\s+$//; # remove trailing whitespace } else { print "unmatched: $_\n"; } Output: "unmatched" At 12:02 AM 20/10/2012, Liam R E Quin wrote: >[resending from the right account - I hate the Evolution mailer >sometimes. I should switch to Inteligent Design] > >On Fri, 2012-10-19 at 21:43 -0400, Chris Jones wrote: > > > Kitchen Area 1C Spc zn 2750. 1400. 0.249 1.000 > > Kitchen Area 1C Pl zn 0. 0. 0.000 0.000 > > > my @zoneLine = split /[\w\s{0,25)$]/+\w{4}/, $inLine; > >This is muddled thinking. Take off your shoes, drink a cup of tea, and >try again :-) > >Someone else suggested using unpack but I'd probably stick with regular >expressions if you can take the time to get used to them, because >they're really really useful an powerful once you have tamed them. > >[...] is a character class. A character class with one space in it >matches the same as a character class with 25 spaces in it. >[abc] matches an "a", a "b" or a "c" in the input. >[a{0,25}] matches an "a", a "{", a "0", a ",", a "2", a "5" or a "}". > >[\w\s]{0,25} matches between 0 and 25 characters, each of which is a >word or space character. It's also not what you want, but it's closer. > >Note also that split takes a regular expression that *separates* fields, >and does not return the part of the input that matched the pattern. > >my @zoneLine = ($inLIne =~ m{ > ^(.{25}) # the zone name > \s*([\d.]+) # supply flow > \s+([\d.]+) # exhaust flow > \s+([\d.]+) # fan kw > \s*([\d.]+) # minimum flow > \s* > $}); > >if (@zoneLine = 5) { # matched OK > $zoneLine[0] =~ s/\s+$//; # remove trailing whitespace > etc_etc_go_crazy)(; >} else { > print "unmatched: $_\n"; >} > >Liam > >-- >Liam Quin - XML Activity Lead, W3C, http://www.w3.org/People/Quin/ >Pictures from old books: http://fromoldbooks.org/ >Ankh: irc.sorcery.net irc.gnome.org freenode/#xml > >-- >Liam Quin - XML Activity Lead, W3C, http://www.w3.org/People/Quin/ >Pictures from old books: http://fromoldbooks.org/ >Ankh: irc.sorcery.net irc.gnome.org freenode/#xml >> Christopher Jones, P.Eng. Suite 1801, 1 Yonge Street Toronto, ON M5E1W7 Tel. 416-203-7465 Fax. 416-946-1005 email cj at enersave.ca From liam at holoweb.net Fri Oct 19 23:51:37 2012 From: liam at holoweb.net (Liam R E Quin) Date: Sat, 20 Oct 2012 02:51:37 -0400 Subject: [tpm] Regex question In-Reply-To: References: <8BA74001-30A5-4564-89A9-954C871AF489@morungos.com> <5F3A909E-D8C8-4066-A0FF-845D0C1C2658@morungos.com> <20121020014349.322DB11FB21@xx1.develooper.com> <1350705777.13689.218.camel@localhost.localdomain> Message-ID: <1350715897.13689.227.camel@localhost.localdomain> On Sat, 2012-10-20 at 01:46 -0400, Olaf Alders wrote: > In the long run the experience with regexes may be more useful day to > day, but I think unpack is actually quite well suited to this problem. No disagreement there. But given the problem domain, I'd recommend spending time learning regular expressions, because the chances are high that (1) once the fields are extracted, there will be substitutions, and (2) it's the sort of case where one suddenly discovers that the problem definition doesn't cover all cases, e.g, sometimes one of the numbers has too many digits and overruns. Best, Liam -- Liam Quin - XML Activity Lead, W3C, http://www.w3.org/People/Quin/ Pictures from old books: http://fromoldbooks.org/ From liam at holoweb.net Fri Oct 19 23:55:48 2012 From: liam at holoweb.net (Liam R E Quin) Date: Sat, 20 Oct 2012 02:55:48 -0400 Subject: [tpm] Regex question References: <8BA74001-30A5-4564-89A9-954C871AF489@morungos.com> <5F3A909E-D8C8-4066-A0FF-845D0C1C2658@morungos.com> <20121020014349.322DB11FB21@xx1.develooper.com> <1350705777.13689.218.camel@localhost.localdomain> Message-ID: <1350716148.13689.229.camel@localhost.localdomain> On Sat, 2012-10-20 at 01:54 -0400, Chris Jones wrote: > Thanks Liam, we are getting closer but no cigar just yet: sorry, should have tested it - I forgot the "x" flag on the regular expression, that lets you include whitespace and comments. #!/usr/bin/perl use strict; my $inLine = "Kitchen Area 1C Spc zn 2750. 1400. 0.249 1.000"; my @zoneLine = ($inLine =~ m{ ^(.{25}) # the zone name \s*([\d.]+) # supply flow \s+([\d.]+) # exhaust flow \s+([\d.]+) # fan kw \s*([\d.]+) # minimum flow \s* $}x); if (@zoneLine == 5) { # matched OK $zoneLine[0] =~ s/\s+$//; # remove trailing whitespace print "match: ", join(', ', @zoneLine), "\n"; } else { print "unmatched: $inLine\n"; } -- Liam Quin - XML Activity Lead, W3C, http://www.w3.org/People/Quin/ Pictures from old books: http://fromoldbooks.org/ Ankh: irc.sorcery.net irc.gnome.org freenode/#xml From cj at enersave.ca Tue Oct 23 07:57:18 2012 From: cj at enersave.ca (Chris Jones) Date: Tue, 23 Oct 2012 10:57:18 -0400 Subject: [tpm] Another Regex question In-Reply-To: <1350716148.13689.229.camel@localhost.localdomain> References: <8BA74001-30A5-4564-89A9-954C871AF489@morungos.com> <5F3A909E-D8C8-4066-A0FF-845D0C1C2658@morungos.com> <20121020014349.322DB11FB21@xx1.develooper.com> <1350705777.13689.218.camel@localhost.localdomain> <1350716148.13689.229.camel@localhost.localdomain> Message-ID: <20121023145723.B844111DE2D@xx1.develooper.com> Thank you so much for all your help! I must make a donation to something in compensation for making my work life more productive! I have a bunch of files to delete in sub-directories. I only want to keep files with the following pattern: SomeFIle-Name.inp SomeFIle-Name.pd2 Any other files should be deleted. Unfortunately my simple search did not separate files such as: SomeFIle-Name.r2.inp SomeFIle-Name.r2.pd2 SimFile-Name.r2 - Baseline Design.inp #!/usr/local/bin/perl use strict; use File::Find; $\="\n"; $,="\n"; my $start=("./"); finddepth (\&wanted, $start); sub wanted { my $file = $_; #mod, eux, cfg test for each one if (( -f $file) && ( $file =~ /\.(inp|pd2)$/ )) { print "File $file, keep\n"; } else { print "File $file, delete\n"; } } >> Christopher Jones, P.Eng. Suite 1801, 1 Yonge Street Toronto, ON M5E1W7 Tel. 416-203-7465 Fax. 416-946-1005 email cj at enersave.ca From antoniosun at lavabit.com Tue Oct 23 08:41:09 2012 From: antoniosun at lavabit.com (Antonio Sun) Date: Tue, 23 Oct 2012 11:41:09 -0400 Subject: [tpm] Another Regex question In-Reply-To: <20121023145723.B844111DE2D@xx1.develooper.com> References: <8BA74001-30A5-4564-89A9-954C871AF489@morungos.com> <5F3A909E-D8C8-4066-A0FF-845D0C1C2658@morungos.com> <20121020014349.322DB11FB21@xx1.develooper.com> <1350705777.13689.218.camel@localhost.localdomain> <1350716148.13689.229.camel@localhost.localdomain> <20121023145723.B844111DE2D@xx1.develooper.com> Message-ID: > if (( -f $file) && ( $file =~ /\.(inp|pd2)$/ )) without much formal requirement definition, try to start with this if (( -f $file) && ( $file =~ /^\w+-\w+\.(inp|pd2)$/ )) On Tue, Oct 23, 2012 at 10:57 AM, Chris Jones wrote: > Thank you so much for all your help! > I must make a donation to something in compensation for making my work > life more productive! > > I have a bunch of files to delete in sub-directories. > > I only want to keep files with the following pattern: > SomeFIle-Name.inp > SomeFIle-Name.pd2 > > Any other files should be deleted. Unfortunately my simple search did not > separate files such as: > SomeFIle-Name.r2.inp > SomeFIle-Name.r2.pd2 > SimFile-Name.r2 - Baseline Design.inp > > #!/usr/local/bin/perl > use strict; > use File::Find; > > $\="\n"; > $,="\n"; > > my $start=("./"); > > finddepth (\&wanted, $start); > sub wanted { > my $file = $_; > #mod, eux, cfg test for each one > if (( -f $file) && ( $file =~ /\.(inp|pd2)$/ )) > { > print "File $file, keep\n"; > } > else > { > print "File $file, delete\n"; > } > } > > > > > > > > >> > Christopher Jones, P.Eng. > Suite 1801, 1 Yonge Street > Toronto, ON M5E1W7 > Tel. 416-203-7465 > Fax. 416-946-1005 > email cj at enersave.ca > > ______________________________**_________________ > toronto-pm mailing list > toronto-pm at pm.org > http://mail.pm.org/mailman/**listinfo/toronto-pm > -------------- next part -------------- An HTML attachment was scrubbed... URL: From fulko.hew at gmail.com Tue Oct 23 09:04:43 2012 From: fulko.hew at gmail.com (Fulko Hew) Date: Tue, 23 Oct 2012 12:04:43 -0400 Subject: [tpm] Another Regex question In-Reply-To: References: <8BA74001-30A5-4564-89A9-954C871AF489@morungos.com> <5F3A909E-D8C8-4066-A0FF-845D0C1C2658@morungos.com> <20121020014349.322DB11FB21@xx1.develooper.com> <1350705777.13689.218.camel@localhost.localdomain> <1350716148.13689.229.camel@localhost.localdomain> <20121023145723.B844111DE2D@xx1.develooper.com> Message-ID: On Tue, Oct 23, 2012 at 11:41 AM, Antonio Sun wrote: > >> if (( -f $file) && ( $file =~ /\.(inp|pd2)$/ )) > > without much formal requirement definition, try to start with this > > if (( -f $file) && ( $file =~ /^\w+-\w+\.(inp|pd2)$/ )) That just makes the regex even MORE specific, the question is why doesn't the original test work? I tried: perl -e '$file = "SomeFIle-Name.r2.pd2"; if ($file =~ /\.(inp|pd2)$/) { print "found\n"; } else { print "not found\n"}' and it worked... just like you'd expect! So I suspect that your being caught on the '-f $file' check. I didn't look into it, but... are you being caught by the (potential?) problem that you are getting just a filename, and not a filespec provided to the '-f' test, and hence the file isn't found ? > > On Tue, Oct 23, 2012 at 10:57 AM, Chris Jones wrote: >> >> Thank you so much for all your help! >> I must make a donation to something in compensation for making my work >> life more productive! >> >> I have a bunch of files to delete in sub-directories. >> >> I only want to keep files with the following pattern: >> SomeFIle-Name.inp >> SomeFIle-Name.pd2 >> >> Any other files should be deleted. Unfortunately my simple search did not >> separate files such as: >> SomeFIle-Name.r2.inp >> SomeFIle-Name.r2.pd2 >> SimFile-Name.r2 - Baseline Design.inp >> >> #!/usr/local/bin/perl >> use strict; >> use File::Find; >> >> $\="\n"; >> $,="\n"; >> >> my $start=("./"); >> >> finddepth (\&wanted, $start); >> sub wanted { >> my $file = $_; >> #mod, eux, cfg test for each one >> if (( -f $file) && ( $file =~ /\.(inp|pd2)$/ )) >> { >> print "File $file, keep\n"; >> } >> else >> { >> print "File $file, delete\n"; >> } >> } >> >> >> >> >> >> >> >> >> >> Christopher Jones, P.Eng. >> Suite 1801, 1 Yonge Street >> Toronto, ON M5E1W7 >> Tel. 416-203-7465 >> Fax. 416-946-1005 >> email cj at enersave.ca >> >> _______________________________________________ >> toronto-pm mailing list >> toronto-pm at pm.org >> http://mail.pm.org/mailman/listinfo/toronto-pm > > > > _______________________________________________ > toronto-pm mailing list > toronto-pm at pm.org > http://mail.pm.org/mailman/listinfo/toronto-pm > From liam at holoweb.net Tue Oct 23 09:55:16 2012 From: liam at holoweb.net (Liam R E Quin) Date: Tue, 23 Oct 2012 12:55:16 -0400 Subject: [tpm] Another Regex question In-Reply-To: <20121023145723.B844111DE2D@xx1.develooper.com> References: <8BA74001-30A5-4564-89A9-954C871AF489@morungos.com> <5F3A909E-D8C8-4066-A0FF-845D0C1C2658@morungos.com> <20121020014349.322DB11FB21@xx1.develooper.com> <1350705777.13689.218.camel@localhost.localdomain> <1350716148.13689.229.camel@localhost.localdomain> <20121023145723.B844111DE2D@xx1.develooper.com> Message-ID: <1351011316.7220.123.camel@localhost.localdomain> On Tue, 2012-10-23 at 10:57 -0400, Chris Jones wrote: > I only want to keep files with the following pattern: > SomeFIle-Name.inp > SomeFIle-Name.pd2 > > Any other files should be deleted. Unfortunately my simple search > did not separate files such as: > SomeFIle-Name.r2.inp > SomeFIle-Name.r2.pd2 > SimFile-Name.r2 - Baseline Design.inp So, you want t okeep files whose names are of the form ^ # start of the name [a-z]+ # letters -[a-z]+ # dash followed by more letters \.(inp|pd2) # file ends in .inp or .pd2 $ # end of string and allow upper and lower case letters, so use the i (case insnsitive) flag. sub iswanted($) { my ($name) = (@_); return $name =~ m{ ^ # start of the name [a-z]+ # letters -[a-z]+ # dash followed by more letters \.(inp|pd2) # file ends in .inp or .pd2 $ # end of string }ix; } Liam -- Liam Quin - the barefoot typographer - http://www.holoweb.net/~liam/ Pictures from old books: http://fromoldbooks.org/ Ankh: irc.sorcery.net irc.gnome.org freenode/#xml Co-author, 5th edition of "Beginning XML", Wrox, Summer 2012 From cj at enersave.ca Tue Oct 23 10:41:31 2012 From: cj at enersave.ca (Chris Jones) Date: Tue, 23 Oct 2012 13:41:31 -0400 Subject: [tpm] Another Regex question In-Reply-To: References: <8BA74001-30A5-4564-89A9-954C871AF489@morungos.com> <5F3A909E-D8C8-4066-A0FF-845D0C1C2658@morungos.com> <20121020014349.322DB11FB21@xx1.develooper.com> <1350705777.13689.218.camel@localhost.localdomain> <1350716148.13689.229.camel@localhost.localdomain> <20121023145723.B844111DE2D@xx1.develooper.com> Message-ID: <20121023174135.7B8422E8A81@xx1.develooper.com> At 12:04 PM 23/10/2012, Fulko Hew wrote: >On Tue, Oct 23, 2012 at 11:41 AM, Antonio Sun wrote: > > > >> if (( -f $file) && ( $file =~ /\.(inp|pd2)$/ )) > > > > without much formal requirement definition, try to start with this > > > > if (( -f $file) && ( $file =~ /^\w+-\w+\.(inp|pd2)$/ )) > > >That just makes the regex even MORE specific, the question is >why doesn't the original test work? > >I tried: > >perl -e '$file = "SomeFIle-Name.r2.pd2"; if ($file =~ /\.(inp|pd2)$/) >{ print "found\n"; } else { print "not found\n"}' > >and it worked... just like you'd expect! > >So I suspect that your being caught on the '-f $file' check. >I didn't look into it, but... are you being caught by the (potential?) problem >that you are getting just a filename, and not a filespec provided to >the '-f' test, >and hence the file isn't found ? > The original regex was finding the files partially correctly. It was finding all files ending with .inp or .pd2. My problem is that I was trying to do too many things with one regex. The program creates a number of "copies" of the original input files and runs those copies as parametric runs. Those parametric files are not removed as they are useful for quality control. So the original input files might be: E4 Trenton - Proposed.inp E4 Trenton - Proposed.pd2 The program will create parametric files: E4 Trenton - Proposed - CompError4.inp E4 Trenton - Proposed - CompError4.pd2 or E4 Trenton - Proposed - MNECB Reference Building.inp In addition to a whole bunch of files with extensions not .inp or .pd2. I have modified the regex to find only .inp or .pd2 files: if (( -f $file) && ( $file =~ /\w+(\s+|\w+|-)\.(inp|pd2)$/ )) Then I added a second test to try to eliminate the extraneous files: sub wanted { my $file = $_; #mod, eux, cfg test for each one if (( -f $file) && ( $file =~ /\w+(\s+|\w+|-)\.(inp|pd2)$/ )) #if (( -f $file) && ( $file =~ /\.(inp|pd2)$/ )) { if ( $file =~ /(HVAC Sizing|CompError|MNECB Proposed Building)\.(inp|pd2)$/ ) { print "File $file, delete 1\n"; } else { print "File $file, keep 1\n"; } } else { print "File $file, delete 2\n"; } } The second test is specific enough for my needs except I need to add a test to ensure I don't delete directories. >> Christopher Jones, P.Eng. Suite 1801, 1 Yonge Street Toronto, ON M5E1W7 Tel. 416-203-7465 Fax. 416-946-1005 email cj at enersave.ca From fulko.hew at gmail.com Tue Oct 23 11:10:56 2012 From: fulko.hew at gmail.com (Fulko Hew) Date: Tue, 23 Oct 2012 14:10:56 -0400 Subject: [tpm] Another Regex question In-Reply-To: <5086d6cf.08ff2a0a.4ece.ffffd06bSMTPIN_ADDED@mx.google.com> References: <8BA74001-30A5-4564-89A9-954C871AF489@morungos.com> <5F3A909E-D8C8-4066-A0FF-845D0C1C2658@morungos.com> <20121020014349.322DB11FB21@xx1.develooper.com> <1350705777.13689.218.camel@localhost.localdomain> <1350716148.13689.229.camel@localhost.localdomain> <20121023145723.B844111DE2D@xx1.develooper.com> <5086d6cf.08ff2a0a.4ece.ffffd06bSMTPIN_ADDED@mx.google.com> Message-ID: On Tue, Oct 23, 2012 at 1:41 PM, Chris Jones wrote: ... snip ... > The original regex was finding the files partially correctly. It was > finding all files ending with .inp or .pd2. My problem is that I was trying > to do too many things with one regex. > > The program creates a number of "copies" of the original input files and > runs those copies as parametric runs. Those parametric files are not > removed as they are useful for quality control. > > So the original input files might be: > > E4 Trenton - Proposed.inp > E4 Trenton - Proposed.pd2 > > The program will create parametric files: > E4 Trenton - Proposed - CompError4.inp > E4 Trenton - Proposed - CompError4.pd2 > or > E4 Trenton - Proposed - MNECB Reference Building.inp > > In addition to a whole bunch of files with extensions not .inp or .pd2. Sorry, I didn't appreciate what you were trying to say, when I first read it. So what _is_ the file naming rule? anything hyphen anything (optional white-space hyphen followed by stuff) dot inp|pd2 ??? From cj at enersave.ca Tue Oct 23 11:32:41 2012 From: cj at enersave.ca (Chris Jones) Date: Tue, 23 Oct 2012 14:32:41 -0400 Subject: [tpm] Another Regex question - follow on question Message-ID: <20121023183244.86B5811F190@xx1.develooper.com> My tests are working correctly, I don't try to delete directories. My follow on question is how do you tell File:Find to skip the directory the script is called from. I only want to delete files in the sub-directories. I can test each file to see if it's directory is '.' but would seem somewhat inefficient? >On Tue, Oct 23, 2012 at 11:41 AM, Antonio Sun wrote: > > > >> if (( -f $file) && ( $file =~ /\.(inp|pd2)$/ )) > > > > without much formal requirement definition, try to start with this > > > > if (( -f $file) && ( $file =~ /^\w+-\w+\.(inp|pd2)$/ )) > > >That just makes the regex even MORE specific, the question is >why doesn't the original test work? > >I tried: > >perl -e '$file = "SomeFIle-Name.r2.pd2"; if ($file =~ /\.(inp|pd2)$/) >{ print "found\n"; } else { print "not found\n"}' > >and it worked... just like you'd expect! > >So I suspect that your being caught on the '-f $file' check. >I didn't look into it, but... are you being caught by the (potential?) problem >that you are getting just a filename, and not a filespec provided to >the '-f' test, >and hence the file isn't found ? The original regex was finding the files partially correctly. It was finding all files ending with .inp or .pd2. My problem is that I was trying to do too many things with one regex. The program creates a number of "copies" of the original input files and runs those copies as parametric runs. Those parametric files are not removed as they are useful for quality control. So the original input files might be: E4 Trenton - Proposed.inp E4 Trenton - Proposed.pd2 The program will create parametric files: E4 Trenton - Proposed - CompError4.inp E4 Trenton - Proposed - CompError4.pd2 or E4 Trenton - Proposed - MNECB Reference Building.inp In addition to a whole bunch of files with extensions not .inp or .pd2. I have modified the regex to find only .inp or .pd2 files: if (( -f $file) && ( $file =~ /\w+(\s+|\w+|-)\.(inp|pd2)$/ )) Then I added a second test to try to eliminate the extraneous files: sub wanted { my $file = $_; #mod, eux, cfg test for each one if (( -f $file) && ( $file =~ /\w+(\s+|\w+|-)\.(inp|pd2)$/ )) #if (( -f $file) && ( $file =~ /\.(inp|pd2)$/ )) { if ( $file =~ /(HVAC Sizing|CompError|MNECB Proposed Building)\.(inp|pd2)$/ ) { print "File $file, delete 1\n"; } else { print "File $file, keep 1\n"; } } else { print "File $file, delete 2\n"; } } The second test is specific enough for my needs except I need to add a test to ensure I don't delete directories. >> Christopher Jones, P.Eng. Suite 1801, 1 Yonge Street Toronto, ON M5E1W7 Tel. 416-203-7465 Fax. 416-946-1005 email cj at enersave.ca From stuart at morungos.com Tue Oct 23 16:55:26 2012 From: stuart at morungos.com (Stuart Watt) Date: Tue, 23 Oct 2012 19:55:26 -0400 Subject: [tpm] Another Regex question - follow on question In-Reply-To: <20121023183244.86B5811F190@xx1.develooper.com> References: <20121023183244.86B5811F190@xx1.develooper.com> Message-ID: <92FBEA54-D8B1-4A1E-BC7B-EE01FC218120@morungos.com> On 2012-10-23, at 2:32 PM, Chris Jones wrote: > My tests are working correctly, I don't try to delete directories. > > My follow on question is how do you tell File:Find to skip the directory the script is called from. I only want to delete files in the sub-directories. > > I can test each file to see if it's directory is '.' but would seem somewhat inefficient? String matching efficiency is probably a thousand times higher than file system accesses, so if I was you I really wouldn't worry about it. I tend to use no_chdir => 1 and $File::Find::name, but to skip everything in the base directory, probably checking to see if $File::Find::dir is the same as the base should be quick and effective. All the best Stuart From olaf.alders at gmail.com Wed Oct 24 12:05:45 2012 From: olaf.alders at gmail.com (Olaf Alders) Date: Wed, 24 Oct 2012 15:05:45 -0400 Subject: [tpm] October meeting Message-ID: Are we all set up with speaker + room for tomorrow's meeting? Olaf -- Olaf Alders olaf.alders at gmail.com http://www.wundercounter.com http://twitter.com/wundercounter 866 503 2204 (Toll free - North America) 416 944 8306 (direct) From jztam at yahoo.com Wed Oct 24 14:14:06 2012 From: jztam at yahoo.com (J Z Tam) Date: Wed, 24 Oct 2012 14:14:06 -0700 (PDT) Subject: [tpm] October meeting In-Reply-To: Message-ID: <1351113246.24867.YahooMailClassic@web120902.mail.ne1.yahoo.com> Room 12-G? is confirmed. I'm Cc:-ing?? Chris Brown? to confirm that he is indeed able to speak about? Postgres'? Top Ten Questions.? IIRC he is hype, ready and Able to do the talk. See you tommorow about 6:30pm! @Chris,?? It is the tower building on the North West corner of Yonge St and? Bloor St.? All glass on the street level Lobby.? CIBC instant teller atrium is attached, as seen from inside.?? There are 3 pleather benches and a semicircular security desk. Just look for a bunch of geeks on the benches.? And look for a Mobile Number to call, at the security desk. Thanks Olaf...?? /jordan --- On Wed, 10/24/12, Olaf Alders wrote: From: Olaf Alders Subject: [tpm] October meeting To: toronto-pm at pm.org Received: Wednesday, October 24, 2012, 3:05 PM Are we all set up with speaker + room for tomorrow's meeting? Olaf -- Olaf Alders olaf.alders at gmail.com http://www.wundercounter.com http://twitter.com/wundercounter 866 503 2204 (Toll free - North America) 416 944 8306 (direct) _______________________________________________ toronto-pm mailing list toronto-pm at pm.org http://mail.pm.org/mailman/listinfo/toronto-pm -------------- next part -------------- An HTML attachment was scrubbed... URL: From jkeen at verizon.net Wed Oct 24 16:27:13 2012 From: jkeen at verizon.net (James E Keenan) Date: Wed, 24 Oct 2012 19:27:13 -0400 Subject: [tpm] Toronto Perl user needs help! Message-ID: <50887951.6070803@verizon.net> Thread starts here: https://rt.perl.org/rt3//Ticket/Display.html?id=115416 Continues here: http://thread.gmane.org/gmane.comp.lang.perl.perl5.porters/116789 The user kindly supplied his phone number and address -- a mere two metro stops from the TPM meeting site! :-) Make a friend! Help this Perl user out! Jim Keenan From jztam at yahoo.com Fri Oct 26 11:16:42 2012 From: jztam at yahoo.com (J Z Tam) Date: Fri, 26 Oct 2012 11:16:42 -0700 (PDT) Subject: [tpm] October meeting In-Reply-To: Message-ID: <1351275402.76916.YahooMailClassic@web120905.mail.ne1.yahoo.com> On behalf of all the Toranna? perlmongeren, THANK YOU!!! Such an informative ramp up on postgres. Please DO attend future meetings. We would love to have you in our midst. /jordan --- On Fri, 10/26/12, Christopher Browne wrote: From: Christopher Browne Subject: Re: [tpm] October meeting To: "J Z Tam" Cc: toronto-pm at pm.org, "Olaf Alders" Received: Friday, October 26, 2012, 12:35 PM FYI, here's a link to the slides from last night. https://docs.google.com/presentation/d/1QNBdwYjkVi-wV11D4tvNgsFu4GHxxsVbtBufUPxjpec/edit -- When confronted by a difficult problem, solve it by reducing it to the question, "How would the Lone Ranger handle this?" -------------- next part -------------- An HTML attachment was scrubbed... URL: From arocker at Vex.Net Fri Oct 26 13:47:54 2012 From: arocker at Vex.Net (arocker at Vex.Net) Date: Fri, 26 Oct 2012 16:47:54 -0400 Subject: [tpm] November meeting Message-ID: As I suggested last night, we still have some Lightning Talks outstanding, so we could use November's meeting to hear them. What's the general opinion? From olaf.alders at gmail.com Fri Oct 26 14:03:56 2012 From: olaf.alders at gmail.com (Olaf Alders) Date: Fri, 26 Oct 2012 17:03:56 -0400 Subject: [tpm] November meeting In-Reply-To: References: Message-ID: <492545BE-02A5-4E54-809C-B360B02806D4@gmail.com> On 2012-10-26, at 4:47 PM, arocker at vex.net wrote: > > As I suggested last night, we still have some Lightning Talks outstanding, > so we could use November's meeting to hear them. > > What's the general opinion? +1 -- Olaf Alders olaf.alders at gmail.com http://www.wundercounter.com http://twitter.com/wundercounter 866 503 2204 (Toll free - North America) 416 944 8306 (direct) From cj at enersave.ca Sat Oct 27 15:19:10 2012 From: cj at enersave.ca (Chris Jones) Date: Sat, 27 Oct 2012 18:19:10 -0400 Subject: [tpm] New Regex question In-Reply-To: <92FBEA54-D8B1-4A1E-BC7B-EE01FC218120@morungos.com> References: <20121023183244.86B5811F190@xx1.develooper.com> <92FBEA54-D8B1-4A1E-BC7B-EE01FC218120@morungos.com> Message-ID: <20121027221915.9FFB911EF55@xx1.develooper.com> Thank Stuart, I did end up using $File::Find::dir, very helpful. New question. I would like to replace multiple spaces with single spaces and multiple end of line with a single end of line. I thought this might work: $expression =~ s/(\s+)/\1/g; # puts back what it found So I tried $expression =~ s/(\s)/\1\s/g; That gave me the original double white space plus an s. Any insight very much appreciated. But that replaces all white spaces with At 07:55 PM 23/10/2012, Stuart Watt wrote: >On 2012-10-23, at 2:32 PM, Chris Jones wrote: > > > My tests are working correctly, I don't try to delete directories. > > > > My follow on question is how do you tell File:Find to skip the > directory the script is called from. I only want to delete files > in the sub-directories. > > > > I can test each file to see if it's directory is '.' but would > seem somewhat inefficient? > >String matching efficiency is probably a thousand times higher than >file system accesses, so if I was you I really wouldn't worry about >it. I tend to use no_chdir => 1 and $File::Find::name, but to skip >everything in the base directory, probably checking to see if >$File::Find::dir is the same as the base should be quick and effective. > >All the best >Stuart >_______________________________________________ >> Christopher Jones, P.Eng. Suite 1801, 1 Yonge Street Toronto, ON M5E1W7 Tel. 416-203-7465 Fax. 416-946-1005 email cj at enersave.ca From janes.rob at gmail.com Sat Oct 27 15:37:30 2012 From: janes.rob at gmail.com (Rob Janes) Date: Sat, 27 Oct 2012 18:37:30 -0400 Subject: [tpm] New Regex question In-Reply-To: <20121027221915.9FFB911EF55@xx1.develooper.com> References: <20121023183244.86B5811F190@xx1.develooper.com> <92FBEA54-D8B1-4A1E-BC7B-EE01FC218120@morungos.com> <20121027221915.9FFB911EF55@xx1.develooper.com> Message-ID: $expression =~ s/(\s)\s+/\1/gs that replaces sequences of two or more \s with one of whatever the first one matched. note that mixed tabs and blanks will get replaced. if you just want replacement of pure strings of a particular character ... $expression =~ s/(\s)\1+/\1/gs this will replace strings of blanks with a single blank, but if the blanks and tabs alternate it will do nothing with it. if you load $expression with multiple lines, this should also reduce multiple lines to one. don't try this on windows files though. cheers, Rob On Sat, Oct 27, 2012 at 6:19 PM, Chris Jones wrote: > Thank Stuart, I did end up using $File::Find::dir, very helpful. > > New question. I would like to replace multiple spaces with single spaces > and multiple end of line with a single end of line. > > I thought this might work: > $expression =~ s/(\s+)/\1/g; # puts back what it found > > So I tried > $expression =~ s/(\s)/\1\s/g; > That gave me the original double white space plus an s. > > Any insight very much appreciated. > > > But that replaces all white spaces with > At 07:55 PM 23/10/2012, Stuart Watt wrote: > >> On 2012-10-23, at 2:32 PM, Chris Jones wrote: >> >> > My tests are working correctly, I don't try to delete directories. >> > >> > My follow on question is how do you tell File:Find to skip the >> directory the script is called from. I only want to delete files in the >> sub-directories. >> > >> > I can test each file to see if it's directory is '.' but would seem >> somewhat inefficient? >> >> String matching efficiency is probably a thousand times higher than file >> system accesses, so if I was you I really wouldn't worry about it. I tend >> to use no_chdir => 1 and $File::Find::name, but to skip everything in the >> base directory, probably checking to see if $File::Find::dir is the same as >> the base should be quick and effective. >> >> All the best >> Stuart >> ______________________________**_________________ >> > > >> > Christopher Jones, P.Eng. > Suite 1801, 1 Yonge Street > Toronto, ON M5E1W7 > Tel. 416-203-7465 > Fax. 416-946-1005 > email cj at enersave.ca > > ______________________________**_________________ > toronto-pm mailing list > toronto-pm at pm.org > http://mail.pm.org/mailman/**listinfo/toronto-pm > -------------- next part -------------- An HTML attachment was scrubbed... URL: From cj at enersave.ca Sat Oct 27 15:48:33 2012 From: cj at enersave.ca (Chris Jones) Date: Sat, 27 Oct 2012 18:48:33 -0400 Subject: [tpm] New Regex question - partially solved Message-ID: <20121027224836.CD5091202DA@xx1.develooper.com> Progress: An example of the text I am trying to regex: Expression: if(Local(TYPE) == 1) then 1.25 else UNCHANGED endif I would like: Expression after: if(Local(TYPE) == 1) then 1.25 else UNCHANGED endif $Expression =~ s/(\s)\1*/\1/g; #gives me: if(Local(TYPE) == 1) then 1.25 else UNCHANGED endif But I can't figure out how to match the double carriage return? At 07:55 PM 23/10/2012, Stuart Watt wrote: >On 2012-10-23, at 2:32 PM, Chris Jones wrote: > > > My tests are working correctly, I don't try to delete directories. > > > > My follow on question is how do you tell File:Find to skip the > directory the script is called from. I only want to delete files > in the sub-directories. > > > > I can test each file to see if it's directory is '.' but would > seem somewhat inefficient? > >String matching efficiency is probably a thousand times higher than >file system accesses, so if I was you I really wouldn't worry about >it. I tend to use no_chdir => 1 and $File::Find::name, but to skip >everything in the base directory, probably checking to see if >$File::Find::dir is the same as the base should be quick and effective. > >All the best >Stuart >_______________________________________________ >> Christopher Jones, P.Eng. Suite 1801, 1 Yonge Street Toronto, ON M5E1W7 Tel. 416-203-7465 Fax. 416-946-1005 email cj at enersave.ca From uri at stemsystems.com Sat Oct 27 15:51:29 2012 From: uri at stemsystems.com (Uri Guttman) Date: Sat, 27 Oct 2012 18:51:29 -0400 Subject: [tpm] New Regex question In-Reply-To: <20121027221915.9FFB911EF55@xx1.develooper.com> References: <20121023183244.86B5811F190@xx1.develooper.com> <92FBEA54-D8B1-4A1E-BC7B-EE01FC218120@morungos.com> <20121027221915.9FFB911EF55@xx1.develooper.com> Message-ID: <508C6571.9050907@stemsystems.com> On 10/27/2012 06:19 PM, Chris Jones wrote: > Thank Stuart, I did end up using $File::Find::dir, very helpful. > > New question. I would like to replace multiple spaces with single > spaces and multiple end of line with a single end of line. > > I thought this might work: > $expression =~ s/(\s+)/\1/g; # puts back what it found > > So I tried > $expression =~ s/(\s)/\1\s/g; someone else gave you a decent solution but i want to clear up a misconception you have. the right side of s/// is a replacement string and \s is only a regex shortcut for white space. putting \s there will only give you a 's' char in the replacement. also \1 is not meant to be used in the replacement but only in the regex. $1 is the correct thing in the replacement. \1 is supported for backwards compatibility. another and likely better solution is to use tr///. this code will replace any run of space, \t, \r\n with a single one of each. tr/ \t\\n\r//s the replacement pattern will be duplicated from the left side and the /s modifier will squeeze them to 1 char. if you want to make any \r or \n runs be squeezed to a single \n you need an explicit replacement part: tr{ \t\n\r}{ \t\n\n}s i switched the delims as there were too many /\ leaning toothpicks. uri From janes.rob at gmail.com Sat Oct 27 15:57:18 2012 From: janes.rob at gmail.com (Rob Janes) Date: Sat, 27 Oct 2012 18:57:18 -0400 Subject: [tpm] New Regex question In-Reply-To: <508C6571.9050907@stemsystems.com> References: <20121023183244.86B5811F190@xx1.develooper.com> <92FBEA54-D8B1-4A1E-BC7B-EE01FC218120@morungos.com> <20121027221915.9FFB911EF55@xx1.develooper.com> <508C6571.9050907@stemsystems.com> Message-ID: $1 doesn't work. \1 is the characters matched while $1 is the pattern matched. It only matters if u want to match pure string. Btw careful with the \n matching. On Oct 27, 2012 6:51 PM, "Uri Guttman" wrote: > On 10/27/2012 06:19 PM, Chris Jones wrote: > >> Thank Stuart, I did end up using $File::Find::dir, very helpful. >> >> New question. I would like to replace multiple spaces with single >> spaces and multiple end of line with a single end of line. >> >> I thought this might work: >> $expression =~ s/(\s+)/\1/g; # puts back what it found >> >> So I tried >> $expression =~ s/(\s)/\1\s/g; >> > > someone else gave you a decent solution but i want to clear up a > misconception you have. the right side of s/// is a replacement string and > \s is only a regex shortcut for white space. putting \s there will only > give you a 's' char in the replacement. also \1 is not meant to be used in > the replacement but only in the regex. $1 is the correct thing in the > replacement. \1 is supported for backwards compatibility. > > another and likely better solution is to use tr///. this code will replace > any run of space, \t, \r\n with a single one of each. > > tr/ \t\\n\r//s > > the replacement pattern will be duplicated from the left side and the /s > modifier will squeeze them to 1 char. if you want to make any \r or \n runs > be squeezed to a single \n you need an explicit replacement part: > > tr{ \t\n\r}{ \t\n\n}s > > i switched the delims as there were too many /\ leaning toothpicks. > > uri > > ______________________________**_________________ > toronto-pm mailing list > toronto-pm at pm.org > http://mail.pm.org/mailman/**listinfo/toronto-pm > -------------- next part -------------- An HTML attachment was scrubbed... URL: From uri at stemsystems.com Sat Oct 27 16:22:04 2012 From: uri at stemsystems.com (Uri Guttman) Date: Sat, 27 Oct 2012 19:22:04 -0400 Subject: [tpm] New Regex question In-Reply-To: References: <20121023183244.86B5811F190@xx1.develooper.com> <92FBEA54-D8B1-4A1E-BC7B-EE01FC218120@morungos.com> <20121027221915.9FFB911EF55@xx1.develooper.com> <508C6571.9050907@stemsystems.com> Message-ID: <508C6C9C.8000009@stemsystems.com> On 10/27/2012 06:57 PM, Rob Janes wrote: > $1 doesn't work. > > \1 is the characters matched while $1 is the pattern matched. > > It only matters if u want to match pure string. that is wrong. both are only references to a grab which is always a string. you can use \1 in the regex to match what you have previously matched and grabbed. $1 is used in the replacement or after the regex to get what was grabbed. neither contains a regex. uri From janes.rob at gmail.com Sat Oct 27 16:37:45 2012 From: janes.rob at gmail.com (Rob Janes) Date: Sat, 27 Oct 2012 19:37:45 -0400 Subject: [tpm] New Regex question In-Reply-To: <508C6C9C.8000009@stemsystems.com> References: <20121023183244.86B5811F190@xx1.develooper.com> <92FBEA54-D8B1-4A1E-BC7B-EE01FC218120@morungos.com> <20121027221915.9FFB911EF55@xx1.develooper.com> <508C6571.9050907@stemsystems.com> <508C6C9C.8000009@stemsystems.com> Message-ID: That's what I thought. Until I tried it. The second use case does not work with $1. Try it. On Oct 27, 2012 7:22 PM, "Uri Guttman" wrote: > On 10/27/2012 06:57 PM, Rob Janes wrote: > >> $1 doesn't work. >> >> \1 is the characters matched while $1 is the pattern matched. >> >> It only matters if u want to match pure string. >> > > that is wrong. both are only references to a grab which is always a > string. you can use \1 in the regex to match what you have previously > matched and grabbed. $1 is used in the replacement or after the regex to > get what was grabbed. neither contains a regex. > > uri > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From janes.rob at gmail.com Sat Oct 27 16:42:17 2012 From: janes.rob at gmail.com (Rob Janes) Date: Sat, 27 Oct 2012 19:42:17 -0400 Subject: [tpm] New Regex question - partially solved In-Reply-To: <20121027224836.CD5091202DA@xx1.develooper.com> References: <20121027224836.CD5091202DA@xx1.develooper.com> Message-ID: Slurp the file and run the second regex. undef $/; $exp = ; $exp =~ s/(\s)\1+/\1/g; Not sure $/. On Oct 27, 2012 6:48 PM, "Chris Jones" wrote: > > > Progress: > > An example of the text I am trying to regex: > Expression: > if(Local(TYPE) == 1) then > 1.25 > > else > UNCHANGED > endif > > I would like: > Expression after: > if(Local(TYPE) == 1) then > 1.25 > else > UNCHANGED > endif > > $Expression =~ s/(\s)\1*/\1/g; #gives me: > if(Local(TYPE) == 1) then > 1.25 > > else > UNCHANGED > endif > > But I can't figure out how to match the double carriage return? > > At 07:55 PM 23/10/2012, Stuart Watt wrote: > >> On 2012-10-23, at 2:32 PM, Chris Jones wrote: >> >> > My tests are working correctly, I don't try to delete directories. >> > >> > My follow on question is how do you tell File:Find to skip the >> directory the script is called from. I only want to delete files in the >> sub-directories. >> > >> > I can test each file to see if it's directory is '.' but would seem >> somewhat inefficient? >> >> String matching efficiency is probably a thousand times higher than file >> system accesses, so if I was you I really wouldn't worry about it. I tend >> to use no_chdir => 1 and $File::Find::name, but to skip everything in the >> base directory, probably checking to see if $File::Find::dir is the same as >> the base should be quick and effective. >> >> All the best >> Stuart >> ______________________________**_________________ >> > > >> > Christopher Jones, P.Eng. > Suite 1801, 1 Yonge Street > Toronto, ON M5E1W7 > Tel. 416-203-7465 > Fax. 416-946-1005 > email cj at enersave.ca > > ______________________________**_________________ > toronto-pm mailing list > toronto-pm at pm.org > http://mail.pm.org/mailman/**listinfo/toronto-pm > -------------- next part -------------- An HTML attachment was scrubbed... URL: From cj at enersave.ca Sat Oct 27 17:18:50 2012 From: cj at enersave.ca (Chris Jones) Date: Sat, 27 Oct 2012 20:18:50 -0400 Subject: [tpm] New Regex question In-Reply-To: References: <20121023183244.86B5811F190@xx1.develooper.com> <92FBEA54-D8B1-4A1E-BC7B-EE01FC218120@morungos.com> <20121027221915.9FFB911EF55@xx1.develooper.com> Message-ID: <20121028001852.6689411DDF7@xx1.develooper.com> I am reading a memo field from an access database so the carriage return/line feeds are in the memo field. I am not sure what character is used but \n doesn't seem to be correct. At 06:45 PM 27/10/2012, Tom Legrady wrote: >Your problem is that you're stuffing back to much, in the 'replace' >have of the s//. You just want to stick in one space. \1 is ALL the >spaces you found; and \s is only special in the search half; in the >replace half it's just the letter 's'. > >my $SPACE = q{ }; >$expression =~ s/(\s+)/$SPACE/g; > >To deal with empty lines, you can search for multiple newlines with >nothing but optional spaces or tabs in between: > >$lines =~ s/\n[ \t]*\n/\n/ > >Personally, I'm more likely to process input files line by line, so >I would simply skip "empty" lines. > >LINE: >while ( my $line = <$fh> ) { > next LINE if $line =~ m{^\s*$}m; > chomp $line; > ... >} >> Christopher Jones, P.Eng. Suite 1801, 1 Yonge Street Toronto, ON M5E1W7 Tel. 416-203-7465 Fax. 416-946-1005 email cj at enersave.ca From janes.rob at gmail.com Sat Oct 27 17:47:15 2012 From: janes.rob at gmail.com (Rob Janes) Date: Sat, 27 Oct 2012 20:47:15 -0400 Subject: [tpm] New Regex question - partially solved In-Reply-To: References: <20121027224836.CD5091202DA@xx1.develooper.com> Message-ID: i'd suggest the squish tr that uri put out. otherwise, $exp =~ s/\r+/\n/g; $exp =~ s/(\s)\1+/\1g; note the use of + instead of *. the second s will not match repeated \r\n, which is probably what you have. On Sat, Oct 27, 2012 at 7:42 PM, Rob Janes wrote: > Slurp the file and run the second regex. > > undef $/; > $exp = ; > $exp =~ s/(\s)\1+/\1/g; > > Not sure $/. > On Oct 27, 2012 6:48 PM, "Chris Jones" wrote: > >> >> >> Progress: >> >> An example of the text I am trying to regex: >> Expression: >> if(Local(TYPE) == 1) then >> 1.25 >> >> else >> UNCHANGED >> endif >> >> I would like: >> Expression after: >> if(Local(TYPE) == 1) then >> 1.25 >> else >> UNCHANGED >> endif >> >> $Expression =~ s/(\s)\1*/\1/g; #gives me: >> if(Local(TYPE) == 1) then >> 1.25 >> >> else >> UNCHANGED >> endif >> >> But I can't figure out how to match the double carriage return? >> >> At 07:55 PM 23/10/2012, Stuart Watt wrote: >> >>> On 2012-10-23, at 2:32 PM, Chris Jones wrote: >>> >>> > My tests are working correctly, I don't try to delete directories. >>> > >>> > My follow on question is how do you tell File:Find to skip the >>> directory the script is called from. I only want to delete files in the >>> sub-directories. >>> > >>> > I can test each file to see if it's directory is '.' but would seem >>> somewhat inefficient? >>> >>> String matching efficiency is probably a thousand times higher than file >>> system accesses, so if I was you I really wouldn't worry about it. I tend >>> to use no_chdir => 1 and $File::Find::name, but to skip everything in the >>> base directory, probably checking to see if $File::Find::dir is the same as >>> the base should be quick and effective. >>> >>> All the best >>> Stuart >>> ______________________________**_________________ >>> >> >> >> >> Christopher Jones, P.Eng. >> Suite 1801, 1 Yonge Street >> Toronto, ON M5E1W7 >> Tel. 416-203-7465 >> Fax. 416-946-1005 >> email cj at enersave.ca >> >> ______________________________**_________________ >> toronto-pm mailing list >> toronto-pm at pm.org >> http://mail.pm.org/mailman/**listinfo/toronto-pm >> > -------------- next part -------------- An HTML attachment was scrubbed... URL: From janes.rob at gmail.com Sat Oct 27 17:52:28 2012 From: janes.rob at gmail.com (Rob Janes) Date: Sat, 27 Oct 2012 20:52:28 -0400 Subject: [tpm] New Regex question In-Reply-To: References: <20121023183244.86B5811F190@xx1.develooper.com> <92FBEA54-D8B1-4A1E-BC7B-EE01FC218120@morungos.com> <20121027221915.9FFB911EF55@xx1.develooper.com> <508C6571.9050907@stemsystems.com> <508C6C9C.8000009@stemsystems.com> Message-ID: sounds a bit muddy ... just to clarify, what I found to my surprise, is that $exp =~ s/(\s)$1+/$1/g; replaces mixed strings of white space with the first character. leading me to conclude that the first $1 actually is the \s, not the specific character matched. However, in the second part of the s, the $1 did indeed give the white space. So the $1 in the context of searching appears to render as the regex, not the characters matched. While in the context of replacing, the $1 renders as the actual characters matched, not the regex used. hope that makes it clearer. oh - perl 5.14.2. -rob On Sat, Oct 27, 2012 at 7:37 PM, Rob Janes wrote: > That's what I thought. > > Until I tried it. The second use case does not work with $1. > > Try it. > On Oct 27, 2012 7:22 PM, "Uri Guttman" wrote: > >> On 10/27/2012 06:57 PM, Rob Janes wrote: >> >>> $1 doesn't work. >>> >>> \1 is the characters matched while $1 is the pattern matched. >>> >>> It only matters if u want to match pure string. >>> >> >> that is wrong. both are only references to a grab which is always a >> string. you can use \1 in the regex to match what you have previously >> matched and grabbed. $1 is used in the replacement or after the regex to >> get what was grabbed. neither contains a regex. >> >> uri >> >> -------------- next part -------------- An HTML attachment was scrubbed... URL: From cj at enersave.ca Sat Oct 27 17:53:49 2012 From: cj at enersave.ca (Chris Jones) Date: Sat, 27 Oct 2012 20:53:49 -0400 Subject: [tpm] New Regex question In-Reply-To: <20121028001852.6689411DDF7@xx1.develooper.com> References: <20121023183244.86B5811F190@xx1.develooper.com> <92FBEA54-D8B1-4A1E-BC7B-EE01FC218120@morungos.com> <20121027221915.9FFB911EF55@xx1.develooper.com> <20121028001852.6689411DDF7@xx1.develooper.com> Message-ID: <20121028005350.E84A011DB99@xx1.develooper.com> The following two regex work. Expression before: if(Local(TYPE) == 1) then 1.25 else UNCHANGED endif Run script. $expression =~ s/(\s)\1*/\1/g; $expression =~ s/(\r\n)+/\r\n/g; Expression after: if(Local(TYPE) == 1) then 1.25 else UNCHANGED endif There is likely a way to make that one expression but it is working for my needs. At 08:18 PM 27/10/2012, Chris Jones wrote: >I am reading a memo field from an access database so the carriage >return/line feeds are in the memo field. I am not sure what >character is used but \n doesn't seem to be correct. > > > > > >At 06:45 PM 27/10/2012, Tom Legrady wrote: >>Your problem is that you're stuffing back to much, in the 'replace' >>have of the s//. You just want to stick in one space. \1 is ALL the >>spaces you found; and \s is only special in the search half; in the >>replace half it's just the letter 's'. >> >>my $SPACE = q{ }; >>$expression =~ s/(\s+)/$SPACE/g; >> >>To deal with empty lines, you can search for multiple newlines with >>nothing but optional spaces or tabs in between: >> >>$lines =~ s/\n[ \t]*\n/\n/ >> >>Personally, I'm more likely to process input files line by line, so >>I would simply skip "empty" lines. >> >>LINE: >>while ( my $line = <$fh> ) { >> next LINE if $line =~ m{^\s*$}m; >> chomp $line; >> ... >>} > > >> >Christopher Jones, P.Eng. >Suite 1801, 1 Yonge Street >Toronto, ON M5E1W7 >Tel. 416-203-7465 >Fax. 416-946-1005 >email cj at enersave.ca > >_______________________________________________ >toronto-pm mailing list >toronto-pm at pm.org >http://mail.pm.org/mailman/listinfo/toronto-pm >> Christopher Jones, P.Eng. Suite 1801, 1 Yonge Street Toronto, ON M5E1W7 Tel. 416-203-7465 Fax. 416-946-1005 email cj at enersave.ca From janes.rob at gmail.com Sat Oct 27 17:59:38 2012 From: janes.rob at gmail.com (Rob Janes) Date: Sat, 27 Oct 2012 20:59:38 -0400 Subject: [tpm] New Regex question In-Reply-To: <20121028005350.E84A011DB99@xx1.develooper.com> References: <20121023183244.86B5811F190@xx1.develooper.com> <92FBEA54-D8B1-4A1E-BC7B-EE01FC218120@morungos.com> <20121027221915.9FFB911EF55@xx1.develooper.com> <20121028001852.6689411DDF7@xx1.develooper.com> <20121028005350.E84A011DB99@xx1.develooper.com> Message-ID: this is a one liner ... $exp =~ s/(\s|\r\n)\1+/\1/g; you should replace the * with a + otherwise you're wasting time replacing something with itself. the regex matches single blanks, which are replaced with single blan On Sat, Oct 27, 2012 at 8:53 PM, Chris Jones wrote: > > The following two regex work. > Expression before: > if(Local(TYPE) == 1) then > 1.25 > > else > UNCHANGED > endif > > Run script. > $expression =~ s/(\s)\1*/\1/g; > $expression =~ s/(\r\n)+/\r\n/g; > > Expression after: > if(Local(TYPE) == 1) then > 1.25 > else > UNCHANGED > endif > > There is likely a way to make that one expression but it is working for my > needs. > > > > > At 08:18 PM 27/10/2012, Chris Jones wrote: > >> I am reading a memo field from an access database so the carriage >> return/line feeds are in the memo field. I am not sure what character is >> used but \n doesn't seem to be correct. >> >> >> >> >> >> At 06:45 PM 27/10/2012, Tom Legrady wrote: >> >>> Your problem is that you're stuffing back to much, in the 'replace' have >>> of the s//. You just want to stick in one space. \1 is ALL the spaces you >>> found; and \s is only special in the search half; in the replace half it's >>> just the letter 's'. >>> >>> my $SPACE = q{ }; >>> $expression =~ s/(\s+)/$SPACE/g; >>> >>> To deal with empty lines, you can search for multiple newlines with >>> nothing but optional spaces or tabs in between: >>> >>> $lines =~ s/\n[ \t]*\n/\n/ >>> >>> Personally, I'm more likely to process input files line by line, so I >>> would simply skip "empty" lines. >>> >>> LINE: >>> while ( my $line = <$fh> ) { >>> next LINE if $line =~ m{^\s*$}m; >>> chomp $line; >>> ... >>> } >>> >> >> >> >> Christopher Jones, P.Eng. >> Suite 1801, 1 Yonge Street >> Toronto, ON M5E1W7 >> Tel. 416-203-7465 >> Fax. 416-946-1005 >> email cj at enersave.ca >> >> ______________________________**_________________ >> toronto-pm mailing list >> toronto-pm at pm.org >> http://mail.pm.org/mailman/**listinfo/toronto-pm >> > > >> > Christopher Jones, P.Eng. > Suite 1801, 1 Yonge Street > Toronto, ON M5E1W7 > Tel. 416-203-7465 > Fax. 416-946-1005 > email cj at enersave.ca > > ______________________________**_________________ > toronto-pm mailing list > toronto-pm at pm.org > http://mail.pm.org/mailman/**listinfo/toronto-pm > -------------- next part -------------- An HTML attachment was scrubbed... URL: From uri at stemsystems.com Sat Oct 27 20:51:14 2012 From: uri at stemsystems.com (Uri Guttman) Date: Sat, 27 Oct 2012 23:51:14 -0400 Subject: [tpm] New Regex question In-Reply-To: References: <20121023183244.86B5811F190@xx1.develooper.com> <92FBEA54-D8B1-4A1E-BC7B-EE01FC218120@morungos.com> <20121027221915.9FFB911EF55@xx1.develooper.com> <508C6571.9050907@stemsystems.com> <508C6C9C.8000009@stemsystems.com> Message-ID: <508CABB2.2080208@stemsystems.com> On 10/27/2012 07:37 PM, Rob Janes wrote: > That's what I thought. > > Until I tried it. The second use case does not work with $1. > please bottom quote so your comments are easier to follow. and also show exactly what code you are talking about. just refering to a second use case is dangling. thanx, uri From uri at stemsystems.com Sat Oct 27 20:52:48 2012 From: uri at stemsystems.com (Uri Guttman) Date: Sat, 27 Oct 2012 23:52:48 -0400 Subject: [tpm] New Regex question - partially solved In-Reply-To: References: <20121027224836.CD5091202DA@xx1.develooper.com> Message-ID: <508CAC10.7010509@stemsystems.com> On 10/27/2012 07:42 PM, Rob Janes wrote: > Slurp the file and run the second regex. > > undef $/; > $exp = ; use File::Slurp is much better for that. > $exp =~ s/(\s)\1+/\1/g; i keep saying to not use \1 in the replacement. it is documented to be wrong but supported. don't use it there. use $1 uri From uri at stemsystems.com Sat Oct 27 20:56:12 2012 From: uri at stemsystems.com (Uri Guttman) Date: Sat, 27 Oct 2012 23:56:12 -0400 Subject: [tpm] New Regex question In-Reply-To: References: <20121023183244.86B5811F190@xx1.develooper.com> <92FBEA54-D8B1-4A1E-BC7B-EE01FC218120@morungos.com> <20121027221915.9FFB911EF55@xx1.develooper.com> <508C6571.9050907@stemsystems.com> <508C6C9C.8000009@stemsystems.com> Message-ID: <508CACDC.60407@stemsystems.com> On 10/27/2012 08:52 PM, Rob Janes wrote: > sounds a bit muddy ... > > just to clarify, what I found to my surprise, is that > > $exp =~ s/(\s)$1+/$1/g; > > replaces mixed strings of white space with the first character. leading me > to conclude that the first $1 actually is the \s, not the specific > character matched. However, in the second part of the s, the $1 did indeed > give the white space. So the $1 in the context of searching appears to > render as the regex, not the characters matched. While in the context of > replacing, the $1 renders as the actual characters matched, not the regex > used. > > hope that makes it clearer. sorry but no. $1 in the regex is what $1 was BEFORE the regex. it gets interpolated and then parsed as a regex. it is not related to the () in the regex. only \1 will be the grabbed text from that (). and $1 in the replacement is just the string matched in the () which is any single whitespace char. uri From uri at stemsystems.com Sat Oct 27 20:57:28 2012 From: uri at stemsystems.com (Uri Guttman) Date: Sat, 27 Oct 2012 23:57:28 -0400 Subject: [tpm] New Regex question In-Reply-To: <20121028005350.E84A011DB99@xx1.develooper.com> References: <20121023183244.86B5811F190@xx1.develooper.com> <92FBEA54-D8B1-4A1E-BC7B-EE01FC218120@morungos.com> <20121027221915.9FFB911EF55@xx1.develooper.com> <20121028001852.6689411DDF7@xx1.develooper.com> <20121028005350.E84A011DB99@xx1.develooper.com> Message-ID: <508CAD28.8090508@stemsystems.com> On 10/27/2012 08:53 PM, Chris Jones wrote: > > The following two regex work. > Expression before: > if(Local(TYPE) == 1) then > 1.25 > > else > UNCHANGED > endif > > Run script. > $expression =~ s/(\s)\1*/\1/g; > $expression =~ s/(\r\n)+/\r\n/g; > > Expression after: > if(Local(TYPE) == 1) then > 1.25 > else > UNCHANGED > endif > > There is likely a way to make that one expression but it is working for > my needs. > and as i said in several other replies, use $1 in the replacement and \1 in the regex. my tr/// version should work for the whole thing. it may need tweaking as i didn't test it. uri From shlomif at shlomifish.org Sat Oct 27 23:59:18 2012 From: shlomif at shlomifish.org (Shlomi Fish) Date: Sun, 28 Oct 2012 08:59:18 +0200 Subject: [tpm] Netiquette: Starting a New Thread [was Re: New Regex question] In-Reply-To: <20121027221915.9FFB911EF55@xx1.develooper.com> References: <20121023183244.86B5811F190@xx1.develooper.com> <92FBEA54-D8B1-4A1E-BC7B-EE01FC218120@morungos.com> <20121027221915.9FFB911EF55@xx1.develooper.com> Message-ID: <20121028085918.4e1b776c@lap.shlomifish.org> Hi all, just a note Chris - don't start a new thread by replying to an existing message, because that way threaded E-mailers (such as Claws-Mail or KMail) display it as a sub-thread of the original thread instead of as a new top-level thread. Instead, send a new E-mail to toronto-pm at pm.org . Regards, Shlomi Fish -- ----------------------------------------------------------------- Shlomi Fish http://www.shlomifish.org/ List of Portability Libraries - http://shlom.in/port-libs Staring at XSLT code for one minute has a 67% chance of making one permanently blind. Please reply to list if it's a mailing list post - http://shlom.in/reply . From janes.rob at gmail.com Sun Oct 28 03:45:35 2012 From: janes.rob at gmail.com (Rob Janes) Date: Sun, 28 Oct 2012 06:45:35 -0400 Subject: [tpm] New Regex question - partially solved In-Reply-To: <508CAC10.7010509@stemsystems.com> References: <20121027224836.CD5091202DA@xx1.develooper.com> <508CAC10.7010509@stemsystems.com> Message-ID: ok, if you don't believe me when I say it doesn't work, try it yourself then. [robj at rj-ul80vt ~]$ perl -e '$x = "one \t\t two"; print "$x\n"; $x =~ s/(\s)$1+/\1/; print "$x\n";' one two one two [robj at rj-ul80vt ~]$ perl -e '$x = "one \t\t two"; print "$x\n"; $x =~ s/(\s)\1+/\1/; print "$x\n";' one two one two notice that the usage of $1 resulted in a mixed string of whitespace being substituted. only the tabs should have been substituted, not everything. therefore, the $1 in the matching regex resolved to \s not space. On Sat, Oct 27, 2012 at 11:52 PM, Uri Guttman wrote: > On 10/27/2012 07:42 PM, Rob Janes wrote: > >> Slurp the file and run the second regex. >> >> undef $/; >> $exp = ; >> > use File::Slurp is much better for that. > > > $exp =~ s/(\s)\1+/\1/g; >> > > i keep saying to not use \1 in the replacement. it is documented to be > wrong but supported. don't use it there. use $1 > > uri > > ______________________________**_________________ > toronto-pm mailing list > toronto-pm at pm.org > http://mail.pm.org/mailman/**listinfo/toronto-pm > -------------- next part -------------- An HTML attachment was scrubbed... URL: From janes.rob at gmail.com Sun Oct 28 04:02:44 2012 From: janes.rob at gmail.com (Rob Janes) Date: Sun, 28 Oct 2012 07:02:44 -0400 Subject: [tpm] New Regex question - partially solved In-Reply-To: References: <20121027224836.CD5091202DA@xx1.develooper.com> <508CAC10.7010509@stemsystems.com> Message-ID: Uri, my apologies, you did say use $1 in the replacement side and I missed that. yes, agreed, use $1 on the replacement side, \1 on the match side. On Sun, Oct 28, 2012 at 6:45 AM, Rob Janes wrote: > ok, if you don't believe me when I say it doesn't work, try it yourself > then. > > [robj at rj-ul80vt ~]$ perl -e '$x = "one \t\t two"; print "$x\n"; $x =~ > s/(\s)$1+/\1/; print "$x\n";' > one two > one two > [robj at rj-ul80vt ~]$ perl -e '$x = "one \t\t two"; print "$x\n"; $x =~ > s/(\s)\1+/\1/; print "$x\n";' > one two > one two > > notice that the usage of $1 resulted in a mixed string of whitespace being > substituted. only the tabs should have been substituted, not everything. > > therefore, the $1 in the matching regex resolved to \s not space. > > > On Sat, Oct 27, 2012 at 11:52 PM, Uri Guttman wrote: > >> On 10/27/2012 07:42 PM, Rob Janes wrote: >> >>> Slurp the file and run the second regex. >>> >>> undef $/; >>> $exp = ; >>> >> use File::Slurp is much better for that. >> >> >> $exp =~ s/(\s)\1+/\1/g; >>> >> >> i keep saying to not use \1 in the replacement. it is documented to be >> wrong but supported. don't use it there. use $1 >> >> uri >> >> ______________________________**_________________ >> toronto-pm mailing list >> toronto-pm at pm.org >> http://mail.pm.org/mailman/**listinfo/toronto-pm >> > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From janes.rob at gmail.com Sun Oct 28 04:43:15 2012 From: janes.rob at gmail.com (Rob Janes) Date: Sun, 28 Oct 2012 07:43:15 -0400 Subject: [tpm] New Regex question In-Reply-To: <508CACDC.60407@stemsystems.com> References: <20121023183244.86B5811F190@xx1.develooper.com> <92FBEA54-D8B1-4A1E-BC7B-EE01FC218120@morungos.com> <20121027221915.9FFB911EF55@xx1.develooper.com> <508C6571.9050907@stemsystems.com> <508C6C9C.8000009@stemsystems.com> <508CACDC.60407@stemsystems.com> Message-ID: I don't think that's exactly correct ... the $1 on the match side appears to refer to the current regex, not a previous regex. or perhaps I've misunderstood what you're saying? [robj at rj-ul80vt ~]$ perl -e '$x = "one \t\t two"; print ".$1.\n"; print "$x\n"; $x =~ s/(\s)$1+/$1/; print "$x\n";' .. one two one two compare with this .. [robj at rj-ul80vt ~]$ perl -e '$x = "one \t\t two"; print ".$1.\n"; print "$x\n"; $x =~ s/(\s)\s+/$1/; print "$x\n";' .. one two one two No g on the sub, $1 is set on the first pass, not the second. It appears to act as if it was a \s not the interpolated contents of the first match. If the $1 was the contents of the parenthesized match, it would have been a space and the space tab tab space would not have been replaced. the match would have occurred only for the two tabs, which would have been replaced with one tab. However, the $1 appears to act as if it was a \s, matching any whitespace character. the parenthesised match matches the space, and the $1+ matches tab tab space. On the replacement side, the $1 is just a space. looked over the perlre man page, didn't see anything about that. i did find some new stuff. \g{1} instead of \1, to remove some ambiguity. also, named capture groups, (?xxxx) There was also the warning about using $1 and the like anywhere, causing an overall slowdown. that might be a reason to use \1 in the replacement, although it's possible that a \1 in that context would also slow perl down. also, I noticed that \1 in the replacement is "grandfathered" not deprecated, not for backwards compatibility, but to avoid shocking sed fans. That means that \1 is not going away. The warning section says it's use is discouraged because of the ambiguity with other uses of \1. This seems to explain what's happening: >>> The operation of interpolation should not be confused with the operation of matching a backreference. Certainly they mean two different things on the left side of the "s///". The only reason I can think of for this behaviour of $1 in a match regex is to replicate a pattern in the regex, perhaps with different modifiers. -rob On Sat, Oct 27, 2012 at 11:56 PM, Uri Guttman wrote: > On 10/27/2012 08:52 PM, Rob Janes wrote: > >> sounds a bit muddy ... >> >> just to clarify, what I found to my surprise, is that >> >> $exp =~ s/(\s)$1+/$1/g; >> >> replaces mixed strings of white space with the first character. leading >> me >> to conclude that the first $1 actually is the \s, not the specific >> character matched. However, in the second part of the s, the $1 did >> indeed >> give the white space. So the $1 in the context of searching appears to >> render as the regex, not the characters matched. While in the context of >> replacing, the $1 renders as the actual characters matched, not the regex >> used. >> >> hope that makes it clearer. >> > > sorry but no. > > $1 in the regex is what $1 was BEFORE the regex. it gets interpolated and > then parsed as a regex. it is not related to the () in the regex. only \1 > will be the grabbed text from that (). and $1 in the replacement is just > the string matched in the () which is any single whitespace char. > > uri > > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From uri at stemsystems.com Sun Oct 28 09:02:49 2012 From: uri at stemsystems.com (Uri Guttman) Date: Sun, 28 Oct 2012 12:02:49 -0400 Subject: [tpm] New Regex question - partially solved In-Reply-To: References: <20121027224836.CD5091202DA@xx1.develooper.com> <508CAC10.7010509@stemsystems.com> Message-ID: <508D5729.9090005@stemsystems.com> On 10/28/2012 06:45 AM, Rob Janes wrote: > ok, if you don't believe me when I say it doesn't work, try it yourself > then. > i haven't tried it as i said i didn't test it. > [robj at rj-ul80vt ~]$ perl -e '$x = "one \t\t two"; print "$x\n"; $x =~ > s/(\s)$1+/\1/; print "$x\n";' > one two > one two > [robj at rj-ul80vt ~]$ perl -e '$x = "one \t\t two"; print "$x\n"; $x =~ > s/(\s)\1+/\1/; print "$x\n";' > one two > one two > > notice that the usage of $1 resulted in a mixed string of whitespace being > substituted. only the tabs should have been substituted, not everything. > > therefore, the $1 in the matching regex resolved to \s not space. > please read the docs. you are greatly mistaken about \1 and $1. you keep using \1 in the replacement where it doesn't belong. why it seems to work is another story. when i get to playing with the code i will figure it out. too busy today. and learn to bottom post too. uri From janes.rob at gmail.com Sun Oct 28 09:35:08 2012 From: janes.rob at gmail.com (Rob Janes) Date: Sun, 28 Oct 2012 12:35:08 -0400 Subject: [tpm] New Regex question - partially solved In-Reply-To: <508D5729.9090005@stemsystems.com> References: <20121027224836.CD5091202DA@xx1.develooper.com> <508CAC10.7010509@stemsystems.com> <508D5729.9090005@stemsystems.com> Message-ID: Sigh. Regarding the accusation that I did not read the docs. Here's an excerpt from man perlre (the highlights are mine): Warning on \1 Instead of $1 Some people get too used to writing things like: $pattern =~ s/(\W)/\\\1/g; This is *grandfathered* (for \1 to \9) for the RHS of a substitute to avoid shocking the sed addicts, but it's a dirty habit to get into. That's because in PerlThink, the righthand side of an "s///" is a double-quoted string. "\1" in the usual double-quoted string means a control-A. The customary Unix meaning of "\1" is kludged in for "s///". However, if you get into the habit of doing that, you get yourself into trouble if you then add an "/e" modifier. s/(\d+)/ \1 + 1 /eg; # causes warning under -w Or if you try to do s/(\d+)/\1000/; You can't disambiguate that by saying "\{1}000", whereas you can fix it with "${1}000". The operation of interpolation should not be confused with the operation of matching a backreference. Certainly they mean two different things on the left side of the "s///". So you see, \1 in the replace is not deprecated, it is grandfathered. Everybody, feel free to keep using it, although it's use may cause reviewers of your code to point and stare, perhaps gesticulate. stylistically, I'd say if you're using \1 on the match side, don't switch to $1 on the replace side. It's confusing. As for being greatly mistaken about \1 and $1, I think not. \1 and $1 are slightly different beasts on the match side of an s/// regex. They both work, and are not deprecated. On the replace side, \1 and $1 are equivalent, there is no deprecation of \1. I've made specific statements about how \1 and $1 behave on the match side so as to better understand their differentiation. I've posted tested examples as well, and snippets of the documentation. So, Uri, what exactly is it that I'm greatly mistaken about? I am not sure what to make of the bottom posting remark. Perhaps it doesn't belong in this thread? fyi, The code snippets I posted were tested with perl 5.14. -rob On Sun, Oct 28, 2012 at 12:02 PM, Uri Guttman wrote: > On 10/28/2012 06:45 AM, Rob Janes wrote: > >> ok, if you don't believe me when I say it doesn't work, try it yourself >> then. >> >> i haven't tried it as i said i didn't test it. > > > [robj at rj-ul80vt ~]$ perl -e '$x = "one \t\t two"; print "$x\n"; $x =~ >> s/(\s)$1+/\1/; print "$x\n";' >> one two >> one two >> [robj at rj-ul80vt ~]$ perl -e '$x = "one \t\t two"; print "$x\n"; $x =~ >> s/(\s)\1+/\1/; print "$x\n";' >> one two >> one two >> >> notice that the usage of $1 resulted in a mixed string of whitespace being >> substituted. only the tabs should have been substituted, not everything. >> >> therefore, the $1 in the matching regex resolved to \s not space. >> >> please read the docs. you are greatly mistaken about \1 and $1. you keep > using \1 in the replacement where it doesn't belong. why it seems to work > is another story. when i get to playing with the code i will figure it out. > too busy today. > > and learn to bottom post too. > > uri > > > > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From cj at enersave.ca Sun Oct 28 11:23:33 2012 From: cj at enersave.ca (Chris Jones) Date: Sun, 28 Oct 2012 14:23:33 -0400 Subject: [tpm] New Regex question In-Reply-To: <508C6C9C.8000009@stemsystems.com> References: <20121023183244.86B5811F190@xx1.develooper.com> <92FBEA54-D8B1-4A1E-BC7B-EE01FC218120@morungos.com> <20121027221915.9FFB911EF55@xx1.develooper.com> <508C6571.9050907@stemsystems.com> <508C6C9C.8000009@stemsystems.com> Message-ID: <20121028182335.A3EF211EB3D@xx1.develooper.com> At 07:22 PM 27/10/2012, Uri Guttman wrote: >On 10/27/2012 06:57 PM, Rob Janes wrote: >>$1 doesn't work. >> >>\1 is the characters matched while $1 is the pattern matched. >> >>It only matters if u want to match pure string. > >that is wrong. both are only references to a grab which is always a >string. you can use \1 in the regex to match what you have >previously matched and grabbed. $1 is used in the replacement or >after the regex to get what was grabbed. neither contains a regex. > >uri Chapman states that \1 is used with in the pattern and $1 is used everywhere else. He offers this example: while(<>) { s/(\w+ and \1/$1 twice/; s/(w+) and (\w+)/$2 and $1/; } This example reverses pairs of different words, 'Marks and Spencer' into 'Spencer and Marks', and collapses identical pairs, taking 'Sattchi and Sattchi' into 'Sattchi twice' So, my example should be $exp =~ s/(\s|\r\n)\1+/$1/g; >> Christopher Jones, P.Eng. Suite 1801, 1 Yonge Street Toronto, ON M5E1W7 Tel. 416-203-7465 Fax. 416-946-1005 email cj at enersave.ca From liam at holoweb.net Sun Oct 28 11:22:20 2012 From: liam at holoweb.net (Liam R E Quin) Date: Sun, 28 Oct 2012 19:22:20 +0100 Subject: [tpm] New Regex question - partially solved In-Reply-To: <508D5729.9090005@stemsystems.com> References: <20121027224836.CD5091202DA@xx1.develooper.com> <508CAC10.7010509@stemsystems.com> <508D5729.9090005@stemsystems.com> Message-ID: <1351448540.3583.44.camel@localhost.localdomain> On Sun, 2012-10-28 at 12:02 -0400, Uri Guttman wrote: > On 10/28/2012 06:45 AM, Rob Janes wrote: [...] > please read the docs. you are greatly mistaken about \1 and $1. You're talking past one another, because Rob missed the word "replacement" in the original note. I think Rob thought it was a question about back-references, which indeed use \1 (or the extended newer syntax). \1 does work in the replacement, and always has, because that's the syntax ed used (and hence sed, ex, vi, and others). But it's not a good idea, and these days $1 is preferred, I think we also all agree on that. I a not sure when $ was introduced for the replacement string, I think in Perl 4. Liam -- Liam Quin - XML Activity Lead, W3C, http://www.w3.org/People/Quin/ Pictures from old books: http://fromoldbooks.org/ Ankh: irc.sorcery.net irc.gnome.org freenode/#xml Co-author: 5th edition of "Beginning XML", Wrox, July 2012 From legrady at gmail.com Sun Oct 28 11:44:15 2012 From: legrady at gmail.com (Tom Legrady) Date: Sun, 28 Oct 2012 14:44:15 -0400 Subject: [tpm] New Regex question In-Reply-To: <20121028182335.A3EF211EB3D@xx1.develooper.com> References: <20121023183244.86B5811F190@xx1.develooper.com> <92FBEA54-D8B1-4A1E-BC7B-EE01FC218120@morungos.com> <20121027221915.9FFB911EF55@xx1.develooper.com> <508C6571.9050907@stemsystems.com> <508C6C9C.8000009@stemsystems.com> <20121028182335.A3EF211EB3D@xx1.develooper.com> Message-ID: On Sun, Oct 28, 2012 at 2:23 PM, Chris Jones wrote: > At 07:22 PM 27/10/2012, Uri Guttman wrote: > >> On 10/27/2012 06:57 PM, Rob Janes wrote: >> >>> $1 doesn't work. >>> >>> \1 is the characters matched while $1 is the pattern matched. >>> >>> It only matters if u want to match pure string. >>> >> >> that is wrong. both are only references to a grab which is always a >> string. you can use \1 in the regex to match what you have previously >> matched and grabbed. $1 is used in the replacement or after the regex to >> get what was grabbed. neither contains a regex. >> >> uri >> > > Chapman states that \1 is used with in the pattern and $1 is used > everywhere else. He offers this example: > > while(<>) > { > s/(\w+ and \1/$1 twice/; > s/(w+) and (\w+)/$2 and $1/; > } > > This example reverses pairs of different words, 'Marks and Spencer' into > 'Spencer and Marks', and collapses identical pairs, taking 'Sattchi and > Sattchi' into 'Sattchi twice' > > So, my example should be $exp =~ s/(\s|\r\n)\1+/$1/g; > You don't need \r\n ... \n is sufficient: "\n matches a logical newline. Perl converts between \n and your OS's native newline character when reading from or writing to text files." 'Character Escapes' in http://perldoc.perl.org/perlrebackslash.html Also, do you want to wind up with either a space or a newline, accidentally, depending on which one came first? Consider "line 1 \n \nline 3" collapsing into "line1 line 3" compared to "line 1\n \nline 3" collapsing into "line1\nline 3" just because of a trailing space. Tom > >> > Christopher Jones, P.Eng. > Suite 1801, 1 Yonge Street > Toronto, ON M5E1W7 > Tel. 416-203-7465 > Fax. 416-946-1005 > email cj at enersave.ca > > ______________________________**_________________ > toronto-pm mailing list > toronto-pm at pm.org > http://mail.pm.org/mailman/**listinfo/toronto-pm > -------------- next part -------------- An HTML attachment was scrubbed... URL: From janes.rob at gmail.com Sun Oct 28 12:04:26 2012 From: janes.rob at gmail.com (Rob Janes) Date: Sun, 28 Oct 2012 15:04:26 -0400 Subject: [tpm] New Regex question In-Reply-To: References: <20121023183244.86B5811F190@xx1.develooper.com> <92FBEA54-D8B1-4A1E-BC7B-EE01FC218120@morungos.com> <20121027221915.9FFB911EF55@xx1.develooper.com> <508C6571.9050907@stemsystems.com> <508C6C9C.8000009@stemsystems.com> <20121028182335.A3EF211EB3D@xx1.develooper.com> Message-ID: I suspect Chris is on linux/unix, reading \r\n. that conversion from \r\n to \n would only happen on a windows perl, reading a windows text file. it's not clear such a conversion would happen even in windows perl if it was reading a database blob (or whatever it was), which is what Chris is doing. On Sun, Oct 28, 2012 at 2:44 PM, Tom Legrady wrote: > > > On Sun, Oct 28, 2012 at 2:23 PM, Chris Jones wrote: > >> At 07:22 PM 27/10/2012, Uri Guttman wrote: >> >>> On 10/27/2012 06:57 PM, Rob Janes wrote: >>> >>>> $1 doesn't work. >>>> >>>> \1 is the characters matched while $1 is the pattern matched. >>>> >>>> It only matters if u want to match pure string. >>>> >>> >>> that is wrong. both are only references to a grab which is always a >>> string. you can use \1 in the regex to match what you have previously >>> matched and grabbed. $1 is used in the replacement or after the regex to >>> get what was grabbed. neither contains a regex. >>> >>> uri >>> >> >> Chapman states that \1 is used with in the pattern and $1 is used >> everywhere else. He offers this example: >> >> while(<>) >> { >> s/(\w+ and \1/$1 twice/; >> s/(w+) and (\w+)/$2 and $1/; >> } >> >> This example reverses pairs of different words, 'Marks and Spencer' into >> 'Spencer and Marks', and collapses identical pairs, taking 'Sattchi and >> Sattchi' into 'Sattchi twice' >> >> So, my example should be $exp =~ s/(\s|\r\n)\1+/$1/g; >> > > You don't need \r\n ... \n is sufficient: > > "\n matches a logical newline. Perl converts between \n and your > OS's native newline character when reading from or writing to text > files." > 'Character Escapes' > in http://perldoc.perl.org/perlrebackslash.html > > Also, do you want to wind up with either a space or a newline, > accidentally, depending on which one came first? > > Consider "line 1 \n \nline 3" collapsing into "line1 line 3" > compared to "line 1\n \nline 3" collapsing into "line1\nline 3" > just because of a trailing space. > > Tom > > >> >> >> Christopher Jones, P.Eng. >> Suite 1801, 1 Yonge Street >> Toronto, ON M5E1W7 >> Tel. 416-203-7465 >> Fax. 416-946-1005 >> email cj at enersave.ca >> >> ______________________________**_________________ >> toronto-pm mailing list >> toronto-pm at pm.org >> http://mail.pm.org/mailman/**listinfo/toronto-pm >> > > > _______________________________________________ > toronto-pm mailing list > toronto-pm at pm.org > http://mail.pm.org/mailman/listinfo/toronto-pm > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From janes.rob at gmail.com Sun Oct 28 12:28:15 2012 From: janes.rob at gmail.com (Rob Janes) Date: Sun, 28 Oct 2012 15:28:15 -0400 Subject: [tpm] New Regex question In-Reply-To: References: <20121023183244.86B5811F190@xx1.develooper.com> <92FBEA54-D8B1-4A1E-BC7B-EE01FC218120@morungos.com> <20121027221915.9FFB911EF55@xx1.develooper.com> <508C6571.9050907@stemsystems.com> <508C6C9C.8000009@stemsystems.com> <20121028182335.A3EF211EB3D@xx1.develooper.com> Message-ID: [robj at rj-ul80vt ~]$ perl -e '$x="line 1 \n\nline 2"; $x =~ s/(\s)\1+/$1/g; print "$x\n";' line 1 line 2 looks ok. [robj at rj-ul80vt ~]$ perl -e '$x="line 1 \n\n line 2"; $x =~ s/(\s)\s+/$1/g; print "$x\n";' line 1 line 2 this ones wrong. On Sun, Oct 28, 2012 at 2:44 PM, Tom Legrady wrote: > > > On Sun, Oct 28, 2012 at 2:23 PM, Chris Jones wrote: > >> At 07:22 PM 27/10/2012, Uri Guttman wrote: >> >>> On 10/27/2012 06:57 PM, Rob Janes wrote: >>> >>>> $1 doesn't work. >>>> >>>> \1 is the characters matched while $1 is the pattern matched. >>>> >>>> It only matters if u want to match pure string. >>>> >>> >>> that is wrong. both are only references to a grab which is always a >>> string. you can use \1 in the regex to match what you have previously >>> matched and grabbed. $1 is used in the replacement or after the regex to >>> get what was grabbed. neither contains a regex. >>> >>> uri >>> >> >> Chapman states that \1 is used with in the pattern and $1 is used >> everywhere else. He offers this example: >> >> while(<>) >> { >> s/(\w+ and \1/$1 twice/; >> s/(w+) and (\w+)/$2 and $1/; >> } >> >> This example reverses pairs of different words, 'Marks and Spencer' into >> 'Spencer and Marks', and collapses identical pairs, taking 'Sattchi and >> Sattchi' into 'Sattchi twice' >> >> So, my example should be $exp =~ s/(\s|\r\n)\1+/$1/g; >> > > You don't need \r\n ... \n is sufficient: > > "\n matches a logical newline. Perl converts between \n and your > OS's native newline character when reading from or writing to text > files." > 'Character Escapes' > in http://perldoc.perl.org/perlrebackslash.html > > Also, do you want to wind up with either a space or a newline, > accidentally, depending on which one came first? > > Consider "line 1 \n \nline 3" collapsing into "line1 line 3" > compared to "line 1\n \nline 3" collapsing into "line1\nline 3" > just because of a trailing space. > > Tom > > >> >> >> Christopher Jones, P.Eng. >> Suite 1801, 1 Yonge Street >> Toronto, ON M5E1W7 >> Tel. 416-203-7465 >> Fax. 416-946-1005 >> email cj at enersave.ca >> >> ______________________________**_________________ >> toronto-pm mailing list >> toronto-pm at pm.org >> http://mail.pm.org/mailman/**listinfo/toronto-pm >> > > > _______________________________________________ > toronto-pm mailing list > toronto-pm at pm.org > http://mail.pm.org/mailman/listinfo/toronto-pm > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From uri at stemsystems.com Sun Oct 28 13:59:47 2012 From: uri at stemsystems.com (Uri Guttman) Date: Sun, 28 Oct 2012 16:59:47 -0400 Subject: [tpm] New Regex question - partially solved In-Reply-To: References: <20121027224836.CD5091202DA@xx1.develooper.com> <508CAC10.7010509@stemsystems.com> <508D5729.9090005@stemsystems.com> Message-ID: <508D9CC3.9040008@stemsystems.com> On 10/28/2012 12:35 PM, Rob Janes wrote: > Sigh. > > Regarding the accusation that I did not read the docs. Here's an excerpt > from man perlre (the highlights are mine): > > Warning on \1 Instead of $1 > Some people get too used to writing things like: > > $pattern =~ s/(\W)/\\\1/g; > > This is *grandfathered* (for \1 to \9) for the RHS of a substitute > to avoid shocking the sed addicts, but it's i said it was allowed but not considered good code. > a dirty habit to get into. That's because in PerlThink, the > righthand side of an "s///" is a double-quoted > string. "\1" in the usual double-quoted string means a control-A. > The customary Unix meaning of "\1" is > kludged in for "s///". However, if you get into the habit of doing > that, you get yourself into trouble if > you then add an "/e" modifier. > > s/(\d+)/ \1 + 1 /eg; # causes warning under -w > > Or if you try to do > > s/(\d+)/\1000/; > > You can't disambiguate that by saying "\{1}000", whereas you can fix > it with "${1}000". The operation of > interpolation should not be confused with the operation of matching > a backreference. Certainly they mean > two different things on the left side of the "s///". > > So you see, \1 in the replace is not deprecated, it is grandfathered. > Everybody, feel free to keep using it, although it's use may cause > reviewers of your code to point and stare, perhaps gesticulate. which is just as bad as being deprecated. i review code for my perlhunter business and that is something i will always note. there is NO reason to use \1 in the replacement when $1 is the same value and works correctly in all situations. just because something may work doesn't make it good code. > > stylistically, I'd say if you're using \1 on the match side, don't switch > to $1 on the replace side. It's confusing. and that is way off base too. $1 is the standard way to access a grab both in the replacement and afterwards. > > As for being greatly mistaken about \1 and $1, I think not. \1 and $1 are > slightly different beasts on the match side of an s/// regex. They both > work, and are not deprecated. On the replace side, \1 and $1 are > equivalent, there is no deprecation of \1. I've made specific statements > about how \1 and $1 behave on the match side so as to better understand > their differentiation. I've posted tested examples as well, and snippets > of the documentation. So, Uri, what exactly is it that I'm greatly > mistaken about? what you just said and what the docs suggest. you keep doing your style. it will not help you get a better perl job if you are stubborn about improving your style. and yes, style matters a great deal in quality code. uri From uri at stemsystems.com Sun Oct 28 14:01:16 2012 From: uri at stemsystems.com (Uri Guttman) Date: Sun, 28 Oct 2012 17:01:16 -0400 Subject: [tpm] New Regex question - partially solved In-Reply-To: <1351448540.3583.44.camel@localhost.localdomain> References: <20121027224836.CD5091202DA@xx1.develooper.com> <508CAC10.7010509@stemsystems.com> <508D5729.9090005@stemsystems.com> <1351448540.3583.44.camel@localhost.localdomain> Message-ID: <508D9D1C.3050009@stemsystems.com> On 10/28/2012 02:22 PM, Liam R E Quin wrote: > On Sun, 2012-10-28 at 12:02 -0400, Uri Guttman wrote: >> On 10/28/2012 06:45 AM, Rob Janes wrote: > [...] >> please read the docs. you are greatly mistaken about \1 and $1. > > You're talking past one another, because Rob missed the word > "replacement" in the original note. I think Rob thought it was a > question about back-references, which indeed use \1 (or the extended > newer syntax). please don't tell me what i was saying. he was using \1 in the replacement and i kept saying replacement. i do know a tiny bit of perl and how to review it. :) uri From liam at holoweb.net Sun Oct 28 14:30:29 2012 From: liam at holoweb.net (Liam R E Quin) Date: Sun, 28 Oct 2012 22:30:29 +0100 Subject: [tpm] New Regex question - partially solved In-Reply-To: <508D9D1C.3050009@stemsystems.com> References: <20121027224836.CD5091202DA@xx1.develooper.com> <508CAC10.7010509@stemsystems.com> <508D5729.9090005@stemsystems.com> <1351448540.3583.44.camel@localhost.localdomain> <508D9D1C.3050009@stemsystems.com> Message-ID: <1351459829.3583.49.camel@localhost.localdomain> On Sun, 2012-10-28 at 17:01 -0400, Uri Guttman wrote: > On 10/28/2012 02:22 PM, Liam R E Quin wrote: \ > > You're talking past one another, because Rob missed the word > > "replacement" in the original note. I think Rob thought it was a > > question about back-references, which indeed use \1 (or the extended > > newer syntax). > > please don't tell me what i was saying. I'm not trying to do that - I'm sorry if it seemed that way. > he was using \1 in the > replacement and i kept saying replacement. Yes. That is why I said you are talking past one another - yuo are each saying things the other is not noticing. I was not criticising your perl knowledge. Liam -- Liam Quin - XML Activity Lead, W3C, http://www.w3.org/People/Quin/ Pictures from old books: http://fromoldbooks.org/ Co-author, 5th edition of 'Beginning XML', Wrox, July 2012 From uri at stemsystems.com Sun Oct 28 15:07:32 2012 From: uri at stemsystems.com (Uri Guttman) Date: Sun, 28 Oct 2012 18:07:32 -0400 Subject: [tpm] New Regex question - partially solved In-Reply-To: <1351459829.3583.49.camel@localhost.localdomain> References: <20121027224836.CD5091202DA@xx1.develooper.com> <508CAC10.7010509@stemsystems.com> <508D5729.9090005@stemsystems.com> <1351448540.3583.44.camel@localhost.localdomain> <508D9D1C.3050009@stemsystems.com> <1351459829.3583.49.camel@localhost.localdomain> Message-ID: <508DACA4.4090403@stemsystems.com> On 10/28/2012 05:30 PM, Liam R E Quin wrote: > On Sun, 2012-10-28 at 17:01 -0400, Uri Guttman wrote: >> On 10/28/2012 02:22 PM, Liam R E Quin wrote: > \ >>> You're talking past one another, because Rob missed the word >>> "replacement" in the original note. I think Rob thought it was a >>> question about back-references, which indeed use \1 (or the extended >>> newer syntax). >> >> please don't tell me what i was saying. > I'm not trying to do that - I'm sorry if it seemed that way. i know what talking past each other is. this wasn't it. >> he was using \1 in the >> replacement and i kept saying replacement. > > Yes. That is why I said you are talking past one another - yuo are each > saying things the other is not noticing. I was not criticising your perl > knowledge. > that is where we differ. i know i wasn't talking past him. i was saying what the docs said and about good style. it fell on deaf ears it appears. :/ uri From janes.rob at gmail.com Sun Oct 28 15:11:13 2012 From: janes.rob at gmail.com (Rob Janes) Date: Sun, 28 Oct 2012 18:11:13 -0400 Subject: [tpm] New Regex question - partially solved In-Reply-To: <1351459829.3583.49.camel@localhost.localdomain> References: <20121027224836.CD5091202DA@xx1.develooper.com> <508CAC10.7010509@stemsystems.com> <508D5729.9090005@stemsystems.com> <1351448540.3583.44.camel@localhost.localdomain> <508D9D1C.3050009@stemsystems.com> <1351459829.3583.49.camel@localhost.localdomain> Message-ID: perl is supposed to be a swiss army knife of things. that's actually what i like about it, it's very accepting, very canadian, very multicultural. I've been doing perl for quite some time now, and I can say very definitely from what I've seen, that using \1 instead of $1 is not going to cost anybody a perl job, if that's the job you want. Sure, if Uri's the interviewer you better be careful, but otherwise I've never seen anybody else really react about something like that. If you're doing perl, you're usually pretty accepting of different styles. There are few courses in perl at university so virtually all of us are self-taught. Python on the other hand - a lot of people come out of school with python, and there's a certain air about them and their use of python. same for c++ and java. people doing those languages are often big on style, and I've seen code reviews completely usurped by style issues with not one glance to functionality, passing the code on correcting spelling mistakes in the comments while leaving gaping holes in the logic. so ... and the last word award goes to .... On Sun, Oct 28, 2012 at 5:30 PM, Liam R E Quin wrote: > On Sun, 2012-10-28 at 17:01 -0400, Uri Guttman wrote: > > On 10/28/2012 02:22 PM, Liam R E Quin wrote: > \ > > > You're talking past one another, because Rob missed the word > > > "replacement" in the original note. I think Rob thought it was a > > > question about back-references, which indeed use \1 (or the extended > > > newer syntax). > > > > please don't tell me what i was saying. > I'm not trying to do that - I'm sorry if it seemed that way. > > he was using \1 in the > > replacement and i kept saying replacement. > > Yes. That is why I said you are talking past one another - yuo are each > saying things the other is not noticing. I was not criticising your perl > knowledge. > > Liam > > -- > Liam Quin - XML Activity Lead, W3C, http://www.w3.org/People/Quin/ > Pictures from old books: http://fromoldbooks.org/ > Co-author, 5th edition of 'Beginning XML', Wrox, July 2012 > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From arocker at Vex.Net Mon Oct 29 07:36:27 2012 From: arocker at Vex.Net (arocker at Vex.Net) Date: Mon, 29 Oct 2012 10:36:27 -0400 Subject: [tpm] New Regex question - partially solved In-Reply-To: References: <20121027224836.CD5091202DA@xx1.develooper.com> <508CAC10.7010509@stemsystems.com> <508D5729.9090005@stemsystems.com> <1351448540.3583.44.camel@localhost.localdomain> <508D9D1C.3050009@stemsystems.com> <1351459829.3583.49.camel@localhost.localdomain> Message-ID: > people doing those languages are often big on style, and I've seen code > reviews completely usurped by style issues with not one glance to > functionality, passing the code on correcting spelling mistakes in the > comments while leaving gaping holes in the logic. so ... > If we are going to discuss code reviews, may I offer the following http://www.jsquared.co.uk/jennyl/verity.htm example? From cj at enersave.ca Tue Oct 30 05:47:10 2012 From: cj at enersave.ca (Chris Jones) Date: Tue, 30 Oct 2012 08:47:10 -0400 Subject: [tpm] New Regex question In-Reply-To: References: <20121023183244.86B5811F190@xx1.develooper.com> <92FBEA54-D8B1-4A1E-BC7B-EE01FC218120@morungos.com> <20121027221915.9FFB911EF55@xx1.develooper.com> <508C6571.9050907@stemsystems.com> <508C6C9C.8000009@stemsystems.com> <20121028182335.A3EF211EB3D@xx1.develooper.com> Message-ID: <20121030165721.B929811EEB7@xx1.develooper.com> > > >You don't need \r\n ... \n is sufficient: > > "\n matches a logical newline. Perl converts between \n and your > OS's native newline character when reading from or writing to text > files." > 'Character Escapes' > in > http://perldoc.perl.org/perlrebackslash.html > >Also, do you want to wind up with either a space or a newline, >accidentally, depending on which one came first? > >Consider "line 1 \n \nline 3" collapsing into "line1 line 3" >compared to "line 1\n \nline 3" collapsing into "line1\nline 3" >just because of a trailing space. > Apparently Microsoft didn't inform Perl that the access database uses \r\n in the memo field. $exp =~ s/(\s|\n)\1+/$1/g; "Expression 1:","if(Local(TYPE) == 1) then 1.25 else UNCHANGED endif", "Expression 2:","if(Local(TYPE) == 1) then 1.25 else UNCHANGED endif" Adding the \r produces the desired output: s/(\s|\r\n)\1+/$1/g; "Expression 1:","if(Local(TYPE) == 1) then 1.25 else UNCHANGED endif", "Expression 2:","if(Local(TYPE) == 1) then 1.25 else UNCHANGED endif" >> Christopher Jones, P.Eng. Suite 1801, 1 Yonge Street Toronto, ON M5E1W7 Tel. 416-203-7465 Fax. 416-946-1005 email cj at enersave.ca -------------- next part -------------- An HTML attachment was scrubbed... URL: