[20013] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 2208 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Nov 26 14:06:03 2001

Date: Mon, 26 Nov 2001 11:05:15 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <1006801515-v10-i2208@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Mon, 26 Nov 2001     Volume: 10 Number: 2208

Today's topics:
        "can't coerce array into hash" problem.... <no.th@ank.you>
        [ANNOUNCE] SPOPS 0.53 released <chris@cwinters.com>
    Re: A Perl Bug? <mcnuttj@dnps-linux1.telecom.missouri.edu>
    Re: A Perl Bug? <mcnuttj@dnps-linux1.telecom.missouri.edu>
    Re: A Perl Bug? <bart.lateur@pandora.be>
    Re: A Perl Bug? (Randal L. Schwartz)
    Re: A Perl Bug? (Randal L. Schwartz)
    Re: A Perl Bug? <jake@chaogic.com>
    Re: Array from a hash (Anno Siegel)
    Re: call-by-reference, no newbie question <jeffp@crusoe.net>
    Re: Can I avoid 2 passes? <godzilla@stomp.stomp.tokyo>
    Re: Can I avoid 2 passes? <5l259r001@sneakemail.com>
    Re: Can I avoid 2 passes? <flavell@mail.cern.ch>
    Re: Can I avoid 2 passes? <admin@asarian-host.net>
        CGI.pm Making Query available to child programs <roman@enterprise.net>
        Confused about timing map vs sub (Aaron Sherman)
    Re: Declaring a filehandle <dan@tuatha.sidhe.org>
    Re: Declaring a filehandle <5l259r001@sneakemail.com>
    Re: Declaring a filehandle <bart.lateur@pandora.be>
    Re: Declaring a filehandle <bart.lateur@pandora.be>
    Re: Declaring a filehandle <uri@stemsystems.com>
        documentation for functions in c <roger_faust@bluewin.ch>
    Re: documentation for functions in c <edgue@web.de>
    Re: documentation for functions in c <Juha.Laiho@iki.fi>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Mon, 26 Nov 2001 17:52:28 -0000
From: "Martin" <no.th@ank.you>
Subject: "can't coerce array into hash" problem....
Message-Id: <3c028396$1_2@mk-nntp-1.news.uk.worldonline.com>

i have the following code:

%t=undef;

$one[$i] = ...."code to populate @one";
$two[$i]= ...."code to populate @two";

while..... { blah
    $t{$one[$i]}{$two[$i]}++;
}


foreach my $key1 (sort keys %t) {

    foreach my $key2 (sort keys %{$t{$key1}}) {
        print FILE "$key1,$key2,$t{$key1}{$key2}\n";
    }
}

which gives me a "can't coerce array into hash" error at the  second foreach
statement.

I've read a few things about hashes-where-array's expected, and vice versa,
but nothing obvious to tell me my problem.

Anyone any thoughts??




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

Date: Sun, 25 Nov 2001 01:54:15 GMT
From: Chris Winters <chris@cwinters.com>
Subject: [ANNOUNCE] SPOPS 0.53 released
Message-Id: <u04g829r9gnb64@corp.supernews.com>


The latest version of SPOPS, Simple Perl Object Persistence with  
Security, has been released and is winging its way around CPAN right
now.  SPOPS is a robust and powerful module that allows you to
serialize objects. You can create most objects without any code, just
configuration.

This latest version (0.53) includes support for multiple-field primary
keys in DBI datasources, plus some additional examples of class
factory and persistence rules.

URLs:

Source (for CPAN-averse folk):

 http://sourceforge.net/project/showfiles.php?group_id=16810&release_id=62730

Release notes/changelog (much more detailed than above):

 http://sourceforge.net/project/shownotes.php?release_id=62730

Sourceforge home (mailing lists, CVS, bugs, to-do list, etc.):

 http://sourceforge.net/projects/openinteract/

Thanks,

Chris

-- 
Chris Winters (chris@cwinters.com)
Building enterprise-capable snack solutions since 1988.




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

Date: 26 Nov 2001 13:04:56 GMT
From: <mcnuttj@dnps-linux1.telecom.missouri.edu>
Subject: Re: A Perl Bug?
Message-Id: <9ttelo$s7i$1@dipsy.missouri.edu>

Logan Shaw <logan@cs.utexas.edu> wrote:

>>Having some religious view about it that either way is Right or
>>Wrong is silly.

> It's not a religious view.  It's the standard way to do it
> on Usenet.  Read the news.newusers.questions FAQ.  You're
> really supposed to read that before you make your first
> post to Usenet anyway.  The section on quoting is at
> http://www.geocities.com/ResearchTriangle/Lab/6882/nquote.html .

And what standards authority maintains this?  IEEE?  IANA?  This
is a matter of social habit, similar to the now-accepted use of
'their' as a singular pronoun.  E.g.  "Each person in the room
should bring their umbrella today."  Used to be wrong, but via
common usage is now the norm.

> If you don't believe that it's standard, go to
> http://groups.google.com/ , pick a few random newsgroups, and
> browse through some articles from several years ago.  You'll
> find that top-posting was essentially non-existent back then,
> and it's only relatively recently with the mass influx of new
> people that top-posting has started to happen on Usenet.

<shrug>  Just because it's a new habit of people - and just
because it may annoy you - doesn't make it bad.  That's merely
an observation about the timing, which is not relevant, any more
than it is relevant to say that there was no top-posting in 1883
when Usenet did not exist.

If you read my earlier post, you would note that I am not a
strong advocate of top-posting.  In most cases, it *is* annoying
and obfuscates a thread.  I am merely pointing out that to go and
condemn all top-posting for All Time Forever and Ever is just as
silly.  There are cases when top-posting is both useful and
appropriate.

Anyway, I'm not going to make my argument all over again.  Read
the other post.  The Main Point, though, is "think!"  There's
rarely a "never do this" or "always do that," espeicially on the
Internet.

--J


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

Date: 26 Nov 2001 13:16:55 GMT
From: <mcnuttj@dnps-linux1.telecom.missouri.edu>
Subject: Re: A Perl Bug?
Message-Id: <9ttfc7$udv$1@dipsy.missouri.edu>

Edwin G?nthner <edgue@web.de> wrote:


> Jake Fan wrote:

>> Standard?  Maybe we should all stick to Perl 1.0, which was the standard
>> many years ago?  Why GUI, since CLI was the standard for a long time in

> I think you are wrong for a number of reasons:

The part where you think there is a Right or Wrong in the first place is
the silly part.

> - It is your decision to use Perl 1.0, Perl 4 or Perl 5.7.2. It doesnt
>   affect other people in any way. But your posting style affects other 
>   people. The majority of people decided: we dont want top postings.

Whatever.  If he or I or anyone else decides to top-post, you can just
skip the article/thread.  No harm done.  Where's the part where it affects
other people?

>   But I can't see any advantages of top postings. This concept

Just because you don't see it doesn't mean it doesn't exist.  The world is
round.  Electricity is real.

>   has / is / and will always be the weaker one. You see - just because
>   everything changes it is not necessary to throw away the good
>   rules (that proved to be good over years).

One need not *only* top-post or *only* scatter one's comments throughout an
article.

One *should* make a reasoned decision about which method to use.  Top-
posting will rarely be the correct choice, but to throw it away because it's
"not the standard" is silly.

> Exactly. And "top posting" is not the standard because its the weaker
> way of providing information.  And by the way: it is just plain impolite
> (IMHO). If you write something, you want others to spend their time
> to read it. So it is YOUR job to provide your information in the best
> way - in the way that makes it easy for your reader to see your point.
> Top-Posting forces the reader to constantly switch between your text
> and the quoted text. They put the workload on the reader ...

You keep talking about these standards as if they're real.  They're not.

If you want to equate it to something like cursing in public, that's more
accurate, but there's no standard for that either.  In some cases, people
would be surprised if you *didn't* curse (say your finger gets cut off).
However, like top-posting, *most* of the time people get upset when you
curse in public.

But it's not a *standard* one way or another, neither is it an absolute.

> - "normal posting style": 
>   one person (author) needs to spent a hard time on doing a good job
>   many many people have an easy job to read ...

Most of the time...

> - top style posting:
>   one person (author) has an easy job to do
>   many many people need to spent much more time on reading and figuring
>   out the logical bridges between new and quoted material

Unless:

a)  Most people actively involved in the thread already know what happened
and others are not (really) invited to join anyway or...

b)  This is a thread that needs to die, thus a summary at the top
discourages additional posting on the topic.

>> who prefer not to do things the old way, is it possible that there is
>> something not quite right with the standard (not intuitive, not convenient)?
>> Perhaps we need to start considering upgrading the standard?

> Just try it. The majority will not follow you. They will simply ignore
> you and in the end, nobody will quote your text - because nobody
> is going to read ...

> Maybe I am wrong. But I doubt it.

<shrug>  I will.  I don't expect the Internet to be convenient.  Top-
posting is so common in Usenet and in e-mail that I've simply learned to
read it, rather than become a social pariah, since everyone I know top-
posts in e-mail, Usenet, etc....

It just doesn't *matter* that much!

--J


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

Date: Mon, 26 Nov 2001 16:10:24 GMT
From: Bart Lateur <bart.lateur@pandora.be>
Subject: Re: A Perl Bug?
Message-Id: <64q40uof0ktakb5jagft26vb97o9jtq7h4@4ax.com>

Jake Fan wrote:

>When you reply to a letter in real life, do you pick the original
>letter apart, make verbatim copy of various sentences and paragraphs, and
>then make comments beneath each one of them?  Probably you don't.

The analogy here is not that you're trying to write a letter, but that
you're turning a monologue -- the post you're replying to -- into a
dialogue.

A letter is personal. You *only* reply to the person that first wrote to
you -- or you write something completely independent, in which case it's
easier for third parties -- eavesdroppers -- to follow.

A reply on usenet is more like a critique to what somebody wrote
somewhere else. People may not have read that post. They shouldn't have
to. Without any specific references to the things you're talking about,
it would appear as if you're just nagging. The quotes here are your
references.

-- 
	Bart.


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

Date: 26 Nov 2001 05:34:51 -0800
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: A Perl Bug?
Message-Id: <m1adx9lkp0.fsf@halfdome.holdit.com>

>>>>> "Jake" == Jake Fan <jake@chaogic.com> writes:

Jake>   If their is a mass influx of new people
Jake> who prefer not to do things the old way, is it possible that there is
Jake> something not quite right with the standard (not intuitive, not convenient)?
Jake> Perhaps we need to start considering upgrading the standard?

No, it's possible that a very large software vendor in Redmond Washington
placed the default cursor in the wrong location, and the masses were
too lazy to move the cursor to the right place.

Don't confuse "lazy programming" with "innovation", please.

Top posting ultimately breaks down when replies are intermingled with
the things on which they are commmenting.  Can you at least agree to
that?  If so, the anti-top-posting crowd is not doing it just based on
tradition.  It's based on *what works* in the long run.

I'm happy to adopt new traditions.  But I'm not happy to give up what
works better.

Just another guy who has been around Usenet since 1980 (yes *1980*),

-- 
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: 26 Nov 2001 05:38:10 -0800
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: A Perl Bug?
Message-Id: <m1667xlkjh.fsf@halfdome.holdit.com>

>>>>> "Jake" == Jake Fan <jake@chaogic.com> writes:

>> rtfm. this is not a helpdesk. it is a discussion group on perl. you are

Jake> This *is a helpdesk, among other things.  I asked for help on a
Jake> problem, you and others provided answers, and I said "thank you
Jake> for your help".  Simple as that.  Next time, I myself could help
Jake> out on other people's problems.  This is the way it's supposed
Jake> to work.

No, it's not.  It's a discussion group that happens to get around to
giving answers to questions.  To put it in "helpdesk" mind gives the
questioner the right to get indignant via (misplaced) expectations
that there *will* be an answer, and it *will* be correct.  There is no
promise of an answer or applicability in this group (nor most other
groups).

When you call me on my 900-number or ask me a question in a class
you're taking from me, I'll answer your questions precisely and
correctly and quickly and (usually) not question why you're asking me
instead of looking in the manual.  *That's* like a help desk.

When you ask me a question here, you should EXPECT to be challenged to
read the manual first, or search available resources.  That's because
*this* is *not* a helpdesk.  See the difference?

print "Just another Perl hacker,"

-- 
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: Mon, 26 Nov 2001 12:42:58 -0600
From: "Jake Fan" <jake@chaogic.com>
Subject: Re: A Perl Bug?
Message-Id: <9tu2gs$caa$1@Masala.CC.UH.EDU>


Randal L. Schwartz <merlyn@stonehenge.com> wrote

> Jake> This *is a helpdesk, among other things.  I asked for help on a
>
> No, it's not.  It's a discussion group that happens to get around to
> giving answers to questions.  To put it in "helpdesk" mind gives the

I guess it's not.  To qualify as a helpdesk, all we now need is a desk -- a
game of words can be fun.  The point is, it's good enough to call it a
helpdesk.  It's a virtual helpdesk where everybody is a potential customer
as well as operator.  And today's customers (newbies) can be tomorrow's
operators (gurus).  It's based on the "one for all, all for one" premise.
And oh, should I mention it's a non-profit helpdesk.

> When you call me on my 900-number

It'd be a hotline

> or ask me a question in a class you're taking from me

It'd be, well, a class

> I'll answer your questions precisely and correctly and quickly

Are you sure all your answers will be precise and correct?  Or maybe I'm
talking to a God indeed (see God Complex in an earlier post)?

> When you ask me a question here, you should EXPECT to be challenged to
> read the manual first, or search available resources.  That's because
> *this* is *not* a helpdesk.  See the difference?

This is always a valid point -- to a certain extent.  I'd imagine that most
posters asking for help here have had quite some struggle with his/her own
unique questions/problems and tried various readily available resources.
But as I mentioned, most likely the readers of this news group come from
vastly different backgrounds.  A Unix sysadmin's definition of "read the
manual" can be quite different from that of a sociologist who happens to
need Perl in her research to accomplish some quick and dirty computing
tasks.

Plus (this is more of a nitpicking point), this helpd... I mean, news group
*is one of the available resources.  And after all it's named
comp.lang.perl.MISC.  Or maybe it should be split into .newbie and .guru?






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

Date: 26 Nov 2001 13:41:52 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Array from a hash
Message-Id: <9ttgr0$103$1@mamenchi.zrz.TU-Berlin.DE>

According to Blnukem <blnukem@hotmail.com>:
> Hi Group
> 
> I need some help I call this array from a hash and I get a bunch of commas
> "," in the output what is the best solution to stop this?

No, you don't "call an array from a hash" (shudder).  You are building
an array from a hash.

> Here is my code:
> 
> foreach $key ( sort{ $a <=> $b } %GRADETEST ){
                          ^^^
Apparently your hash keys are numeric.  You may consider using an
array instead of the hash, unless the population is very sparse.

I'll also assume that the line was actually meant to read

    foreach $key ( sort{ $a <=> $b } keys %GRADETEST ){

(note "keys" keyword).  It doesn't make much sense otherwise.

> push ( @USRANWSERS, $GRADETEST{$key});
> }
> 
> foreach (@USRANWSERS){
> ($questnumber,$questionanswer) = split(/\|/);
> 
> print "Content-type: text/html\n\n";

I don't think you want to print this each time through the loop.  Put
it before the loop.

> print "$questnumber $questionanswer<br>";
> }

Where commas enter the picture is anybody's guess.  They are most likely
already in the values of %GRADTEST, which you don't show.

Your code can be written more compactly like this (untested):

    print join( " ", split /\|/), '<br>' for
        @GRADTEST[ sort { $a <=> $b } keys %GRADTEST];

Anno


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

Date: Mon, 26 Nov 2001 09:42:50 -0500
From: Jeff 'japhy' Pinyan <jeffp@crusoe.net>
Subject: Re: call-by-reference, no newbie question
Message-Id: <Pine.GSO.4.21.0111260941280.23999-100000@crusoe.crusoe.net>

[posted & mailed]

On Nov 26, martin@unix-ag.org said:

>sub alter ($) {
>  $_[0]= $_[0] . " blub";
>}

>In effect what i want to have, but my sub is more
>complex and i use $_[0] a lot, where i've got to my problem
>by now. I want to give the variable / scalar which i
>use / modify in the sub a reasonable name and don't want to
>handle with $_[0] all the time. ok, we have these
>references in perl, using them it can be done like this:

If you don't have any early return()s, you could simply reassign to $_[0]
at the end of your function:

  sub alter {
    my $word = $_[0];  # NOT SHIFT!
    # modify $word
    $_[0] = $word;
  }

Otherwise, use an aliasing trick:

  sub alter {
    no strict 'vars';
    local *word = \$_[0];
    # modify word
  }

-- 
Jeff "japhy" Pinyan      japhy@pobox.com      http://www.pobox.com/~japhy/
RPI Acacia brother #734   http://www.perlmonks.org/   http://www.cpan.org/
** Look for "Regular Expressions in Perl" published by Manning, in 2002 **



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

Date: Mon, 26 Nov 2001 06:12:07 -0800
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: Can I avoid 2 passes?
Message-Id: <3C024DB7.216B8C37@stomp.stomp.tokyo>

Dale Henderson wrote:
 
> Godzilla! wrote:

(snipped)
 
> Actually, I've programmed perl for a number of years and even did
> it professionally for a while.


I have tiny winged blue monkeys flying out of my big butt,
each harmoniously singing Steppenwolf's "Born To Be Wild."


Godzilla!
--
 http://la.znet.com/~callgirl3/bornwild.mid


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

Date: Mon, 26 Nov 2001 18:50:22 +0100
From: "Steffen Müller" <5l259r001@sneakemail.com>
Subject: Re: Can I avoid 2 passes?
Message-Id: <9ttval$hvu$00$1@news.t-online.com>

"Godzilla!" <godzilla@stomp.stomp.tokyo> schrieb im Newsbeitrag
news:3C024DB7.216B8C37@stomp.stomp.tokyo...
| Dale Henderson wrote:
|
| > Godzilla! wrote:
|
| (snipped)
|
| > Actually, I've programmed perl for a number of years and even did
| > it professionally for a while.
|
|
| I have tiny winged blue monkeys flying out of my big butt,
| each harmoniously singing Steppenwolf's "Born To Be Wild."

You horrible troll! You posted that exact phrase before.

My answer: (2001-08-12 23:41:02 PST)

> > my big butt
>
> Cute. That's what I thought.
>
> How many elephants do you have sitting in your butt that sing Creed's "My
> Own Prison"?

Steffen
--
$_=q;0cb212c210b0bb010c0113bb0c410c0b516c0bb3d212c2b0b0b016b6cb2b2c21010c0
b41110b3bba0e0c0d2c4b2b6bc013d2c0d0b01012b0b0;;s/\n//g;s/(\d)/$1<2?$1:'0'x
$1/ge;s/([a-f])/'1'x(ord($1)-97)/ge;$o=$_;push@o,substr($o,$_*8,8) for(0..
24);for(@o){print"\0"x(26-$i).chr(oct('0b'.($_)))."\r";$i++};print"\n"#stm




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

Date: Mon, 26 Nov 2001 19:09:28 +0100
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: Can I avoid 2 passes?
Message-Id: <Pine.LNX.4.30.0111261903120.32094-100000@lxplus023.cern.ch>

On Nov 26, Steffen Müller inscribed on the eternal scroll:

[snipped]

Please, folks, do not feed the troll.

I'm not saying anything against the occasional public-service warning
being posted.  But taunting is futile: it just raises the general
noise level, and makes the group less-useful for everyone.

f'ups set.




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

Date: Mon, 26 Nov 2001 19:36:11 +0100
From: "Mark" <admin@asarian-host.net>
Subject: Re: Can I avoid 2 passes?
Message-Id: <9tu220$4tts4$1@ID-91012.news.dfncis.de>

"Godzilla!" <godzilla@stomp.stomp.tokyo> wrote in message
news:3BFAED23.7D7FEDDD@stomp.stomp.tokyo...

> Bart Lateur wrote:
>
> > Godzilla! wrote:
>
> > >>      So what's the difference between a hash and and associative
> > >>      array?
>
> > >Format, creation and access methodologies along with efficiency.
>
> > You stupid person. A "hash" is simply another shorter name for an
> > "associative array". Technically, they're the same thing.
>
> > So what's the difference between a car and an automobile?
>
> You state, with clarity, an associative array and a hash
> are the same, identical, no difference between the two.
> This you have stated, without any doubt.


He stated it with all the clarity, correctness, urgency and deliberation
that the truthfulness of his statement warranted. :)

An "associative array" got its name, because, unlike a regular array, it
associates a key with a value:

$simpletons{'godzilla'} = 'not understanding hashes';

Whereas in a regular array:

push (@simpletons, 'godzilla');

There is nothing to associate the element with; except, of course, the
temporary laughter elicited by the memory of your studious display of
failing to grasp even the most basic perl fundamentals. But, while amusing
to watch, hardly makes this array associative. :)

- Mark




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

Date: Mon, 26 Nov 2001 15:53:22 -0000
From: "Roman" <roman@enterprise.net>
Subject: CGI.pm Making Query available to child programs
Message-Id: <XbWrwGpdBHA.281@newssvr.manx.net>

I am using the PERL CGI module, I have a routine that uses the append()
method to add to a CGI query object, how can I make this the default 'query'
ie.  I have the main program (prog1) which makes the afore mentioned change
to the CGI object, this program then calls a second program (prog2), by
using system(),  which needs to be able to read the modified query.  I want
to be able to do this without having to modify prog2 which just gets the
parameters by using CGI::param().  Does anyone know how to accomplish this?




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

Date: 26 Nov 2001 08:24:25 -0800
From: ajs@ajs.com (Aaron Sherman)
Subject: Confused about timing map vs sub
Message-Id: <eaa2c627.0111260824.f15ba4d@posting.google.com>

I've written the uniq function over and over. It looks like this:

  sub uniq {
    my @r;
    my %x;
    foreach my $e (@_) {
      push @r, $e unless $x{$e}++;
    }
    return @r;
  }

In one case, I did not need to preserve order, but cared about keeping
the original floating-point representation (without converting to/from
string), so I wrote:

  values %{{map {("$_",$_)} @mylist}}

To be sure that this was more efficient, I ran some timing tests, and
was STUNNED! It turns out that this is less efficient on a 50,000
element list of (already unique) items BY A FACTOR OF MORE THAN 6!

I'm not certain how this could be. Does anyone have an understanding
of what could be going on? The temporary array, and temporary hash are
the same size in both cases. It seems to me that they should be the
same running time, except that one can be more easily inlined by hand
(which is what I was doing).

Even stranger!

  @tmp{@mylist}=@mylist;@result=values %tmp;

is a hair FASTER than the subroutine version.... Now I'm really
confused!

Just a side note: the nice part is that in Perl 6 this will be:

  keys %{{map {($_,undef)} @mylist}}

and the original floating-point representation will still be preserved
automatically. Very nice, thanks Larry!


Here are my timing tests:

bash$ time perl -le '@a=(1..50_000);@a=uniq(@a);print scalar(@a);sub
uniq {my@r;my%x;foreach my $e (@_){push @r,$e unless $x{$e}++}return
@r}'
50000

real	0m0.616s
user	0m0.590s
sys	0m0.020s
bash$ time perl -le '@a=(1..50_000);@a=values %{{map {("$_",$_)}
@a}};print scalar(@a)'
50000

real	0m5.165s
user	0m5.140s
sys	0m0.020s
bash$ time perl -le '@a=(1..50_000);@a{@a}=(@a);@a=values %a;print
scalar(@a)'
50000

real	0m0.428s
user	0m0.380s
sys	0m0.040s

perl -v

This is perl, v5.6.0 built for i386-linux

Copyright 1987-2000, Larry Wall

Perl may be copied only under the terms of either the Artistic License
or the
GNU General Public License, which may be found in the Perl 5.0 source
kit.

Complete documentation for Perl, including FAQ lists, should be found
on
this system using `man perl' or `perldoc perl'.  If you have access to
the
Internet, point your browser at http://www.perl.com/, the Perl Home
Page.


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

Date: Mon, 26 Nov 2001 16:08:48 GMT
From: Dan Sugalski <dan@tuatha.sidhe.org>
Subject: Re: Declaring a filehandle
Message-Id: <kOtM7.69655$Y6.7665080@news1.rdc1.ct.home.com>

news.bmthonline.net <p.tomkins@virgin.net> wrote:
> Thanks for your replies. They are really appreciated. I guess the answer can
> be summarized as

> local *FILE_HANDLE works but my *FILE_HANDLE does not.

Right. Local only works on globals, and there's no way to have a lexical
glob.

> and that is really the only reliable way to achieve it.

Well... not quite. The Symbol module, shipped with perl for ages, lets
you do this. Something like:

  use Symbol;
  my $file_handle = gensym();
  open $file_handle, "foo" or die "Can't open foo, $!/$^E";
  while (<$file_handle>) {
    ...
  }

Sorry I didn't think to mention that earlier.

					Dan


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

Date: Mon, 26 Nov 2001 17:19:19 +0100
From: "Steffen Müller" <5l259r001@sneakemail.com>
Subject: Re: Declaring a filehandle
Message-Id: <9ttq02$mc6$05$1@news.t-online.com>

"Godzilla!" <godzilla@stomp.stomp.tokyo> schrieb im Newsbeitrag
news:3C017DBA.37E72AAD@stomp.stomp.tokyo...| Steffen Müller wrote:
| > {
| >    open( my $fh, "my_pants") or die "Could not open my pants! $!";
| >    my $var = <$fh>; # reads the next line. (je nach $/)
| > }
|
| > my $var = <$fh>; # error, out of scope!
|
| This is a poor programming practice and
| provides no benefit.
|
| My suggestion is you unzip your pants
| and take a look at what you are doing.

Hey, lizard,

while not really *declaring* a filehandle (see other posts about local),
this is a very nice way to make a filehandle lexically scoped to a block.
When it goes out of scope, it's automagically closed.

So actually, your horrible example is wrong. Well, explicitly closing a file
handle isn't wrong in itself, but if you needn't, you shouldn't. That's
laziness, you troll!

Now, leave.

Steffen

P.S:
Do not pay any attention to what Godzilla says. It  is a  troll, and
has no decent working knowledge of Perl or  programming  in general.
Search groups.google.com to see a history  of its posts  and replies
to these posts.
--
$_=q;0cb212c210b0bb010c0113bb0c410c0b516c0bb3d212c2b0b0b016b6cb2b2c21010c0
b41110b3bba0e0c0d2c4b2b6bc013d2c0d0b01012b0b0;;s/\n//g;s/(\d)/$1<2?$1:'0'x
$1/ge;s/([a-f])/'1'x(ord($1)-97)/ge;$o=$_;push@o,substr($o,$_*8,8) for(0..
24);for(@o){print"\0"x(26-$i).chr(oct('0b'.($_)))."\r";$i++};print"\n"#stm





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

Date: Mon, 26 Nov 2001 17:41:11 GMT
From: Bart Lateur <bart.lateur@pandora.be>
Subject: Re: Declaring a filehandle
Message-Id: <21v40u4580dsaeifmsu7go08bt0e5dr9jr@4ax.com>

news.bmthonline.net wrote:

>I know that we can declare a scoped scalar, array or hash as
>my ($scalar, @array, %hash)
>
>but how do we declare a filehandle?

Ancient way:

	local *HANDLE;

but more modern is to stuff the handle into a scalar, and get a new
instance using the module FileHandle or (even more modern) IO::File.
(See perl5004delta to see why I claim that.)

	use FileHandle;
	my $fh = new FileHandle;

The cute thing is that you can open a file in the "new" call, with a
proper error message if the open() fails:

	use IO::File;
	my $fh = new IO::File('test.out.txt', 'w');

You can then still do

	while(<$fh>) { ... }

(if the file was opened for reading,) and

	print $fh @args;   # no comma!

-- 
	Bart.


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

Date: Mon, 26 Nov 2001 18:18:11 GMT
From: Bart Lateur <bart.lateur@pandora.be>
Subject: Re: Declaring a filehandle
Message-Id: <1o150u468487n1tsr1isanf1dvogudvkdm@4ax.com>

news.bmthonline.net wrote:

>local *FILE_HANDLE works but my *FILE_HANDLE does not.
>
>and that is really the only reliable way to achieve it.

Bope. Not if you want to open a localized filehandle in one sub and pass
it on in an object to be called in other subs/methods (Heh. What a long
phrase). "use FileHandle" works for that case.

-- 
	Bart.


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

Date: Mon, 26 Nov 2001 18:40:29 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Declaring a filehandle
Message-Id: <x7oflp8jdu.fsf@home.sysarch.com>

>>>>> "BL" == Bart Lateur <bart.lateur@pandora.be> writes:

  BL> news.bmthonline.net wrote:
  >> local *FILE_HANDLE works but my *FILE_HANDLE does not.
  >> 
  >> and that is really the only reliable way to achieve it.

  BL> Bope. Not if you want to open a localized filehandle in one sub and pass
  BL> it on in an object to be called in other subs/methods (Heh. What a long
  BL> phrase). "use FileHandle" works for that case.

and as you noted, IO::* is more modern. in fact FileHandle is a shell
module that just loads IO::Handle and it is slightly deprecated too:

	NOTE: This class is now a front-end to the IO::* classes.

there is no reason to use or mention FileHandle anymore. it is there
only for backwards compatibility

uri

-- 
Uri Guttman  ------  uri@stemsystems.com  -------- http://www.stemsystems.com
-- Stem is an Open Source Network Development Toolkit and Application Suite -
----- Stem and Perl Development, Systems Architecture, Design and Coding ----
Search or Offer Perl Jobs  ----------------------------  http://jobs.perl.org


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

Date: Mon, 26 Nov 2001 19:53:24 +0100
From: Roger Faust <roger_faust@bluewin.ch>
Subject: documentation for functions in c
Message-Id: <3c0269dd$1_1@news.bluewin.ch>

hi

I'm searching some docs for writing functions for perl in C. i've alredy 
found perlapi, perlguts, perlxs and perlxstut. is there more around?

thanks

-- 
        Roger Faust


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

Date: Mon, 26 Nov 2001 17:32:02 +0100
From: Edwin =?iso-8859-1?Q?G=FCnthner?= <edgue@web.de>
Subject: Re: documentation for functions in c
Message-Id: <3C026E82.774423D9@web.de>



Roger Faust wrote:

> I'm searching some docs for writing functions for perl in C. i've alredy
> found perlapi, perlguts, perlxs and perlxstut. is there more around?

www.swig.org might of interest for you.

regards,
eg


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

Date: Mon, 26 Nov 2001 17:15:57 GMT
From: Juha Laiho <Juha.Laiho@iki.fi>
Subject: Re: documentation for functions in c
Message-Id: <9tttd0$3n9$6@ichaos.ichaos-int>

roger_faust@bluewin.ch said:
>I'm searching some docs for writing functions for perl in C. i've alredy 
>found perlapi, perlguts, perlxs and perlxstut. is there more around?

I recall those were the four I read when I experimented with
perl/C interface layer.
-- 
Wolf  a.k.a.  Juha Laiho     Espoo, Finland
(GC 3.0) GIT d- s+: a C++ UH++++$ UL++++$ P++@ L+++ E(-) W+$@ N++ !K w !O
         !M V PS(+) PE Y+ PGP(+) t- 5 !X R !tv b+ !DI D G e+ h--- r+++ y+++
"...cancel my subscription to the resurrection!" (Jim Morrison)


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

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


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