[25153] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 7402 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Nov 14 00:05:47 2004

Date: Sat, 13 Nov 2004 21:05:06 -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           Sat, 13 Nov 2004     Volume: 10 Number: 7402

Today's topics:
    Re: creating and validating encrypted password <sam.wun@authtec.net>
    Re: creating and validating encrypted password <sam.wun@authtec.net>
    Re: Difficulty with slice of referenced array <sdn.girths00869@zoemail.net>
        FAQ 4.11: How do I get a random number between X and Y? <comdog@panix.com>
        FAQ 9.23: How do I find out my hostname/domainname/IP a <comdog@panix.com>
        Image::EXIF troubles <dd-b@dd-b.net>
    Re: Image::EXIF troubles <1usa@llenroc.ude.invalid>
    Re: Lisp's "some" and "every" functions <tassilo.von.parseval@rwth-aachen.de>
    Re: passing arguments from template <1usa@llenroc.ude.invalid>
    Re: Reflection or discovery of object methods in perl? <sdn.girths00869@zoemail.net>
    Re: regexp s// too greedy (bettyann)
    Re: regexp s// too greedy <noreply@gunnar.cc>
    Re: Trying to get sendmail to attach text file to email <and11@rol.ru>
    Re: Trying to get sendmail to attach text file to email (Mortgageloan2004)
    Re: Trying to get sendmail to attach text file to email <1usa@llenroc.ude.invalid>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Sun, 14 Nov 2004 10:29:27 +0800
From: sam <sam.wun@authtec.net>
Subject: Re: creating and validating encrypted password
Message-Id: <cn6hff$iga$1@news.hgc.com.hk>

Brian McCauley wrote:

> 
> If the password file is to use the standard Unix crypt() function then 
> you would use the Perl builitin function that provides an interface to
> Unix crypt() function.  (Guessing the name is left as an exercise for 
> the reader).
> 
>> Is there any example written in perl that I can follow?
> 
> 
> Yes, in the documentation of the aforementioned function.
> 
> 

Thanks for the hints.
I found there is another perl module Digest::md5 for the same purpose. 
What is this difference compare to Crypt::UnixCrypt_XS?

Thanks
Sam


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

Date: Sun, 14 Nov 2004 11:15:46 +0800
From: sam <sam.wun@authtec.net>
Subject: Re: creating and validating encrypted password
Message-Id: <cn6k6a$k0m$1@news.hgc.com.hk>

sam wrote:

> Brian McCauley wrote:
> 
>>
>> If the password file is to use the standard Unix crypt() function then 
>> you would use the Perl builitin function that provides an interface to
>> Unix crypt() function.  (Guessing the name is left as an exercise for 
>> the reader).
>>
>>> Is there any example written in perl that I can follow?
>>
>>
>>
>> Yes, in the documentation of the aforementioned function.
>>
>>
> 
> Thanks for the hints.
> I found there is another perl module Digest::md5 for the same purpose. 
> What is this difference compare to Crypt::UnixCrypt_XS?
> 
I found found Digest::MD5 is more usable. But the example only shows 
adding MD5 encrypted password to file, there is no method/function for 
reading and validate the password.

Sam.

> Thanks
> Sam


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

Date: Sat, 13 Nov 2004 22:28:38 -0600
From: "Eric J. Roode" <sdn.girths00869@zoemail.net>
Subject: Re: Difficulty with slice of referenced array
Message-Id: <Xns95A0EF1DF90C1sdn.comcast@216.196.97.136>

Henry Law <lawshouse.public@btconnect.com> wrote in 
news:lu04p0df0bsrs7b92q4o727bk0fv4oi92c@4ax.com:

> This doesn't seem to be a FAQ; I tried Googling but couldn't find a
> suitable search string to get a manageable set of results ...
[...] 
> I expected $lref->[0..2] to be a slice consisting of the first three
> elements of the array pointed to by $lref, i.e. the same as
> ($lref->[0],$lref->[1],$lref->[2])) but plainly it's not.  In order to
> get an array to pass to my subroutine am I condemned to coding the
> elements separately, or is there a correct way of coding the slice?

Anno Siegel has already given you a fine answer, but I would like to 
amend it.  He gave you

    @{$lref}[0..2]

which is fine and all, but I greatly prefer the simpler

    @$lref[0..2]

You know that the leading character (the 'sigil') must be $ if what you 
will end up with is a scalar, and @ if what you'll end up with is an 
array (er, list.  You know).  So, for a scalar dereference of an 
arrayref, use

    $foo->[$index]

and for an array slice dereference of an arrayref, use

    @$foo[$index, $index, ...]

You don't need the -> (and in fact, it'd be an error to use it), because 
$foo doesn't need to be further dereferenced after the @.

Bonus: For an array slice of a hash reference, use

    @$foo{$key, $key, $key}

Once you grok all of the above notations, you will be well on your way to 
Perl reference mastery, my son.

-- 
Eric
`$=`;$_=\%!;($_)=/(.)/;$==++$|;($.,$/,$,,$\,$",$;,$^,$#,$~,$*,$:,@%)=(
$!=~/(.)(.).(.)(.)(.)(.)..(.)(.)(.)..(.)......(.)/,$"),$=++;$.++;$.++;
$_++;$_++;($_,$\,$,)=($~.$"."$;$/$%[$?]$_$\$,$:$%[$?]",$"&$~,$#,);$,++
;$,++;$^|=$";`$_$\$,$/$:$;$~$*$%[$?]$.$~$*${#}$%[$?]$;$\$"$^$~$*.>&$=`


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

Date: Sun, 14 Nov 2004 05:03:01 +0000 (UTC)
From: PerlFAQ Server <comdog@panix.com>
Subject: FAQ 4.11: How do I get a random number between X and Y?
Message-Id: <cn6ou5$m5f$1@reader1.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.11: How do I get a random number between X and Y?

    "rand($x)" returns a number such that "0 <= rand($x) < $x". Thus what
    you want to have perl figure out is a random number in the range from 0
    to the difference between your *X* and *Y*.

    That is, to get a number between 10 and 15, inclusive, you want a random
    number between 0 and 5 that you can then add to 10.

        my $number = 10 + int rand( 15-10+1 );

    Hence you derive the following simple function to abstract that. It
    selects a random integer between the two given integers (inclusive), For
    example: "random_int_in(50,120)".

       sub random_int_in ($$) {
         my($min, $max) = @_;
          # Assumes that the two arguments are integers themselves!
         return $min if $min == $max;
         ($min, $max) = ($max, $min)  if  $min > $max;
         return $min + int rand(1 + $max - $min);
       }



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

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: Sat, 13 Nov 2004 23:03:01 +0000 (UTC)
From: PerlFAQ Server <comdog@panix.com>
Subject: FAQ 9.23: How do I find out my hostname/domainname/IP address?
Message-Id: <cn63r5$gga$1@reader1.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.

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

9.23: How do I find out my hostname/domainname/IP address?

    The normal way to find your own hostname is to call the `hostname`
    program. While sometimes expedient, this has some problems, such as not
    knowing whether you've got the canonical name or not. It's one of those
    tradeoffs of convenience versus portability.

    The Sys::Hostname module (part of the standard perl distribution) will
    give you the hostname after which you can find out the IP address
    (assuming you have working DNS) with a gethostbyname() call.

        use Socket;
        use Sys::Hostname;
        my $host = hostname();
        my $addr = inet_ntoa(scalar gethostbyname($host || 'localhost'));

    Probably the simplest way to learn your DNS domain name is to grok it
    out of /etc/resolv.conf, at least under Unix. Of course, this assumes
    several things about your resolv.conf configuration, including that it
    exists.

    (We still need a good DNS domain name-learning method for non-Unix
    systems.)



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

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: Sat, 13 Nov 2004 20:21:31 -0600
From: David Dyer-Bennet <dd-b@dd-b.net>
Subject: Image::EXIF troubles
Message-Id: <m2u0rtjhlg.fsf@gw.dd-b.net>

Anybody else using Image::EXIF to read exposure data and such out of
image files from digital cameras?  Or is there some other module that
people like better for that? 

I find its error reporting confusing or unreliable or something.  I've
got a case where it doesn't read any data, but doesn't indicate
$exif->error() either; but this is under mod_perl, and *doesn't*
happen standalone, so it's probable running afoul of some restriction
there (and I've asked on the mod_perl mailing list, no responses
yet). 
-- 
David Dyer-Bennet, <mailto:dd-b@dd-b.net>, <http://www.dd-b.net/dd-b/>
RKBA: <http://noguns-nomoney.com/> <http://www.dd-b.net/carry/>
Pics: <http://dd-b.lighthunters.net/> <http://www.dd-b.net/dd-b/SnapshotAlbum/>
Dragaera/Steven Brust: <http://dragaera.info/>


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

Date: 14 Nov 2004 02:59:22 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: Image::EXIF troubles
Message-Id: <Xns95A0DFADE9222asu1cornelledu@132.236.56.8>

David Dyer-Bennet <dd-b@dd-b.net> wrote in news:m2u0rtjhlg.fsf@gw.dd-b.net:

> Anybody else using Image::EXIF to read exposure data and such out of
> image files from digital cameras?  Or is there some other module that
> people like better for that? 
> 
> I find its error reporting confusing or unreliable or something.  I've
> got a case where it doesn't read any data, but doesn't indicate
> $exif->error() either; but this is under mod_perl, and *doesn't*
> happen standalone, so it's probable running afoul of some restriction
> there (and I've asked on the mod_perl mailing list, no responses
> yet). 

Please post a short but complete script that exhibits the problem you are 
experiencing.

Sinan.


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

Date: Sat, 13 Nov 2004 20:13:48 +0100
From: "Tassilo v. Parseval" <tassilo.von.parseval@rwth-aachen.de>
Subject: Re: Lisp's "some" and "every" functions
Message-Id: <slrncpcn7c.1ef.tassilo.von.parseval@localhost.localdomain>

Also sprach Brian McCauley:

> Tassilo v. Parseval wrote:

>> Not so much merged into but renamed to. I was made aware that
>> List::MoreUtils would be a better namespace choice. So that means the
>> latest release is always at 
>> 
>>     http://search.cpan.org/~vparseval/List-MoreUtils/
>> 
>> Tassilo
>
> Any chance the old apply() function could find a home there?

Ah, sure. I'm always looking for more useful list operations.

> sub apply (&@) {
>      my $action = shift;
>      &$action for my @values = @_;
>      wantarray ? @values : $values[-1];
> }

I can use that verbatimly for the pure-Perl implementation. The XS one
shouldn't be too tricky either. I'll do that tomorrow.

Tassilo
-- 
$_=q#",}])!JAPH!qq(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?<=sub).+q#q!'"qq.\t$&."'!#+sexisexiixesixeseg;y~\n~~dddd;eval


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

Date: 14 Nov 2004 02:57:18 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: passing arguments from template
Message-Id: <Xns95A0DF53B721Easu1cornelledu@132.236.56.8>

mortgageloan2004@aol.com (Mortgageloan2004) wrote in
news:20041113214853.07211.00000503@mb-m10.aol.com: 

> I have a template file:

Posting the same stuff multiple times with different subjects will not make 
you many friends.

Sinan


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

Date: Sat, 13 Nov 2004 22:18:07 -0600
From: "Eric J. Roode" <sdn.girths00869@zoemail.net>
Subject: Re: Reflection or discovery of object methods in perl?
Message-Id: <Xns95A0ED52EE77Bsdn.comcast@216.196.97.136>

bboett@sept.u-strasbg.fr () wrote in
news:cmq8q7$fcq$1@news.u-strasbg.fr: 

> hello!
> 
> again i am trying to get some stuff working (this time CORBA...), and
> again i would need an inspection tool telling me what class an object
> is and what methods its possesses...
> 
> i know UNIVERSAL::can but that one expects a method name, it doesn't
> spit out the whole list when not provided with a method name...
> 
> so is there that type of mechanism in perl?
> 
> thanks

The 'ref' operator will tell you what class an object is a member of.
(Usually).

There is no real way to list all the methods for a Perl class, because 
classes in Perl are allowed to (and sometimes do!) create methods on the 
fly, via the AUTOLOAD subroutine.  A class can potentially have an 
unlimited number of methods, none of which are defined at compile time.

-- 
Eric
`$=`;$_=\%!;($_)=/(.)/;$==++$|;($.,$/,$,,$\,$",$;,$^,$#,$~,$*,$:,@%)=(
$!=~/(.)(.).(.)(.)(.)(.)..(.)(.)(.)..(.)......(.)/,$"),$=++;$.++;$.++;
$_++;$_++;($_,$\,$,)=($~.$"."$;$/$%[$?]$_$\$,$:$%[$?]",$"&$~,$#,);$,++
;$,++;$^|=$";`$_$\$,$/$:$;$~$*$%[$?]$.$~$*${#}$%[$?]$;$\$"$^$~$*.>&$=`


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

Date: 13 Nov 2004 16:08:10 -0800
From: bettyann@campbell.com (bettyann)
Subject: Re: regexp s// too greedy
Message-Id: <287ea6c.0411131608.400c4a44@posting.google.com>

> Now this is something that's going slow it down a bit, matching n times
> for n possibilities.  

indeed.

> A hash lets you do them all in one go.  Quite simple:
> 
>     my %replace = (
>         'hold.bmp' => 0,
>         'go.bmp'   => 1,
>         # ...
>         NaN        => -1,
>     );
> 
> Then the five substitutions could become (untested, probably more
> the spirit than the real thing)
> 
>     s/^(([^,]*,){5}([^,]*))/$1,$replace{ $2}/;

thanks!  this works well.  altho the i needed to use the $3 capture as
a key to the hash, ie,

   s/^(([^,]*,){5}([^,]*))/$1,$replace{$3}/;

as the key is captured with the 3rd open-parenthesis.

gunnar, thanks, too.  altho i found the "e" option in the command
"s//e"  gave me this error so i simply removed the "e":

Scalar found where operator expected at (eval 4571) line 1, near
"}${4}"
        (Missing operator before ${4}?)

thanks for all the help and ideas.  i've incorporated hash tables in a
few other places in my code where they really make the logic cleaner.

thanks!
- bettyann


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

Date: Sun, 14 Nov 2004 01:26:52 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: regexp s// too greedy
Message-Id: <2vnnghF2nnlojU1@uni-berlin.de>

bettyann wrote:
> gunnar, thanks, too.  altho i found the "e" option in the command
> "s//e"  gave me this error so i simply removed the "e":
> 
> Scalar found where operator expected at (eval 4571) line 1, near
> "}${4}"
>         (Missing operator before ${4}?)

Well, Anno's and my suggestions weren't identical. The /e modifier makes 
the right side of the s/// operator expect an expression rather than a 
string, and I made use of that to prevent changes (and warnings) for 
possible lines whose sixth column don't match any of the hash keys. Only 
you can tell what exactly you need.

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


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

Date: Sun, 14 Nov 2004 05:10:10 +0000
From: Andrew Tkachenko <and11@rol.ru>
Subject: Re: Trying to get sendmail to attach text file to email.
Message-Id: <cn6eun$3dc$1@news.rol.ru>

Mortgageloan2004 wrote on 14 Ноябрь 2004 01:27:

> I get an email, but I'm having a problem getting sendmail to see the path
> I think. 

sendmail does not care about file path. You pass to sendmail just base64
encoded data.

> If you go to www.mortgage-applications-online.com/form3/search.htm and
enter
> 1001 Scot into the box 2 records will come up. If you highlight the link,
you
> can see in your browser bar what goes to the program below: The
dataresent.htm
> page isn't getting printed either via print "Location: ...

Sorry, I did'nt dig your code to see what's the problem (if any) with
sendmail, but here you should remove this line from your script:

> print "Content-type: text/html\n\n";

to get user redirected to desired page.


Regards,
Andrew.



-- 
Andrew


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

Date: 14 Nov 2004 02:33:04 GMT
From: mortgageloan2004@aol.com (Mortgageloan2004)
Subject: Re: Trying to get sendmail to attach text file to email.
Message-Id: <20041113213304.07211.00000502@mb-m10.aol.com>

Andrew,

I tried what you said here:

use CGI::Carp qw(fatalsToBrowser);
use MIME::Base64 qw(encode_base64);
my $datalocation     = 	"../" . $ENV{QUERY_STRING}.".txt";
#print $datalocation;
sendfile($admin_mail, $from, $subject, $messageToAdmin, $datalocation);
print "Location: ../pages/dataresent.htm";
exit;

I removed the print "Content-type: text/html
and updleoaded it and I got a 404 not found error. It's not printing the html
page in the browser. Nor is it attaching the text file to my message.

Scot


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

Date: 14 Nov 2004 02:55:54 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: Trying to get sendmail to attach text file to email.
Message-Id: <Xns95A0DF16E4ECFasu1cornelledu@132.236.56.8>

mortgageloan2004@aol.com (Mortgageloan2004) wrote in
news:20041113202738.06574.00000626@mb-m15.aol.com: 

> I get an email, but I'm having a problem getting sendmail to see the
> path I think. I use a template to pass the info.  Here is the
> template: 

Use one of the CPAN template modules such as HTML::Template.

> If you go to www.mortgage-applications-online.com/form3/search.htm and
> enter 1001 Scot into the box 2 records will come up. If you highlight
> the link, you can see in your browser bar what goes to the program
> below: The dataresent.htm page isn't getting printed either via print
> "Location: ... 

Use CGI.pm.

> #!/usr/bin/perl

use strict;
use warnings;

See http://search.cpan.org/~yves/MIME-Lite-3.01/lib/MIME/Lite.pm

> ##########################################################
> use CGI::Carp qw(fatalsToBrowser);
> use MIME::Base64 qw(encode_base64);
> my $datalocation     =      "../" . $ENV{QUERY_STRING}.".txt";

Bang!

> sub sendfile {
> my $email = $_[0];
> my $from = $_[1];
> my $subject = $_[2];
> my $message = $_[3];
> my $file = $_[4];

my ($email, $from, $subject, $message, $file) = @_;

Not that I think you should use this code.

I can't follow your code at all.

> sub get_file {
>      my $zip;
>      my $getfile = shift;
>      open (F, $getfile) || error("can't open file");

open my $F, '<', $getfile or ...;

>      binmode F;
>         while (read(F, my $buf, 60*57)) {

Why 60*57?

>      exit;

You should probably die here rather than exiting.

Actually, I just noticed something:

> sub sendfile {
> ...
> my $file_cont=encode_base64(get_file($file));
> ...
> }

 ...

> sub get_file {
> 	my $zip;
> 	my $getfile = shift;
> 	open (F, $getfile) || error("can't open file");
> 	binmode F;
>         while (read(F, my $buf, 60*57)) {
>         $zip .= encode_base64($buf);
>    }
> 	close F;
> return $zip;
> }

The string you return from get_file is already base64 encoded. WHy are you 
encoding it again.

Overall, the best thing you can do with the script you posted is to dump 
it. Just cobbling something together from the examples provided with CGI.pm 
and Mime::Lite would work infinitely better.


Sinan.


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

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


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