[9262] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 2856 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Jun 12 15:17:19 1998

Date: Fri, 12 Jun 98 12:00:32 -0700
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Fri, 12 Jun 1998     Volume: 8 Number: 2856

Today's topics:
    Re: Actually a proposal: (was: Grieving our dying commu (Jacqui Caren) (Jacqui Caren)
    Re: ceil or trunc <aqumsieh@matrox.com>
    Re: Certified Perl Programmers (Jack Ostroff)
    Re: Command line substitution thru subdirectories spicard@my-dejanews.com
        Commercial use of perl. (Michael C. Tiernan)
    Re: COMPARING TIME & DATE <devs@usa.net>
    Re: ending a foreach loop <devs@usa.net>
    Re: ending a foreach loop (Mike Stok)
    Re: ending a foreach loop (Allan M. Due)
        goto in Perl debugger? <morse@segsrv.hlo.dec.com>
    Re: Have we got a good free Perl manual? (Kris Van Hees)
    Re: Have we got a good free Perl manual? <barmar@bbnplanet.com>
    Re: Have we got a good free Perl manual? <tchrist@mox.perl.com>
    Re: Help with Perl CGI script <gabriele@kollwitz.doit.wisc.edu>
    Re: lambda fun in Perl <tchrist@mox.perl.com>
    Re: lambda fun in Perl <jdporter@min.net>
    Re: More Perlish file size (bytes, KB, MB) (Joe McMahon)
    Re: Most common element of array. <vallon@bear.com>
    Re: Most common element of array. (Mike Whitaker)
    Re: Most common element of array. (Mike Whitaker)
    Re: Most common element of array. (Jack Ostroff)
    Re: Most common element of array. <danboo@negia.net>
    Re: NEED PERL SCRIPTING mchunziker@us.fortis.com
        null value checking with numbers (Irene Barg)
    Re: open and overwrite query... <barnett@houston.Geco-Prakla.slb.com>
    Re: pack/unpack seps <rs83@is7.nyu.edu>
    Re: perl and recursion? (Craig Berry)
        Perl and Shadow authentication (Sean Mahrt)
        Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)

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

Date: Fri, 12 Jun 1998 16:49:59 GMT
From: Jacqui.Caren@ig.co.uk (Jacqui Caren) (Jacqui Caren)
Subject: Re: Actually a proposal: (was: Grieving our dying community)
Message-Id: <EuG6rC.Jt6@ig.co.uk>

In article <355ADABE.D36068DA@nortel.co.uk>,
Frank L. Quednau <quednauf@nortel.co.uk> wrote:
>Andy Armstrong wrote:
>
>> How would you point people at the wizard instead of this newsgroup?
>
>Well, the newsgroups itself would have to be notified, and the link made
>known to the important websites on the world related to Perl.
>
>> If people were prepared to do the necessary legwork to find the answers to
>> their questions ... then the problem would ... cease to be.
>
>Certainly valid, but it's a basic 'feature' of our time that everything has
>to go fast, also information seeking. Personally I don't see an advantage in
>hunting down information, I would gladly use any way that would make this
>easier for me.

If "Time is money" then you have two options.

Plead mercy on those experts in these newsgroups and ignore the
ridcule you receive for asking FAQ's :-) or pay someone to find
the answer for you.

<PLUG SHAMELESS>
See http://www.perlclinic.com/
and http://www.perlsupport.com/

for further information. :-)
</PLUG>

>flexible in a way as that it is easily extendable within the given
>structure. I'll definitely have a think about that.

You mean like perldoc -f map ? :-)

Most of the perl documentation is reasonable well indexed and
I find myself using grep on periodic basis when other mechnaisms
fail. 

Converting the docs to HTML and running a search engine
over them (i.e. excite) provides a very good source
of information.  This sort of solution is also very easy
to implement and only costs time and effort - which can
be automated.

Jacqui

-- 
Email: Jacqui.Caren@ig.co.uk  http://www.ig.co.uk/
Fax  : +44 1483 419 419       http://www.perlclinic.com/
Phone: +44 1483 424 424       http://www.perl.co.uk/
Paul Ingram Group Ltd,140A High Street,Godalming GU7 1AB United Kingdom



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

Date: Fri, 12 Jun 1998 14:30:56 -0400
From: Ala Qumsieh <aqumsieh@matrox.com>
Subject: Re: ceil or trunc
Message-Id: <358173E0.2CAA0617@matrox.com>

Gopinath Venkataramanan wrote:

> Hi
>
> Is there a ceil or trunc function in perl (to round off numbers)
>
> thanx for ur time.

 I would use:

$rounded_num = int ($num + 0.5);

--
Ala Qumsieh             |  No .. not just another
ASIC Design Engineer    |  Perl Hacker!!!!!
Matrox Graphics Inc.    |
Montreal, Quebec        |  (Not yet!)





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

Date: 12 Jun 1998 17:26:53 GMT
From: jack_h_ostroff@groton.pfizer.com (Jack Ostroff)
To: tchrist@mox.perl.com (Tom Christiansen)
Subject: Re: Certified Perl Programmers
Message-Id: <6lrocu$1322@mascagni.pfizer.com>

[courtesy cc of this posting sent to cited author via email]

>> :But I think that cert comes with a shirt with really long sleeves.
> 
>  No, certs come with retsin.
> 
>  --tom
I'd say enough retsina is likely to lead to certifiability.

(The legal notice which may or may not have been appended by my corporate firewall may be ignored, since there is
no confidential information in this message.)


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

Date: Fri, 12 Jun 1998 18:18:09 GMT
From: spicard@my-dejanews.com
Subject: Re: Command line substitution thru subdirectories
Message-Id: <6lrrd0$2st$1@nnrp1.dejanews.com>



Tom, if you still didn't get Xuming Wang's point, then...

And Xuming, don't buy the camel book. Buy the Llama book.
It is the "Learning Perl" book.  Randal Schwartz is the primary
author... Tom's name appears in the latest addition, but it still
is a good book and he isn't as irritable as he is lately in
this group...

Tom, take it or leave it, but answering a newbie's question politely
doesn't mean you are not a real person.  You said as much in one
of your previous posts.

	-Sam

In article <357EA421.93D73366@emai.unc.edu>,
  Xuming Wang <xuming@emai.unc.edu> wrote:
>
> Wolfgang Denk wrote:
> >
> > xuming@email.unc.edu (Xuming Wang) writes:
> >
> > >"Uwe Honekamp" <uwe.honekamp@etas.de> wrote:
> >
> > >>On win32, however, you have to install a proper working find and xargs.
> > >>These (and more) can be found at www.cygnus.com/win32.
> > ...
> > >programmer.  but I am a newbie in programming and no one (until you,
> > >Uwe, thanks) told me where to get this non-Perl tool which is required
> >
> > It is not really "required". Life is just a LOT easier when you  have
> > the  right tools. This is a Perl group, so we won't discuss where you
> > can get all the other precious tools you may want to have.
>
> whatever it is required by his script or not he didn't say.  I tried his
script
> and posted the result and got this from him:
>
> > Stop bitching about not having tools.  It's not our fault that you're
> > too lazy, stupid, or rude to bother to install an operating system.
> > You can't get any useful work done with your problem.  If you want
> > to program, install a programming environment.  If you prefer to
> > watch MTV, you know where to find it.
> >
> > --tom
>
> no one has told me what kind of programming envionment besides an OS and a
perl
> distribution is needed to learn Perl.  anyway, now I know that without a find
> and xargs from www.cygnus.com/win32 I can't get any useful work done with my
> problem.  thanks guys.
>
> so would anyone kindly point out where people discuss or where can I ask where
I
> can get all the other precious tools which are not really required but can
make
> my life a LOT easier as a full time graduate student in biochemistry major who
> just wants to learn a little bit of Perl for fun or at least can make Tom's
> scripts runnable?  comp.os.ms-windows.programmer.tools*?  but I also use Unix.
> thanks in advance.
>
> > However, feel free to ask...
>
> yeah, but I won't post any testing results anymore (I guess this can also make
> my life a LOT easier).
>
> --
> Xuming Wang
>


-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/   Now offering spam-free web-based newsreading


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

Date: Fri, 12 Jun 1998 18:53:57 GMT
From: mtiernan@bbn.com (Michael C. Tiernan)
Subject: Commercial use of perl.
Message-Id: <9Peg1.117$Fr5.1400983@cam-news-reader1.bbnplanet.com>

	Okay, say a company wanted to utilize perl in a product,
	there's two possible scenarios that come to my mind:
		1) Company A sells a product that uses perl but they
		   don't supply it, that's up to the purchaser to get
		   and install.

		2) Company A sells a product that has perl bundled in it.

	I would suspect that legally, either one qualifies as
	commercial use of perl and as such will require some further
	discussions with SOMEONE.

	Two questions:
		A) Am I right in my assumptions?
		B) Who gets talked to?

	Thanks for all your time folks.
--
        << MCT >>                        mtiernan@bbn.com
        Michael C Tiernan                Customer Support Engineering
        Phone: +1 (617) 873-5603         733 Concord Ave., MS: 18/1C
          FAX: +1 (617) 873-5681         Cambridge, MA.   02138


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

Date: Fri, 12 Jun 1998 12:12:44 -0500
From: Deva Seetharam <devs@usa.net>
Subject: Re: COMPARING TIME & DATE
Message-Id: <3581618C.22985EF1@usa.net>

Mathijs Oosterom wrote:

> Hi all,
>
> In a temp-file on my Linux-server I have a date & time written. In a
> certain Perl-script I want to determine the difference between the date &
> time in the temp-file and the current date & time.
>
> Of course this can be done by writing a routine that does a lot of
> calculations, but I wonder if there is a better and faster way to do it.
> Maybe there's some sort of function for this?
>
> All help will be appreciated, thanx in advance,
>
> Thijs.

  In www.perl.com, under perl reference, there is an entry called "Time".
 Follow that link, to get details on modules that would do date-time
manipulation.




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

Date: Fri, 12 Jun 1998 11:47:38 -0500
From: Deva Seetharam <devs@usa.net>
Subject: Re: ending a foreach loop
Message-Id: <35815BAA.63292AE4@usa.net>



Kevin Thorley wrote:

> I'm using the following lines of code to search an array line by line
> for a given string.  When I find the string though, I don't want to
> continue searchin (it will only appear once).  Can I break out of a
> foreach loop, or should I be using another type of loop.
>
>         foreach (@DATA){
>         if (! m/^\#/) {
>                 if (m/^$file_name/){
>                         split(/\t+/);
>                 }
>         }
>
>         Kevin Thorley
>         kthorley@mpgnews.com

You can use "last" statement to exit foreach loop.Deva



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

Date: 12 Jun 1998 17:07:57 GMT
From: mike@stok.co.uk (Mike Stok)
Subject: Re: ending a foreach loop
Message-Id: <6lrn9d$m81@news-central.tiac.net>

In article <35815749.4031@idt.net>, Kevin Thorley  <kthor@idt.net> wrote:
>I'm using the following lines of code to search an array line by line
>for a given string.  When I find the string though, I don't want to
>continue searchin (it will only appear once).  Can I break out of a
>foreach loop, or should I be using another type of loop.
>
>
>	foreach (@DATA){
>	if (! m/^\#/) {
>		if (m/^$file_name/){
>			split(/\t+/);
>		}
>	}

You can use perl's loop control statements which are documented in the
perlsyn man page

  foreach (@DATA) {
    next if /^#/;

    if (/^$file_name/) {
      split(/\t+/);
      last;
    }
  }

might do what you want,m the perlsyn man page describes what last and next
do in detail.

If you were scanning a file rather than an array in memory then you might
consider using while (<FILE>) rather than foreach (<FILE>).

Hope this helps,

Mike

-- 
mike@stok.co.uk                    |           The "`Stok' disclaimers" apply.
http://www.stok.co.uk/~mike/       |   PGP fingerprint FE 56 4D 7D 42 1A 4A 9C
http://www.tiac.net/users/stok/    |                   65 F3 3F 1D 27 22 B7 41
stok@colltech.com                  |            Collective Technologies (work)


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

Date: 12 Jun 1998 17:13:17 GMT
From: due@murray.fordham.edu (Allan M. Due)
Subject: Re: ending a foreach loop
Message-Id: <6lrnjd$hnv$0@206.165.146.93>

[This followup was posted to comp.lang.perl.misc and a copy was sent to 
the cited author.]

In article <35815749.4031@idt.net>, Kevin Thorley (kthor@idt.net) 
posted...
|I'm using the following lines of code to search an array line by line
|for a given string.  When I find the string though, I don't want to
|continue searchin (it will only appear once).  Can I break out of a
|foreach loop, or should I be using another type of loop.
|
|
|	foreach (@DATA){
|	if (! m/^\#/) {
|		if (m/^$file_name/){
|			split(/\t+/);
|		}
|	}
|
|
|
|	Kevin Thorley
|	kthorley@mpgnews.com
|

Well, if you are done, then that is the last time you need to loop!

perldoc -f last

There is an example using foreach in the Camel book on pg 25.
HTH
-- 
Allan M. Due
Due@Murray.Fordham.edu
Allan@Due.nu Yes it's new

The beginning of wisdom is the definitions of terms.
- Socrates


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

Date: Fri, 12 Jun 1998 13:22:47 -0400
From: Tim Morse <morse@segsrv.hlo.dec.com>
Subject: goto in Perl debugger?
Message-Id: <358163E7.41C6@segsrv.hlo.dec.com>

Is there a 'goto <linenumber>'-like command for the perl debugger?
I'd like to be able to change the flow of control when I debug
my perl scripts but can't figure out how to do it.

I can't find any likely commands in the debugger and I've looked
at the FAQs and newsgroup archives with no luck.  It seems like
I must be missing something obvious.  Any help would be appreciated,
thanks.


Tim Morse


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

Date: 12 Jun 1998 16:51:09 GMT
From: aedil@fnx.com (Kris Van Hees)
Subject: Re: Have we got a good free Perl manual?
Message-Id: <6lrm9t$mic$1@client2.news.psi.net>

With all this racket going on about a good free manual for Perl...  I don't
see why a manual has to be free, since even a non-free manual can promote the
use of free software.  And for sure, the existance of a non-free manual should
not be a blame on the author for writing a non-free manual, but rather on the
free software community for failing to come up with a free manual.

If I were to develop a piece of software (which I do), and I choose to make the
most extensive documentation non-free (which I might do - who knows), then am
I going against free SOFTWARE ideas?  No, especially not since I don't prevent
anyone from taking up a project of providing free documentation.

Anyhow...  What I wonder about is why I can't find a decent GCC manual, free
or not free.  There is a nice document on porting GCC etc (though it is a bit
shaky), but I don't find any really good documentation on GCC, with how things
work, why, what the effects of certain switches are, what the output of the
various stages is, and how to interpret it...  It can be distilled from the
porting guide and sources, but still...

If the FSF cannot provide sufficient documentation for its own software, I do
not think it is fair to attack software for which documentation exists, be it
free or not.

Aedil


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

Date: Fri, 12 Jun 1998 17:12:18 GMT
From: Barry Margolin <barmar@bbnplanet.com>
Subject: Re: Have we got a good free Perl manual?
Message-Id: <Sjdg1.114$Fr5.1316181@cam-news-reader1.bbnplanet.com>

In article <6lrm9t$mic$1@client2.news.psi.net>,
Kris Van Hees <aedil@fnx.com> wrote:
>If I were to develop a piece of software (which I do), and I choose to make the
>most extensive documentation non-free (which I might do - who knows), then am
>I going against free SOFTWARE ideas?  No, especially not since I don't prevent
>anyone from taking up a project of providing free documentation.

That's precisely what RMS is asking for.  This whole discussion is about an
item on the GNU Project task list that says something like "Someone should
write a good, free manual for Perl."  He never claims there's something
wrong with Perl because its documentation isn't free, he's just asking for
volunteers to provide what he sees as a missing feature.

Of course, if you make your documentation free in the first place, you're
helping the free software community more, since it's one less thing that
has to be reinvented.  In RMS's mind, anyone who creates non-free software
or documentation is hurting the free software community.  And it seems
inconsistent to write free software but then provide only non-free
documentation; it puts up a large barrier against modification of the
software (a small change to the software could require you to recreate all
of the documentation from scratch, just so you can document the change
properly).  Morally, making it difficult for someone to modify the code is
almost as bad as prohibiting it outright.

-- 
Barry Margolin, barmar@bbnplanet.com
GTE Internetworking, Powered by BBN, Cambridge, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.


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

Date: 12 Jun 1998 17:11:00 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: Have we got a good free Perl manual?
Message-Id: <6lrnf4$r15$1@csnews.cs.colorado.edu>

 [courtesy cc of this posting sent to cited author via email]

In comp.lang.perl.misc, 
    aedil@fnx.com (Kris Van Hees) writes:
:Anyhow...  What I wonder about is why I can't find a decent GCC manual, free
:or not free.  

Funny, eh?  

>If the FSF cannot provide sufficient documentation for its own software

I don't imagine you're referring to that terrible habit of sending out
cruddy manpages, ones that say they're intentionally wrong?

--tom
-- 
    Besides, REAL computers have a rename() system call.    :-)
                    --Larry Wall in <7937@jpl-devvax.JPL.NASA.GOV>


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

Date: Fri, 12 Jun 1998 12:02:19 -0500
From: "Gabriele R. Fariello" <gabriele@kollwitz.doit.wisc.edu>
To: Tom Phoenix <rootbeer@teleport.com>
Subject: Re: Help with Perl CGI script
Message-Id: <Pine.LNX.3.96.980612120040.2532A-100000@kollwitz.doit.wisc.edu>

On Thu, 11 Jun 1998, Tom Phoenix wrote:

> On Thu, 11 Jun 1998, Gabriele R. Fariello wrote:
> 
> > I confess I do not know what os we are talking about here, but this works
> > for me in UNIX if I do not have anyof the Mail pm's available:
> > 
> > open(MAIL, "| /usr/sbin/sendmail -t") or die "Puke! $!";
> > print MAIL <<"EOF"
> > To: "Someone" <someone@somewhere.com>
> 
> No, that doesn't work for you. :-)
> 

Ooops, I should test my work before I post. Sorry about that, you need to
have a semicolon at the end of "EOF" and each "@" needs to be escaped
(i.e. "\@"). I am ashamed.

-Gabriele




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

Date: 12 Jun 1998 16:49:18 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: lambda fun in Perl
Message-Id: <6lrm6e$p26$1@csnews.cs.colorado.edu>

 [courtesy cc of this posting sent to cited author via email]

In comp.lang.perl.misc, 
    Xah Lee <xah@shell13.ba.best.com> writes:
:Is there a way to sequence functions without nesting notation?

    print reverse sort readline *STDIN;

--tom
-- 
"Everything you said about Plan 9 is wrong"
     -- Rob Pike, letting a speaker have it


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

Date: Fri, 12 Jun 1998 18:18:56 GMT
From: John Porter <jdporter@min.net>
Subject: Re: lambda fun in Perl
Message-Id: <35817281.393D@min.net>

Xah Lee wrote:
> 
> Xah Lee wrote:
> >
> > Is there a way to sequence pure functions without
> > using a nesting notation such as the following?
> >
> > sub{sort @_;} ->
> >         (sub{map {$_/2} @_;}->
> >                 ( sub {reverse @_;}->
> >                         ( sub {map {$_ *2} @_; } ->
> >                                 (1..4))));
> 
> John Porter <jdporter@min.net> writes:
> > Um, any reason why that is to be prefered over, say,
> >
> >       sort
> >       map { $_ / 2 }
> >       reverse
> >       map { $_ * 2 }
> >       (1..4);
> 
> Interesting example that caused me to think a bit. I think the reason
> is analogous to "why are there purely functional languages while we
> could program functionally in existing languages?".


Well, we already know what your bias is.
Perl is a wonderful, powerful tool. If you find that Perl still doesn't
meet your standards for terseness, then by all means, help yourself
away from Perl.



> In the above case, if I string > a sequence of functions, I can
> copy and paste worry-free. Otherwise,  I'd have to worry about
> side effects. Lambda calculus is what I want to line up to...


You have to worry about side-effects in any case, if the 
language permits them.  If you really want to never have to
worry about side-effects, then you must restrict yourself to
language which don't allow them.



> Is there a way to sequence functions without nesting notation?

Yes, by using prototypes.  But, AFAIK, this cannot currently be
combined with anonymous subs.

John Porter


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

Date: Fri, 12 Jun 1998 14:04:57 -0400
From: joe.mcmahon@gsfc.nasa.gov (Joe McMahon)
Subject: Re: More Perlish file size (bytes, KB, MB)
Message-Id: <joe.mcmahon-1206981404570001@prtims.stx.com>

In article <3580B443.499D@comenius.ms.mff.cuni.cz>, Jan Krynicky
<JKRY3025@comenius.ms.mff.cuni.cz> wrote:

>Joe McMahon wrote:
>> 
>> In article <6kv4q7$qup@newshub.atmnet.net>, "C.W.Holeman II"
>> <choleman@simpact.com> wrote:
>> 
>> >This works but how about something more Perlish?
>> 
>> Okay, how about a tied scalar that automagically prints out reformatted?
>> Very Perlish, but kinda silly...
>> 
>>  --- Joe M.
>> 
>> use KFormatter;
>> tie $memsize,"KFormatter";
>> $memsize = 20_345_645;
>> print $memsize; # 319.40M2
>> 
><code snipped>
>
>You may want to look at Interpolation.pm 
>( http://www.plover.com/~mjd/perl/Interpolation/ )
>
>
>use Interpolation kilo => sub {do something with $_[0] ...};
>
>print "The file is $kilo{-s $filename}\n";
>
Yup, I've seen it - this was just an example I've used to illustrate a 
"perly" way to do something that might stimulate someone to look at a 
problem differently.

 --- Joe M.


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

Date: Fri, 12 Jun 1998 16:58:44 GMT
From: Justin Vallon <vallon@bear.com>
Subject: Re: Most common element of array.
Message-Id: <x6era0umu9m.fsf@pearl.bear.com>

mrw@malay.entropic.co.uk (Mike Whitaker) writes:

> #!/usr/bin/perl -w
> 
> use strict;
> use diagnostics;
> 
> sub most_common {
>     my %count;
>     foreach (@_) { $count{$_}++; }
>     (sort { $count{$b} <=> $count{$a} } keys %count)[0]; 
> }
> 
> my @ary = qw/duck duck duck grouse moan complain grouse duck/;
> 
> print most_common(@ary), "\n";

You just want the max, right?  Just find the max.

sub most_common {
    my %count;
    foreach (@_) { $count{$_}++; }
    my $best_item, $best_count;
    if (($best_item, $best_count) = each %count) {
       # Got one
       while (($i, $c) = each %count) {
           ($best_item, $best_count) = ($i, $c) if $c > $count;
       }
    }
    return $best_item;
}

my @ary = qw/duck duck duck grouse moan complain grouse duck/;

print most_common(@ary), "\n";

-- 
-Justin
vallon@bear.com


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

Date: 12 Jun 1998 17:04:54 GMT
From: mrw@malay.entropic.co.uk (Mike Whitaker)
Subject: Re: Most common element of array.
Message-Id: <slrn6o2nnd.ger.mrw@malay.entropic.co.uk>

On Fri, 12 Jun 1998 16:58:44 GMT,
  Justin Vallon <vallon@bear.com> wrote:

>You just want the max, right?  Just find the max.

Yeah, but I was going for Laziness and Hubris this time round.
*grin*
-- 
Mike Whitaker: Sysadmin, Entropic Cambridge Research Labs


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

Date: 12 Jun 1998 17:02:40 GMT
From: mrw@malay.entropic.co.uk (Mike Whitaker)
Subject: Re: Most common element of array.
Message-Id: <slrn6o2nj6.ger.mrw@malay.entropic.co.uk>

On 12 Jun 1998 16:40:38 GMT,
  Jahwan Kim <jahwan@lilac.engin.umich.edu> wrote:
>On 12 Jun 1998 12:33:37 GMT, Mike Whitaker <mrw@malay.entropic.co.uk> wrote:
>[snip]
>> 
>> #!/usr/bin/perl -w
>> 
>> use strict;
>> use diagnostics;
>> 
>> sub most_common {
>>     my %count;
>>     foreach (@_) { $count{$_}++; }
>>     (sort { $count{$b} <=> $count{$a} } keys %count)[0]; 
>       ^^^^
>
>   Not the fastest way...  If we had the 'extremum' function which has the
>same syntax as sort as someone suggested in the group sometime ago, I'd
>replace sort by that.  Sorry, don't have a patch.

No, certainly not the fastest.
But it made me go and look up a couple of things and turn 'I think I know
how this works' into 'I know how this works'. (And coindentally get
sidetrack by the next paragraph along into learning something else...)
-- 
Mike Whitaker: Sysadmin, Entropic Cambridge Research Labs


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

Date: 12 Jun 1998 17:52:30 GMT
From: jack_h_ostroff@groton.pfizer.com (Jack Ostroff)
To: gebis@albrecht.ecn.purdue.edu (Michael J Gebis)
Subject: Re: Most common element of array.
Message-Id: <6lrpsu$1323@mascagni.pfizer.com>

In article <6lq57u$673@mozo.cc.purdue.edu>, gebis@albrecht.ecn.purdue.edu (Michael J Gebis) writes:
> @array=('duck','duck','duck','duck','goose','duck','goose');
> 
> I'd like to find the most common element in the array:
> 
> print most_common(@array);	#prints "duck"
> 
How about the following, which only makes one pass through the list?

sub find_most_common {
  my $max = ' ';
  my %stuff = (' ', 0);
  foreach (@_) {
    $max = $_ if (++$stuff{$_} > $stuff{$max});
  }
  return "$stuff{$max} ocurrences of $max\n";
}

print find_most_common qw(duck duck goose goose bear goose duck);


Jack Ostroff
jack_h_ostroff@groton.pfizer.com

(My corporate firewall sometimes appends a legal notice, which can be ignored, since there
is nothing confidential in this message.)


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

Date: Fri, 12 Jun 1998 14:46:31 -0400
From: Dan Boorstein <danboo@negia.net>
Subject: Re: Most common element of array.
Message-Id: <35817787.DC22B0B5@negia.net>

Justin Vallon wrote:
> 
[SNIP]
> 
> You just want the max, right?  Just find the max.
> 
> sub most_common {
>     my %count;
>     foreach (@_) { $count{$_}++; }
>     my $best_item, $best_count;
>     if (($best_item, $best_count) = each %count) {
>        # Got one
>        while (($i, $c) = each %count) {
>            ($best_item, $best_count) = ($i, $c) if $c > $count;
>        }
>     }
>     return $best_item;
> }
> 
> my @ary = qw/duck duck duck grouse moan complain grouse duck/;
> 
> print most_common(@ary), "\n";

hmm, i see some problems. try running this with warnings on.

1. 'my' binds more tightly than the comma
2. $count is used only once
     a. my @ary = qw/foo foo duck/; tells me that duck is the
        most common
3. style wise, you're iterating twice when you only need do it once

though i still like Mike Whitaker's solution for its cleverness and
speed, here is something along the lines of what you were trying:


sub most_common {
  my ($count, $most, %parts) = (0);
  for (@_) {
    if (++$parts{$_} > $count) {
      $count = $parts{$_};
      $most = $_;
    }
  }
  return $most;
}

cheers,

-- 
Dan Boorstein   home: danboo@negia.net  work: danboo@y-dna.com

 "THERE IS AS YET INSUFFICIENT DATA FOR A MEANINGFUL ANSWER."
                         - Cosmic AC


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

Date: Fri, 12 Jun 1998 17:54:23 GMT
From: mchunziker@us.fortis.com
Subject: Re: NEED PERL SCRIPTING
Message-Id: <6lrq0f$ln$1@nnrp1.dejanews.com>



I have to agree, lord knows I could use a workout, but it
doesn't put bread on the table. I think you'll have to up
your offer to generate any interest.

>In article <6lrcc2$c8r$1@usenet11.supernews.com>,
  petdance@maxx.mc.net (Andy Lester) wrote:
>
> : Not certain on  pay but will consider workout.
>
> Having to exercise hardly seems like adequate remuneration for my
> programming skills, but maybe I'm just overly sedentary.
>
> xoxo,
> Andy
>
> --
> --
> Andy Lester:        <andy@petdance.com>       http://tezcat.com/~andy/
> Chicago Shows List: <shows@ChicagoMusic.com>  http://ChicagoMusic.com/
>
>


-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/   Now offering spam-free web-based newsreading


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

Date: 12 Jun 1998 18:44:23 GMT
From: barg@nickel.as.arizona.edu (Irene Barg)
Subject: null value checking with numbers
Message-Id: <6lrsu7$efg$1@news.ccit.arizona.edu>

Hello,

I need to check if a numeric value is null (or not defined), but
don't want to use 'defined' because I get unpredictable results.
What I've tied is shown below:

#!/home/sybase/bin/perl

# source the subroutines
use lib '/home/sybase/bin';
require "archive_subs.pl";

$dt = "Dec  9 1997  7:41:39:000PM";
$vallist = "";

$value = matchfoc($dt);
if ($value eq "ERR") {
    print "Error:  rel focus = $value\n";
    exit(-1);
}
print "value = $value\n";

if ($value == "") {
    $vallist .= "null,";    	           
} else {
    $vallist .= "$value,";
}
print "vallist = $vallist\n";
exit(0);

When I run 'test.pl', I get:

value = 0
vallist = null,

In this case, zero is a valid value, but it still gets reset as 'null'.

Suggestions?
Thanks,
--irene

-------------------------------------------------------------------
Irene Barg			Email:	ibarg@as.arizona.edu
Steward Observatory		Phone:  520-621-2602
University of Arizona		FAX:    520-621-1891
Tucson, AZ  85721		http://nickel.as.arizona.edu/~barg
-------------------------------------------------------------------



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

Date: Fri, 12 Jun 1998 11:36:30 -0500
From: Dave Barnett <barnett@houston.Geco-Prakla.slb.com>
Subject: Re: open and overwrite query...
Message-Id: <3581590E.3F637C3D@houston.Geco-Prakla.slb.com>

Jason Nugent wrote:
> 
>         Hi folks,
> 
>         this has been bothering me for a while now and I figured I would
> ask.  I've been trying to open a file using the standard open() command so
> that I can read it in and then overwrite it all at once.  Is there a
> open() modifier that lets you this?
> 
>         open(HANDLE,"file") or die "$!";  # read mode only
>         open(HANDLE,"<file") or die "$!"; # ditto
>         open(HANDLE,"<file") or die "$!";  # write mode only
>         open(HANDLE,"+<file") or die "$!"; # read and append mode?
>         open(HANDLE,">>file") or die "$!"; # append mode
> 
>         The one that seems to offer promise is
> 
>         open(HANDLE,"+>file") or die "$!";
> 
>         but it munges the file before I get to read it.  Is there a way to
> read the contents in, and then overwrite the file?
<snip>

1.  Either open the file, and read the data, close & reopen for output,
or
2.  read perldoc -f open

I quote:

If the filename begins with '<' or nothing, the file is opened for
input.
If the filename begins with '>', the file is truncated and opened for
output.  If the filename begins with '>>', the file is opened for
appending.  You can put a '+' in front of the '>' or '<' to indicate
that
you want both read and write access to the file; thus '+<' is almost
always preferred for read/write updates--the '+>' mode would clobber the
file first.  The prefix and the filename may be separated with spaces.
These various prefixes correspond to the fopen(3) modes of 'r', 'r+',
'w',
'w+', 'a', and 'a+'.


What you are describing is documented perl behaviour.

HTH.

Dave

-- 
"Security through obscurity is no security at all."
		-comp.lang.perl.misc newsgroup posting

----------------------------------------------------------------------
Dave Barnett                 U.S.: barnett@houston.Geco-Prakla.slb.com
DAPD Software Support Eng    U.K.: barnett@gatwick.Geco-Prakla.slb.com
----------------------------------------------------------------------


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

Date: Sat, 13 Jun 1998 14:02:07 -0400
From: Ruben I Safir <rs83@is7.nyu.edu>
To: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: pack/unpack seps
Message-Id: <3582BE9F.C8E14CEE@is7.nyu.edu>

There's no reason to be rude.  I'm understand the answer and has written
about 800 lines of perl code inbetween the answers for 4 programs.

I was just explaining to you my problem with the documentation.  If you want
to hide your head in the sand and say that the docs explain the function
clearly, go right ahead.

PACK and UNPACK are to be used on databases, some of them may not even be
written in PERL - go forbid.  Under these circumstances, the simple
explainations without focus on datatypes is NOT effective, IMO.


I have a byte that I can look at in a datafile with OD....I needed to know
exactly why the two permutations were returning different values.  It was
explained and I understand.

You didn't understand what I didn't understand in the docs, I tried to
explain it to you.  This is not a game or a high school project, this is a
live database and I needed to be sure of what I was looking at.

Thank you for your time.

Ruben


Tom Christiansen wrote:

>  [courtesy cc of this posting sent to cited author via email]
>
> In comp.lang.perl.misc, Ruben I Safir <rs83@is7.nyu.edu> writes:
> :  I have a data file I need to parse, and UNPACK(a) and UNPACK(c) returns
> :different
> :results.
>
> You have just exhausted your alotted quota of repeating the same question
> again and again, and continuing to fail to understand despite innumerable
> private and public answers.  Since it's obvious that we are all too
> stupid to understand how to help you, I think it's time for you to to
> use your own brain to uncover these answers empirically.
>
> 5% -> 300%
>
> --tom





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

Date: 12 Jun 1998 17:39:37 GMT
From: cberry@cinenet.net (Craig Berry)
Subject: Re: perl and recursion?
Message-Id: <6lrp4p$7jg$1@marina.cinenet.net>

Michael Wentzel (wentzel@umr.edu) wrote:
: Does perl allow recursion? In other words, does this work?
: 
: sub update_totals
:   { ...
:     if ($filename ne "") { &update_totals; }
:     ...
:   }
: 
: If anyone can help me with this or point me in the right direction I
: would appreciate it.  Thanks.

Why not just try it?  (But yes, it does.  Be careful to make proper use of
'my' and/or 'local' to get proper scoping for variables used in the
subroutine.)

---------------------------------------------------------------------
   |   Craig Berry - cberry@cinenet.net
 --*--    Home Page: http://www.cinenet.net/users/cberry/home.html
   |      Member of The HTML Writers Guild: http://www.hwg.org/   
       "Every man and every woman is a star."


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

Date: Fri, 12 Jun 1998 13:48:18 -0500
From: bigmouth@iastate.edu (Sean Mahrt)
Subject: Perl and Shadow authentication
Message-Id: <bigmouth-1206981348180001@mahrt.ag.iastate.edu>

I've been beating my head trying to get anything working with suid under
c, so I chose another route.  Now I want to do verification of passwords
within a perl program when I'm running shadow?  I found a little tar file
for it, but it doesn't compile and has absolutely no docs or who it was
written by...    Any ideas?  I don't want to have two passwords for users
to remember...

Sean


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

Date: 8 Mar 97 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 8 Mar 97)
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.misc (and this Digest), send your
article to perl-users@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.

The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq". The real FAQ, as it
appeared last in the newsgroup, can be retrieved with the request "send
perl-users FAQ". Due to their sizes, neither the Meta-FAQ nor the FAQ
are included in the digest.

The "mini-FAQ", which is an updated version of the Meta-FAQ, is
available by requesting "send perl-users mini-faq". It appears twice
weekly in the group, but is not distributed in the digest.

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 V8 Issue 2856
**************************************

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