[24978] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 7228 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Oct 9 14:06:49 2004

Date: Sat, 9 Oct 2004 11:05:07 -0700 (PDT)
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, 9 Oct 2004     Volume: 10 Number: 7228

Today's topics:
    Re: [newbie] Problems with character output. <flavell@ph.gla.ac.uk>
    Re: any tools to enable test automation for scripting l <sdn.girths00869@zoemail.net>
        correct way to check for empty hash (justme)
    Re: correct way to check for empty hash <see@sig.invalid>
    Re: Getting all directories/files from current director <bik.mido@tiscalinet.it>
    Re: getting telnet banner <lv@aol.com>
    Re: How to capture output of CVS via Perl? <mritty@gmail.com>
    Re: How to capture output of CVS via Perl? <tadmc@augustmail.com>
    Re: Is PHP still slower than Perl? (Randal L. Schwartz)
    Re: Is PHP still slower than Perl? <sdn.girths00869@zoemail.net>
    Re: Loop through scalar? <abigail@abigail.nl>
        Parrot 0.1.1 "Poicephalus" Released <slrn@toetsch.at>
    Re: Perl6 <sdn.girths00869@zoemail.net>
    Re: subtracting strings <bik.mido@tiscalinet.it>
    Re: To Tad: Great perl class, and question (Randal L. Schwartz)
    Re: To Tad: Great perl class, and question (Peter Scott)
    Re: To Tad: Great perl class, and question <uri@stemsystems.com>
    Re: To Tad: Great perl class, and question <someone@example.com>
    Re: Top 10 list algorithm <abigail@abigail.nl>
    Re: Using a string as a variable name. <sdn.girths00869@zoemail.net>
    Re: Who's responsible for this ? <sdn.girths00869@zoemail.net>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Sat, 9 Oct 2004 13:10:28 +0100
From: "Alan J. Flavell" <flavell@ph.gla.ac.uk>
Subject: Re: [newbie] Problems with character output.
Message-Id: <Pine.LNX.4.61.0410091250330.689@ppepc56.ph.gla.ac.uk>

On Sat, 9 Oct 2004, Reven wrote:

> I've installed ActivePerl on win XP and I'm having some problems. 
> I've tried documentation at activestate but found nothing on this 
> topic.

Your problem is in using a command window (which by default is 
effectively providing an MS-DOS environment).

[...]
> $u = "á"; # The value of this string is an "a" acute
[...]
> gives no result. Instead of an "a tilde"

I think you mean "a-acute" (in iso-8859-1 or windows-1252 coding, that 
would be 0xE1)

> I get a Greek Beta.

Here's a clue.  Visit 
http://www.unicode.org/Public/MAPPINGS/VENDORS/MICSFT/PC/
and inspect the CP437 (USA national DOS codepage) or CP850 
(multinational DOS codepage) tables, where you will find that 0xE1
represents "small letter sharp-s" (the German double-s character),
which has fooled you by looking rather like a Greek beta.

> I've also tried "iso-8859-1" and "windows-1252", but to the same 
> effect. I'm quite lost. This is just a wild guess: could there be 
> any problem with the console itself?

In a sense, yes.  This is a longstanding misunderstanding, which 
Microsoft have not put much effort into documenting for the end user: 
right from the start of MS Windows, the DOS command window has 
implemented the MS-DOS character "code pages", which pre-date current 
8-bit character coding conventions (such as iso-8859-x and 
windows-125y for various x and y).

> Could I be *so* lucky to find a bug?

At best it could be described as "documented as broken", but the 
documentation is very hard to find if you don't know what you're 
looking for.  I haven't studied this issue specifically in XP, but I 
first met it in Win95, and again later (and somewhat differently) in 
Win/NT4.

You may be able to fool it by changing your DOS window font from its 
initial setting (does yours say "Raster Fonts", as my Win2000 system 
is doing?) to e.g "Lucida Console".  However, doing that globally 
might have some unpleasant effects on any software which was actually 
designed to run under DOS (for example, DOS box-drawing characters 
will come out funky).

There may be some useful terms in this posting that you can use to 
Google for other answers related to this issue.  Good luck.


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

Date: Sat, 09 Oct 2004 11:44:25 -0500
From: "Eric J. Roode" <sdn.girths00869@zoemail.net>
Subject: Re: any tools to enable test automation for scripting language like perl?
Message-Id: <Xns957D819CEC652sdn.comcast@216.196.97.136>

ty_li@yahoo.com (matt) wrote in 
news:10ca4b4a.0410080445.5a72a00c@posting.google.com:

> hi all:
> I am working on a script language very similiar to Perl.

I'm curious: do you mean that you are developing a script language similar 
to Perl, or that you are coding in an existing language that is similar to 
Perl?

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


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

Date: 9 Oct 2004 06:12:41 -0700
From: eight02645999@yahoo.com (justme)
Subject: correct way to check for empty hash
Message-Id: <c0837966.0410090512.21c15ca1@posting.google.com>

hi

in the perldoc, the way to check for a hash with members is 

if ( %hash )
{
 print "has elements";
}

but what is the correct way to check for empty hash?

Which is the correct way 
1) if (!%hash ) or
2) if (%hash < 1) 


or other methods??
thanks...


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

Date: Sat, 09 Oct 2004 10:04:35 -0400
From: Bob Walton <see@sig.invalid>
Subject: Re: correct way to check for empty hash
Message-Id: <4167edf4$1_2@127.0.0.1>

justme wrote:
 ...
> in the perldoc, the way to check for a hash with members is 
> 
> if ( %hash )
> {
>  print "has elements";
> }
> 
> but what is the correct way to check for empty hash?
> 
> Which is the correct way 
> 1) if (!%hash ) or
> 2) if (%hash < 1) 
> 
> 
> or other methods??
 ...

How about:

    unless(%hash){
       #code for empty hash
    }

-- 
Bob Walton
Email: http://bwalton.com/cgi-bin/emailbob.pl


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

Date: Sat, 09 Oct 2004 12:49:11 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: Getting all directories/files from current directory and using -d flag for the directories
Message-Id: <ldbfm0hq5grkf9bkl9dgskdo3cm9on0fmt@4ax.com>

On 8 Oct 2004 13:05:10 -0700, adam.petrie@walgreens.com (Adam Petrie)
wrote:

>opendir(DIR,$home_dir) or die "Can't open the current directory:
[snip]
>   if (-d $name){            # is this a directory?


How strange! This very same question was asked here a few days ago,
see:

<41648726$0$1274$5a62ac22@per-qv1-newsreader-01.iinet.net.au>

and followups.


Michele
-- 
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
 .'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,


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

Date: Sat, 09 Oct 2004 11:42:52 -0500
From: l v <lv@aol.com>
Subject: Re: getting telnet banner
Message-Id: <41681305$1_4@127.0.0.1>

Zebee Johnstone wrote:
> In comp.lang.perl.misc on Fri, 08 Oct 2004 22:43:28 -0500
> l v <lv@aol.com> wrote:
> 
>>Try using Net::Telnet's getlines ......  untested snippet follows ...
>>
>>$t = new Net::Telnet (Timeout => $secs,
>>                       Prompt => "/$serverName:.+/");
>>$mode = $t->errmode('return');
>>
>>$t->open("$serverName.xxx.com");
>>@lines = $t->getlines;
>>$t->close;
>>
> 
> 
> As I said, Net::Telnet doesn't appear to return things till you log on.
> 
> This snippet times out and produces nothing.
> 
> Zebee

Well, well, well, a bit snippy aren't we.  I'm not sure then why I 
wasted more time on *your* problem.  But I did....

Net::Telnet is capable of doing what you are asking for, however, you 
need to read and more importantly, understand the documentation and 
think about how native telnet works and how to mimic that behavior in 
your program.

Here is another snippet which worked on both AIX 4.3.3 and Redhat 7.3. 
Change the waitfor to whatever text your server prompts for the login 
user id.  $prematch should contain the banner text you are looking for.

$t = new Net::Telnet (Timeout => $secs,
                        Prompt => "/$serverName:.+/"
					   );
$mode = $t->errmode('return');

$t->open("$serverName.mtco.com");
($prematch, $match) = $t->waitfor("\/login:.+\/");
$t->close;


Len


----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= East/West-Coast Server Farms - Total Privacy via Encryption =---


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

Date: Sat, 09 Oct 2004 06:29:51 -0400
From: Paul Lalli <mritty@gmail.com>
Subject: Re: How to capture output of CVS via Perl?
Message-Id: <ck8eje$mln$1@misc-cct.server.rpi.edu>

Chris Weiss wrote:

> Paul Lalli <mritty@gmail.com> wrote in message news:<ck79n2$j7l$1@misc-cct.server.rpi.edu>...
> 
>>Chris Weiss wrote:
>>
>>>system($cvs." ".$cvsroot." ".$cvs_update_args);
>>
>>You're not even bothering to determine if this command ran successfully.
> 
> That's the intent of capturing the output. To parse for errors (of all
> kinds) and send the log via email (that part I have working with other
> portions of the script).

Capturing output is not a particular good means of determining *if* 
there was an error - only to determine what the error was.  All programs 
return an exit code that tells you whether or not the program succeeded 
or failed.  Read the documentation for the function you're using:

perldoc -f system


>>>Any thoughts on what's going on? 
>>
>>Yes.  You have a misperception about the cvs command.
> 
> Feel free to enlighten - I should have started with "I'm new to
> this...", but it seems pretty obvious.

Did you try the program I told you to below?  That should tell you your 
misperception.

>>>Any help would be greatly appreciated!
>>
>>Forget perl for a moment.  Try this command in your shell:
>>
>>cvs update > output.txt 2> err.txt

Paul Lalli


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

Date: Sat, 9 Oct 2004 08:53:13 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: How to capture output of CVS via Perl?
Message-Id: <slrncmfra9.8fi.tadmc@magna.augustmail.com>

Chris Weiss <cweiss@stickyc.com> wrote:
> Paul Lalli <mritty@gmail.com> wrote in message news:<ck79n2$j7l$1@misc-cct.server.rpi.edu>...
>> Chris Weiss wrote:

>> > open(STDOUT, ">".$logfile);
>> 
>> Always check the return value of open.
> 
> Will do - this was a first stab.


Checking the return value from open() is best employed as a first stab. :-)


>> > system($cvs." ".$cvsroot." ".$cvs_update_args);
>> 
>> You're not even bothering to determine if this command ran successfully.
> 
> That's the intent of capturing the output. 


You seem to be confusing errors with output.

The return value from system() indicates errors (if it is a "polite" program).

The output from system() is NOT captured at all, you need a different
operator to capture the output.


> To parse for errors (of all
> kinds) and send the log via email (that part I have working with other
> portions of the script).


Then you want to be capturing STDERR, as that is where the error
messages should be going.

   perldoc -q STDERR

       How can I capture STDERR from an external command?


>> You have a misperception about the cvs command.
> 
> Feel free to enlighten - I should have started with "I'm new to
> this...", but it seems pretty obvious.


We might assume you are new to Perl, but we would not assume that
you are new to programming itself...


>> Forget perl for a moment.  Try this command in your shell:
>> 
>> cvs update > output.txt 2> err.txt
>> 
>> The results of that should point you in the right direction.


The enlightenment offered here is:

   program's normal output goes to STDOUT

   program's error output goes to STDERR


Which one you want to capture depends on which one you want to capture. :-)


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


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

Date: 09 Oct 2004 02:51:56 -0700
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: Is PHP still slower than Perl?
Message-Id: <1097318003.tKNnAuVGG8UTlvI/2XMNIA@teranews>

>>>>> "Chris" == Chris Hope <blackhole@electrictoolbox.com> writes:

Chris> CPAN is a huge repository of prebuilt and reusable packages. I
Chris> think I saw someone mention that there's currently about 7000
Chris> packages available.

Just a moment ago, it looks like 28000 modules in 8000 packages.

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


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

Date: Sat, 09 Oct 2004 11:14:35 -0500
From: "Eric J. Roode" <sdn.girths00869@zoemail.net>
Subject: Re: Is PHP still slower than Perl?
Message-Id: <Xns957D7CB37F90Csdn.comcast@216.196.97.136>

Joe Smith <Joe.Smith@inwap.com> wrote in news:2uw7d.96052$wV.30196
@attbi_s54:

> @ wrote:
> 
>> C. I don't know why it is not popular.
> 
> I'd say it is because C does not have strings as a native data type.
> Other than initializing an array of char, the C compiler has no
> string manipulation built in; it requires library functions to do that.
>      -Joe

I'm surprised that there aren't any open-source CGI libraries out there for 
doing things like parsing CGI variables, getting/setting cookies, etc.

Every now and then, I think of writing one, but I hardly use C any more....

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


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

Date: 09 Oct 2004 10:18:59 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: Loop through scalar?
Message-Id: <slrncmfeoi.34g.abigail@alexandra.abigail.nl>

Eric J. Roode (sdn.girths00869@zoemail.net) wrote on MMMMLVI September
MCMXCIII in <URL:news:Xns957BE31C83106sdn.comcast@216.196.97.136>:
??  Abigail <abigail@abigail.nl> wrote in 
??  news:slrncljpj4.hv.abigail@alexandra.abigail.nl:
??  
?? > Unlike others in this thread, I wouldn't use split, but m//g:
?? > 
?? >     while ($var =~ /(.*\n)/g) {
??  
??  Out of curiosity, why?


Because $var is potentially large. A list containing all the lines
will need space more than twice the memory $var takes.


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


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

Date: Sat, 9 Oct 2004 13:43:05 GMT
From: Leopold Toetsch <slrn@toetsch.at>
Subject: Parrot 0.1.1 "Poicephalus" Released
Message-Id: <I5Bos1.1tpo@zorch.sf-bay.org>

On behalf of the Parrot team I'm proud to announce the Parrot 0.1.1
release.

Parrot 0.1.1 is an intermediate release with tons of updates and fixes.

 - Python support: Parrot runs 4/7 of the pie-thon test suite
 - Better OS support: more platforms, compilers, OS functions
 - Improved PIR syntax for method calls and <op>= assignment
 - Dynamic loading reworked including a "make install" target
 - MMD - multi method dispatch for binary vtable methods
 - Library improvement and cleanup
 - BigInt, Complex, *Array, Slice, Enumerate, None PMC classes
 - IA64 and hppa JIT supprt
 - Tons of fixes, improvements, new tests, and documentation updates.

A lot is unfinished and keeps changing. Nethertheless Parrot is stable
and usable at the surface, while internals are moving.

After some pause you can grab it from
<http://www.cpan.org/authors/id/L/LT/LTOETSCH/parrot-0.1.1.tar.gz> or
just get the latest and best from CVS by following the directions at
<http://dev.perl.org/cvs/>.

Turn your web browser towards <http://www.parrotcode.org/> for more
information about Parrot, get involved, and:

Have fun!
leo
-- 




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

Date: Sat, 09 Oct 2004 11:23:14 -0500
From: "Eric J. Roode" <sdn.girths00869@zoemail.net>
Subject: Re: Perl6
Message-Id: <Xns957D7E2C89F49sdn.comcast@216.196.97.136>

Gregory Toomey <nospam@bigpond.com> wrote in
news:2sf4kjF1jovcvU1@uni-berlin.de: 

> Its due for release when George Bush finds a weapon of mass
> destruction in Iraq! See http://dev.perl.org/perl6/exegesis/
> 
> Over 100 operators, every paradigm known to computer science, Perl 6
> has it all ...

<rotfl>  :-)

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


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

Date: Sat, 09 Oct 2004 12:49:12 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: subtracting strings
Message-Id: <gegfm015pgb0el1kshrnp888a12bm2cc4n@4ax.com>

On Sat, 09 Oct 2004 02:58:30 +0200, Gunnar Hjalmarsson
<noreply@gunnar.cc> wrote:

>     (my $newstring = $string) =~ s/$stringtosub//;

If doing it this way, then

      (my $newstring = $string) =~ s/\Q$stringtosub//;

would definitely be better...


Michele
-- 
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
 .'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,


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

Date: 09 Oct 2004 02:49:14 -0700
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: To Tad: Great perl class, and question
Message-Id: <1097318002.O5epQnDCqwvEaT5+vVNIEA@teranews>

>>>>> "Tad" == Tad McClellan <tadmc@augustmail.com> writes:

Tad> It was my 1st time in Kentucky, I found I liked it a lot.

Not sure whether that means that you liked it because it was Kentucky,
or you liked it because it was your first time.

:-)

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


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

Date: Sat, 09 Oct 2004 13:32:03 GMT
From: peter@PSDT.com (Peter Scott)
Subject: Re: To Tad: Great perl class, and question
Message-Id: <nLR9d.668019$M95.667821@pd7tw1no>

In article <ceudnfHqqcydYPvcRVn-rg@adelphia.com>,
 "Robert" <catcher@linuxmail.org> writes:
>"asdfasd" <af4bh@iglou.com> wrote in message 
>news:41661b40$1_1@news.iglou.com...
>> Just a quick question:  We have some old perl scripts that don't really
>> conform to the new coding standard, mainly with the problem of variable
>> scoping. 
[snip]
>>
>I just want to recommend the book "Perl Medic" as an outstanding resource in 
>this area.

Modesty forbids me from tooting my own horn.  Therefore I shall instead
applaud this posting for its sagacity, judgement, relevance, and
the obvious intelligence of its author.

:-)

-- 
Peter Scott
http://www.perldebugged.com/
*** NEW *** http://www.perlmedic.com/


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

Date: Sat, 09 Oct 2004 14:56:09 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: To Tad: Great perl class, and question
Message-Id: <x7zn2wosau.fsf@mail.sysarch.com>

>>>>> "PS" == Peter Scott <peter@PSDT.com> writes:

  PS> In article <ceudnfHqqcydYPvcRVn-rg@adelphia.com>,
  PS>  "Robert" <catcher@linuxmail.org> writes:
  >> "asdfasd" <af4bh@iglou.com> wrote in message 
  >> news:41661b40$1_1@news.iglou.com...
  >>> Just a quick question:  We have some old perl scripts that don't really
  >>> conform to the new coding standard, mainly with the problem of variable
  >>> scoping. 
  PS> [snip]
  >>> 
  >> I just want to recommend the book "Perl Medic" as an outstanding resource in 
  >> this area.

  PS> Modesty forbids me from tooting my own horn.  Therefore I shall instead
  PS> applaud this posting for its sagacity, judgement, relevance, and
  PS> the obvious intelligence of its author.

  PS> :-)

and i will also toot peter's horn. the book is well worth whatever you
pay for it. buy it so peter can pay for his mortgage. :)

<and check out the acknowledgement page (online) to see why i plug it :)>

uri

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


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

Date: Sat, 09 Oct 2004 15:03:07 GMT
From: "John W. Krahn" <someone@example.com>
Subject: Re: To Tad: Great perl class, and question
Message-Id: <L4T9d.2463$663.1016@edtnps84>

Tad McClellan wrote:
> asdfasd <af4bh@iglou.com> wrote:
> 
>>Thanks Tad.  I enjoy your training class a lot during your visit here in
>>Lexington, Kentucky.
> 
> Cool! 
> 
> It was my 1st time in Kentucky, I found I liked it a lot.

Did you bring us back some J.D.   :-)


John
-- 
use Perl;
program
fulfillment


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

Date: 09 Oct 2004 10:21:34 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: Top 10 list algorithm
Message-Id: <slrncmfetd.34g.abigail@alexandra.abigail.nl>

Anno Siegel (anno4000@lublin.zrz.tu-berlin.de) wrote on MMMMLVI September
MCMXCIII in <URL:news:ck6r6r$f55$1@mamenchi.zrz.TU-Berlin.DE>:
\\  Abigail  <abigail@abigail.nl> wrote in comp.lang.perl.misc:
\\ > Fatted (fatted@gmail.com) wrote on MMMMLV September MCMXCIII in
\\ > <URL:news:2skn1fF1msrubU1@uni-berlin.de>:
\\ > !!  Is there a better (faster) way of implementing my top_sort function? 
\\ > !!  (Creating a top 10 list of the highest numbers from a large set).
\\ > !!  Or did I get lucky? :)
\\ > 
\\ > 
\\ > #!/usr/bin/perl
\\ > 
\\ > use strict;
\\ > use warnings;
\\ > no warnings qw /syntax/;
\\ > 
\\ > my @heap = map {int rand 1_000_000} 1 .. 100_000;
\\ > 
\\ > sub heapify;
\\ > sub heapify {
\\ >     my $index = shift;
\\ > 
\\ >     my ($c1, $c2) = (2 * $index + 1, 2 * $index + 2);
\\ >     my $max = $index;
\\ >     $max = $c1 if $c1 < @heap && $heap [$c1] > $heap [$max];
\\ >     $max = $c2 if $c2 < @heap && $heap [$c2] > $heap [$max];
\\ > 
\\ >     return if $max == $index;
\\ > 
\\ >     @heap [$index, $max] = @heap [$max, $index];
\\ >     heapify $max;
\\ > }
\\ > 
\\ > 
\\ > for (my $i = int (@heap / 2); $i >= 0; $i --) {heapify $i}
\\ > 
\\ > if (@heap) {
\\ >     for (1 .. 10) {
\\ >         print $heap [0], "\n";
\\ >         my $tmp = pop @heap;
\\ >         last unless @heap;
\\ >         $heap [0] = $tmp;
\\ >         heapify 0;
\\ >     }
\\ > }
\\  
\\  Well, you're heapifying the entire list, which is still an n log n
\\  operation.  Might as well sort :)

No! It's not. Look carefully, and do the math. It's an O (n) operation.
Note that the list is heapified from the left.



Abigail
-- 
sub _ {$_ = shift and y/b-yB-Y/a-yB-Y/                xor      !@ _?
       exit print                                                  :
            print and push @_ => shift and goto &{(caller (0)) [3]}}
            split // => "KsvQtbuf fbsodpmu\ni flsI "  xor       & _


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

Date: Sat, 09 Oct 2004 11:27:44 -0500
From: "Eric J. Roode" <sdn.girths00869@zoemail.net>
Subject: Re: Using a string as a variable name.
Message-Id: <Xns957D7EF0F5CECsdn.comcast@216.196.97.136>

Jeff@aetherweb.co.uk (Jeff) wrote in
news:525192b4.0410050834.25c2ee5f@posting.google.com: 

> Hi,
> 
> I want to do things like this:
> 
> my $v1 = "varname";
> my $varname = "it worked!";
> print ${$v1};
> 
> And have the final statement know that it should print the content of
> $varname. 
> 
> Is it possible?

Strange that you could figure out how to print the indirect value out, but 
you couldn't figure out how to assign indirectly.   :-)

    ${$v1} = "it worked!";

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


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

Date: Sat, 09 Oct 2004 11:06:48 -0500
From: "Eric J. Roode" <sdn.girths00869@zoemail.net>
Subject: Re: Who's responsible for this ?
Message-Id: <Xns957D7B5FDBA10sdn.comcast@216.196.97.136>

Csaba <root@localhost> wrote in news:Xns9574E216AE493rs232@195.129.110.131:

>  not exp log srand xor s qq qx xor
>  s x x length uc ord and print chr
>  ord for qw q join use sub tied qx
>  xor eval xor print qq q q xor int
>  eval lc q m cos and print chr ord
>  for qw y abs ne open tied hex exp
>  ref y m xor scalar srand print qq
>  q q xor int eval lc qq y sqrt cos
>  and print chr ord for qw x printf
>  each return local x y or print qq
>  s s and eval q s undef or oct xor
>  time xor ref print chr int ord lc
>  foreach qw y hex alarm chdir kill
>  exec return y s gt sin sort split
> 
> 

It's beautiful, isn't it?  No punctuation at all.

For your enjoyment, I present the exact opposite, a JAPH I wrote a few 
weeks ago.  It contains no alphabetic, numeric, or whitespace characters.  
(sadly, it only works on unix-like systems)

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


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

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


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