[22551] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4772 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Mar 27 21:05:39 2003

Date: Thu, 27 Mar 2003 18:05:08 -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, 27 Mar 2003     Volume: 10 Number: 4772

Today's topics:
        $< and $> - permanently dropping privileges <mbear@uq.net.au>
    Re: CGI.pm or roll-your-own? <flavell@mail.cern.ch>
    Re: CGI.pm or roll-your-own? (Randal L. Schwartz)
    Re: CGI.pm or roll-your-own? <pkent77tea@yahoo.com.tea>
    Re: declaring vars & values from a file <pkent77tea@yahoo.com.tea>
        How to use class in one file? <pengtaoli@hotmail.com>
    Re: How to use Net::FTP - FTP Client class through a Fi <pkent77tea@yahoo.com.tea>
    Re: Perl and C++ <mail@annuna.com>
    Re: perl generating bad html <uri@stemsystems.com>
    Re: perl generating bad html (Randal L. Schwartz)
    Re: perl generating bad html <jurgenex@hotmail.com>
        Perl/LWP Question <mooncm.lbkejwiAhEgSfSe@dAcEbSaS>
    Re: Perl/LWP Question <uri@stemsystems.com>
    Re: Perl/LWP Question <tony_curtis32@yahoo.com>
    Re: Problem using personal module in Apache? <shah@typhoon.xnet.com>
    Re: regex question <glex_nospam@qwest.net>
    Re: regex question <michael.p.broida@boeing.com>
        search.cpan.org seems to be down <webmastr@localhost.localdomain>
    Re: Sorting keys in a hash runs slower now. <goldbb2@earthlink.net>
        What does $_ ^= $_++; do? <bdonlan@bd-home-comp.no-ip.org>
    Re: What does $_ ^= $_++; do? <abigail@abigail.nl>
    Re: What does $_ ^= $_++; do? <jkeen@concentric.net>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Fri, 28 Mar 2003 11:34:44 +1000
From: Matthew Braid <mbear@uq.net.au>
Subject: $< and $> - permanently dropping privileges
Message-Id: <b608rk$57$1@bunyip.cc.uq.edu.au>

Hi all,

Just having a small problem...

I need to run a few scripts setuid as a dummy user so that I can access 
some library functions that have database passwords in them. I wrote a 
wrapper C program that's suid and that at least is working fine. The 
problem is when I try to change privileges back to the actual calling 
user's.

When the script starts, it has a realuid of whoever called it (let's say 
the uid is 100) and an effective uid of the owner of the wrapper (let's 
say 200). Once the libraries are loaded (which since they're loaded with 
'use' is pretty much straight away) I set the effective to be the same 
as the real by:

$> = $<; # Effective UID is now the real UID

This works nicely, however this:

print "REALLY I'M $<, BUT I'M ACTING AS $>\n";
$ou = $>;
$> = $<;
print "NOW I'M BACK TO NORMAL - REALLY I'M $< AND I'M ACTING AS $>\n";
$> = $ou;
print "NOW I'M BACK TO THE WAY I WAS - REALLY I'M $<, BUT I'M ACTING AS 
$>\n";

results in:

REALLY I'M 100, BUT I'M ACTING AS 200
NOW I'M BACK TO NORMAL - REALLY I'M 100 AND I'M ACTING AS 100
NOW I'M BACK TO THE WAY I WAS - REALLY I'M 100 BUT I'M ACTING AS 200

What I want is to make sure that the program cannot get back its 
'elevated' privileges, so the the output of the above should be:

REALLY I'M 100, BUT I'M ACTING AS 200
NOW I'M BACK TO NORMAL - REALLY I'M 100 AND I'M ACTING AS 100
NOW I'M BACK TO THE WAY I WAS - REALLY I'M 100 BUT I'M ACTING AS 100
                                                                  ^^^

In C I would use setreuid(<realid>, <realid>) but I don't know how to do 
it in perl. Any ideas?

MB



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

Date: Thu, 27 Mar 2003 23:36:14 +0100
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: CGI.pm or roll-your-own?
Message-Id: <Pine.LNX.4.53.0303272312480.14921@lxplus087.cern.ch>

On Thu, Mar 27, William C. Ray inscribed on the eternal scroll:

> Readers who need to understand minutiae are repeatedly informed that we
> can provide only a glancing view of the tip of the iceberg, and that
> there are a multitude of resources available to them from which to
> learn not only more information, but better practices as well.

I wouldn't for a moment argue with that...

> >CGI.pm can take care of all that for them.
>
> CGI.pm doesn't solve the educational need.

I hear what you say, but - looking at what follows - I'm not sure
that how I interpreted it was how you meant it.

> Yes, it will do the
> parsing _better_ but it's neither small enough, nor simple enough

Neither, with respect, is the Perl system itself - which they have no
need to understand in detail in order to make productive use of it.

So the open question in my mind (I have to admit it's based only on
what you have posted, and not having looked for the book in question)
is are you trying to teach them how to achieve something productive
(in this case in the context of a server-side script), or is it about
getting them to a position where they understand what's going on
behind the scenes?  Sure, it would be nice to achieve both, but given
that your aims are more limited, you presumably had to set a priority?

> a novice reader can look at it and reasonably believe that they
> understand what it's doing and how it's doing it.

Well, there are people here on this group who teach the stuff for a
living, I sure can't evaluate the method better than they'd be able
to.

> I can see I need to stick my pedantic nose in John's chapter here
> on the next revision, as I firmly believe in telling the reader
> the right way to do things, but I'll stick by my assertion that
> the average traditional Mac reader risks being turned off by a bare
> use of CGI.pm with no-more explanation than we have space to devote to
> it in the book.

Seems to me that the chain: HTML-form-on-browser, submit to server,
server passes request to script, script returns response to server,
server digests response and returns appropriate result to browser, can
be drawn as a pretty picture without worrying over-much about the
details of the stages in the chain.    As we know, the script could be
coded in any supported language, it doesn't _have_ to be Perl.  But
given that that choice has been made...

Consider CGI.pm as part of the Perl system itself (it is, after all,
now a core module): just use it, and leave the details to be worried
over later. To drive a car you don't _have_ to be able to build your
own gearbox, after all.

The important thing to my way of thinking is to gain the right mental
model.  The details in many cases are an unnecessary distraction to
the newcomer.  And I say that as a fully paid up pedant who wants to
nit pick every detail until it's just right (as quite a number around
here will inevitably confirm...).

OK, what say the real educators in this group?  ;-)



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

Date: Thu, 27 Mar 2003 23:42:16 GMT
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: CGI.pm or roll-your-own?
Message-Id: <f30f595f74022c57bf6f4ef1e5b89800@news.teranews.com>

>>>>> "Alan" == Alan J Flavell <flavell@mail.cern.ch> writes:

Alan> OK, what say the real educators in this group?  ;-)

Well, I've already spoken. :)

Any code that hand-parses the CGI parameters should be labeled
as "scaffolding that we're going to kick away in a few minutes".

One example. I'll permit *one* example in a CGI book that does it "by
hand", just to show how much stuff has to be done, and has to be
remembered.  And the next example better be how to do the same exact
thing with CGI.pm, including the other things it's getting right
(entities, multi-select form elements, POST/GET being interchangable,
correct interpretation of content-encoding, using both ";" and "&" as
delimiters, preventing DOS attacks by limiting the incoming data,
portability to mod_perl Apache::Registry when the time comes, etc
etc).

Drilling down with the by-hand code is like showing how to multiply by
doing repeated additions and bitshifting.  Sure, it's interesting, but
IT IS NOT PRODUCTIVE IN THE LONG RUN.  Nor is it how *real* programs
are written.

And that's why we're learning Perl.  To get the job done.

print "Just another Perl hacker,"

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!


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

Date: Fri, 28 Mar 2003 00:24:59 GMT
From: pkent <pkent77tea@yahoo.com.tea>
Subject: Re: CGI.pm or roll-your-own?
Message-Id: <pkent77tea-646193.00051328032003@[10.1.1.10]>

In article <b5vpff$qf5@soyokaze.biosci.ohio-state.edu>,
 ray@soyokaze.biosci.ohio-state.edu (William C. Ray) wrote:

> it looks like a black box with
> a button on it that says "Solve My Problems".

I want one of those!!!


That is, if it solves problems in a nice way.

[I admit it; posting excessively trimmed for comic effect]

P

-- 
pkent 77 at yahoo dot, er... what's the last bit, oh yes, com
Remove the tea to reply


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

Date: Fri, 28 Mar 2003 00:25:00 GMT
From: pkent <pkent77tea@yahoo.com.tea>
Subject: Re: declaring vars & values from a file
Message-Id: <pkent77tea-76B412.00153528032003@[10.1.1.10]>

In article <3E827993.3C7DD05A@earthlink.net>,
 Benjamin Goldberg <goldbb2@earthlink.net> wrote:

> tim wrote:
> [snip]
> > $inipath="/home/tim/settings";
> > open (INFILE, "$inipath")||die "Cannot open $inipath for reading";
> 
> Some simple code for reading the ini file format is as follows:

Or there's Config::Inifiles on CPAN - 
http://theoryx5.uwinnipeg.ca/CPAN/data/Config-IniFiles/IniFiles.html

P

-- 
pkent 77 at yahoo dot, er... what's the last bit, oh yes, com
Remove the tea to reply


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

Date: Fri, 28 Mar 2003 09:03:44 +0800
From: "Franklin Lee" <pengtaoli@hotmail.com>
Subject: How to use class in one file?
Message-Id: <b6071o$k21@netnews.proxy.lucent.com>

Hello All,

I want to define one clase using package, then use it in the same file.
Program prototype like below:
**********************************************************************
BEGIN{
package mypackage;

BEGIN{
use Exporter;
@ISA = { Exporter };

use strict;

#define variable

#define functions
sub new;
sub abc;
}
sub new{
 ...
}
sub abc{
 ...
}

1;
}

#main
package main;
use mypackage;
my $a=new mypackage;
$a->abc;
*********************************************************************
Perl always tell me that no mypackage.pm can use. But I don't want to ceate
one file mypackage.pm. I want to create some classes in one file and use
them
like C++.

Who can tell me how to do it and the reason? And where can find refence?

Thank you in advance!

Franklin





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

Date: Fri, 28 Mar 2003 00:54:52 GMT
From: pkent <pkent77tea@yahoo.com.tea>
Subject: Re: How to use Net::FTP - FTP Client class through a Firewall
Message-Id: <pkent77tea-25C3F2.00235328032003@[10.1.1.10]>

In article <fca4c27e.0303270611.78a38c6c@posting.google.com>,
 joey19020@aol.com (Joe Kamenar) wrote:

>     $ftp = Net::FTP->new("ftp.fund.xxxxx.com", Firewall =>
> "ftp-gateway.xxxx.net", FirewallType => 5, Debug => 1) or die("Unable
> to create ftp object");
>     $ftp->authorize("fundstn", "password");
>     $ftp->login("nationuser",'pass77');
>     $ftp->cwd("/pub");
 ...
> Net::FTP=GLOB(0x1ab2cec)<<< 220-Secure Gateway FTP server
> Net::FTP=GLOB(0x1ab2cec)<<< 220-Corporate Firewall Gateway.
> Net::FTP=GLOB(0x1ab2cec)<<< 220 Ready
> Net::FTP=GLOB(0x1ab2cec)>>> AUTH fundstn
> Net::FTP=GLOB(0x1ab2cec)<<< 500 Syntax error, command unrecognized:
> 'AUTH fundstn
> 
> What is causing this error?

Your FTP application level proxy. It doesn't understand the 'AUTH' 
command, which I presume is send by the authorize() method. Check with 
the friendly administrator:

a) whether you need to authorize at all
b) if so, what kind of authorization it is
c) ideally some pointer to some source code that _can_ negotiate the 
proxy.

I had a quick look on Google but couldn't find anything about your 
proxy/firewall.

You can use the $ftp->quot() method to send pretty much whatever you 
want:

       quot (CMD [,ARGS])
           Send a command, that Net::FTP does not directly
           support, to the remote server and wait for a response.

           Returns most significant digit of the response code.

           WARNING This call should only be used on commands that
           do not require data connections. Misuse of this method
           can hang the connection.


P

-- 
pkent 77 at yahoo dot, er... what's the last bit, oh yes, com
Remove the tea to reply


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

Date: Thu, 27 Mar 2003 18:12:31 -0600
From: Joe Creaney <mail@annuna.com>
Subject: Re: Perl and C++
Message-Id: <3E83936F.4020207@annuna.com>



Michael Carman wrote:
> On 3/27/2003 4:18 PM, Joe Creaney wrote:
> 
>>I have been trying to learn C++ and Perl. I like Perl more for 
>>programming. It is much easier to do thingsin perl but I realy
>>prefer the way C++ creates objects and classes.
> 
> 
> That's nice. Did you have a Perl question?
> 
> -mjc
> 
No Just wanted to make a comment.  I realy don't think there is a way to 
use C++ object syntax in perl.




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

Date: Thu, 27 Mar 2003 23:14:22 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: perl generating bad html
Message-Id: <x7d6kc9zch.fsf@mail.sysarch.com>

>>>>> "MC" == Michael Carman <mjcarman@mchsi.com> writes:

  MC> On 3/27/2003 4:06 PM, Ernest wrote:
  >> Hello. I have a perl shopping cart script. And it's generating code
  >> with multiple <body> tags. The script works in Netscape, but not in
  >> IE. We recently switched from a UNIX server, where it worked, to an
  >> NT server, where we started having these problems. Any ideas?
  >> Thanks.

  MC> Your vehilisnitzer is frezzledonked. Try upping the blugits for
  MC> your wibbler.

abigail found the bug already on line 17. please don't give out
incorrect information like this. it is a disservice to the perl
community.

uri

-- 
Uri Guttman  ------  uri@stemsystems.com  -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs  ----------------------------  http://jobs.perl.org


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

Date: Thu, 27 Mar 2003 23:52:25 GMT
From: merlyn@stonehenge.com (Randal L. Schwartz)
To: Keith Keller <kkeller@wombat.san-francisco.ca.us>
Subject: Re: perl generating bad html
Message-Id: <06c7e6483838257b540e8689f1a86615@news.teranews.com>

>>>>> "Keith" == Keith Keller <kkeller-spammmm@wombat.san-francisco.ca.us> writes:

Keith> In article <slrnb86u9d.lrb.abigail@alexandra.abigail.nl>, Abigail wrote:
>> Why on earth would you want to switch from Unix to NT anyway?
>> No wonder things break.

Keith> Can't this be haiku-ized?

Keith> 	Why would you want to
Keith> 	Switch from unix to NT?
Keith> 	No wonder things break.

A true Haiku has to mention a season as well.

    Spring, Summer, or Fall
    I switch Unix to NT?
    Hell feels like Winter!

print "Just another Perl hacker,"

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!


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

Date: Fri, 28 Mar 2003 01:08:28 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: perl generating bad html
Message-Id: <ggNga.112163$iq1.9190@nwrddc02.gnilink.net>

Ernest wrote:
> Hello. I have a perl shopping cart script. And it's generating code
> with multiple <body> tags.

Well, I guess in that case your program has a bug.

> The script works in Netscape, but not in
> IE.

You run a Perl script in Netscape and/or IE? I don't believe you. Don't know
about Netscape but IE certainly does not support Perl. There is a PerlScript
module for IE from ActiveState, but that would be PerlScript, not Perl.

> We recently switched from a UNIX server, where it worked, to an NT
> server, where we started having these problems. Any ideas? Thanks.

Check line 42.

jue




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

Date: Fri, 28 Mar 2003 01:08:28 GMT
From: "BSK" <mooncm.lbkejwiAhEgSfSe@dAcEbSaS>
Subject: Perl/LWP Question
Message-Id: <ggNga.22802$pK4.2004222@newsread1.prod.itd.earthlink.net>

Hello All,

I'm in the process of reading Sean Burke's book entitled "Perl & LWP" and I
came across the following code on page 26:

use LWP;
my $browser;
sub do_GET{
  $browser = LWP::UserAgent->new unless $browser;
  my $resp = $browser->get(@_);
  return ($resp->content, $resp->status_line, $resp->is_success, $resp) if
wantarray;
  return unless $resp->is_success;
  return $resp->content;
}

This code works but I'm a bit confused with the top return statement.  In
particular, the word "wantarrary" appears, to me, to be a bare word.  Since
it's being used in conjunction with an if statement, it must be a boolean
variable-- and since it's a variable shouldn't it be written as
"$wantarrary"?

Another question I have is, where does that variable come from?  It just
seems to appear out of nowhere.

Thanks for your help.

BSK
[For AntiSpam: Email address is spelled
backwards.  Remove every other letter
starting with 'a' in 'SaS'.]







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

Date: Fri, 28 Mar 2003 01:15:38 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Perl/LWP Question
Message-Id: <x7brzw8f5x.fsf@mail.sysarch.com>

>>>>> "B" == BSK  <mooncm.lbkejwiAhEgSfSe@dAcEbSaS> writes:

  B>   return ($resp->content, $resp->status_line, $resp->is_success,
  B>   $resp) if wantarray;

  B> This code works but I'm a bit confused with the top return
  B> statement.  In particular, the word "wantarrary" appears, to me, to
  B> be a bare word.  Since it's being used in conjunction with an if
  B> statement, it must be a boolean variable-- and since it's a
  B> variable shouldn't it be written as "$wantarrary"?

perldoc -f wantarray.

uri

-- 
Uri Guttman  ------  uri@stemsystems.com  -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs  ----------------------------  http://jobs.perl.org


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

Date: Thu, 27 Mar 2003 19:21:42 -0600
From: Tony Curtis <tony_curtis32@yahoo.com>
Subject: Re: Perl/LWP Question
Message-Id: <87n0jgcml5.fsf@limey.hpcc.uh.edu>

>> On Fri, 28 Mar 2003 01:08:28 GMT,
>> "BSK" <mooncm.lbkejwiAhEgSfSe@dAcEbSaS> said:

> Hello All, I'm in the process of reading Sean Burke's
> book entitled "Perl & LWP" and I came across the
> following code on page 26:

> use LWP;
> my $browser;
> sub do_GET{
>   $browser = LWP::UserAgent->new unless $browser;
   ^^^

I don't see why $browser is declared outside the sub, nor
how it is initialised (note the test).  It should be
my()ed here, or a parameter or possibly a class variable
if it's coming from somewhere else.

>   my $resp = $browser->get(@_);
>   return ($resp->content, $resp->status_line, $resp->is_success, $resp) if
> wantarray;

> This code works but I'm a bit confused with the top
> return statement.  In particular, the word "wantarrary"
> appears, to me, to be a bare word.  Since it's being
> used in conjunction with an if statement, it must be a
> boolean variable-- and since it's a variable shouldn't
> it be written as "$wantarrary"?

The answer is "perldoc -f wantarray".

> Another question I have is, where does that variable
> come from?  It just seems to appear out of nowhere.

Which variable?  wantarray isn't a variable, and I don't
know what's going on with $browser.

This code looks like it is trying to reinvent the wheel in
LWP::Simple::get().

hth
t


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

Date: Fri, 28 Mar 2003 01:02:15 +0000 (UTC)
From: Hemant Shah <shah@typhoon.xnet.com>
Subject: Re: Problem using personal module in Apache?
Message-Id: <b606un$e8g$1@flood.xnet.com>

While stranded on information super highway Tad McClellan wrote:
:)Hemant Shah <shah@typhoon.xnet.com> wrote:
:)

 Sorry about the errors, I should have copy/pasted it instead of typing it
 again.

:)
:)> In my perl script I have following code:
:)
:)> #!/usr/local/bin/perl -w
:)
:)
:)   use strict;   # ask for all the help you can get

   I added strict, but still same problem.
:)
:)
:)>           open(LOGFILE, "> /tmp/MyApp.log");
:)
:)
:)You should always, yes *always*, check the return value from open():
:)
:)  open(LOGFILE, "> /tmp/MyApp.log" or die "could not open '/tmp/MyApp.log' $!";

   In my test code I did not have but I do have "|| die"
:)
:)(or carp() instead of die(), but some appropriate action)
:)
:)
:)> ecit(0);
:)   ^
:)   ^

  This is a typo, like I said I should have copy/pasted the code instead of
  typing it again.


:)
:)> I do not see any other errors.
:)
:)
:)I am finding that hard to believe at this point...
:)
:)
:)
:)    Do not re-type Perl code
:)        Use copy/paste or your editor's "import" function rather than
:)        attempting to type in your code. If you make a typo you will get
:)        followups about your typos instead of about the question you are
:)        trying to get answered.
:)
:)
:)-- 
:)    Tad McClellan                          SGML consulting
:)    tadmc@augustmail.com                   Perl programming
:)    Fort Worth, Texas

-- 
Hemant Shah                           /"\  ASCII ribbon campaign
E-mail: NoJunkMailshah@xnet.com       \ /  --------------------- 
                                       X     against HTML mail
TO REPLY, REMOVE NoJunkMail           / \      and postings      
FROM MY E-MAIL ADDRESS.           
-----------------[DO NOT SEND UNSOLICITED BULK E-MAIL]------------------
I haven't lost my mind,                Above opinions are mine only.
it's backed up on tape somewhere.      Others can have their own.


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

Date: Thu, 27 Mar 2003 17:34:28 -0600
From: Jeff D Gleixner <glex_nospam@qwest.net>
Subject: Re: regex question
Message-Id: <cRLga.1275$1O3.45367@news.uswest.net>

Gary Fu wrote:
> Hi,
> 
> if $xx = 'ABC 123 a b c', I want $id = 123 and $txt = 'b c';
> if $xx = 'ABC 123 a c c', I want $id = 123 and don't care about $txt
> 
> I cannot figure out how to do this with something like
> 
> ($id, $txt) = $xx =~ /ABC (\d+) (b c)/  # I won't get $id for the 2nd case.

($id, $txt) = $xx =~ /ABC (\d+) (b c)?/ ;

The '?' means 0 or more.



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

Date: Fri, 28 Mar 2003 00:23:14 GMT
From: "Michael P. Broida" <michael.p.broida@boeing.com>
Subject: Re: regex question
Message-Id: <3E8395F2.386592B2@boeing.com>

Jeff D Gleixner wrote:
> 
> Gary Fu wrote:
> > Hi,
> >
> > if $xx = 'ABC 123 a b c', I want $id = 123 and $txt = 'b c';
> > if $xx = 'ABC 123 a c c', I want $id = 123 and don't care about $txt
> >
> > I cannot figure out how to do this with something like
> >
> > ($id, $txt) = $xx =~ /ABC (\d+) (b c)/  # I won't get $id for the 2nd case.
> 
> ($id, $txt) = $xx =~ /ABC (\d+) (b c)?/ ;
> 
> The '?' means 0 or more.

	I think he also needs an "a" in there or it won't
	match what he specified at the top of his post.

	($id, $txt) = $xx =~ /ABC (\d+) a (b c)?/ ;

		Mike


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

Date: Fri, 28 Mar 2003 00:58:53 GMT
From: "none" <webmastr@localhost.localdomain>
Subject: search.cpan.org seems to be down
Message-Id: <h7Nga.324053$na.23113256@news2.calgary.shaw.ca>

Hello,
About 2 days now. Has anyone experienced the same problem? Are there any
alternate sites that post module documentation?
NagitaK


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

Date: Thu, 27 Mar 2003 21:18:28 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Sorting keys in a hash runs slower now.
Message-Id: <3E83B0F4.91F7DBFF@earthlink.net>

C Marshall wrote:
> 
> Benjamin Goldberg <goldbb2@earthlink.net> wrote in message
> >
> > How about an algorithmic comparison?
> >
> >    my %short = qw( O/N 1 T/N 2 S/N 3 );

A hash with "O/N", "T/N", and "S/N" as keys, and 1, 2, 3 as values.

I've no idea what these strings actually mean, but I assume that they
are really small time units.

> >    my %scale = qw( Y 1 M 12 W 52 );

A hash with "Y", "M", "W", as keys, and 1, 12, and 52 as values.

This will be used to scale units into fractions of a year -- thus a
string "9M" is the number 9/12, and "3W" is the number 3/52.

> >    *a = *main::a; *b = *main::b;

This makes $a and $b in this package, aliases for $a and $b in the main
package.  It's easier to write this here, than writing $main::a and
$main::b all over the place.

> >    sub pillar_order {
> >       if( exists $short{$a} and exists $short{$b} ) {
> >          $short{$a} cmp $short{$b};

If both are really short time units, look them up in the hash and
compare them.  (This probably should be <=> instead of cmp, but it's
harmless)

> >       } elsif( exists $short{$a} ) {
> >          -1;
> >       } elsif( exists $short{$b} ) {
> >          +1;

If only one is a short time unit, then we can "know" that the other unit
is longer without looking at it -- return 1 or -1, depending on which of
$a or $b was a short time unit.

> >       } else {
> >          my ($aval, $atype) = $a =~ /(\d+)(.)/;
> >          my ($bval, $btype) = $b =~ /(\d+)(.)/;

Seperate the leading digit(s) from the trailing letter.

> >          $aval / $scale{$atype} cmp $bval / $scale{$btype};

This scales the numbers down to be years or fractions of a year, as I
described earlier.

This really should be '<=>' instead of 'cmp'.


> >       }
> >    }
> >
> 
> Please could you explain how this works in more detail for me.

I hope my explanation is useful to you.

-- 
$a=24;split//,240513;s/\B/ => /for@@=qw(ac ab bc ba cb ca
);{push(@b,$a),($a-=6)^=1 for 2..$a/6x--$|;print "$@[$a%6
]\n";((6<=($a-=6))?$a+=$_[$a%6]-$a%6:($a=pop @b))&&redo;}


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

Date: Thu, 27 Mar 2003 18:59:22 -0500
From: "bd" <bdonlan@bd-home-comp.no-ip.org>
Subject: What does $_ ^= $_++; do?
Message-Id: <pan.2003.03.27.23.59.21.885179@bd-home-comp.no-ip.org>

What does $_ ^= $_++; do? The C equivalent is undefined behavior - is it
on perl, too? It behaves weirdly, but the weirdness seems to be
deterministic, based on the previous value of $_.
-- 
Freenet distribution (temporary): http://24.25.175.161:8891/FDKmwcRHfQA/
Having nothing, nothing can he lose.
		-- William Shakespeare, "Henry VI"



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

Date: 28 Mar 2003 00:11:14 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: What does $_ ^= $_++; do?
Message-Id: <slrnb874p2.lrb.abigail@alexandra.abigail.nl>

bd (bdonlan@bd-home-comp.no-ip.org) wrote on MMMCDXCV September MCMXCIII
in <URL:news:pan.2003.03.27.23.59.21.885179@bd-home-comp.no-ip.org>:
--  What does $_ ^= $_++; do? The C equivalent is undefined behavior - is it
--  on perl, too? It behaves weirdly, but the weirdness seems to be
--  deterministic, based on the previous value of $_.


It's undefined in Perl too. Undefined behaviour doesn't mean that for
a particular implementation and input value, the output can't be
determined.

$_ ^= $_++; is a variant of the ancient '$i = $i ++;', which is 
undefined.


Abigail, awaiting the hords of people argueing '$i = $i ++;' is
         well defined cause their particular Perl variant happens
         to set $i to what they think it should be set to.
-- 
srand 123456;$-=rand$_--=>@[[$-,$_]=@[[$_,$-]for(reverse+1..(@[=split
//=>"IGrACVGQ\x02GJCWVhP\x02PL\x02jNMP"));print+(map{$_^q^"^}@[),"\n"


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

Date: 28 Mar 2003 00:24:07 GMT
From: "James E Keenan" <jkeen@concentric.net>
Subject: Re: What does $_ ^= $_++; do?
Message-Id: <b604n7$9du@dispatch.concentric.net>


"bd" <bdonlan@bd-home-comp.no-ip.org> wrote in message
news:pan.2003.03.27.23.59.21.885179@bd-home-comp.no-ip.org...
> What does $_ ^= $_++; do? The C equivalent is undefined behavior - is it
> on perl, too? It behaves weirdly, but the weirdness seems to be
> deterministic, based on the previous value of $_.
> --

A good question ... and the Perl documentation (perldoc perlop as well as
Camel book, p107) simply say "Perl recognizes the C assignment operators, as
well as providing some of its own."  This offers no guidance to anyone who
hasn't already studied C.  Can some C-programmers help us out?




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

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.  

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


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