[29032] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 276 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Mar 28 06:14:13 2007

Date: Wed, 28 Mar 2007 03:14:05 -0700 (PDT)
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, 28 Mar 2007     Volume: 11 Number: 276

Today's topics:
    Re: Replacing characters in file <jurgenex@hotmail.com>
    Re: Replacing characters in file <anony-mouse@hole.in.the.wall.com>
    Re: Replacing characters in file <bik.mido@tiscalinet.it>
    Re: Replacing characters in file <bik.mido@tiscalinet.it>
    Re: Replacing characters in file <bik.mido@tiscalinet.it>
    Re: Replacing characters in file <bik.mido@tiscalinet.it>
    Re: Sweetest Accessor? <please@nospam.net>
    Re: Troubleshooting cpan <thepoet_nospam@arcor.de>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Wed, 28 Mar 2007 05:42:39 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: Replacing characters in file
Message-Id: <jfnOh.2170$Rp2.838@trndny04>

Anony-mouse wrote:
> In article <%7iOh.1641$Rp2.877@trndny04>, "Jürgen Exner"
> <jurgenex@hotmail.com> wrote:
>
>> Anony-mouse wrote:
>>> In article <Z9aOh.3620$J21.675@trndny03>, "Jürgen Exner"
>>>> If on the other hand you don't have a text file, then maybe it is
>>>> time to stop treating it as a text file but start handling it as a
>>>> binary file instead.
>>>
>>> It's not a text file. As I said it's a .DAT file
>>
>> Whatever that is supposed to mean.
>> A file name ending of .DAT doesn't imply anything as to the content
>> of the file.
>
> Although not necessarily true, it does imply that it's not a simple
> .TXT file.

Well, the file ending has no bearing on the content of a file. So, yes and 
so what?

>>> that contains control
>>> characters, including EOF ones.  :o\
>>
>> Well, if it is not a text file but a binary file, then it isn't very
>> meaningful to talk about characters.
>> It would have been much less confusing if you had said "I have a
>> two-byte sequence"01 5F" (denoted in hex) and like to replace it
>> with "01 5C".
>
> Symantics (or pendaticism, whichever you prefer).

Not really. Computers are notorious at being extremely pedantic. You will 
have much success when dealing with computers if you adapt a precise 
language, too.

> It still means the
> same thing

Well, it doesn't. A character and a byte are two very different things. And 
a text file and data/binary file are two very different things, too.

> and some people seem to have understood what I was saying,

Some people are better in guessing than others.

> while others simply want to get picky about terminology.

As I mentioned, terminology is important when dealing with something as 
pedantic as computers.

>> I still don't understand why a simply
>>     s/\x01\x5F/\x01\x5C/g
>> shouldn't work.
>
> It doesn't work in SED because SED aborts when it hits the first EOF
> character and so doesn't complete the file.

Not surprising. AFAIK SED is designed to work for text files and files that 
contain text by definition don't have any content after an EOF. Do you now 
realize how important the distinction between text and binary files is 
sometimes?

> In the version of Perl I've been using it simply does nothing - I get
> a completely empty result file.

And which version would that be?
    perl -v

jue

I'll have to wait until I finish
> downloading Active Perl and see what happens there, but that may be
> too big in filesize for my needs.
>
>
>                           _
>                         _/ \___
> Anony-mouse says     o_/O _/   \
>  "Eek-eek-eek!"       \__/_|_/_|\____/ 




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

Date: Wed, 28 Mar 2007 18:31:24 +1200
From: Anony-mouse <anony-mouse@hole.in.the.wall.com>
Subject: Re: Replacing characters in file
Message-Id: <280320071831245870%anony-mouse@hole.in.the.wall.com>


Many thanks to Klaus and a couple of others who actually tried to help
me with this problem by posting sensible replies, but I now give up
wasting time with Perl and this newsgroup. 

It's simply not worth the hassle dealing with the pedantic fools in
this newsgroup that simply want to prove how clever they are by
nitpicking teminology. Thanks for nothing.  :o(


                           _
                         _/ \___
 Anony-mouse says     o_/O _/   \
  "Eek-eek-eek!"       \__/_|_/_|\____/


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

Date: Wed, 28 Mar 2007 10:59:00 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: Replacing characters in file
Message-Id: <058k039icfiihrt76rjuctnrfg0re1uqq9@4ax.com>

On Wed, 28 Mar 2007 12:40:14 +1200, Anony-mouse
<anony-mouse@hole.in.the.wall.com> wrote:

>> > It's not a text file. As I said it's a .DAT file
>> 
>> Whatever that is supposed to mean.
>> A file name ending of .DAT doesn't imply anything as to the content of the 
>> file.
>
>Although not necessarily true, it does imply that it's not a simple
>.TXT file.  

Again there's not such a thing as "a simple .TXT file" - although the
 .txt or .TXT extension is often associated to text files, there's no
way for an extension to force the contents of the file, not even on
systems where associations play a major role.

>> > that contains control
>> > characters, including EOF ones.  :o\
>> 
>> Well, if it is not a text file but a binary file, then it isn't very 
>> meaningful to talk about characters.
>> It would have been much less confusing if you had said "I have a two-byte 
>> sequence"01 5F" (denoted in hex) and like to replace it with "01 5C".
>
>Symantics (or pendaticism, whichever you prefer). It still means the
>same thing and some people seem to have understood what I was saying,
>while others simply want to get picky about terminology.

No, most definitely they do *NOT* mean the same thing. That some
people *DID* understand you, is a whole another story.

>> I still don't understand why a simply
>>     s/\x01\x5F/\x01\x5C/g
>> shouldn't work.
>
>It doesn't work in SED because SED aborts when it hits the first EOF
>character and so doesn't complete the file.
>
>In the version of Perl I've been using it simply does nothing - I get a
>completely empty result file. I'll have to wait until I finish

What code did you try exactly? It's hard to believe your claim.

  #!/usr/bin/perl
  
  use strict;
  use warnings;
  
  open my $fh, '+>:raw', undef 
    or die "Can't open temp file: $!\n";
  print $fh do{
      my $t=join '' => map chr, 0..255;
      join "\x01\x5F" => ($t) x 5;
  };
  seek $fh, 0, 0;
  {
      local $/;
      print "I made ",
        s/\x01\x5F/\x01\x5C/g,
        " substitutions\n" while <$fh>;
  }
  
  __END__

>downloading Active Perl and see what happens there, but that may be too
>big in filesize for my needs.

And I explained to you how you can cope with this problem in another
post.

Consider the above program, it's in test.pl:

  C:\temp>pp -o test.exe test.pl
  
  C:\temp>wc -c test.exe
  1829658 test.exe

Isn't that small enough for you?


HTH,
Michele
-- 
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
 .'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,


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

Date: Wed, 28 Mar 2007 11:03:49 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: Replacing characters in file
Message-Id: <clbk03p00p7cgjgdv80gr4hl5snf0qhhm7@4ax.com>

On Wed, 28 Mar 2007 08:55:35 +1200, Anony-mouse
<anony-mouse@hole.in.the.wall.com> wrote:

>> I understood that. Now, did you understand I suggested you to upgrade?
>
>As I said in a previous message. I was using an old version that was
>nice and small (around 300K) to fit on a Flash drive. Obvoiusly this
>old version doesn't like the Mbytes and Mopen options. 

I'm afraid that would be a very, very old version...

>I'm trying to get the Active Perl that the original person was using,
>but it's 15MB and I'm on a limited time dial-up account, so it will
>take a while before I can even try it. Although that's the installer
>filesize, it may well turn out that the version of Perl is simply too
>big for my needs anyway.

  ppm install par
  perldoc pp

I gave you an explicit example in another post I just sent you. Is
1.7Mb small enough to fit on your flash drive?


Michele
-- 
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
 .'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,


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

Date: Wed, 28 Mar 2007 11:07:06 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: Replacing characters in file
Message-Id: <vvbk03p82ll7l3bf5qookh32gcgfauj92t@4ax.com>

On Wed, 28 Mar 2007 12:45:05 +1200, Anony-mouse
<anony-mouse@hole.in.the.wall.com> wrote:

>> I think it is best that you rephrase your question to something like:
>> I want to replace, in a binary file on a DOS-type system, the
>> two-byte-sequence "0x01 0x5F" by "0x01 0x5C".
>
>The terminology is irrelevant since some people have obvoiusly
>understood.

The terminology is *relevant* since more people would have obvoiusly
understood, had you used a correct one.


Michele
-- 
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
 .'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,


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

Date: Wed, 28 Mar 2007 11:09:38 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: Replacing characters in file
Message-Id: <p5ck03hkmkk9ok6l50eoiv9ogj7u2d0rme@4ax.com>

On Tue, 27 Mar 2007 19:59:32 -0500, Uri Guttman <uri@stemsystems.com>
wrote:

>binary option enabled. do not do this with perl's -p/-n options as they
>will run in text mode. i doubt even using -0777 will work as nothing is
>telling perl or winblows that your file is binary so the ^Z will hit
>you.

The C<open> *pragma* will.


Michele
-- 
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
 .'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,


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

Date: Wed, 28 Mar 2007 01:29:14 -0700
From: Xiong Changnian <please@nospam.net>
Subject: Re: Sweetest Accessor?
Message-Id: <please-A3A2FE.01291328032007@free.teranews.com>

In article <56sml4F2758v9U1@mid.dfncis.de>,
 anno4000@radom.zrz.tu-berlin.de wrote:

> Another problem is that you won't be able to assign a boolean false
> value that way.

Well, I'm not sure that's a problem. I abhor boolean false values as a 
matter of taste. Reserving FALSE demands that every value assigned to a 
variable have a TRUE value (obviously) and I think that's good style. I 
realize that someone else will be quite comfortable with, say, integer 
zero values in some places and require an accessor that permits them. I 
just don't. 

If I ever thought I would want deliberately to set a variable inside a 
complex data structure to 0, "", or undef, I'd write a distinct "clear" 
method. 


> The standard get-set accessor in Perl is
> 
>     sub name {
>         my $obj = shift;
>         $obj->{ name} = shift if @_;
>         $obj->{ name};
>     }

No offense, but that's neither short nor sweet. I particularly don't 
care for mixing shift and @_ in the same sub -- visually. 

Of course, a working accessor might be written in any number of ways and 
perhaps there are several idioms that will all compile to equivalent 
byte code or be equally efficient. My immediate goal here is terseness, 
sweetness -- "niftyness", if you will. Sorry if that sounds trivial. 


>     sub name : lvalue { shift()->{ name} }

I really, really like the idea of lvalue subs. They make calling syntax 
much more symmetrical and "natural". I was scared off by dire warnings 
(eg):

"WARNING: Lvalue subroutines are still experimental and the 
implementation may change in future versions of Perl." 

I'd welcome comments. Are lvalue subs coming or going? Will my code blow 
up next release? 

I would like to see what sort of Frankenstein's Monsters I can build 
with lvalue subs, prototypes, and overloading. I'm sure any code I post 
from that lab will raise eyebrows. 


In article <ddaOh.131662$_73.108653@newsread2.news.pas.earthlink.net>,
 "Mumia W." <paduille.4060.mumia.w+nospam@earthlink.net> wrote:

> perldoc Class::Accessor

I'm sure you mean well but you must be a get-the-job-done type. It's 
useless to me to let George do it; I'm experimenting. 

FWIW, here's what the indicated module's doc says it generates: 

    # Your foo may vary.
    sub foo {
        my($self) = shift;
        if(@_) {    # set
            return $self->set('foo', @_);
        }
        else {
            return $self->get('foo');
        }
    }

That is definitely not a terse idiom. 

I dunno, but maybe my METHOD2 is as far as one can go in my chosen 
direction: 

   METHOD2:

   sub name {
      $_[1] ? $_[0]->{NAME} = 
      $_[1] : $_[0]->{NAME};
   };

Still, nothing can beat the lvalue sub for sheer terse beauty. If only 
we could depend on it?
-- 
Xiong Changnian
xiong102ATxuefangDOTcom

-- 
Posted via a free Usenet account from http://www.teranews.com



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

Date: Wed, 28 Mar 2007 07:53:23 +0200
From: Christian Winter <thepoet_nospam@arcor.de>
Subject: Re: Troubleshooting cpan
Message-Id: <460a02d3$0$6398$9b4e6d93@newsspool2.arcor-online.net>

kj wrote:
> When I try to use the cpan command, attempts to fetch files (e.g.
> 01mailrc.txt.gz) time out.  This happens in 2 out of the 3 machines
> I've tried it on, all of which live in the same LAN and behind the
> same firewall.  I can't figure out why cpan works in one of the
> machines but not in the others.  The two "failing machines" are
> entirely different (a SuSE Linux box and an iMac).  The machine
> where cpan works is another SuSE Linux box.
> 
> More confusingly still, I can download 01mailrc.txt.gz from the
> "failing machines" if I use wget, which rules out some major
> connection problem.  Unfortunately, cpan does not emit any diagnostic
> to explain why its attempts to download files time out.  Why would
> cpan fail when wget succeeds on the same machine?

Does the machine from which it works have, by any chance, either
an environment variable FTP_PASSIVE set or the option
"ftp_int_passive" enabled in libnet.cfg? If not, has it got
an ftp_proxy environment setting that the others are missing?

-Chris


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

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


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