[7249] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 874 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Aug 15 13:08:11 1997

Date: Fri, 15 Aug 97 10:00:23 -0700
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Fri, 15 Aug 1997     Volume: 8 Number: 874

Today's topics:
     Re: .htgroup files and HTTPD:GroupAdmin:Text.pm <rootbeer@teleport.com>
     ANNOUNCE: Argv::Parse New Powerful & Flexible getopt uri@sysarch.com
     Re: Begginner need simple script (Andreas Schmidt)
     Broken pipes and Perl (Arielle Sumits)
     Re: File Locking... <rootbeer@teleport.com>
     Re: File Locking... (Nathan V. Patwardhan)
     Filling in internet explorer forms Richard.Cudd@unitedkingdom.ncr.com
     Re: hel: enviroment vars <rootbeer@teleport.com>
     Re: Help with Regexp (Sajjad Lateef)
     HELP!  Full-text search in large DB <nobody@secret.squirrel.owl.de>
     Re: How can I check repeated URL? <rootbeer@teleport.com>
     How can I send data to printer <henryto@ix.netcom.com>
     Re: incredibly simple question <rootbeer@teleport.com>
     Re: Indexing search engine? <neiled@enteract.com>
     Is there a DB_File for Win32? <neiled@enteract.com>
     Need Help! <cmartin@interware.net>
     Re: Need Help! <rootbeer@teleport.com>
     Re: Net::FTP documentation and examples <rootbeer@teleport.com>
     Re: NetBSD-current pmax bug with perl5.00401 <davidson@zk3.dec.com>
     NT File Permission Assignment <kgenus@us.newbridge.com>
     Re: Pass arguments to Perl (Nathan V. Patwardhan)
     Re: Possible in Perl? Do it, I'll Pay ya! <khallera@hklaw.com>
     Re: Question of using stat function (Nathan V. Patwardhan)
     Re: Reading regexp from a file <rootbeer@teleport.com>
     Re: Using perl noninternet, stand alone for processing! <tonylabb@infonline.net>
     Re: Why doesn't sort take a reference any more? <friedman@uci.edu>
     Re: XS (converting perl array to char**..) (Andreas Schmidt)
     Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)

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

Date: Fri, 15 Aug 1997 08:41:35 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: "John W. Yates" <jwyates@netcom.com>
Subject: Re: .htgroup files and HTTPD:GroupAdmin:Text.pm
Message-Id: <Pine.GSO.3.96.970815083949.1951R-100000@julie.teleport.com>

On Fri, 15 Aug 1997, John W. Yates wrote:

>   I'm coding some stuff using HTTPD::GroupAdmin and think it has
> a bug, or at least and incompatability with in "Text" mode Apache:  
> It creates .htgroup files comma delimited.  I believe Apache is 
> interpreting the comma as part of the logon name in the group list 
> and thus all but the last name in the list fail authentication when 
> I try to use group authentication.

What do the Apache docs say? If Apache isn't behaving as documented,
notify the Apache development team. If the module isn't doing what it
should, notify its author or maintainer. Hope this helps!

-- 
Tom Phoenix           http://www.teleport.com/~rootbeer/
rootbeer@teleport.com  PGP   Skribu al mi per Esperanto!
Randal Schwartz Case:  http://www.rahul.net/jeffrey/ovs/



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

Date: 15 Aug 1997 12:36:30 -0400
From: uri@sysarch.com
Subject: ANNOUNCE: Argv::Parse New Powerful & Flexible getopt
Message-Id: <x7n2mjflo1.fsf@sysarch.com>


This is an announcement of a new perl module for parsing ARGV options
and values. It is very different from existing Getopt modules as it is
designed to be as easy to use as they are but far more powerful and
flexible. The module is currently called Argv::Parse and it has a single entry
called Parse. These names will likely change when the module is loaded
into the CPAN tree. It currently is in alpha test and I am looking for
testers and feedback.  I wrote it over a year ago and sat on it because
of my extreme laziness. I am releasing it now right before the Perl
Conference to hopefully maximize its use. I will be at the conference
and available to autograph printouts of Argv::Parse :-).

Also in order to publicize Argv::Parse it is being released with a new
and hopefully very popular license. You may have heard of beerware where
you have to drink a beer in honor of the author of a program. You have
alos heard of runtime royalties whereby you pay the author a fee for
each copy you use. Argv::Parse is runtime beerware. Each time you CALL
it you must drink a beer (hopefully a good microbrew!). This should
ensure a widespread use. If you buy me a beer at the conference you will
be given a lifetime license.

The current source is at http://www.sysarch.com/perl/argv/Argv.pl
Also there is a test program in the same directory called
test_argv.pl. It has a good examples of many option types. The module is
completely documented in pod in the source file and is in html form at 
http://www.sysarch.com/perl/argv/argv.html. 

All feedback will be willingly received and should be sent to
uri@sysarch.com. I am looking for bugs, documentation problems
(including better use of pod formatting), wanted features, better tests
and help in creating a CPAN module. I want to make all other option
parsers obsolete and then to destroy Microsoft.

Argv::Parse describes each option with a hash of attributes. An
reference to list of these attribute hashes is the main argument to
Argv::Parse. The optional second argument is a single hash reference
with values which control the behavior of Parse such as setting the long
option prefix (default is '--'), etc. Most attributes are optional so a
simple single letter boolean option can be described with a single
attribute like this:

	{ 'short' => 'a' }

which will parse out '-a' and set $opt_a if it is found.

But that is the tip of the iceberg of the attributes an option can
have. Here are some the attributes for options:

	short (single letter) or long option names

	the option variable can be explicitly named or defaulted to opt_xxx

	options can have defaults or environment variables can be used

	options can be boolean, scalar (1 value), arrays (preset number
	of values) or multivalued (multiple occurances of an option like
	-Iincdir1 -Iincdir2)

	option values can be checked for range, if they are from a set
	of values, if file exists or is of a certain type, etc.
	user verification routines can be called if desired.

	options can have short and long help strings and can be
	designated to print those strings (typically -h, -H or -help).
	help text is associated with the option description so maintaining
	it is much simpler.

	options can be required or a set of options can be mutually
	exclusive

for a complete list of option attributes see the documentation at
http://www.sysarch.com/perl/argv/argv.html. 

enjoy it in good health!!

uri

-- 
Uri Guttman		        SYStems ARCHitecture and Software Engineering
uri@sysarch.com			                         Have Perl, Will Hack
http://www.sysarch.com		                        "Your Web Specialist"
(617) 643-7504 x*2  FAX: (617) 643-2710    These ARE the opinions of Sysarch!


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

Date: 15 Aug 1997 16:41:02 GMT
From: schmidt@miserv2iai.kfk.de (Andreas Schmidt)
To: "Henry Wolff" <henrywolff@hatsoftnevada.lovelock.nv.us.nospam>
Subject: Re: Begginner need simple script
Message-Id: <5t20qu$7ga$2@nz12.rz.uni-karlsruhe.de>

In article <01bca95f$93e559c0$b11de4cf@hatsoftnevada.lovelock.nv.us>, "Henry Wolff" <henrywolff@hatsoftnevada.lovelock.nv.us.nospam> writes:
|> When it comes to programming in other languages, even PC assembler, I do
|> fairly well, but this Perl is killing me.
|> I need a real simple little script that does the following:
|> 
|> opens a file that contains:
|> variable1a
|> variable1b
|> variable2a
|> variable2b
|> etc...
|> 
|> then reads the file data in, then does this test
|> if (variable1a contains testVar) {
|>    foundVar = variable1b
|> }
|> 
|> I thought that this would work
|> open (COUNT,"$file");
|> @lines = (COUNT);
|> close (COUNT);
|> ($var1, $var2) = @lines;
|> foreach ($line(@lines) (
|>  if (var1 eq testVar) {
|>    foundVar = var2;
|>  }
|> }
|> 


hola henry

here is an solution of your problem if i had understood it right. the script goes
through the file up to the moment the variablename matches an special condition.
in this case the special condition i used is a regular expression matching
variable names starting with characters and ending with digits ( expr: ^\w+\d+$)

#!/public/tools/bin/perl  -w

my $file = 'test_dict.txt';
open (COUNT,"$file") || die "Could not open \'$file\'\n";;
my ($var1, $var2, $foundedVar);
my $testVar = '\w+\d+';
while (defined($var1 = <COUNT>)) {
    $var2 = <COUNT>;
    if ($var1 =~ /$testVar/) {
	$foundedVar = $var2;
	last;
 }
}
close (COUNT);
print $foundedVar if defined $foundedVar;


my file test_dict.txt looks like:

hungry
[variable with only characters]
something2eat
[variable with characters and digits mixed]
drink33
[variable, ending with digits]


if you are looking for an easy to read and fast to lern book for perl i could
recomment you 'learning perl' from randal l. schwartz

enjoyperl
smiff
========================================================================
andreas schmidt                                email: schmidt@iai.fzk.de 
institut fuer angewandte informatik (iai)        phone: +49 7247 82 5714
forschungszentrum karlsruhe gmbh
    - technik und umwelt -       
postfach 3640                                  76021 karlsruhe (germany)



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

Date: 15 Aug 1997 14:43:07 GMT
From: arielle@mit.edu (Arielle Sumits)
Subject: Broken pipes and Perl
Message-Id: <arielle-1508971046010001@olc-mac-4.mit.edu>



What defect in a perl cgi script could cause a broken pipe error?

Some of the scripts on our web server consistently produce broken pipe
errors, others do not, so I don't believe it's the fault of our server
software. Must have something to do with the individual scripts.

I appreciate your help.

Thanks,

Arielle


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

Date: Fri, 15 Aug 1997 08:12:55 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: David Mellors <dgm@globalnet.co.uk>
Subject: Re: File Locking...
Message-Id: <Pine.GSO.3.96.970815081221.1951L-100000@julie.teleport.com>

On 15 Aug 1997, David Mellors wrote:

> Does perl automatically lock files when writing to them?

No. That's the programmer's responsibility. :-)

> If not, can anyone supply information on the best way of locking files
> using Perl running under Linux and BSDI.

I think you could use the methods in Randal's fourth Web Techniques
column, which explains how to use flock() to avoid problems when multiple
processes need to modify one file. Hope this helps! 

   http://www.stonehenge.com/merlyn/WebTechniques/

-- 
Tom Phoenix           http://www.teleport.com/~rootbeer/
rootbeer@teleport.com  PGP   Skribu al mi per Esperanto!
Randal Schwartz Case:  http://www.rahul.net/jeffrey/ovs/



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

Date: 15 Aug 1997 15:21:55 GMT
From: nvp@shore.net (Nathan V. Patwardhan)
Subject: Re: File Locking...
Message-Id: <5t1s6j$4ar@fridge-nf0.shore.net>

David Mellors (dgm@globalnet.co.uk) wrote:
: Does perl automatically lock files when writing to them?

No.  Well, no, does your OS automatically lock files when opening them
for writing?

: If not, can anyone supply information on the best way of locking files
: using Perl running under Linux and BSDI.

I'd suggest looking at the perlfunc manpage for flock().

--
Nathan V. Patwardhan
nvp@shore.net



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

Date: Fri, 15 Aug 1997 11:41:39 -0600
From: Richard.Cudd@unitedkingdom.ncr.com
Subject: Filling in internet explorer forms
Message-Id: <871663169.4033@dejanews.com>

Does anyone know of a way to fill out forms when using internet explorer.
I've heard perl can be used to do this.  I'm trying to get into a web
site which requires a password and I want the form to be filled out
automatically and in the background so that the user cannot see that it
is happening.  It's a fairly normal looking windows 95 network password
dialogue box.

Any Ideas ??

Thanks,

Richard Cudd

-------------------==== Posted via Deja News ====-----------------------
      http://www.dejanews.com/     Search, Read, Post to Usenet


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

Date: Fri, 15 Aug 1997 07:55:21 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: Gabor Gyorfi <gyorfi@mediaport.org>
Subject: Re: hel: enviroment vars
Message-Id: <Pine.GSO.3.96.970815074343.1951I-100000@julie.teleport.com>

On Wed, 13 Aug 1997, Gabor Gyorfi wrote:

> I tried to install perl on an nt system, now I can run a perl script
> from a HTML form, but I can't pass any data , it seems there is no
> enviroment variamles are visible from the perl script, and ther is
> nothing at stdin.

If your server isn't giving your script those things, there's nothing that
Perl can do about it. (But see below.) Just to be sure, let's make sure
that Perl is working right. Does this script do anything unexpected when
you run it from the command line? (Don't try it from the web; it's not a 
CGI script.) 

    #!/usr/bin/perl -w		# Fix as needed...

    # Dump the environment
    print "The environment is:\n",
	map {
	    my($copy) = $ENV{$_};
	    $copy =~ s/([\\'])/\\$1/g;
	    "    $_ => '$copy'\n"
	} keys %ENV;

    print "Empty environment - that's not good!\n"
	unless keys %ENV;

    print "Please type your name here: ";
    chomp($name = <STDIN>);
    print "Well, $name, I hope your Perl is working right for you!\n";
    __END__

If that program does the right stuff, then the problem may be with your
webserver. Check with a server newsgroup for more help with server
problems. Hope this helps!

-- 
Tom Phoenix           http://www.teleport.com/~rootbeer/
rootbeer@teleport.com  PGP   Skribu al mi per Esperanto!
Randal Schwartz Case:  http://www.rahul.net/jeffrey/ovs/



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

Date: 15 Aug 1997 15:44:45 GMT
From: sajjad@uic.edu (Sajjad Lateef)
Subject: Re: Help with Regexp
Message-Id: <5t1thd$23r8$1@piglet.cc.uic.edu>

Hi,
I got this to work with the following regexp:
/(^((\w+)+\s?)+\.?$)|(^(\d+[:\/-]?)+$)/

The first part before the | matches sentences and words that may
end in a period. The second part matches phone numbers, Date and 
Time fields. 
I was able to use the suggestion to use "or" to specify different
types of fields and use of + instead of *. Thanks Mike, Jeff!

Thanks again,
Sajjad

>Hello Regexp gurus,
>	I am trying to match the following different strings
>with one regexp. 
>abc   		# string of chars with no embedded spaces
>123		# Number with no embedded spaces
>07/12/1997 	# Date
>212-212-2222 	# Phone Number
>11:00		# Time format
>abc123		# alphanumeric string
>This is a test	# A sentence with alphanumeric fields
>
>I thought that /(\w*:?\/?-?\s*)*/ would do the trick. 
: >I thought that /(\w*:?\/?-?\s*)*/ would do the trick. 
: >I get a message (warning?) that it matches null strings many times.
: >And, of course, it does not do what I want it to do.

: The main problem I see is that you are using an asterisk, which matches
: any number of matches (including 0), when you should be using a +, which
: matches 1 or more hits.

: ----------------
: | "Here we are now, entertain us!"
: | 	- Nirvana
: ----------------
: Jeff "TechMaster" Pinyan | http://users.bergen.org/~jefpin
: I do: HTML!! CGI!! Perl!! JavaScript!! jefpin@bergen.org
: Got a JavaScript/CGI/Perl question or problem?  Let me know!

: webXS - the new eZine for WebProgrammers! TechMaster@bergen.org
: Visit us @ http://users.bergen.org/~jefpin/webXS


--
Sajjad Lateef			http://www.eecs.uic.edu/~slateef/		
sajjad <at> acm.org


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

Date: 15 Aug 1997 11:11:04 -0000
From: Secret Squirrel <nobody@secret.squirrel.owl.de>
Subject: HELP!  Full-text search in large DB
Message-Id: <ee237c73afc4c3063442594e991bae76@squirrel>



Hi.  I want to write a perl front-end to access (read & write) a
largish database (ca. 20 MB).  I'm just now finding my way around and
learning about DB_File and Berkeley DB, but there's a particular
feature I need that doesn't seem to be supported by this system (as
far as I can tell).  I'm hoping to get some helpful pointers that will
channel my search and programming efforts.

This is a bibliographic database, and it is crucial that users be able
to search the full text of certain fields such as Keywords, Abstract,
and Comments.  Can someone please tell me what is the standard
approach to this problem, and whether there is anything out there that
I can use to speed up a Perl implementation of this?

Thank you *very much* in advance.

K.

(please post; no email, please)



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

Date: Fri, 15 Aug 1997 08:06:28 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: Aitor <citas@hotmail.com>
Subject: Re: How can I check repeated URL?
Message-Id: <Pine.GSO.3.96.970815075652.1951J-100000@julie.teleport.com>

On Fri, 15 Aug 1997, Aitor wrote:

> how can I check if the URL is already added? 

Keep a hash whose keys are the URLs you've seen, then do something like
this.

	next if exists $seen{$url};

> open(FILE,"$filename");

Always check that the open call succeeded. (And those quote marks are only
misleading.) 

>     if ($line =~ /\<li\>\<a href\=\"([^\"]+)\">([^<]+)<\/a>/) {

You don't have to backwhack most of those characters in a regular
expression. Leaving out the excess backslashes will make that easier to
read, understand, and maintain. 

> I've tried to add it but I get an error, any idea?

Since there are around 400 different error messages you might be seeing,
it's hard for anyone to guess which one you saw! :-)  But your message
should be listed in the perldiag(1) manpage.

> Also ho w can I keep. for example the last 100 links, so if you add
> another link the oldest one gets deleted?

Sounds like a job for an array, using push and shift perhaps.

I think you could use some of the ideas in Randal's Web Techniques
columns. They're worth looking over for general edification as well.

   http://www.stonehenge.com/merlyn/WebTechniques/

Hope this helps!

-- 
Tom Phoenix           http://www.teleport.com/~rootbeer/
rootbeer@teleport.com  PGP   Skribu al mi per Esperanto!
Randal Schwartz Case:  http://www.rahul.net/jeffrey/ovs/



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

Date: Fri, 15 Aug 1997 12:42:34 +0000
From: "Henry J. Torralvo" <henryto@ix.netcom.com>
Subject: How can I send data to printer
Message-Id: <33F44EBA.686@ix.netcom.com>

I am new to perl, I would like to know how to make perl send the data to
printer.


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

Date: Fri, 15 Aug 1997 08:16:04 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: "Nicholas J. Leon" <nicholas@neko.binary9.net>
Subject: Re: incredibly simple question
Message-Id: <Pine.GSO.3.96.970815081328.1951M-100000@julie.teleport.com>

On 15 Aug 1997, Nicholas J. Leon wrote:

>    $resp=~/^y+/i
> 
> actually mean any number of "y"s?? Such as "yyyy" or "yyyyyyy", but
> not "yes". Wouldn't something like:
> 
> $resp=~/^y/i
> 
> be more appopriate?

They both match the same set of strings. Unless you examine $& or $' after
the match, there's no functional difference. But you're right that the
second one should be a better choice in most cases. Hope this helps!

-- 
Tom Phoenix           http://www.teleport.com/~rootbeer/
rootbeer@teleport.com  PGP   Skribu al mi per Esperanto!
Randal Schwartz Case:  http://www.rahul.net/jeffrey/ovs/



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

Date: 15 Aug 1997 15:09:51 GMT
From: "Neil Edmondson" <neiled@enteract.com>
Subject: Re: Indexing search engine?
Message-Id: <01bca98d$3f38c820$b194e5cf@nedmondson>


> I'm looking for an indexing search engine. It has to be written in Perl
> as CGIs in other languages aren't allowd on the server. I've found some
> on-the-fly search scripts (Matt's simple search, WebSearch, Randall
> Schwartz' WebTechniques 4/1997), but they proved to be just a bit too
> slow.
> 

Try the following ... a crawler, which ain't fast - cos it's indexing EVERY
word); then a searcher, which is fast cos the major work has already been
done by crawler (via CGI - so you'd have to redo that, but the principles
are prob. the same).

I also recommend checking out that reference for Brian Slesinsky -
http://www.webmonkey.com/code/97/16/index2a.html

Neil
---------------------------------

#!/usr/bin/perl -Tw

use DB_File;
use File::Find;
use Time::Local;

# webcrawl.pl - create a full text index to a web site

# based on an idea by Brian Slesinsky
# http://www.webmonkey.com/code/97/16/index2a.html

$startpath = "/domain/http-docs";
$db = "search_index.db";
$db_current = $startpath . "/" . $db;
$db_new = $startpath . "/" . $db . ".new";
print $db_new;
# remove any previous attempt at indexing then create a new index file
unlink($db_new);
my %db;
dbmopen(%db, $db_new, 0644) or die "dbmopen: $!";
my $fileno = 0;

# scan and index every file
find(\&makeindex,$startpath);

# close the new index and replace any existing index
untie %db;
unlink($db_current);
link($db_new,$db_current) or die "link: $!";
unlink($db_new) or die "unlink: $!";

exit(0);

sub makeindex {
	if (/html$/) {

		# read the file content into $html
		$fullname = $File::Find::name;

                ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,
                        $atime,$mtime,$ctime,$blksize,$blocks) = stat
$fullname;

                ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) =
localtime($mtime);
                $modtime = join '/', ++$mon, $mday, $year;

		print "$modtime indexing $fullname\n";
		open (HTML, $fullname) || print "open $fullname: $!\n";
		my $html = join ('', <HTML>);
		close HTML;

		# make a link to the file
		$fullname =~ s/$startpath//;
		$url = substr($fullname,1);		
		my ($title) =($html =~/<title>([^<]*)/i);
		$title = $url if (!defined $title);
		$url = "http://www.weaveware.com/" . $url;
		$db{--$fileno} = "<a href=\"$url\">$title $modtime</a>";

		# extract the words from the HTML
		$html =~ s/<[^>]+>//g;
		$html =~ tr/A-Z/a-z/;
		my @words = ($html =~ /\w+/g);

		# add this page to the inverted index
		my $last = "";
		for (sort @words) {
			next if($_ eq $last);
			$last = $_;
			$db{$_} = defined $db{$_} ? $db{$_}.$fileno : $fileno;
		}
	}
}


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

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

use DB_File;


# search.pl - search page for a Web site

# based on an idea by Brian Slesinsky
# http://www.webmonkey.com/code/97/16/index2a.html

# parse form data

my $query = $ENV{'QUERY_STRING'};
$query =~ s/s=//;
$query =~ s/%[0-9a-fA-F]{2}/ /g;
my @words = ($query =~ /\w+/g);


# print search form

my $query_value = join(' ',@words);
print <<END;
Content-type: text/html

<body bgcolor="#FFFFFF">
<form>
<p><input name=s value="$query_value"><input type=submit value="Search">
</form>
<p>
END

exit if($query eq "");

# count the number of search terms on each relevant page

my %db;
dbmopen(%db, "/domain/http-docs/search_index.db", undef) or print "dbmopen:
$!";

my %counters;
my $word;
for $word (@words) {
    my $pages = $db{lc $word};
    my $page;
    for $page ($pages =~ /(-\d+)/g) {
	$counters{$page}++;
    }
}


# print links to the pages that have all the search terms

my $linkcount = 0;
my $page;
for $page (sort keys %counters) {
    if($counters{$page}==scalar(@words)) {
	$linkcount++;
	if($linkcount>50) {
	    print "<p>(only the first 50 matches are shown)";
	    last;
	}
	my $href = $db{$page};
	print "$href<br>";
    }
}

__END__




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

Date: 15 Aug 1997 14:58:52 GMT
From: "Neil Edmondson" <neiled@enteract.com>
Subject: Is there a DB_File for Win32?
Message-Id: <01bca98b$b6b206c0$b194e5cf@nedmondson>

Anyone aware of a Win32 implementation of DB_File and the underpinning
Berkeley DB?

TIA, Neil (cc: neiled@enteract.com if convenient)


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

Date: Fri, 15 Aug 1997 10:56:53 -0400
From: Craig Martin <cmartin@interware.net>
Subject: Need Help!
Message-Id: <33F46E35.163C@interware.net>

Hi There!

My name is Craig Martin and I work for an ISP in Toronto, Ontario,
Canada. This newsgroup has been very helpful in the past to me and I
thank everyone involved for this. I have yet another problem which I
need help with.

I have a PERL script setup to grab information entered on a form and
create a nice e-mail message that is legible. The only thing I can't
seem to figure out is how to put the date in here. I have tried the
system("date") idea but that gets me nowhere fast. If anyone has any
ideas on how I can grab the date and then place it in the e-mail message
I would love to hear them!

Thanks in advance.
-- 
	Craig Martin
	cmartin@interware.net
	http://www.interware.net
	mailto:cmartin@interware.net


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

Date: Fri, 15 Aug 1997 09:00:21 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: Craig Martin <cmartin@interware.net>
Subject: Re: Need Help!
Message-Id: <Pine.GSO.3.96.970815085915.1951U-100000@julie.teleport.com>

On Fri, 15 Aug 1997, Craig Martin wrote:

> Subject: Need Help!

Please check out this helpful information on choosing good subject
lines. It will be a big help to you in making it more likely that your
requests will be answered.

    http://www.perl.com/CPAN/authors/Dean_Roehrich/subjects.post

> how I can grab the date 

    $today = localtime; 

Hope this helps!

-- 
Tom Phoenix           http://www.teleport.com/~rootbeer/
rootbeer@teleport.com  PGP   Skribu al mi per Esperanto!
Randal Schwartz Case:  http://www.rahul.net/jeffrey/ovs/



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

Date: Fri, 15 Aug 1997 08:25:45 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: Mattias Brunschen <mb@sfb3.b.eunet.de>
Subject: Re: Net::FTP documentation and examples
Message-Id: <Pine.GSO.3.96.970815081634.1951N-100000@julie.teleport.com>

On Fri, 15 Aug 1997, Mattias Brunschen wrote:

> > : For docs, try perldoc Net::FTP.  

> I tried it, but the only response is
> "No documentation found for 'Net::FTP'"
> 
> Could you please just post a www-link or something like that
> where to find the docs ?

I don't think they're on the web in a browser-readable form, but I haven't
looked. :-)  But wouldn't it be better for you to find out how to fix
perldoc, so that you can get _all_ the docs for _all_ the modules? (Maybe
Net::FTP isn't installed in any of the @INC directories; try 'perldoc
perldoc' to see what you can do about that.)

But if you can't fix perldoc, you should still be able to read the POD
docs in Net::FTP with any text reader. (That is, open up the FTP.pm file
and look for "=head". The docs follow that line.)

Hope this helps!

-- 
Tom Phoenix           http://www.teleport.com/~rootbeer/
rootbeer@teleport.com  PGP   Skribu al mi per Esperanto!
Randal Schwartz Case:  http://www.rahul.net/jeffrey/ovs/



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

Date: Wed, 13 Aug 1997 16:56:55 -0400
From: "D. Sean Davidson" <davidson@zk3.dec.com>
Subject: Re: NetBSD-current pmax bug with perl5.00401
Message-Id: <33F21F97.37A42C20@zk3.dec.com>

I finally tracked this down to a problem in the NetBSD-current pmax modf
code that was being called in the pp.c PP(pp_int) routine.

Sean


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

Date: 15 Aug 1997 14:48:28 GMT
From: "Kevin Genus" <kgenus@us.newbridge.com>
Subject: NT File Permission Assignment
Message-Id: <01bca98b$2c976980$a346788a@new.us.newbridge.com>

Is there are module or process that I can employ which will allow me to
add/remove file and directory permissions from a perl script.

I've got a file with various directories and permission schemes taken from
a mac which are to be migrated to NT.  As of now, the files are:

directory		mac file permissions
\\server\share\directory,fold file chg

With what tools would one go about assigning these permissions?  My scripts
are done, I need only add this to them.

-Kevin Genus



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

Date: 15 Aug 1997 14:53:32 GMT
From: nvp@shore.net (Nathan V. Patwardhan)
Subject: Re: Pass arguments to Perl
Message-Id: <5t1qhc$39g@fridge-nf0.shore.net>

Wei Tang (wtang@cs.ualberta.ca) wrote:

: Could someone tell me how to pass command-line arguments in Perl? Will
: $ARGV work?

No, $ARGV won't work - $ARGV represents the current file when you're
using the diamond operator, <>.

You're looking for @ARGV, which is documented in perlfunc and perlvar
(look in perlvar first).  You might also look into the Getopt modules.

--
Nathan V. Patwardhan
nvp@shore.net



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

Date: 15 Aug 1997 15:39:23 GMT
From: "Kevin Halleran" <khallera@hklaw.com>
Subject: Re: Possible in Perl? Do it, I'll Pay ya!
Message-Id: <01bca991$925928c0$61064696@KevinWork>

I posted yesterday to this group regarding this question.  the only problem
I'm having is with the sockaddr_in function.  Please help.

Kevin

> it's certainly possible and almost already completely written on page
> 349 of Programming Perl, 2nd Edition not to mention the perlipc man page.
> 
><SNIP>
> -- 
> brian d foy                                   <comdog@computerdog.com>
> 


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

Date: 15 Aug 1997 15:17:47 GMT
From: nvp@shore.net (Nathan V. Patwardhan)
Subject: Re: Question of using stat function
Message-Id: <5t1rur$4ar@fridge-nf0.shore.net>

Jerry Xia (jxia@worldnet.att.net) wrote:

: I tried to get the access permission for a file. I got file mode(big
: integer number) by using stat() function. But how can I interpret that mode
: in Perl? If somebody has the answer, please post it.

I think you're looking for the %o option for printf.

perl -e 'printf("%o\n", (stat "filename")[2]);'

--
Nathan V. Patwardhan
nvp@shore.net



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

Date: Fri, 15 Aug 1997 08:11:24 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: Marcel Turcotte <M.Turcotte@icrf.icnet.uk>
Subject: Re: Reading regexp from a file
Message-Id: <Pine.GSO.3.96.970815080904.1951K-100000@julie.teleport.com>

On 15 Aug 1997, Marcel Turcotte wrote:

> while (<CONF>) {
>     next if (/^#/ || /^$/);
>     push(@filter,$_);
> }

Note that elements of @filter will have a trailing newline. (Except maybe
the last one.) Since those are your regular expressions, the newline will
be significant. I think you want chomp(). Hope this helps!

-- 
Tom Phoenix           http://www.teleport.com/~rootbeer/
rootbeer@teleport.com  PGP   Skribu al mi per Esperanto!
Randal Schwartz Case:  http://www.rahul.net/jeffrey/ovs/



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

Date: Fri, 15 Aug 1997 11:49:00 -0400
From: Tony Labbiento <tonylabb@infonline.net>
Subject: Re: Using perl noninternet, stand alone for processing!!????????!!!!
Message-Id: <33F47A6C.CA8AF14F@infonline.net>

This is a cryptographically signed message in MIME format.

--------------ms1BF1965AD2172891FF7A5B7B
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

Matthew Wagley wrote:

>   I am wanting to use perl on my system at work to compile and tear
> down
> *.txt files.  I can not find any resource to this effect on the net.
> All
> of the relate to perl for the internet on using it on your site or
> pages.
> I want to use this at work.  I have read books and such, still a
> newbie,
> but I can't figure out the /usr/page/  blah blah blah to turn into
> terms
> that my windows95 or DOS can understand instead of for Unix.
>   Your help is appreciated very much.
> Thanks in advance.
> Matthew Wagley

Matt,

    You can find PERL for Win95/NT at http://www.activeware.com. I hope
this helps.

--
   ****************************************
   *    Tony Labbiento                    *
   *    Infinity Online, Inc.             *
   *    Programmer/Network Administrator  *
   ****************************************


--------------ms1BF1965AD2172891FF7A5B7B
Content-Type: application/x-pkcs7-signature; name="smime.p7s"
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="smime.p7s"
Content-Description: S/MIME Cryptographic Signature

MIIRbQYJKoZIhvcNAQcCoIIRXjCCEVoCAQExCzAJBgUrDgMCGgUAMAsGCSqGSIb3DQEHAaCC
D2UwggqvMIIKGKADAgECAhB6h0vRx+CTFUsiPCAFqCPIMA0GCSqGSIb3DQEBBAUAMGIxETAP
BgNVBAcTCEludGVybmV0MRcwFQYDVQQKEw5WZXJpU2lnbiwgSW5jLjE0MDIGA1UECxMrVmVy
aVNpZ24gQ2xhc3MgMSBDQSAtIEluZGl2aWR1YWwgU3Vic2NyaWJlcjAeFw05NzA1MTYwMDAw
MDBaFw05NzExMTUyMzU5NTlaMIIBEjERMA8GA1UEBxMISW50ZXJuZXQxFzAVBgNVBAoTDlZl
cmlTaWduLCBJbmMuMTQwMgYDVQQLEytWZXJpU2lnbiBDbGFzcyAxIENBIC0gSW5kaXZpZHVh
bCBTdWJzY3JpYmVyMUYwRAYDVQQLEz13d3cudmVyaXNpZ24uY29tL3JlcG9zaXRvcnkvQ1BT
IEluY29ycC4gYnkgUmVmLixMSUFCLkxURChjKTk2MSYwJAYDVQQLEx1EaWdpdGFsIElEIENs
YXNzIDEgLSBOZXRzY2FwZTEXMBUGA1UEAxMOVG9ueSBMYWJiaWVudG8xJTAjBgkqhkiG9w0B
CQEWFnRvbnlsYWJiQGluZm9ubGluZS5uZXQwgZ8wDQYJKoZIhv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SutbeDlJhMCYPog==
--------------ms1BF1965AD2172891FF7A5B7B--



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

Date: 15 Aug 1997 16:02:36 GMT
From: "Eric D. Friedman" <friedman@uci.edu>
Subject: Re: Why doesn't sort take a reference any more?
Message-Id: <5t1uis$6pi@news.service.uci.edu>

[mailed, posted]

In article <EEy933.92K@world.std.com>,
Andrew M. Langmead <aml@world.std.com> wrote:
<
<You can get the same effect by dereferencing the subref in an
<anonymous block:
<
<    sort { &$compsub } (keys %hash)
<
<Or if you use named (rather than anonymous) subroutines, you can use
<the name of the subrotine to use as a parameter.
<
<sub foo {}
<sub bar {}
<
<$compsub = 'foo';
<
<sort $compsub
<
<Or you can use typeglobs (which I guess in this case is just a way of
<turning an anymous sub into a named sub):
<
<*compsub = sub { ... };
<sort compsub (keys %hash)

It may be helpful to know that you can localize that typeglob.  When I
asked this same question ~5 months ago, I believe it was Andrew (or
maybe Michael Constant? They both replied, and very helpfully too) who
pointed out that the local typeglob solution was more efficient than
dereferncing the subroutine reference in an anonymous block, because
you eliminate the overhead of dereferencing every time your sort
routine is called (a lot, potentially).

Thus, I came up with something like this:

sub sort_dir_contents
{
  my ($self, $dir, $code) = @_;
  my $func = eval $code;  # $code contains a text representation of an
                          # anonymous sub which, when eval'ed, returns
                          # a reference to $func;
                          # for example: $code = 'sub { $b <=> $a }';
  $self->error("Bad sort function: $code. Check config file: $@") if $@;
  local *sort_function = $func;  # Give the anonymous sub a name,
                                 # temporarily

  opendir DIR, $dir or $self->error("Can't open directory $dir: $!");
  my @directories = sort sort_function # Sort with user defined function
                    grep -d,           # a list of directories
                    map "$dir/$_",     # mapped out to their complete paths
                    grep !/^\.\.?$/,   # but with no dot files.
                    readdir DIR;
  return wantarray ? @directories : \@directories;
}

Though it's probably still available on DejaNews (which you did check,
right ;-) ), here's the thread as I've saved it.


>>> perl:78

 -- using Eric's mhl.format template --
Date:    Sun, 30 Mar 1997 06:04:51 PST
From:    "Eric Daniel Friedman" <FRIEDMAN@uci.edu>
To:      friedman@uci.edu
Newsgroups: comp.lang.perl.misc
Organization: University of California, Irvine
Fcc:     perl
Subject: Why is no subscripting allowed in custom sort routines?

[perl 5.002; SunOS medusa.acs.uci.edu 5.4 Generic_101945-13 sun4m sparc]

With reference to the syntax for custom sort routines, the manpage on
sort says

"SUBNAME may be a scalar variable name, in which case the value provides
the name of the subroutine to use. In place of a SUBNAME, you can
provide a BLOCK as an anonymous, in-line sort subroutine."

Consequently the following does not work:

use strict;
my @foo = qw( cat mouse dog fish bird squirrel zebra );
my $routine = sub { $a cmp $b };
my @sorted_foo = sort &$routine @foo;

My question:  how can I write an anonymous sort subroutine that is NOT
an in-line BLOCK? I want to be able to create a reference to a default
sort routine which I could then change if one condition or another is
met.

As in the following pseudocode:

if ( defined($opt_s) ) {
        $sort = eval "sub { $opt_s };";
} else {
        $sort = sub {$a cmp $b};
}

foreach (sort &$sort @dirs) {
        ...
}

At present it seems that only named subroutines or IN-LINE BLOCKS will
work, and that neither of these is suited for the task spelled out
above.

I suppose I could eval the whole foreach loop using the BLOCK syntax,
but that seems like a major kludge.

if ( defined($opt_s) ) {
        eval "foreach (sort { $opt_s } \@dirs) { do stuff }";
} else {
        eval "foreach (sort {\$a cmp \$b} \@dirs) { do stuff }";
}
-- 
Eric D. Friedman
friedman@uci.edu



>>> perl:79

 -- using Eric's mhl.format template --
Date:    Mon, 31 Mar 1997 02:22:01 GMT
From:    aml@world.std.com (Andrew M. Langmead)
>From aml@world.std.com Sun Mar 30 23: 04:55 PST 1997
Article: 72048 of comp.lang.perl.misc
Newsgroups: comp.lang.perl.misc
Organization: The World @ Software Tool & Die
Subject: Re: Why is no subscripting allowed in custom sort routines?

friedman@medusa.acs.uci.edu (Eric D. Friedman) writes:


>Consequently the following does not work:

>use strict;
>my @foo = qw( cat mouse dog fish bird squirrel zebra );
>my $routine = sub { $a cmp $b };
>my @sorted_foo = sort &$routine @foo;

>My question:  how can I write an anonymous sort subroutine that is NOT
>an in-line BLOCK? I want to be able to create a reference to a default
>sort routine which I could then change if one condition or another is
>met.

One suggestion is:

my @sorted_foo = sort { &$routine } @foo;

But it is a little slower because there is an extra subroutine
call. (The block calls the subroutine by reference)

In "Programming Perl" 2ed, it says that the scalar can contain a
reference to a subroutine, so maybe its just another case of the
implementation needing to catch up to the documentation, and someday
you will be able to just say

my @sorted_foo = sort $routine @foo;

Another idea is to keep the name of the sort subroutine fixed, and
eval a string that creates a subroutine of that name at runtime.

$sortsub = $opt_s || '$a cmp $b';

eval "sub by_specified_criteria { $sortsub }"; 
die $@ if $@;

foreach (sort by_specified_criteria @dirs) {
  # do stuff
}


Even your idea of eval'ing the entire sort statement could be made a
little easier by taking the sorting out of the for loop.

if ($opt_s) {
  @sorted_dirs = eval "sort  $opt_s \@dirs";
}
else {
  @sorted_dirs = sort @dirs; # same as 'sort { $a cmp $b } @dirs'
}

foreach (@sorted_dirs) {
  # do stuff
}
-- 
Andrew Langmead





>>> perl:80

 -- using Eric's mhl.format template --
Date:    30 Mar 1997 23:27:37 PST
From:    mconst@soda.CSUA.Berkeley.EDU (Michael Constant)
>From mconst@soda.CSUA.Berkeley.EDU Mon Mar 31 09: 35:45 PST 1997
Article: 72070 of comp.lang.perl.misc
Newsgroups: comp.lang.perl.misc
Organization: Society for the Prevention of Cruelty to Vegetables, UC Berkeley
NNTP-Posting-Host: soda.csua.berkeley.edu
Subject: Re: Why is no subscripting allowed in custom sort routines?

Eric D. Friedman <friedman@medusa.acs.uci.edu> wrote:
>    my $routine = sub { $a cmp $b };
>    my @sorted_foo = sort &$routine @foo;
>
>My question:  how can I write an anonymous sort subroutine that is NOT
>an in-line BLOCK?

Give your anonymous subroutine a name, for a while:

    local *anonymous = $routine;
    sort anonymous @foo;

See perlmod(1) under "Symbol Tables" for an explanation of what it
means to assign to a typeglob.
-- 
        Michael Constant (mconst@soda.csua.berkeley.edu)


-- 
Eric D. Friedman
friedman@uci.edu


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

Date: 15 Aug 1997 16:03:34 GMT
From: schmidt@miserv2iai.kfk.de (Andreas Schmidt)
To: John Tucker <jatucker@austin.dsccc.com>
Subject: Re: XS (converting perl array to char**..)
Message-Id: <5t1ukm$7ga$1@nz12.rz.uni-karlsruhe.de>

In article <33F37489.54F1@austin.dsccc.com>, John Tucker <jatucker@austin.dsccc.com> writes:
|> Hello,
|> 
|> I'm using perlxs to create a perl extension package for a set C
|> functions
|> and most of thes functions expect a "char**" member which represents an
|> array of file pathnames.
|> 
|>   In my perl ".xs" file I would like to create a direct mapping
|>   to the C function,  by allowing someone to call it
|>   from a perl script with a perl array variable for the files
|>   and then be apple to translate that array into the "char**"
|>   format expected by your function.
|> 
|>   The following shows a the way I want the Perl interface to
|>   the C function to be and the ".xs" code that I'm trying to develop:
|> 
|>   ---------------------------------------------------------------------
|>   #!/usr/local/bin/perl
|> 
|>   use MyExt;
|> 
|>   my $result = &MyExt::func(@files, "fixed all errors.");
|> 

<snip>

hi john

here is a little xs - function that allows the access to the perl array.
there is no use of typemaps and no error checking it simply shows the
principle.


the perl script looks like:

 ...
my @a=('a','b','c','d','e','f');
my $in =\@a;
print test::input($in);
 ...

and the xs-function is the following:

static void
input(sv)
        SV * sv
    PPCODE:
	AV *av = (AV *) SvRV(sv);
        int lastpos = av_len(av);
	printf("the len of the array is %d\n", lastpos + 1);
        int len = av_len(av);
        int lval = 0;
        for (int i=0; i < lastpos + 1; i++ ) {
	     SV ** ssv = av_fetch(av, i, lval);
	     char * elem = SvPV(*ssv, na);
	     printf("  -> '%s'\n", elem);
        }
 
the output is something like:
       
the len of the array is 6
  -> 'a'
  -> 'b'
  -> 'c'
  -> 'd'
  -> 'e'
  -> 'f'


i use a reference to an array, instead the array itself, because in your
perl-script suggestion   

my $result = &MyExt::func(@files, "fixed all errors.");

perl could not differntiate between the first parameter (the array) and the
second parameter (the string). perl treats this as one array with $#files+1
elements.

hopethishelps
smiff

========================================================================
andreas schmidt                                email: schmidt@iai.fzk.de 
institut fuer angewandte informatik (iai)        phone: +49 7247 82 5714
forschungszentrum karlsruhe gmbh
    - technik und umwelt -       
postfach 3640                                  76021 karlsruhe (germany)

 



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

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


Administrivia:

The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc.  For subscription or unsubscription requests, send
the single line:

	subscribe perl-users
or:
	unsubscribe perl-users

to almanac@ruby.oce.orst.edu.  

To submit articles to comp.lang.perl.misc (and this Digest), send your
article to perl-users@ruby.oce.orst.edu.

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.

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

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

For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V8 Issue 874
*************************************

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