[15901] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 3314 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Jun 10 18:10:36 2000

Date: Sat, 10 Jun 2000 15:10:16 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <960675016-v9-i3314@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Sat, 10 Jun 2000     Volume: 9 Number: 3314

Today's topics:
    Re: obfuscated but useful magic() - for your perlish am <gisle@ActiveState.com>
    Re: obfuscated but useful magic() - for your perlish am <gisle@ActiveState.com>
    Re: obfuscated but useful magic() - for your perlish am <gellyfish@gellyfish.com>
    Re: obfuscated but useful magic() - for your perlish am (Bart Lateur)
    Re: obfuscated but useful magic() - for your perlish am <tcuffel@exactis.com>
    Re: Operator Overloading, Use Parent, Multiple Inherita <gellyfish@gellyfish.com>
    Re: Operator Overloading, Use Parent, Multiple Inherita <gellyfish@gellyfish.com>
    Re: PLEASE HELP: Perl for WWW (Bart Lateur)
    Re: pnggraph/gifgraph and logarithmic axes <randy@theory.uwinnipeg.ca>
    Re: Problem with Perl + CPAN... <gellyfish@gellyfish.com>
    Re: Profiling Perl, flock and NT <gellyfish@gellyfish.com>
        RE:Routing users by username & password msorense@my-deja.com
    Re: reverse urlizier <gellyfish@gellyfish.com>
    Re: sorting pointers? <gellyfish@gellyfish.com>
    Re: uses for PERL <rootbeer@redcat.com>
    Re: uses for PERL <gellyfish@gellyfish.com>
    Re: Using perl's modules DBD:Mysql and DBI and mysql <jeff@vpservices.com>
    Re: Variables inside strings? <gellyfish@gellyfish.com>
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: 10 Jun 2000 20:04:39 +0200
From: Gisle Aas <gisle@ActiveState.com>
Subject: Re: obfuscated but useful magic() - for your perlish amusement
Message-Id: <m3g0qlbefc.fsf@eik.g.aas.no>

merlyn@stonehenge.com (Randal L. Schwartz) writes:

> OK, now you got me thinking...
> 
>     sub magic {
>       my%r=map{my$m=substr gmtime 26e5*($_-.5),4,3;$m,$_,$_,$m}1..12;
>       $r{+shift};
>     }
> 
> 74 chars not counting the leading/trailing whitespace. :)

But that one can obviously be rewritten to:

sub magic{+{map{my$m=substr gmtime 26e5*($_-.5),4,3;$m,$_,$_,$m}1..12}->{$_[0]}}

-- 
Gisle Aas


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

Date: 10 Jun 2000 20:13:04 +0200
From: Gisle Aas <gisle@ActiveState.com>
Subject: Re: obfuscated but useful magic() - for your perlish amusement
Message-Id: <m3ya4d9zgv.fsf@eik.g.aas.no>

"Swee Heng" <sweeheng@usa.net> writes:

> >     sub magic {
> >       my%r=map{my$m=substr gmtime 26e5*($_-.5),4,3;$m,$_,$_,$m}1..12;
> >       $r{+shift};
> >     }
> >
> > 74 chars not counting the leading/trailing whitespace. :)
> >
> > Durn it -- I swore I'd never get into a game of golf.  Now I'm in the
> > lead. :)
> 
> wait a minute! this is 5 chars less (took out the (, -.5) and replace 6 with
> 5)!
> 
>       sub magic {
>         my%r=map{my$m=substr gmtime 25e5*$_,4,3;$m,$_,$_,$m}1..12;
>         $r{+shift};
>       }

  sub magic{+{map{my$m=substr gmtime 25e5*$_,4,3;$m,$_,$_,$m}1..12}->{$_[0]}}

-- 
Gisle Aas


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

Date: 10 Jun 2000 21:10:35 +0100
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: obfuscated but useful magic() - for your perlish amusement
Message-Id: <8hu7br$l2q$1@orpheus.gellyfish.com>

On Sun, 11 Jun 2000 00:50:40 +0800 Swee Heng wrote:
> 
>                                back to the working table. :o)
> 

Once I can take but twice ... I think you mean drawing board ;-}

/J\
-- 
fortune oscar homer


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

Date: Sat, 10 Jun 2000 20:43:10 GMT
From: bart.lateur@skynet.be (Bart Lateur)
Subject: Re: obfuscated but useful magic() - for your perlish amusement
Message-Id: <3947a5f5.3961245@news.skynet.be>

Swee Heng wrote:

>sub magic{local$_='Jan1Feb2Mar3Apr4May5Jun6Jul7Aug8Sep9Oct10Nov11Dec12';
>my$d=shift;$d=~/^\D+$/?(/$d(\d+)/)[0]:$d=~/^\d+$/?(/(\D+)$d/)[0]:''or'bad'}
>
>printf "%s => %s\n", $_=$ARGV[0], magic($_);
>---------------------------------------------------------------------------
>
>A friend asked me how to map months to numbers and vice versa, i.e. Apr =>
>4, 12 => Dec. The magic() sub is the shortest I coded. Any challengers? :o)

I don't know about short. Concise, yes.

    my @monthname = qw'Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec';
    @monthnumber{@monthname} = 0 .. $#monthname;

Convert month number to month name:

	$months[$i-1]

month name to month number:

	1+$monthnumber{$n}


Note that originally, my indexes are zero based, so Jan is number 0.

-- 
	Bart.


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

Date: Sat, 10 Jun 2000 15:22:19 -0500
From: "Tim" <tcuffel@exactis.com>
Subject: Re: obfuscated but useful magic() - for your perlish amusement
Message-Id: <23y05.636$Ck1.33989@den-news1.rmi.net>

Gisle Aas wrote in message ...

>  sub magic{+{map{my$m=substr gmtime 25e5*$_,4,3;$m,$_,$_,$m}1..12}->{$_[0]}}


Shaving a char...

   sub magic{+{map{(my$m=substr gmtime 25e5*$_,4,3),$_,$_,$m}1..12}->{$_[0]}}




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

Date: 10 Jun 2000 20:29:24 +0100
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: Operator Overloading, Use Parent, Multiple Inheritance
Message-Id: <8hu4uk$knc$1@orpheus.gellyfish.com>

On Sat, 10 Jun 2000 04:25:08 GMT Neo-X wrote:
> I've been messing around with perl classes lately and came across a couple
> things that puzzled me.
> 
> First,  is there any way to do operator overloading in Perl like you can
> with C++?
> 

There is an overload module which will allow you to do this to some
degree :

   man overload

> Secondly, when you create a derived class, from what I can tell, you push
> parent class names onto the @ISA list.  In addition, it seems that you have
> to "use parent" for each parent class as well.  Is this correct, or am I
> doing something wrong?
> 

You will need to at least 'require' the module as in general you wont care
about any importing but your class will need to know about the methods
that it will inherit.

> Finally, I can't quite figure out the intricacies of multiple inheritance.
> Specifically, if a given class has two parent classes who both contain the
> function foo(), how does the child class behave if an instance of it calls
> foo? Or if the child class has its own foo() function, how does the
> psuedoclass SUPER behave? From the program I tested, in either case (with or
> without a child polymorphic foo()), it seems to simply display a warning
> about function redefinition and use the foo() from the last parent class
> that was 'use'd.  But then again, this may result from an extension of the
> 'use' problem stated above, if such a problem exists.
> 

It will use the first one it find in the modules in @INC;

> Ther is another problem that crossed my mind about multiple inheritence that
> I haven't been able to test yet because of the above problem.  Suppose you
> have a function called Ancestor.  Derived from it are two classes, call them
> Mother and Father.  Then you have a function called Child that is a child
> class of both Mother and Father.  Now say Ancestor has a function called
> foo(), and I call foo() on an instance of Child.  Theoretically, how would
> the program respond (would be foo() be called twice, once, something else)?
> 

It will use the one defined in the current package or if there isnt one 
the fist one it finds in the packages in @INC.

/J\
-- 
fortune oscar homer


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

Date: 10 Jun 2000 20:21:43 +0100
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: Operator Overloading, Use Parent, Multiple Inheritance
Message-Id: <8hu4g7$kmk$1@orpheus.gellyfish.com>

On Sat, 10 Jun 2000 15:07:27 GMT Neo-X wrote:
> Ah, but that would cost money, which is an item I am currently lacking.

Sure, but its probably a lot cheaper for you than the time it takes for
us to type it in for you ;-}

/J\
-- 
fortune oscar homer


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

Date: Sat, 10 Jun 2000 19:32:38 GMT
From: bart.lateur@skynet.be (Bart Lateur)
Subject: Re: PLEASE HELP: Perl for WWW
Message-Id: <39429794.280556@news.skynet.be>

Jonathan Stowe wrote:

>> If you must use MS$ Word as your edit do save the file as a text file.
>
>Of course it might be possible to write a source filter that will extract
>Perl program source from a word document...

What version?

If MS did keep making Word's file format a moving target, it might
indeed be feasable. Now it's extremely impractical.

-- 
	Bart.


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

Date: Sat, 10 Jun 2000 14:00:10 -0500
From: "Randy Kobes" <randy@theory.uwinnipeg.ca>
Subject: Re: pnggraph/gifgraph and logarithmic axes
Message-Id: <8hu3bn$fhm$1@canopus.cc.umanitoba.ca>


Sundar Raman <cybertoast@mindless.com> wrote in
     message news:393FA58C.F8332EB@mindless.com...
> Michael Schlueter wrote:
> >
> > I think there is an option for log-scales. What you can always do is to
> > calculate the log(y) separately and display this on a linear y'-scale.
>
> Problem is that the axis values will be incorrect.  The end user needs
> to be able to see the "true" values.  It's easy enough for me to graph
> the log(y), but there's no option in PNGgraph to specify a different set
> of axis-markers than the data-set :-(

If you use GD::Graph, there's an option y_number_format
which could be useful in this context. See, for example,
http://theoryx5.uwinnipeg.ca/CPAN/data/GDGraph/Graph.html
for a discussion of its use.

best regards,
randy kobes





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

Date: 10 Jun 2000 21:15:46 +0100
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: Problem with Perl + CPAN...
Message-Id: <8hu7li$l35$1@orpheus.gellyfish.com>

On Thu, 8 Jun 2000 14:36:25 +0200 news.sektornet.dk wrote:
> 
> Btw. first time i used perl -MCPAN... it created some sort of configuration
> file from answers i typed in like what cpan archieve to use etc.. any idea
> where i can find the config file and how i can reconfigure it?

in the .cpan sub-directory of your home directory.  You could read the
CPAN manpage to find out how to change the settings or you could simply
delete the MyConfig.pm file and reconfigure from scratch.

/J\
-- 
fortune oscar homer


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

Date: 10 Jun 2000 20:35:12 +0100
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: Profiling Perl, flock and NT
Message-Id: <8hu59g$koe$1@orpheus.gellyfish.com>

On Sat, 10 Jun 2000 03:54:36 +0200 Ralf Hoffmann wrote:
> - Is flock valid under Windows NT ? - How can I handle exclusive write
> access ?

Of course it is.  The perlport manpage is probably a good place for you
to look if you have similar questions as it discusses cross platform
compatibility issues.

/J\
-- 
fortune oscar homer


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

Date: Sat, 10 Jun 2000 21:30:26 GMT
From: msorense@my-deja.com
Subject: RE:Routing users by username & password
Message-Id: <8huc1j$bb8$1@nnrp1.deja.com>

Dear Perl Gurus:

I am trying to implement a password script on my site (Apache server)
that simply directs the user to a protected page based on their username
and password.  The protected page may contain further links to other
protected pages that the user should be able to freely retrieve (i.e.
should only have to enter username and password once).   I don't think
the htaccess per-directory authorization scheme works because it only
protects directories, it does not route a particular user to a
particular page.

Hopefully someone can give me the general strategy behind such a script.
  My current script tries to use chmod to change the permissions of the
requested file ($request), send the URL corresponding to that file
($target), and then reset the permissions.  This is shown in the snippet
below:

  chmod 0755, $request;
  print redirect(-uri => $target);
  chmod 0700, $request;

For some reason I can't understand, chmod does not work when the script
is called over the net, it only works when called from a shell.  (i.e.
perl password.pl).  My script also sends an encrypted cookie to the
browser with the username and the higest level directory they are
permitted to access so that subsequent requests won't require reentering
a username and password (I think that will work but I haven't tested it
yet).

I have read many other articles on this newsgroup regarding password
protection but I haven't quite found what I'm looking for.  Again, I'm
looking for answers to the following:

1. Is there a generally accepted method to route users with a valid
username and password to a protected page based on their username and
password?  If so what is it?

2.  Can I use htaccess in conjunction with such a scheme?

3.  Why doesn't my call to chmod work when called over the net?

Thank you for your help,

Mark Sorensen


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: 10 Jun 2000 19:19:13 +0100
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: reverse urlizier
Message-Id: <8hu0r1$khh$1@orpheus.gellyfish.com>

On Sat, 10 Jun 2000 14:46:21 GMT red [2] wrote:
> thanks a long time ago to you guys i got an url to convert into a link.
> now, i need to get it to go the other way around
> 
> $post =~ s!(http://[\-~A-Za-z0-9_/\.]+)!<a href=\"$1\">$1</a>!gi;
> is what im using to convert http://www.quadmonkey.co.uk/ into
> <a href=" etc
> 
> but i want to convert
> <a href="http://[\-~A-Za-z0-9_/\.]+)">URLNAME</a> into
> URLNAME <http://url/>
> 
> can you wonderful people help me out again... im not sure how to strip from
> the href= to the > , mainly because im not sure how to do it IF there's a "
> or not (id like it to be flexible)
> 

You want to use HTML::Parser - there is an example at my page :
<http://www.gellyfish.com/htexamples/> that will do almost exactly what
you want.

/J\
-- 
fortune oscar homer


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

Date: 10 Jun 2000 20:14:34 +0100
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: sorting pointers?
Message-Id: <8hu42q$klv$1@orpheus.gellyfish.com>

On Sat, 10 Jun 2000 18:18:22 +0800 Swee Heng wrote:
> 
> No one seems to refer to them as pointers - just call them references. But
> yes, I do think of them as pointers.

But they arent pointers what use is there in thinking of them like that.
They refer to items within the Perl data space - but do not point to
actual memory locations as you might have in C or assembler.  Asserting
that this might be the case is only going to lead to confusion with people
thinking that it is possible to address memory locations like that in Perl.

/J\
-- 
fortune oscar homer


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

Date: Sat, 10 Jun 2000 12:24:49 -0700
From: Tom Phoenix <rootbeer@redcat.com>
Subject: Re: uses for PERL
Message-Id: <Pine.GSO.4.10.10006101220450.10286-100000@user2.teleport.com>

On Sat, 10 Jun 2000, david wrote:

> I know PERL is widely used on websites, but it seems PHP is becoming
> increasingly popular everyday.  What other uses are there for PERL
> besides creating websites?

It's totally useless. That's why there are no postings in this newsgroup.
As, of course, you saw when you looked at it before you posted your
message, right?

Please, don't waste our time and yours when you can learn this stuff for
yourself. Read any dozen of the past days' postings and you'll start to
see what people are using Perl for. But it's an open-ended tool; any list
is sure to be incomplete, just like a list of what books can teach you,
what recipes make good food, or what obvious questions will be asked on
Usenet.

Cheers!

-- 
Tom Phoenix       Perl Training and Hacking       Esperanto
Randal Schwartz Case:     http://www.rahul.net/jeffrey/ovs/



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

Date: 10 Jun 2000 21:00:13 +0100
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: uses for PERL
Message-Id: <8hu6od$l20$1@orpheus.gellyfish.com>

On Sat, 10 Jun 2000 11:54:18 -0500 david wrote:
> I know PERL is widely used on websites, but it seems PHP is becoming
> increasingly popular everyday.  What other uses are there for PERL
> besides creating websites?

That is Perl BTW.  Please read the appropriate documentation where this is
discussed.

Anyhow where do you want to start ?  Bearing in mind that only 15 out
the 234 example programmes I have made for this newsgroup in the last
6 months have been anything to do with the CGI ...

/J\
-- 
fortune oscar homer


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

Date: Sat, 10 Jun 2000 12:58:14 -0700
From: Jeff Zucker <jeff@vpservices.com>
Subject: Re: Using perl's modules DBD:Mysql and DBI and mysql
Message-Id: <39429DD6.C77AA4E9@vpservices.com>

Sebastien THOMAS wrote:
> 
> Hi all,
> 
> I'm trying to do an "insert" to my mysql database from a perl program.
> I've installed the DBI module for perl, as so the DBD:mysql-msql driver.
> 
> $dbh_mysql=DBI->connect("news\@localhost","$user",$password, "mysql");

Wrong.

> $dbh_mysql=DBI->connect("dbi:mysql:news\@localhost","$user",$password);)

Right, but the backslash is not needed and you do not turn on error
checking.

> $dbh_mysql=Mysql->Connect($host,$database,$user,$password)

The non-DBI mysql.pm module says right in it that it has been replaced
by the DBI version.  Use it with DBI, not stand alone.

> Third problem is that nobody seems to do insert to an mysql databas 

??? There must be hundreds or thousands of people doing that.  The
examples in DBI.pm are clear.

-- 
Jeff


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

Date: 10 Jun 2000 19:56:59 +0100
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: Variables inside strings?
Message-Id: <8hu31r$kk7$1@orpheus.gellyfish.com>

On Sat, 10 Jun 2000 13:33:33 +0200 Raphael Pirker wrote:
> Hi,
> 
> I have the following code:
> 
> #######
> ## form-input of $message ##
> <input type="hidden" name="message" value="Hi !!name/!! (!!email/!!),
> Thanks for visiting !!site/!!. Hope you enjoyed your stay.">
> ## end form-input ##
> 
> 
> ## inside the script ##
> $message     = $FORM{message};
> $message     =~ s/!!(.*?)\/!!/\$$1/g;
> print MAIL "$message"
> #######
> 
> This returns:
> 
> Hi $name ($email),
> Thanks for visiting $site. Hope you enjoyed your stay.
> 
> Which is just how I wanted it, only I wanted the variables to be "parsed".
> How do I get Perl to exchange the variables with the values inside the
> script? Right now it appears to be a string which has a "\" infront of the
> "$" sign so it gets printed out as-is...

In the first instance I would recommend that you read the item in perlfaq4:

       How can I expand variables in text strings?

/J\
-- 
fortune oscar homer


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

Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 16 Sep 99)
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: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.

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 V9 Issue 3314
**************************************


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