From me at heyjay.com Wed Apr 6 21:28:02 2011 From: me at heyjay.com (Jay Strauss) Date: Wed, 6 Apr 2011 23:28:02 -0500 Subject: [Chicago-talk] Autosplit on windows Message-ID: Hi, I just thought I'd post this for the next person who needs it. I had a hard time getting the escaping correct when running on strawberry perl under windows. perl -na -F/"\|"/ -e "print $#F,\"\n\" " some_data_file.txt read a file, autosplit on '|', print the count of fields Jay keywords: autosplit windows M$ MSFT strawberry -------------- next part -------------- An HTML attachment was scrubbed... URL: From richard at rushlogistics.com Fri Apr 8 09:00:12 2011 From: richard at rushlogistics.com (Richard Reina) Date: Fri, 08 Apr 2011 12:00:12 -0400 (EDT) Subject: [Chicago-talk] sending images with Mime::Lite Message-ID: <20110408160012.830E375B@courageux.xo.com> I am trying to send an email with an image in the signature but when I do the image does not show up. Can anyone tell me what I am doing wrong? # create a new MIME Lite based email my $msg = MIME::Lite->new ( Subject => "HTML email test", >From => 'richard at rushlogistics.com', To => $email, Type => 'text/html', Data => 'Image should be here. Please visit our site online
' ); -- Richard Reina Rush Logistics, Inc. Watch our 3 minute movie: http://www.rushlogistics.com/movie From younda at gmail.com Fri Apr 8 09:06:34 2011 From: younda at gmail.com (David J. Young) Date: Fri, 8 Apr 2011 11:06:34 -0500 Subject: [Chicago-talk] sending images with Mime::Lite In-Reply-To: <20110408160012.830E375B@courageux.xo.com> References: <20110408160012.830E375B@courageux.xo.com> Message-ID: Probably needs to be an absolute URL, not relative. ydy On Fri, Apr 8, 2011 at 11:00 AM, Richard Reina wrote: > I am trying to send an email with an image in the signature but when I do > the image does not show up. Can anyone tell me what I am doing wrong? > > # create a new MIME Lite based email > my $msg = MIME::Lite->new > ( > Subject => "HTML email test", > From => 'richard at rushlogistics.com', > To => $email, > Type => 'text/html', > Data => 'Image should be
> here. > Please visit our site online
' > ); > -- > Richard Reina > Rush Logistics, Inc. > Watch our 3 minute movie: > http://www.rushlogistics.com/movie > > _______________________________________________ > Chicago-talk mailing list > Chicago-talk at pm.org > http://mail.pm.org/mailman/listinfo/chicago-talk > -- I take the "Shhhh" out of IT - ydy -------------- next part -------------- An HTML attachment was scrubbed... URL: From imranjj at gmail.com Fri Apr 8 09:09:50 2011 From: imranjj at gmail.com (imran javaid) Date: Fri, 8 Apr 2011 11:09:50 -0500 Subject: [Chicago-talk] sending images with Mime::Lite In-Reply-To: <20110408160012.830E375B@courageux.xo.com> References: <20110408160012.830E375B@courageux.xo.com> Message-ID: Try this (note the cid in the img src): my $msg = MIME::Lite->new( From => 'richard at rushlogistics.com', To => $email, Subject => "HTML email test", Type =>'multipart/related' ); my $gif = "/home/richard/gator_head.gif"; my $message = 'Image should be
here. Please visit our site online
'; $msg->attach( Type => 'text/html', Data => $message, ); $msg->attach( Type => 'image/gif', Id => basename($gif), Path => $gif, ); On Fri, Apr 8, 2011 at 11:00 AM, Richard Reina wrote: > I am trying to send an email with an image in the signature but when I do > the image does not show up. Can anyone tell me what I am doing wrong? > > # create a new MIME Lite based email > my $msg = MIME::Lite->new > ( > Subject => "HTML email test", > From => 'richard at rushlogistics.com', > To => $email, > Type => 'text/html', > Data => 'Image should be
> here. > Please visit our site online
' > ); > -- > Richard Reina > Rush Logistics, Inc. > Watch our 3 minute movie: > http://www.rushlogistics.com/movie > > _______________________________________________ > Chicago-talk mailing list > Chicago-talk at pm.org > http://mail.pm.org/mailman/listinfo/chicago-talk > -------------- next part -------------- An HTML attachment was scrubbed... URL: From richard at rushlogistics.com Fri Apr 8 09:13:27 2011 From: richard at rushlogistics.com (Richard Reina) Date: Fri, 08 Apr 2011 12:13:27 -0400 (EDT) Subject: [Chicago-talk] sending images with Mime::Lite In-Reply-To: <20110408160012.830E375B@courageux.xo.com> Message-ID: <20110408161328.03A0C378@victory.xo.com> Will give that a try. > > Thanks > > Chicago.pm chatter wrote: Probably needs to be an absolute URL, not relative. > > ydy > > > On Fri, Apr 8, 2011 at 11:00 AM, Richard Reina wrote: > I am trying to send an email with an image in the > signature but when I do the image does not show up. > ?Can anyone tell me what I am doing wrong? > > # create a new MIME Lite based email > my $msg = MIME::Lite->new > ( > Subject => "HTML email test", > From ? ?=> 'richard at rushlogistics.com', > To ? ? ?=> $email, > Type ? ?=> 'text/html', > Data ? ?=> ' alt="Image should be here."/> > Please visit our site online
' > ); > -- > Richard Reina > Rush Logistics, Inc. > Watch our 3 minute movie: > http://www.rushlogistics.com/movie > > _______________________________________________ > Chicago-talk mailing list > Chicago-talk at pm.org > http://mail.pm.org/mailman/listinfo/chicago-talk > > > -- > I take the "Shhhh" out of IT - ydy -- Richard Reina Rush Logistics, Inc. Watch our 3 -------------- next part -------------- An HTML attachment was scrubbed... URL: From richard at rushlogistics.com Wed Apr 13 14:09:19 2011 From: richard at rushlogistics.com (Richard Reina) Date: Wed, 13 Apr 2011 17:09:19 -0400 (EDT) Subject: [Chicago-talk] Mime::Lite HTML question Message-ID: <20110413210919.953EB200F@bellona.xo.com> I using the code below to try to get image in the signature of an email. It works but the the name of the image appears next to it. Does anyone know how I can get it to appear more embeded so that the name of the file does not appear? Thanks for any help. Richard #!/usr/bin/perl -w use strict; use MIME::Lite; # SendTo email id my $email = 'gatorreina at gmail.com'; my $msg = MIME::Lite->new( To =>$email, Subject =>'HTML with in-line image!', Type =>'multipart/related' ); $msg->attach( Type => 'text/html', Data => qq{ Here's my image: }, ); $msg->attach( Type => 'image/jpg', Id => 'gator_head.gif', Path => '/home/richard/gator_head.gif', ); $msg->send(); -- Richard Reina Rush Logistics, Inc. Watch our 3 minute movie: http://www.rushlogistics.com/movie From imranjj at gmail.com Wed Apr 13 14:30:05 2011 From: imranjj at gmail.com (imran javaid) Date: Wed, 13 Apr 2011 16:30:05 -0500 Subject: [Chicago-talk] Mime::Lite HTML question In-Reply-To: <20110413210919.953EB200F@bellona.xo.com> References: <20110413210919.953EB200F@bellona.xo.com> Message-ID: Can you try running it with the following changes? to save the gators and Type => 'image/jpg', to Type => 'image/gif', -imran On Wed, Apr 13, 2011 at 4:09 PM, Richard Reina wrote: > I using the code below to try to get image in the signature of an email. It > works but the the name of the image appears next to it. Does anyone know > how I can get it to appear more embeded so that the name of the file does > not appear? > > Thanks for any help. > > Richard > > #!/usr/bin/perl -w > use strict; > use MIME::Lite; > > # SendTo email id > my $email = 'gatorreina at gmail.com'; > > my $msg = MIME::Lite->new( > To =>$email, > Subject =>'HTML with in-line image!', > Type =>'multipart/related' > ); > $msg->attach( > Type => 'text/html', > Data => qq{ > > Here's my image: > > > }, > ); > $msg->attach( > Type => 'image/jpg', > Id => 'gator_head.gif', > Path => '/home/richard/gator_head.gif', > ); > $msg->send(); > > -- > Richard Reina > Rush Logistics, Inc. > Watch our 3 minute movie: > http://www.rushlogistics.com/movie > > _______________________________________________ > Chicago-talk mailing list > Chicago-talk at pm.org > http://mail.pm.org/mailman/listinfo/chicago-talk > -------------- next part -------------- An HTML attachment was scrubbed... URL: From imranjj at gmail.com Wed Apr 13 21:14:28 2011 From: imranjj at gmail.com (imran javaid) Date: Wed, 13 Apr 2011 23:14:28 -0500 Subject: [Chicago-talk] Mime::Lite HTML question In-Reply-To: References: <20110413210919.953EB200F@bellona.xo.com> Message-ID: I think the display of the email also depends on the email client. It appears perfectly in Outlook but not the way you want it in the gmail web interface. On Wed, Apr 13, 2011 at 4:30 PM, imran javaid wrote: > Can you try running it with the following changes? > > > to > save the gators > > and > Type => 'image/jpg', > to > Type => 'image/gif', > > -imran > > > On Wed, Apr 13, 2011 at 4:09 PM, Richard Reina wrote: > >> I using the code below to try to get image in the signature of an email. >> It works but the the name of the image appears next to it. Does anyone know >> how I can get it to appear more embeded so that the name of the file does >> not appear? >> >> Thanks for any help. >> >> Richard >> >> #!/usr/bin/perl -w >> use strict; >> use MIME::Lite; >> >> # SendTo email id >> my $email = 'gatorreina at gmail.com'; >> >> my $msg = MIME::Lite->new( >> To =>$email, >> Subject =>'HTML with in-line image!', >> Type =>'multipart/related' >> ); >> $msg->attach( >> Type => 'text/html', >> Data => qq{ >> >> Here's my image: >> >> >> }, >> ); >> $msg->attach( >> Type => 'image/jpg', >> Id => 'gator_head.gif', >> Path => '/home/richard/gator_head.gif', >> ); >> $msg->send(); >> >> -- >> Richard Reina >> Rush Logistics, Inc. >> Watch our 3 minute movie: >> http://www.rushlogistics.com/movie >> >> _______________________________________________ >> Chicago-talk mailing list >> Chicago-talk at pm.org >> http://mail.pm.org/mailman/listinfo/chicago-talk >> > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From me at heyjay.com Wed Apr 20 09:37:47 2011 From: me at heyjay.com (Jay Strauss) Date: Wed, 20 Apr 2011 11:37:47 -0500 Subject: [Chicago-talk] Performance issue Message-ID: Hi all, I have a csv file, with quoted strings (i.e. "field1","field2",...). The file is 3.5M records. I'm running strawberry perl on win7 (not that I think that's the issue). What I need to do is convert any embedded "|" to "-", convert the field delimiter ' "," ' to "|". I know there are cpan mods for parsing csv but my situation is pretty straight forward. I'm doing: use strict; while(<>) { $_ = substr $_, 1, -2; # Remove first and last ", and remove # the \n at the same time # s/\|/-/g; # Change embedded "|" into "-" my @words = split(/\",\"/,$_,-1); # split on the remaining "," print join("|", @words),"\n"; } But it's take what seems like a long time to run (like 15 mins). I'd think this would be an ideal use for Perl, and could rip through the file lickedy split. I'm I doing something costly in the script above that is making it run so slow? Thanks Jay -------------- next part -------------- An HTML attachment was scrubbed... URL: From tigerpeng2001 at yahoo.com Wed Apr 20 09:49:03 2011 From: tigerpeng2001 at yahoo.com (tiger peng) Date: Wed, 20 Apr 2011 09:49:03 -0700 (PDT) Subject: [Chicago-talk] Performance issue In-Reply-To: References: Message-ID: <404881.70551.qm@web120507.mail.ne1.yahoo.com> why split and join? try replace '","' with '|' directly. ________________________________ From: Jay Strauss To: Chicago.pm chatter Sent: Wed, April 20, 2011 11:37:47 AM Subject: [Chicago-talk] Performance issue Hi all, I have a csv file, with quoted strings (i.e. "field1","field2",...). The file is 3.5M records. I'm running strawberry perl on win7 (not that I think that's the issue). What I need to do is convert any embedded "|" to "-", convert the field delimiter ' "," ' to "|". I know there are cpan mods for parsing csv but my situation is pretty straight forward. I'm doing: use strict; while(<>) { $_ = substr $_, 1, -2; #Remove first and last ", and remove #the \n at the same time # s/\|/-/g; # Change embedded "|" into "-" my @words = split(/\",\"/,$_,-1);# split on the remaining "," print join("|", @words),"\n"; } But it's take what seems like a long time to run (like 15 mins). I'd think this would be an ideal use for Perl, and could rip through the file lickedy split. I'm I doing something costly in the script above that is making it run so slow? Thanks Jay -------------- next part -------------- An HTML attachment was scrubbed... URL: From warren.lindsey at gmail.com Wed Apr 20 10:03:53 2011 From: warren.lindsey at gmail.com (Warren Lindsey) Date: Wed, 20 Apr 2011 12:03:53 -0500 Subject: [Chicago-talk] Performance issue In-Reply-To: References: Message-ID: <77DD713F-34B6-498E-87D4-1E11DFF8CA48@gmail.com> I assume by your use of <> and print without a filehandle that you are going through pipes and reading from STDIN and writing to STDOUT. I suspect opening input and output file handles will be more efficient. Less data movement between buffers. Cheers, Warren On Apr 20, 2011, at 11:37 AM, Jay Strauss wrote: > Hi all, > > I have a csv file, with quoted strings (i.e. "field1","field2",...). The file is 3.5M records. I'm running strawberry perl on win7 (not that I think that's the issue). What I need to do is convert any embedded "|" to "-", convert the field delimiter ' "," ' to "|". I know there are cpan mods for parsing csv but my situation is pretty straight forward. I'm doing: > > use strict; > > while(<>) { > > $_ = substr $_, 1, -2; # Remove first and last ", and remove > # the \n at the same time > # > > s/\|/-/g; # Change embedded "|" into "-" > > my @words = split(/\",\"/,$_,-1); # split on the remaining "," > > print join("|", @words),"\n"; > } > > But it's take what seems like a long time to run (like 15 mins). I'd think this would be an ideal use for Perl, and could rip through the file lickedy split. > > I'm I doing something costly in the script above that is making it run so slow? > > Thanks > Jay > > _______________________________________________ > Chicago-talk mailing list > Chicago-talk at pm.org > http://mail.pm.org/mailman/listinfo/chicago-talk From andy at petdance.com Wed Apr 20 10:06:02 2011 From: andy at petdance.com (Andy Lester) Date: Wed, 20 Apr 2011 12:06:02 -0500 Subject: [Chicago-talk] Performance issue In-Reply-To: <77DD713F-34B6-498E-87D4-1E11DFF8CA48@gmail.com> References: <77DD713F-34B6-498E-87D4-1E11DFF8CA48@gmail.com> Message-ID: On Apr 20, 2011, at 12:03 PM, Warren Lindsey wrote: > I assume by your use of <> and print without a filehandle that you are going through pipes and reading from STDIN and writing to STDOUT. I suspect opening input and output file handles will be more efficient. Less data movement between buffers. First rule of optimization: Don't optimize without measuring first. I'd suggest running your program under Devel::NYTProf and finding out where all the time is being spent. xoa -- Andy Lester => andy at petdance.com => www.techworklove.com => AIM:petdance From me at heyjay.com Wed Apr 20 20:37:52 2011 From: me at heyjay.com (Jay Strauss) Date: Wed, 20 Apr 2011 22:37:52 -0500 Subject: [Chicago-talk] Performance issue In-Reply-To: <77DD713F-34B6-498E-87D4-1E11DFF8CA48@gmail.com> References: <77DD713F-34B6-498E-87D4-1E11DFF8CA48@gmail.com> Message-ID: I stopped using pipes, started using file handles, and things sped up nicely. Thanks Jay On Wed, Apr 20, 2011 at 12:03 PM, Warren Lindsey wrote: > I assume by your use of <> and print without a filehandle that you are > going through pipes and reading from STDIN and writing to STDOUT. I suspect > opening input and output file handles will be more efficient. Less data > movement between buffers. > > Cheers, > Warren > > On Apr 20, 2011, at 11:37 AM, Jay Strauss wrote: > > > Hi all, > > > > I have a csv file, with quoted strings (i.e. "field1","field2",...). The > file is 3.5M records. I'm running strawberry perl on win7 (not that I think > that's the issue). What I need to do is convert any embedded "|" to "-", > convert the field delimiter ' "," ' to "|". I know there are cpan mods for > parsing csv but my situation is pretty straight forward. I'm doing: > > > > use strict; > > > > while(<>) { > > > > $_ = substr $_, 1, -2; # Remove first and last ", and remove > > # the \n at the same time > > # > > > > s/\|/-/g; # Change embedded "|" into "-" > > > > my @words = split(/\",\"/,$_,-1); # split on the remaining > "," > > > > print join("|", @words),"\n"; > > } > > > > But it's take what seems like a long time to run (like 15 mins). I'd > think this would be an ideal use for Perl, and could rip through the file > lickedy split. > > > > I'm I doing something costly in the script above that is making it run so > slow? > > > > Thanks > > Jay > > > > _______________________________________________ > > Chicago-talk mailing list > > Chicago-talk at pm.org > > http://mail.pm.org/mailman/listinfo/chicago-talk > _______________________________________________ > Chicago-talk mailing list > Chicago-talk at pm.org > http://mail.pm.org/mailman/listinfo/chicago-talk > -------------- next part -------------- An HTML attachment was scrubbed... URL: From me at heyjay.com Wed Apr 20 20:42:56 2011 From: me at heyjay.com (Jay Strauss) Date: Wed, 20 Apr 2011 22:42:56 -0500 Subject: [Chicago-talk] Performance issue In-Reply-To: <404881.70551.qm@web120507.mail.ne1.yahoo.com> References: <404881.70551.qm@web120507.mail.ne1.yahoo.com> Message-ID: I was under the impression that regexs were slow. I changed to your suggestion. I think the real prob was using pipes Thank you Jay On Wed, Apr 20, 2011 at 11:49 AM, tiger peng wrote: > why split and join? try replace '","' with '|' directly. > > > ------------------------------ > *From:* Jay Strauss > *To:* Chicago.pm chatter > *Sent:* Wed, April 20, 2011 11:37:47 AM > *Subject:* [Chicago-talk] Performance issue > > Hi all, > > I have a csv file, with quoted strings (i.e. "field1","field2",...). The > file is 3.5M records. I'm running strawberry perl on win7 (not that I think > that's the issue). What I need to do is convert any embedded "|" to "-", > convert the field delimiter ' "," ' to "|". I know there are cpan mods for > parsing csv but my situation is pretty straight forward. I'm doing: > > use strict; > > while(<>) { > > $_ = substr $_, 1, -2; # Remove first and last ", and remove > # the \n at the same time > # > > s/\|/-/g; # Change embedded "|" into "-" > > my @words = split(/\",\"/,$_,-1); # split on the remaining "," > > print join("|", @words),"\n"; > } > > But it's take what seems like a long time to run (like 15 mins). I'd think > this would be an ideal use for Perl, and could rip through the file lickedy > split. > > I'm I doing something costly in the script above that is making it run so > slow? > > Thanks > Jay > > > _______________________________________________ > Chicago-talk mailing list > Chicago-talk at pm.org > http://mail.pm.org/mailman/listinfo/chicago-talk > -------------- next part -------------- An HTML attachment was scrubbed... URL: From lembark at wrkhors.com Thu Apr 21 06:30:11 2011 From: lembark at wrkhors.com (Steven Lembark) Date: Thu, 21 Apr 2011 09:30:11 -0400 Subject: [Chicago-talk] Performance issue In-Reply-To: References: <404881.70551.qm@web120507.mail.ne1.yahoo.com> Message-ID: <20110421093011.66de49bd.lembark_wrkhors.com@wrkhors.com> On Wed, 20 Apr 2011 22:42:56 -0500 Jay Strauss wrote: > I was under the impression that regexs were slow. In general replacing the contents of a string in-place will take much less time than using a regex to break up the string into an array and then paste the array back together. For example, stripping the closing quote with a regex should be quite fast: while( <> ) { s{^ \s*? " }{}x; # shortest match to the first quote s{ " \s* $}{}x; # shortest match to the end of line s{ [|] }{-}gx; # pipes to dashes s{ , }{|}gx; # commas to pipes # use the line here } should be about the fastest way you can perform the replacement. I'd suggest avoiding a "substr $x, -2" to strip the trailing quote since any minor change in the file format (e.g. the source providing ^M^J instead of just ^J for the line endings) will completely break the process. With the regex you always get everything after the final quote stripped. -- Steven Lembark 3646 Flora Pl Workhorse Computing St Louis, MO 63110 lembark at wrkhors.com +1 888 359 3508 From eviljoel at linux.com Thu Apr 21 08:08:03 2011 From: eviljoel at linux.com (eviljoel) Date: Thu, 21 Apr 2011 10:08:03 -0500 Subject: [Chicago-talk] BARcamp Chicago 2011 - July 9th & 10th - Save the Date Message-ID: Greetings, The sixth annual BARcamp Chicago "Unconference" will be held on July 9th & 10th at the community makerspace Pumping Station: One. BARcamp Chicago is a great place to learn new skills, network with the best of Chicago's tech community and maybe even get a head start on founding your own business. But unlike regular conferences, at BARcamp it is the attendees who hold the talks and run the activities. If you are a technology enthusiast and have a desire to teach or learn, BARcamp Chicago is an event you will not want to miss. Right now we are trying to get an idea of who is planning to attend this year. While registration is not required, if you are planning to attend we would appreciate it if you sign up on our EventBrite: http://barcampchicago.eventbrite.com/. If you would like more information about BARcamp Chicago, our website is http://www.barcampchicago.org/. If you would like to provide suggestions about what you want and don't want to see at this year's BARcamp, please do so at http://barcampchicago.uservoice.com/. Finally, if you are interested in helping plan BARcamp Chicago, please sign up on our planning list here: http://groups.google.com/group/barcamp-chicago/. BARcamp is only possible by generous contributions from sponsors. If your company is interested in sponsoring BARcamp Chicago, please e-mail Kevin at kharriss at barcampchicago.org. Hope to see you there, Joel Luellwitz From richard at rushlogistics.com Thu Apr 28 05:34:34 2011 From: richard at rushlogistics.com (Richard Reina) Date: Thu, 28 Apr 2011 08:34:34 -0400 (EDT) Subject: [Chicago-talk] Regex question Message-ID: <20110428123434.5F15426A8@alexander.xo.com> I have the code below that replaces the string "Hello," with a scalar $ES which consists of "Hello " . $persons_first_name ","; It works fine. However, what I can't figure out is how to make it also substitute a string that already has a first name after hello. For example, if finds Hello Kim, I want it to replace it with $ES. Sorry for my ignorance. Any help would be greatly appreciated. Thanks, Richard sub change_salutation { my ($ES) = @_; @ARGV = qw(L_FILE); $^I=""; while (<>) { $_ =~ s/Hello,/$ES/g; $print $_; } } # end of sub } } From MikeRaffety at earthlink.net Thu Apr 28 06:05:27 2011 From: MikeRaffety at earthlink.net (Mike Raffety) Date: Thu, 28 Apr 2011 08:05:27 -0500 Subject: [Chicago-talk] Regex question In-Reply-To: <20110428123434.5F15426A8@alexander.xo.com> References: <20110428123434.5F15426A8@alexander.xo.com> Message-ID: <4DB96617.80006@earthlink.net> Change the "Hello," to "Hello.*,", so it includes any characters between the salutation and the comma. Richard Reina wrote, On 4/28/2011 7:34 AM: > I have the code below that replaces the string "Hello," with a scalar $ES which consists of "Hello " . $persons_first_name ","; It works fine. However, what I can't figure out is how to make it also substitute a string that already has a first name after hello. For example, if finds Hello Kim, I want it to replace it with $ES. Sorry for my ignorance. Any help would be greatly appreciated. > > Thanks, > > Richard > > sub change_salutation { > > my ($ES) = @_; > > @ARGV = qw(L_FILE); > > $^I=""; > > while (<>) { > > $_ =~ s/Hello,/$ES/g; > $print $_; > > } > > } # end of sub > > > } > > > } > _______________________________________________ > Chicago-talk mailing list > Chicago-talk at pm.org > http://mail.pm.org/mailman/listinfo/chicago-talk > From kent at c2group.net Thu Apr 28 06:27:26 2011 From: kent at c2group.net (Kent Cowgill) Date: Thu, 28 Apr 2011 08:27:26 -0500 Subject: [Chicago-talk] Regex question In-Reply-To: <4DB96617.80006@earthlink.net> References: <20110428123434.5F15426A8@alexander.xo.com> <4DB96617.80006@earthlink.net> Message-ID: <6fa9e952161fb97fe0126058f1816758@pobox.com> Or perhaps, $_ =~ s/Hello(?:\s\w+)?,/$ES/g; So it optionally includes a space followed by a word, and doesn't bother to capture the grouping. On Thu, 28 Apr 2011 08:05:27 -0500, Mike Raffety wrote: > Change the "Hello," to "Hello.*,", so it includes any characters > between the salutation and the comma. > > Richard Reina wrote, On 4/28/2011 7:34 AM: >> I have the code below that replaces the string "Hello," with a >> scalar $ES which consists of "Hello " . $persons_first_name ","; It >> works fine. However, what I can't figure out is how to make it also >> substitute a string that already has a first name after hello. For >> example, if finds Hello Kim, I want it to replace it with $ES. Sorry >> for my ignorance. Any help would be greatly appreciated. >> >> Thanks, >> >> Richard >> >> sub change_salutation { >> >> my ($ES) = @_; >> >> @ARGV = qw(L_FILE); >> >> $^I=""; >> >> while (<>) { >> >> $_ =~ s/Hello,/$ES/g; >> $print $_; >> >> } >> >> } # end of sub >> >> >> } >> >> >> } >> _______________________________________________ >> Chicago-talk mailing list >> Chicago-talk at pm.org >> http://mail.pm.org/mailman/listinfo/chicago-talk >> > _______________________________________________ > Chicago-talk mailing list > Chicago-talk at pm.org > http://mail.pm.org/mailman/listinfo/chicago-talk -- Kent Cowgill kent at c2group.net http://kentcowgill.org/blog http://youtube.com/kcowgill http://kentcowgill.org/photos http://flickr.com/people/kcowgill From davidy at nationalcycle.com Thu Apr 28 06:09:11 2011 From: davidy at nationalcycle.com (David Young) Date: Thu, 28 Apr 2011 08:09:11 -0500 Subject: [Chicago-talk] Regex question In-Reply-To: <20110428123434.5F15426A8@alexander.xo.com> References: <20110428123434.5F15426A8@alexander.xo.com> Message-ID: Richard, $_ =~ s/Hello.*,/$ES/g should do the trick. To learn and/or test goto regextester.com. Here is your example: [image: re.jpg] ydy On Thu, Apr 28, 2011 at 7:34 AM, Richard Reina wrote: > I have the code below that replaces the string "Hello," with a scalar $ES > which consists of "Hello " . $persons_first_name ","; It works fine. > However, what I can't figure out is how to make it also substitute a string > that already has a first name after hello. For example, if finds Hello Kim, > I want it to replace it with $ES. Sorry for my ignorance. Any help would > be greatly appreciated. > > Thanks, > > Richard > > sub change_salutation { > > my ($ES) = @_; > > @ARGV = qw(L_FILE); > > $^I=""; > > while (<>) { > > $_ =~ s/Hello,/$ES/g; > $print $_; > > } > > } # end of sub > > > } > > > } > _______________________________________________ > Chicago-talk mailing list > Chicago-talk at pm.org > http://mail.pm.org/mailman/listinfo/chicago-talk > -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: image/jpeg Size: 42656 bytes Desc: not available URL: From richard at rushlogistics.com Thu Apr 28 07:27:24 2011 From: richard at rushlogistics.com (Richard Reina) Date: Thu, 28 Apr 2011 10:27:24 -0400 (EDT) Subject: [Chicago-talk] Regex question In-Reply-To: <20110428123434.5F15426A8@alexander.xo.com> Message-ID: <20110428142724.8707C302@victory.xo.com> This worked great. Thanks! ---- Chicago.pm chatter wrote: > > Change the "Hello," to "Hello.*,", so it includes any characters between > the salutation and the comma. > > Richard Reina wrote, On 4/28/2011 7:34 AM: > > I have the code below that replaces the string "Hello," with a scalar $ES which consists of "Hello " . $persons_first_name ","; It works fine. However, what I can't figure out is how to make it also substitute a string that already has a first name after hello. For example, if finds Hello Kim, I want it to replace it with $ES. Sorry for my ignorance. Any help would be greatly appreciated. > > > > Thanks, > > > > Richard > > > > sub change_salutation { > > > > my ($ES) = @_; > > > > @ARGV = qw(L_FILE); > > > > $^I=""; > > > > while (<>) { > > > > $_ =~ s/Hello,/$ES/g; > > $print $_; > > > > } > > > > } # end of sub > > > > > > } > > > > > > } > > _______________________________________________ > > Chicago-talk mailing list > > Chicago-talk at pm.org > > http://mail.pm.org/mailman/listinfo/chicago-talk > > > _______________________________________________ > Chicago-talk mailing list > Chicago-talk at pm.org > http://mail.pm.org/mailman/listinfo/chicago-talk > From scott.sexton at gmail.com Thu Apr 28 09:51:09 2011 From: scott.sexton at gmail.com (Scott Sexton) Date: Thu, 28 Apr 2011 11:51:09 -0500 Subject: [Chicago-talk] Regex question In-Reply-To: <20110428142724.8707C302@victory.xo.com> References: <20110428123434.5F15426A8@alexander.xo.com> <20110428142724.8707C302@victory.xo.com> Message-ID: You're actually going to want to use it with a ? in there: s/Hello.*,?/$ES/g; Otherwise it's greedy and will replace everything from Hello through the last comma instead of the first comma. ~Scott On Thu, Apr 28, 2011 at 9:27 AM, Richard Reina wrote: > > This worked great. > > Thanks! > > > ---- Chicago.pm chatter wrote: > > > > Change the "Hello," to "Hello.*,", so it includes any characters between > > the salutation and the comma. > > > > Richard Reina wrote, On 4/28/2011 7:34 AM: > > > I have the code below that replaces the string "Hello," with a scalar > $ES which consists of "Hello " . $persons_first_name ","; It works fine. > However, what I can't figure out is how to make it also substitute a string > that already has a first name after hello. For example, if finds Hello Kim, > I want it to replace it with $ES. Sorry for my ignorance. Any help would > be greatly appreciated. > > > > > > Thanks, > > > > > > Richard > > > > > > sub change_salutation { > > > > > > my ($ES) = @_; > > > > > > @ARGV = qw(L_FILE); > > > > > > $^I=""; > > > > > > while (<>) { > > > > > > $_ =~ s/Hello,/$ES/g; > > > $print $_; > > > > > > } > > > > > > } # end of sub > > > > > > > > > } > > > > > > > > > } > > > _______________________________________________ > > > Chicago-talk mailing list > > > Chicago-talk at pm.org > > > http://mail.pm.org/mailman/listinfo/chicago-talk > > > > > _______________________________________________ > > Chicago-talk mailing list > > Chicago-talk at pm.org > > http://mail.pm.org/mailman/listinfo/chicago-talk > > > _______________________________________________ > Chicago-talk mailing list > Chicago-talk at pm.org > http://mail.pm.org/mailman/listinfo/chicago-talk > -------------- next part -------------- An HTML attachment was scrubbed... URL: From kent at c2group.net Thu Apr 28 09:54:45 2011 From: kent at c2group.net (Kent Cowgill) Date: Thu, 28 Apr 2011 11:54:45 -0500 Subject: [Chicago-talk] Regex question In-Reply-To: References: <20110428123434.5F15426A8@alexander.xo.com> <20110428142724.8707C302@victory.xo.com> Message-ID: ITYM s/Hello.*?,/$ES/g; On Thu, 28 Apr 2011 11:51:09 -0500, Scott Sexton wrote: > You're actually going to want to use it with a ? in there: > > s/Hello.*,?/$ES/g; > > Otherwise it's greedy and will replace everything from Hello through > the last comma instead of the first comma. > > ~Scott > > On Thu, Apr 28, 2011 at 9:27 AM, Richard Reina wrote: > >> This worked great. >> >> Thanks! >> >> ---- Chicago.pm chatter wrote: >> > >> > Change the "Hello," to "Hello.*,", so it includes any characters >> between >> > the salutation and the comma. >> > >> > Richard Reina wrote, On 4/28/2011 7:34 AM: >> >>> > I have the code below that replaces the string "Hello," with a >> scalar $ES which consists of "Hello " . $persons_first_name ","; >> ?It works fine. ?However, what I can't figure out is how to make >> it also substitute a string that already has a first name after >> hello. ?For example, if finds Hello Kim, I want it to replace it >> with $ES. ?Sorry for my ignorance. ?Any help would be greatly >> appreciated. >> > > >> > > Thanks, >> > > >> > > Richard >> > > >> > > sub change_salutation { >> > > >> > > my ($ES) = @_; >> > > >> > > @ARGV = qw(L_FILE); >> > > >> > > $^I=""; >> > > >> > > while () { >> > > >> > > ? ? $_ =~ s/Hello,/$ES/g; >> > > ? ? $print $_; >> > > >> > > } >> > > >> > > } # end of sub >> > > >> > > >> > > } >> > > >> > > >> > > } >> > > _______________________________________________ >> > > Chicago-talk mailing list >> > > Chicago-talk at pm.org [2] >> > > http://mail.pm.org/mailman/listinfo/chicago-talk [3] >> > > >> > _______________________________________________ >> > Chicago-talk mailing list >> > Chicago-talk at pm.org [4] >> > http://mail.pm.org/mailman/listinfo/chicago-talk [5] >> > >> _______________________________________________ >> Chicago-talk mailing list >> Chicago-talk at pm.org [6] >> http://mail.pm.org/mailman/listinfo/chicago-talk [7] > > > > Links: > ------ > [1] mailto:chicago-talk at pm.org > [2] mailto:Chicago-talk at pm.org > [3] http://mail.pm.org/mailman/listinfo/chicago-talk > [4] mailto:Chicago-talk at pm.org > [5] http://mail.pm.org/mailman/listinfo/chicago-talk > [6] mailto:Chicago-talk at pm.org > [7] http://mail.pm.org/mailman/listinfo/chicago-talk > [8] mailto:richard at rushlogistics.com -- Kent Cowgill kent at c2group.net http://kentcowgill.org/blog http://youtube.com/kcowgill http://kentcowgill.org/photos http://flickr.com/people/kcowgill From Andy_Bach at wiwb.uscourts.gov Thu Apr 28 10:05:48 2011 From: Andy_Bach at wiwb.uscourts.gov (Andy_Bach at wiwb.uscourts.gov) Date: Thu, 28 Apr 2011 12:05:48 -0500 Subject: [Chicago-talk] Regex question In-Reply-To: References: <20110428123434.5F15426A8@alexander.xo.com> <20110428142724.8707C302@victory.xo.com> Message-ID: > You're actually going to want to use it with a ? in there: s/Hello.*,?/$ES/g; > Otherwise it's greedy and will replace everything from Hello through the last comma Maybe a typo but: s/Hello.*?,/$ES/g; the "?" modifies the '*', in the original it was saying "zero or one commas" - and you'd need to replace the "Hello " text too. the "/g" would mean there's possibly more than one "Hello ...." chunk in your letter? Another good idiom is to use the negative char class for the marker s/Hello\s+[^,]+,/Hello $ES,/; That is - "one or more of anything besides a comma" a ---------------------- Andy Bach Systems Mangler Internet: andy_bach at wiwb.uscourts.gov Voice: (608) 261-5738; Cell: (608) 658-1890 "All that I care to know is that a man is a human being --that is enough for me; he can't be any worse." Mark Twain (1835-1910) -------------- next part -------------- An HTML attachment was scrubbed... URL: From scott.sexton at gmail.com Thu Apr 28 10:09:47 2011 From: scott.sexton at gmail.com (Scott Sexton) Date: Thu, 28 Apr 2011 12:09:47 -0500 Subject: [Chicago-talk] Regex question In-Reply-To: References: <20110428123434.5F15426A8@alexander.xo.com> <20110428142724.8707C302@victory.xo.com> Message-ID: Oops yeah typo. I mean ? before the , s/Hello.*?,/$ES/g; On Thu, Apr 28, 2011 at 11:51 AM, Scott Sexton wrote: > You're actually going to want to use it with a ? in there: > > s/Hello.*,?/$ES/g; > > Otherwise it's greedy and will replace everything from Hello through the > last comma instead of the first comma. > > ~Scott > > > On Thu, Apr 28, 2011 at 9:27 AM, Richard Reina wrote: > >> >> This worked great. >> >> Thanks! >> >> >> ---- Chicago.pm chatter wrote: >> > >> > Change the "Hello," to "Hello.*,", so it includes any characters between >> > the salutation and the comma. >> > >> > Richard Reina wrote, On 4/28/2011 7:34 AM: >> > > I have the code below that replaces the string "Hello," with a scalar >> $ES which consists of "Hello " . $persons_first_name ","; It works fine. >> However, what I can't figure out is how to make it also substitute a string >> that already has a first name after hello. For example, if finds Hello Kim, >> I want it to replace it with $ES. Sorry for my ignorance. Any help would >> be greatly appreciated. >> > > >> > > Thanks, >> > > >> > > Richard >> > > >> > > sub change_salutation { >> > > >> > > my ($ES) = @_; >> > > >> > > @ARGV = qw(L_FILE); >> > > >> > > $^I=""; >> > > >> > > while (<>) { >> > > >> > > $_ =~ s/Hello,/$ES/g; >> > > $print $_; >> > > >> > > } >> > > >> > > } # end of sub >> > > >> > > >> > > } >> > > >> > > >> > > } >> > > _______________________________________________ >> > > Chicago-talk mailing list >> > > Chicago-talk at pm.org >> > > http://mail.pm.org/mailman/listinfo/chicago-talk >> > > >> > _______________________________________________ >> > Chicago-talk mailing list >> > Chicago-talk at pm.org >> > http://mail.pm.org/mailman/listinfo/chicago-talk >> > >> _______________________________________________ >> Chicago-talk mailing list >> Chicago-talk at pm.org >> http://mail.pm.org/mailman/listinfo/chicago-talk >> > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From richard at rushlogistics.com Thu Apr 28 10:18:38 2011 From: richard at rushlogistics.com (Richard Reina) Date: Thu, 28 Apr 2011 13:18:38 -0400 (EDT) Subject: [Chicago-talk] Regex question In-Reply-To: <20110428123434.5F15426A8@alexander.xo.com> <20110428142724.8707C302@victory.xo.com> Message-ID: <20110428171838.7CE763EFB@theseus.xo.com> Good to know. Thanks, I will add the ?. > > Chicago.pm chatter wrote: Oops yeah typo. I mean ? before the , > s/Hello.*?,/$ES/g; > > > On Thu, Apr 28, 2011 at 11:51 AM, Scott Sexton wrote: > You're actually going to want to use it with a ? > in there: > s/Hello.*,?/$ES/g; > Otherwise it's greedy and will replace everything > from Hello through the last comma instead of the first > comma. > ~Scott > > > > > On Thu, Apr 28, 2011 at 9:27 AM, Richard Reina wrote: > > This worked great. > > Thanks! > > > > ---- Chicago.pm chatter wrote: > > > > Change the "Hello," to "Hello.*,", so it includes > any characters between > > the salutation and the comma. > > > > Richard Reina wrote, On 4/28/2011 7:34 AM: > > > > I have the code below that replaces the string > "Hello," with a scalar $ES which consists of "Hello > " . $persons_first_name ","; ?It works fine. ?However, > what I can't figure out is how to make it also substitute > a string that already has a first name after hello. > ?For example, if finds Hello Kim, I want it to replace > it with $ES. ?Sorry for my ignorance. ?Any help would > be greatly appreciated. > > > > > > Thanks, > > > > > > Richard > > > > > > sub change_salutation { > > > > > > my ($ES) = @_; > > > > > > @ARGV = qw(L_FILE); > > > > > > $^I=""; > > > > > > while (<>) { > > > > > > ? ? $_ =~ s/Hello,/$ES/g; > > > ? ? $print $_; > > > > > > } > > > > > > } # end of sub > > > > > > > > > } > > > > > > > > > } > > > > Chicago-talk mailing list > > > Chicago-talk at pm.org > > > http://mail.pm.org/mailman/listinfo/chicago-talk > > > > > > Chicago-talk mailing list > > Chicago-talk at pm.org > > http://mail.pm.org/mailman/listinfo/chicago-talk > > > _______________________________________________ > Chicago-talk mailing list > Chicago-talk at pm.org > http://mail.pm.org/mailman/listinfo/chicago-talk -- Richard Reina Rush Logistics, Inc. Watch our 3 -------------- next part -------------- An HTML attachment was scrubbed... URL: From sean at blanton.com Thu Apr 28 14:00:36 2011 From: sean at blanton.com (Sean Blanton) Date: Thu, 28 Apr 2011 16:00:36 -0500 Subject: [Chicago-talk] undef and Moose types Message-ID: When you have a constructor and it fails, It's not common practice to return a "null" object. Perl modules usually return undef. However, in Moose, in a Moose role that I want to do this: has ssh => ( is => 'rw', isa => 'Net::SSH2', default => \&ssh_builder, lazy => 1, ); --- To use this within a class, I do this: my $ssh = $self->ssh; $log->warn("couldn't connect") unless defined $ssh; #-- this line for illustration --- So, I want to handle any errors such as when \&ssh_builder fails and returns 'undef', but what happens is that it crashes before the error handling code because 'undef' is not of type 'Net::SSH2'. So what I do to fix it is take out the 'isa => 'Net::SSH2',' from the definition of the 'ssh' attribute. Now I lose the advantage of having the type check in my development for the 99.99% of the time when there are no errors. It seems to me that 'undef' should be considered to be a member of every class, or better yet have an option to make it so. Is there another way of getting the advantages of the type checking and also handling exceptions like this? Thanks, Sean -------------- next part -------------- An HTML attachment was scrubbed... URL: From andrew at cleverdomain.org Fri Apr 29 06:37:39 2011 From: andrew at cleverdomain.org (Andrew Rodland) Date: Fri, 29 Apr 2011 09:37:39 -0400 Subject: [Chicago-talk] undef and Moose types Message-ID: <201104290937.39913.andrew@cleverdomain.org> On Thursday, April 28, 2011 05:00:36 PM Sean Blanton wrote: > When you have a constructor and it fails, It's not common practice to > return a "null" object. Perl modules usually return undef. > > However, in Moose, in a Moose role that I want to do this: > > has ssh => ( > is => 'rw', > isa => 'Net::SSH2', > default => \&ssh_builder, > lazy => 1, > ); > > --- > > To use this within a class, I do this: > > my $ssh = $self->ssh; > $log->warn("couldn't connect") unless defined $ssh; #-- this line for > illustration > > --- > > So, I want to handle any errors such as when \&ssh_builder fails and > returns 'undef', but what happens is that it crashes before the error > handling code because 'undef' is not of type 'Net::SSH2'. So what I do to > fix it is take out the 'isa => 'Net::SSH2',' from the definition of > the 'ssh' attribute. > > Now I lose the advantage of having the type check in my development for the > 99.99% of the time when there are no errors. It seems to me that 'undef' > should be considered to be a member of every class, or better yet have an > option to make it so. Is there another way of getting the advantages of > the type checking and also handling exceptions like this? > > Thanks, > Sean There's a parameterized type in the default Moose type library called "Maybe" that deals with this -- isa => "Maybe[Net::SSH2]" will allow in Net::SSH2 or undef -- you can read more in the Moose::Util::Typeconstraints. That really strikes me as wrong, though. An attribute initializer *should* die if the builder isn't able to provide the resource that the attribute is supposed to hold. If you want to provide error handling for ssh object lazybuild, then I'd consider writing a method that does something like sub ssh_safe { my $self = shift; return try { $self->ssh } catch { ... } } but that's just my first impression. Andrew From sean at blanton.com Fri Apr 29 09:38:13 2011 From: sean at blanton.com (Sean Blanton) Date: Fri, 29 Apr 2011 11:38:13 -0500 Subject: [Chicago-talk] undef and Moose types In-Reply-To: <201104290937.39913.andrew@cleverdomain.org> References: <201104290937.39913.andrew@cleverdomain.org> Message-ID: Yeah, the 'Maybe' works great, and thanks for pointing me to the doc. My ssh_builder looks like your safe_ssh, not sure what you meant. I have one &ssh_builder for all (86!) classes. If a new class wants an ssh connection, it consumes the 'SSH' role with the ssh attribute populated by &ssh_builder. I have one case where I'm connecting to a bunch of machines and if one machine is offline I absolutely want the script to keep going to process the other machines and not die. In other cases, I connect to one machine and if it can't connect, then there is no point in continuing and go ahead and die. (In fact, I'm frequently forking and threading off the connections in parallel now, but that's besides the point - I want to reserve the right to handle any exception elegantly.) So in my case, the consuming class, instead of the builder, needs to decide how to handle a bad ssh connection: die or handle it and propagate handling up the class hierarchy. Therefore the builder via the attribute needs to pass success or fail to the consuming class and not make it's own decision to die. And, I want as much of the common code as possible and all of the Net::SSH2 code to go into &ssh_builder. Finally, I get a lot of benefit from using this within the lazy build context. It simplifies use of ssh for the consuming class - just check to see if it has a value of undef (thanks now to 'Maybe') and if not, start using it. It provides great encapsulation and minimizes over all resources, because the program may end before needing to create some or all of the connections. Thanks Again, Sean On Fri, Apr 29, 2011 at 8:37 AM, Andrew Rodland wrote: > Moose::Util::Typeconstraints -------------- next part -------------- An HTML attachment was scrubbed... URL: From jon-chicagotalk at jrock.us Fri Apr 29 22:36:45 2011 From: jon-chicagotalk at jrock.us (Jonathan Rockway) Date: Sat, 30 Apr 2011 00:36:45 -0500 Subject: [Chicago-talk] undef and Moose types In-Reply-To: (Sean Blanton's message of "Fri, 29 Apr 2011 11:38:13 -0500") References: <201104290937.39913.andrew@cleverdomain.org> Message-ID: <87ei4kxpua.fsf@snowball2.jrock.us> * On Fri, Apr 29 2011, Sean Blanton wrote: > Yeah, the 'Maybe' works great, and thanks for pointing me to the doc. > > My ssh_builder looks like your safe_ssh, not sure what you meant.?I > have one &ssh_builder for all (86!) classes. If a new class wants an > ssh connection, it consumes the 'SSH' role with the ssh attribute > populated by &ssh_builder. This means you want dependency injection. Classes should *not* know how to build things that they have; that's the job for some other part of the program. Bread::Board is a Moose-based module for dependency injection. You can write something like this: use Bread::Board; my $c = container 'MyApp' as { service 'ssh' => ( class => 'Net::SSH', lifecycle => 'Singleton', # if you want the same # instance each time ); service 'LogInAndDeleteEverything' => ( class => 'MyApp::Action::LogInAndDeleteEverything', dependencies => [ depends_on('ssh') ], ); }; my $action = $c->resolve( service => 'LogInAndDeleteEverything' ); $action->execute; # everything is deleted Your MyApp::Action::LogInAndDeleteEverything would look something like: package MyApp::Action::LogInAndDeleteEverything; use Moose; has 'ssh' => ( is => 'ro', isa => 'Net::SSH', required => 1, ); sub execute { ... } Bread::Board also has support for type mapping, so theoretically there won't be much boilerplate even if you have 86 classes that all need the 'ssh' service. I haven't used this feature much, however. In addition to class injection, there is also block injection, where you can use a coderef to build the instance. Sometimes convenient. It's also worth noting that services can have parameters and that you can pass in args during "resolve", so if your code looked something like: has 'ssh' => ( ... as above ... ); has 'chdir_to' => ( ... ); Your service could be changed to: service 'LogInAndDeleteEverything' => ( # remind me never to use such # a long name for an example! class => 'MyApp::Action::LogInAndDeleteEverything', dependencies => [ depends_on('ssh') ], parameters => { chdir_to => { default => '/' } }, ); Then, if you want to delete /etc, you would say: my $action = $c->resolve( service => 'LogInAndDeleteEverything', parameters => { chdir_to => '/etc' }, ); $action->execute; # BAI. Anyway, Bread::Board is pretty simple and easy to hack on, so it should be possible to do what you want without making a mess. One more thing: you can make diagrams of your services and your dependencies: https://github.com/jrockway/BreadBoard/commit/83de2f946b0af5a129146a085abfc95173ed0130 Finally, I used Bread::Board::Service as an example in the README here: https://github.com/jrockway/graphviz-hasa Pretty! -- print just => another => perl => hacker => if $,=$"