[26429] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 8598 Volume: 10

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

Date: Wed, 2 Nov 2005 08:05: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, 2 Nov 2005     Volume: 10 Number: 8598

Today's topics:
    Re: dynamically adding member sub to object? <casabianca@suplitein.junk.de.net.org.com>
    Re: Find a hex digit. <tadmc@augustmail.com>
    Re: How to use string as two dimensional array <tadmc@augustmail.com>
    Re: IIS 5.1 + Perl <flavell@ph.gla.ac.uk>
    Re: IIS 5.1 + Perl <1usa@llenroc.ude.invalid>
    Re: IIS 5.1 + Perl <1usa@llenroc.ude.invalid>
    Re: passing data (Anno Siegel)
    Re: passing data <matthew.garrish@sympatico.ca>
    Re: passing data <news@cutmeukjay.com>
        s///x <rvtol+news@isolution.nl>
    Re: s///x (Anno Siegel)
    Re: s///x <noreply@gunnar.cc>
    Re: s///x <rvtol+news@isolution.nl>
    Re: s///x <noreply@gunnar.cc>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Wed, 2 Nov 2005 07:29:05 -0800
From: "Eckstein C." <casabianca@suplitein.junk.de.net.org.com>
Subject: Re: dynamically adding member sub to object?
Message-Id: <3ss4abFps17dU1@individual.net>

John Bokma wrote:
> "Eckstein C." <casabianca@suplitein.junk.de.net.org.com> wrote:
>
>> 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. )
>
> I would inherit from "SomeClass", and use AUTOLOAD.

I wanted to avoid that, and I wanted to loop through the "properties" 
(hash items) and dynamically generate a method for that class on the 
fly, but I can't find any info anywhere (perldoc, google, etc.) 




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

Date: Wed, 2 Nov 2005 05:38:28 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Find a hex digit.
Message-Id: <slrndmh99k.hsi.tadmc@magna.augustmail.com>

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]; 
> 
> What is this doing, 


It converts a _number_ in the range of 10..15 to the corresponding
_character_ in a hexidecimal representation.


> and how?


By using a "list slice".


I'd prefer for it to function properly over the entire range
of hex values:

   $hexdigit = ( '0'..'9', 'a'..'f' )[$digit];

Or just use sprintf().


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


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

Date: Wed, 2 Nov 2005 07:19:07 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: How to use string as two dimensional array
Message-Id: <slrndmhf6b.i21.tadmc@magna.augustmail.com>

toplicanac <info@toplice.com.remove> wrote:

> How to use string as two dimensional array


You cannot use a string as a two dimensional array.

You can however load a 2-D array from a string.


> $string="123456abc";
> -------------------------------------------
> I want to read it like this
> 
> $mat(1,1) = "1"
> $mat(2,1) = "2"
> $mat(3,1) = "3"


x varies, y is constant.  (and indexes start at zero in Perl)


> $mat(1,2) = "4"
> $mat(2,2) = "5"
> $mat(3,2) = "6"


x varies, y is constant.


> $mat(3,1) = "a"
> $mat(3,2) = "b"
> $mat(3,3) = "c"


x is constant, y varies!

Please exercise more care in describing what you want.


> What is easiest way to do it in Perl?


This should get you started:

---------------------
#!/usr/bin/perl
use warnings;
use strict;
use Data::Dumper;

my $string = '123456abc';
my @twoD = str2array(3, $string);
print Dumper \@twoD;


sub str2array {
   my($dim, $str) = @_;

   die "'$str' is not evenly divisible by $dim\n"
      if length($str) % $dim;

   my @ra;
   while ( my $row = substr $str, 0, 3, '' ) {
      push @ra, [ split //, $row ];
   }
   return @ra;
}
---------------------


See also:

   perldoc perlreftut
   perldoc perlref
   perldoc perllol
   perldoc perldsc


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


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

Date: Wed, 2 Nov 2005 11:04:30 +0000
From: "Alan J. Flavell" <flavell@ph.gla.ac.uk>
Subject: Re: IIS 5.1 + Perl
Message-Id: <Pine.LNX.4.62.0511021047440.25732@ppepc56.ph.gla.ac.uk>

On Wed, 2 Nov 2005, A. Sinan Unur wrote:

> 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

yes

> from the file extension.

Sometimes - but it's a last resort after their other guesswork has 
drawn a blank.

This crass violation of a mandatory requirement of RFC2616 has been 
going on for a long time, and is one of the points on which MSIE 
disqualifies itself as a web browser.  It's a potential security 
exposure (which was, I feel sure, the reason for RFC2616 insisting on 
this point).

However, MS have stated that as from XP SP2, IE will honour the 
text/plain content-type. 

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

Sounds as if you're not up to date with MS software fixes :-{

See the highlighted bits regarding XP SP2 in 
http://msdn.microsoft.com/workshop/networking/moniker/overview/appendix_a.asp

(and google for "content-type saga" if you want to go into any 
detail).  At no point have I seen them admit that they are violating 
the interworking specifications, but at least they did take out their 
earlier mischievous cross-reference to RFC2616 (cited as if they might 
be observing it, when in fact they were violating it).

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

You (and anyone else concerned) should use a www-compatible browser.

> Sigh.

Indeed.

-- 

  Since XP XP2, you have the option: of having your Windows dangerously
  open, or uselessly shut.   -- Richard Bos in the Monastery


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

Date: Wed, 2 Nov 2005 14:23:45 +0000 (UTC)
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: IIS 5.1 + Perl
Message-Id: <Xns97025F942B640asu1cornelledu@132.236.56.8>

Gunnar Hjalmarsson <noreply@gunnar.cc> wrote in
news: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
> 
> ;-)
> 

Point taken. Thanks.

Sinan


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

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

"Alan J. Flavell" <flavell@ph.gla.ac.uk> wrote in
news:Pine.LNX.4.62.0511021047440.25732@ppepc56.ph.gla.ac.uk: 

> On Wed, 2 Nov 2005, A. Sinan Unur wrote:
> 
>> On my system, I get the same response if I try to access the default 
>> printenv.pl script that came with Apache.
> 
> Sounds as if you're not up to date with MS software fixes :-{

Help -> About shows:

Version 6.0.2900.2180.xpsp2_gdr.050301-1519
Update Versions:; SP2; 

I don't know how much more up-to-date I can be.

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: 2 Nov 2005 12:15:28 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: passing data
Message-Id: <dkaal0$2rv$1@mamenchi.zrz.TU-Berlin.DE>
Keywords: idiot

PhEaSaNt PLuCKeR <news@cutmeukjay.com> wrote in comp.lang.perl.misc:
> 
> "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

LOL?  What's funny?

> The point I was making was it is difficult to explain the help required NOT 
> what I need to achieve!

Being unable to explain a problem is a sign of insufficient understanding.

> I never said I would use a socket solution, DID I????

Don't try to fool people about what you said and didn't say.  Your words:

    Ok Thanks Xho, The data is continuous via a socket.
    (use IO::Socket;)

> So before you jump down my throat etc. LMFAO

You come across slightly hysterical with all that laughter.

Anno
-- 
If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article.  Click on 
"show options" at the top of the article, then click on the 
"Reply" at the bottom of the article headers.


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

Date: Wed, 2 Nov 2005 07:16:05 -0500
From: "Matt Garrish" <matthew.garrish@sympatico.ca>
Subject: Re: passing data
Message-Id: <662af.5122$LF3.540480@news20.bellglobal.com>


"PhEaSaNt PLuCKeR" <news@cutmeukjay.com> wrote in message 
news:dk9j06$2t3$1@newsg4.svr.pol.co.uk...
>
> "Matt Garrish" <matthew.garrish@sympatico.ca> wrote in message 
> news:cqU9f.4877$LF3.475112@news20.bellglobal.com...
>>
>>
>> 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.
>>
>
> 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
>

It's not called jumping down your throat; it's called telling you to do your 
design first before you start coding with only half-formed ideas. It's nice 
that you have a general concept that you want some script to run and do 
something and pass some kind of data to another script or something, but 
that shows that you haven't taken your design to the next step, which is 
working out the details to a level where you're reasonably sure about all 
aspects of your plan.The last guy I saw try to code without a good design 
took a three week job and turned it into an eleven month debacle before 
being encouraged to leave the company.

Matt 




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

Date: Wed, 2 Nov 2005 16:03:22 -0000
From: "PhEaSaNt PLuCKeR" <news@cutmeukjay.com>
Subject: Re: passing data
Message-Id: <dkao09$mmr$1@newsg3.svr.pol.co.uk>


"Matt Garrish" <matthew.garrish@sympatico.ca> wrote in message 
news:662af.5122$LF3.540480@news20.bellglobal.com...
>
> "PhEaSaNt PLuCKeR" <news@cutmeukjay.com> wrote in message 
> news:dk9j06$2t3$1@newsg4.svr.pol.co.uk...
>>
>> "Matt Garrish" <matthew.garrish@sympatico.ca> wrote in message 
>> news:cqU9f.4877$LF3.475112@news20.bellglobal.com...
>>>
>>>
>>> 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.
>>>
>>
>> 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
>>
>
> It's not called jumping down your throat; it's called telling you to do 
> your design first before you start coding with only half-formed ideas. 
> It's nice that you have a general concept that you want some script to run 
> and do something and pass some kind of data to another script or 
> something, but that shows that you haven't taken your design to the next 
> step, which is working out the details to a level where you're reasonably 
> sure about all aspects of your plan.The last guy I saw try to code without 
> a good design took a three week job and turned it into an eleven month 
> debacle before being encouraged to leave the company.
>
> Matt
>

Ok Matt I take your point but in this particular instance I must admit that 
this
project is a rather free and easy one.
I would like to try using a socket to pass data, even though there may be 
another way of doing things.
The reason being I am already thinking of other ideas that I could employ 
doing it this way.
So discussing this has already paid dividends for me!
Ok I will confess,  it's just a means to get used to coding in perl, I have 
coded in c++ and Java, but only
briefly tried perl before.


-- 

James (Ukjay)

used perl




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

Date: Wed, 2 Nov 2005 13:31:43 +0100
From: "Dr.Ruud" <rvtol+news@isolution.nl>
Subject: s///x
Message-Id: <dkafg1.o0.1@news.isolution.nl>

I was trying the s///x syntax and got unexpected results.
Somebody cares to explain?

Simplified example:

#!/usr/bin/perl

use warnings;
use strict;

  local ($,, $\) = ("\t", "\n");
  my $x;

  $_ = "abc 123 def 123 ghi";

  $x = s/       # Replace
          1             # ONE
          2             # TWO
          3             # THREE
        /       # by
          4             # FOUR
          5             # FIVE
          6             # SIX
        /gsx;           # global, single line, extended format

  print 'Made', $x, 'replacements.';
  print;


This printed:

Made    2       replacements.
abc     # by
          4             # FOUR
          5             # FIVE
          6             # SIX
         def    # by
          4             # FOUR
          5             # FIVE
          6             # SIX
         ghi

I expected: abc 456 def 456 ghi

-- 
Affijn, Ruud & perl, v5.8.6 built for i386-freebsd-64int

"Gewoon is een tijger."


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

Date: 2 Nov 2005 13:00:54 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: s///x
Message-Id: <dkada6$6i2$1@mamenchi.zrz.TU-Berlin.DE>

Dr.Ruud <rvtol+news@isolution.nl> wrote in comp.lang.perl.misc:
> I was trying the s///x syntax and got unexpected results.
> Somebody cares to explain?
>
> Simplified example:
> 
> #!/usr/bin/perl
> 
> use warnings;
> use strict;
> 
>   local ($,, $\) = ("\t", "\n");
>   my $x;
> 
>   $_ = "abc 123 def 123 ghi";
> 
>   $x = s/       # Replace
>           1             # ONE
>           2             # TWO
>           3             # THREE
>         /       # by
>           4             # FOUR
>           5             # FIVE
>           6             # SIX
>         /gsx;           # global, single line, extended format
> 
>   print 'Made', $x, 'replacements.';
>   print;
> 
> 
> This printed:
> 
> Made    2       replacements.
> abc     # by
>           4             # FOUR
>           5             # FIVE
>           6             # SIX
>          def    # by
>           4             # FOUR
>           5             # FIVE
>           6             # SIX
>          ghi
> 
> I expected: abc 456 def 456 ghi
> 

The changes by /x only affect the regex proper.  The replacement part
is still an ordinary double-quotish string.

Anno
-- 
If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article.  Click on 
"show options" at the top of the article, then click on the 
"Reply" at the bottom of the article headers.


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

Date: Wed, 02 Nov 2005 14:09:00 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: s///x
Message-Id: <3srrviFpc28aU1@individual.net>

Dr.Ruud wrote:
> I was trying the s///x syntax and got unexpected results.
> Somebody cares to explain?
> 
> Simplified example:
> 
> #!/usr/bin/perl
> 
> use warnings;
> use strict;
> 
>   local ($,, $\) = ("\t", "\n");
>   my $x;
> 
>   $_ = "abc 123 def 123 ghi";
> 
>   $x = s/       # Replace
>           1             # ONE
>           2             # TWO
>           3             # THREE
>         /       # by
>           4             # FOUR
>           5             # FIVE
>           6             # SIX
>         /gsx;           # global, single line, extended format
> 
>   print 'Made', $x, 'replacements.';
>   print;
> 
> 
> This printed:
> 
> Made    2       replacements.
> abc     # by
>           4             # FOUR
>           5             # FIVE
>           6             # SIX
>          def    # by
>           4             # FOUR
>           5             # FIVE
>           6             # SIX
>          ghi
> 
> I expected: abc 456 def 456 ghi

Try:

   $x = s/       # Replace
           1             # ONE
           2             # TWO
           3             # THREE
         /456/gx;           # global, extended format

Note that the /s modifier is redundant (see "perldoc perlre").

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


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

Date: Wed, 2 Nov 2005 14:37:42 +0100
From: "Dr.Ruud" <rvtol+news@isolution.nl>
Subject: Re: s///x
Message-Id: <dkaj8k.1i4.1@news.isolution.nl>

Gunnar Hjalmarsson schreef:


> [s/ 123 #one-two-three / 456 #four-five-six /x]
>
> Try:
>
>    $x = s/       # Replace
>            1             # ONE
>            2             # TWO
>            3             # THREE
>          /456/gx;           # global, extended format

Of course what is in my real and working code is a lot more like that.
But I like the commented format much better and was real disappointed
that it didn't work.


> Note that the /s modifier is redundant (see "perldoc perlre").

I don't consider the /s modifier redundant. It was not needed in my
example, so maybe you meant "redundant here"?

-- 
Affijn, Ruud

"Gewoon is een tijger."



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

Date: Wed, 02 Nov 2005 16:45:09 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: s///x
Message-Id: <3ss54cFpe3koU1@individual.net>

Dr.Ruud wrote:
> Gunnar Hjalmarsson schreef:
>>Note that the /s modifier is redundant (see "perldoc perlre").
> 
> I don't consider the /s modifier redundant. It was not needed in my
> example, so maybe you meant "redundant here"?

Okay, redundant (or extraneous...) here. I mentioned it because people 
misunderstand the meaning of it all the time, and I believe one reason 
for that is that "perldoc perlre" - unlike e.g. "perldoc perlop" - is 
the only place in the docs (to my knowledge) where its meaning is 
properly explained.

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


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

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


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