[19443] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 1638 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Aug 28 11:05:31 2001

Date: Tue, 28 Aug 2001 08:05:09 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <999011108-v10-i1638@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Tue, 28 Aug 2001     Volume: 10 Number: 1638

Today's topics:
    Re:  Java mucks up split 194.203.212.8 [demerphq@hotmail.com]
    Re:  Re: A bit of expaination of caller() please 194.203.212.8 [demerphq@hotmail.com]
    Re:  Re: CODE reference to member function of package C 194.203.212.8 [demerphq@hotmail.com]
    Re: 4th ed of the Camel? <djberge@uswest.com>
    Re: Adding a html break tag at eol in text... <jbc@west.net>
        Beginner PERL Book (at)
    Re: Beginner PERL Book <bart.lateur@skynet.be>
    Re: Beginner PERL Book <Thomas@Baetzler.de>
        changing users within a perl script <none@westriv.com>
    Re: Checking entries in a CSV file....? (Martien Verbruggen)
    Re: Checking entries in a CSV file....? <james@zephyr.org.uk>
    Re: Checking entries in a CSV file....? <bart.lateur@skynet.be>
    Re: Checking entries in a CSV file....? <james@zephyr.org.uk>
    Re: form post to https server, best method (Helgi Briem)
    Re: fwd: Sex or perl? <bemsha@midsouthSPAM.rr.com>
        how to do 'c' - 'a' = 2 in perl? <cheng@cs.wustl.edu>
    Re: how to get named constants in Perl (Martien Verbruggen)
    Re: how to get named constants in Perl (Martien Verbruggen)
    Re: Java mucks up split (Randal L. Schwartz)
    Re: Keeping files open <yanoff@yahoo.com>
    Re: Perl number conversion Utilities <hasting@agere.com>
        pipe, fork and Gtk+ <jens@irs-net.com>
    Re: searching an arrey <djberge@uswest.com>
    Re: searching an arrey <joe+usenet@sunstarsys.com>
    Re: searching an arrey <joe+usenet@sunstarsys.com>
    Re: use() versus import() changing semantics? <tinamue@zedat.fu-berlin.de>
    Re: use() versus import() changing semantics? <Tassilo.Parseval@post.rwth-aachen.de>
    Re: Yet another regex question <jasper@guideguide.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Tue, 28 Aug 2001 13:49:43 GMT
From: 194.203.212.8 [demerphq@hotmail.com]
Subject: Re:  Java mucks up split
Message-Id: <XjNi7.1385$3x.4984@news.bc.tac.net>

> Those Java folks at Sun seem to have trouble getting it right, even
> when it's already been done for them.  They've added regexps and
> "split" to Java 1.4, but the split doc
> http://java.sun.com/j2se/1.4/docs/api/java/util/regex/Pattern.html
> says
> 
> The input "boo:and:foo", for example, yields the following results
> with these parameters:
> 
> Regex    Limit    Result
>    :        2     { "boo", "and" }
> 
> That's just dumb, and misses the whole point of the limit.  This is
> going to lead to confusion and cause some people to think that Perl is
> just as broken, since Java's split is taken from Perl.  What can be
> done to get Sun to do it right?

Why do you want Sun to get it right?  Aren't you a perler?  

Yves



==================================
Poster's IP address: 194.203.212.8
Posted via http://nodevice.com
Linux Programmer's Site


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

Date: Tue, 28 Aug 2001 14:09:11 GMT
From: 194.203.212.8 [demerphq@hotmail.com]
Subject: Re:  Re: A bit of expaination of caller() please
Message-Id: <bCNi7.1386$3x.4902@news.bc.tac.net>

> According to Stan Brown <stanb@panix.com>:
> > How can I use caller() to print out the current callstack? All of it thta
> > is?
> 
>     my $i = 0;
>     while ( @context = caller( $i++) {
>         print "$i: @context\n";
>     }

Or you could go a different way:

use Carp;

my $stacktrace=Carp::longmess; # put me into the sub...

But that would be from the callers perspective...

I hacked this out of Carp::Heavy a while back:

use overload;

sub stacktrace {
	#this is taken almost verbatum from Carp::Heavy::longmess_heavy
    no strict;
    no warnings;
    return @_ if ref $_[0];
    my $error = join '', @_;
    my $mess = "";
    my $i = 0;
    my @stack;
    my ($pack,$file,$line,$sub,$hargs,$eval,$require);
    my (@a);
    #
    # crawl up the stack....
    #
    while (do { { package DB; @a = caller($i++) } } ) {
	# get copies of the variables returned from caller()
	($pack,$file,$line,$sub,$hargs,undef,$eval,$require) = @a;

        # Build a string, $sub, which names the sub-routine called.
	# This may also be "require ...", "eval '...' or "eval {...}"
	    if (defined $eval) {
		if ($require) {
		    $sub = "require $eval";
		} else {
		    $eval =~ s/([\\\'])/\\$1/g;
		    if ($MaxEvalLen && length($eval) > $MaxEvalLen) {
			substr($eval,$MaxEvalLen) = '...';
		    }
		    $sub = "eval '$eval'";
		}
	    } elsif ($sub eq '(eval)') {
		$sub = 'eval {...}';
	    }
	    # if there are any arguments in the sub-routine call, format
	    # them according to the format variables defined earlier in
	    # this file and join them onto the $sub sub-routine string
	    if ($hargs) {
		# we may trash some of the args so we take a copy
		@a = @DB::args;	# must get local copy of args
		# don't print any more than $MaxArgNums
		if ($MaxArgNums and @a > $MaxArgNums) {
		    # cap the length of $#a and set the last element to '...'
		    $#a = $MaxArgNums;
		    $a[$#a] = "...";
		}
		for (@a) {
		    # set args to the string "undef" if undefined
		    $_ = "undef", next unless defined $_;
		    if (ref $_) {
			# force reference to string representation
			$_ = overload::StrVal($_);
			s/'/\\'/g;
		    }
		    else {
			s/'/\\'/g;
			# terminate the string early with '...' if too long
			substr($_,$MaxArgLen) = '...'
			    if $MaxArgLen and $MaxArgLen < length;
		    }
		    # 'quote' arg unless it looks like a number
		    $_ = "'$_'" unless /^-?[\d.]+$/;
		    # print high-end chars as 'M-<char>'
		    s/([\200-\377])/sprintf("M-%c",ord($1)&0177)/eg;
		    # print remaining control chars as ^<char>
		    s/([\0-\37\177])/sprintf("^%c",ord($1)^64)/eg;
		}
		# append ('all', 'the', 'arguments') to the $sub string
		$sub .= '(' . join(', ', @a) . ')';
	    }
	    # here's where the error message, $mess, gets constructed
	    unshift @stack,"$sub $error at $file line $line".
	    		((defined &Thread::tid)
	    		  ? " thread ". Thread->self->tid
			  : "");


	}
    join ("\n",@stack) || "No stack at toplevel...\n";
}

sub root {&child}
sub child {&grandchild}
sub grandchild {&stacktrace}
print root("Stacktrace");

Yves




==================================
Poster's IP address: 194.203.212.8
Posted via http://nodevice.com
Linux Programmer's Site


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

Date: Tue, 28 Aug 2001 13:43:10 GMT
From: 194.203.212.8 [demerphq@hotmail.com]
Subject: Re:  Re: CODE reference to member function of package Confusing..
Message-Id: <OdNi7.1384$3x.4991@news.bc.tac.net>

> According to Yves Orton <demerphq@hotmail.com>:
> > nobull@mail.com wrote in message news:<u9snemzxuk.fsf@wcl-l.bham.ac.uk>...
> > 
> > > Komtanoo  Pinpimai <romerun@greezi.com> writes a question from the FAQ's..
> > > So your question is "How can I pass a method?".
> > 
> > > This is a FAQ: "How can I pass/return a {Function, FileHandle, Array,
> > > Hash, Method, Regex}?"
> > 
> > > > what should I do?
> > > > suggestion please...
> > 
> > > I suggest that what you should do is check the FAQ before posting to
> > > Usenet.
> > 
> > Just curious nobull, but do you think that after this comment CLPM
> > will magically become free of newbies asking questions from the FAQ?
>  
> Why do you assume he expects that?  You probably never sweep your
> floor because that doesn't magically make it dust-free forever.

I would buy this if the OP had posted a bunch of FAQ questions.  But just one?  And no I never sweep.  Hoovers are much easier. :-)

> > Also did it occur to you that perhaps his English is maybe not native?
> > And that therefore reading/searching the faqs might not be so easy? 
> > (Oh wait, the concept of not speaking English comes hard as hard to
> > Brits as to Septic Tanks doesnt it....)
> 
> So fuckin what?  Are you saying clpm is easier to read than the Perl FAQ?

Yes. Its easier to write a pointed question and then read the replies. The perl FAQs are organised in such a way that it is not entirely obvious where to look for a given question unless you had read through a big chunk of them at least once before.  I mean does objectively is 'Perl Language Issues' a title that strongly suggests that it is the doc to read in this case?  Maybe im think (probably actually) but it didnt to me. (I looked elsewhere first.)

OTOH I wouldnt have said anything if the reply had been very simply 

perldoc -q Method

> Yes, it's a handicap when your first language isn't English.  A few of
> us have to live with that.  

For me its a handicap that my first language isn't Deutsch.

:-)

I suppose my reply was written from that point of view.

>It applies to clpm as well as the FAQ and
> a lot of documentation.  I you want to program, you need access to the
> resources, no matter what.  Better get used to it.

I am used to it.  I do tend to look things up.  I dont tend to post many questions, in fact I try to contributemore answers (or at least my best attempt) than questions. (As you know)  The point is that while the nettetiquette is 'RTFM first!' there is also normal human etiquette, something like 'do unto others as you would have them do to you'.  I believe most people dislike uncalled for snarky answers so why give em?
 
> > Ive seen the tagline that is attributed to you, the one about this
> > being a discussion forum and answering questions is purely incidental.
> >  Good comment.  But heres one for you:
> > 
> > If you dont like the fact that someone is asking questions that you'd
> > rather not answer, THEN DONT! Dont bitch, and don't answer.
> 
> FAQ questions are easy to answer.  These are questions that we'd rather
> not *see* in the first place.  This being a high-volume news group
> makes the sheer number relevant.
>
> The quality of a news group depends on the vigilance of its regulars.

Agreed.  And a bunch of regulars replied, *without* abusing the OP.  
Dont you think that generally it is nicer to start off nice?
 
Cheers Anno,
Yves


==================================
Poster's IP address: 194.203.212.8
Posted via http://nodevice.com
Linux Programmer's Site


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

Date: Tue, 28 Aug 2001 09:23:47 -0500
From: Mr Sunblade <djberge@uswest.com>
Subject: Re: 4th ed of the Camel?
Message-Id: <3B8BA973.214973F8@uswest.com>

"Rob - Rock13.com" wrote:

>
>
> LOL. I bought the 2nd camel shortly before the 3rd came out, so I
> have them both dogeared and well used. You might check eBay before
> buying new--if that is an option.

You'll find lots of good deals on half.com as well if you don't mind
used books.  For new books, use bestbookbuys.com, though more often than
not I resort to bookpool.com for most of my computer book needs.

Regards,

Mr. Sunblade


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





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

Date: Tue, 28 Aug 2001 07:44:32 -0700
From: John Callender <jbc@west.net>
Subject: Re: Adding a html break tag at eol in text...
Message-Id: <3B8BAE50.4138A896@west.net>

"Matt L." wrote:

> I need a snippet of
> code (or some guidance 80) that reads in the text from the aforementioned
> textarea and inserts a html <br> tag wherever the end of line character is
> encountered.

[snip]

> Does it make any difference that the CGI runs on Linux and the textarea is
> edited on a Win32 based system?

Yes, it does, since the two systems have different ideas about
what an "end of line" sequence consists of.

If I were sure that the code would never have to handle any but
Win32-based input, I might try something like this:

$text =~ s{\r\n}{<BR>\n}g;

Otherwise, I'd probably split it into two steps, like this:

$text =~ s{\r\n?}{\n}g;
$text =~ s{\n}{<BR>\n}g;

-- 
John Callender
jbc@west.net


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

Date: 28 Aug 2001 09:40:29 -0500
From: "Jason B. Swaim" matalo(at)ev1.net
Subject: Beginner PERL Book
Message-Id: <3b8bad5d_1@newsa.ev1.net>


Can someone tell me which is the "best" beginner PERL book out there? I have
taken a 2 day course for PERL where they shoved quite a bit of info and am
having a hard time remembering anything at all...I want to start from the
basics. I bought two books. PERL Annotated Archives and PERL from the ground
up.

Or should I just go to a university and take the time to learn?
Thank you,
Jason B. Swaim


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

Date: Tue, 28 Aug 2001 14:55:52 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Beginner PERL Book
Message-Id: <35cnotcfir9ff3u9int1cf8jq1hh1hoe9m@4ax.com>

Jason B. Swaim matalo wrote:

>Can someone tell me which is the "best" beginner PERL book out there? I have
>taken a 2 day course for PERL where they shoved quite a bit of info and am
>having a hard time remembering anything at all...

"Learning Perl" from Randal Schwartz is very good, IMO. There's a
Windows specific version, too. Check out <http://learn.perl.org> for
more tips.

-- 
	Bart.


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

Date: Tue, 28 Aug 2001 16:59:40 +0200
From: =?ISO-8859-1?Q?Thomas_B=E4tzler?= <Thomas@Baetzler.de>
Subject: Re: Beginner PERL Book
Message-Id: <b7cnotonhqa0phpdijmcqbqumr0sllq86u@4ax.com>

On 28 Aug 2001, "Jason B. Swaim" matalo(at)ev1.net wrote:
>Can someone tell me which is the "best" beginner PERL book out there? I have
>taken a 2 day course for PERL where they shoved quite a bit of info and am
>having a hard time remembering anything at all...I want to start from the
>basics. I bought two books. PERL Annotated Archives and PERL from the ground
>up.

"Learning Perl, 3rd. Ed." from O'Reilly - see their catalog page
http://www.oreilly.com/catalog/lperl3/ for more info.

>Or should I just go to a university and take the time to learn?

Either way, it's practise that makes you proficient.

HTH,
-- 
Thomas Baetzler - http://baetzler.de/ - Clan LoL - http://lavabackflips.de/
I am the "ILOVEGNU" signature virus. Just copy me to your signature.
This post was infected under the terms of the GNU General Public License.


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

Date: Tue, 28 Aug 2001 07:57:36 -0600
From: "justme" <none@westriv.com>
Subject: changing users within a perl script
Message-Id: <ton8qjklc2mbd4@corp.supernews.com>

I'm new to programming in perl, so this may be an easy question.  I have a
program that I need to run as a certain user.  Does anyone know how to
switch to a different user or run a program as a different user within a
perl script?

Thanks
Doug




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

Date: Tue, 28 Aug 2001 23:42:25 +1000
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: Checking entries in a CSV file....?
Message-Id: <slrn9on7u1.3ga.mgjv@martien.heliotrope.home>

On 28 Aug 2001 03:57:02 -0700,
	Pete Sohi <amanpreet.sohi@sbs.siemens.co.uk> wrote:
> Calling all code warriors!
> 
> Does anyone know how to process (e.g. open and count the number of
> records in) a CSV file?

That depends on what you believe is allowed in a CSV file. Some fairly
loose standards allow newlines inside double quoted fields. Most don't.

> Presumably this is somewhat more complicated than simply counting the
> number of lines in a normal txt file....?

If you don't allow newlines, except as record separators, then you can
just count the number of lines. otherwise, you'll have to parse.

Martien
-- 
Martien Verbruggen              | Since light travels faster than
Interactive Media Division      | sound, isn't that why some people
Commercial Dynamics Pty. Ltd.   | appear bright until you hear them
NSW, Australia                  | speak?


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

Date: Tue, 28 Aug 2001 14:56:58 +0100
From: James Coupe <james@zephyr.org.uk>
Subject: Re: Checking entries in a CSV file....?
Message-Id: <riQa1rUqM6i7Ewjp@gratiano.zephyr.org.uk>

In message <3B8B0E4A.6DFEBE0D@ce.gatech.edu>, Robert Sherman
<rsherman@ce.gatech.edu> writes
>nope. just count the record seperators...you can set $/ to whatever you
>are using as a separator, if it is not a newline.

How many records will your method tell me if I give it the line:

        1,blue,"2, Orange Road",9.9

?

Using either Jeffrey Friedl's nice regex or a CSV module (of which there
are many on CPAN) strikes me as a somewhat better solution.

-- 
James Coupe                                                PGP Key: 0x5D623D5D
Close your eyes so you don't feel them                           EBD690ECD7A1F
They don't need to see you cry                                   B457CA213D7E6
I can't promise I will heal you, but if you want to I will try  68C3695D623D5D


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

Date: Tue, 28 Aug 2001 14:10:34 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Checking entries in a CSV file....?
Message-Id: <6f9not8hkk7jgk90pvmkl5b5nkuj3kl315@4ax.com>

James Coupe wrote:

>How many records will your method tell me if I give it the line:
>
>        1,blue,"2, Orange Road",9.9
>
>?

One.

The problem is that some fields MAY contain newlines, if they are
quoted:

	1,blue,"2, Orange Road",9.9,"seven and
  	a half"

That's one record.

Parsing with Text::CSV_XS, or possibly with Text::CSV, that seems the
simplest to me.

-- 
	Bart.


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

Date: Tue, 28 Aug 2001 15:17:17 +0100
From: James Coupe <james@zephyr.org.uk>
Subject: Re: Checking entries in a CSV file....?
Message-Id: <qSBapjVtf6i7EwAF@gratiano.zephyr.org.uk>

In message <6f9not8hkk7jgk90pvmkl5b5nkuj3kl315@4ax.com>, Bart Lateur
<bart.lateur@skynet.be> writes
>James Coupe wrote:
>>How many records will your method tell me if I give it the line:
>>
>>        1,blue,"2, Orange Road",9.9
>
>One.

Given the original poster's thoughts about counting lines, I assumed
that he may have been wanting to count individual items.

-- 
James Coupe                                                PGP Key: 0x5D623D5D
Close your eyes so you don't feel them                           EBD690ECD7A1F
They don't need to see you cry                                   B457CA213D7E6
I can't promise I will heal you, but if you want to I will try  68C3695D623D5D


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

Date: Tue, 28 Aug 2001 14:22:18 GMT
From: helgi@NOSPAMdecode.is (Helgi Briem)
Subject: Re: form post to https server, best method
Message-Id: <3b8ba77a.3131285610@news.isholf.is>

On 27 Aug 2001 15:09:19 +0100, nobull@mail.com wrote:

>"Nitin G" <niting@onebox.com> writes:
>
>> am looking at implementing a solution where I need to post some data to a
>> https server. Before I went down a path that led to nowhere, I wanted to get
>> input from people who might have implemented a similar solution. What's the
>> best recommended module to use for handling such a situation?
>
>It's far from perfect but I'd still use LWP.  
>
>Setting up HTTPS support for LWP can be fiddly - in particular I've
>seen a lot of posts saying it's difficult on Win32 (not that I've ever
>tried). 

No, it is very easy.  Example below using
the Helsinki University HTTPS server (BTW,
I am running this under Win32).


use strict;
use LWP::UserAgent;
use Crypt::SSLeay;

my $url = 'https://www.helsinki.fi/';
my $proxy = 'http://proxy.domain.com:666';

my $ua = LWP::UserAgent->new;
$ua->proxy(['http'] => $proxy);

my $req = HTTP::Request->new(GET => $url);
my $res = $ua->request($req);

if ($res->is_success) {
  print $res->as_string;
} else {
print "Failed: ", $res->status_line, "\n";
}

__END__

Regards,
Helgi Briem


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

Date: Tue, 28 Aug 2001 13:57:03 GMT
From: Little Pussy <bemsha@midsouthSPAM.rr.com>
Subject: Re: fwd: Sex or perl?
Message-Id: <MPG.15f55f32eaffe2e2989888@news-server.midsouth.rr.com>

In the Ancient Tome of " <awHi7.314535$Do6.14289690@nnrp4.clara.net> ", 
Listy The Feeble said... 

> 
> "Little Pussy" <bemsha@midsouthSPAM.rr.com> wrote in message
> news:MPG.15f494d3947d4537989885@news-server.midsouth.rr.com...
> > In the Ancient Tome of " <Pine.LNX.4.21.0108271444490.12574-100000
> > @bdslppp62.spkn.uswest.net> ", Brian A. Stumm The Feeble said...
> >
> > > On Mon, 27 Aug 2001, Little Pussy wrote:
> > >
> > > > In the Ancient Tome of " <slrn9olq0v.jqr.trammell@haqq.hypersloth.net> ",
> > > > John J. Trammell The Feeble said...
> > > >
> > > > > On Mon, 27 Aug 2001 12:50:40 -0700, Brian A. Stumm <bs@bs-linux.com> wrote:
> > > > > > I'm the Brain. I do everything right...
> > > > >
> > > > > +10 points for pro-GNU .sig
> > > > > -10000 points for 18-line .sig
> > > > >
> > > > > http://www.math.fu-berlin.de/~guckes/afw/
> > > > >
> > > >
> > > > Yeah! Brain is so thoughtless!
> > > >
> > > >
> > > Well then that's -11,666.66* points for you Bemsha.
> > >
> > > *mathematical equation based on the fact that 18 line sig equals negative
> > > 10,000 points.
> > >
> >
> > Oh yeah? Well, that was another -10,000 for you!
> 
> Can I have some points?
> 

:o\

if you insist.

/gets out largest file

this may hurt a bit...

-- 
Bemsha - Now You Know.®
Professor, Human Search Engine Mechanics,
University of Pants

"Hentai porn anime should not require explication. If I have to tell you, 
then Google isn't doing it's job." - Mark Morford

"It just over the next dune, I swear to God!" -- Moses

"Nothing will benefit human health and increase the chances for survival 
on Earth as much as the evolution to a vegetarian diet." -- Albert 
Einstein

I love little pussy,
His coat is so warm,
And if I don't hurt him,
He'll do me no harm.
I'll sit by the fire
And give him some food,
And pussy will love me
Because I am good. 


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

Date: Tue, 28 Aug 2001 10:03:02 -0500
From: cheng huang <cheng@cs.wustl.edu>
Subject: how to do 'c' - 'a' = 2 in perl?
Message-Id: <9mgboi$kkq$1@newsreader.wustl.edu>

Say I have a $letter variable and want to know what it is exactly, can sb. 
get some advice? Thanks.

-- Cheng


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

Date: Tue, 28 Aug 2001 23:35:41 +1000
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: how to get named constants in Perl
Message-Id: <slrn9on7hd.3ga.mgjv@martien.heliotrope.home>

On 28 Aug 2001 03:51:25 -0700,
	Randal L. Schwartz <merlyn@stonehenge.com> wrote:
>>>>>> "Martien" == Martien Verbruggen <mgjv@tradingpost.com.au> writes:
> 
>Martien> use const PI => 4 * atan2(1, 1);
> 
> Why the 4?  Why not just pick the right x,y?
> 
> use constant PI => atan2(0,-1);
> 
> print "Just another Perl hacker," if PI < 3.2;

Just because I've used that rule for so long that I can't even remember
anymore where I got it from. Probably from maths in high school. It's
easier to remember (visually, with the unity circle) that the tangent of
1/4 pi is 1, than any other rule.

Martien
-- 
Martien Verbruggen              | My friend has a baby. I'm writing
Interactive Media Division      | down all the noises the baby makes so
Commercial Dynamics Pty. Ltd.   | later I can ask him what he meant -
NSW, Australia                  | Steven Wright


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

Date: Tue, 28 Aug 2001 23:38:24 +1000
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: how to get named constants in Perl
Message-Id: <slrn9on7mg.3ga.mgjv@martien.heliotrope.home>

On 28 Aug 2001 13:34:31 +0200,
	Peter J. Acklam <jacklam@math.uio.no> wrote:
> 
>> Peter J. Acklam <jacklam@math.uio.no> wrote:
>> 
>> > merlyn@stonehenge.com (Randal L. Schwartz) wrote:
>> >
>> > > >>>>> "Martien" == Martien Verbruggen <mgjv@tradingpost.com.au> writes:
>> > > 
>> > > Martien> use const PI => 4 * atan2(1, 1);

>> >  sub PI () { 4 * atan2 1, 1 }      # As good as it gets,
>> >
>> > > use constant PI => atan2(0,-1);
>> >
>> > Sure, but this isn't suggested anywhere in the docs.
>> 
>> So?
> 
> So, that's probably why he used "4 * atan2(1, 1)" rather than
> "atan2(0,-1)".
> 
> It's documented, it works, so he probably didn't think much more
> about it.

Just to cut this short: I didn't even know this was in the
documentation. I've used this calculation of pi for longer than Perl has
existed :). It's the logical conclusion to draw from the fact that the
tangent of 1/4 pi is 1.

Martien
-- 
Martien Verbruggen              | 
Interactive Media Division      | Hi, Dave here, what's the root
Commercial Dynamics Pty. Ltd.   | password?
NSW, Australia                  | 


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

Date: 28 Aug 2001 07:18:34 -0700
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: Java mucks up split
Message-Id: <m1pu9gl139.fsf@halfdome.holdit.com>

>>>>> "Trewth" == Trewth Seeker <trewth_seeker@yahoo.com> writes:

Trewth> Those Java folks at Sun seem to have trouble getting it right, even
Trewth> when it's already been done for them.  They've added regexps and
Trewth> "split" to Java 1.4, but the split doc
Trewth> http://java.sun.com/j2se/1.4/docs/api/java/util/regex/Pattern.html
Trewth> says

Trewth> The input "boo:and:foo", for example, yields the following results
Trewth> with these parameters:

Trewth> Regex    Limit    Result
Trewth>    :        2     { "boo", "and" }

Trewth> That's just dumb, and misses the whole point of the limit.  This is
Trewth> going to lead to confusion and cause some people to think that Perl is
Trewth> just as broken, since Java's split is taken from Perl.  What can be
Trewth> done to get Sun to do it right?

It's worse than that.  The java regex library I saw (there's more than
one, apparently) returns a separate memory value for *each* *capture*,
not *each* definition.  So in this instance (looking for the last word
in a span of word/spaces):

        "foo bar bletch, fred barney" =~ /^(\w+\s)+(\w+)/

you'd have to look at $3, not $2 to find bletch, but in

        "ho ho ho santa, merry christmas!" =~ /^(\w+\s)+(\w+)/

the interesting string is now in $4!  Argh!

And since non-capturing parens are not available, there are some
strings you just cannot parse reliably as you can in Perl.  Argh.
They just didn't "get it" about why the $n count has to be
compile-time based, not runtime based.  Apparently, they didn't ask
the Perl'ers. :)

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: Tue, 28 Aug 2001 08:52:32 -0500
From: Scott Yanoff <yanoff@yahoo.com>
To: Etienne Pelaprat <etienne@hci.ucsd.edu>
Subject: Re: Keeping files open
Message-Id: <3B8BA220.EDE6F1FF@yahoo.com>

Etienne Pelaprat wrote:
> 
> Hi,
> 
> I would like to write a perl script which constantly reads from
> /var/log/maillog, but I'm having trouble figuring out how I can open
> it up and not have it close when it reaches the end of the file.
> Instead, when it reaches the end, I want it to wait until a new line
> gets entered into /var/log/maillog which I can then parse.  Basically,
> how do I write a perl script that does what the command $> tail -f
> /var/log/maillog does?

Perl Power Tools implementation of the tail command:
http://language.perl.com/ppt/src/tail/index.html
There is a subroutine in their code called "tail_f" that you might want
to look at.

Good luck,
-- 
-Scott
yanoff@yahoo.com | http://www.yanoff.org | AOL IM: SAY KJY


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

Date: Tue, 28 Aug 2001 10:48:55 -0400
From: Joseph Hasting <hasting@agere.com>
Subject: Re: Perl number conversion Utilities
Message-Id: <3B8BAF57.D67445DE@agere.com>

Look.  I hate being like you people and submitting pointless entries to
this newsgroup, but you people need to realize that these subroutines
will translate a decimal number into a hexidecimal number, period. Put
them in a script,  if you have a hexidecimal variable, the subroutine
will return the hexideciaml version, THAT IS THE POINT OF THE
SUBROUTINES!!! I don't care what you want to call the subroutines. 

I originally made this post to help people (who actually do PERL work
rather than make pointless semantic complaint posts to this newsgroups)
by having all of the conversion subroutines together, not to have some
people complain about the name of the routines. If you people want to
sound smart by flooding the newsgroup with semantics complaints, GOTO
ANOTHER NEWSGROUP.
J


"Randal L. Schwartz" wrote:
> 
> >>>>> "Peter" == Peter J Acklam <jacklam@math.uio.no> writes:
> 
> Peter> merlyn@stonehenge.com (Randal L. Schwartz) wrote:
> >> But those aren't "dec2hex", "hex2dec" and so on.  Those are
> >> "num2hex" and "hex2num", and so on.
> 
> Peter> Since they are all limited to dealing with integers, I prefer
> Peter> "int2hex", "hex2int", etc.
> 
> Ooh yes.  Thank you.  I'll add that to the Stamp Out dec2hex Crusade FAQ. :)
> 
> --
> 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: Tue, 28 Aug 2001 15:19:19 +0200
From: "Jens Luedicke" <jens@irs-net.com>
Subject: pipe, fork and Gtk+
Message-Id: <pan.2001.08.28.15.19.19.449.12125@irs-net.com>

hi ...

Is there a safe way of exiting a child process
that has been created by an Perl/Gtk+ based parent process?

I used the 'pipe2' example from the Cookbook and when
I try to exit the child process the parent will exit/die.

How can I avoid this? 

jens


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

Date: Tue, 28 Aug 2001 09:21:48 -0500
From: Mr Sunblade <djberge@uswest.com>
Subject: Re: searching an arrey
Message-Id: <3B8BA8FC.D7C403AA@uswest.com>

nathan wrote:

> how can i search an arrey for a word, and show the whole line that it's on .
> the word can be any where on the line

foreach my $line (@array){
   if($line =~ /^(.*?word_to_be_searched_for.*?)$/){ print $1 }
}

Regards,

Mr. Sunblade

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





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

Date: 28 Aug 2001 10:23:10 -0400
From: Joe Schaefer <joe+usenet@sunstarsys.com>
Subject: Re: searching an arrey
Message-Id: <m3pu9gqn5d.fsf@mumonkan.sunstarsys.com>

"nathan" <michealo@ozemail.com.au> writes:

> how can i search an arrey for a word, and show the whole line that it's on .
> the word can be any where on the line

  print grep index($_,$word)>=0, @array;


-- 
Joe Schaefer    "The important thing is not to stop questioning. Curiosity has
                                its own reason for existing."
                                               --Albert Einstein



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

Date: 28 Aug 2001 11:02:50 -0400
From: Joe Schaefer <joe+usenet@sunstarsys.com>
Subject: Re: searching an arrey
Message-Id: <m3lmk4qlb9.fsf@mumonkan.sunstarsys.com>

Joe Schaefer <joe+usenet@sunstarsys.com> writes:

> "nathan" <michealo@ozemail.com.au> writes:
> 
> > how can i search an arrey for a word, and show the whole line that
> > it's on . 
> > the word can be any where on the line
> 
>   print grep index($_,$word)>=0, @array;

Or maybe

  print grep /\b \Q$word\E \b/x, @array;

depending on whether you really want "word" matches, or just 
substring matches. See

  % perldoc -f grep
  % perldoc perlre

for details.

-- 
Joe Schaefer             "Life is just one damn thing after another."
                                               --Mark Twain



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

Date: 28 Aug 2001 13:08:09 GMT
From: Tina Mueller <tinamue@zedat.fu-berlin.de>
Subject: Re: use() versus import() changing semantics?
Message-Id: <9mg53p$22lto$2@fu-berlin.de>

hi,

Kristian Fischer <kristian.fischer@koehlershohn.de> wrote:

> Tassilo von Parseval wrote:
>> 
>> Kristian Fischer wrote:
>> 
>> > perl -e '$var = 1; unless($var){ use URI::Find; } print $@ if($@);'
>> >
>> > The use statement is *allways* executed at compile-time.
>> 
>> Yes, and this was my problem since I looked for a way to include
>> URI::Find at runtime depending on whether the box has this module
>> installed. It seems to work the way Tina suggested: Putting require into
>> a BEGIN-block. In case of failure I now set a global-variable that is
>> later checked when the method is invoked.
>> 
>> I think URI::Find::find_uris should change its function parameter
>> profile from (\$&) to ($&) where there first parameter would have to be
>> an explicit scalar-ref.

> AFAIK this is the right way:

> eval { require URI::Find; import URI::Find; }
> if($@){
>   # error
> }else{
>   # do it
> }

> so you'll not run in problems later.

hm, if i do this:
require URI::Find;import URI::Find qw(find_uris);
print find_uris($test,$code);
i also get the error message
Can't use string ("test") as a SCALAR ref while "strict refs"
    in use at /usr/lib/perl5/site_perl/5.6.0/URI/Find.pm line 124.

but as i said in my other post, maybe there's a possibility to not
use find_uris() because it's deprecated...
regards,
tina
-- 
http://www.tinita.de \  enter__| |__the___ _ _ ___
tina's moviedatabase  \     / _` / _ \/ _ \ '_(_-< of
search & add comments  \    \ _,_\ __/\ __/_| /__/ perception
---   Warning: content of homepage hopelessly out-dated   ---


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

Date: Tue, 28 Aug 2001 15:22:14 +0200
From: Tassilo von Parseval <Tassilo.Parseval@post.rwth-aachen.de>
Subject: Re: use() versus import() changing semantics?
Message-Id: <3B8B9B06.7060706@post.rwth-aachen.de>

Tina Mueller wrote:

> well, the author says, that find_uris() is deprecated, so you
> shouldn't use it at all. maybe you can do the same using
> find() and other methods, but i haven't looked into the
> docs too much...

Uaah, great! I just checked my version, it was 0.04...subsequently there 
was no mentioning of deprecation. A quick glance into the docs of the 
current version tells me that find() should be able to do the same as 
find_uris. And moreover: it is find(\$string) now. :-)

But now that I fixed it with the old one I'll stick with it. For I might 
not be the only one having an old URI::Find.

Tassilo

-- 
$a=[(74,116)];$b=[($a->[1]-1,$a->[1]++,0x20)];$c=[(97,110)];$d=[($c->
[1]+1,$b->[1],"her")];for(@{[$a,$b,$c,$d]}){for(@{$_}){$_=~/\d+/?print
(chr($_)):print;}}$c=sub{$l=shift;[(0x20+$l-1,0x50,0x65,0x73-0x01,108
),(0x20,0x68,0x61,)]};print(map{chr($_)}@{($c->(1))});$h={a=>33*3,b=>
10**2+7,c=>"1"."0"."1",d=>0162};@h=sort(keys(%$h));for(@h){print(chr(
ord(chr($h->{$_}))))};



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

Date: Tue, 28 Aug 2001 15:28:39 +0100
From: Jasper McCrea <jasper@guideguide.com>
Subject: Re: Yet another regex question
Message-Id: <3B8BAA97.66532B80@guideguide.com>

Kira scrawled:
> 
> Randal L. Schwartz wrote:
> 
> > >>>>> Wyzelli wrote:
> > > Stan Brown wrote:

snip

> Well, there are lots of options when clear, concise and coherent
> parameters are provided. The author provided stereotypical
                                                            ^^
> incoherent gibberish parameters.
            ^
> 
Commas? 'Gibberish' is a noun, not an adjective.

> * not surprised seventy-five percent of high school students *
>   *  do not read nor write at an acceptable skill level *

Hey, that's what they're in school for.

snip
 
> This one below my signature does it a little more efficiently
> but not as stylish as your method and, not quite with the
   (is)    or      (-ly)            ^^^^ no need for comma after 'and'
(especially since you haven't got one after 'but' in the same sentence).

Did you mean '...method, _nor_ quite ...'?

> same parameters you set for yourself. My benchmark comparison
                          ^^^ superfluous
> is not truly a valid test with unequal parameters but rather
                            ^^^^ do you mean 'having'?
And should it not be 'different parameters'?

> exemplifies how efficiency can be address when working with
                                         ^^(ed)
> well stated information and well stated parameters.

Ironic that this sentence contains the word 'efficiency'.

> With the orginating author writing an article amounting to
> nothing more than pure gibberish, I have made an assumption
                                                              (that)
> his parenthetical data is single space delimited as shown
     5 syllables - must be a good word! Use it more!       ^ comma(?)
> with multiple spaces not a part of data.
> 
> My experience is, when a participant within this newsgroup
                  ^ comma should be 'that' or ';'
I think one participates _in_, not within.

> writes clear, concise and coherent articles, especially
> pertaining to parameters, efficiency can be well addressed.

Just like this clear, concise and coherent Dilbert-esque paragraph.
 
> Godzilla!  Queen Of High Literacia.

    Queen of pseudo-highbrow,
       using-two-long-words-where-one-short-one-would-do,
       a-little-knowledge-is-a-bad-thing,
       living-in-glass-house-but-still-throwing-stones,
          Literacia, perhaps?
        
But who am I to talk? I got a 'u' (ungradable) in my English Language
'o'-level. Let's say I'm using the 'let he who is without sin bit' here,
not the whole glass houses bag.

Cheery-pip,
Jasper
-- 
      split//,'019617511192'.
      '17011111610114101114'.
      '21011141011840799901'.
            '17101174';
            foreach(0..         # my
            $#_){$_[$_          # signature is too
            ++]^=$_[$_          # bignature
            --]^=$_[$_
]^=$_[++    $_]if!($_%
2)}$g.=$_  ,chr($g)=~
 /(\w)/&&($o.=$1and
   $g='')foreach@_;
      print"$o\n"


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

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


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