[30975] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 2220 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Feb 19 03:09:51 2009

Date: Thu, 19 Feb 2009 00:09:10 -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           Thu, 19 Feb 2009     Volume: 11 Number: 2220

Today's topics:
    Re: extracting values from vmstat output <alfonso.baldaserra@gmail.com>
    Re: extracting values from vmstat output <tim@burlyhost.com>
    Re: extracting values from vmstat output <spamtrap@dot-app.org>
    Re: Net::SSH2 scp_put not working! <schaitan@gmail.com>
    Re: Net::SSH2 scp_put not working! <ben@morrow.me.uk>
    Re: Net::SSH2 scp_put not working! <schaitan@gmail.com>
    Re: Net::SSH2 scp_put not working! <ben@morrow.me.uk>
        new CPAN modules on Thu Feb 19 2009 (Randal Schwartz)
    Re: Read/write with UCS-2* encodings - Possible??? <nospam-abuse@ilyaz.org>
    Re: Read/write with UCS-2* encodings - Possible??? <ben@morrow.me.uk>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Wed, 18 Feb 2009 21:46:32 -0800 (PST)
From: alfonsobaldaserra <alfonso.baldaserra@gmail.com>
Subject: Re: extracting values from vmstat output
Message-Id: <873c7687-1be9-4a38-9aa0-b8553683bf1b@v5g2000prm.googlegroups.com>

> =A0 =A0 # untested
> =A0 =A0 my $vmstat =3D qx/vmstat -v/;
> =A0 =A0 my($memory) =3D $vmstat =3D~ /(\d+) memory pages/;
> =A0 =A0 my($free) =A0 =3D $vmstat =3D~ /(\d+) free pages/;
>

your untested code turned out to be perfect. i got what i wanted.
thank you.

but i have one question could you please answer? why are you using
$memory and $free in list context? i tried running it as scalar and
the output was 1 but in list context it gives correct value.

greg your code worked very nice and thank you so much for the amazing
explanations.


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

Date: Wed, 18 Feb 2009 23:12:59 -0800
From: Tim Greer <tim@burlyhost.com>
Subject: Re: extracting values from vmstat output
Message-Id: <0E7nl.11843$2O4.3506@newsfe03.iad>

alfonsobaldaserra wrote:

>> # untested
>> my $vmstat = qx/vmstat -v/;
>> my($memory) = $vmstat =~ /(\d+) memory pages/;
>> my($free)   = $vmstat =~ /(\d+) free pages/;
>>
> 
> your untested code turned out to be perfect. i got what i wanted.
> thank you.
> 
> but i have one question could you please answer? why are you using
> $memory and $free in list context? i tried running it as scalar and
> the output was 1 but in list context it gives correct value.
> 
> greg your code worked very nice and thank you so much for the amazing
> explanations.

One method is the result of the "test" of that condition (matching),
while the other assigns the value returned (not true or false).  It's
not that it's in a list context, in other words, and you can see the
difference in how it's used in the results you've witnessed.
-- 
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: Thu, 19 Feb 2009 02:26:54 -0500
From: Sherm Pendley <spamtrap@dot-app.org>
Subject: Re: extracting values from vmstat output
Message-Id: <m17i3mga4h.fsf@dot-app.org>

Tim Greer <tim@burlyhost.com> writes:

> alfonsobaldaserra wrote:
>
>>> # untested
>>> my $vmstat = qx/vmstat -v/;
>>> my($memory) = $vmstat =~ /(\d+) memory pages/;
>>> my($free)   = $vmstat =~ /(\d+) free pages/;
>>>
>> 
>> your untested code turned out to be perfect. i got what i wanted.
>> thank you.
>> 
>> but i have one question could you please answer? why are you using
>> $memory and $free in list context? i tried running it as scalar and
>> the output was 1 but in list context it gives correct value.
>
> One method is the result of the "test" of that condition (matching),
> while the other assigns the value returned (not true or false).  It's
> not that it's in a list context

Context is *exactly* what makes that difference. In scalar context,
the =~ operator returns true/false, and in list context it returns a list
of the matched subexpressions.

See 'perldoc perlop' and 'perldoc perlre' for details.

sherm--

-- 
My blog: http://shermspace.blogspot.com
Cocoa programming in Perl: http://camelbones.sourceforge.net


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

Date: Wed, 18 Feb 2009 11:16:27 -0800 (PST)
From: Krishna Chaitanya <schaitan@gmail.com>
Subject: Re: Net::SSH2 scp_put not working!
Message-Id: <d0dabb8d-1e74-4bff-bc65-41473f4f29aa@o2g2000prl.googlegroups.com>

Thanks, Gunnar. Apologies for not doing it earlier.....it wasn't
deliberate, I missed your earlier post completely.

When I printed $ssh2->error, it said LIBSSH2_ERROR_EAGAIN (-37).
Looked up "man 3 libssh2_scp_send_ex" and it says this:

"LIBSSH2_ERROR_EAGAIN - Marked for non-blocking I/O but the call would
block."

Combining that with the documentation of Net::SSH2::blocking ("Note
that if blocking is disabled, methods that create channels may fail,
e.g. channel, SFTP, scp_*."), I figured out that $chan2->blocking(0)
was the mistake. Now I've re-written the code as:

====================
Listing 1.pl
---------------

#!/usr/bin/perl

use warnings;
use strict;

use Net::SSH2;

my $ssh2 = Net::SSH2->new();

$ssh2->connect('10.0.1.174') or die;

if ($ssh2->auth_password('inmdev','inmdev')) {
        print "Authorization successful\n";
        my $chan2 = $ssh2->channel();
        $chan2->shell();
        $ssh2->blocking(0);
        print $chan2 "uname -a\n";
        print "LINE : $_" while <$chan2>;
        $chan2->close();
        $ssh2->blocking(1);
        $ssh2->scp_put("/home/perl_progs/2.pl","/tmp/2.pl") or warn
"Could not scp
the file 2.pl ";
} else {

        print "Authorization failure\n";

}

====================

Just added $ssh2->blocking(1) before calling scp_put and it worked
successfully !!!

Thanks everyone! I am summarising this:

"If you intend to use channel, SFTP, scp_* (methods that create
channels), do not disable blocking ... i.e. do NOT say $ssh->blocking
(0) before executing those methods. Also, always print out $ssh->error
for descriptive info of error and combine it with the man pages of
libssh2"


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

Date: Wed, 18 Feb 2009 20:26:02 +0000
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: Net::SSH2 scp_put not working!
Message-Id: <qf7u66-sq3.ln1@osiris.mauzo.dyndns.org>


Quoth Krishna Chaitanya <schaitan@gmail.com>:
> Thanks, Gunnar. Apologies for not doing it earlier.....it wasn't
> deliberate, I missed your earlier post completely.
> 
> When I printed $ssh2->error, it said LIBSSH2_ERROR_EAGAIN (-37).
> Looked up "man 3 libssh2_scp_send_ex" and it says this:
> 
> "LIBSSH2_ERROR_EAGAIN - Marked for non-blocking I/O but the call would
> block."

You do know that EAGAIN isn't really an error code, and (if you actually
need non-blockking IO) the correct response is to call ->poll and then
retry?

<snip>
> if ($ssh2->auth_password('inmdev','inmdev')) {
>         print "Authorization successful\n";
>         my $chan2 = $ssh2->channel();
>         $chan2->shell();
>         $ssh2->blocking(0);

Why are you doing this? You run the risk of getting EAGAIN failures from
both the print and the <>, and you're not handling them. (You're not
even checking that the print succeeded, which you should.) That you
haven't yet just means the box you are talking to is not very loaded,
and your network not very busy.

Do you understand what non-blocking IO is for? It's only useful if you
have something else to do while waiting for the block to go away. Since
you don't, you should just stick to blocking IO.

Ben



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

Date: Wed, 18 Feb 2009 19:44:14 -0800 (PST)
From: Krishna Chaitanya <schaitan@gmail.com>
Subject: Re: Net::SSH2 scp_put not working!
Message-Id: <196389a5-7402-4fd8-935b-739a41786d1b@u8g2000prd.googlegroups.com>

Hi Ben,

Thnx for your insight. It's true that I don't have anything else to do
while the I/O goes on...so you're right, I should just stick to
blocking I/O. But when I'm doing that, the results in repeated runs of
my program are unpredictable. Sometimes, it returns soon after
successfully copying the file, sometimes it just "hangs". This
particular program will be developed to use on a large network
(predictably 100s or more of Linux boxes) to copy some files to each
Linux box and it'd be ideal to see a predictable nature of response
with every run.


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

Date: Thu, 19 Feb 2009 05:41:38 +0000
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: Net::SSH2 scp_put not working!
Message-Id: <i18v66-389.ln1@osiris.mauzo.dyndns.org>


Quoth Krishna Chaitanya <schaitan@gmail.com>:
> 
> Thnx for your insight. It's true that I don't have anything else to do
> while the I/O goes on...so you're right, I should just stick to
> blocking I/O. But when I'm doing that, the results in repeated runs of
> my program are unpredictable. Sometimes, it returns soon after
> successfully copying the file, sometimes it just "hangs". This
> particular program will be developed to use on a large network
> (predictably 100s or more of Linux boxes) to copy some files to each
> Linux box and it'd be ideal to see a predictable nature of response
> with every run.

Well, the hangs will still be happening, it may just be you're ignoring
them. If this is more than just normal network variablility, it may
indicate something's going wrong with the transfer. I would start
debugging the problem by using tcpdump or something equivalent to see
where the protocol's getting jammed.

Ben



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

Date: Thu, 19 Feb 2009 05:42:26 GMT
From: merlyn@stonehenge.com (Randal Schwartz)
Subject: new CPAN modules on Thu Feb 19 2009
Message-Id: <KFAt6q.11BK@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.

Algorithm-Evolutionary-0.64_1
http://search.cpan.org/~jmerelo/Algorithm-Evolutionary-0.64_1/
Perl module for performing paradigm-free evolutionary algorithms. 
----
App-Maisha-0.11
http://search.cpan.org/~barbie/App-Maisha-0.11/
A command line social micro-blog networking tool. 
----
BerkeleyDB-0.37
http://search.cpan.org/~pmqs/BerkeleyDB-0.37/
Perl extension for Berkeley DB version 2, 3 or 4 
----
Bread-Board-0.07
http://search.cpan.org/~dmaki/Bread-Board-0.07/
A solderless way to wire up you application components 
----
Business-WebMoney-0.07
http://search.cpan.org/~aml/Business-WebMoney-0.07/
Perl API to WebMoney 
----
CPANPLUS-Dist-Build-0.06_04
http://search.cpan.org/~bingos/CPANPLUS-Dist-Build-0.06_04/
CPANPLUS plugin to install packages that use Build.PL 
----
Capture-Tiny-0.02
http://search.cpan.org/~dagolden/Capture-Tiny-0.02/
Capture STDOUT and STDERR from Perl, XS or external programs 
----
Catalyst-Action-RenderView-0.09
http://search.cpan.org/~mramberg/Catalyst-Action-RenderView-0.09/
Sensible default end action. 
----
Catalyst-Authentication-Store-Tangram-0.009
http://search.cpan.org/~bobtfish/Catalyst-Authentication-Store-Tangram-0.009/
A storage class for Catalyst authentication from a class stored in Tangram 
----
Catalyst-Example-InstantCRUD-0.0.24
http://search.cpan.org/~zby/Catalyst-Example-InstantCRUD-0.0.24/
A CRUD scaffolding for Catalyst. 
----
Catalyst-Example-InstantCRUD-0.0.25
http://search.cpan.org/~zby/Catalyst-Example-InstantCRUD-0.0.25/
A CRUD scaffolding for Catalyst. 
----
Catalyst-View-CSS-Minifier-XS-0.02
http://search.cpan.org/~drinchev/Catalyst-View-CSS-Minifier-XS-0.02/
Minify your multiple CSS files and use them with Catalyst. 
----
Catalyst-View-JavaScript-Minifier-XS-0.02
http://search.cpan.org/~drinchev/Catalyst-View-JavaScript-Minifier-XS-0.02/
Concenate and minify your JavaScript files. 
----
Catalyst-View-TT-0.28
http://search.cpan.org/~mramberg/Catalyst-View-TT-0.28/
Template View Class 
----
Class-C3-Adopt-NEXT-0.07
http://search.cpan.org/~flora/Class-C3-Adopt-NEXT-0.07/
make NEXT suck less 
----
CouchDB-ExternalProcess-0.01
http://search.cpan.org/~fansipans/CouchDB-ExternalProcess-0.01/
Make creating Perl-based external processs for CouchDB easy 
----
DB_File-1.819
http://search.cpan.org/~pmqs/DB_File-1.819/
Perl5 access to Berkeley DB version 1.x 
----
DateTimeX-Format-00.01_01
http://search.cpan.org/~ecarroll/DateTimeX-Format-00.01_01/
A base class for building next generation DateTime abstraction layers 
----
DateTimeX-Format-00.01_02
http://search.cpan.org/~ecarroll/DateTimeX-Format-00.01_02/
A base class for building next generation DateTime abstraction layers 
----
DateTimeX-Format-00.01_03
http://search.cpan.org/~ecarroll/DateTimeX-Format-00.01_03/
Moose Roles for building next generation DateTime formats 
----
DateTimeX-Format-00.01_04
http://search.cpan.org/~ecarroll/DateTimeX-Format-00.01_04/
Moose Roles for building next generation DateTime formats 
----
DateTimeX-Format-POSIX-Strptime-00.01_01
http://search.cpan.org/~ecarroll/DateTimeX-Format-POSIX-Strptime-00.01_01/
----
File-Find-Object-Rule-0.0100
http://search.cpan.org/~shlomif/File-Find-Object-Rule-0.0100/
Alternative interface to File::Find::Object 
----
File-Find-Rule-Perl-1.05
http://search.cpan.org/~adamk/File-Find-Rule-Perl-1.05/
Common rules for searching for Perl things 
----
HTML-Revelation-1.01
http://search.cpan.org/~rsavage/HTML-Revelation-1.01/
Reveal HTML document structure in a myriad of colors 
----
HTTP-Engine-0.1.4_01
http://search.cpan.org/~yappo/HTTP-Engine-0.1.4_01/
Web Server Gateway Interface and HTTP Server Engine Drivers (Yet Another Catalyst::Engine) 
----
HTTP-Engine-Middleware-0.07
http://search.cpan.org/~yappo/HTTP-Engine-Middleware-0.07/
middlewares distribution 
----
HTTP-Engine-Middleware-0.08_01
http://search.cpan.org/~yappo/HTTP-Engine-Middleware-0.08_01/
middlewares distribution 
----
IO-Event-0.701
http://search.cpan.org/~muir/IO-Event-0.701/
Tied Filehandles for Nonblocking IO with Object Callbacks 
----
IPC-Lite-0.1.17
http://search.cpan.org/~earonesty/IPC-Lite-0.1.17/
share variables between processes in a platform neutral way 
----
IPC-Lite-0.1.21
http://search.cpan.org/~earonesty/IPC-Lite-0.1.21/
Share variables between processes 
----
JSON-XS-2.2311
http://search.cpan.org/~mlehmann/JSON-XS-2.2311/
JSON serialising/deserialising, done correctly and fast 
----
Kools-Okapi-2.6.3.L3.001
http://search.cpan.org/~muguet/Kools-Okapi-2.6.3.L3.001/
Perl extension for the OKAPI api of Kondor+ 2.6 
----
Log-Fine-0.22
http://search.cpan.org/~cfuhrman/Log-Fine-0.22/
Yet another logging framework 
----
Modern-Perl-1.03
http://search.cpan.org/~chromatic/Modern-Perl-1.03/
enable all of the features of Modern Perl with one command 
----
Module-Metadata-Changes-1.04
http://search.cpan.org/~rsavage/Module-Metadata-Changes-1.04/
Manage a module's machine-readable Changelog.ini file 
----
Mouse-0.17
http://search.cpan.org/~sartak/Mouse-0.17/
Moose minus the antlers 
----
NCBIx-BigFetch-0.50
http://search.cpan.org/~rogerhall/NCBIx-BigFetch-0.50/
Retrieve very large NCBI sequence result sets based on keyword search 
----
NCBIx-BigFetch-0.51
http://search.cpan.org/~rogerhall/NCBIx-BigFetch-0.51/
Retrieve very large NCBI sequence result sets based on keyword search 
----
NCBIx-BigFetch-0.52
http://search.cpan.org/~rogerhall/NCBIx-BigFetch-0.52/
Retrieve very large NCBI sequence result sets based on keyword search 
----
Net-SFTP-Foreign-1.48_03
http://search.cpan.org/~salva/Net-SFTP-Foreign-1.48_03/
SSH File Transfer Protocol client 
----
NetHack-Item-0.06
http://search.cpan.org/~sartak/NetHack-Item-0.06/
parse and interact with a NetHack item 
----
Object-Event-0.7
http://search.cpan.org/~elmex/Object-Event-0.7/
A class that provides an event callback interface 
----
Object-InsideOut-3.53
http://search.cpan.org/~jdhedden/Object-InsideOut-3.53/
Comprehensive inside-out object support module 
----
Object-InsideOut-3.54
http://search.cpan.org/~jdhedden/Object-InsideOut-3.54/
Comprehensive inside-out object support module 
----
POE-Component-Algorithm-Evolutionary-0.2.0
http://search.cpan.org/~jmerelo/POE-Component-Algorithm-Evolutionary-0.2.0/
Run evolutionary algorithms in a preemptive multitasking way. 
----
POE-Component-Client-DNS-1.03
http://search.cpan.org/~rcaputo/POE-Component-Client-DNS-1.03/
non-blocking, concurrent DNS requests 
----
Padre-Plugin-Parrot-0.23
http://search.cpan.org/~szabgab/Padre-Plugin-Parrot-0.23/
Experimental Padre plugin that runs on Parrot 
----
Provision-Unix-0.45
http://search.cpan.org/~msimerson/Provision-Unix-0.45/
provision accounts on unix systems 
----
Quote-Reference-1.0.0
http://search.cpan.org/~kilna/Quote-Reference-1.0.0/
Shortcut notation for whitespace-delimited array and hash references 
----
Rose-HTMLx-Form-DBIC-0.03
http://search.cpan.org/~zby/Rose-HTMLx-Form-DBIC-0.03/
Module abstract (<= 44 characters) goes here 
----
Rose-HTMLx-Form-DBIC-0.04
http://search.cpan.org/~zby/Rose-HTMLx-Form-DBIC-0.04/
Module abstract (<= 44 characters) goes here 
----
Rose-HTMLx-Form-DBIC-0.05
http://search.cpan.org/~zby/Rose-HTMLx-Form-DBIC-0.05/
Module abstract (<= 44 characters) goes here 
----
Search-Indexer-Incremental-MD5-0.01_01
http://search.cpan.org/~nkh/Search-Indexer-Incremental-MD5-0.01_01/
Incrementaly index your files 
----
String-Perl-Warnings-0.02
http://search.cpan.org/~bingos/String-Perl-Warnings-0.02/
Determine if a string looks like a perl warning 
----
String-Tagged-0.02
http://search.cpan.org/~pevans/String-Tagged-0.02/
string buffers with value tags on extents 
----
TaskForest-1.16
http://search.cpan.org/~enoor/TaskForest-1.16/
A simple but expressive job scheduler that allows you to chain jobs/tasks and create time dependencies. Uses text config files to specify task dependencies. 
----
Template-Plugin-Dumper-Perltidy-0.01
http://search.cpan.org/~fayland/Template-Plugin-Dumper-Perltidy-0.01/
Template Toolkit plugin interface to Data::Dumper::Perltidy 
----
Template-Plugin-XML-Feed-0.01
http://search.cpan.org/~davecross/Template-Plugin-XML-Feed-0.01/
Plugin interface to XML::Feed 
----
Test-Most-0.21
http://search.cpan.org/~ovid/Test-Most-0.21/
Most commonly needed test functions and features. 
----
Test-Most-0.21_01
http://search.cpan.org/~ovid/Test-Most-0.21_01/
Most commonly needed test functions and features. 
----
Test-Weaken-1.003_004
http://search.cpan.org/~jkegl/Test-Weaken-1.003_004/
Test that freed references are, indeed, freed 
----
Tie-Proxy-Changes-0.1
http://search.cpan.org/~maluku/Tie-Proxy-Changes-0.1/
Track changes in your tied objects 
----
Tk-EntrySet-0.09
http://search.cpan.org/~lamprecht/Tk-EntrySet-0.09/
display/edit a list of values in a Set of Widgets. 
----
UMLS-Interface-0.21
http://search.cpan.org/~btmcinnes/UMLS-Interface-0.21/
Perl interface to the Unified Medical Language System (UMLS) 
----
WWW-Freshmeat-0.12
http://search.cpan.org/~chorny/WWW-Freshmeat-0.12/
automates searches on Freshmeat.net 
----
Win32-WindowsUpdate-0.01
http://search.cpan.org/~wilsond/Win32-WindowsUpdate-0.01/
Access to Windows Update functions 
----
Win32-WindowsUpdate-0.02
http://search.cpan.org/~wilsond/Win32-WindowsUpdate-0.02/
Access to Windows Update functions 
----
Win32-WindowsUpdate-0.03
http://search.cpan.org/~wilsond/Win32-WindowsUpdate-0.03/
Access to Windows Update functions 
----
any-feature-0.01
http://search.cpan.org/~marcel/any-feature-0.01/
Backwards-compatible handling of new syntactic features 
----
parrot-0.9.1
http://search.cpan.org/~arandal/parrot-0.9.1/


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: Wed, 18 Feb 2009 21:04:04 GMT
From: Ilya Zakharevich <nospam-abuse@ilyaz.org>
Subject: Re: Read/write with UCS-2* encodings - Possible???
Message-Id: <slrngpotu4.tdn.nospam-abuse@chorin.math.berkeley.edu>

On 2009-02-18, Ben Morrow <ben@morrow.me.uk> wrote:
>> So now the question boils down to: how to make
>> 
>>   binmode STDOUT, 'encoding(UCS-2)';
>> 
>> done on a filehandle which is in :crlf mode do the moral equivalent of
>> 
>>   binmode STDOUT, ":raw:encoding(UCS-2):crlf";
>
> Well, I think the only answer is 'write a new :crlf layer'. 

Why?  I think it should be a modification of :encoding layer: when
installed, it should pay attention to a presence of :crlf/:cr...

>> And how one would easily switch :crlf layer off on such a handle?
>> Doing just `binmode' switches off encoding as well; and my perl does
>> not support :lf...
>
> Yes... I can see that would be annoying. Personally I'd use :eol from
> CPAN instead of :crlf (it's less weird, and can cope with mixed
> newlines) and remove it with :pop. Or you could write PerlIO::nocrlf,
> which goes through the stack turning off all the CRLF flags and then
> pops itself.

> Of course, if it's not at the top then you've got a problem.

Yes.

> You *may*
> be able to pop down to the :eol layer without losing buffered data and
> then push the other layers back on without losing state, but it's
> unlikely. This is part of why I think using PerlIO for anything other
> than :unix, :encoding and :scalar is a mistake: it just doesn't work
> properly.

I agree: I see no purpose and no convenience in the current design...

> I must admit I've never had anything to do with creating Win32-format
> text files. Generally the extent of my knowledge of such things is 'how
> do I get this wretched OS to stop messing up my files?' :).

This is one of the sides of the problem.  *This* part can be fixed if
:encoding(UCS2) would just remove :crlf flag.

>> >> 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.
>> 
>> How would it know this?  What is the semantic of binmode()?

> You've always had to binmode filehandles when writing binary data.

By definition, piconv does not work with binary files...

> I think you mean the other way around? The case where you push
>
>     raw
>     encoding
>     crlf
>
> in that order is the case that works. What you want is for a push of
>:encoding to notice the filehandle is already :crlf, remove the :crlf,
> and re-push it on top of itself.

Yes.

> While this is certainly possible, I somewhat doubt the behaviour of
> :encoding will be changed now.

Given that its current behaviour makes no sense, why not?

Thanks,
Ilya


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

Date: Wed, 18 Feb 2009 22:04:04 +0000
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: Read/write with UCS-2* encodings - Possible???
Message-Id: <k7du66-ul4.ln1@osiris.mauzo.dyndns.org>

[sorry, it seems I snipped one of your attributions.]

Quoth Ilya Zakharevich <nospam-abuse@ilyaz.org>:
> On 2009-02-18, Ben Morrow <ben@morrow.me.uk> wrote:
> >> Quoth Ilya Zakharevich <nospam-abuse@ilyaz.org>:
> >>
> >> So now the question boils down to: how to make
> >> 
> >>   binmode STDOUT, 'encoding(UCS-2)';
> >> 
> >> done on a filehandle which is in :crlf mode do the moral equivalent of
> >> 
> >>   binmode STDOUT, ":raw:encoding(UCS-2):crlf";
> >
> > Well, I think the only answer is 'write a new :crlf layer'. 
> 
> Why?  I think it should be a modification of :encoding layer: when
> installed, it should pay attention to a presence of :crlf/:cr...

Yes, a new :encoding-like would be better than trying to modify :crlf. I
hadn't quite thought that through.

> > I must admit I've never had anything to do with creating Win32-format
> > text files. Generally the extent of my knowledge of such things is 'how
> > do I get this wretched OS to stop messing up my files?' :).
> 
> This is one of the sides of the problem.  *This* part can be fixed if
> :encoding(UCS2) would just remove :crlf flag.

Yes, but I don't think this will change either.

> >> >> 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.
> >> 
> >> How would it know this?  What is the semantic of binmode()?
> 
> > You've always had to binmode filehandles when writing binary data.
> 
> By definition, piconv does not work with binary files...

Yes it does. 'Text' as used by perl means 'some 8bit extension of ASCII,
with reasonably short lines delimited with the OS newline sequence, no
non-spacing control characters and no NULs'. By this definition UCS-2 is
(and most wide encodings are) 'binary'. -B will return true on a UCS-2
file, for instance.

> > While this is certainly possible, I somewhat doubt the behaviour of
> > :encoding will be changed now.
> 
> Given that its current behaviour makes no sense, why not?

Because perl 5.8 was released a good while ago, so people have been
working with and around the current behaviour for some time. Changing it
now would almost certainly break working code, whereas a new layer on
CPAN would not, and would allow those with old perls to get the new
behaviour if they want it.

It's possible that some sort of flag to :encoding (or to 'use
PerlIO::encoding') would be OK. Porting/Maintainters.pl says that
PerlIO::encoding is not currently dual-life, which may make upgrading a
little tricky; but that's not a new problem. Obviously, if you wish to
take this to p5p, feel free :).

Ben



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

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


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