[19432] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 1627 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Aug 27 14:05:41 2001

Date: Mon, 27 Aug 2001 11:05:11 -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: <998935511-v10-i1627@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Mon, 27 Aug 2001     Volume: 10 Number: 1627

Today's topics:
    Re: adding rows in a text file (John J. Trammell)
        anonymous code refs and 'sort' <djberge@uswest.com>
    Re: anonymous code refs and 'sort' <Rainer.Klier@erl.sbs.de>
    Re: anonymous code refs and 'sort' <Rainer.Klier@erl.sbs.de>
    Re: anonymous code refs and 'sort' <djberge@uswest.com>
    Re: anonymous code refs and 'sort' <djberge@uswest.com>
    Re: anonymous code refs and 'sort' <djberge@uswest.com>
    Re: Avoiding symbolic references. (Anno Siegel)
    Re: Editor Question <ren@tivoli.com>
    Re: email this page script (Abigail)
    Re: File::Find not recursing on Win32 Perl 5.001 (Phil Hibbs)
        First Program, Need Help <rom616@bellsouth.net>
    Re: First Program, Need Help <godzilla@stomp.stomp.tokyo>
    Re: form post to https server, best method <dw123@knology.net>
    Re: fwd: Sex or perl? <l@maine.rr.com>
    Re: global and local variables <johndporter@yahoo.com>
        Help!  Trying to configure SendMail.pm is driving me cr <dmartin119@home.com>
    Re: It's to AM for me to think (Abigail)
    Re: It's to AM for me to think (Abigail)
    Re: It's to AM for me to think (Anno Siegel)
    Re: localtime() - returns the wrong year! <cberry@cinenet.net>
    Re: Object oriented question <ilya@martynov.org>
    Re: Object oriented question <jwl@sgi.com>
    Re: Object oriented question <joe+usenet@sunstarsys.com>
        path logfile <j.lan@chello.nl>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: 27 Aug 2001 14:13:38 GMT
From: trammell@haqq.hypersloth.invalid (John J. Trammell)
Subject: Re: adding rows in a text file
Message-Id: <slrn9ol4i6.hro.trammell@haqq.hypersloth.net>

On 27 Aug 2001 05:36:52 -0700, soumitra bhattacharya wrote:
> i.e.
> 1||....
> 2||..
> 3||..
> 4||...
> 5-10||sum of mails read for 5 to 10||sum of mails deleted for5-10||.....
> 11-20||...
> 21-30||....
> 31-40||...
> 41-50||....
> 50-whatever is max
> so in first row will be data for people logged in once,
> but in row 5-10 will be sum of data in rows 5,6,7,8,9,10 if they exist.
> similarly for the row named 11-20 will be sum of data in rows 11..20 if they exist.
> How do I do this.

One way is to use a hash to accumulate the sums:

my %sum;

while (<>)
{
	my ($index,$data) = split(/\|\|/,$_); # or whatever
	my $key;
	for ($index)
	{
		$_ < 5  && do { $key = $_; last; };
		$_ < 11 && do { $key = "5-10"; last; };
		$_ < 21 && do { $key = "11-20"; last; };
		$_ < 31 && do { $key = "21-30"; last; }; 
		$_ < 41 && do { $key = "31-40"; last; }; 
		$_ < 51 && do { $key = "41-50"; last; }; 
		$key = "50+";
	}
	$sum{$key} += $data;
}

while (my($k,$v) = each %sum) { print "$k => $v\n" }

I'm sure there are other solutions, but this one isn't terrible.  :-)

-- 
[W]hen the manager knows his boss will accept status reports without
panic or preeemption, he comes to give honest appraisals.
                               - F. Brooks, _The Mythical Man-Month_


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

Date: Mon, 27 Aug 2001 08:20:07 -0500
From: Mr Sunblade <djberge@uswest.com>
Subject: anonymous code refs and 'sort'
Message-Id: <3B8A4907.9B5524E2@uswest.com>

Hi all,

I'm revisiting a previous post but with a different focus.  I was having
trouble
sending anonymous sub refs to the sort method.   I couldn't remember the

code I was using (cable modem is still down), so I wrote it down and
brought it in with me this time.  Doing this within the same package
worked
with no trouble, but...

Ok, I think I found the source of my troubles.  Here's what I was trying
to do:

#!/usr/local/bin/perl -w

mypackage::sortArray(sub { $a <=> $b });

package mypackage;

sub sortArray{
   $coderef = shift;
   my @array = qw(3 4 10 1 2 3);
   my @sorted = sort $coderef @array;
   print "Sorted: ", join(',',@sorted),"\n";
}

This fails, presumably because of the way that the special variables $a
and $b
work (read Camel, p.658).  That being said, is there a way to make this
work?

Just for kicks, I tried initializing $a and $b.  Got rid of the
warnings, but it didn't
work (and no, I didn't actually expect it to work).

Regards,

Mr. Sunblade

--
"Evil will always triumph because Good is *dumb*."
-- Dark Helmet, 'Spaceballs: The Movie'





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

Date: Mon, 27 Aug 2001 14:56:16 -0100
From: Rainer Klier <Rainer.Klier@erl.sbs.de>
Subject: Re: anonymous code refs and 'sort'
Message-Id: <3B8A6DA0.6B6B965E@erl.sbs.de>

Mr Sunblade wrote:
> Ok, I think I found the source of my troubles.  Here's what I was trying
> to do:
> 
> #!/usr/local/bin/perl -w
> 
> mypackage::sortArray(sub { $a <=> $b });
> 
> package mypackage;
> 
> sub sortArray{
>    $coderef = shift;
>    my @array = qw(3 4 10 1 2 3);
>    my @sorted = sort $coderef @array;
>    print "Sorted: ", join(',',@sorted),"\n";
> }
> 
> This fails, presumably because of the way that the special variables $a
> and $b
> work (read Camel, p.658).  That being said, is there a way to make this
> work?

mypackage::sortArray(\sub { $mypackage::a <=> $mypackage::b });

package mypackage;
sub sortArray{
    my $coderef = shift;
    my @array = qw(3 4 10 1 2 3);
    my @sorted = sort { &$$coderef } @array;
    print "Sorted: ", join(',',@sorted),"\n";
}

This should do it.

Regards,
Rainer


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

Date: Mon, 27 Aug 2001 14:58:24 -0100
From: Rainer Klier <Rainer.Klier@erl.sbs.de>
Subject: Re: anonymous code refs and 'sort'
Message-Id: <3B8A6E20.94E4A4DA@erl.sbs.de>

Rainer Klier wrote:
> 
> Mr Sunblade wrote:
> > Ok, I think I found the source of my troubles.  Here's what I was trying
> > to do:
> >
> > #!/usr/local/bin/perl -w
> >
> > mypackage::sortArray(sub { $a <=> $b });
> >
> > package mypackage;
> >
> > sub sortArray{
> >    $coderef = shift;
> >    my @array = qw(3 4 10 1 2 3);
> >    my @sorted = sort $coderef @array;
> >    print "Sorted: ", join(',',@sorted),"\n";
> > }
> >
> > This fails, presumably because of the way that the special variables $a
> > and $b
> > work (read Camel, p.658).  That being said, is there a way to make this
> > work?
> 
> mypackage::sortArray(\sub { $mypackage::a <=> $mypackage::b });
> 
> package mypackage;
> sub sortArray{
>     my $coderef = shift;
>     my @array = qw(3 4 10 1 2 3);
>     my @sorted = sort { &$$coderef } @array;
>     print "Sorted: ", join(',',@sorted),"\n";
> }

One level of refs too much :)
You can call it also without \ at the sub and without the
second $ in &$$coderef.

Rainer


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

Date: Mon, 27 Aug 2001 09:41:12 -0500
From: Mr Sunblade <djberge@uswest.com>
Subject: Re: anonymous code refs and 'sort'
Message-Id: <3B8A5C08.726E8DAA@uswest.com>

Rainer Klier wrote:

> mypackage::sortArray(\sub { $mypackage::a <=> $mypackage::b });
>
> package mypackage;
> sub sortArray{
>     my $coderef = shift;
>     my @array = qw(3 4 10 1 2 3);
>     my @sorted = sort { &$$coderef } @array;
>     print "Sorted: ", join(',',@sorted),"\n";
> }
>
> This should do it.
>
> Regards,
> Rainer

2 things...

1) Thanks!

2) Ick!

Regards,

Mr. Sunblade

--
"Evil will always triumph because Good is *dumb*."
-- Dark Helmet, 'Spaceballs: The Movie'





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

Date: Mon, 27 Aug 2001 10:28:50 -0500
From: Mr Sunblade <djberge@uswest.com>
Subject: Re: anonymous code refs and 'sort'
Message-Id: <3B8A6732.BBD6D178@uswest.com>

Rainer Klier wrote:

> >
> > mypackage::sortArray(\sub { $mypackage::a <=> $mypackage::b });
> >
> > package mypackage;
> > sub sortArray{
> >     my $coderef = shift;
> >     my @array = qw(3 4 10 1 2 3);
> >     my @sorted = sort { &$$coderef } @array;
> >     print "Sorted: ", join(',',@sorted),"\n";
> > }
>
> One level of refs too much :)
> You can call it also without \ at the sub and without the
> second $ in &$$coderef.
>
> Rainer

Actually, no dereferencing is required.  This worked for me:

#!/usr/local/bin/perl -w

my $a = 0;
my $b = 1;
mypackage::sortArray(sub { $mypackage::a <=> $mypackage::b });

package mypackage;

sub sortArray{
   $coderef = shift;
   my @array = qw(3 4 10 1 2 3);
   my @sorted = sort $coderef @array;
   print "Sorted: ", join(',',@sorted),"\n";
}

Thanks again.

Regards,

Mr. Sunblade

--
"Evil will always triumph because Good is *dumb*."
-- Dark Helmet, 'Spaceballs: The Movie'





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

Date: Mon, 27 Aug 2001 11:28:01 -0500
From: Mr Sunblade <djberge@uswest.com>
Subject: Re: anonymous code refs and 'sort'
Message-Id: <3B8A7511.7C426FF7@uswest.com>

> Actually, no dereferencing is required.  This worked for me:
>
> #!/usr/local/bin/perl -w
>
> my $a = 0;
> my $b = 1;
> mypackage::sortArray(sub { $mypackage::a <=> $mypackage::b });
>
> package mypackage;
>
> sub sortArray{
>    $coderef = shift;
>    my @array = qw(3 4 10 1 2 3);
>    my @sorted = sort $coderef @array;
>    print "Sorted: ", join(',',@sorted),"\n";
> }
>
>

Oops - get rid of the $a and $b assignments. :)

Regards,

Mr. Sunblade


--
"Evil will always triumph because Good is *dumb*."
-- Dark Helmet, 'Spaceballs: The Movie'





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

Date: 27 Aug 2001 13:47:41 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Avoiding symbolic references.
Message-Id: <9mdj1t$qgl$1@mamenchi.zrz.TU-Berlin.DE>

According to Benjamin Goldberg  <goldbb2@earthlink.net>:

[calculating Euler's number]

> I suppose it doesn't matter much, anyway.  Having seen the amount of
> time it takes to calculate successive significant bits of euler's
> number, I've given up on calculating it to the log2(256!) significant
> bits I need to do what I want.

It can't be that bad.  Using e = 1 + 1/1! + ... + 1/n!, the error is
less than twice the first neglected term, so we want n = 256.  My measly
Pentium 90 does that in about 15 seconds.

>                                It's far easier and faster to download
> it off of a website.

That may still be true, if you count writing the program.

Anno


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

Date: 27 Aug 2001 11:41:22 -0500
From: Ren Maddox <ren@tivoli.com>
Subject: Re: Editor Question
Message-Id: <m34rqtv4jx.fsf@dhcp9-161.support.tivoli.com>

On 26 Aug 2001, gorilla@elaine.furryape.com wrote:

> In article <998686028.740761307999492.gnarinn@hotmail.com>,
> gnari  <gnarinn@hotmail.com> wrote:
>>
>>>        # print RESULTS "Accuracy:
>>>${$RxTxData{$key}{statistics}{$key2}}[1]\n";
>>                                           ^ a string starts here
>>                                           ------------------^
> 
> No it doesn't. You missed the " on the previous line.

Actually, the previous line is a comment.

But I expect the noted line is really a part of that comment and was
just wrapped on posting.  In which case this still isn't the problem.

-- 
Ren Maddox
ren@tivoli.com


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

Date: 27 Aug 2001 17:55:19 GMT
From: abigail@foad.org (Abigail)
Subject: Re: email this page script
Message-Id: <slrn9ol2cc.plv.abigail@alexandra.xs4all.nl>

Class Spokesman (galligat@tcd.ie) wrote on MMCMXIV September MCMXCIII in
<URL:news:3B850966.7D1FC124@tcd.ie>:
^^     Hay
^^ I'm looking for a freeware perl script that can email a page
^^ Does anyone where i can find one thanks


I'd suggest you go bugger the people in comp.lang.python for such
a script in Python, then use the following Perl program:

    #!/opt/perl/bin/perl -W
    use strict;
    system "email.py" && die $?;
    __END__


Assuming the program is in the 'email.py'.


HTH. HAND.



Abigail
-- 
print 74.117.115.116.32.97.110.111.116.104.101.114.
      32.80.101.114.108.32.72.97.99.107.101.114.10;


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

Date: 27 Aug 2001 08:53:44 -0700
From: phil.hibbs@capgemini.co.uk (Phil Hibbs)
Subject: Re: File::Find not recursing on Win32 Perl 5.001
Message-Id: <153e25f0.0108270753.5b2b1d7e@posting.google.com>

>Are you giving it directories on the command line (@ARGV)?

I've tried it with a directory, and without.

> Do they have any actual subdirectories 
>(as opposed to symlinks to directories,
>which will NOT be recursed)?

This is windows. We don't have symbolic links 'round here.

>What does invoking this with @ARGV set
>to qw(/) do?

It does this:
//
/06.01.zip
/Database.zip
/dev/
/EARS Macros/
/Firewall/
/Outlook/
/Perl Bookshelf/
/PVCS Version Manager Manuals/
/RECYCLER/
/temp/

which is exactly the same as with @ARGV set to qw(.), even though the
current directory is "/dev".

regards,

Philip Hibbs


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

Date: Mon, 27 Aug 2001 11:57:31 -0400
From: "JII" <rom616@bellsouth.net>
Subject: First Program, Need Help
Message-Id: <C%ti7.24549$zk4.1326418@e3500-atl1.usenetserver.com>

Dear Fellow PERL programmers,

    I am trying to learn Perl (I have 5.6) on a windows machine.  Main
problems was that I didn't have anything I could write that I could use.  I
finally found something to do: write a prgram to help solve the Word Jumble
in the daily paper.  I'm having some problems with it, and it's not finished
yet, but I can't get any farther until I figure this out.  My program is at
the bottom of the page

    My problems are these:

    1: In the first "for" loop, I try to assign the letters to variables
(i.e. $a0, $a1...).  It doesn't work.  I read through the manuals and books
I have trying to find out how to do that, but I haven't been able to figure
it out. (Lines 7-11)

    2: I can't figure out a way to get PERL to create combinations of
letters and print them, so that they will never be the same.  I have spent
at least a couple of hours trying to think of a way.(Lines 30-34).

   Maybe there is a module out there that can help me.  Maybe I missed some
functions that would do it for me.  Like I said, I'm new.  And I appreciate
any help you can give me with this attempt to program.  (I'll still be
looking through my books, trying to find a way).
Thanks again!

BEGIN PERL FILE
--------------------------------
print "\n" . 'Type text of Jumble combination and then hit the Enter key:' .
"\n";
$txtin=<STDIN>; #Get keyboard input for word
@txt=split(//,$txtin); # Put input into a list for easier usage
# in making the possible combinations
$number=length($txtin);
print "The word is $number letters long.\n\n"; # print number of letters in
word.
####LINE 7#### for($i=0; $i <= $number; $i+=1) # create variables for each
letter
 {  $a = '$a' . "$i"; # workaround for not allowing
      # scalars in the name of a variable
  $a = $txt[$i];
 }

@mh=[];
$b=1;
# possible number of combinations
for ($i=$number; $i > 0; $i =$i - 1) #create numbers for factorialization
 {
  splice(@mh, $#mh+1, 0, ("$i"));
  $b+=1;
 }
$poscomb = 1;
$b -= 1;
while ($b >= 1)  # while loop that does factorialization of $poscomb
 { $d = $mh[$b];
  $poscomb *= $d;
  $b = $b - 1;
 }
$e = $number -1;
print "There are $poscomb possible combinations of letters.";
####LINE 30#### for ($i=0; $i <= 10; $i +=1) # loop(s) to create
combinations of letters
# that will not repeat and print them on screen for the user to see and
compare with puzzle
 {
  ;
  ;
 }
END PERL FILE
--------------------------------





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

Date: Mon, 27 Aug 2001 10:08:12 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: First Program, Need Help
Message-Id: <3B8A7E7C.9FE7ADB4@stomp.stomp.tokyo>

JII wrote:

(snipped)

> I am trying to learn Perl (I have 5.6) on a windows machine.  Main
> problems was that I didn't have anything I could write that I could use.  I
> finally found something to do: write a prgram to help solve the Word Jumble
> in the daily paper.  

> 2: I can't figure out a way to get PERL to create combinations of
> letters and print them, so that they will never be the same.  I have spent
> at least a couple of hours trying to think of a way.(Lines 30-34).


Hey! It's a CLPM Troll rehash of a rehash of a rehash of the Knapsack problem!


Godzilla!
--

#!perl

print "Content-type: text/plain\n\n";

@Input = qw (G o d z i l l a !);

@Array = (1 .. $#Input + 1);

$permutate = 1;
$letters = 0;

while (@Array)
 {
  $permutate = $Array[0] * $permutate;
  $letters++;
  shift (@Array);
 }

print "Your magic word is ", @Input, "\n\n";

print "Number Of Letters: $letters\n  Number Of Permutations: $permutate\n";

print "\n\nBoss, would you like me to print all $permutate permutations?";

exit;


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

Date: Mon, 27 Aug 2001 12:15:21 -0500
From: "Dennis" <dw123@knology.net>
Subject: Re: form post to https server, best method
Message-Id: <_bvi7.28821$e8.6766319@e3500-chi1.usenetserver.com>


"Michael Budash" <mbudash@sonic.net> wrote in message
news:mbudash-6EBD86.21413726082001@news.sonic.net...
> In article <3B89899A.CF8C41A0@rochester.rr.com>, Bob Walton
> <bwalton@rochester.rr.com> wrote:
>
> > Nitin G wrote:
> > >
> > > am looking at implementing a solution where I need to post some data
to
> > > a
> > > https server. Before I went down a path that led to nowhere, I wanted
> > > to get
> > > input from people who might have implemented a similar solution.
What's
> > > the
> > > best recommended module to use for handling such a situation?
> > ...
> > > -Nitin
> >
> > I would start with the LWP module.  The following should be very
> > helpful:
> >
> >    perldoc lwpcook
> >
> > You might have to get the Crypt::SSLeay module.
>
> which itself requires openssl... the whole system is easy to install and
> works great...
>
> hth-
> --
> Michael Budash ~~~~~~~~~~ mbudash@sonic.net

Could you tell me where to get the easy to install modules for NT and
Solaris since all I can find is source to be compiled

Thanks





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

Date: Mon, 27 Aug 2001 16:27:21 GMT
From: "vanyel On RR" <l@maine.rr.com>
Subject: Re: fwd: Sex or perl?
Message-Id: <Jxui7.397893$T97.45603484@typhoon.nyroc.rr.com>


>
> But to answer the question, Sex is better. Eventually Perl will be
> outdated and obsolete. Sex ensures that their will be future programmers
> creating newer, better software...
>
Only if you do it right.





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

Date: Mon, 27 Aug 2001 14:30:20 GMT
From: John Porter <johndporter@yahoo.com>
Subject: Re: global and local variables
Message-Id: <3B8A58CB.3B4D093D@yahoo.com>

Jens Luedicke wrote:
> I have two modules that don't belong to a special package.
> Within those modules I use only variables that are declared
> in the main program with "our (...)". When I include "use strict"
> in those modules I get lots of errors like:

You need to "our()" the variables in every place they are used.

-- 
John Porter


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

Date: Mon, 27 Aug 2001 17:23:06 GMT
From: "JerryGarciuh" <dmartin119@home.com>
Subject: Help!  Trying to configure SendMail.pm is driving me crazy!!
Message-Id: <_lvi7.134432$oh1.52034544@news2.rdc2.tx.home.com>

My tests got error :

no host: , please specify SMTP server with "$obj = new
SendMail('your.smtp.server');"

So in SendMail.pm I edited

$smtpserver   = "mail.server.com";

to

$smtpserver   = "mail.mysite.com";

and got same error.  Since error said to edit

"$obj = new SendMail('your.smtp.server');"

I went down to

$obj = new SendMail();
  $obj = new SendMail($smtpserver);
  $obj = new SendMail($smtpserver, $smtpport);

and changed first line to

$obj = new SendMail(mail.mysite.com);

got same error

so I changed it back and tried replacing variable  $smtpserver with my info
which off course rendered script inoperable.

I REALLY don't get why setting $smtpserver   = "mail.mysite.com"; gave error
no host  when   $obj = new SendMail($smtpserver);
should have had the info it needed from var.

Please help me!
TIA
jg


--
http://www.nolaFlash.com

We, in all humidity, are the people
of currant times. This concept grinds
our critical, seething minds to a halt.
                         ~~Anders Henriksson
                            "Life Reeked With Joy"







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

Date: 27 Aug 2001 17:26:07 GMT
From: abigail@foad.org (Abigail)
Subject: Re: It's to AM for me to think
Message-Id: <slrn9ol0lk.plv.abigail@alexandra.xs4all.nl>

Tassilo von Parseval (Tassilo.Parseval@post.rwth-aachen.de) wrote on
MMCMXVII September MCMXCIII in <URL:news:3B897766.20506@post.rwth-aachen.de>:
}} Mark Jason Dominus wrote:
}} 
}} >>So, a pure Perl-loop of O(n) seems to be quicker than a C-optimized Perl-sort of
}} >>O(n log(n)).
}} >>
}} > 
}} > That's because you cheated by picking a very special test case.  The
}} > array elements are in order from largest to smallest.  This is the
}} > *optimal* case for the loop code, because it only performs one
}} > assignment, and is a common worst-case for sort functions.  In such a
}} > case, the following algorithm is the most efficient:
}} > 
}} >         my $largest = $array[0];
}} 
}} Ah, shit, sorry! Reversed order is indeed bad for the sort-algorithm and 
}} good for the loop....I overlooked it.
}} 
}} But I just did it again, this time with the ordered list for the loop 
}} and reverse order for the sort. This would mean worst case with maximum 
}} number of assignements. For a 1000 element list and with 1000 
}} iterations, the loop is still 52% quicker. Same for smaller lists of 100 
}} and 10 elements. So it does not result in a fundemantal change.

One of the problems of vanilla Quicksort is that both ordered and
reverse ordered inputs lead to worst case behaviour. Perl's specific
implementation however doesn't suffer from this ("middle-of-three"
picking of the pivot). That means by not reversing you didn't go from
"worst-case" to "best-case". Note that it's still easy to create inputs
for Perl's sort that cause it to use quadratic time: so called "organ
pipe" inputs will do:  (1 .. $N, 1 .. $N) for instance.

Note that you are totally wrong by taking the raw outputs of the Benchmark
and say "method1 is X% faster than method2", as your Benchmark creates the
array the algorithm works on. Since the array creation takes Theta(N), and
one of the algorithms takes Theta(N) as well, the time spend to create the
array is far from insignificant. 

}} Implicitely I said which version I at least use. I have 5.6.1 while I 
}} pointed out that since 5.6.0 Perl uses merge-sort. I wouldn't have said 
}} it had I used an older version. ;-)

But that isn't true. 5.6.x Perl uses a specially for Perl optimized
quicksort.  But it's still a quicksort. Merge-sort is in Perl 5.7.x.



Abigail
-- 
use   lib sub {($\) = split /\./ => pop; print $"};
eval "use Just" || eval "use another" || eval "use Perl" || eval "use Hacker";


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

Date: 27 Aug 2001 17:29:53 GMT
From: abigail@foad.org (Abigail)
Subject: Re: It's to AM for me to think
Message-Id: <slrn9ol0sm.plv.abigail@alexandra.xs4all.nl>

Anno Siegel (anno4000@lublin.zrz.tu-berlin.de) wrote on MMCMXVIII
September MCMXCIII in <URL:news:9mdbdo$5nf$1@mamenchi.zrz.TU-Berlin.DE>:
|| According to Logan Shaw <logan@cs.utexas.edu>:
|| 
|| > By the way, I just realized there is an optimization to my method
|| > that also makes the code clearer in addition to being faster:
|| > 
|| > 	@array = qw{ -111 6 5 7 89 3 76 };
|| > 
|| > 	$largest = $array[0];	# assume first element is largest
|| 
||         $largest = shift @array;
|| 
|| > 	foreach my $i (@array)
|| > 	{
|| > 	    $largest = $i if $i > $largest;
|| > 	}
|| > 
|| > 	print $largest, "\n";
|| 
|| A minuscule optimization, but it comes free.


No, it doesn't come free - or at least it isn't clear at all why it's
free.

It would be free if 'shift(@array)' takes as much time as '$array[0]',
but it would surprise me if it does; after all, the shift() has to
modify a pointer in the AV, while the array lookup doesn't.

It *might* be an optimization, but perhaps it isn't. Perhaps it's even
a minuscule slowdown.


Abigail
-- 
use   lib sub {($\) = split /\./ => pop; print $"};
eval "use Just" || eval "use another" || eval "use Perl" || eval "use Hacker";


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

Date: 27 Aug 2001 17:53:04 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: It's to AM for me to think
Message-Id: <9me1e0$c5n$1@mamenchi.zrz.TU-Berlin.DE>

According to Abigail <abigail@foad.org>:
> Anno Siegel (anno4000@lublin.zrz.tu-berlin.de) wrote on MMCMXVIII
> September MCMXCIII in <URL:news:9mdbdo$5nf$1@mamenchi.zrz.TU-Berlin.DE>:
> || According to Logan Shaw <logan@cs.utexas.edu>:
> || 
> || > By the way, I just realized there is an optimization to my method
> || > that also makes the code clearer in addition to being faster:
> || > 
> || > 	@array = qw{ -111 6 5 7 89 3 76 };
> || > 
> || > 	$largest = $array[0];	# assume first element is largest
> || 
> ||         $largest = shift @array;
> || 
> || > 	foreach my $i (@array)
> || > 	{
> || > 	    $largest = $i if $i > $largest;
> || > 	}
> || > 
> || > 	print $largest, "\n";
> || 
> || A minuscule optimization, but it comes free.
> 
> 
> No, it doesn't come free - or at least it isn't clear at all why it's
> free.
> 
> It would be free if 'shift(@array)' takes as much time as '$array[0]',
> but it would surprise me if it does; after all, the shift() has to
> modify a pointer in the AV, while the array lookup doesn't.
> 
> It *might* be an optimization, but perhaps it isn't. Perhaps it's even
> a minuscule slowdown.

That could only happen if the overhead of "shift @array" vs. "$array[ 0]"
is greater than one round through the loop.  I was betting that it isn't
(and still do), but you're right to point it out.

Anno



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

Date: Mon, 27 Aug 2001 17:55:47 -0000
From: Craig Berry <cberry@cinenet.net>
Subject: Re: localtime() - returns the wrong year!
Message-Id: <Xns910A6F2EFA92Ecberrycinenetnet1@207.126.101.92>

"Peter Mann" <Pcmann1@btinternet.com> wrote in
news:9m6idn$p3s$1@neptunium.btinternet.com: 
> I have a small problem I can't work out!

Like most such, your problem would have been infinitely easier to solve by 
recourse to the fine manual (in this case, 'perldoc -f localtime') than by 
asking thousands of perl users and waiting for their perhaps unhelpful 
responses.

> I need to retrieve the current date and display it in 'short date' format.
> This is my code I have to try and achieve this! The problem is that is
> displays '24/07/101'
> The day and month are correct, but 101 for the year isn't! Why wont is
> give me back the correct year?

Grasshopper, you impose your own view of 'correctness' on the world, and the 
world is not impressed.  101 is indeed the correct value for the current 
year, in the form returned by localtime() in list conext.  Read the manual 
and become enlightened.

> sub tasksBehind
> {
>   my (undef, undef, undef, $day, $month, $year) = localtime();

Easier:

  my ($day, $month, $year) = (localtime)[3, 4, 5];

>   print "$day/$month/$year";

I'll wager that, if you look carefully, the month value you see printed will 
be surprising to you, too.  Again, the manual is your friend.

-- 
Craig Berry <http://www.cinenet.net/~cberry/>
"That which is now known, was once only imagined." - William Blake



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

Date: 27 Aug 2001 17:20:05 +0400
From: Ilya Martynov <ilya@martynov.org>
Subject: Re: Object oriented question
Message-Id: <878zg5mygq.fsf@abra.ru>

>>>>> On Mon, 27 Aug 2001 09:00:14 -0400, Jim Lynch <jwl@sgi.com> said:

JL> Is there a way within the OO framework of Perl to initialize variables
JL> at the first instantance of an object other than making them global?

JL> Here's what I want to do.  I want to create objects that contain the
JL> data from a since row of a database fetch.  Since the prepare operation
JL> of the DBI module needs only be done once and is expensive (time wise),
JL> I'd like to do the prepare only once when the first row object is
JL> created.  Same goes for the database connect.  I know I could make the
JL> prepare global but that kind of defeats the spirit of object oriented
JL> programming.  I suppose I could put the onus on the programmer and
JL> require that he instantiate another class that contains the prepared
JL> statement(s) and open the database, but if possible I'd like to hide
JL> that complexity.   

JL> Any suggestions?

When you really need global var it is ok to have it. It is no against
object oriented programming. If you want clean object oriented
solution use singeltons. Singelton is a class which can have only one
instance.

Simplified example of class - singelton:

package Singelton;

my $instance = undef;

sub new {
    my $class = shift;

    $instance ||= $class->init(@_);

    return $instance;
}

sub init {
    my $class = shift;

    my $self = bless {}, $class;
    ...
    ...

    return $self;
}

Instance of class Singelton will be created only on first call of
Singelton->new(). Next calls will return same object.

It is quate transparent since you can replace singelton with usual
class without changing API at any time.

-- 
 -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
| Ilya Martynov (http://martynov.org/)                                    |
| GnuPG 1024D/323BDEE6 D7F7 561E 4C1D 8A15 8E80  E4AE BE1A 53EB 323B DEE6 |
| AGAVA Software Company (http://www.agava.com/)                          |
 -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-


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

Date: Mon, 27 Aug 2001 09:27:30 -0400
From: Jim Lynch <jwl@sgi.com>
Subject: Re: Object oriented question
Message-Id: <3B8A4AC1.B11A9CBE@sgi.com>



Ilya Martynov wrote:
> 
> >>>>> On Mon, 27 Aug 2001 09:00:14 -0400, Jim Lynch <jwl@sgi.com> said:
> 
(snip)
> When you really need global var it is ok to have it. It is no against
> object oriented programming. If you want clean object oriented
> solution use singeltons. Singelton is a class which can have only one
> instance.
> 
(snip)

Hi, Ilya,

Thank you very much.  That's just what I was looking for.

Jim.


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

Date: 27 Aug 2001 13:48:50 -0400
From: Joe Schaefer <joe+usenet@sunstarsys.com>
Subject: Re: Object oriented question
Message-Id: <m3d75hs8al.fsf@mumonkan.sunstarsys.com>

Jim Lynch <jwl@sgi.com> writes:

> Since the prepare operation of the DBI module needs only be done once
> and is expensive (time wise), I'd like to do the prepare only once
> when the first row object is created.  

See the DBI's documentation for the prepare_cached() method.

> Same goes for the database connect.

Ditto- try connect_cached().  See 
  
  % perldoc DBI

for details.

-- 
Joe Schaefer    "Few things are harder to put up with than the annoyance of a
                                        good example."
                                               --Mark Twain



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

Date: Mon, 27 Aug 2001 17:05:31 GMT
From: "Jian Lan" <j.lan@chello.nl>
Subject: path logfile
Message-Id: <v5vi7.358323$ef.9739699@Flipper>


hi;

I have downloaded a email log script.
By default sta the log file log.txt and the perl script maillog.pl in the
same directory. I works fine. But I try to put log.txt in another directory.
I have tried the following options. But I still got 'Can not open file'
error.
The log file path is not right. But I can not figure out.
In the FTP:

maillog.pl is in the /cgi-bin/maillog/
log.txt is in the /htdocs/mylog/

Default setting:
$log="log.txt"

My options:

$log = "http://www.mycom.com/mylog/log.txt";
$log = "/mylog/log.txt";
$log = "/htdocs/mylog/log.txt";

HOW TO ENTER THE FULL PATH TO WHERE LOG FILE IS KEPT ???

thanks





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

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


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