[30972] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 2217 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Feb 18 03:09:47 2009

Date: Wed, 18 Feb 2009 00:09:09 -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           Wed, 18 Feb 2009     Volume: 11 Number: 2217

Today's topics:
    Re: FAQ 6.11 How do I use a regular expression to strip sln@netherlands.com
    Re: FAQ 6.11 How do I use a regular expression to strip sln@netherlands.com
    Re: FAQ 6.14 How do I process each word on each line? <larry@example.invalid>
    Re: FAQ 6.14 How do I process each word on each line? <tim@burlyhost.com>
    Re: FAQ 6.14 How do I process each word on each line? sln@netherlands.com
    Re: FAQ 6.14 How do I process each word on each line? <larry@example.invalid>
    Re: how do I print the name and value of a scalar <RedGrittyBrick@spamweary.invalid>
    Re: how do I print the name and value of a scalar <jay-1941-@hotmail.com>
    Re: Net::SSH2 scp_put not working! <schaitan@gmail.com>
        new CPAN modules on Wed Feb 18 2009 (Randal Schwartz)
    Re: Read/write with UCS-2* encodings - Possible??? <ben@morrow.me.uk>
    Re: Read/write with UCS-2* encodings - Possible??? <hjp-usenet2@hjp.at>
    Re: Read/write with UCS-2* encodings - Possible??? <perl@marc-s.de>
        Resolving Quantifiers of Sub-Expression Quantifiers:  i sln@netherlands.com
        Undefined subroutine &main::param called paul.hopgood@deathnotify.com
    Re: Undefined subroutine &main::param called <schaitan@gmail.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: Tue, 17 Feb 2009 21:18:31 GMT
From: sln@netherlands.com
Subject: Re: FAQ 6.11 How do I use a regular expression to strip C style comments from a file?
Message-Id: <hd9mp45nkj34dtm8qupq2dhc37f9dg2aai@4ax.com>

On Mon, 16 Feb 2009 12:03:01 -0800, PerlFAQ Server <brian@stonehenge.com> wrote:

[snip FAQ header]
faq>
faq>6.11: How do I use a regular expression to strip C style comments from a file?
faq>
faq>    While this actually can be done, it's much harder than you'd think. For
faq>    example, this one-liner
faq>
faq>            perl -0777 -pe 's{/\*.*?\*/}{}gs' foo.c
faq>
faq>    will work in many but not all cases. You see, it's too simple-minded for
faq>    certain kinds of C programs, in particular, those with what appear to be
faq>    comments in quoted strings. For that, you'd need something like this,
faq>    created by Jeffrey Friedl and later modified by Fred Curtis.
faq>
faq>            $/ = undef;
faq>            $_ = <>;
faq>            s#/\*[^*]*\*+([^/*][^*]*\*+)*/|("(\\.|[^"\\])*"|'(\\.|[^'\\])*'|.[^/"'\\]*)#defined $2 ? $2 : ""#gse;
faq>            print;
faq>
[snip /x expansion]

faq>    A slight modification also removes C++ comments, as long as they are not
faq>    spread over multiple lines using a continuation character):
faq>
faq>            s#/\*[^*]*\*+([^/*][^*]*\*+)*/|//[^\n]*|("(\\.|[^"\\])*"|'(\\.|[^'\\])*'|.[^/"'\\]*)#defined $2 ? $2 : ""#gse;
                                               ^^^^^^^^                                              ^^^^^^^^^^^^^^^
                                         //([^\\]|[^\n][\n]?)*?\n                                    defined $3 ? $3

With another slight modification, C++ comments can be removed even if they span lines via continuation character(s) '\';
If you find a case where it doesen't work, let me know.

-sln

------------------------------------

## Cpp_Comment_Regex.pl
## ====================
## C++ style comments regex that
## works with or without (and even/odd number of)
## line continuation's.
## ---------------------------------------------------
## To be used in larger regex that
## understands C style /**/ priority
## and quoted syntax.
##
## -sln (if questions)
##
## Matching:
##
##     #//([^\\]|[^\n][\n]?)*?\n#gs;
##
##  or  #//(?:[^\\]|[^\n][\n]?)*?\n#gs;
##
##  or {
##       //    ##  Start of //... comment
##       (
##           [^\\]       ## Any Non-Continuation character ^\
##         |             ##   OR
##           [^\n][\n]?  ## Any Continuation character \ followed by 0-1 newline \n
##                     
##       )*?             ## To be done 0-many times, stopping at the first end of comment
##                   
##       \n    ##  End of //... comment
##     }gxs;
##

use strict;
use warnings;

my $Rx = qr!(//([^\\]|[^\n][\n]?)*?)\n!;

$_ = join '',<DATA>;

while ( /$Rx/sg ) { print "\n-->'$1'\n" } 

print "\nDone !!!\n";

__DATA__

///
// This comment is sdfg\continued here-> \\
this is the second line continued\

Should not see this 

No comment here

// Yes here is a comment
but not here

// Another comment  odd\\\
another continued even\\
another last




------------------------------

Date: Tue, 17 Feb 2009 22:06:53 GMT
From: sln@netherlands.com
Subject: Re: FAQ 6.11 How do I use a regular expression to strip C style comments from a file?
Message-Id: <mrcmp4hrhmh274a2e1outejmokahahq48m@4ax.com>

On Tue, 17 Feb 2009 21:18:31 GMT, sln@netherlands.com wrote:

>On Mon, 16 Feb 2009 12:03:01 -0800, PerlFAQ Server <brian@stonehenge.com> wrote:
>
>[snip FAQ header]
>faq>
>faq>6.11: How do I use a regular expression to strip C style comments from a file?
>faq>
>faq>    While this actually can be done, it's much harder than you'd think. For
>faq>    example, this one-liner
>faq>
>faq>            perl -0777 -pe 's{/\*.*?\*/}{}gs' foo.c
>faq>
>faq>    will work in many but not all cases. You see, it's too simple-minded for
>faq>    certain kinds of C programs, in particular, those with what appear to be
>faq>    comments in quoted strings. For that, you'd need something like this,
>faq>    created by Jeffrey Friedl and later modified by Fred Curtis.
>faq>
>faq>            $/ = undef;
>faq>            $_ = <>;
>faq>            s#/\*[^*]*\*+([^/*][^*]*\*+)*/|("(\\.|[^"\\])*"|'(\\.|[^'\\])*'|.[^/"'\\]*)#defined $2 ? $2 : ""#gse;
>faq>            print;
>faq>
>[snip /x expansion]
>
>faq>    A slight modification also removes C++ comments, as long as they are not
>faq>    spread over multiple lines using a continuation character):
>faq>
>faq>            s#/\*[^*]*\*+([^/*][^*]*\*+)*/|//[^\n]*|("(\\.|[^"\\])*"|'(\\.|[^'\\])*'|.[^/"'\\]*)#defined $2 ? $2 : ""#gse;
>                                               ^^^^^^^^                                              ^^^^^^^^^^^^^^^
>                                         //([^\\]|[^\n][\n]?)*?\n                                    defined $3 ? $3
                                          ^^^^^^^^^^^^^^^^^^^^^^^^
above works but it probably looks better this way:
                                          //([^\\]|\\\n?)*?\n
## Matching:
##
##     #//([^\\]|\\\n?)*?\n#gs
##
##  or  #//(?:[^\\]|\\\n?)*?\n#gs
##
##  or {
##       //    ##  Start of //... comment
##       (
##           [^\\]       ## Any Non-Continuation character ^\
##         |             ##   OR
##           \\\n?       ## Any Continuation character followed by 0-1 newline \n
##                     
##       )*?             ## To be done 0-many times, stopping at the first end of comment
##                   
##       \n    ##  End of comment
##     }gxs;
##

-sln



------------------------------

Date: Tue, 17 Feb 2009 14:50:16 -0700
From: Larry Gates <larry@example.invalid>
Subject: Re: FAQ 6.14 How do I process each word on each line?
Message-Id: <1tc7ox8ocohq7$.1toxdvsrwzk2d$.dlg@40tude.net>

On Mon, 16 Feb 2009 07:43:10 -0600, Tad J McClellan wrote:

> Larry Gates <larry@example.invalid> wrote:

>> So if your data are 
>> quick brown %% fixed %noise
>> you will do something with $word 4 times?
> 
> 
> What happened when you tried it?

C:\MinGW\source>perl index13.pl
quick
brown
fixed
noise
__END__
perl
index13
pl

C:\MinGW\source> perl index13.pl
Can't modify constant item in preincrement (++) at index13.pl line 5, near
"i;"
Execution of index13.pl aborted due to compilation errors.

C:\MinGW\source> perl index13.pl
Can't modify constant item in postincrement (++) at index13.pl line 5, near
"i +
+"
Execution of index13.pl aborted due to compilation errors.

C:\MinGW\source>perl index13.pl
i is 1 and this is the word quick
i is 2 and this is the word brown
i is 3 and this is the word fixed
i is 4 and this is the word noise
i is 5 and this is the word __END__
i is 6 and this is the word perl
i is 7 and this is the word index13
i is 8 and this is the word pl

C:\MinGW\source>type index13.pl

my $i=0;
 while (<DATA>) {
foreach $word (m/(\w+)/g) {
++ $i;
print "i is $i and this is the word $word \n";
         }
 }
__DATA__
quick brown %% %fixed noise
__END__
# perl index13.pl
C:\MinGW\source>

One thing I didn't realize is that /%fixed/ was outputted without the /%/.

There are several "blemishes" in the above script, but there's one I want
to focus on in particular.  I know exactly which line is printing on every
iteration, so I know where execution is at eight different times of this
program.

In the data I've been looking at recently, there are four hits on the
center tags.  I want to write a control structure that does one thing if
i=1, nothing if i is 2 or 3, and then uses an olderscript of mine to
process if i=4.  That's why $elem is not doing me enough good here:

foreach my $elem ( $tree2->look_down('_tag', 'center') ) {
++ $i;
print "i is $i\n";
print "elem is $elem\n";

    print $elem->as_text(), "\n";
}

Fishing for tips. 
-- 
larry gates

Real programmers can write assembly code in any language.   :-)
             -- Larry Wall in  <8571@jpl-devvax.JPL.NASA.GOV>


------------------------------

Date: Tue, 17 Feb 2009 15:17:43 -0800
From: Tim Greer <tim@burlyhost.com>
Subject: Re: FAQ 6.14 How do I process each word on each line?
Message-Id: <wAHml.9911$EO2.8139@newsfe04.iad>

Larry Gates wrote:

> my $i=0;
> while (<DATA>) {
> foreach $word (m/(\w+)/g) {

 ...

> __DATA__
> quick brown %% %fixed noise
> __END__
> # perl index13.pl
> C:\MinGW\source>
> 
> One thing I didn't realize is that /%fixed/ was outputted without the
> /%/.
> 

Well, (\w+) is capturing any word character(s) (one or more), so it
won't catpure the text "%value" or "!value", it'll only capture
"value".  \w+ is one or more characters that are a-z, 0-9 and an
underscore_. I won't get into the rest of the code.
-- 
Tim Greer, CEO/Founder/CTO, BurlyHost.com, Inc.
Shared Hosting, Reseller Hosting, Dedicated & Semi-Dedicated servers
and Custom Hosting.  24/7 support, 30 day guarantee, secure servers.
Industry's most experienced staff! -- Web Hosting With Muscle!


------------------------------

Date: Wed, 18 Feb 2009 03:06:44 GMT
From: sln@netherlands.com
Subject: Re: FAQ 6.14 How do I process each word on each line?
Message-Id: <saump41t90bev1nndf7flrg3kf1kl17u59@4ax.com>

On Tue, 17 Feb 2009 14:50:16 -0700, Larry Gates <larry@example.invalid> wrote:

>On Mon, 16 Feb 2009 07:43:10 -0600, Tad J McClellan wrote:
>
>> Larry Gates <larry@example.invalid> wrote:
>
>>> So if your data are 
>>> quick brown %% fixed %noise
>>> you will do something with $word 4 times?
>> 
>> 
>> What happened when you tried it?
>
>C:\MinGW\source>perl index13.pl
>quick
>brown
>fixed
>noise
>__END__
>perl
>index13
>pl
>
>C:\MinGW\source> perl index13.pl
>Can't modify constant item in preincrement (++) at index13.pl line 5, near
>"i;"
>Execution of index13.pl aborted due to compilation errors.
>
[snip]
>
>One thing I didn't realize is that /%fixed/ was outputted without the /%/.
>
>There are several "blemishes" in the above script, but there's one I want
>to focus on in particular.  I know exactly which line is printing on every
>iteration, so I know where execution is at eight different times of this
>program.
>
[snip]

You know, you should stop flambouant verbage and try to be a little more
technical. It's obvious you know enough Perl to decipher things, but not
enough to know technically how to describe it. Are you trying to learn
Perl or are you trying to complete a work-related project piecing together
code snippets here, which is what it seem's like. In that case, what ever
you piece together will never be fully trusted in your brain now or in the
future if you have to explain and/or modify the code.

Just some advice..

-sln


------------------------------

Date: Tue, 17 Feb 2009 20:51:40 -0700
From: Larry Gates <larry@example.invalid>
Subject: Re: FAQ 6.14 How do I process each word on each line?
Message-Id: <155snjkppvbgf$.13ir80pik0jvn.dlg@40tude.net>

On Tue, 17 Feb 2009 15:17:43 -0800, Tim Greer wrote:

> Larry Gates wrote:
> 
>> my $i=0;
>> while (<DATA>) {
>> foreach $word (m/(\w+)/g) {
> 
> ...
> 
>> __DATA__
>> quick brown %% %fixed noise
>> __END__
>> # perl index13.pl
>> C:\MinGW\source>
>> 
>> One thing I didn't realize is that /%fixed/ was outputted without the
>> /%/.
>> 
> 
> Well, (\w+) is capturing any word character(s) (one or more), so it
> won't catpure the text "%value" or "!value", it'll only capture
> "value".  \w+ is one or more characters that are a-z, 0-9 and an
> underscore_. I won't get into the rest of the code.

What I didn't see there was that m/// was *capturing*, as opposed to
setting some boolean value.

-- 
larry gates

Does the same as the system call of that name.
If you don't know what it does, don't worry about it.
             -- Larry Wall in the perl man page regarding chroot(2)


------------------------------

Date: Tue, 17 Feb 2009 16:57:11 +0000
From: RedGrittyBrick <RedGrittyBrick@spamweary.invalid>
Subject: Re: how do I print the name and value of a scalar
Message-Id: <499aec6a$0$16176$db0fefd9@news.zen.co.uk>


Frank Seitz wrote:
> RedGrittyBrick wrote:
>> I think Frank was [...]
> 
> s/Frank/Ben Morrow/g;
> 

Oops, my apologies to you both.

-- 
RGB


------------------------------

Date: Tue, 17 Feb 2009 12:07:27 -0500
From: Jay Somerset <jay-1941-@hotmail.com>
Subject: Re: how do I print the name and value of a scalar
Message-Id: <ierlp4pp4u120j1msf53qgs0v9b28lsu92@4ax.com>

On Mon, 16 Feb 2009 20:25:11 -0800 (PST), cartercc
<cartercc@gmail.com> wrote:

[snip]
>
>It's kind of hard to do when you explain this to my boss (which I did)
>and ask for some time to redesign the whole thing from top to bottom
>and do it right (which I did) and be told that it wasn't important
>enough to do but to leave it alone. Unfortunately, the people I have
>to work with aren't developers or designers and think that writing a
>'little app' is more or less the same as writing up a PowerPoint for a
>presentation. I was told this just a few days ago by someone WHO
>KNOWS!
>
[snip]
>
>Come talk to my boss, and his boss. I do my work on schedule and under
>budget. My crisis experiences come from others when they come to me to
>bail them out on a project that's already late and over budget, or to
>fill in for someone who left yesterday for a two week vacation.

I guess your boss(es) have never learned that "haste makes waste" and
"if you want it 'real bad', that exactly what it will be".   Then
there is always "penny wise; pound foolish" which seems to be today's
corporate philosophy.  :-(
-- 
Jay (remove dashes for legal email address)


------------------------------

Date: Tue, 17 Feb 2009 21:55:20 -0800 (PST)
From: Krishna Chaitanya <schaitan@gmail.com>
Subject: Re: Net::SSH2 scp_put not working!
Message-Id: <b3a58c43-68da-431c-a052-f4130628503b@q40g2000prh.googlegroups.com>

Bumping this up...


------------------------------

Date: Wed, 18 Feb 2009 05:42:24 GMT
From: merlyn@stonehenge.com (Randal Schwartz)
Subject: new CPAN modules on Wed Feb 18 2009
Message-Id: <KF8yIo.1x5v@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.

Acme-CPANAuthors-You-re_using-0.02
http://search.cpan.org/~vpit/Acme-CPANAuthors-You-re_using-0.02/
We are the CPAN authors that have written the modules installed on your perl! 
----
Any-Moose-0.04
http://search.cpan.org/~sartak/Any-Moose-0.04/
use Moose or Mouse modules 
----
Apache2-Mojo-0.004
http://search.cpan.org/~uvoelker/Apache2-Mojo-0.004/
mod_perl2 handler for Mojo 
----
App-CPAN2Pkg-0.5.0
http://search.cpan.org/~jquelin/App-CPAN2Pkg-0.5.0/
generating native linux packages from cpan 
----
App-Daemon-0.05
http://search.cpan.org/~mschilli/App-Daemon-0.05/
Start an Application as a Daemon 
----
App-Maisha-0.07
http://search.cpan.org/~barbie/App-Maisha-0.07/
A command line social micro-blog networking tool. 
----
App-Maisha-0.08
http://search.cpan.org/~barbie/App-Maisha-0.08/
A command line social micro-blog networking tool. 
----
App-Maisha-0.09
http://search.cpan.org/~barbie/App-Maisha-0.09/
A command line social micro-blog networking tool. 
----
App-Maisha-0.10
http://search.cpan.org/~barbie/App-Maisha-0.10/
A command line social micro-blog networking tool. 
----
App-Maisha-Plugin-PingFM-0.02
http://search.cpan.org/~barbie/App-Maisha-Plugin-PingFM-0.02/
Maisha interface to ping.fm 
----
App-Sequence-0.03_03
http://search.cpan.org/~kimoto/App-Sequence-0.03_03/
pluggable subroutine engine. 
----
App-TimeTracker-0.21
http://search.cpan.org/~domm/App-TimeTracker-0.21/
Track time spend on projects from the commandline 
----
Biblio-COUNTER-0.11
http://search.cpan.org/~nkuitse/Biblio-COUNTER-0.11/
COUNTER Codes of Practice report processing 
----
CPAN-SQLite-0.197
http://search.cpan.org/~rkobes/CPAN-SQLite-0.197/
maintain and search a minimal CPAN database 
----
Catalyst-Example-InstantCRUD-0.0.22
http://search.cpan.org/~zby/Catalyst-Example-InstantCRUD-0.0.22/
A CRUD scaffolding for Catalyst. 
----
Catalyst-Example-InstantCRUD-0.0.23
http://search.cpan.org/~zby/Catalyst-Example-InstantCRUD-0.0.23/
A CRUD scaffolding for Catalyst. 
----
Catalyst-View-CSS-Minifier-XS-0.001
http://search.cpan.org/~drinchev/Catalyst-View-CSS-Minifier-XS-0.001/
Minify your multiple CSS files and use them with Catalyst. 
----
Config-Augeas-0.400
http://search.cpan.org/~ddumont/Config-Augeas-0.400/
Edit configuration files through Augeas C library 
----
DBIx-Class-ResultSet-RecursiveUpdate-v0.002
http://search.cpan.org/~zby/DBIx-Class-ResultSet-RecursiveUpdate-v0.002/
like update_or_create - but recursive 
----
DBIx-DataAudit-0.09
http://search.cpan.org/~corion/DBIx-DataAudit-0.09/
summarize column data for a table 
----
Dackup-0.33
http://search.cpan.org/~lbrocard/Dackup-0.33/
Flexible file backup 
----
Data-Visitor-Encode-0.10003
http://search.cpan.org/~dmaki/Data-Visitor-Encode-0.10003/
Encode/Decode Values In A Structure 
----
Encode-IMAPUTF7-1.01
http://search.cpan.org/~pmakholm/Encode-IMAPUTF7-1.01/
modification of UTF-7 encoding for IMAP 
----
Finance-Bank-IE-PermanentTSB-0.4
http://search.cpan.org/~pallotron/Finance-Bank-IE-PermanentTSB-0.4/
Perl Interface to the PermanentTSB Open24 homebanking on <http://www.open24.ie> 
----
Google-Adwords-1.12.2
http://search.cpan.org/~rohan/Google-Adwords-1.12.2/
an interface which abstracts the Google Adwords SOAP API 
----
HTTP-Engine-Middleware-0.06
http://search.cpan.org/~yappo/HTTP-Engine-Middleware-0.06/
middlewares distribution 
----
HeliosX-Logger-HiRes-0.01_0821
http://search.cpan.org/~lajandy/HeliosX-Logger-HiRes-0.01_0821/
HeliosX::Logger subclass providing high resolution logging for Helios 
----
HeliosX-Logger-Log4perl-0.02_0811
http://search.cpan.org/~lajandy/HeliosX-Logger-Log4perl-0.02_0811/
HeliosX::Logger subclass implementing logging to Log4perl for Helios 
----
Hook-Output-File-0.05
http://search.cpan.org/~schubiger/Hook-Output-File-0.05/
Redirect STDOUT/STDERR to a file 
----
Net-Oping-1.02
http://search.cpan.org/~octo/Net-Oping-1.02/
ICMP latency measurement module using the oping library. 
----
Params-Util-0.38
http://search.cpan.org/~adamk/Params-Util-0.38/
Simple, compact and correct param-checking functions 
----
Pod-Tidy-0.10
http://search.cpan.org/~jhoblitt/Pod-Tidy-0.10/
a reformatting Pod Processor 
----
Rose-HTMLx-Form-DBIC-0.02
http://search.cpan.org/~zby/Rose-HTMLx-Form-DBIC-0.02/
Module abstract (<= 44 characters) goes here 
----
SQL-Abstract-1.49_03
http://search.cpan.org/~mstrout/SQL-Abstract-1.49_03/
Generate SQL from Perl data structures 
----
Simo-0.0803
http://search.cpan.org/~kimoto/Simo-0.0803/
Very simple framework for Object Oriented Perl. 
----
Simo-Util-0.01_03
http://search.cpan.org/~kimoto/Simo-Util-0.01_03/
Utility Class for Simo 
----
Simo-Wrapper-0.01_03
http://search.cpan.org/~kimoto/Simo-Wrapper-0.01_03/
Object wrapper to manipulate attrs and methods. 
----
Simo-Wrapper-0.01_04
http://search.cpan.org/~kimoto/Simo-Wrapper-0.01_04/
Object wrapper to manipulate attrs and methods. 
----
Simo-Wrapper-0.01_05
http://search.cpan.org/~kimoto/Simo-Wrapper-0.01_05/
Object wrapper to manipulate attrs and methods. 
----
Test-Harness-3.15
http://search.cpan.org/~andya/Test-Harness-3.15/
Run Perl standard test scripts with statistics 
----
Test-Script-Run-0.01
http://search.cpan.org/~sunnavy/Test-Script-Run-0.01/
test the script with run 
----
Test-WWW-Mechanize-Catalyst-0.50
http://search.cpan.org/~ash/Test-WWW-Mechanize-Catalyst-0.50/
Test::WWW::Mechanize for Catalyst 
----
Text-Snippet-0.03
http://search.cpan.org/~bphillips/Text-Snippet-0.03/
TextMate-like snippet functionality 
----
TheSchwartz-Moosified-0.03
http://search.cpan.org/~fayland/TheSchwartz-Moosified-0.03/
TheSchwartz based on Moose! 
----
Tk-EntrySet-0.08
http://search.cpan.org/~lamprecht/Tk-EntrySet-0.08/
display/edit a list of values in a Set of Widgets. 
----
WWW-Mechanize-TreeBuilder-1.10000
http://search.cpan.org/~ash/WWW-Mechanize-TreeBuilder-1.10000/
----
ZML-0.5.2
http://search.cpan.org/~vvelox/ZML-0.5.2/
A simple, fast, and easy to read binary data storage format. 
----
forks-0.30
http://search.cpan.org/~rybskej/forks-0.30/
drop-in replacement for Perl threads using fork() 
----
forks-BerkeleyDB-0.06
http://search.cpan.org/~rybskej/forks-BerkeleyDB-0.06/
high-performance drop-in replacement for threads 
----
xcruciate-009
http://search.cpan.org/~melonman/xcruciate-009/
----
xcruciate-010
http://search.cpan.org/~melonman/xcruciate-010/


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/>
Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
See http://methodsandmessages.vox.com/ for Smalltalk and Seaside discussion


------------------------------

Date: Tue, 17 Feb 2009 17:33:37 +0000
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: Read/write with UCS-2* encodings - Possible???
Message-Id: <h09r66-mt2.ln1@osiris.mauzo.dyndns.org>


Quoth Ilya Zakharevich <nospam-abuse@ilyaz.org>:
> What should one fix to make UCS-2* encodings work on the file handles
> in Perl?  E.g., should not
> 
>   perl -wlpe "BEGIN{binmode STDOUT, q(:encoding(UCS-2));}" < xyz > xyz1
> 
> just work?  Currently, it requires additional `binmode STDOUT' in
> advance, which changes the semantic.  And doing
> 
>   binmode STDOUT;
>   binmode STDOUT, q(:encoding(UCS-2));
>   binmode STDOUT, q(:crlf);
> 
> does not work, since :crlf layer is put AFTER :encoding, not before it
> as expected...

You are working on Win32? What are you actually trying to achieve? It
seems to me things are working as documented. If you want to write UCS2
to a filehandle, that is binary data, so you need to binmode the
filehandle first. If you want LF->CRLF translation before the data is
converted to UCS2, you need to push :crlf after :encoding.

(You presumably know you can use

    binmode STDOUT, ":raw:encoding(UCS-2):crlf";

rather that three separate statements?)

> Another indication is that
> 
>   piconv -t UCS-2
> 
> gives wrong results on DOSISH platforms (which is not surprizing,
> since the version I have uses q(:encoding(UCS-2))).

That's just a bug in piconv, then. It should binmode its filehandles if
it's writing potentially binary data.

> For best results, I would prefer a solution which allows doing
> 
>   binmode STDOUT, q(:encoding(UCS-2));
> 
> and
> 
>   binmode STDOUT, q(:crlf);
> 
> in arbitrary order so that the result does not depend on the order
> (as now), but works ;-/.

That would be... weird. It matters whether the LF->CRLF conversion is
done before or after the characters->UCS-2 conversion, since you get
different results. There's already more than enough weirdness in PerlIO
without adding more.

Ben



------------------------------

Date: Tue, 17 Feb 2009 20:20:19 +0100
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: Read/write with UCS-2* encodings - Possible???
Message-Id: <slrngpm3fk.mc4.hjp-usenet2@hrunkner.hjp.at>

On 2009-02-17 14:16, Marc Lucksch <perl@marc-s.de> wrote:
> To make perl generate UTF-16, UTF-32 files that can be used by the 
> Windows Editor (CRLF), I used a small trick of which I also put in my 
> Sofu module: 
> http://search.cpan.org/~maluku/Sofu-0.3/lib/Data/Sofu.pm#NOTE_on_Unicode
>
>    #Write Windows CRLF UTF-16 Files
>    open my $fh,">:raw:encoding(UTF-16):crlf:utf8","out.sofu";

Why the ":utf8"? It doesn't make sense to me (you want UTF-16, not
UTF-8, and you most definitely don't want to double-encode), and it
doesn't seem to make any difference anyway.


>    print $fh chr(65279); #Print UTF-8 Byte Order Mark (Some programs 
> want it, some programs die on it...)

:encoding(UTF-16) already causes a BOM to be written, so this writes a
second BOM.

	hp

PS: Only tested with 5.10.0.



------------------------------

Date: Tue, 17 Feb 2009 21:00:40 +0100
From: Marc Lucksch <perl@marc-s.de>
Subject: Re: Read/write with UCS-2* encodings - Possible???
Message-Id: <gnf50e$e51$1@ariadne.rz.tu-clausthal.de>

Peter J. Holzer schrieb:
> On 2009-02-17 14:16, Marc Lucksch <perl@marc-s.de> wrote:
>> To make perl generate UTF-16, UTF-32 files that can be used by the 
>> Windows Editor (CRLF), I used a small trick of which I also put in my 
>> Sofu module: 
>> http://search.cpan.org/~maluku/Sofu-0.3/lib/Data/Sofu.pm#NOTE_on_Unicode
>>
>>    #Write Windows CRLF UTF-16 Files
>>    open my $fh,">:raw:encoding(UTF-16):crlf:utf8","out.sofu";
> 
> Why the ":utf8"? It doesn't make sense to me (you want UTF-16, not
> UTF-8, and you most definitely don't want to double-encode), and it
> doesn't seem to make any difference anyway.
As far as I remember when I wrote that, I ended up getting a warning 
about wide characters from the :crlf layer, it doesn't happen anymore in 
perl5.10.0 (see below). So it is not needed anymore (still work though)

The :utf8 layer somehow makes the next layer accept wide characters even 
if it shouldn't.

It tested it with perl5.8.1 when I did that. And the test routine I 
wrote for this also works for perl5.10.0. (in Data::Sofu 0.3).


>>    print $fh chr(65279); #Print UTF-8 Byte Order Mark (Some programs 
>> want it, some programs die on it...)
> 
> :encoding(UTF-16) already causes a BOM to be written, so this writes a
> second BOM.
> 
Yeah, that was my error, I didn't delete that line.. There were two 
lines before that discribing how to make UTF-8. and that line belonged 
to that.

Take my old test script:

#!/usr/bin/perl
use strict;
use warnings;

open my $fh,">:raw:encoding(UTF-16):crlf:utf8","windows.txt";
print $fh "Hello\nWorld";
close $fh;

open $fh,">:raw:encoding(UTF-16)","unix.txt";
print $fh "Hello\nWorld";
close $fh;

# this is logical, since perlIO layers are from left to right
open $fh,">:raw:encoding(UTF-16):crlf","logical.txt";
print $fh "Hello\nWorld";
close $fh;

# this is unlogical, since perlIO layers are from left to right, but test it
# anyway
open $fh,">:raw:crlf:encoding(UTF-16)","unlogical.txt";
print $fh "Hello\nWorld";
close $fh;

# In Windows :crlf is the default
open $fh,">:encoding(UTF-16)","justutf-16.txt";
print $fh "Hello\nWorld";
close $fh;


Test on Windows with perl5.10.0

windows.txt:
Editor:
Hello
World
Vim:
Hello
World
[converted][noeol]

unix.txt:
Editor:
HelloWorld
Vim:
Hello
World
[unix][converted][noeol]


And now the others:

logical.txt:
Works as the windows.txt one (didn't for me before)
And there is no more warning. *happy*


Unlogical:
VIM:
þÿ\0H\0e\0\l\0l\0o\0
\0W\0o\0r\0l\0d
[noeol]
Editor:
Hello਀圀漀爀氀

justutf-16.txt:
Same as unlogical.txt, which is strange

So to conclude:
open my $fh,">:raw:encoding(UTF-16):crlf:utf8","windows.txt";# working
open $fh,">:raw:encoding(UTF-16)","unix.txt"; #working for unix

open $fh,">:raw:encoding(UTF-16):crlf","logical.txt"; #Working in 5.10.0

When I add "\x{343f}" to the string it still works well in the Editor, 
but my VIM7.2 won't read the files anymore. :(

Marc "Maluku" Lucksch


------------------------------

Date: Wed, 18 Feb 2009 00:48:19 GMT
From: sln@netherlands.com
Subject: Resolving Quantifiers of Sub-Expression Quantifiers:  ie: /( ( ( foo\w* )+? | ( fle\w+)* ){0,5} ) )? bar/xg; ?
Message-Id: <climp4dpfasra8s5f2k4rlknjkmhp99vtp@4ax.com>

I recently think its possible the Regex engine does variable,
muti-phrase with inner quantifier, sub-expression matching, that
can be as well, enumerated with outer quantifiers to control the result.

I thought, "this can be very labor intensive to talk this out in English",
when designing a regex. But, an inner quantifier controlled, variable,
multi-phrase match, would be nice to be repeated by an outer quantifier capture
group instead of being picked up in pieces in a while loop for later assembly.

I understand the possible infinte loop scenario, anchor characters usually take care of that.

My observations:

 . The Regex engine will modify/optimize the submitted expression and the resulting thing
might not be what you think.

 . I have not seen in all the perldocs the subject of exponential matching, only linear
matching as it relates to quantifiers (ie: quantifiers of sub-expression quantifiers
aren't covered).

The subject line is a crude example   /( ( ( foo\w* )+? | ( fle\w+)* ){0,5} ) )? bar/xg;
or   /( ( ( foo\w* )+? | ( fle\w+)* ){0,5} ) )+? bar/xg

But, I need to 'capture' a variable quantifier controlled phrase, repeating some
quantifier controlled sequenced amount, in a 'single' capture.

Not too hard of a concept. I've always wanted/needed to do this, but never had any
sucess until today, where I did it in a very limited/sparce regex. I need to understand
this more.

My big question is I need some confirmation if this is right and possible, and how
deep it can go.

Lets assume the Regex engine doesen't talk in English to itself when it parses/optimizes
the expression. How does it resolve inner expression groups with quantifiers, with outer
expression quantifiers?

Is there a formula, given inner vs. outer quantifiers, that shows the resultant quantifier
and or optimized expression?

Just asking, no need to say "look at the Regex engine code". I'm not being paid to do that.

Hey, nice web site!
-sln



------------------------------

Date: Tue, 17 Feb 2009 23:16:25 -0800 (PST)
From: paul.hopgood@deathnotify.com
Subject: Undefined subroutine &main::param called
Message-Id: <198ffa8f-af04-4698-b925-c9919e2e1cd2@f24g2000vbf.googlegroups.com>

I need help solving a subroutine error in my Pearl script.
Here is the error I'm getting:
binmode() on closed filehandle SAVE at /recording.pl line 12.
Undefined subroutine &main::param called at /recording.pl line 13.

Below is my script:

#!/usr/bin/perl -w

use strict;
$|++;

my $pathToRecordings="http://www.deathnotify.com/recordings";
my $newRecording = "test.wav";



 open (SAVE, "> $pathToRecordings/recordings");
   binmode(SAVE);
   while (read(param("voiceMessage"),$newRecording,1024))
      { print SAVE $newRecording; }
 close(SAVE);

Any suggestions would be most appreciated.
Thanks!
-Paul


------------------------------

Date: Wed, 18 Feb 2009 00:06:49 -0800 (PST)
From: Krishna Chaitanya <schaitan@gmail.com>
Subject: Re: Undefined subroutine &main::param called
Message-Id: <35514507-7343-468e-bee1-9a40634850eb@t39g2000prh.googlegroups.com>

Hi Paul,

The error messages by Perl are pretty informative, actually...

> binmode() on closed filehandle SAVE at /recording.pl line 12.

This could be due to open failing to create the SAVE filehandle. Check
the syntax and file-name/path you are trying to open. Use the "or die"
idiom. (i.e. open(SAVE,.....) or die "Could not open SAVE on .... ")

> Undefined subroutine &main::param called at /recording.pl line 13.

That's because there is no function called param written by you in
this script. And neither does param sound like a Perl built-in (check
Functions side-tab in http://perldoc.perl.org for a list of Perl built-
in functions). So Perl couldn't locate the param call and complained.

You could've known more info by using warnings and strict as follows:

use warnings;
use strict;

Always use these as they save a lot of headache....hope this helps.

-Chaitanya


------------------------------

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 2217
***************************************


home help back first fref pref prev next nref lref last post