[11424] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 5024 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Mar 1 15:07:30 1999

Date: Mon, 1 Mar 99 12:00:47 -0800
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Mon, 1 Mar 1999     Volume: 8 Number: 5024

Today's topics:
    Re: 'x' operator to pre-extend a string <gellyfish@btinternet.com>
    Re: 'x' operator to pre-extend a string <mikeryan@acm.org>
    Re: *** FAQ: ANSWERS TO YOUR QUESTIONS! READ FIRST! Pos <uri@home.sysarch.com>
    Re: *** FAQ: ANSWERS TO YOUR QUESTIONS! READ FIRST! Pos (Jonathan Stowe)
    Re: *** FAQ: ANSWERS TO YOUR QUESTIONS! READ FIRST! Pos <andrewf@beausys.demon.co.uk>
        2x strange behaviour in Perl script <ruedas@geophysik.uni-frankfurt.de>
        @#/s#! Regular Expressions! :o( (Neil Jedrzejewski)
    Re: Add Default Directory to @INC <gellyfish@btinternet.com>
    Re: Array question. (Ronald J Kimball)
    Re: c2perl, awk2perl, sed2perl <gellyfish@btinternet.com>
    Re: Can I do this w/ Perl? (Ken )
    Re: Can I do this w/ Perl? (Ken )
        CDK-Module on RedHat5.2 (Jens Calisti)
    Re: CFSCRIPTS.COM - ColdFusion Resource Site! <gellyfish@btinternet.com>
    Re: Do you really need to do 'open(whatever, ..) or die <baillie@my-dejanews.com>
    Re: Do you really need to do 'open(whatever, ..) or die <jeromeo@atrieva.com>
    Re: does perl discourage obfuscated code? (was Re: Perl (Bart Lateur)
    Re: does perl discourage obfuscated code? (was Re: Perl (I R A Aggie)
    Re: Email from Perl on NT <gellyfish@btinternet.com>
        FAQ 7.19: Why doesn't "my($foo) = E<lt>FILEE<gt>;" work <perlfaq-suggestions@perl.com>
    Re: Forcing data to be a numeric float value <jeromeo@atrieva.com>
        forum program wanted <ulrikestar@hotmail.com>
    Re: Help - regex to extract two fields in "uptime" <gellyfish@btinternet.com>
        how to make a character recognized without "enter" ? <natoofi@dac.neu.edu>
        Special: Digest Administrivia (Last modified: 12 Dec 98 (Perl-Users-Digest Admin)

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

Date: 28 Feb 1999 16:41:33 -0000
From: Jonathan Stowe <gellyfish@btinternet.com>
Subject: Re: 'x' operator to pre-extend a string
Message-Id: <7bbrjt$9m$1@gellyfish.btinternet.com>

On Tue, 23 Feb 1999 00:59:54 +0000 Michael Ryan wrote:
> camel book, 2d ed., page 541:
> "Pre-extending a string with the x operator ..."
> which got me thinking because i couldn't find an example except the $^M
> allocation.
> 
> is the proper syntax pre-extending something like:
> 
> $s = 'a' x ( 1 << 16 )
> $s = ""  # $s is still large
> $s = "first element" . "second element"
> print $s  # which should print "first elementsecond element"
> 
> is it better to tr/a//d the string to clear it?
> 

In the end of the day both achieve the same effect (given your string)
However there obviously are differences - let the the numbers speak for
themselves:


#!/usr/bin/perl
use Benchmark;


sub Assign
{
   $s = 'a' x ( 1 << 16 );
   $s = "";  # $s is still large
}

sub Translate
{
$s = 'a' x ( 1 << 16 );
$s =~ tr/a//d;
}

timethese (1000, {
		                 Translate => \&Translate,
										 Assign    => \&Assign
									 });


gellyfish@gellyfish:/home/gellyfish/clpmtest > extend.pl
Benchmark: timing 1000 iterations of Assign, Translate...
   Assign:     3 wallclock secs ( 2.37 usr +  0.00 sys =  2.37 CPU)
	 Translate:  7 wallclock secs ( 7.67 usr +  0.00 sys =  7.67 CPU)

As you can see using an assignment is far more efficient which stands to
reason as 'tr' will effectively have to touch each of the 65536 characters
in your string.  

Amazingly, and as an aside, the accidental reboot of my machine just now
took a whole second off the times of both methods.

/J\
-- 
Jonathan Stowe <jns@btinternet.com>
Some of your questions answered:
<URL:http://www.btinternet.com/~gellyfish/resources/wwwfaq.htm>
Hastings: <URL:http://www.newhoo.com/Regional/UK/England/East_Sussex/Hastings>


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

Date: Sun, 28 Feb 1999 12:50:46 -0800
From: "Michael J. Ryan" <mikeryan@acm.org>
Subject: Re: 'x' operator to pre-extend a string
Message-Id: <7bc9ps$rs4$1@remarQ.com>

thanks jonathan.  i couldn't figure out if the assignment left the large
memory in place or not.  your message tells me that it does.

cheers
//michael


Jonathan Stowe wrote in message <7bbqgt$63k$1@gellyfish.btinternet.com>...
>On Tue, 23 Feb 1999 00:59:54 +0000 Michael Ryan wrote:
[...setup trimmed...]
>> $s = 'a' x ( 1 << 16 )
>> $s = ""  # $s is still large
>> $s = "first element" . "second element"
>> print $s  # which should print "first elementsecond element"
>>
>> is it better to tr/a//d the string to clear it?
>>
>
>Both of course achieve same reult however there is of course some
>performance difference:
[...nice timing code trimmed...]
>
>gellyfish@gellyfish:/home/gellyfish/clpmtest > extend.pl
>Benchmark: timing 1000 iterations of Assign, Translate...
>    Assign:  2 wallclock secs ( 2.41 usr +  0.01 sys =  2.42 CPU)
> Translate:  8 wallclock secs ( 7.75 usr +  0.02 sys =  7.77 CPU)
>
>So I would suggest you would want to go with the assignment.  It makes
>sense really because 'tr' has to visit each 65536 of the characters in
>the string.
>
>/J\





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

Date: 28 Feb 1999 13:21:04 -0500
From: Uri Guttman <uri@home.sysarch.com>
Subject: Re: *** FAQ: ANSWERS TO YOUR QUESTIONS! READ FIRST! Posted Twice Weekly ***
Message-Id: <x71zjagzjj.fsf@home.sysarch.com>

>>>>> "AF" == Andrew Fry <andrewf@beausys.demon.co.uk> writes:

  AF> This can be condensed as follows...
  AF> "This newsgroup is reserved for use by us Perl experts to discuss
  AF>  *INTERESTING* Perl issues. Dont waste our time by posting uninteresting
  AF>  questions. If you really *MUST* post a question to which you need a
  AF>  quick reply, make sure that you that you first read the FAQ, man pages,
  AF>  articles on the WWW and main Perl books in their entirety, and then
  AF>  sign an affidavit to confirm they you have read all these."

usenet is was never meant for QUICK replies. if you expect that, you get
what you deserve.

  AF> I have to say that I find this really quite patronising.
  AF> By the time a newbiew has done all that is suggested here, Perl
  AF> will have gone out of fashion!

out of fashion for that newbie.

  AF> BTW, I realize the value and importance of a person doing a little
  AF> research and investigation of his own, and the importance of knowing
  AF> what documentation exists and referring to it. Dont get me wrong.
  AF> The key point here is that you have no right whatsoever to tell people
  AF> how to use this newgroup...

we, who don't like to answer FAQ's all day, hereby appoint you (and by
the nature of your post you obviously accept!), to answer all newbie
questions and FAQ's in a timely and accurate manner. congratulations on
your new 24 hour job! i hope you enjoy it, the benefits and pay are
great!

ATTENTION all perl newbies, instead of posting to this group, send you
questions by email to andrew fry, he will answer them all, accurately
quickly and over and over and over and over and over and over and over
and over and ...

have fun,

uri


-- 
Uri Guttman  -----------------  SYStems ARCHitecture and Software Engineering
Perl Hacker for Hire  ----------------------  Perl, Internet, UNIX Consulting
uri@sysarch.com  ------------------------------------  http://www.sysarch.com
The Best Search Engine on the Net -------------  http://www.northernlight.com


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

Date: Mon, 01 Mar 1999 09:49:18 GMT
From: gellyfish@btinternet.com (Jonathan Stowe)
Subject: Re: *** FAQ: ANSWERS TO YOUR QUESTIONS! READ FIRST! Posted Twice Weekly ***
Message-Id: <36da61ec.3282080@news.dircon.co.uk>

On 28 Feb 1999 13:21:04 -0500, Uri Guttman <uri@home.sysarch.com>
wrote:

>>>>>> "AF" == Andrew Fry <andrewf@beausys.demon.co.uk> writes:
>
>  AF> This can be condensed as follows...
>  AF> "This newsgroup is reserved for use by us Perl experts to discuss
>  AF>  *INTERESTING* Perl issues. Dont waste our time by posting uninteresting
>  AF>  questions. If you really *MUST* post a question to which you need a
>  AF>  quick reply, make sure that you that you first read the FAQ, man pages,
>  AF>  articles on the WWW and main Perl books in their entirety, and then
>  AF>  sign an affidavit to confirm they you have read all these."
>
>usenet is was never meant for QUICK replies. if you expect that, you get
>what you deserve.
>

Yeah but Uri he obviously thinks it is:

<http://www.dejanews.com/[ST_rn=ap]/dnquery.xp?search=thread&recnum=%3c882R7JAziLq2EwFK@beausys.demon.co.uk%3e%231/1&svcclass=dnserver>

It appears that Andrew would rather discuss meta-issues than Perl
anyhow by the looks of things.

/J\


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

Date: Mon, 1 Mar 1999 00:43:01 +0000
From: Andrew Fry <andrewf@beausys.demon.co.uk>
Subject: Re: *** FAQ: ANSWERS TO YOUR QUESTIONS! READ FIRST! Posted Twice Weekly ***
Message-Id: <mos2vHAVKe22Ew3W@beausys.demon.co.uk>

In article <x71zjagzjj.fsf@home.sysarch.com>, Uri Guttman
<uri@home.sysarch.com> writes
>>>>>> "AF" == Andrew Fry <andrewf@beausys.demon.co.uk> writes:
>
>  AF> This can be condensed as follows...
>  AF> "This newsgroup is reserved for use by us Perl experts to discuss
>  AF>  *INTERESTING* Perl issues. Dont waste our time by posting uninteresting
>  AF>  questions. If you really *MUST* post a question to which you need a
>  AF>  quick reply, make sure that you that you first read the FAQ, man pages,
>  AF>  articles on the WWW and main Perl books in their entirety, and then
>  AF>  sign an affidavit to confirm they you have read all these."
>
>usenet is was never meant for QUICK replies. if you expect that, you get
>what you deserve.

Where, precisely, does it say that it was never meant for quick
replies ? Or is that just your personal view ? And who are you to
dictate what it is for, and the terms and conditions under which
people might use it ?

>  AF> I have to say that I find this really quite patronising.
>  AF> By the time a newbiew has done all that is suggested here, Perl
>  AF> will have gone out of fashion!
>
>out of fashion for that newbie.
>
>  AF> BTW, I realize the value and importance of a person doing a little
>  AF> research and investigation of his own, and the importance of knowing
>  AF> what documentation exists and referring to it. Dont get me wrong.
>  AF> The key point here is that you have no right whatsoever to tell people
>  AF> how to use this newgroup...
>
>we, who don't like to answer FAQ's all day, hereby appoint you (and by
>the nature of your post you obviously accept!), to answer all newbie
>questions and FAQ's in a timely and accurate manner. congratulations on
>your new 24 hour job! i hope you enjoy it, the benefits and pay are
>great!
>
>ATTENTION all perl newbies, instead of posting to this group, send you
>questions by email to andrew fry, he will answer them all, accurately
>quickly and over and over and over and over and over and over and over
>and over and ...
>
>have fun,
>
>uri

Well, there just isnt any point in replying to stupid comments like
this.

---
Andrew Fry
"Time flies like an arrow. Fruit flies like a banana". (Groucho Marx).


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

Date: Sun, 28 Feb 1999 02:01:40 +0100
From: Thomas Ruedas <ruedas@geophysik.uni-frankfurt.de>
Subject: 2x strange behaviour in Perl script
Message-Id: <36D89574.237C@geophysik.uni-frankfurt.de>

Hello,
I'm writing a Perl script which shall convert database entries of the
following format:
 GEOPHYSICS, 1999 JAN-FEB, V64 N1                         29 citations

   3.1 Kaelin, B; Johnson, LR.
         Using seismic crosswell surveys to determine the aperture of
       partially water-saturated fractures.                pp. 13-23
   3.2 Calvert, AJ; Li, YX.
 ...
to BiBTeX; leading blanks are actually in the database. The crucial sub
is this (sorry for posting such a long thing):
sub makeentry {
    local(@dummy,$imax);
    if ($line =~ /\d\.\d/x) {
# articles: extract authors, title and pages
	@dummy=split(' ',$line);                            #<--
	shift @dummy;
 $imax=($dummy[$#dummy] eq "others.") ? $imax=$#dummy-1 : $imax=$#dummy;
	for ($i=1; $i<=$imax; $i+2) {
	    $dummy[$i]=join(".",(split('',substr($dummy[$i],0,-1))));
	    unless ($i == $imax || $dummy[$i+1] eq "and") {
		$dummy[$i]=join(" ",$dummy[$i],"and");      #<<<--
	    }
	}
	$author=join(" ",@dummy);
	$art_title="";
	while ($line = <INFILE>) {
	    $art_title=join(" ",($art_title,$line));
	    if ($line =~ /pp\./) { last; }
	}
	($art_title,$art_pages)=split("pp. ",$art_title);
	$art_title=~ s/\.\s\s+//;
	$art_pages=~ s/-/--/;
#       build BiBTeX entry
	$lab_el=substr($journal_year,2);
	print JOURNAL "\@ARTICLE{$lab_el,\n";
	print JOURNAL "  AUTHOR = {$author},\n";
#...
	print JOURNAL "  PAGES = {$art_pages}}\n";
    } elsif ($line =~ /citations/x) {
# first list line containing issue information
	$journal_name="";
	@dummy=split(' ',$line);
	foreach(@dummy) {
	    if ($_ =~ /\d\d\d\d/x) {
		$journal_name=substr($journal_name,0,-1);
		$journal_year=$_;
		last;
	    }
	    $journal_name=join(" ",($journal_name,(shift(@dummy))));
	}
	$journal_name=&abbrv(substr($journal_name,1));
	foreach(@dummy) {
	    if ( $_ =~ /^V/ ) {
		$journal_volume=substr($_,1);
	    } elsif ( $_ =~ /^N/ ) {
		$journal_number=substr($_,1);
	    }
	}
    }
}
The 2nd branch of the if block seems to work, while the script hangs
when entering the 1st. Actually, print @dummy; for testing was not
possible after the line marked with #<-- I have the impression that the
split does not work.
Additionally, when invoking perl -cw on the script, I get these
messages:
Useless use of addition in void context at gsi2bib.pl line 40.
Useless use of addition in void context at gsi2bib.pl line 40.
gsi2bib.pl syntax OK
Line 40 is marked with #<<<-- above. What does this mean? I don't see an
addition there!

Any help is greatly appreciated. Please also respond by email, in case
my news server fails.
-- 
--------------------------------------------
Thomas Ruedas
Institute of Meteorology and Geophysics, 
J.W. Goethe University Frankfurt/Main
Feldbergstrasse 47			D-60323 Frankfurt/Main, Germany
Phone:+49-(0)69-798-24949		Fax:+49-(0)69-798-23280
e-mail: ruedas@geophysik.uni-frankfurt.de
http://www.geophysik.uni-frankfurt.de/~ruedas/
--------------------------------------------


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

Date: Mon, 01 Mar 1999 09:57:53 GMT
From: jed@grafx.co.uk (Neil Jedrzejewski)
Subject: @#/s#! Regular Expressions! :o(
Message-Id: <36da64a0.4639890@news.dircon.co.uk>

Hi All,

Can ANYONE help me get my head around this?

I admit now that I am NOT the worlds greatest Perl programmer so I
apologies if I'm being dense straight away.

Heres the problem....

We have a need on our quirky system to read mail from POP3 Mailboxes,
re-address the mail, and pass it on through our SMTP server. Wierd I
know but it has to be this way...

I've written a Perl script in Perl5 that opens the POP3 box (using
MAIL::POP3) reads the header and works out who its going to. This is
fine if the mail has been relayed as it appears at the top of the
message in the Recieved: field.

However, some of the messages don't have this, and as such I need to 
be able to parse the To: field and get all the e-mail addresses from
it, change the domain name and then put them into an array of people
to be mailed to.

First of all, I've covered all the stuff including getting all the
addresses into one variable and stripping out superfluous spaces, etc.

Now the crunch.

I need (I guess) a few lines of code that probably uses a regular
expression that will look at the line, see all the e-mail addresses
and put them into an array.

Although there are a lot of variations to the layout of e-mail
addresses in the line basically they are either seperated by a space,
comma or semi-colon or a combination. Other stuff like less-than,
greater-thans can be stripped later.

Anyone got any ideas/code/thoughts?

I'd appreciate it if you could post replies to Jed@grafx.co.uk as well
as to the group - I've got a dodgy newsfeed.

Thanks and regards

- Jed


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

Date: 28 Feb 1999 20:37:52 -0000
From: Jonathan Stowe <gellyfish@btinternet.com>
Subject: Re: Add Default Directory to @INC
Message-Id: <7bc9f0$np$1@gellyfish.btinternet.com>

On Fri, 26 Feb 1999 18:34:19 -0600 Andrew J. Piziali wrote:
>    I am currently running Perl 5.003 and upgrading to 5.005.  A number
> of installed programs reference modules in /usr/lib/perl5/site_perl.
> When I built Perl 5.005 this directory was excluded; only
> 
> 	/usr/lib/perl5/5.00502/i386-linux
> 	/usr/lib/perl5/5.00502
> 	/usr/lib/perl5/site_perl/5.005/i386-linux
> 	/usr/lib/perl5/site_perl/5.005
> 
> are searched.
> 
>    How do I add /usr/lib/perl5/site_perl to the default @INC search
> path?  I'd like to avoid having to modify the other programs, such as
> those in LWP.pm.
> 

I dont recomend you to do that - you will almost certainly throw up some
niggling incompatibities that you will spend more time fixing than you
would do reinstalling the modules.

/j\

-- 
Jonathan Stowe <jns@btinternet.com>
Some of your questions answered:
<URL:http://www.btinternet.com/~gellyfish/resources/wwwfaq.htm>
Hastings: <URL:http://www.newhoo.com/Regional/UK/England/East_Sussex/Hastings>


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

Date: Sun, 28 Feb 1999 15:27:07 -0500
From: rjk@linguist.dartmouth.edu (Ronald J Kimball)
Subject: Re: Array question.
Message-Id: <1dnxz1s.1sbf9p218x926gN@bay1-187.quincy.ziplink.net>

Ala Qumsieh <aqumsieh@matrox.com> wrote:

> undef()ing an array is not equivalent to clearing "all elements from
> an array". The first solution above leaves the array defined, but with
> no elements. The second solution undefines the array, so trying to
> access @ary in any means will result in a warning. Consult perlfunc
> for more infor on undef().

What does "trying to access @ary in any means will result in a warning"
mean?  Can you really demonstrate differences in behavior of warnings
between using 'undef @ary' and '@ary = ()'?

Whether you undef the array or assign an empty list to it, the array
will be empty.  Anything you do to get a warning with the undefed array
will also give you a warning with the emptied array.


#!perl -w
@ary = (1,2);
undef @ary;
print scalar @ary, " [@ary]\n";
__END__
0 []

No warnings.

-- 
#!/usr/bin/sh -- chipmunk (aka Ronald J Kimball)
    perl -e'for(sort keys%main::){print if $$_ eq 1}
        ' -s  -- -' Just' -' another ' -'Perl ' -'hacker 
' http://www.ziplink.net/~rjk/  [rjk@linguist.dartmouth.edu]


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

Date: 28 Feb 1999 17:02:24 -0000
From: Jonathan Stowe <gellyfish@btinternet.com>
Subject: Re: c2perl, awk2perl, sed2perl
Message-Id: <7bbsr0$ak$1@gellyfish.btinternet.com>

On Sat, 27 Feb 1999 19:47:15 -0800 coyote38 wrote:
> 
> I remember reading about awk2perl and sed2perl once.  I cannot find
> any information about these anywhere on the internet or within CPAN.
> I think they were mentioned in the camel book.
> 

These are a2p and s2p respectively - they are part of the distibutin so if
you have Perl installed on your system then you should have them as well,

> What I am really looking for is c2perl.  Does anyone know where I can
> find such a thing so I don't have to write it myself?
> 

I know of no such beast myself - again there are c2ph and h2xs in the
distribution which respectively convert the #defines in a C header file
to something Perl can use and create a stub XS interface to that defined
in a C header file.

In a way a c2perl translator would not really be a good thing as you will
find that much of the C idiom is unnecessary in Perl - you will find that
much of what one might do with linked lists and plenty of malloc()ing in
C for instance might be better done with Data structures based on Hashes of
Hashes or whatever in Perl.

If you have a particularly large body of C code that you want to use in a
Perl Program then you might want to implement it as an XS based module -
check out the perlxstut manpage for more on this.

/J\
-- 
Jonathan Stowe <jns@btinternet.com>
Some of your questions answered:
<URL:http://www.btinternet.com/~gellyfish/resources/wwwfaq.htm>
Hastings: <URL:http://www.newhoo.com/Regional/UK/England/East_Sussex/Hastings>


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

Date: Mon, 01 Mar 1999 19:22:24 GMT
From: cant_take@thespam.com (Ken )
Subject: Re: Can I do this w/ Perl?
Message-Id: <36dae8c6.6607917@news.tiac.net>

abigail@fnx.com (Abigail) wrote:

>Tad McClellan (tadmc@metronet.com) wrote on MMVII September MCMXCIII in
><URL:news:i1abb7.0mh.ln@magna.metronet.com>:
>-- Ken (cant_take@thespam.com) wrote:
>-- : abigail@fnx.com (Abigail) wrote:
>--
>-- : >Also trivial in Perl. Users aren't Perl driven, they run on hamburgers.
>-- : >Again, Perl can quietly rest while you educate your users to enter events.
>--
>-- : A little cryptic, Abigail.  Are you saying I don't need Perl to have
>-- : users enter data on a web page?  
>--
>-- : How would I do it then?
>--
>--    However, to _do something_ with the data that those users enter,
>--    you _do_ need some sort of CGI program to handle the returned
>--    form values. (but you didn't ask about what to _do_ with the
>--    entered data)
>
>
>You don't even need a program that uses the CGI protocol.
>

It's getting boring, Abigail

Ken


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

Date: Mon, 01 Mar 1999 19:30:38 GMT
From: cant_take@thespam.com (Ken )
Subject: Re: Can I do this w/ Perl?
Message-Id: <36daea62.7019969@news.tiac.net>

For an example of what I want to do see:

http://www.net1plus.com/cgi-bin/socman.pl

When I look at this code i don't see (what I recognize as)  perl
language.  What does the .pl extension mean?  How come when I try to
save this file to my system it wants an html extension?

Ken


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

Date: Mon, 01 Mar 1999 13:27:23 +0100
From: Jens.Calisti@eiskonzept.com (Jens Calisti)
Subject: CDK-Module on RedHat5.2
Message-Id: <Jens.Calisti-0103991327230001@192.168.2.201>

Hi all,

i have a problem installing the CDK-Module from CPAN.

I installed all the libs :

cdk-4.9.6

the curses module.

and finally Cdk.pm

When i try to run one of the example i always get the following error-message :

-----------------------------CUT-----------------------------------
[root@dev examples]# perl label
Can't load '/usr/lib/perl5/site_perl/i386-linux/auto/Cdk/Cdk.so' for
module Cdk: /usr/lib/perl5/site_perl/i386-linux/auto/Cdk/Cdk.so: undefined
symbol: lstat at /usr/lib/perl5/i386-linux/5.00404/DynaLoader.pm line 168.

 at label line 10
BEGIN failed--compilation aborted at label line 10.

----------------------------ENDCUT---------------------------------


This thing is driven me crazy because under SuSE Linux it runs perfectly ?!?!

Thanks & Bye,

Jens Calisti


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

Date: 28 Feb 1999 17:18:24 -0000
From: Jonathan Stowe <gellyfish@btinternet.com>
Subject: Re: CFSCRIPTS.COM - ColdFusion Resource Site!
Message-Id: <7bbtp0$as$1@gellyfish.btinternet.com>

In comp.lang.perl.misc Nektarios Kalogridis <nektarios@home.com> wrote:
> Hi,
> 
> A new Cold Fusion resource web site has been launched called
> CFScripts.com, located at: http://www.cfscripts.com .
> 

I think you must have got this newsgroup confused with another -
ColdFusion is a tool designed (as far as I can determine) for making
Web applications whereas the majority of uses to which Perl is put have
nothing to do with that whatsoever as a cursory examination of this
group would have determined.

/J\
-- 
Jonathan Stowe <jns@btinternet.com>
Some of your questions answered:
<URL:http://www.btinternet.com/~gellyfish/resources/wwwfaq.htm>
Hastings: <URL:http://www.newhoo.com/Regional/UK/England/East_Sussex/Hastings>


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

Date: Mon, 01 Mar 1999 19:01:47 GMT
From: Baillie <baillie@my-dejanews.com>
Subject: Re: Do you really need to do 'open(whatever, ..) or die..'
Message-Id: <7beo6l$vag$1@nnrp1.dejanews.com>

In article <m3lnhhjfxy.fsf@joshua.panix.com>,
  Jonathan Feinberg <jdf@pobox.com> wrote:
> Baillie <baillie@my-dejanews.com> writes:
>
> > It seems as if a program will never die at the open line, but rather
> > at the close line.  Why is that?
>
> Who knows?  What does the error message say?  You've printed out the
> contents of $!, so you've got the answer right in front of you.
>

I guess what I'm asking is, you always see a file being opened like this:

open(FILE, "$myfile") || die "error $!";

Even if the file doesn't exist the die never actually seems to happen, so
what's the point in saying '|| die "error $!";'??

This will never die until you try to close the file, which I find peculiar
because a decent portion of a program has executed unnecessarily.

It's not that I can't figure out how to "-e $file" or whatever, I just don't
understand the practice of saying 'open or die'.

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    


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

Date: Mon, 01 Mar 1999 11:36:04 -0800
From: Jerome O'Neil <jeromeo@atrieva.com>
Subject: Re: Do you really need to do 'open(whatever, ..) or die..'
Message-Id: <36DAEC24.166BAFC9@atrieva.com>

Baillie wrote:
 
> I guess what I'm asking is, you always see a file being opened like this:
> 
> open(FILE, "$myfile") || die "error $!";
> 
> Even if the file doesn't exist the die never actually seems to happen, so
> what's the point in saying '|| die "error $!";'??

More things can go wrong when opening a file than just having the file
not exist.  In fact, the file not existing is usually not a problem. 
What if you don't have permission to open the file?  What if you are out
of disk space?  What if magic elves corrupted the file?

> This will never die until you try to close the file, which I find peculiar
> because a decent portion of a program has executed unnecessarily.

If the file existing is a condition of opening it, check for the
existence of the file *before* you open it.

if(-e $file){ # Does it exist?
	open(FILE, "$file") or die "Unable to open $file: $!";
}else{
	die "File $file does not exist."
}

> It's not that I can't figure out how to "-e $file" or whatever, I just don't
> understand the practice of saying 'open or die'.

Because file I/O is semi-complex, and lots of things can go wrong.  It's
a Good Thing when we know sooner than later.


-- 
Jerome O'Neil, Operations and Information Services
Atrieva Corporation, 600 University St., Ste. 911, Seattle, WA 98101
jeromeo@atrieva.com - Voice:206/749-2947 
The Atrieva Service: Safe and Easy Online Backup  http://www.atrieva.com


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

Date: Mon, 01 Mar 1999 09:21:10 GMT
From: bart.lateur@skynet.be (Bart Lateur)
Subject: Re: does perl discourage obfuscated code? (was Re: Perl evangelism)
Message-Id: <36da595a.2405769@news.skynet.be>

Russell Schulz wrote:

>Perl encourages hard-to-read code.  that's just the
>way it is, and if you don't apply a strong discipline when writing
>Perl, you're going to be the proud owner of a ton of read-only code.

"write-only", but anyway. I don't agree.

Perl does encourage you to write very concise code. When you get more
experience, you find out that you can often write code in one or two
lines, which would require writing a complex, lengthy function in other
languages. At first, this will look intimidating. But it's mostly a
matter of getting used to the idiom. Then, you'll recognize the patterns
("oh, a Schwartzian Transform"), and they'll be readable just fine.

	Bart.


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

Date: 28 Feb 1999 21:25:50 GMT
From: fl_aggie@thepentagon.com (I R A Aggie)
Subject: Re: does perl discourage obfuscated code? (was Re: Perl evangelism)
Message-Id: <slrn7djd7p.o33.fl_aggie@enso.coaps.fsu.edu>

On 28 Feb 1999 00:01:11 -0800, Russ Allbery <rra@stanford.edu> wrote:

+ Actually, among all of the languages that I know, the one that takes the
+ prise for the most generally unreadable language (and it's not even
+ *close*) is FORTRAN, mostly due to the variable naming conventions that
+ most FORTRAN programmers use.

Ah, the legacy of the old IBM days of 'variable names are to be 6
characters or less'. Actually, they could be more, but the compiler
"optimized" the excess away. This meant that such things as:

      integer abcdef123,abcdef321

where the same variable. In my perl coding, I have backlashed away from
such limitations, typically using longish, meaningful names. At least
until I do something like:

$length_of_first_name=length($first_name);

Ok, that's a bit much... :)

+ Perl honestly isn't anywhere near the same ballpark, if you're looking at
+ actual production Perl code.

I have some old FORTRAN IV code laying around. I can post parts, if you
want scary stuff... :)

James


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

Date: 28 Feb 1999 19:28:14 -0000
From: Jonathan Stowe <gellyfish@btinternet.com>
Subject: Re: Email from Perl on NT
Message-Id: <7bc5ce$ln$1@gellyfish.btinternet.com>

On Fri, 26 Feb 1999 12:54:01 +1000 Jaime Metcher wrote:
> There's always "sendmail", of course, but it's not freeware.
> 

Of course 'sendmail' itself is freeware - but there are available 
commercial NT ports that are not.  However there is a port that is
available from Microsoft's ftp site.  I Cant remember the complete
URL but a little poking around should turn it up.

/J\
-- 
Jonathan Stowe <jns@btinternet.com>
Some of your questions answered:
<URL:http://www.btinternet.com/~gellyfish/resources/wwwfaq.htm>
Hastings: <URL:http://www.newhoo.com/Regional/UK/England/East_Sussex/Hastings>


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

Date: 28 Feb 1999 11:33:00 -0700
From: Tom Christiansen <perlfaq-suggestions@perl.com>
Subject: FAQ 7.19: Why doesn't "my($foo) = E<lt>FILEE<gt>;" work right?  
Message-Id: <36d98bdc@csnews>

(This excerpt from perlfaq7 - Perl Language Issues 
    ($Revision: 1.24 $, $Date: 1999/01/08 05:32:11 $)
part of the standard set of documentation included with every 
valid Perl distribution, like the one on your system.
See also http://language.perl.com/newdocs/pod/perlfaq7.html
if your negligent system adminstrator has been remiss in his duties.)

  Why doesn't "my($foo) = <FILE>;" work right?

    `my()' and `local()' give list context to the right hand side of `='.
    The <FH> read operation, like so many of Perl's functions and operators,
    can tell which context it was called in and behaves appropriately. In
    general, the scalar() function can help. This function does nothing to
    the data itself (contrary to popular myth) but rather tells its argument
    to behave in whatever its scalar fashion is. If that function doesn't
    have a defined scalar behavior, this of course doesn't help you (such as
    with sort()).

    To enforce scalar context in this particular case, however, you need
    merely omit the parentheses:

        local($foo) = <FILE>;           # WRONG
        local($foo) = scalar(<FILE>);   # ok
        local $foo  = <FILE>;           # right

    You should probably be using lexical variables anyway, although the
    issue is the same here:

        my($foo) = <FILE>;  # WRONG
        my $foo  = <FILE>;  # right

-- 
    X-Windows: "The first fully modular software disaster.
	--Jamie Zawinski


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

Date: Mon, 01 Mar 1999 11:05:56 -0800
From: Jerome O'Neil <jeromeo@atrieva.com>
To: Chris Beatson <cbeatson@mail.ci.lubbock.tx.us>
Subject: Re: Forcing data to be a numeric float value
Message-Id: <36DAE514.2DB36B9C@atrieva.com>

Use sprintf().  You can format your data to look like anything you
want.  See the perlfunc documentation for all the exciting detail on
formated print statements.  Also, you might try the 'format' man page.

my($formated) = sprintf("%0.2f", $unformated);

Good Luck!


Chris Beatson wrote:
> Is there a way to ensure that these values are floats instead of ints so I
> don't have to worry about rounding. The reason I am forcing them, is because
> sometimes the value may be null in which case it needs to be made 0, or
> preferably 0.0.
> 
> Any suggestions would be appreciated
> Chris Beatson

-- 
Jerome O'Neil, Operations and Information Services
Atrieva Corporation, 600 University St., Ste. 911, Seattle, WA 98101
jeromeo@atrieva.com - Voice:206/749-2947 
The Atrieva Service: Safe and Easy Online Backup  http://www.atrieva.com


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

Date: Sun, 28 Feb 1999 21:01:43 +0100
From: Ulrike <ulrikestar@hotmail.com>
Subject: forum program wanted
Message-Id: <36D9A0A7.A1B8C8B@hotmail.com>

Hi perl experts!

I'm looking for a perl program which allows a threaded discussion
forum on a web page. It would also need to have administration features.
If
anyone out there has seen anything that could help me, shareware or
even  freeware programs, I would really appreciate it. Even any advice
on where I could search further would be great, or which programs are
the best as there are so many out there it gets a bit confusing. Well
thanks very much for listening and I hope to hear from you soon.

Ulrike.





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

Date: 28 Feb 1999 20:11:44 -0000
From: Jonathan Stowe <gellyfish@btinternet.com>
Subject: Re: Help - regex to extract two fields in "uptime"
Message-Id: <7bc7u0$ni$1@gellyfish.btinternet.com>

On Sun, 28 Feb 1999 17:20:25 GMT Ken Gaugler wrote:
> Hello,
> 
> I have a file full of lines of the output from "uptime", from which I would
> like to extract just the time and the 1-minute load average. That is, for
> the line:
> 
>   8:00am  up 23 day(s), 21:34,  7 users,  load average: 0.13, 0.08, 0.09
> 
> I want to extract:
> 
> 8:00am  0.13
> 
> note that the leading spaces are also removed.
> 
> Can someone tell me the regular expression that would eliminate the unwanted
> characters?
> 

I could do but I though I'd give you something more useful - a little
snippet that will extract all of the fields into a hash that you can use
to something more with in your program:


#!/usr/bin/perl -w

use strict;

my $uptime = `/usr/bin/uptime`;
my %uphash = ();

if ($uptime =~ /^\s+(.+?)
                 \s+\w+\s+
                 (.+?),
                 \s+(\d+)
                 \s+users,.+:\ 
                 ([\d\.]+),\ 
                 ([\d\.]+),\ 
                 ([\d\.]+)/x)
{

  $uphash{time}             = $1;
  $uphash{uptime}           = $2;
  $uphash{users}            = $3;
  $uphash{one_min_load}     = $4;
  $uphash{five_min_load}    = $5;
  $uphash{fifteen_min_load} = $6;
}

foreach (keys %uphash )
  {
    print $_," = ", $uphash{$_},"\n";
  }

Of course now you should go off and read the perlre manpage to get a better
idea of what is going on here.

/J\
-- 
Jonathan Stowe <jns@btinternet.com>
Some of your questions answered:
<URL:http://www.btinternet.com/~gellyfish/resources/wwwfaq.htm>
Hastings: <URL:http://www.newhoo.com/Regional/UK/England/East_Sussex/Hastings>


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

Date: Sat, 27 Feb 1999 14:58:50 -0500
From: "navid atoofi" <natoofi@dac.neu.edu>
Subject: how to make a character recognized without "enter" ?
Message-Id: <7bc6t0$mqv$1@isn.dac.neu.edu>

Hello:


I have a program .It needs to recognize letters (e.g. "a", "b") without
pressing "enter".
Or in the other word It has to take action without pressing enter, Or
recognize key stroke without enter.

Thanks
Navid





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

Date: 12 Dec 98 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Special: Digest Administrivia (Last modified: 12 Dec 98)
Message-Id: <null>


Administrivia:

Well, after 6 months, here's the answer to the quiz: what do we do about
comp.lang.perl.moderated. Answer: nothing. 

]From: Russ Allbery <rra@stanford.edu>
]Date: 21 Sep 1998 19:53:43 -0700
]Subject: comp.lang.perl.moderated available via e-mail
]
]It is possible to subscribe to comp.lang.perl.moderated as a mailing list.
]To do so, send mail to majordomo@eyrie.org with "subscribe clpm" in the
]body.  Majordomo will then send you instructions on how to confirm your
]subscription.  This is provided as a general service for those people who
]cannot receive the newsgroup for whatever reason or who just prefer to
]receive messages via e-mail.

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

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