[21935] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4157 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Nov 21 18:05:53 2002

Date: Thu, 21 Nov 2002 15:05:10 -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, 21 Nov 2002     Volume: 10 Number: 4157

Today's topics:
        Can Postmail's "From" arg be used as return address? <alphseeker@yahoo.com>
    Re: Can Postmail's "From" arg be used as return address <nobull@mail.com>
    Re: File::Find problem (scope of wanted)? <krahnj@acm.org>
    Re: Format  a one line file to get two columns (Scott Blankenship)
    Re: Format  a one line file to get two columns <usenet@dwall.fastmail.fm>
    Re: Format  a one line file to get two columns <krahnj@acm.org>
    Re: having problems parsing an error log. <fxn@hashref.com>
    Re: help this Newbie in Distress (Walter Roberson)
    Re: help this Newbie in Distress <bkennedy@hmsonline.com>
    Re: help this Newbie in Distress <dover@nortelnetworks.com>
    Re: if statment help (Scott Blankenship)
    Re: implementing a self() method for classes <goldbb2@earthlink.net>
        Math::TrulyRandom on Linux (lynto)
    Re: Math::TrulyRandom on Linux (Walter Roberson)
    Re: passing address between classes - OO type question <tassilo.parseval@post.rwth-aachen.de>
    Re: passing address between classes - OO type question <uri@stemsystems.com>
    Re: Perl one-liners in Win32 <krahnj@acm.org>
    Re: Question about interpolation during substitution <goldbb2@earthlink.net>
        regex subroutine \) passing variables <lance@augustmail.com>
    Re: semantics of nested backreferences in regular expre <edi@agharta.de>
    Re: semantics of nested backreferences in regular expre (Malcolm Dew-Jones)
    Re: Setting cookie <spam@digitaltension.com>
    Re: top-posting (was Re: help this Newbie in Distress) <nobull@mail.com>
    Re: Using Getopts in a case-insensitive manner (Johan Vromans)
    Re: Web Graphs <news@tvreclames.nl>
    Re: Web Graphs <mgjv@tradingpost.com.au>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Thu, 21 Nov 2002 11:34:39 -0800
From: "Patrick Flinn" <alphseeker@yahoo.com>
Subject: Can Postmail's "From" arg be used as return address?
Message-Id: <MxaD9.2$PE2.125@news03.micron.net>

I'm launching Postmail.exe from my code, and providing it with a valid email
address as the "From" argument (-F "address").  However, when the email is
recieved, the address ( bob@smithinc.com, let's say) has been parsed into
"bob_smithinc_com".

This seems to preclude the use of the "From" address as a return address in
case the email bounces.  Is the -F argument just not meant to be used this
way, or is there some trick to making it work?

Also, if anyone can point me to some Postmail.exe documentation, I would
appreciate it.

Thanks. -Pat




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

Date: 21 Nov 2002 19:51:28 +0000
From: Brian McCauley <nobull@mail.com>
Subject: Re: Can Postmail's "From" arg be used as return address?
Message-Id: <u9r8der9a7.fsf@wcl-l.bham.ac.uk>

"Patrick Flinn" <alphseeker@yahoo.com> writes:

> Newsgroups: comp.lang.perl.misc

This is a Perl newsgroup.  Here we discuss matters relating to Perl.

> I'm launching Postmail.exe from my code, and...
 [ snip question about a program called postmail.exe ]

> Also, if anyone can point me to some Postmail.exe documentation, I would
> appreciate it.

Perhaps you should look at wherever you got the program from.

Can you explain how you could even imagine that this question had the
slightest thing to do with Perl?

-- 
     \\   ( )
  .  _\\__[oo
 .__/  \\ /\@
 .  l___\\
  # ll  l\\
 ###LL  LL\\


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

Date: Thu, 21 Nov 2002 21:21:29 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: File::Find problem (scope of wanted)?
Message-Id: <3DDD4E1E.D44B4682@acm.org>

Jeremy Smith wrote:
> 
> perl 5.6.1
> 
> I'm having some issues with File::Find.  I have a program that:
> +calls find on a directory with a subroutine A
>   If the item is a directiory, A calls another subroutine B that contains
>   another find.   That find's subroutine, C, does a bunch of work and finishes.
> 
> My problem is, that when the main program should again call A, it instead calls
> _C_.  That is, it seems that that the wanted subroutine has been overwritten.
> 
> The code is printed below.
> The first time the first find loops through, it works.
> find calls statmodule, finds a directory, runs javacount on the directory,
> and then returns.
> On the second time, find calls "javacount" not statmodule.
> How do I make it call "statmodule".
> 
> Thanks in advance.
> 
> Jeremy Smith
> 
> #!/usr/bin/perl
> #use strict;
> use File::Find;
> use File::Basename;
> use Getopt::Std;
> 
> #checks options, v=verbose q=quiet d=directory name
> getopts('vqd:');
> $rootdir=".";
> if ($opt_d){
>   $rootdir="$opt_d";
> }
> find ( \&statmodule, $rootdir);
> 
> sub statmodule {
>   if (-d && !/\.$/) { #this means, if it's a directory unless it's "."
>   print $File::Find::name . "\n"; #print the module name
>   $modulename = $File::Find::name;
>   codecounter($modulename);
>   $File::Find::prune = 1;         #stop decending because we don't want to go down

Since you are only getting the directories at this level it is probably better to use
opendir/readdir.


>   }
> }
> 
> sub codecounter {
> $totallinecount = $totalcodecount = $totalcommentcount = 0;
> if ($_[0]){
>   $countdir="$_[0]";
              ^     ^
Useless use of quotes.

> }
> find (\&javacodecount, $countdir);
> print $totallinecount . "," . $totalcodecount . "," . $totalcommentcount ."\n";
> 
> sub javacodecount {
>   if (/\.java$/) {
>   my $total = my $code_count = my $comments = my $file_contents = my $file_stripped = 0;
>   print "Now opening file $File::Find::name\n";
>   undef $/;
>   $file_stripped = $file_contents;
>                                 # strip lines containing only "{" or "}"
>   while ($file_contents =~ s/\n[ \t]*[\{\}][ \t]*\n/\n/) {}

This is more idiomatically written as

    1 while $file_contents =~ s/\n[ \t]*[\{\}][ \t]*\n/\n/;

However, you don't need a while loop if you use a pattern that doesn't overlap

    $file_contents =~ s/^[ \t]*[\{\}][ \t]*\n/\n/mg;


>                                 # strip blank lines
>   while ($file_contents =~ s/\n\s*\n/\n/) {}
>   $file_contents =~ s/^\s*\n//;
>                                 # count the resulting number of lines
>   $total = ($file_contents =~ tr/\n/\n/);
> 
>                                 # strip "//" and "/* */" style comments.
>                                 # HA!  just try to figure out this regexp:
>   $file_stripped =~ s:(//.*)|(/\*([^*]*\*+[^*/])*[^*]*\*+/)::g;

Have you read the FAQ about stripping C and C++ comments?

perldoc -q "strip C style comments"


>                                 # strip lines containing only "{" or "}"
>   while ($file_stripped =~ s/\n[ \t]*[\{\}][ \t]*\n/\n/) {}
>                                 # strip blank lines
>   while ($file_stripped =~ s/\n\s*\n/\n/) {}
>   $file_stripped =~ s/^\s*\n//;
>                                 # count the resulting number of lines
>   $code_count = ($file_stripped =~ tr/\n/\n/);
> 
>   $comments = ($total - $code_count);
>   print "Total Lines: ". $total . "\n";
>   print "Comments: " . $comments . "\n";
>   print "Code: " .  $code_count . "\n";
>   $totallinecount = $totallinecount + $total;
>   $totalcodecount = $totalcodecount + $code_count;
>   $totalcommentcount = $totalcommentcount + $comments;
> print $totallinecount . "," . $totalcodecount . "," . $totalcommentcount ."\n";
>   }
> }
> }
> 
> sub readFileContents {
>   my($fileName) = shift;
>   my($buffer);
>   $fileName = basename("$fileName");
                         ^         ^
Useless use of quotes

>   local($/) = undef;
>   open(FILE, $fileName)
>     or die "couldn't open $fileName for reading: $!\n";
>   $buffer = <FILE>;
>   close(FILE);
>   return($buffer);
>   }


This should do what you want:

#!/usr/bin/perl 
use warnings;
use strict;
use Cwd;
use File::Find;
use Getopt::Std;

#checks options, v=verbose q=quiet d=directory name
my %opt;
getopts( 'vqd:', \%opt );
my $rootdir = $opt{'d'} || cwd;

opendir my $dh, $rootdir or die "Cannot open $rootdir: $!";
my @dirs = map { "$rootdir/$_" } grep { -d and not /^\.\.?$/ } readdir $dh;
closedir $dh;

my $totallinecount;
my $totalcodecount;
my $totalcommentcount;

find( \&javacodecount, @dirs );

sub javacodecount {
    return unless /\.java$/;

    print "Now opening file $File::Find::name\n";
    my $file_contents = readFileContents( $File::Find::name );

    $file_contents .= "\n" if substr( $file_contents, -1 ) ne "\n";

    my $total = $file_contents =~ tr/\n//;

    # Remove C and C++ comments as per perlfaq6
    $file_contents =~
    s:/\*[^*]*\*+([^/*][^*]*\*+)*/|//[^\n]*|("(\\.|[^"\\])*"|'(\\.|[^'\\])*'|.[^/"'\\]*):$2:gs;
    # Remove lines containing only "{" or "}"
    $file_contents =~ s/^[ \t]*[{}][ \t]*\n//mg;
    # Remove blank lines
    $file_contents =~ s/^\s*\n//mg;

    # count the resulting number of lines
    my $code_count = $file_contents =~ tr/\n//;

    my $comments = $total - $code_count;

    print "Total Lines: $total\n";
    print "Comments: $comments\n";
    print "Code: $code_count\n";

    $totallinecount    += $total;
    $totalcodecount    += $code_count;
    $totalcommentcount += $comments;

    print "$totallinecount,$totalcodecount,$totalcommentcount\n";
    }

sub readFileContents {
    my $fileName = shift;
    local $/;
    open my $fh, $fileName or die "couldn't open $fileName for reading: $!\n";
    return <$fh>;
    }

__END__



John
-- 
use Perl;
program
fulfillment


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

Date: 21 Nov 2002 13:03:35 -0800
From: sjblanky@yahoo.com (Scott Blankenship)
Subject: Re: Format  a one line file to get two columns
Message-Id: <63206a4f.0211211303.510dbafc@posting.google.com>

tellaway@polymersealing.com (Tim Ellaway) wrote in message news:<1ffffd4b.0211210430.6f9db003@posting.google.com>...
> Please could someone tell me how to format a file containing one
> continuous line so that there's two columns?
> 
> E.g. from this: 
> 
> -0.529766666666667 -8.89410873529075 -0.522816666666667
> -8.628319980362 0 0 4.9781502 12.02 5.0119999 12.05375
> 
> to this:
> 
> -0.529766666666667 -8.89410873529075
> -0.522816666666667 -8.628319980362
> 0 0
> 4.9781502 12.02
> 5.0119999 12.05375


#!/usr/local/bin/perl -w
use strict;

local $/;
$_ = <DATA>;
s/(\S+)\s+(\S+)\s+/$1 $2\n/g;
print;

__DATA__
-0.529766666666667 -8.89410873529075 -0.522816666666667 -8.628319980362 0 0
4.9781502 12.02 5.0119999 12.05375


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

Date: Thu, 21 Nov 2002 21:43:15 -0000
From: "David K. Wall" <usenet@dwall.fastmail.fm>
Subject: Re: Format  a one line file to get two columns
Message-Id: <Xns92CDAA18522DCdkwwashere@216.168.3.30>

Tad McClellan <tadmc@augustmail.com> wrote on 21 Nov 2002:

> Tim Ellaway <tellaway@polymersealing.com> wrote:
> 
>> Please could someone tell me how to format a file containing one
>> continuous line so that there's two columns?
> 
> But the data you showed was NOT on one continuous line.
> 
> This will work whether the "parts" are on a single line or not.
> 
> ----------------------------
> #!/usr/bin/perl
> use warnings;
> use strict;
> 
> { local $/;    # enable "slurp mode"
>   $_ = <DATA>;
> }
> 
> print "$1 $2\n" while /(\S+)\s+(\S+)/g;
> 
> __DATA__
> -0.529766666666667 -8.89410873529075 -0.522816666666667
> -8.628319980362 0 0 4.9781502 12.02 5.0119999 12.05375

Here's a longer way that that doesn't slurp the whole file.  

Yeah, the OP said it was all on one line, but I was pleased with this idea.   
I'm sure it's much slower than your way (all that splitting, pushing, and 
shifting), but for a large file with lots of relatively short lines it uses 
less memory, right?

----------------------------
use strict;
use warnings;
my @parts;
while ( <DATA> ) {
    push @parts, split;
    print shift @parts, ' ', shift @parts, "\n" while (@parts >=2 );
}
# print any leftovers (in case the total number of parts is odd)
print shift @parts, "\n" if @parts;

__DATA__
-0.529766666666667 -8.89410873529075 -0.522816666666667
-8.628319980362 0 0 4.9781502 12.02 5.0119999 12.05375
2.71828
----------------------------

I put that 2.71828 in there make the number of parts odd.  (e is a bit 
"odd", isn't it? :-)


-- 
David K. Wall - usenet@dwall.fastmail.fm
"Oook."


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

Date: Thu, 21 Nov 2002 22:13:38 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: Format  a one line file to get two columns
Message-Id: <3DDD5A58.A827B1CD@acm.org>

Tim Ellaway wrote:
> 
> Please could someone tell me how to format a file containing one
> continuous line so that there's two columns?
> 
> E.g. from this:
> 
> -0.529766666666667 -8.89410873529075 -0.522816666666667
> -8.628319980362 0 0 4.9781502 12.02 5.0119999 12.05375
> 
> to this:
> 
> -0.529766666666667 -8.89410873529075
> -0.522816666666667 -8.628319980362
> 0 0
> 4.9781502 12.02
> 5.0119999 12.05375

perl -i~ -0777pe's/(\S+)\s+(\S+)\s+/$1 $2\n/g' yourfile


John
-- 
use Perl;
program
fulfillment


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

Date: Thu, 21 Nov 2002 19:57:02 +0000 (UTC)
From: Francesc Xavier Noria <fxn@hashref.com>
Subject: Re: having problems parsing an error log.
Message-Id: <arjdqe$77q$1@news.ya.com>

Newsgroups: comp.lang.perl.misc
From: Francesc Xavier Noria <fxn@hashref.com>
Subject: Re: having problems parsing an error log.
References: <f16594a7.0211211057.79b7ff30@posting.google.com>
Followup-To: 

Newsgroups: comp.lang.perl.misc
From: Francesc Xavier Noria <fxn@hashref.com>
Subject: Re: having problems parsing an error log.
References: <f16594a7.0211211057.79b7ff30@posting.google.com>
Followup-To: 

In article <f16594a7.0211211057.79b7ff30@posting.google.com>, JimL. wrote:
: I am trying to write a script to capture some specifics of an error
: log.
: the log sample is as follows:

[sample]

: My problem is, I need the date stamp, error title, and certain offsets
: of only the Bad Password Disconnects. The output would need to be
: something like...
: 18 NOV 02  07:55:39AM^M
: *** Illegal Number Of Bad Password Attempts Accessing Mailbox^M
: 00010   90160000 DE000100 03000A28 12743983   
: This is what I have so far:
: 
: open (ERRORLOG,"$inputfile")|| die "cant open $inputfile $!\n";
: @errorlog=(<ERRORLOG>);
: foreach $line(@errorlog){
: 	if ($line=~/^\d{2}\s{1}\D{3}.*/){
: 		$date=$line;
: 		chomp$date
: 		}
: 	if ($line=~/.*Bad.*Passw.*/){
: 		$error=$line;
: 		chomp $error;
: 		}
: 	if ($line=~/^00010\s{3}/){
: 		$mbx=$line;
: 		chomp $mbx;
: 		}
: }
: Now I'm STUCK!! Can anyone help get me kickstarted again

Depending on some assumptions, the way I'd write this would be

    # untested
    while ($line = <ERRORLOG>) {
        next unless $line =~ /^\d{2} \D{3} \d{2}/;
	$date = $line;
	$msg  = <ERRORLOG>;
        next unless $msg =~ /Bad.*Passwd/;
	do {
	    $mbx = <ERRORLOG>;
	} until $mbx =~ /^00010/;
	print $date, $msg, $mbx;
    }

Since you know the format of the file you can try to read the necessary
lines in a row once you get one with a date. If the message is not the one
we are interested in we look no further, with "next" we go to the top of the
while and iterate again until another date is found.

Note that newlines are not chomped, since you want them in the output we
leave them untouched.

Hope that helps.

-- fxn


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

Date: 21 Nov 2002 19:14:31 GMT
From: roberson@ibd.nrc.ca (Walter Roberson)
Subject: Re: help this Newbie in Distress
Message-Id: <arjban$s72$1@canopus.cc.umanitoba.ca>

In article <3DDCEBAB.32AD1736@chris.com>, D  <doris@chris.com> wrote:
:By the way, regarding, "top-posting"...... how can ANYONE think "bottom posting"
:is a good thing!?!  Nothing is more annoying than having to scroll down. Why not
:see the answer right away?

Most people, when they post, express more than one idea. Many people
here, when they reply, deal with those ideas one at a time, carefully
deconstructing the syntax, semantics and assumptions of the original
message a piece at a time, in order to show clearly how the expressed
train of thought led to misunderstanding or faulty conclusions.

When people have perl issues, it's not usually due to a simple typo:
it's often because they have misunderstood some foundation and have
built shakey mental edifices thereupon. To just give them "the answer"
(i.e., corrected code) is to just paper over a problem: we do
them a better service when we strip the logic down and rebuild.
--
Would you buy a used bit from this man??


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

Date: Thu, 21 Nov 2002 17:03:53 -0500
From: "Ben Kennedy" <bkennedy@hmsonline.com>
Subject: Re: help this Newbie in Distress
Message-Id: <fg6dnVx5W6kHxUCgXTWcpw@giganews.com>


"D" <doris@chris.com> wrote in message news:3DDCEBAB.32AD1736@chris.com...

> By the way, regarding, "top-posting"...... how can ANYONE think "bottom
posting"
> is a good thing!?!

Blind people, for one.  This point and others are mentioned at:

http://www.dickalba.demon.co.uk/usenet/guide/faq_topp.html

--Ben Kennedy




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

Date: Thu, 21 Nov 2002 16:58:53 -0600
From: "Bob Dover" <dover@nortelnetworks.com>
Subject: Re: help this Newbie in Distress
Message-Id: <arjobm$82h$1@bcarh8ab.ca.nortel.com>

"Ben Kennedy" wrote...
> "D" wrote...
> > By the way, regarding, "top-posting"...... how can ANYONE think "bottom
> > posting" is a good thing!?!
> Blind people, for one.

Another problem often seen in this NG (but not flamed as much as top-posting) is
the habit some have of quoting an entire article only to comment on a line or two
at the end.




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

Date: 21 Nov 2002 14:08:28 -0800
From: sjblanky@yahoo.com (Scott Blankenship)
Subject: Re: if statment help
Message-Id: <63206a4f.0211211408.75e87848@posting.google.com>

"Mike" <44movies@warpdriveonline.com> wrote in message news:<A9CdnfHPKMXnKEagXTWc3w@warpdrive.net>...
> The simple things are driving me crazy today.  Ok, I have a subroutine that
> checks a name for invalid chars and badwords so someone can't register the
> name "cock" or "../badstuff".
> 
> The program opens a file handle BADWORDS which is a one per line file of
> words we don't want registered
> 
> ok...The if statment in the while loop is the problem.  If I use 'eq'
> nothing ever matches, if I use '==' everything matches... any idea what I'm
> doing wrong here?
> 
> 
> Here it is:
> 
> sub checkUsername() {
>     if ($username =~ /^[a-zA-Z0-9-)+$/) {
>         print STDOUT "good\n";
>     } else {
>      exit;
>     }
>     while(<BADWORDS>) {
>         if ($username eq $_) {
>             print STDOUT "BADWORD!\n";
>             exit;
>         } else {
>             print STDOUT "good";
>         }
>     }
>  print STDOUT "Name check complete\n";
> }

In addition to the other fine suggestions already posted, I would
recosider your design with regard to looping through a BADWORDS file
for every username you check. It would seem better to read the file
once, store the results in a list, and loop through the list. Your use
of a subroutine suggests you'll be running this bit of code more than
once per program execution. Reading the file everytime would slow
things down (although it's probably not noticable of your badwords
file is small).


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

Date: Thu, 21 Nov 2002 16:59:55 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: implementing a self() method for classes
Message-Id: <3DDD575B.1A018E65@earthlink.net>

Xavier Noria wrote:
[snip]
> First, this is a method factory:
> 
> package MethodFactory;
> 
> require Exporter;
> use base 'Exporter';
> use vars '@EXPORT';
> 
> @EXPORT = qw(&defmethod &self);
> 
> sub defmethod (*&) {
>     my $name = shift;
>     my $body = shift;
>     my $pkg  = caller;
>     eval <<METHOD;
> package $pkg;
> sub $name {
>     local \$self = shift;
>     sub self { return \$self };
>     &\$body;
> }
> METHOD
> }
> 
> 1;

I seriously dislike the use of eval STRING, especially when it's
unnecessary.  Furthermore, using a package variable $self doesn't seem
the best thing to do... well, not unless you explicitly state that
you're doing that.  Plus, you're not properly localizing the &self
sub... you should at least *try* to make it disappear when you're not in
a method call.

package MethodFactory;
BEGIN {
   require Exporter;
   @ISA = qw(Exporter);
   @EXPORT = qw(&self $self);
   @EXPORT_OK = qw(&defmethod);
}

use strict;

sub self () {
   require Carp;
   Carp::croak("Not in a method call");
}

use Symbol qw(qualify_to_ref);
sub defmethod(*&) {
   my $methglob = qualify_to_ref( shift, caller );
   no strict 'refs';
   my $methcode = \&{+shift};
   my $selfglob = \*{ caller() . "::self" };
   use strict 'refs';
   *$methglob = sub {
      my $self = shift();
      local *$selfglob;
      *$selfglob = sub () { $self };
      *$selfglob = \$self;
      &$methcode;
   };
}
1;
__END__
[untested]


-- 
my $n = 2; print +(split //, 'e,4c3H r ktulrnsJ2tPaeh'
 ."\n1oa! er")[map $n = ($n * 24 + 30) % 31, (42) x 26]


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

Date: 21 Nov 2002 12:00:49 -0800
From: lynch@agere.com (lynto)
Subject: Math::TrulyRandom on Linux
Message-Id: <503469eb.0211211200.39fe05c9@posting.google.com>

Greetings:

Is Math::TrulyRandom the best module to use for generating Truly
Random numbers or is there a better module. I've looked in CPAN and
there seems to be quite a few Random Modules. I've found that
Math::TrulyRandom doesn't run "make test" on Redhat Linux (hangs)....

Thanks for the help in advance!

Tom


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

Date: 21 Nov 2002 21:35:35 GMT
From: roberson@ibd.nrc.ca (Walter Roberson)
Subject: Re: Math::TrulyRandom on Linux
Message-Id: <arjjj7$2jr$1@canopus.cc.umanitoba.ca>

In article <503469eb.0211211200.39fe05c9@posting.google.com>,
lynto <lynch@agere.com> wrote:
:Is Math::TrulyRandom the best module to use for generating Truly
:Random numbers or is there a better module. I've looked in CPAN and
:there seems to be quite a few Random Modules. I've found that
:Math::TrulyRandom doesn't run "make test" on Redhat Linux (hangs)....

 * WARNING: depending on the particular platform, truerand() output may
 * be biased or correlated.  In general, you can expect about 16 bits of
 * "pseudo-entropy" out of each 32 bit word returned by truerand(),
 * but it may not be uniformly diffused.  You should therefore run
 * the output through some post-whitening function (like MD5 or DES or
 * whatever) before using it to generate key material.  (RSAREF's
 * random package does this for you when you feed truerand() bits to the
 * seed input function.)


 * This software seems to work well (at 16 bits per truerand() call) on
 * a Sun Sparc-20 under SunOS 4.1.3 and on a P100 under BSDI 2.0.  You're
 * on your own elsewhere.


I think you'll have to tell us more about how you want "best"
to be measured before we can tell you whether Math::TrulyRandom
is appropriate for your needs. Are you measuring speed? Code size?
Correlation -- under which tests? 

For some people, the "best" module would be the one that fetches
true random numbers over the 'net, from one of the sources that
measures radioactive decay. Others need a lot of random numbers
very quickly (radioactive decay cannot provide a bounded time to
get a result.) Some people need to be able to generate locally and
aren't allowed to fetch over the 'net. Some need uniform distribution,
others normal distribution, others gaussian or poisson...

--
Pity the poor electron, floating around minding its own business for
billions of years; and then suddenly Bam!! -- annihilated just so
you could read this posting.


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

Date: 21 Nov 2002 20:55:34 GMT
From: "Tassilo v. Parseval" <tassilo.parseval@post.rwth-aachen.de>
Subject: Re: passing address between classes - OO type question
Message-Id: <arjh86$5b7$1@nets3.rz.RWTH-Aachen.DE>

Also sprach Uri Guttman:

>>>>>> "TvP" == Tassilo v Parseval <tassilo.parseval@post.rwth-aachen.de> writes:

>  TvP> Yet I don't see why this subtle distinction between reference and
>  TvP> referent is needed here. In which way would the (apparently incorrect)
>  TvP> idea which I have of objects so far affect my programs or render them
>  TvP> even unfunctional?
> 
> it is both a conceptual issue and it can affect code if you are not
> aware of it. the blessing affects the referent itself and not the
> reference. so this works:
> 
> 	bless \%foo ;
> 	(\%foo)->method() ;
> 
> 	$bar = \%foo ;
> 	$bar->method() ;
> 
> %foo is the referent and $bar is the reference object.

Thanks, Uri. I think that's clear now. It's really the thing that is
referred to that is changed. Hadn't I seen that I'd hardly have believed
it. Odd, how long one can live quite happily with a misconception in
mind (two years now in my case).

Tassilo
-- 
$_=q!",}])(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus;})(rekcah{lrePbus;})(lreP{rehtonabus;})(rehtona{tsuJbus!;
$_=reverse;s/sub/(reverse"bus").chr(32)/xge;tr~\n~~d;eval;


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

Date: Thu, 21 Nov 2002 21:26:30 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: passing address between classes - OO type question
Message-Id: <x78yzmfwcb.fsf@mail.sysarch.com>

>>>>> "TvP" == Tassilo v Parseval <tassilo.parseval@post.rwth-aachen.de> writes:

  >> bless \%foo ;
  >> (\%foo)->method() ;
  >> 
  >> $bar = \%foo ;
  >> $bar->method() ;
  >> 
  >> %foo is the referent and $bar is the reference object.

  TvP> Thanks, Uri. I think that's clear now. It's really the thing that is
  TvP> referred to that is changed. Hadn't I seen that I'd hardly have believed
  TvP> it. Odd, how long one can live quite happily with a misconception in
  TvP> mind (two years now in my case).

like i said, many have this misconception. and when i first read OOP i
had it too. the perl docs at that time were not clear on this (i am not
sure if that has improved). damian came up with the name referent for
the blessed thingy to make it clearer. similarly he says the 'invocant'
(what is usually stored in $self) is the object which is used in a
method call to clarify that area.

uri

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


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

Date: Thu, 21 Nov 2002 21:47:50 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: Perl one-liners in Win32
Message-Id: <3DDD5448.F4FD337E@acm.org>

Dave E wrote:
> 
> Yes, now I get it!  I knew about the -n or -p switches but something in my
> head just didn't make the connection between the filelist in @ARGV and the
> loop.  I guess the begin thing threw me off.
> 
> so, now:
>     perl -e "BEGIN{@ARGV=map{glob}@ARGV}foreach (@ARGV) {print \"$_\n\"}" *.*

Since you are not using -p or -n switch there is no need for the BEGIN
block.  Also, you can use the qq operator to avoid backslashes.

     perl -e "foreach (map{glob}@ARGV) {print qq($_\n)}" *.*

OR

     perl -le "print for map{glob}@ARGV" *.*




John
-- 
use Perl;
program
fulfillment


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

Date: Thu, 21 Nov 2002 17:26:04 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Question about interpolation during substitution
Message-Id: <3DDD5D7C.A0E1BBEB@earthlink.net>

MG wrote:
> 
> I have the following code:
> 
> my $search_text='(abc)d';
> my $replacement_text='$1 some other text';
> my $text='abcdef';
> 
> $text=~s/$search_text/$replacement_text/;
> 
> # Now I would like for $text to become: 'abc some other textdef'

Try:

my $replacement = sub { qq[$1 some other text] };

$text =~ s/$search_text/&$replacement()/e;

-- 
my $n = 2; print +(split //, 'e,4c3H r ktulrnsJ2tPaeh'
 ."\n1oa! er")[map $n = ($n * 24 + 30) % 31, (42) x 26]


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

Date: Thu, 21 Nov 2002 16:52:07 -0600
From: Lance Hoffmeyer <lance@augustmail.com>
Subject: regex subroutine \) passing variables
Message-Id: <pan.2002.11.21.22.52.05.756814.27400@augustmail.com>

I keep trying to run this subroutine.
It keeps bombing out on the second item

"\(\+5\) VERY"

Quantifier follows nothing before HERE 2 (+ <<HERE
if I remove the "+" I get error
Unmatched ( before HERE   ( <<HERE


So, I guess my slashs are not being passed and a \+ is being interpreted
as a + and a \( is being interpreted as a (.

How do I correct this?

sub find_num{
##############################
#Subroutine to find numbers
#The following variables are needed
# TABLE   = 82;                                        # Table number to look for
# ROWTEXT = "YES, AWARE OF KEEP";                      # Row text (Should be row with freqs not percents)
# COLUMN  = "N";          XT,COLUMN)
##############################
my $colnum = column2column_number($_[2]);
$file =~ /TABLE\s*$_[0].*?$_[1].*?(?:(\d{1,2}\.\d)\D+){$colnum}/s;
return my $num = $1;
}



my $var = find_num(103,"\(\+5\) VERY","H");$var = Round($var,0);



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

Date: 21 Nov 2002 21:22:51 +0100
From: Edi Weitz <edi@agharta.de>
Subject: Re: semantics of nested backreferences in regular expressions
Message-Id: <87ptsyy8o4.fsf@bird.agharta.de>

peter@PSDT.com (Peter Scott) writes:

> In article <87smxxq6ly.fsf@bird.agharta.de>,
>  Edi Weitz <edi@agharta.de> writes:
> >With 5.6.1 and 5.8.0 I see this behaviour
> >
> >  edi@bird:~ > perl -le 'use Data::Dumper; $_="a"; /((a)*)*/; print Dumper $1, $2'
> >  $VAR1 = '';
> >  $VAR2 = undef;
> >
> >  edi@bird:~ > perl -le 'use Data::Dumper; $_="ab"; /((a)|(b))*/; print Dumper $1, $2, $3'
> >  $VAR1 = 'b';
> >  $VAR2 = 'a';
> >  $VAR3 = 'b';
> >
> >which confuses me. 
> 
> Me too.  Since no one followed up, I took this to Jeff Pinyan, and
> he supplied the answer below, which I am posting at his request:

Thanks. I began to fear that I was the only one interested in
this... :)

I don't have Mr. Pinyan's address but would appreciate if you could
forward my reply to him:

> ---------- begin forwarded material ----------
> 
> ((a)*)* matches the "a", and puts it in $1 and $2, but then the
> outermost * causes ((a)*) to try again!  The (a)* matches zero times
> (and /(x)?/ sets $1 to undef if the 'x' can't match), and we can
> match the empty string zero or more times.
> 
> It's confusing, I admit, but I understand it.  Use (?{ ... }) to
> help get it:

Yes, I understand that, too. My problem is not that I don't understand
what's happening (I have in fact implemented a regular expression
matcher myself), my problem is that I think the two cases aren't
mutually consistent - or at least that the behaviour shown here is
counter-intuitive.

>   "a" =~ m{
>     (?:
>       ( (a)* )
>       (?{
>         printf "1=%s; 2=%s\n",
>           defined($1) ? "'$1'" : "undef",
>           defined($2) ? "'$2'" : "undef"
>       })
>     )*
>   }x;
> 
> The output is:
> 
>   1='a'; 2='a'
>   1=''; 2=undef
> 
> >>   edi@bird:~ > perl -le 'use Data::Dumper; $_="ab"; /((a)|(b))*/; print Dumper $1, $2, $3'
> >>   $VAR1 = 'b';
> >>   $VAR2 = 'a';
> >>   $VAR3 = 'b';
> 
> Ok, I think I know why this result (above) differs from this result
> (below):
> 
> >  edi@bird:~ > perl -le 'use Data::Dumper; $_="ab"; print Dumper $1, $2, $3 while /((a)|(b))/g'
> >  $VAR1 = 'a';
> >  $VAR2 = 'a';
> >  $VAR3 = undef;
> >
> >  $VAR1 = 'b';
> >  $VAR2 = undef;
> >  $VAR3 = 'b';
> 
> The second approach uses more than one regex; so ALL the $DIGIT vars
> are "reset".

Hmm. I've always seen the 'while /.../g' thing as asking the _same_
regex to continue where it left off - I didn't see it as _different_
regexes at work all of which start with a 'clear' state (so to
say). That explains this part but IMHO the inconsistency remains (see
below).

> The first approach shows a behavior of regexes I
> hadn't previously paid attention to:
> 
>   "XY" =~ m{ (?: (X) | (Y) ){2} }x
> 
> stores X in $1, and store Y in $2 without undef'ing $1.

OK, and here we return to my initial problem: In the first example -
"a" =~ /((a)*)*/ - $2 is undef'ed before entering the outer group for
the second time. In the second example - "ab" =~ /((a)|(b))*/ - $2 is
_not_ undef'ed before entering the outer group for the second time. It
keeps its value "a" from the first repetition while in the first
example $2 does _not_ keep its value "a" from the first repetition.

So my point, again, is: To me this looks inconsistent. Either you
undef all enclosed back-references before entering a group or you
don't. My examples seem to imply that Perl sometimes does this and
sometimes doesn't. I'd like to know if there's a rationale for this
that I don't grasp or if this is a bug.

Thanks again,
Edi.

> 
> ------ end forwarded material -----------
> 
> -- 
> Peter Scott
> http://www.perldebugged.com


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

Date: 21 Nov 2002 13:30:30 -0800
From: yf110@vtn1.victoria.tc.ca (Malcolm Dew-Jones)
Subject: Re: semantics of nested backreferences in regular expressions
Message-Id: <3ddd5076@news.victoria.tc.ca>

Edi Weitz (edi@agharta.de) wrote:
: peter@PSDT.com (Peter Scott) writes:

: > In article <87smxxq6ly.fsf@bird.agharta.de>,
: >  Edi Weitz <edi@agharta.de> writes:
: > >With 5.6.1 and 5.8.0 I see this behaviour
: > >
: > >  edi@bird:~ > perl -le 'use Data::Dumper; $_="a"; /((a)*)*/; print Dumper $1, $2'
: > >  $VAR1 = '';
: > >  $VAR2 = undef;
: > >
: > >  edi@bird:~ > perl -le 'use Data::Dumper; $_="ab"; /((a)|(b))*/; print Dumper $1, $2, $3'
: > >  $VAR1 = 'b';
: > >  $VAR2 = 'a';
: > >  $VAR3 = 'b';
: > >
: > >which confuses me. 
: > 

This is also different than at least one earlier perl.

perl -v 
This is perl, version 5.005_03 built for MSWin32-x86-object

perl -le "use Data::Dumper; $_='a'; /((a)*)*/; print Dumper $1, $2"
$VAR1 = '';
$VAR2 = 'a';

It's interesting to use /g to examine everything in the match

        perl -e "$_='a'; print join ':',/((a)*)*/g"

        :a::

	perl -e "$_='a'; print join ':',/((a)*)/g"   # note no final *

	a:a::

The first one is certainly counter intuitive to me.

However, I think as a rule of thumb, it's bad to extract individual
captures when you start *'ing on the outside of the ()'s because this sort
of confusion arises very easily.  Or use /g to get all the captures and
then figure out what to do with them programatically.  It's also not clear
to me what it should, intuitively, mean to capture a single item using an
expression that says match and capture multiple times.  In other places in
perl where a list is returned into a single item it is clearly pointed out
that there is no standard rule on how it is handled. 



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

Date: Thu, 21 Nov 2002 13:43:10 -0800
From: "Brandon L" <spam@digitaltension.com>
Subject: Re: Setting cookie
Message-Id: <utqkrveq5pu3c7@corp.supernews.com>

"Asad" <g0khaasa@cdf.toronto.edu> wrote in message
news:Pine.LNX.4.30.0211132142060.5378-100000@b210-02.cdf...
: Hi!
:
: I have the following sub-routine in my addToCart.pl file:
:
: sub print_page_start {
:         if ($session_id) {
:                 my $cookie = $query->cookie(-name=>'session_id',
: -value=>$session_id);
:                 print $query->header(-cookie=>$cookie);
:         }
:         else {
:                 print $query->header;
:         }
:         print "<html>\n<head></head>\n";
:         print "<body>\n";
: }
:
: However, it is totally goofing up and writing out the cookie
information
: out to my html file. It appears on the page that is. However, when I
view
: source, the cookie information appears right at the end, even after
the
: </html> tag.
:
: BTW, I did need it to redisplay the same page (by calling another
perl
: function) so I inlcuded this line on top of my perl script:
:
: require ("fetchMovies.pl") || die ("Can't find fetchMovies.pl\n");
:
: and somehow it miracilously reloads the page :s
:
: Lil help.

This is what I use to get cookies

sub getCookie {
    $cookies = $ENV{'HTTP_COOKIE'};
    @allCookies = split(/;\s*/, $cookies);
    foreach $i (@allCookies){
        ($name,$value) = split(/\s*=\s*/, $i);
        $cookie{$name} = $value;
    }
}

so to get what you want (i think) i would do a print
"$cookie{session_id}";




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

Date: 21 Nov 2002 19:46:45 +0000
From: Brian McCauley <nobull@mail.com>
Subject: Re: top-posting (was Re: help this Newbie in Distress)
Message-Id: <u9vg2qr9i2.fsf@wcl-l.bham.ac.uk>

tadmc@augustmail.com (Tad McClellan) writes:

> 
> D <doris@chris.com> wrote:
> 
> > but I seriously  think I comprize at LEAST 60% of the
> > population!

Doris, for any measure of good character 60% of people will fall below
the upper 40%ile.  Does this make being below the 40%ile something to
which one should aspire?

> What matters in this newsgroup is the population of this newsgroup,
> and they clearly do not have your opinion in the majority.

A straight majority is not the issue.  He who pays the piper calls the
tune.  If the piper is giving his services pro bono then the piper
calls the tune.  Without the people who give their time to provide
accurate answers this newsgroup would beniefit nobody. 

-- 
     \\   ( )
  .  _\\__[oo
 .__/  \\ /\@
 .  l___\\
  # ll  l\\
 ###LL  LL\\


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

Date: 21 Nov 2002 22:38:27 +0100
From: jvromans@squirrel.nl (Johan Vromans)
Subject: Re: Using Getopts in a case-insensitive manner
Message-Id: <m2bs4ihacs.fsf@phoenix.squirrel.nl>

Paulo Dutra <paulo@xilinx.com> writes:

> &Getopt::Long::config('ignore_case');

This is the default behaviour.

-- Johan


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

Date: Thu, 21 Nov 2002 21:28:47 +0100
From: Bart van den Burg <news@tvreclames.nl>
Subject: Re: Web Graphs
Message-Id: <arjfqd$8d6$1@reader12.wxs.nl>

Simon Oliver wrote:
> haniz wrote:
> 
>> This could sound a ridiculous issue... but I'd like to confirm if I'm
>> on the right way to solve my problem.
>>
>> If I want to use Perl to create a graph to be published on a dynamic
>> web page, I have to follow these steps:
>>
>> 1. Download and install the packages GD and GDGraph;
>> 2. Code a mygraph.pl file using these packages' functions;
>> 3. Insert a <img src=.../mygraph.pl?args> on my html page.
>>
>> I appreciate a simple "yes" or "no" response. Any complements will be
>> welcome.
> 
> 
> yes
> 
> Don't forget to send a content type header with the image. Here's an 
> example script:
> 
> #!perl -w
> use strict;
> use GD::Graph::bars;
> 
> my @data = ( [qw(a b c d e f g)], [1,2,3,4,5,6,7] );
> 
> my $graph = GD::Graph::bars->new(200, 200);
> 
> my $gd = $graph->plot(\@data);
> 
> binmode STDOUT;
> 
> print "Content-type: image/png\n\n";
> print $gd->png();
> 

it's that easy???
damn, i've been working for more that an hour creating a graph with GD !!
ow well, back to the drawing tables ;)

Bart



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

Date: Thu, 21 Nov 2002 22:52:59 GMT
From: Martien Verbruggen <mgjv@tradingpost.com.au>
Subject: Re: Web Graphs
Message-Id: <slrnatqp2m.djj.mgjv@verbruggen.comdyn.com.au>

On 21 Nov 2002 06:59:44 -0800,
	haniz <haniz@uol.com.br> wrote:
> This could sound a ridiculous issue... but I'd like to confirm if I'm
> on the right way to solve my problem.
> 
> If I want to use Perl to create a graph to be published on a dynamic
> web page, I have to follow these steps:
> 
> 1. Download and install the packages GD and GDGraph;

There are other modules that do charting (see search.cpan.org), but
most of them would require GD. To be able to use GD::Graph, you'll
also need to get the GDTextUtils pacakge.

> 2. Code a mygraph.pl file using these packages' functions;

And hopefully, this mygraph.pl would use the CGI module to do all the
CGI specific stuff. It will make your life enormously easier, compared
to when you try to do it all yourself.

> 3. Insert a <img src=.../mygraph.pl?args> on my html page.

Yep. I'd also include width and height attributes, and probably an
alt.

> I appreciate a simple "yes" or "no" response. Any complements will be
> welcome.

Ok.

Yes, except that you also need GD::Text::Align from the GDTextUtils
package, because it is used by GD::Graph.

Martien
-- 
                        | 
Martien Verbruggen      | +++ Out of Cheese Error +++ Reinstall
Trading Post Australia  | Universe and Reboot +++
                        | 


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

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


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