[11531] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 5131 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Mar 14 11:07:21 1999

Date: Sun, 14 Mar 99 08:00:23 -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           Sun, 14 Mar 1999     Volume: 8 Number: 5131

Today's topics:
    Re: *** FAQ: ANSWERS TO YOUR QUESTIONS! READ FIRST! Pos <staffan@ngb.se>
        Another woeful flock post shanx24@my-dejanews.com
        Another woeful FLOCK post <mkshanx@ust.hk>
    Re: Another woeful flock post (Tad McClellan)
    Re: Another woeful FLOCK post (Benjamin Franz)
    Re: Can a PARENT NOT wait on a CHILD Process? HOW? info@multilinks.net
    Re: Can't Increment Counter in FILE Using http:// <ebohlman@netcom.com>
        Cleaning up memory <pcion@cybersource.com>
    Re: complicated reg-exp question <jacklam@math.uio.no>
    Re: Deleting the rest of the line... gertyk@mail.cybernex.net
    Re: does perl discourage obfuscated code? (was Re: Perl ran@netgate.net
        Editing array content <u4ia@nospam.videotron.ca>
    Re: Editing array content (Tad McClellan)
    Re: Fast DNS lookups? <borud@lucifer.fast.no>
        Help with Authen::Basic <kgmcdonald@earthlink.net>
    Re: Help: File locking. (Tad McClellan)
    Re: How can I count the 2 dimenion array element? <au_aaron@hongkong.com>
    Re: How can I count the 2 dimenion array element? (Randal L. Schwartz)
        Manipulating Service startup scottjohnstone@my-dejanews.com
    Re: Printing a Copyright character <staffan@ngb.se>
        Problems with files that a script creates, new Perl use (David Bowles)
    Re: Regex $1 behavior gertyk@mail.cybernex ADD .net
    Re: SSI query <staffan@ngb.se>
        Special: Digest Administrivia (Last modified: 12 Dec 98 (Perl-Users-Digest Admin)

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

Date: Sun, 14 Mar 1999 16:54:46 +0100
From: Staffan Liljas <staffan@ngb.se>
Subject: Re: *** FAQ: ANSWERS TO YOUR QUESTIONS! READ FIRST! Posted Twice Weekly  ***
Message-Id: <36EBDBC6.8ECBF36A@ngb.se>

Hmm. I'm sure Abigail doesn't need my support, but anyway...

jeff@axismutatis.net wrote:
> 
> In article <7bhei2$rgt$1@client2.news.psi.net>,
>   abigail@fnx.com wrote:
> > Andrew Fry (andrewf@beausys.demon.co.uk) wrote on MMIX September
> > MCMXCIII in <URL:news:g75mKCA88822EwWw@beausys.demon.co.uk>:
> > ^^ I am quite calm, thanks, and have not made any stupid remarks. 
> > ^^ My point is simply that I find it irritating and patronizing to
> > ^^ be constatntly told what I should be reading. I know what I
> > ^^ should be reading, I know how much time I have to read, and Ill
> > ^^ get around to it at my own pace.

Now, this has been said before, but I'll say it again: If someone sais 
'perldoc -f sort' to you, it's not a RTFM, and it's not inpolite, and
it's not not answering the question, and it's not patronizing, and it's
not telling you what you should be reading etc. 

It's a way of reducing the number of characters the person responding to
a question has to type to give the full, correct and well-written
answer. For you to cut out that line, paste it in a shell and run it,
and then read what it produces shouldn't take more time than it would
for you to read the answer if it was posted. Despite this fact, many
people quote the manuals or faqs. 

If you find it patronizing when people give you an answer to a question,
and you see that the answer was easy to find, it is probably because
you've got a bad conscience for not reading the docs. Perhaps you
should, and perhaps you shouldn't. But don't misinterpret what you were
told to be a RTFM just because it makes you feel bad. And if it helps
you to find the solution to your next question without posting it, you
will probably find the answer quicker (hmm, last time I was told to do
perldoc -f sort, so since my question is on open, I'll try perldoc -f
open...).

> > Your time is more important than other people time?
> 
> I seriously doubt your time is terribly important. Most of your
> replies in this newsgroup are either filled with sarcasm or insults,
> and aren't terribly informative at all.

Abigail seems to me to be a vey resourceful person, and knowledgable
programmer. I'm sure the time Abigail doesn't take to answer peoples
questions on clp.misc is well spent doing productive programmer for some
company.

There aren't many people in this newsgroup who provide more instructive
pointers to questions than Abigail does, and when doing a search on
dejanews, I get 30 RTFM's from Abigail... Out of 3096 posts. Looking
through those 30 results, I conclude that only about half actually
contained a RTFM by Abigail, the rest in quoted text. Of the remaining,
half was RTFMs on questions not related to perl. Half of those remaining
from that was RTFMs to people giving incorrect solutions. Half of those
remaining were RTFMs to people asking "What does chop mean" and then the
last two were rather rude. Shame on Abigail.

> If your time is so damned precious, perhaps you should leave this
> newsgroup?

Why should a MAJOR contributor leave a newsgroup because you get
offended when you are reminded that you haven't had the time to look
through the documentation?
 
> The guy has a point - not everything is answered in a FAQ. Not every
> question is frequent. Sometimes, the answer given in a FAQ is unclear.
> Many people  come here when the FAQs have failed them.

When people say "I didn't find/understand the answer in the
documentation", they _never_ get a RTFM from anybody.

The world would be a better place if people learned to use the good
resources there are about perl, and to use them in an appropriate order
(this list shows my preferred order). 

1) Manuals
2) FAQs
3) FMTEYEWTK
4) language.perl.com reference.perl.com www.perl.com
5) Dejanews clp.misc archives
6) clp.misc

I don't mean to say that you have to go through the entire list each
time, but try at least one or two of the approaches before resorting to
the last... I'd say: If you sincerely tried for more then half an hour
to find the answer (using a decent technique) in the first five
resources, you have good reason to go to the sixth. Usually, doing 1)
and 5) is all it takes, and those are fast.

(What I don't know is: is there a searchable index of the complete
documentation online? i.e. manuals, FAQs and FMTEYEWTKs?)

Staffan


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

Date: Sun, 14 Mar 1999 12:08:17 GMT
From: shanx24@my-dejanews.com
Subject: Another woeful flock post
Message-Id: <7cg8rd$fd8$1@nnrp1.dejanews.com>

Hi fellow-JAPHs,

I'm afraid the whole newsgroup is riddled with flock() posts, but I swear
none of them works for me! (I am sorta surprised at Perl because it works so
differently on so many platforms, particularly for unfortunate people like
me!)

I am a beginner, and I have the following very simple code:

_____________________CODE__________________________

#!/usr/local/bin/perl5.00502 -w
use fcntl ':flock';

open(db, ">>data.txt") or die "Please call the experimenter: $!\n";
        flock(db, LOCK_EX);
        seek(db, 0, 2);
        print db "Hi there\n";
close db;

print "record written";

____________________/CODE_______________________



I am using Perl5.00502 and Sun OS "something.6" version... SYS command returns
Sun4x_55 though I was told that it is a new enough version of SunOS to support
file locks and stuff. So thats that.

Now my problem is that when I run this program at the command line, it gives
me the folllowig errors:


-----------------
syntax error in file last2.cgi at line 2, next 2 tokens "use fcntl"
syntax error in file last2.cgi at line 4, next 2 tokens ") or"
Execution of last2.cgi aborted due to compilation errors.
-----------------



The use of Fcntl is something I picked up from Perl.com site in their FAQ 5,
as recommended by various posts in this group. And that is not working!

Could you please tell me whats wrong with the above code?

Would be grateful if you could also post a CC message to winframe@iname.com.

Thanks a lot for your time.

Best regards
Shanx24

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


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

Date: Sun, 14 Mar 1999 20:28:29 +0800
From: "Shanx" <mkshanx@ust.hk>
Subject: Another woeful FLOCK post
Message-Id: <7cg9va$ivu@ustsu10.ust.hk>

Hi fellow-JAPHs,

I'm afraid the whole newsgroup is riddled with flock() posts, but I swear
none of them works for me! (I am sorta surprised at Perl because it works so
differently on so many platforms, particularly for unfortunate people like
me!)

I am a beginner, and I have the following very simple code:

_____________________CODE__________________________

#!/usr/local/bin/perl5.00502 -w
use fcntl ':flock';

open(db, ">>data.txt") or die "Please call the experimenter: $!\n";
        flock(db, LOCK_EX);
        seek(db, 0, 2);
        print db "Hi there\n";
close db;

print "record written";

____________________/CODE_______________________



I am using Perl5.00502 and Sun OS "something.6" version... SYS command
returns Sun4x_55 though I was told that it is a new enough version of SunOS
to support file locks and stuff. So thats that.

Now my problem is that when I run this program at the command line, it gives
me the folllowig errors:


-----------------
syntax error in file last2.cgi at line 2, next 2 tokens "use fcntl"
syntax error in file last2.cgi at line 4, next 2 tokens ") or"
Execution of last2.cgi aborted due to compilation errors.
-----------------



The use of Fcntl is something I picked up from Perl.com site in their FAQ 5,
as recommended by various posts in this group. And that is not working!

Could you please tell me whats wrong with the above code?

Would be grateful if you could also post a CC message to winframe@iname.com.

Thanks a lot for your time.

Best regards
Shanx




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

Date: Sun, 14 Mar 1999 03:37:09 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Another woeful flock post
Message-Id: <lfsfc7.br.ln@magna.metronet.com>

shanx24@my-dejanews.com wrote:

: use fcntl ':flock';
      ^
      ^
: syntax error in file last2.cgi at line 2, next 2 tokens "use fcntl"

: The use of Fcntl is something I picked up from Perl.com site in their FAQ 5,
             ^
             ^

: Could you please tell me whats wrong with the above code?


   You didn't type the name correctly...


--
    Tad McClellan                          SGML Consulting
    tadmc@metronet.com                     Perl programming
    Fort Worth, Texas


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

Date: Sun, 14 Mar 1999 15:31:45 GMT
From: snowhare@devilbunnies.org (Benjamin Franz)
Subject: Re: Another woeful FLOCK post
Message-Id: <BDQG2.7075$TD3.80476@typhoon-sf.pbi.net>

In article <7cg9va$ivu@ustsu10.ust.hk>, Shanx <mkshanx@ust.hk> wrote:
>Hi fellow-JAPHs,
>
>I'm afraid the whole newsgroup is riddled with flock() posts, but I swear
>none of them works for me! (I am sorta surprised at Perl because it works so
>differently on so many platforms, particularly for unfortunate people like
>me!)
>
>I am a beginner, and I have the following very simple code:
>
>_____________________CODE__________________________
>
>#!/usr/local/bin/perl5.00502 -w
>use fcntl ':flock';

[snip]

That is wrong.

use Fcntl qw (:flock);

Also, name your filehandles in uppercase - you will get a bunch
of warnings if you don't.

Lastly, check the _result codes_ of flock and seek or you could
be in for nasty surprises down the road.

-- 
Benjamin Franz


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

Date: Sun, 14 Mar 1999 15:22:25 GMT
From: info@multilinks.net
Subject: Re: Can a PARENT NOT wait on a CHILD Process? HOW?
Message-Id: <7cgk7a$ntq$1@nnrp1.dejanews.com>

In article <36E77136.5BAB9EB3@iname.com>,
  Frank Varnavas <varnavas@iname.com> wrote:
> I don't know what the 'parent' is doing after the print occurs but the
> printed data may be bufferred up because:
>
>   - you didn't set the handle to be non-bufferred
>   - you didn't put a \n at the end of the data
>
> frank v
>
> global3@my-dejanews.com wrote:
> >
> > tried using the pipe() function. Here  is the code from my script that I've
> > tried without success:
> >
> > $add = "title=$title&url=$url&email=$email&section=$section";
> >
> > open(LPR,"|$subprog") || die "can't fork $subprog: $!\n";
> > print LPR $add;
> >
> > Best regards,
> > Alan
> >
> > -----------== Posted via Deja News, The Discussion Network ==----------
> > http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own
>

Hi, I work with Agni who posted this info request.  I have been trying to
figure out how to set non-buffering on the filehandle as you suggested.  I am
trying

open(LPR,"|$subprog", O_NONBLOCK) || die "can't fork $subprog: $!\n";

but this is reporting "too many parameters".  I have also tried:

open(LPR,"|$subprog") || die "can't fork $subprog: $!\n"; $|=1;

but this does not change the result - ie. the parent still waits on the child.

Just to expand on what we are trying to do. I am using a web based input
form. The parent takes in the info does some checking and sends it to the
child to do a long process.  I want the parent to report a message back to
the browser (Your request is being processed) before the child completes.

I hope you can help again.  Thanks, Vladimir

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


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

Date: Sun, 14 Mar 1999 11:05:19 GMT
From: Eric Bohlman <ebohlman@netcom.com>
Subject: Re: Can't Increment Counter in FILE Using http://
Message-Id: <ebohlmanF8L04w.Btp@netcom.com>

George Crissman <strads@tmisnet.com> wrote:
: That still leaves me wondering why the program works great when 
: called from the command line but not when called by the browser.

This is one of those cases where it's essential to be precise and 
nitpicky about language.  There's no such thing as "running a program 
from a browser."  CGI scripts are run by a Web *server*.

When you run a program from the command line, that program runs with user 
*you*.  When you click on a button in a Web browser, the browser asks the 
Web server to run the program.  The server runs with user *it*.  If the 
server doesn't have permission to access your files, the program won't 
work when run by the server.  If the program relies on your account 
directory being the current directory, it will fail when run by the server.

The point here is that when you activate a script from a Web page, *you* 
aren't the one running it.  The server is.  The server isn't you.



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

Date: Sun, 14 Mar 1999 05:01:11 -0800
From: Pete Cion <pcion@cybersource.com>
Subject: Cleaning up memory
Message-Id: <36EBB316.CFDCE395@cybersource.com>

Hello -

I have run into a situation where I am using rather large variables and
arrays, and want to clean them out of memory.  Unfortunately, neither
using "undef" nor waiting for them to go out of scope does not work -
the underlying memory is still tied up.

Is there a way to actually go in an clean out memory?  I have attached a
sample program, foo.pl, below.  (btw, the same results occurred when
declaring the variables as "local" rather than "my").

I appreciate any help with this one.

Thanks,

Pete Cion

"foo.pl" 62 lines, 784 characters

#!/usr/local/bin/perl -w

print "At top \n";

&sub1;

# should be undefined here.
print "$var_in_sub";

print "at very end! \n";
$thetop = `top | grep foo`;
print $thetop;

exit(1);



sub sub1 {
print "at top of sub1\n";
$thetop = `top | grep foo`;
print $thetop;

my $var_in_sub;

$filledvar = &fillit($var_in_sub);
undef($filledvar);
undef($var_in_sub);

print "in the middle of sub1 \n";
$thetop = `top | grep foo`;
print $thetop;

$filledvar = &fillit($var_in_sub);
undef($filledvar);
undef($var_in_sub);

print "at the end of sub1 \n";
$thetop = `top | grep foo`;
print $thetop;

return;

}



sub fillit{

local ($tofill) = @_;
print "In fillit \n";

for ($i=0; $i<1000000; $i++) {

     $tofill .= "hello";
}

$thetop = `top | grep foo`;
print $thetop;

return($tofill);
}


Results:
>foo.pl

Name "main::var_in_sub" used only once: possible typo at foo.pl line 8.
At top
at top of sub1
16002 pcion      1  23    0 2128K 1776K sleep   0:00  0.07% foo.pl
In fillit
16002 pcion      1   5    0   18M   14M sleep   0:04  9.53% foo.pl
in the middle of sub1
16002 pcion      1 -15    0   26M   19M sleep   0:04  9.52% foo.pl
In fillit
16002 pcion      1 -25    0   26M   19M sleep   0:09 17.69% foo.pl
at the end of sub1
16002 pcion      1   5    0   26M   19M sleep   0:09 17.41% foo.pl
Use of uninitialized value at foo.pl line 8.
at very end!
16002 pcion      1  -5    0   26M   19M sleep   0:09 17.10% foo.pl




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

Date: Sun, 14 Mar 1999 13:10:56 +0100
From: Peter John Acklam <jacklam@math.uio.no>
Subject: Re: complicated reg-exp question
Message-Id: <36EBA750.32B24A8D@math.uio.no>

Alex Farber wrote:
> 
> Hi,
> 
> I must extract all the function names from some MATLAB files.

See

  http://www.math.uio.no/~jacklam/matlab/perl/mlfundef.txt

I started writing a Perl module that does this (and more), but due
to lack of time, it's still far from being really useful. :-(

> But the problem is to recognize escaped quotes which are double
> quotes ('') in MATLAB:
> 
>     'blah'              ->    ''
>     'Say ''Hello!'''    ->    ''

Using an approach similar to what I used in the program that I referred
to above, you should not need this.  Anyway, in Matlab, a single quote
is a transpose operator if followed by a closing paren/brace/bracket, a
letter, digit, underscore, or dot.  So the lookbehind has to include the
dot.  Also, strings are not allowed to span multiple lines.   You can
also speed things up by "unrolling the loop" (see Mastering Regular
Expressions by J. E. Friedl).  This gives

   s/ (?<![]})\w.])   # leading context
      '               # Opening single quote that starts the string.
        [^'\n]*       # Zero or more chars that are neither single
                      #   quotes (special) nor newlines (illegal).
        (?:           # Non-backreferencing grouping parenthesis.
          ''          # An embedded (literal) single quote character.
          [^'\n]*     # Again, zero or more chars that are neither
                      #   single quotes nor newlines.
        )*            # Match zero or more times.
      '               # Closing single quote that ends the string.
    / '' /gx;         # remove everything between quotes

Peter

PS.  If you think THAT is complicated, take a look at the regular
expression needed that matches all valid Matlab function declarations,
and does not match any invalid function declarations (wrapped at 64
columns):

^[ \t\f]*function\b(?:[ \t]*(?:\.\.\.+[^\n]*\n[ \t]*)*(?:\[[ \t]
*(?:\.\.\.+[^\n]*\n[ \t]*)*(?:[a-zA-Z][a-zA-Z0-9_]*(?:[ \t]*(?:\
 .\.\.+[^\n]*\n[ \t]*)*,[ \t]*(?:\.\.\.+[^\n]*\n[ \t]*)*[a-zA-Z][
a-zA-Z0-9_]*)*[ \t]*(?:\.\.\.+[^\n]*\n[ \t]*)*)?\]|[a-zA-Z][a-zA
-Z0-9_]*)[ \t]*(?:\.\.\.+[^\n]*\n[ \t]*)*=)?[ \t]*(?:\.\.\.+[^\n
]*\n[ \t]*)*[a-zA-Z][a-zA-Z0-9_]*(?:[ \t]*(?:\.\.\.+[^\n]*\n[ \t
]*)*\([ \t]*(?:\.\.\.+[^\n]*\n[ \t]*)*(?:[a-zA-Z][a-zA-Z0-9_]*(?
:[ \t]*(?:\.\.\.+[^\n]*\n[ \t]*)*,[ \t]*(?:\.\.\.+[^\n]*\n[ \t]*
)*[a-zA-Z][a-zA-Z0-9_]*)*[ \t]*(?:\.\.\.+[^\n]*\n[ \t]*)*)?\))?(
?=[ \t]*(?:\.\.\.+[^\n]*\n[ \t]*)*\r?[\n,;])

It could be simplified a little by replacing [a-zA-Z0-9_] with \w
and \.\.\.+ with \.{3,} but it would still be fairly large.  :-)

-- 
Peter J. Acklam - jacklam@math.uio.no - http://www.math.uio.no/~jacklam



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

Date: Sun, 14 Mar 1999 15:09:47 GMT
From: gertyk@mail.cybernex.net
Subject: Re: Deleting the rest of the line...
Message-Id: <36ebd042.8366911@news.cybernex.net>

Try this:
@lines=("Something TRUCK something else\n",
	    "TRUCK nothing before\n", 
		"Nothing after TRUCK\n",
		"This has TRUCK two TRUCK times!\n");
		
foreach $line(@lines){
	$line=~/(.*\bTRUCK)\b.*/;  #<---- Here is the Regex
	print $1."\n";
	}


On Sat, 13 Mar 1999 06:52:16 -0500, tadmc@metronet.com (Tad McClellan)
wrote:

>David Falconer (webmaster@guestcities.com) wrote:
>
>: In a text file I have, I want to delete all characters after a certain
>: occurance of a word.
>
>: So each time it comes across the word TRUCK it deletes all characters after
>: that for the rest of the line.
>
>
>   s/TRUCK.*/TRUCK/;
>
>      or
>
>   s/\bTRUCK\b.*/TRUCK/;  # leave FIRETRUCK alone
>
>
>--
>    Tad McClellan                          SGML Consulting
>    tadmc@metronet.com                     Perl programming
>    Fort Worth, Texas



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

Date: 14 Mar 1999 14:45:16 GMT
From: ran@netgate.net
Subject: Re: does perl discourage obfuscated code? (was Re: Perl evangelism)
Message-Id: <7cgi1s$fj4$3@remarQ.com>

In <199903140159.SAA07019@asarian-host.org>, Mark <admin@asarian-host.org> writes:

>Powerful, from my Assembly language background, is the art of packing many
>complex operations into a terse command, be it a single mnemonic, or a line of
>code. So, to me, an instruction like "foreach" is far more powerful than, say,
>"for(i=0; i < arraylen; i++)". Why? Because the former, though it effectively
>does the same, is much more compact.

But,  "foreach" only "does the same" for *some* uses of the "for" loop. 
"foreach" giveth,  but it also taketh away:  the values of "i" and 
"arraylen" might be put to other uses in the loop.  E.g.,  to do a 
little look-ahead or look-back through the list,  display a "percent 
complete" indicator for a long process,  etc.

Perl can be said to be "more powerful" in its terseness because it can 
automatically handle a lot of the "housekeeping" of writing the
equivalent code in C when there's no need for it to be "visible".  Just 
as C takes care of a lot of "housekeeping" in subscript arithmetic, 
stack frame construction/teardown,  etc. that's "visible" in assembly.

Since there's a large set of problems for which that "housekeeping" just
gets in the way,  and has no useful aspects (like,  say,  the loop 
index,  when all you need it for is to get to the current element of the
list you're iterating through),  there's a large set of cases in which 
Perl is "more powerful".  There's also a large set of cases in which 
it's not <shrug>.

Trying to arbitrarily declare one language "more powerful" without 
reference to what it's going to be used for is like arguing about 
whether a chainsaw is "better than" a Swiss Army knife without 
specifying whether you're planning to trim your fingernails or cut down 
a tree.

>It is only less legible
>if you do not adjust your reading speed. One is the result of the other: the
>denser, terser, the coding (= powerful,) the more it naturally follows that an
>unrolled, more descriptive coding makes for easier reading.

And,  since a significant part of the function of most programs is to 
communicate the intent of the original author to a future maintainer, 
the "power" of a language can't be measured solely in terms of its 
ability to save coding keystrokes.  Having a program take one hour, 
instead of three,  to write is great if it's a throwaway.  If it later 
takes three hours,  instead of one,  for every new maintainer to figure 
out what the #$%@ the original author could've been thinking of,  the 
advantage disappears fast.

The best measure of language "power" is probably life-cycle costs:  30 
years ago,  assembly was the most "powerful",  because it reduced the 
consumption of the most expensive resource (CPU power).  Today,  the 
trade-off for many applications favors programmer time,  instead.  But, 
as anyone who has tried to use NT can attest,  there's still lots of 
"power" in languages and methods that generate efficient object code ;-)

Ran




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

Date: Sun, 14 Mar 1999 07:08:44 -0500
From: "u4ia" <u4ia@nospam.videotron.ca>
Subject: Editing array content
Message-Id: <IKNG2.124$AI1.270@weber.videotron.net>

Hi,

I am wondering how I could edit the content of an array. For example, let's
say my array contains the following:

Doe, John
March 1st, 1967
johndoe@isp.com
NoName, Jeanne
April 24th, 1980
jeanne@myprovider.net
Anothername, Firstname
December 2nd, 1958
anf@freeemail.org

I have to create on the fly a webpage with mailto: links and I don't want to
show birthdates. The array is created via a non-editable file, so don't say
"remove the birthdate directly in the file" ;o)

In other words, I want to set the name in $name, set the email in $email and
forget the birthdate.

I hope you understand what I'm saying ;o)

Thanks for the help.


Martin.
u4ia "at" videotron.ca




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

Date: Sun, 14 Mar 1999 04:10:45 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Editing array content
Message-Id: <leufc7.j21.ln@magna.metronet.com>

u4ia (u4ia@nospam.videotron.ca) wrote:

: I am wondering how I could edit the content of an array. For example, let's
: say my array contains the following:

: Doe, John
: March 1st, 1967
: johndoe@isp.com
: NoName, Jeanne
: April 24th, 1980
: jeanne@myprovider.net
: Anothername, Firstname
: December 2nd, 1958
: anf@freeemail.org

: I have to create on the fly a webpage with mailto: links and I don't want to
: show birthdates. The array is created via a non-editable file, so don't say
: "remove the birthdate directly in the file" ;o)

: In other words, I want to set the name in $name, set the email in $email and
: forget the birthdate.


for ($i=0; $i<@ra; $i+=3) {
   $name = $ra[$i];
   $email = $ra[$i+2];

   print "$email <$name>\n";
}


--
    Tad McClellan                          SGML Consulting
    tadmc@metronet.com                     Perl programming
    Fort Worth, Texas


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

Date: 14 Mar 1999 13:57:09 +0100
From: Bjorn Borud <borud@lucifer.fast.no>
Subject: Re: Fast DNS lookups?
Message-Id: <m2sob8rzyy.fsf@lucifer.fast.no>

[Justin England]
| 
| Well, I am writing a perl / CGI program that will query the MySQL db
| and generate some stats.  I am concered about speed, and so far
| everything runs as quick I need, except when it comes to DNS
| lookups.  I know that their are alot of variables outside of my perl
| program that will determine how fast an DNS lookup is, but I am
| wondering what the fast way would be.  Here's what I am using right
| now:

so if I understand you correctly, you are trying to look up a fairly
large number of IP-adresses to generate some stats?

[Jon Drukman]
|
| here are three things you can do to speed the process up, in order
| of increasing complexity:
|
| 1.  keep an in-memory hash of IP's and hostnames.  that way you can
| look up the IP in the hash and know whether you've already done the
| (time consuming) dns resolution.

| 2.  set an alarm before you do the gethostbyaddr() call and abort it
| if takes more than a few seconds.  you may miss some servers with slow
| response times.  decide if it's worth the tradeoff.

| 3.  fork off a bunch of child processes to do the dns lookups and
| somehow coordinate getting the results back from them.  combine this
| with the previous two techniques.

if you're going to repeat the process every now and then I would use a
BSD db file/hash to store hostname, TTL and the time when the lookup
was made.  that way you know when you _should_ look the entries up
again (in most cases it is fairly safe to put a lower bound on the TTL
to at least a few days).  you should also cache negative hits to the
db hash so you don't spend a lot of time waiting for DNS servers that
are down or wrongly configured.

now for the exciting part;  instead of crawling forward looking up one
name at a time you use Net::DNS to fire off a bunch of packets in
batches of 50-100 at a time.  then you use IO::Select to listen for
replies and for timing out.  there is an example in the Net::DNS
package that does this.  check the demo/mresolv program.

running several processes in parallel each performing sequential
lookups will give you better performance than one process doing
sequential lookups,  but it will still be a lot slower than the method
mentioned above.


PS : you should be extremely careful to set alarms.  it is usually
     okay in an application,  but when used in libraries it can cause
     a lot of grief for other users.

-Bjxrn
-- 
 Bjxrn Borud <borud@fast.no>, <URL:http://borud.priv.no/>


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

Date: Sat, 13 Mar 1999 21:11:46 -0600
From: MaC <kgmcdonald@earthlink.net>
Subject: Help with Authen::Basic
Message-Id: <36EB28F2.BE68002C@earthlink.net>

I am using Authen::Basic to control access to a directory. How do you
access the user name that was used to authenticate?


Thanks in advance,

Kelly McDonald
kgmcdonald@earthlink.net



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

Date: Sun, 14 Mar 1999 03:05:48 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Help: File locking.
Message-Id: <skqfc7.2m.ln@magna.metronet.com>

networks@skynet.co.uk wrote:

: I've read the other messages posted in the group about locking files.
: Everyone seems to use FLOCK, but I've been studing some code by
: commercial programmer which does this:

: 	open (LOCK,">$classdir/$short_category_name.lock");

   This is absurd, since it will work *even if the file already exists!*

   If the file already exists, then that means the file is locked.

   This code *ignores* the fact that the file is already locked.

   It does not respect the lock, which is the whole point of locking.


   The "commercial programmer" is pretty amateurish for two reasons:

      1) the locking scheme doesn't work!

      2) he/she didn't check the return value from the open() call


   To lock a file, you should use the function(s) designed
   for locking files  :-)


: 	close LOCK;
: 	.....
: 	unlink("$classdir/$short_category_name.lock");

: Whats the difference between using FLOCK and $short_category_name.lock


   One of them works and one of them doesn't  :-)


: The file I wish to lock is a tab delimited text file  - I don't know
: if that matters.


   The contents of the file matter not at all.


: Can someone coment on this please. Thanks in advance :)


   It sucks.

   Don't use it.

   Carefully examine all code written by that person as there
   may be other broken stuff there too...



   Perl FAQ, part 5:

      "What can't I just open(FH, ">file.lock")?"



--
    Tad McClellan                          SGML Consulting
    tadmc@metronet.com                     Perl programming
    Fort Worth, Texas


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

Date: Sun, 14 Mar 1999 21:25:14 +0800
From: Aaron Au <au_aaron@hongkong.com>
To: hans-georg@rist.net
Subject: Re: How can I count the 2 dimenion array element?
Message-Id: <36EBB8BA.968F7A80@hongkong.com>

Thanks for your help!
One more question, I want to separate two counters for each group and
elements.
(2 x 4) = 8 elements.

Hans-Georg Rist wrote:

> Aaron Au <au_aaron@hongkong.com> wrote:
>
> >@array = ([1,2,3,4],[5,6,7,8]);
> >
> >How can I count how many elements in this array?
>
> this depends of what you want: 2 or 8 elements?
>
> print scalar( @array ), "\n";                # 2 elements (references)
>
> print scalar( map{ @$_ } @array ), "\n";     # 8 elements (numbers)
>
> # or:
>
> $c = 0;
> foreach my $e ( @array ) {
>    $c += @$e;
> }
> print $c, "\n";                              # 8 elements (numbers)
>
> HTH,
> HG
>
> --
> Hans-Georg Rist
> hans-georg@rist.net

--
Cheers,
Aaron Au




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

Date: 14 Mar 1999 07:20:33 -0800
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: How can I count the 2 dimenion array element?
Message-Id: <m1aexgt7we.fsf@halfdome.holdit.com>

>>>>> "Hans-Georg" == Hans-Georg Rist <hans-georg@rist.net> writes:

Hans-Georg> print scalar( map{ @$_ } @array ), "\n";     # 8 elements (numbers)

You lucked out on this one.  Although "map" in a scalar context is
undocumented, it does indeed return the total number of elements that
it would have returned in a list context.

   print scalar map 1..$_, 3..5; # prints 12

It's probably not wise to count on such un(der)documented features
though.  It's quite possible that map() in a scalar context could have
invoked nethack instead. :) I'm cc'ing perlbug so that the doc can be
fixed to reflect the current behavior.

print "Just another Perl hacker,"

-- 
Name: Randal L. Schwartz / Stonehenge Consulting Services (503)777-0095
Keywords: Perl training, UNIX[tm] consulting, video production, skiing, flying
Email: <merlyn@stonehenge.com> Snail: (Call) PGP-Key: (finger merlyn@teleport.com)
Web: <A HREF="http://www.stonehenge.com/merlyn/">My Home Page!</A>
Quote: "I'm telling you, if I could have five lines in my .sig, I would!" -- me


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

Date: Sun, 14 Mar 1999 14:13:12 GMT
From: scottjohnstone@my-dejanews.com
Subject: Manipulating Service startup
Message-Id: <7cgg5k$koi$1@nnrp1.dejanews.com>

I'm trying to get/set the startup value of an NT service (automatic, disabled,
manual) along with setting the "log on as" field.

This can't be done through Win32::Service.  It can be done through the
registry.

Has anybody already written something to do this?  So far I haven't found
anything...

Thanks,

scott

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


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

Date: Sun, 14 Mar 1999 14:51:07 +0100
From: Staffan Liljas <staffan@ngb.se>
Subject: Re: Printing a Copyright character
Message-Id: <36EBBECB.DF6646DC@ngb.se>

Jonathan Stowe wrote:
> 
> On Fri, 12 Mar 1999 12:11:38 -0500 Dave Abramowitz wrote:
> > Is there a way to print the copyright character (the c inside a circle)?
> 
> The ISO 8859-1 character code for that character is 169.
> 
> The Perl function for printing a character from its value is chr().

And in html, &copy; should work.

Staffan


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

Date: Sun, 14 Mar 1999 00:50:20 GMT
From: davbow@earthlink.net (David Bowles)
Subject: Problems with files that a script creates, new Perl user
Message-Id: <7cf127$7bb$1@holly.prod.itd.earthlink.net>

I recently changed servers and have run into a file permissions problem.  
Now, when files are created by the Perl script, (the files are user files in 
flat database format), the owner and group of the file defaults to "www" and 
"www" respectively.  The permissions are also not set correctly. In this case 
it causes a problem because passwords are contained in the files and they are 
visible by the URL of the file.   I can not set permissions or manually 
modify the files.  I tried to use chmod within my script but it did not seem 
to have any effect on the files. The server is running Red Hat L. and Apache 
1.3. 

I am interested in how to best handle the situation.  Can anyone point me to 
some resources that might help me with this situation?  

I am fairly new to Perl (several months) and would love to have any 
suggestions anyone might be able to throw, hurl or chunk my way.

David
davbow@earthlink.net



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

Date: Sun, 14 Mar 1999 15:55:03 GMT
From: gertyk@mail.cybernex ADD .net
Subject: Re: Regex $1 behavior
Message-Id: <36ebdb60.11212870@news.cybernex.net>

Try this:

$address = "127.0.0.1";
$address =~ s/((\d+\.)+)\d+/\1/;
print $address;



On 12 Mar 1999 21:21:34 GMT, jalovel@orl.ilstu.edu (Jeff Lovell)
wrote:

>Ok, I'm sure I must be missing something fairly obvious here, but I can't
>seem to find it.  When I use the $1 backreference in s/// it doesn't seem
>to work.  Here is the code I am working with:
>
>#!/usr/bin/perl -w
>
>$address = "127.0.0.1";
>$address =~ s/((\d+\.)*)/$1/;
>print $address, "\n";  # eq "127.0.0.1" <- I don't want this.
>print $1, "\n";        # eq "127.0.0."  <- I want this.
>
>
>Any help would be appreciated.  If you could CC via mail I would be greatful
>too.  My news server is on the fritz here, and posts are lost left and right.
>
>
>Jeff



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

Date: Sun, 14 Mar 1999 15:30:06 +0100
From: Staffan Liljas <staffan@ngb.se>
Subject: Re: SSI query
Message-Id: <36EBC7EE.51969739@ngb.se>

Jay Glascoe wrote:
> 
> Mike Cardosa wrote:
> >
> > Is it possible to use a query string while calling an SSI?  I need 
> > this to work!

> > EX:
> > <!--#exec cgi="scriptname.cgi?this=should&work=nicely"-->
> 
> command line arguments work (or am I being to Unix-centric?)
> 
> <!--#exec cmd="/bin/echo hi hello biz" -->

You can also use 

<!--#include virtual="scriptname.cgi?this=should&work=nicely" -->

And I think you want to have a space before "-->". There might be a
special setting you have to set in one of the Apache initialization
files for this to work, but I'm not sure. Try.

HTH
Staffan


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

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

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