[26426] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 8596 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Nov 2 03:05:40 2005

Date: Wed, 2 Nov 2005 00:05:07 -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, 2 Nov 2005     Volume: 10 Number: 8596

Today's topics:
    Re: Bug in &= (bitwise or) <tassilo.von.parseval@rwth-aachen.de>
        dynamically adding member sub to object? <casabianca@suplitein.junk.de.net.org.com>
        FAQ 4.34 How do I extract selected columns from a strin <comdog@pair.com>
        Find a hex digit. <VSRawat@Invalid.none>
    Re: Find a hex digit. <someone@example.com>
    Re: Find a hex digit. <someone@example.com>
    Re: IIS 5.1 + Perl <1usa@llenroc.ude.invalid>
    Re: IIS 5.1 + Perl <noreply@gunnar.cc>
    Re: passing data <news@cutmeukjay.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Wed, 2 Nov 2005 08:40:36 +0100
From: "Tassilo v. Parseval" <tassilo.von.parseval@rwth-aachen.de>
Subject: Re: Bug in &= (bitwise or)
Message-Id: <3sr8rnFppq7qU1@news.dfncis.de>

Also sprach Ilya Zakharevich:

><tassilo.von.parseval@rwth-aachen.de>], who wrote in article <3snf0uFotcprU1@news.dfncis.de>:
>> For testing what the raw string looks like after the bitwise-and, you
>> can use:
>
> Is not it much easier to parse the output of Devel::Peek, and read the
> PV by unpack()?

No, it wasn't for me. :-)

Can you give an example how to do it with unpack? I feel the 'P'
template is needed but I never know how to use that one.

>>     my $a = 'aa';
>>     $a &= 'a';
>>     test($a);
>
> For those who are too lazy to run this, the result it
>
>   97,97,0
>
>> Then I am not sure myself what the result of
>> 
>>     $s = 'aa' & 'a'
>> 
>> should be.
>
> I think the current result is both correct and intuitive enough
> (modulo two bugs which comprise this problem).  It is compatible with
> both
>
>    a) junk-in-junk-out		("what is after end of 'a' is junk")
>    b) strings behave as if followed by infinitely many \0s.
>
> By (b), the output string should also be considered as having
> infinitely many \0s; the question is where to stop this flow.  And (a)
> looks as a reasonable argument to choose this cut-off point.

What are those two bugs you mentioned? For me the real bug is that an
'impossible' string value can be constructed thus. I would expect:

    ('aa' & 'a') eq "a\0"

Taking (b) into account, the smaller string should be padded with '\0'
which, on bit-wise ANDing, should yield '\0'.

There's another oddity:
   
$ perl -MDevel::Peek -e 'my $a = 'aa'; $a &= 'a'; Dump($a)'
SV = PV(0x814ce90) at 0x814cc6c
  REFCNT = 1
  FLAGS = (PADBUSY,PADMY,POK,pPOK)
  PV = 0x815d628 "a"
  CUR = 1
  LEN = 3

$ perl -MDevel::Peek -e 'my $a = 'aa' & 'a'; Dump($a)'
SV = PV(0x814cf20) at 0x814cc6c
  REFCNT = 1
  FLAGS = (PADBUSY,PADMY,POK,pPOK)
  PV = 0x815c0e8 "a"\0
  CUR = 1
  LEN = 2

Why are those two not equivalent?

> [My opinion may be a little bit skewed, since I do not remember
> whether it was me who decided on this behaviour.  ;-]

I am sure it is. ;-)

Tassilo
-- 
use bigint;
$n=71423350343770280161397026330337371139054411854220053437565440;
$m=-8,;;$_=$n&(0xff)<<$m,,$_>>=$m,,print+chr,,while(($m+=8)<=200);


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

Date: Tue, 1 Nov 2005 21:15:25 -0800
From: "Eckstein C." <casabianca@suplitein.junk.de.net.org.com>
Subject: dynamically adding member sub to object?
Message-Id: <3sr0btFpmhehU1@individual.net>

Take this code:

[Code]
   package SomeClass;

   sub new {
      my $this = shift;
      my $class = ref($this) || $this;
      my $obj; # { Val = 1 };
      $obj->{'SomeProp1'} = '';
      $obj->{'SomeProp2'} = '';

      bless $obj, $class;
      return $obj;
   }

   package main;

   print "<pre>" if $ENV{'HTTP_HOST'};

   my $c = new SomeClass;
[/Code]

(The above is just an example, and only for the purposes of my question, 
more below.)

The /actual/ class and construction code are out of my hands (generated 
by COM objects or sorts,) in a program that allows for Perl scripting, 
mostly used for event handling, and provides "built in" objects, such as 
$Server (Server object for the script's context), $Window (currrent 
Window object), etc.

Ok, here is ever my question comes in. "read only properties" are member 
subs, ie $Server->Name;, while "read/write properties" are 
$Server->{SomeProp};

What I want to do is go through each "property" of a given $Obj and 
(dynamically) create a (lvalue) sub for each one (added to the 
"properties" object of course.)

[Code]
   sub SomeProp : lvalue {
      my $this = shift;
      $this->{'SomeProp'};
   }
[/Code]

OR

sub SomeProp : lvalue { $_[0]->{'SomeProp'}; }


Is this possible? (Without using eval, as the scripts in this app seem 
to be wrapped in a eval behind the scenes, evident when theres an error 
in the code, in the error mesages. )

Thanks. 




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

Date: Wed, 2 Nov 2005 05:03:00 +0000 (UTC)
From: PerlFAQ Server <comdog@pair.com>
Subject: FAQ 4.34 How do I extract selected columns from a string?
Message-Id: <dk9ha4$2dd$1@reader2.panix.com>

This message is one of several periodic postings to comp.lang.perl.misc
intended to make it easier for perl programmers to find answers to
common questions. The core of this message represents an excerpt
from the documentation provided with Perl.

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

4.34: How do I extract selected columns from a string?

    Use substr() or unpack(), both documented in perlfunc. If you prefer
    thinking in terms of columns instead of widths, you can use this kind of
    thing:

        # determine the unpack format needed to split Linux ps output
        # arguments are cut columns
        my $fmt = cut2fmt(8, 14, 20, 26, 30, 34, 41, 47, 59, 63, 67, 72);

        sub cut2fmt {
            my(@positions) = @_;
            my $template  = '';
            my $lastpos   = 1;
            for my $place (@positions) {
                $template .= "A" . ($place - $lastpos) . " ";
                $lastpos   = $place;
            }
            $template .= "A*";
            return $template;
        }



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

Documents such as this have been called "Answers to Frequently
Asked Questions" or FAQ for short.  They represent an important
part of the Usenet tradition.  They serve to reduce the volume of
redundant traffic on a news group by providing quality answers to
questions that keep coming up.

If you are some how irritated by seeing these postings you are free
to ignore them or add the sender to your killfile.  If you find
errors or other problems with these postings please send corrections
or comments to the posting email address or to the maintainers as
directed in the perlfaq manual page.

Note that the FAQ text posted by this server may have been modified
from that distributed in the stable Perl release.  It may have been
edited to reflect the additions, changes and corrections provided
by respondents, reviewers, and critics to previous postings of
these FAQ. Complete text of these FAQ are available on request.

The perlfaq manual page contains the following copyright notice.

  AUTHOR AND COPYRIGHT

    Copyright (c) 1997-2002 Tom Christiansen and Nathan
    Torkington, and other contributors as noted. All rights 
    reserved.

This posting is provided in the hope that it will be useful but
does not represent a commitment or contract of any kind on the part
of the contributers, authors or their agents.


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

Date: 2 Nov 2005 05:04:56 +0100
From: "V S Rawat" <VSRawat@Invalid.none>
Subject: Find a hex digit.
Message-Id: <xn0e97yxg179kh000@xananews>

Saw the following in a manual.

# Find a hex digit.
$hexdigit = ('a','b','c','d','e','f')[$digit-10]; 

What is this doing, and how?
-------------------

On testing it,

for ($digit = -1;  $digit <= 20; $digit++) {
    $hexdigit = ('a','b','c','d','e','f')[$digit-10];
    print $digit, " ", $digit - 10, " ", [$digit - 10], " ",
$hexdigit, "\n";
}

---------- Capture Output ----------
-1 -11 ARRAY(0x224ed4) 
0 -10 ARRAY(0x224ed4) 
1 -9 ARRAY(0x224ed4) 
2 -8 ARRAY(0x224ed4) 
3 -7 ARRAY(0x224ed4) 
4 -6 ARRAY(0x224ed4) a
5 -5 ARRAY(0x224ed4) b
6 -4 ARRAY(0x224ed4) c
7 -3 ARRAY(0x224ed4) d
8 -2 ARRAY(0x224ed4) e
9 -1 ARRAY(0x224ed4) f
10 0 ARRAY(0x224ed4) a
11 1 ARRAY(0x224ed4) b
12 2 ARRAY(0x224ed4) c
13 3 ARRAY(0x224ed4) d
14 4 ARRAY(0x224ed4) e
15 5 ARRAY(0x224ed4) f
16 6 ARRAY(0x224ed4) 
17 7 ARRAY(0x224ed4) 
18 8 ARRAY(0x224ed4) 
19 9 ARRAY(0x224ed4) 
20 10 ARRAY(0x224ed4) 

What exactly is happening?


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

Date: Wed, 02 Nov 2005 04:33:27 GMT
From: "John W. Krahn" <someone@example.com>
Subject: Re: Find a hex digit.
Message-Id: <rkX9f.73940$S4.43807@edtnps84>

V S Rawat wrote:
> Saw the following in a manual.
> 
> # Find a hex digit.
> $hexdigit = ('a','b','c','d','e','f')[$digit-10]; 
> 
> What is this doing, and how?

()[] is a list slice where () contains the list and [] is the index of the
list.  Lookup the section "Slices" in:

perldoc perldata


> On testing it,
> 
> for ($digit = -1;  $digit <= 20; $digit++) {
>     $hexdigit = ('a','b','c','d','e','f')[$digit-10];
>     print $digit, " ", $digit - 10, " ", [$digit - 10], " ",
> $hexdigit, "\n";
> }
> 
> ---------- Capture Output ----------
> -1 -11 ARRAY(0x224ed4) 
> 0 -10 ARRAY(0x224ed4) 
> 1 -9 ARRAY(0x224ed4) 
> 2 -8 ARRAY(0x224ed4) 
> 3 -7 ARRAY(0x224ed4) 
> 4 -6 ARRAY(0x224ed4) a
> 5 -5 ARRAY(0x224ed4) b
> 6 -4 ARRAY(0x224ed4) c
> 7 -3 ARRAY(0x224ed4) d
> 8 -2 ARRAY(0x224ed4) e
> 9 -1 ARRAY(0x224ed4) f
> 10 0 ARRAY(0x224ed4) a
> 11 1 ARRAY(0x224ed4) b
> 12 2 ARRAY(0x224ed4) c
> 13 3 ARRAY(0x224ed4) d
> 14 4 ARRAY(0x224ed4) e
> 15 5 ARRAY(0x224ed4) f
> 16 6 ARRAY(0x224ed4) 
> 17 7 ARRAY(0x224ed4) 
> 18 8 ARRAY(0x224ed4) 
> 19 9 ARRAY(0x224ed4) 
> 20 10 ARRAY(0x224ed4) 
> 
> What exactly is happening?

The first column is the number, the second column is the number - 10, the
third column is an anonymous array reference and the fourth column is the
member of the list that $digit - 10 references or undef if it is outside the
range of the list.



John
-- 
use Perl;
program
fulfillment


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

Date: Wed, 02 Nov 2005 07:30:02 GMT
From: "John W. Krahn" <someone@example.com>
Subject: Re: Find a hex digit.
Message-Id: <_VZ9f.68144$yS6.42323@clgrps12>

John Bokma wrote:
> "V S Rawat" <VSRawat@Invalid.none> wrote:
> 
>>Saw the following in a manual.
>>
>># Find a hex digit.
>>$hexdigit = ('a','b','c','d','e','f')[$digit-10]; 
> 
> perldoc -f hex

hex() converts hexidecimal TO decimal.  You probably meant:

perldoc -f sprintf

As in:

my $hexdigit = sprintf '%x', $digit;



John
-- 
use Perl;
program
fulfillment


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

Date: Wed, 02 Nov 2005 02:52:31 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: IIS 5.1 + Perl
Message-Id: <Xns9701DE883653Fasu1cornelledu@127.0.0.1>

John Bokma <john@castleamber.com> wrote in
news:Xns9701CF7659F86castleamber@130.133.1.4: 

> I managed to get IIS 5.1 [1] running my hello.pl script in Firefox. 
> However, IE wants me to download it.

I don't think this problem has anything to do with the web server your are 
using, but rather with the fact that IE ignores text/plain, and tries to 
deduce content type from the file extension.

On my system, I get the same response if I try to access the default 
printenv.pl script that came with Apache.

If I change the content type to text/html, then the output of the script 
is displayed in the browser window.

Sigh.

Sinan
-- 
A. Sinan Unur <1usa@llenroc.ude.invalid>
(reverse each component and remove .invalid for email address)

comp.lang.perl.misc guidelines on the WWW:
http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html



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

Date: Wed, 02 Nov 2005 04:45:49 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: IIS 5.1 + Perl
Message-Id: <3sqqvkFp27gjU1@individual.net>

A. Sinan Unur wrote:
> John Bokma wrote: 
>>I managed to get IIS 5.1 [1] running my hello.pl script in Firefox. 
>>However, IE wants me to download it.
> 
> I don't think this problem has anything to do with the web server your are 
> using, but rather with the fact that IE ignores text/plain, and tries to 
> deduce content type from the file extension.

That fact makes it also not very helpful to deliver comments like this 
to newbies: 
http://groups.google.com/group/comp.lang.perl.misc/msg/259b0940fc4130e5

;-)

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


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

Date: Wed, 2 Nov 2005 05:31:51 -0000
From: "PhEaSaNt PLuCKeR" <news@cutmeukjay.com>
Subject: Re: passing data
Message-Id: <dk9j06$2t3$1@newsg4.svr.pol.co.uk>
Keywords: idiot


"Matt Garrish" <matthew.garrish@sympatico.ca> wrote in message 
news:cqU9f.4877$LF3.475112@news20.bellglobal.com...
>
> "PhEaSaNt PLuCKeR" <news@cutmeukjay.com> wrote in message 
> news:dk8o40$9ei$1@newsg3.svr.pol.co.uk...
>> So my first script is the data engine, I need to pass various commands to 
>> this engine
>> Then have it obtain the data so that i can present it continuously in 
>> some other form
>> using another script.
>> Was never very good at explaining in fact "The hardest part is how to ask 
>> a question" in my case ;-)
>>
>
> If you can't present your situation clearly, then you shouldn't be pushing 
> ahead with the programming. You should sit down and work out all the 
> vagaries in your statement above before you wind up wasting hours/days 
> coding a socket solution that never required a continuously running script 
> in the first place.
>
> Matt
>

You know the problem is that there are too many people who are quick to 
criticize on here LOL
The point I was making was it is difficult to explain the help required NOT 
what I need to achieve!
I never said I would use a socket solution, DID I????
So before you jump down my throat etc. LMFAO


-- 

James (Ukjay)




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

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 V10 Issue 8596
***************************************


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