[30973] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 2218 Volume: 11

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

Date: Wed, 18 Feb 2009 11:09:16 -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: 2218

Today's topics:
        extracting values from vmstat output <alfonso.baldaserra@gmail.com>
    Re: extracting values from vmstat output <tadmc@seesig.invalid>
    Re: extracting values from vmstat output (Greg Bacon)
    Re: extracting values from vmstat output <uri@stemsystems.com>
    Re: Net::SSH2 scp_put not working! <zentara@highstream.net>
    Re: Net::SSH2 scp_put not working! <tadmc@seesig.invalid>
    Re: Net::SSH2 scp_put not working! <schaitan@gmail.com>
    Re: Net::SSH2 scp_put not working! <noreply@gunnar.cc>
    Re: PERL windows : "Windows cannot access the specified <tadmc@seesig.invalid>
        PERL windows : "Windows cannot access the specified dev <guru.naveen@gmail.com>
    Re: PERL windows : "Windows cannot access the specified <noreply@gunnar.cc>
    Re: PERL windows : "Windows cannot access the specified <noreply@gunnar.cc>
    Re: PERL windows : "Windows cannot access the specified <glex_no-spam@qwest-spam-no.invalid>
    Re: Read/write with UCS-2* encodings - Possible??? <nospam-abuse@ilyaz.org>
    Re: Read/write with UCS-2* encodings - Possible??? <perl@marc-s.de>
    Re: Read/write with UCS-2* encodings - Possible??? <hjp-usenet2@hjp.at>
    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 05:06:42 -0800 (PST)
From: alfonsobaldaserra <alfonso.baldaserra@gmail.com>
Subject: extracting values from vmstat output
Message-Id: <cc949bdf-adf1-45b1-a565-7422e418edaf@q38g2000prq.googlegroups.com>

hi list,

i'm trying to calculate memory pages on aix platform.  the output of

$ vmstat -v  is like
              2031616 memory pages
              1953185 lruable pages
               935166 free pages
                    1 memory pools
               170943 pinned pages
                 80.0 maxpin percentage
                  3.0 minperm percentage
                 90.0 maxperm percentage
                  6.8 numperm percentage
               133573 file pages
                  0.0 compressed percentage
                    0 compressed pages
                  6.8 numclient percentage
                 90.0 maxclient percentage
               133573 client pages
                    0 remote pageouts scheduled
                   81 pending disk I/Os blocked with no pbuf
                    0 paging space I/Os blocked with no psbuf
                 2484 filesystem I/Os blocked with no fsbuf
                    0 client filesystem I/Os blocked with no fsbuf
                  451 external pager filesystem I/Os blocked with no
fsbuf
                    0 Virtualized Partition Memory Page Faults
                 0.00 Time resolving virtualized partition memory page
faults

in perl code i'm storing this value into a variable

my @vmstat = system("vmstat -v");

now i want to extract the numerical values of memory pages and free
pages.  what is the best possible way to do that?

thanks in advance


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

Date: Wed, 18 Feb 2009 08:02:49 -0600
From: Tad J McClellan <tadmc@seesig.invalid>
Subject: Re: extracting values from vmstat output
Message-Id: <slrngpo589.csm.tadmc@tadmc30.sbcglobal.net>

alfonsobaldaserra <alfonso.baldaserra@gmail.com> wrote:

> $ vmstat -v  is like
>               2031616 memory pages
>               1953185 lruable pages
>                935166 free pages
>                     1 memory pools
>                170943 pinned pages
>                  80.0 maxpin percentage
>                   3.0 minperm percentage
>                  90.0 maxperm percentage
>                   6.8 numperm percentage
>                133573 file pages
>                   0.0 compressed percentage
>                     0 compressed pages
>                   6.8 numclient percentage
>                  90.0 maxclient percentage
>                133573 client pages
>                     0 remote pageouts scheduled
>                    81 pending disk I/Os blocked with no pbuf
>                     0 paging space I/Os blocked with no psbuf
>                  2484 filesystem I/Os blocked with no fsbuf
>                     0 client filesystem I/Os blocked with no fsbuf
>                   451 external pager filesystem I/Os blocked with no
> fsbuf
>                     0 Virtualized Partition Memory Page Faults
>                  0.00 Time resolving virtualized partition memory page
> faults
>
> in perl code i'm storing this value into a variable


No you're not. You are storing some other value into a one-element array.


> my @vmstat = system("vmstat -v");


Have you examined the contents of @vmstat?

It does not contain what you think it contains...

You should read the documentation for the functions that you use:

    perldoc -f system


> now i want to extract the numerical values of memory pages and free
> pages.  what is the best possible way to do that?


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


-- 
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"


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

Date: Wed, 18 Feb 2009 12:15:11 -0600
From: gbacon@hiwaay.net (Greg Bacon)
Subject: Re: extracting values from vmstat output
Message-Id: <VZydnYz4ENayzQHUnZ2dnUVZ_gmWnZ2d@posted.hiwaay2>

In article <cc949bdf-adf1-45b1-a565-7422e418edaf@q38g2000prq.googlegroups.com>,
    alfonsobaldaserra  <alfonso.baldaserra@gmail.com> wrote:

: [...]
: my @vmstat = system("vmstat -v");

Perl's system operator returns an exit status (a number), not the
program's output. Use backticks or qx -- search the perlop manpage
for qx/STRING/ or `STRING` -- instead.

: now i want to extract the numerical values of memory pages and free
: pages.  what is the best possible way to do that?

Below, I explain a couple of ways to do it.

    #! /usr/bin/perl

    use warnings;
    use strict;

    no warnings "exec";

    open my $fh, "vmstat -v |"
      or die "$0: can't execute vmstat: $!\n";

    my %vmstat;

    while (<$fh>) {
      chomp;
      my($n,$desc) = split " ", $_, 2;

      $vmstat{$desc} = $n;
    }

    print "Memory pages: $vmstat{'memory pages'}\n",
          "Free pages:   $vmstat{'free pages'}\n";

When the filename argument to open ends with a pipe, Perl runs the
named command and makes its output available on the returned
filehandle. I turn off the autogenerated error (no warnings "exec")
because I like my format better.

Looking at vmstat's output, each line has a value and a description,
so the plan is to read each line and stash the parameters where we
can find them later. A hash is a perfect data structure for this
task.

Most of the time, the pattern to the split operator is a regular
expression, but with no arguments (or a pattern of a lone space)
it acts like awk, throwing away leading whitespace. Because the
descriptions contain spaces, we don't want to split on them and
tell Perl to give us back exactly two fields.

The output is straightforward: print the desired values.

You can of course be more clever:

    #! /usr/bin/perl

    %vmstat = reverse `vmstat -v` =~ /(\S+) (.+)/g;

    print "Memory pages: $vmstat{'memory pages'}\n",
          "Free pages:   $vmstat{'free pages'}\n";

Instead of a piped open, this time we use backticks (``) to capture
vmstat's output and from the output extract the values and
descriptions.

The regular expression \S+ means a sequence of one or more
non-whitespace characters, and this matches the numbers in the
output. You might be tempted to use \d+ (one or more digits),
but this will give you surprising results on the floating-point
numbers.

By default, dot does not match newline, so the (.+) subpattern
matches through the rest of the current line -- the description
in this case.

The /g regular-expression switch means we get all possible non-
overlapping matches.

The list returned from the match will look like (2031616,
"memory pages", 1953185, "lruable pages", ...), but that's
the opposite order from hash initialization, i.e., key then
value. The reverse operator fixes this problem.

Hope this helps,
Greg
-- 
For purposes of controversy this is logically sufficient, since, free
trade being natural trade, the onus of proof must lie upon those who
would restrict it.
    -- Henry George, Protection or Free Trade


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

Date: Wed, 18 Feb 2009 13:57:33 -0500
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: extracting values from vmstat output
Message-Id: <x7wsbn609u.fsf@mail.sysarch.com>

>>>>> "GB" == Greg Bacon <gbacon@hiwaay.net> writes:

  GB>     no warnings "exec";

why is that needed?

  GB>     open my $fh, "vmstat -v |"
  GB>       or die "$0: can't execute vmstat: $!\n";

as you said a qx would work too and would be simpler. in a list context
it returns lines so you could do a for loop. i doubt it will generate
too many lines.

  GB>     %vmstat = reverse `vmstat -v` =~ /(\S+) (.+)/g;

that is how i would do it and i thought of the same code before i saw
yours. i do a very similar thing with file::slurp and parsing simple
config files. parsing a multiline string with m//g into a key/value list
and assigning directly to a hash is a great and underused idiom. it is
also much faster than looping over lines and parsing each one and
assigning into the hash.

uri

-- 
Uri Guttman  ------  uri@stemsystems.com  --------  http://www.sysarch.com --
-----  Perl Code Review , Architecture, Development, Training, Support ------
--------- Free Perl Training --- http://perlhunter.com/college.html ---------
---------  Gourmet Hot Cocoa Mix  ----  http://bestfriendscocoa.com ---------


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

Date: Wed, 18 Feb 2009 05:27:07 -0500
From: zentara <zentara@highstream.net>
Subject: Re: Net::SSH2 scp_put not working!
Message-Id: <61onp4di0h1klsn185he03henpfj7clvqc@4ax.com>

On Tue, 17 Feb 2009 06:17:40 -0800 (PST), Krishna Chaitanya
<schaitan@gmail.com> wrote:

>Hi,
>
>This is from Net::SSH2 documentation of scp_put :
>
>===============================
>
>scp_put ( local [, remote ] )
>
>
>So I ran my program through perl -d and when it came to the line
>having _scp_put, I printed out values of variables $path and $remote
>and their values were "/home/perl_progs/2.pl" and "2.pl" ($remote is
>filled up by basename as seen in code above). Now it's clear that both
>the local and remote variables have values.....but shouldn't $remote
>have some mention of the remote "DIRECTORY" too?

Yeah, thats my point...it NEEDS the directory too. It wants fully
qualified pathnames to \ on the remote machine. I don't think it
gaurantees that you intend the transfer with an automatic pathname
created by some regex than sends the localfilename to the cwd
on the remote machine.  It is more secure than that...it demands
you know the full path on the remote computer.

>Also, where does _scp_put function exist? It looks from naming
>convention like a method from a base class. I even tried doing an "nm"
>on libssh2.* in /usr/lib (where I installed libssh2).
>
>Thanks,
>Chaitanya
All that stuff is hidden in the XS stuff that accesses the libssh2 c
libs.  You rarely need to question those libs and their access, they are
widely scruntized.
As a Perl scripter, you don't need to know the inner workings....that is
for the security people to decide. Suffice it to say, that SSH code is
not the easiest stuff to comprehend, at least for me anyways. :-)

zentara


-- 
I'm not really a human, but I play one on earth.
http://www.zentara.net/~zentaran/My_Petition_to_the_Great_Cosmic_Conciousness.html 


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

Date: Wed, 18 Feb 2009 06:31:03 -0600
From: Tad J McClellan <tadmc@seesig.invalid>
Subject: Re: Net::SSH2 scp_put not working!
Message-Id: <slrngpnvs7.c09.tadmc@tadmc30.sbcglobal.net>

Krishna Chaitanya <schaitan@gmail.com> wrote:

> Bumping this up...


Scoring this OP down...

(Usenet is not a BBS)


-- 
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"


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

Date: Wed, 18 Feb 2009 08:27:14 -0800 (PST)
From: Krishna Chaitanya <schaitan@gmail.com>
Subject: Re: Net::SSH2 scp_put not working!
Message-Id: <b177e592-cbdd-41e7-a8d5-1aa24214263a@b38g2000prf.googlegroups.com>

Hi Ted, sorry...I'm new to groups, I'll keep in mind not to bump any
posts...

Hi Zentara,

If it NEEDS the directory, then why would it document the remote path
as optional (conventionally...anything in square brackets...)? Also, I
had pasted the code of scp_put function for your review.....and in it,
the $remote variable is filled up by doing a basename on $file ....
which means it intends to only grab the file's basename.....why this
issue then? Can anyone answer please?

-Chaitanya


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

Date: Wed, 18 Feb 2009 19:10:34 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Net::SSH2 scp_put not working!
Message-Id: <7031cnFmmvcsU1@mid.individual.net>

Krishna Chaitanya wrote:
> Can anyone answer please?

You ignored my suggestion to have Net::SSH2 tell you *why* scp_put fails 
(without digging in the source code).

-- 
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl


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

Date: Wed, 18 Feb 2009 06:44:04 -0600
From: Tad J McClellan <tadmc@seesig.invalid>
Subject: Re: PERL windows : "Windows cannot access the specified device, path or  file. You may not have the appropriate permission to access the item."
Message-Id: <slrngpo0kk.c09.tadmc@tadmc30.sbcglobal.net>

guru <guru.naveen@gmail.com> wrote:


> I am getting following error
> "
> "Windows cannot access the specified device, path or file. You may not
> have the appropriate permission to access the item."


> take each file and concatenate them to a list
>
> like:
>
> while($filename = readdir(DIR))
> {
> 	$list .= $filename;
> }


So if readdir() returns "1.doc" and "2.doc", then $list (which is not a list)
will contain "1.doc2.doc".

Is that what you wanted to do?

Did you try printing out $list after the while loop?


-- 
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"


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

Date: Wed, 18 Feb 2009 03:11:26 -0800 (PST)
From: guru <guru.naveen@gmail.com>
Subject: PERL windows : "Windows cannot access the specified device, path or  file. You may not have the appropriate permission to access the item."
Message-Id: <1f08dee0-e7e7-48db-b4df-705679b963cc@s9g2000prg.googlegroups.com>

Hi,

I am getting following error
"
"Windows cannot access the specified device, path or file. You may not
have the appropriate permission to access the item."

When i tried to pass a list consisting of 300 file names.

Scenario:

folder F:\Testing\loc\

Contains around 300 files

I have to pass these files as parameter to one perl script .pl,
where these files are processed( opened and read).

Alg:

take each file and concatenate them to a list

like:

while($filename = readdir(DIR))
{
	$list .= $filename;
}

At the end, the list contains 300 file names.

When I pass this as parameter to .pl file in windows it is throwing
error:

"Windows cannot access the specified device, path or file. You may not
have the appropriate permission
to access the item."

But when I create list of around 70 files and pass then it is working
fine.

But passing list of files as argument in linux is working fine. But
failing in windows.

Is there any alternative way to resolve this problem.

Thanks & Regards
Gururaja


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

Date: Wed, 18 Feb 2009 15:22:38 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: PERL windows : "Windows cannot access the specified device, path or    file. You may not have the appropriate permission to access the item."
Message-Id: <702k1bFmeph2U1@mid.individual.net>

guru wrote:
> 
> while($filename = readdir(DIR))
> {
> 	$list .= $filename;
> }

How about

     my $list = join ' ', readdir DIR;

-- 
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl


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

Date: Wed, 18 Feb 2009 16:30:32 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: PERL windows : "Windows cannot access the specified device, path or    file. You may not have the appropriate permission to access the item."
Message-Id: <702o0lFmb437U1@mid.individual.net>

guru wrote:
> 
> folder F:\Testing\loc\
> 
> Contains around 300 files
> 
> I have to pass these files as parameter to one perl script .pl,
> where these files are processed( opened and read).
> 
> Alg:
> 
> take each file and concatenate them to a list
> 
> like:
> 
> while($filename = readdir(DIR))
> {
> 	$list .= $filename;
> }
> 
> At the end, the list contains 300 file names.
> 
> When I pass this as parameter to .pl file in windows it is throwing
> error:
> 
> "Windows cannot access the specified device, path or file. You may not
> have the appropriate permission
> to access the item."

Can it possibly be that there is a space in one or more of the files? In 
that case you may want to try:

     my $list = '"' . join('" "', grep !/^\.{1,2}/, readdir DIR) . '"';

-- 
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl


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

Date: Wed, 18 Feb 2009 10:46:19 -0600
From: "J. Gleixner" <glex_no-spam@qwest-spam-no.invalid>
Subject: Re: PERL windows : "Windows cannot access the specified device, path or  file. You may not have the appropriate permission to access the item."
Message-Id: <499c3b5b$0$87071$815e3792@news.qwest.net>

guru wrote:
> Hi,
> 
> I am getting following error
> "
> "Windows cannot access the specified device, path or file. You may not
> have the appropriate permission to access the item."
> 
> When i tried to pass a list consisting of 300 file names.
> 
> Scenario:
> 
> folder F:\Testing\loc\
> 
> Contains around 300 files
> 
> I have to pass these files as parameter to one perl script .pl,
> where these files are processed( opened and read).

How are you passing the files and how is the other program
reading the input?


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

Date: Wed, 18 Feb 2009 10:26:19 GMT
From: Ilya Zakharevich <nospam-abuse@ilyaz.org>
Subject: Re: Read/write with UCS-2* encodings - Possible???
Message-Id: <slrngpnoib.mqs.nospam-abuse@chorin.math.berkeley.edu>

On 2009-02-17, Ben Morrow <ben@morrow.me.uk> wrote:
> (You presumably know you can use
>
>     binmode STDOUT, ":raw:encoding(UCS-2):crlf";
>
> rather that three separate statements?)

No, I did not.  And adding :utf8 at the end fixes a warning as well.

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";

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...

(When this works, a lot of programs would magically start to work as expected.)

>> 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()?  As usual,
the documentation is close to useless:

  The directives alter the behaviour of the file handle.

Thank a lot!!!  HOW do they alter the behaviour???  Is the intent to
be incremental (:crlf does not change the encoding layers), or is the
semantic to remove all the layers, and add the specified ones?

>> 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.

No, I think this is not adding weirdness, but using it.  IIRC, the
'binmode' directive is passed through the layers, and they have a
possibility to handle it.

The wide-char encoding layer should notice that somebody wants to add
:crlf, and should not let it pass through itself: the newly created
layer should be anchored `before' the encoding layer.

Yours,
Ilya


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

Date: Wed, 18 Feb 2009 14:04:29 +0100
From: Marc Lucksch <perl@marc-s.de>
Subject: Re: Read/write with UCS-2* encodings - Possible???
Message-Id: <gnh100$1h5s$1@ariadne.rz.tu-clausthal.de>

Ilya Zakharevich schrieb:
>   binmode STDOUT, ":raw:encoding(UCS-2):crlf";
> 
> 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...

binmode STDOUT ":pop"; #Removes the topmost layer

See perldoc perlio:

 > :pop
 >
 > A pseudo layer that removes the top-most layer. Gives perl code a way
 > to manipulate the layer stack. Should be considered as experimental.
 > Note that :pop only works on real layers and will not undo the effects
 > of pseudo layers like :utf8 .


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

Date: Wed, 18 Feb 2009 14:56:11 +0100
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: Read/write with UCS-2* encodings - Possible???
Message-Id: <slrngpo4rs.m8.hjp-usenet2@hrunkner.hjp.at>

On 2009-02-18 13:04, Marc Lucksch <perl@marc-s.de> wrote:
> Ilya Zakharevich schrieb:
>>   binmode STDOUT, ":raw:encoding(UCS-2):crlf";
>> 
>> 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...
>
> binmode STDOUT ":pop"; #Removes the topmost layer
>
> See perldoc perlio:
>
> > :pop
> >
> > A pseudo layer that removes the top-most layer. Gives perl code a way
> > to manipulate the layer stack. Should be considered as experimental.
> > Note that :pop only works on real layers and will not undo the effects
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> > of pseudo layers like :utf8 .
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^

:crlf is a pseudo-layer.

	hp


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

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


Quoth Ilya Zakharevich <nospam-abuse@ilyaz.org>:
> On 2009-02-17, Ben Morrow <ben@morrow.me.uk> wrote:
> > (You presumably know you can use
> >
> >     binmode STDOUT, ":raw:encoding(UCS-2):crlf";
> >
> > rather that three separate statements?)
> 
> No, I did not.  And adding :utf8 at the end fixes a warning as well.
> 
> 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'. 

> 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. 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 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?' :).

> >> 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.

> As usual,
> the documentation is close to useless:
> 
>   The directives alter the behaviour of the file handle.
> 
> Thank a lot!!!  HOW do they alter the behaviour???  Is the intent to
> be incremental (:crlf does not change the encoding layers), or is the
> semantic to remove all the layers, and add the specified ones?

Read the next paragraph, which directs you to L<PerlIO>? Basically the
semantic is that layers are pushed, but the a special 'pushed' method is
called on the layer, so it can change the stack at that point. Some
layers (like :raw and :pop) look down through the stack and remove some
other layers in their 'pushed' method. :crlf has its own weird behaviour
(documented in PerlIO) which is why I would always prefer :eol.

> >> 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.
> 
> No, I think this is not adding weirdness, but using it.  IIRC, the
> 'binmode' directive is passed through the layers, and they have a
> possibility to handle it.

Err... don't remember :). It's a while since I've looked at perliol.c.
It may be that just the (new) top layer is notified, and the other
layers only get called if the top layer chooses to.

> The wide-char encoding layer should notice that somebody wants to add
> :crlf, and should not let it pass through itself: the newly created
> layer should be anchored `before' the encoding layer.

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. While this is certainly possible, I
somewhat doubt the behaviour of :encoding will be changed now. Again,
writing a replacement for :encoding that does this wouldn't be too hard.

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


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