[30036] in Perl-Users-Digest
Perl-Users Digest, Issue: 1279 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Feb 15 03:09:41 2008
Date: Fri, 15 Feb 2008 00:09:05 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Fri, 15 Feb 2008 Volume: 11 Number: 1279
Today's topics:
Re: A Gtk2 IRC Chat Client <zentara@highstream.net>
Any Idea why this code doesn't remove all the blank lin <wk1989@gmail.com>
Re: Any Idea why this code doesn't remove all the blank <someone@example.com>
Re: Any Idea why this code doesn't remove all the blank xhoster@gmail.com
Re: Any Idea why this code doesn't remove all the blank <uri@stemsystems.com>
Re: Any Idea why this code doesn't remove all the blank <m@rtij.nl.invlalid>
Re: Fast checksums? <usenet@davidfilmer.com>
new CPAN modules on Fri Feb 15 2008 (Randal Schwartz)
perl 5.8, utf8 and DBI <stoupa@practisoft.cz>
Re: question about "requiring" linux/stat.ph <szrRE@szromanMO.comVE>
Re: question about "requiring" linux/stat.ph <ben@morrow.me.uk>
Re: Question to format <bol@adv.magwien.gv.at>
View life as a continuous learning experience. <grazzy.cool@gmail.com>
Re: www::mechanize for windows 2k using ActiveState Per <glex_no-spam@qwest-spam-no.invalid>
Re: www::mechanize for windows 2k using ActiveState Per <ben@morrow.me.uk>
Re: XML::Parser Q: The Char handler always returns '1' <mittra@juno.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Thu, 14 Feb 2008 13:39:37 -0500
From: zentara <zentara@highstream.net>
Subject: Re: A Gtk2 IRC Chat Client
Message-Id: <hg29r3h42u9r6anje22pv2il065e00ptie@4ax.com>
On Wed, 13 Feb 2008 20:43:10 -0800 (PST), deadpickle
<deadpickle@gmail.com> wrote:
>On Feb 12, 10:06 am, Ben Morrow <b...@morrow.me.uk> wrote:
>> Quoth deadpickle <deadpic...@gmail.com>:
>Yep your both right. Adding sysread corrected the problem and now I
>have another question. I am trying to complete the IRC Client with
>giving the user the ability to disconnect and reconnect to the IRC
>server. The problem I am encountering is that when the user
>disconnects the Glib::IO tries to read from the closed socket. I tried
>to undefine the Glib::IO but that hasent work.
Without messing with your code, I can tell you what you need to do.
You need to stop the current connection, then reconnect. There are
a couple of ways to do it. It is probably best to have a disconnect and
connect subs.
But basically you need to return false from your io callback and close
the socket.
Usually, you would do it something like
sub disconnect{
Gtk2::Helper->remove_watch( $sock );
close $sock;
#here you would reenable the Connect button,
#and do miscelaneous clean-up
#the reconnect again with a fresh socket
#and GLIB::IO watch on the new $sock.
# would be done in the "connect sub".
return 0;
}
zentara
--
I'm not really a human, but I play one on earth.
http://zentara.net/japh.html
------------------------------
Date: Thu, 14 Feb 2008 13:09:08 -0800 (PST)
From: Jack Wang <wk1989@gmail.com>
Subject: Any Idea why this code doesn't remove all the blank lines?
Message-Id: <c1c921a4-b6de-43bf-aff9-213ea7a22442@e10g2000prf.googlegroups.com>
This is the code I've written so far.
#!/usr/bin/perl
my $result = "";
while (<>){
if (/---START---/../--END\s---/){
$result.=$_;
}
}
$text="";
$result=~m/^---START---(.*)--END\s---$/s;
$text.=$1;
$text =~ s/\n+/\n/g;
print $text;
This is the text that it should handle (shortened, ........ represents
more data).
---START---
1342A 1O B10/B11
1003 1O B45/Z46
1094 1O F39/F40
1416 1O G37/G38
1007 1O Z33/A34
.........................
............................
............................
....stuff here..........
....................
4105 4L F31/F32
......................
.....................
--END ---
I want to extract the data betweeen ---START--- and --END ---,
removing any blanklines. However, the above mentioned program would
outputs everything correctly except it leaves a blank line at the top
and I can't figure out why. Thanks for any help!
------------------------------
Date: Thu, 14 Feb 2008 21:20:46 GMT
From: "John W. Krahn" <someone@example.com>
Subject: Re: Any Idea why this code doesn't remove all the blank lines?
Message-Id: <Og2tj.14229$FO1.14131@edtnps82>
Jack Wang wrote:
> This is the code I've written so far.
>
> #!/usr/bin/perl
use warnings;
use strict;
> my $result = "";
> while (<>){
> if (/---START---/../--END\s---/){
next unless /\S/;
next if /---START---/ || /--END\s---/;
> $result.=$_;
> }
> }
> $text="";
> $result=~m/^---START---(.*)--END\s---$/s;
> $text.=$1;
> $text =~ s/\n+/\n/g;
> print $text;
John
--
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order. -- Larry Wall
------------------------------
Date: 14 Feb 2008 21:41:21 GMT
From: xhoster@gmail.com
Subject: Re: Any Idea why this code doesn't remove all the blank lines?
Message-Id: <20080214164124.316$Db@newsreader.com>
Jack Wang <wk1989@gmail.com> wrote:
> $result=~m/^---START---(.*)--END\s---$/s;
> $text.=$1;
> $text =~ s/\n+/\n/g;
...
> However, the above mentioned program would
> outputs everything correctly except it leaves a blank line at the top
> and I can't figure out why. Thanks for any help!
You get a blank line either when there are two \n in a row, or when
the string has a single \n at the beginning. Your regex captures one,
but not the other.
Either don't capture them in the first place:
$result=~m/^---START---\n*(.*)--END\s---$/s;
Or remove it particularly:
$text =~ s/\n+/\n/g;
$text =~ s/^\n+//;
Xho
--
-------------------- http://NewsReader.Com/ --------------------
The costs of publication of this article were defrayed in part by the
payment of page charges. This article must therefore be hereby marked
advertisement in accordance with 18 U.S.C. Section 1734 solely to indicate
this fact.
------------------------------
Date: Thu, 14 Feb 2008 21:43:46 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Any Idea why this code doesn't remove all the blank lines?
Message-Id: <x7ir0r9pta.fsf@mail.sysarch.com>
>>>>> "JWK" == John W Krahn <someone@example.com> writes:
JWK> Jack Wang wrote:
>> This is the code I've written so far.
>> #!/usr/bin/perl
JWK> use warnings;
JWK> use strict;
>> my $result = "";
>> while (<>){
>> if (/---START---/../--END\s---/){
JWK> next unless /\S/;
JWK> next if /---START---/ || /--END\s---/;
you can use the return value of .. to eliminate the redundancy of those
regexes:
if ( my $range_num = /---START---/ .. /--END\s---/ ) {
next if $range_num == 1 || $range_num =~ /e/i ;
}
i would even drop the block:
my $range_num = /---START---/ .. /--END\s---/ ) {
next unless $range_num ;
next if $range_num == 1 || $range_num =~ /e/i ;
next unless /\S/ ;
but my favorite way is so much faster and shorter (untested):
use File::Slurp ;
my $text = read_file( \*STDIN ) ;
while( my( $result ) = $text =~ m/^---START---(.+)--END\s---$/msg ) {
# do newline and other cleanup here
$result =~ tr/\n//s ;
print $result ;
}
can't get much simpler than that.
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.sysarch.com --
----- Perl Architecture, Development, Training, Support, Code Review ------
----------- Search or Offer Perl Jobs ----- http://jobs.perl.org ---------
--------- Gourmet Hot Cocoa Mix ---- http://bestfriendscocoa.com ---------
------------------------------
Date: Thu, 14 Feb 2008 22:47:34 +0100
From: Martijn Lievaart <m@rtij.nl.invlalid>
Subject: Re: Any Idea why this code doesn't remove all the blank lines?
Message-Id: <pan.2008.02.14.21.47.33@rtij.nl.invlalid>
On Thu, 14 Feb 2008 13:09:08 -0800, Jack Wang wrote:
> I want to extract the data betweeen ---START--- and --END ---,
> removing any blanklines. However, the above mentioned program would
> outputs everything correctly except it leaves a blank line at the top
> and I can't figure out why. Thanks for any help!
Because you ask it to?
Your problem can be shortened to:
$ perl -e '$t="\ntest\n\ntest\n"; $t=~ s/^\n+/\n/g; print "t=$t\n"'
This does exactly the same thing, it leaves the first empty line. Why?
Because you replace the newline there wit a newline.
Try:
$ perl -e '$t="\ntest\n\ntest\n"; $t=~ s/\n+/x/g; print "t=$t\n"'
And you'll see what I mean.
You probably want to add:
$text =~ s/^\n//;
to achieve what you want.
Some stylistic issues:
> #!/usr/bin/perl
use strict;
use warnings;
> my $result = "";
> while (<>){
> if (/---START---/../--END\s---/){
> $result.=$_;
> }
> }
Indentation helps for readability.
> $text="";
> $result=~m/^---START---(.*)--END\s---$/s;
> $text.=$1;
Useless use of concatenation, Change to:
$result=~m/^---START---(.*)--END\s---$/s;
my $text = $1;
> $text =~ s/\n+/\n/g;
> print $text;
HTH,
M4
------------------------------
Date: Thu, 14 Feb 2008 13:34:06 -0800
From: David Filmer <usenet@davidfilmer.com>
Subject: Re: Fast checksums?
Message-Id: <0IydnVBPOvYTLina4p2dnAA@giganews.com>
Abigail wrote:
> The OP *is* aware of the existance of rsync, as he mentioned it in his
> paragraph, including the reason he cannot use it:
Oops, you're right. My bad; I should have read more closely.
------------------------------
Date: Fri, 15 Feb 2008 05:42:17 GMT
From: merlyn@stonehenge.com (Randal Schwartz)
Subject: new CPAN modules on Fri Feb 15 2008
Message-Id: <Jw9MIH.13or@zorch.sf-bay.org>
The following modules have recently been added to or updated in the
Comprehensive Perl Archive Network (CPAN). You can install them using the
instructions in the 'perlmodinstall' page included with your Perl
distribution.
ASNMTAP-3.000016001
http://search.cpan.org/~asnmtap/ASNMTAP-3.000016001/
----
Amazon-SQS-Simple-0.7
http://search.cpan.org/~swhitaker/Amazon-SQS-Simple-0.7/
OO API for accessing the Amazon Simple Queue Service
----
Catalyst-Plugin-CookiedSession-0.32
http://search.cpan.org/~lbrocard/Catalyst-Plugin-CookiedSession-0.32/
Store sessions in a browser cookie
----
Config-Model-0.618
http://search.cpan.org/~ddumont/Config-Model-0.618/
Model to create configuration validation tool
----
Data-Validate-XSD-1.05
http://search.cpan.org/~doctormo/Data-Validate-XSD-1.05/
Validate complex structures by definition
----
Egg-Release-DBIC-0.01
http://search.cpan.org/~lushe/Egg-Release-DBIC-0.01/
Package kit to use DBIx::Class.
----
Email-Fingerprint-0.19
http://search.cpan.org/~budney/Email-Fingerprint-0.19/
Calculate a digest for recognizing duplicate emails
----
JSON-RPC-0.92
http://search.cpan.org/~makamaka/JSON-RPC-0.92/
Perl implementation of JSON-RPC 1.1 protocol
----
LoadHtml-7.04
http://search.cpan.org/~turnerjw/LoadHtml-7.04/
----
Mac-Pasteboard-0.000_03
http://search.cpan.org/~wyant/Mac-Pasteboard-0.000_03/
Manipulate Mac OS X clipboards/pasteboards.
----
Net-SSLeay-1.33_01
http://search.cpan.org/~flora/Net-SSLeay-1.33_01/
Perl extension for using OpenSSL
----
ONTO-PERL-1.11
http://search.cpan.org/~easr/ONTO-PERL-1.11/
----
POE-Component-Server-AsyncEndpoint-0.02
http://search.cpan.org/~aimass/POE-Component-Server-AsyncEndpoint-0.02/
Asynchronous Endpoint Server for EAI
----
POEIKC-0.00_00
http://search.cpan.org/~suzuki/POEIKC-0.00_00/
----
RT-Authen-PAUSE-0.02
http://search.cpan.org/~ruz/RT-Authen-PAUSE-0.02/
authenticate RT users against PAUSE
----
RT-Extension-SLA-0.01
http://search.cpan.org/~ruz/RT-Extension-SLA-0.01/
Service Level Agreements for RT
----
SOAP-WSDL-2.00_32
http://search.cpan.org/~mkutter/SOAP-WSDL-2.00_32/
SOAP with WSDL support
----
Socket-GetAddrInfo-0.08_7
http://search.cpan.org/~pevans/Socket-GetAddrInfo-0.08_7/
RFC 2553's getaddrinfo and getnameinfo functions.
----
Sub-Uplevel-0.19
http://search.cpan.org/~dagolden/Sub-Uplevel-0.19/
apparently run a function in a higher stack frame
----
Thread-Semaphore-2.02
http://search.cpan.org/~jdhedden/Thread-Semaphore-2.02/
Thread-safe semaphores
----
WikiText-0.07
http://search.cpan.org/~ingy/WikiText-0.07/
Wiki Text Conversion Tools
----
WikiText-Socialtext-0.06
http://search.cpan.org/~ingy/WikiText-Socialtext-0.06/
Socialtext WikiText Module
----
WikiText-Socialtext-0.07
http://search.cpan.org/~ingy/WikiText-Socialtext-0.07/
Socialtext WikiText Module
----
perfSONAR_PS-Base-0.07
http://search.cpan.org/~perfsonar/perfSONAR_PS-Base-0.07/
If you're an author of one of these modules, please submit a detailed
announcement to comp.lang.perl.announce, and we'll pass it along.
This message was generated by a Perl program described in my Linux
Magazine column, which can be found on-line (along with more than
200 other freely available past column articles) at
http://www.stonehenge.com/merlyn/LinuxMag/col82.html
print "Just another Perl hacker," # the original
--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
------------------------------
Date: Thu, 14 Feb 2008 18:32:29 +0100
From: "Petr Vileta" <stoupa@practisoft.cz>
Subject: perl 5.8, utf8 and DBI
Message-Id: <fp1u1i$6f9$1@ns.felk.cvut.cz>
At first I must say I'm Perl5.6.1 user ;-)
I'm reading some web pages coded in windows-1250 codepage and I store content
into MySQL table with utf-8 charset. Under Windows and Perl 5.6.1 all work as
expected, but I put my script to Linux hosting where Perl 5.8.x is running and
I got bad data in MySQL.
My main concept is this
#!/usr/bin/perl
use strict;
use LWP::UserAgent;
use Unicode::Lite;
use DBI;
require utf8 if($] > 5.006.001);
# ...
my $content = readweb($url); # content is in CP1250
$content = convert('CP1250', 'UTF8', $content) if($] > 5.006.001); # if Perl
5.8
# do something with $content and store part to $data
# ...
$data = convert(''CP1250', 'UTF8', $data) if($] <= 5.006.001); # if Perl 5.6
my $sth=$dbh->prepare("INSERT INTO test SET myfield=?");
$sth->execute($data) or die "Can't store";
$sth->finish;
What I do wrong? Please can anybody help me?
--
Petr Vileta, Czech republic
(My server rejects all messages from Yahoo and Hotmail. Send me your mail from
another non-spammer site please.)
Please reply to <petr AT practisoft DOT cz>
------------------------------
Date: Thu, 14 Feb 2008 09:10:56 -0800
From: "szr" <szrRE@szromanMO.comVE>
Subject: Re: question about "requiring" linux/stat.ph
Message-Id: <fp1sn101rv5@news2.newsguy.com>
John W. Krahn wrote:
> szr wrote:
>> Hello. I am wrapping up a rather large server migration job I was
>> tasked with. Everything is running wonderfully.
>>
>> One thing I noticed in a few legacy Perl scripts that had
>> <code>require "linux/stat.ph";</code> near the top and making use of
>> functions like S_ISLNK, resulting in this sort of error, which can
>> be easily reproduced:
>>
>> $ perl -e 'require "linux/stat.ph"; &S_ISLNK'
>> Undefined subroutine &main::S_ISLNK called at -e line 1.
>
> Change:
>
> require "linux/stat.ph";
>
> To:
>
> use Fcntl;
>
>
> perldoc -f stat
> [ SNIP ]
> You can import symbolic mode constants ("S_IF*") and functions
> ("S_IS*") from the Fcntl module:
>
Thanks.
use Fcntl ':mode';
did the trick :)
--
szr
------------------------------
Date: Thu, 14 Feb 2008 23:59:10 +0000
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: question about "requiring" linux/stat.ph
Message-Id: <e71f85-134.ln1@osiris.mauzo.dyndns.org>
Quoth "szr" <szrRE@szromanMO.comVE>:
> Hello. I am wrapping up a rather large server migration job I was tasked
> with. Everything is running wonderfully.
>
> One thing I noticed in a few legacy Perl scripts that had <code>require
> "linux/stat.ph";</code> near the top and making use of functions like
> S_ISLNK, resulting in this sort of error, which can be easily
> reproduced:
>
> $ perl -e 'require "linux/stat.ph"; &S_ISLNK'
> Undefined subroutine &main::S_ISLNK called at -e line 1.
You should be importing these constants from Fcntl with non-ancient
versions of Perl. h2ph can't always cope with the complicated
conditional definitions in Linux' system headers, so sometimes the
generated .ph files are not useable.
perl -MFcntl=:mode -le'print S_ISLNK(S_IFLNK)'
Generally speaking you can just use -l instead, though.
Ben
------------------------------
Date: Fri, 15 Feb 2008 08:29:36 +0100
From: "Ferry Bolhar" <bol@adv.magwien.gv.at>
Subject: Re: Question to format
Message-Id: <1203060577.570717@proxy.dienste.wien.at>
John W. Krahn:
>> What is the required format picture to get values
>> in the range "00" - "99"?`
>
> format =
> @>
> sprintf( '%02d', $data )
> .
Great solution, many thanks! So I'd guess there is no
native format pattern to accomplish this?
Ferry,
--
Ing Ferry Bolhar
Magistrat der Stadt Wien - MA 14
A-1010 Wien
E-Mail: ferdinand.bolhar-nordenkampf@wien.gv.at
------------------------------
Date: Thu, 14 Feb 2008 23:56:01 -0800 (PST)
From: "grazzy.cool@gmail.com" <grazzy.cool@gmail.com>
Subject: View life as a continuous learning experience.
Message-Id: <97f474c5-65fa-4852-a1df-406db6d6cff4@e6g2000prf.googlegroups.com>
View life as a continuous learning experience.
http://smallbusinessebooks.googlepages.com/
http://smallbusiness-ebooks.blogspot.com/
------------------------------
Date: Thu, 14 Feb 2008 10:48:31 -0600
From: "J. Gleixner" <glex_no-spam@qwest-spam-no.invalid>
Subject: Re: www::mechanize for windows 2k using ActiveState Perl v 5.8.0
Message-Id: <47b470e0$0$503$815e3792@news.qwest.net>
Yogi wrote:
> On Feb 14, 3:14 pm, Yogi <yogeshkagra...@gmail.com> wrote:
>> Hi,
>> I have been struggling to use www::mechanize for one of my script.
>> The version of activestate perl i have (v5.8.0) does not provide
>> www::mechanize as standard distribution. [...]
>
> Hi Guys,
> I got the answer to my question. Got nmake utility from "http://
> download.microsoft.com/download/vc15/Patch/1.52/W95/EN-US/Nmake15.exe"
> and also figured out how to use CPAN modules.
> http://www.perlmonks.org/?node_id=434813
Might also want to take the time now to upgrade to a more
recent version. 5.8.0 had a few bugs that were resolved
in later releases.
------------------------------
Date: Fri, 15 Feb 2008 00:01:19 +0000
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: www::mechanize for windows 2k using ActiveState Perl v 5.8.0
Message-Id: <fb1f85-134.ln1@osiris.mauzo.dyndns.org>
Quoth Yogi <yogeshkagrawal@gmail.com>:
> Hi,
> I have been struggling to use www::mechanize for one of my script.
> The version of activestate perl i have (v5.8.0) does not provide
> www::mechanize as standard distribution. I read in some of the links
> that I will have to download "WWW-Mechanize-1.34.tar.gz" from CPAN and
> then install it in my machine. While doing the process, there are
> certain steps like:
<snip>
When using ActivePerl, it is usually easier to install modules using ppm
than directly from CPAN. Apart from anything else, some modules require
a C compiler to build, and you probably don't have MSVC. Newer versions
of ppm have a rather nice GUI; older version only have a command-line
interface; see the documentation installed in c:\perl\html.
Ben
------------------------------
Date: Thu, 14 Feb 2008 10:43:04 -0800 (PST)
From: Swapnajit Mitra <mittra@juno.com>
Subject: Re: XML::Parser Q: The Char handler always returns '1'
Message-Id: <6c1d926b-e49d-4742-92ec-d2870e428f9f@e6g2000prf.googlegroups.com>
Jim,
I finally made it work. It was a mistake that I had made in parsing
the $data variable (as you correctly suspected).
Thanks for your help.
------------------------------
Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>
Administrivia:
#The Perl-Users Digest is a retransmission of the USENET newsgroup
#comp.lang.perl.misc. For subscription or unsubscription requests, send
#the single line:
#
# subscribe perl-users
#or:
# unsubscribe perl-users
#
#to almanac@ruby.oce.orst.edu.
NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
#To request back copies (available for a week or so), send your request
#to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
#where x is the volume number and y is the issue number.
#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V11 Issue 1279
***************************************