[13196] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 606 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Aug 20 20:07:16 1999

Date: Fri, 20 Aug 1999 17:05:11 -0700 (PDT)
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, 20 Aug 1999     Volume: 9 Number: 606

Today's topics:
    Re: $8.99 NT/UNIX HOST, 100 megs, UNLIM HITS! CHEAP! Ju <arunas@an!m.org>
    Re: Attn: CRAP (was Re: voting system pealse advise) (Larry Rosler)
    Re: Creating a perl extension. (Arved Sandstrom)
    Re: Creating a perl extension. <cassell@mail.cor.epa.gov>
        Do something with the 1st Nth of a Hash (Mesarchm)
    Re: exponentiation please explain what it means <meowing@banet.net>
    Re: Help with CGI::$ENV <makkulka@cisco.com>
    Re: How do I create a log consisting of warnings? (Larry Rosler)
    Re: How Perl handles time (Larry Rosler)
        Mail Script Question davidc1275@my-deja.com
    Re: NT Internet Explorer5.0 for perl script dguzak@ci.glendora.ca.us
    Re: Perl script for sending email on NT <cassell@mail.cor.epa.gov>
    Re: processing html on the fly part 2 (Larry Rosler)
    Re: processing html on the fly part 2 <flavell@mail.cern.ch>
    Re: Processing html on the fly <arunas@an!m.org>
    Re: recovering the query string while using CGI.pm gmahler@my-deja.com
    Re: recovering the query string while using CGI.pm <makarand_kulkarni@my-deja.com>
    Re: Recursing through directory headache (Sean McAfee)
    Re: Recursing through directory headache (Sean McAfee)
    Re: Recursing through directory headache (Ilya Zakharevich)
    Re: Regular Expression?? <jkeating@dna.ie>
    Re: Request for Comments: www.perl.com <tye@metronet.com>
    Re: Request for Comments: www.perl.com dguzak@ci.glendora.ca.us
    Re: Shell vs Perl (Sean McAfee)
    Re: Shell vs Perl kcounts@my-deja.com
    Re: Sort Files by Date and then Name (Larry Rosler)
    Re: Sort Files by Date and then Name (Larry Rosler)
    Re: The real reason people don't use CGI.pm (Arved Sandstrom)
    Re: The real reason people don't use CGI.pm (Alan Curry)
    Re: Why $|++ (was: Re: perl system()) (Neko)
        Digest Administrivia (Last modified: 1 Jul 99) (Perl-Users-Digest Admin)

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

Date: Fri, 20 Aug 1999 17:28:17 -0600
From: "Arunas Salkauskas" <arunas@an!m.org>
Subject: Re: $8.99 NT/UNIX HOST, 100 megs, UNLIM HITS! CHEAP! Just found it!
Message-Id: <37bde4a0@news.cadvision.com>

David Cassell wrote in message <37BDA8AD.CFA410E5@mail.cor.epa.gov>...
>Philip 'Yes, that's my address' Newton wrote:

>I hope you also noticed that FrontPage not only produces
>lousy HTML, but cannot spell its own name either.  Spell
>checker, anyone?
>
>David
>--
>David Cassell, OAO                     cassell@mail.cor.epa.gov
>Senior computing specialist
>mathematical statistician

Sure: checker

That was easy, you gave away the answer!
--
- Arunas Salkauskas
High Point Designs
www.highpointdesigns.com






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

Date: Fri, 20 Aug 1999 16:03:23 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Attn: CRAP (was Re: voting system pealse advise)
Message-Id: <MPG.12277e91593465e7989e84@nntp.hpl.hp.com>

In article <7pkivn$32p$1@216.39.141.200> on 20 Aug 1999 21:57:11 GMT, 
Neko <tgy@chocobo.org> says...
> On 20 Aug 1999 08:08:55 GMT, sholden@pgrad.cs.usyd.edu.au (Sam Holden) wrote:
> 
> >On Fri, 20 Aug 1999 00:49:36 -0700, Larry Rosler <lr@hpl.hp.com> wrote:
 ...
> >>  ({
> >>	add_topic	=>	\&add_topic,
> >> 	showvote	=>	\&showvote,
> >> 	others	=>	\&others,
> >> 	vote		=>	\&vote,
> >> 	results	=>	\&results,
> >> 	delete	=>	\&delete,
> >>  }->{$FORM{action})->();
> >
> >eval "&$FORM{action}()";
> >
> >Why use a hash when you have got the symbol table I say ;)
> 
> Or if the prospect of running unknown code through eval() scares you:
> 
>    $FORM{action}->();

At least the 'eval' form makes it through "use strict 'refs';"

And both of these approaches assume that the names of the subroutines 
are the same as the values of $assFORM{action}, which isn't necessary in 
general.

-- 
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


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

Date: Fri, 20 Aug 1999 19:40:39 -0300
From: Arved_37@chebucto.ns.ca (Arved Sandstrom)
Subject: Re: Creating a perl extension.
Message-Id: <Arved_37-2008991940390001@dyip-2.chebucto.ns.ca>

In article <37BDB6F2.BC6917BE@anlon.com>, Kangas <kangas@anlon.com> wrote:

> Where is the best place for some documentation on creating a perl
> extension. I don't care if all it does is print 'Hello, World.'. I just
> want to try it.
> 
The 'perlxstut' manpage. This will get you started.


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

Date: Fri, 20 Aug 1999 16:39:18 -0700
From: David Cassell <cassell@mail.cor.epa.gov>
Subject: Re: Creating a perl extension.
Message-Id: <37BDE726.14C93DD6@mail.cor.epa.gov>

Arved Sandstrom wrote:
> 
> In article <37BDB6F2.BC6917BE@anlon.com>, Kangas <kangas@anlon.com> wrote:
> 
> > Where is the best place for some documentation on creating a perl
> > extension. I don't care if all it does is print 'Hello, World.'. I just
> > want to try it.
> >
> The 'perlxstut' manpage. This will get you started.

Hmm.  I guess it's a good thing I didn't answer Mike's post,
because this was totally different from what *I* thought he 
was asking.

I thought he was asking about using filename extensions and
mapping in order to get web servers to recognize Perl programs
as CGI scripts.  There's an entire section in the ActivePerl
FAQ on webserver config, which would have been appropriate
if I had been right.

Oh well.  Or as they say in Quebec, c'est la vie.  :-)

David
-- 
David Cassell, OAO                     cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician


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

Date: 20 Aug 1999 23:56:50 GMT
From: mesarchm@aol.com (Mesarchm)
Subject: Do something with the 1st Nth of a Hash
Message-Id: <19990820195650.04216.00000139@ng-fi1.aol.com>

How can I print out the 1st Nth values of a hash?

foreach $key (sort { $problems{$b} cmp $problems{$a} }  keys %problems)
		{
			$item = $problems{"$key"};
			print "$key $item\n<br>";
		}
If you can help I'd appreciate it.
Thanks,
Mike


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

Date: 20 Aug 1999 18:56:06 -0400
From: meow <meowing@banet.net>
Subject: Re: exponentiation please explain what it means
Message-Id: <87so5eawop.fsf@banet.net>

David Cassell <cassell@mail.cor.epa.gov> wrote:

> Ben Horowitz wrote:
> Given your question, I don't think that 'exponentiation' is
> the word you were looking for.  'Interpolation' maybe?

I think it was the first.  It looks as though the original poster
chose to start learning Perl by reading the perlop docs (that would be
one scary place to start, but hey, whatever works), which sure enough
begins by showing a huge table of weird punctuation and jumps into
exponentiation early on.

Probably the best idea, is not to start with perlop :/


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

Date: Fri, 20 Aug 1999 15:49:59 -0700
From: Makarand Kulkarni <makkulka@cisco.com>
Subject: Re: Help with CGI::$ENV
Message-Id: <37BDDB97.613335F7@cisco.com>

[ "Jason W. Storer" wrote:

> Does anyone know an online resource to find all the uses of the $ENV hash?
> All I know right now is how to get the url parameters (?...&...)?  Thanks!

There is no online resource listing all the possible uses of $ENV{}

The following resource http://hoohoo.ncsa.uiuc.edu/cgi/env.html documents
the usage of $ENV{} in CGI programs.

--



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

Date: Fri, 20 Aug 1999 16:17:04 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: How do I create a log consisting of warnings?
Message-Id: <MPG.122781c8ce906a70989e86@nntp.hpl.hp.com>

In article <37bdb551.183805339@news2.channel1.com> on Fri, 20 Aug 1999 
20:13:58 GMT, Brian Pontz <pontz@channel1.com> says...

[Rearranged to put the question ahead of the answer.  And where is the 
attribution?]

> >When I run my script I get a bunch of warnings.  How do I get those
> >warning to print to a file so that I can read them later?
> 
> I'm no expert but I would prob do a sub with warnings like
> 
> open(FILE "$file") || &Error("Couldnt open $file:$!");

I'll trade you those first two double-quotes and the ampersand for one 
comma in the open() call.
 
> sub Error {
> my($mesg)=@_;
> open (ERROR, ">>$errorfile") || die;
> print ERROR "$mesg\n";
> close(ERROR);
> exit 0;
> }

That would seem to handle exactly one explicit call to Error(), not 'a 
bunch of warnings'.

I think the warnings referred to may be Perl run-time warnings generated 
by the '-w' flag.  Probably the easiest thing to do is to intercept them 
by a handler like this:

   $SIG{__WARN__ = sub {
        # Append the argument to an already opened output file.\
   };

This is discussed under %SIG in perlvar.

-- 
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


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

Date: Fri, 20 Aug 1999 16:22:35 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: How Perl handles time
Message-Id: <MPG.12278319d496940e989e87@nntp.hpl.hp.com>

In article <37BDBD12.1054A39B@mail.cor.epa.gov> on Fri, 20 Aug 1999 
13:39:46 -0700, David Cassell <cassell@mail.cor.epa.gov> says...
> steveeq1@earthlink.net wrote:
 ...
> > Simple stuff. However, does anyone know how to do the opposite? That
> > is, take a date (Say, "03/01/99) and convert it to the long integer
> > (935175372)?
> 
> Umm, did you look in the FAQ?  Because this is a Frequently
> Asked Question.  You can use perldoc like this at a command
> line:
>    perldoc -q dates
> and find the answer to this question:
> "How can I compare two dates and find the difference?"
> 
> > Reason I need to do this is because I need to compare dates in perl and
> > comparing the long integers seems to be the best way to do it.
> 
> Yes, it probably is.  Perl has a number of modules which
> can help you here.  Most of them are in the Date:: hierarchy
> on CPAN.

That FAQ points to the wrong (big, slow, unwieldy) modules.  The 
following FAQ has it right (Time::Local).

How can I compare two dates and find the difference?

If you're storing your dates as epoch seconds then simply subtract one 
from the other. If you've got a structured date (distinct year, day, 
month, hour, minute, seconds values) then use one of the Date::Manip and 
Date::Calc modules from CPAN. 

How can I take a string and turn it into epoch seconds?

If it's a regular enough string that it always has the same format, you 
can split it up and pass the parts to timelocal in the standard 
Time::Local module. Otherwise, you should look into the Date::Calc and 
Date::Manip modules from CPAN. 

-- 
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


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

Date: Fri, 20 Aug 1999 23:54:57 GMT
From: davidc1275@my-deja.com
Subject: Mail Script Question
Message-Id: <7pkpsc$khn$1@nnrp1.deja.com>

I'm having a problem with a perl script. The
problem
we are having is with the E-mailing of
information to a
client. To make it simple, the script that sends
an Email
to someone when they enter their address (Mary
Smith in
the following example). The script includes the
following
lines for sending the mail:

 ...

open(MAIL,"|$mailprog -t");

print MAIL "To: Mary Smith\n";
print MAIL "From: John\n\n");
print MAIL "Subject: Information\n\n";

 ...

When the Email is received by the person however,
the "From"
field reads not "John",
but "John@whsun626.webhosting.com"

How do we get rid of the extra server info
following the name?
We've tried a few things but it always reads the
same.

Thank you for your time...


Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.


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

Date: Fri, 20 Aug 1999 22:48:45 GMT
From: dguzak@ci.glendora.ca.us
Subject: Re: NT Internet Explorer5.0 for perl script
Message-Id: <7pkm09$hts$1@nnrp1.deja.com>

Hmmmm I am somewhat new myself at this but ready to take a stab at
it.  Looks like one of these problems:

1) Your IIS is not properly "mapped" for .pl files
2) Your file is not in a directory that is set for script processing.
(Something about the attributes in there needs to be set.)
3) You don't have the proper extention on the file?

If your using NT I'm going to assume your using IIS.  My suggestion is
download option pack 4.  It's big, it takes forever, but for me it's
been worth it.

After you install Option Pack 4 and IIS looks totally alien to you,
download ActivePerl by ActiveState and install that.  It makes the file
associations "stupid simple".

Be careful about the security warnings, read the docs well in this
section, make sure your perl.exe is not available from any HTTP url or
bad things may happen.

A newbie mistake I made was viewing the .pl file directly through a
network share.  This will NOT work.  You have to have HTTP: at the
beginning of the line or your not viewing the file through IIS.
Basicly IIS has to think "Someone has asked for a file at this
location, hmmm but this file is a .pl extention.  (You can use CGI too
if it's mapped right but I like to be specific and use .pl)  I don't
send the file stright to them I send it to Perl first."

If my NT server crashed, I'd never map it manually again, I would just
use ActiveState's Active perl.

Have fun, best of luck, long live perl.

-Dave

In article <xziv3.276$ct6.82275@typhoon2.gnilink.net>,
  "mc" <mzchen@bellatlantic.net> wrote:
>
> 1st line:     #!e:/Perl/bin/perl    ( Do I need to put this line here
for
> NT?)

In my experience, no.


>
> Thanks in advance.
>
> mc

Your welcome


Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.


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

Date: Fri, 20 Aug 1999 16:35:51 -0700
From: David Cassell <cassell@mail.cor.epa.gov>
Subject: Re: Perl script for sending email on NT
Message-Id: <37BDE657.99395C6C@mail.cor.epa.gov>

SH wrote:
> 
> mc <mzchen@bellatlantic.net> wrote in message
> news:IHiv3.277$B55.68297@typhoon1.gnilink.net...
> > Does anyone know how to write Perl script to send email on NT?
> >
> >  on UNIX, it is like:
> >  open(MAIL, "|sendmail......)
> try sender.pm

One option.  But in the win32 FAQ (what is called the ActivePerl
FAQ in the ActivePerl HTML docs) there is a more thorough
answer.  If the poster looks in the docs that came with the
Perl install, s?he will find this question:
   "How do I send email from Perl for Win32?"
with references to Net::SMTP , Mail::Sender , Mail::Sendmail 
[all these have code included], and MTAs for win32 such
as Blat, wrmail, and the NT version of sendmail.

So, as usual in Perl, TMTOWTDI.

David
-- 
David Cassell, OAO                     cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician


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

Date: Fri, 20 Aug 1999 15:06:30 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: processing html on the fly part 2
Message-Id: <MPG.12277142648b6a68989e82@nntp.hpl.hp.com>

In article <Pine.HPP.3.95a.990820215102.17601B-100000@hpplus03.cern.ch> 
on Fri, 20 Aug 1999 22:10:50 +0200, Alan J. Flavell 
<flavell@mail.cern.ch> says...
> On Fri, 20 Aug 1999, Larry Rosler wrote:
> 
> > > > When I run a perl script from my cgi-bin that processes an HTML page
> > > > and then spits the page out to the browser, the web browser treats the
>                                                       ^^^^^^^^^^^
> > > > cgi-bin as the starting directory to find images and reference all the
> > > > paths in the web page. 
> > > 
> > > Of course.  If you're writing CGI scripts, then this elementary fact
> > > should be well known to you.
> > 
> > It's not well known to me.
 ...
> When the _browser_ retrieves a document from the server, it does it by
> means of a URL.  That URL defines (by means of its hierarchical
> components, separated by "/") a logical hierarchy.  It (the browser)
> neither knows nor cares which directory of the server's local file
> system contains it. 
> 
> When the resultant document contains relative URLs, the browser resolves
> those URLs by reference to the "base URL" of the document which contains
> them, and that is the whole issue that seemed to be under discussion in
> the previous thread.

Yes.  But the "base URL" is the server's web root directory, which has 
nothing whatever to do with the cgi-bin directory, which the poster 
described as being treated 'as the starting directory to find images and 
reference all the paths in the web page.' 

To which you responded "Of course."

To which I respond "Of course not!".

But there are no Perl issues here whatsoever.

-- 
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


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

Date: Sat, 21 Aug 1999 01:36:00 +0200
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: processing html on the fly part 2
Message-Id: <Pine.HPP.3.95a.990821013507.9119A-100000@hpplus03.cern.ch>


Get the sackcloth and ashes ready, I'm just going to review this thread
again and see if I can work out what went wrong.



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

Date: Fri, 20 Aug 1999 17:26:07 -0600
From: "Arunas Salkauskas" <arunas@an!m.org>
Subject: Re: Processing html on the fly
Message-Id: <37bde41d@news.cadvision.com>

Base is a nuisance too, since you have to go through all your pages and
change that if you want to move them someplace.

Things like this can be facilitated with the PATH_TRANSLATED variable.  But
these are not Perl issues - lookup CGI, and look at the documentation for
your web server.

--
- Arunas Salkauskas
High Point Designs
www.highpointdesigns.com

Alessandro Guffanti wrote in message <37BD7B10.2172672C@sanger.ac.uk>...
>Hi. This is an HTML and not a Perl problem.
>Just add a <BASE href="http://your.doc.dir">
>in the <HEAD> part of the HTML file and all
>the relative links will refer to the BASE.
>Not quite sure about the syntax of <BASE>
>but you can retrieve it from any HTML guide.
>
>BW,
>
>Alessandro G.
>
>Mandarin Lodge #343 wrote:
>>
>> When I run a perl script from my cgi-bin that processes an HTML page and
>> then spits the page out to the browser, the web browser treats the
cgi-bin
>> as the starting directory to find images and reference all the paths in
the
>> web page. I want the web browser to look in another directory, say
>> http_docs, and use that as the base path. How can I accomplish this in
perl?
>> Is their an ENV var I need to set or something?
>>
>> Thanks,
>>
>> Jeff
>>
>> smile777@hotmail.com
>
>--




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

Date: Fri, 20 Aug 1999 22:52:46 GMT
From: gmahler@my-deja.com
Subject: Re: recovering the query string while using CGI.pm
Message-Id: <7pkm7q$i0s$1@nnrp1.deja.com>

In article <37BDC98F.17A1B559@cisco.com>,
  Makarand Kulkarni <makkulka@cisco.com> wrote:

> The function you can call is query_string(). This is mentioned in the
> part where HTTP session variables are discussed ( in the CGI.pm doc).
> You can even use $ENV{'QUERY_STRING'} to get this value.
>

Thans for replying.  Actually, it seems that whenever I
use the statement "use CGI(:standard)" all of a sudden
things like $ENV{'QUERY_STRING') don't return anything,
and moreover, I think query_string() must be accessed
by a CGI object, which I don't know how to create before
losing the query string to the "use CGI(:standard)" statement.
For instance,

use CGI(:standard);
$qs = $ENV{'QUERY_STRING'};
print $ps;

does nothing becuase I assume the first line eats
all the environment variable info.  Also, to use
query_string() I though you'd have to do somehthing
like (I forget the syntax)

use CGI(:standard);
$x = new CGI;
print $x->query_string;

and in this case still nothing happens because, again,
(and I admit I don't understand the magic behind CGI.pm),
"use CGI(:standard)" eats the data.

I wanted to try

use CGI(:standard);
$x=new CGI( $the_query_string );

so that "print $x->query_string" would give me what I
want, but obtaining the_query_string is my original
question.

Anybody do this before?  I mean, I can do it the long
way, using POST, like the previous poster suggested,
but I thought CGI.pm would make it available.

Thanks to the previous poster as well!

Greg




Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.


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

Date: Fri, 20 Aug 1999 23:43:19 GMT
From: Makarand Kulkarni <makarand_kulkarni@my-deja.com>
Subject: Re: recovering the query string while using CGI.pm
Message-Id: <7pkp6l$k4p$1@nnrp1.deja.com>

[In article <7pkm7q$i0s$1@nnrp1.deja.com>,
  gmahler@my-deja.com wrote:
> Thans for replying.  Actually, it seems that whenever I
> use the statement "use CGI(:standard)" all of a sudden
> things like $ENV{'QUERY_STRING') don't return anything,
> and moreover, I think query_string() must be accessed
> by a CGI object, which I don't know how to create before
> losing the query string to the "use CGI(:standard)" statement.
> For instance ..

The following code works perfectly for me
when called as  http://whatever/.../form.pl?value=v
and I am using CGI as standard.

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

use CGI qw(:standard);
print header() ;
print start_html ();
print "<BR>" ;
print "ENV= ",  $ENV{'QUERY_STRING'} . "<br>" ;
print "ENV= ", query_string() ."<br>" ;
print end_html ();

--results --
ENV= value=v
ENV= value=v


Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.


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

Date: Fri, 20 Aug 1999 22:25:55 GMT
From: mcafee@waits.facilities.med.umich.edu (Sean McAfee)
Subject: Re: Recursing through directory headache
Message-Id: <TBkv3.2598$J72.533169@news.itd.umich.edu>

In article <7pkhrd$ev1$1@nnrp1.deja.com>,  <unibrow@my-deja.com> wrote:
>I am trying to do a routine which recurses through
>a given directory tree at the same time renaming
>files.  The original routine which I put together
>worked just fine on NT, but when I tried it on Solaris
>it broke down.  Any ideas on a simple method of renaming
>files withing a directory tree of unknown depth?

>I recurse just fine, but the renames always fail.

First of all, you can find out why the renames fail.  That's what the error
variable $! is for.

rename($oldfile, $newfile) or die "Can't rename $oldfile to $newfile: $!\n";

You should *always* test the return value of a system call.

Second, I hate to break it to you, but the hard work has already been done.
Use the standard File::Find module.

----------------------------------------------------------------------
use File::Find;

sub my_rename {
    return unless -f && /(.*)\.(txt|csv)$/;
    my $new_file = $1 . uc($2);
    rename $_, $new_file or die "Can't rename $_ to $new_file: $!\n";
}

find \&my_rename, '/directory/to/start/';
----------------------------------------------------------------------

Use "perldoc File::Find" to get the details.

Also, there's a serious problem with one part of the code you posted:

>sub list
>{
> local($mdir) = @_;
> local($mname);
> local *MDIR;
>     unless (opendir(MDIR, $mdir)) {
>             return;
>     }
>     local $_;
>     foreach $mname (readdir(MDIR)) {
>             if ($mname eq '.' || $mname eq '..') { print("dots\n");}
>             else {
>                     if (-f $mdir.'/'.$mname) {
>                             $mname =~ /(.+)\.(.+)/;
                              ^^^^^^^^^^^^^^^^^^^^^^^
If the match fails, $1 and $2 remain *unchanged* from the previous match.
So, if you process the file "foo.csv", and the next file is called
"ignore-me", $1 and $2 still contain "foo" and "csv" (respectively) from
the previous match, and the program will happily attempt to rename
"ignore-me" to "foo.CSV".  *Always* test that a match succeeded before
using $1, $2, etc.

>                             if($2 eq "csv") {
>                                 unless(rename($mname, $1 . ".CSV")) {
>                                     die("Could not rename $1.csv\n");
>                                 }
>                             }
>                             if($2 eq "txt") {
>                                   unless(rename($mname, $1 . ".TXT")) {
>                                      die("Could not rename $1.txt\n");
>                                   }
>                             }

This would be written in a more Perl-like fashion as follows:

if ($mname =~ /(.*)\.csv$/) {
	rename $mname, "$1.CSV" or die "Can't rename $mname: $!\n";
} elsif ($mname =~ /(.*)\.txt$/) {
	rename $mname, "$2.TXT" or die "Can't rename $mname: $!\n";
}

Even shorter possibilities exist (see my File::Find code above).

-- 
Sean McAfee                                                mcafee@umich.edu
print eval eval eval eval eval eval eval eval eval eval eval eval eval eval
q!q@q#q$q%q^q&q*q-q=q+q|q~q:q? Just Another Perl Hacker ?:~|+=-*&^%$#@!


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

Date: Fri, 20 Aug 1999 22:27:25 GMT
From: mcafee@waits.facilities.med.umich.edu (Sean McAfee)
Subject: Re: Recursing through directory headache
Message-Id: <hDkv3.2599$J72.533259@news.itd.umich.edu>

In article <TBkv3.2598$J72.533169@news.itd.umich.edu>, I wrote:
>In article <7pkhrd$ev1$1@nnrp1.deja.com>,  <unibrow@my-deja.com> wrote:
>>                             $mname =~ /(.+)\.(.+)/;
>                              ^^^^^^^^^^^^^^^^^^^^^^^
>If the match fails, $1 and $2 remain *unchanged* from the previous match.

D'oh!  Make that the previous *successful* match.

-- 
Sean McAfee                                                mcafee@umich.edu
print eval eval eval eval eval eval eval eval eval eval eval eval eval eval
q!q@q#q$q%q^q&q*q-q=q+q|q~q:q? Just Another Perl Hacker ?:~|+=-*&^%$#@!


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

Date: 20 Aug 1999 23:32:09 GMT
From: ilya@math.ohio-state.edu (Ilya Zakharevich)
Subject: Re: Recursing through directory headache
Message-Id: <7pkohp$ce1$1@charm.magnus.acs.ohio-state.edu>

[A complimentary Cc of this posting was sent to Sean McAfee
<mcafee@waits.facilities.med.umich.edu>],
who wrote in article <TBkv3.2598$J72.533169@news.itd.umich.edu>:
> Second, I hate to break it to you, but the hard work has already been done.
> Use the standard File::Find module.

I hate to break it to you, but please explain how File::Find can work
in presence of renames.

Ilya


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

Date: Fri, 20 Aug 1999 23:16:45 +0100
From: "John Keating" <jkeating@dna.ie>
Subject: Re: Regular Expression??
Message-Id: <37bdd363@royan.d-n-a.net>

There is a good example of this in the Perl Cookbook (TC &NT) on page
198ish. I have modified it to take any number of arguments from
the command line and build an OR or AND pattern to be used
in the match. It works very well and you can have it if you email me
on john.keating@dna.ie. Further explanations of the recipes in
the Perl Cookbook may be found in Mastering Regular Expressions
(SG).

Hope this helps, John.

Pete wrote in message <37bce4c2.10981194@netnews.worldnet.att.net>...
>Something simple I would think ...
>
>We're using DBMAN (www.gossamer-threads.com) a Perl flat-file db
>application.  It allows for regular expression searches, we can do
>"or" searches -- cats|dogs -- OK but how do you do "cats and dogs?" in
>a PERL regular expression?  The searches iterate through the form
>fields looking for matches.
>
>Gary




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

Date: 20 Aug 1999 17:47:43 -0500
From: Tye McQueen <tye@metronet.com>
Subject: Re: Request for Comments: www.perl.com
Message-Id: <7pkluf$svv@beanix.metronet.com>

Tom Christiansen <tchrist@mox.perl.com> writes:
)     What you like at www.perl.com

About the only thing I use is the fast access to CPAN-local.  I
just went to the front page for the first time in weeks.  It looks
better.  You even fixed my top pet peave [not being able to find
mention of the e-mail lists].

)     What you don't like at www.perl.com

That to get to PAUSE I have to go hunting in CPAN-local and load
and click in half a dozen documents.  Searching for "PAUSE" finds
nothing.

That browsing (reference=>lists) gets one list of e-mail lists
that is almost completely different from the list of e-mail lists
that is the first link you find when searching for "mail" [and the
browsable one doesn't show up in the search].  That under
"Reference", e-mail lists are sorted under "lists" rather than
"e-mail" or "mail" where I would have looked.

That the "win32" link in /pub/language-info/mailing-lists.html is
broken.  Perhaps a verifier should be used?

That going one or two levels deep seems to get you to tons of
specific things which makes it hard to find the general, big
items.  Why is the announcement of Perl security issues
buried in the middle of a list of specific security-related
modules [because they are sorted alphabetically by title, of
course].

When I want something obscure, I go to altavista.com and search.
If I want something common, I go to yahoo.com because if I search
for "weather" on yahoo, the top of the page is going to have the
big, important links directly related to weather and some categories
that deal with specific weather things.

If I click on "security", I don't want an altavista-style list of
anything on the web site that mentions security [at least altavista
tries to sort by relevance, not alphabetically].  I want the the
big important links first [Perl security announcements, security
FAQ, link to perlsec.pod], followed by some categories [link to
list of modules and only modules dealing with security, link to
wider list of security-related documentation, link to list of
products that offer security features], then the list of specific
matches.

In fact, I care less about the list of specifics.  If I _click_ on
"security", I'd be happy with a hint or button at the bottom to
request the search for the specifics.

)     What you would like to see at www.perl.com

Big wish:  A decent search interface to e-mail and usenet groups. 
deja.com provides good search facilities [if you avoid their "new
look" by going in via infoseek.com, for example].  egroups.com
provides terrible search facilities to e-mail lists.  I'd _love_
to be able to submit one search that hits both Perl usenet groups
and Perl e-mail lists.

It needs a list describing and linking to the major Perl sites.

I think the headings and links need to include the _type_ of
information.  Many of them leave me wondering whether I'm going to
a list of modules related to that topic, a tutorial about writing
Perl code that deals with that topic, how that topic relates to
Perl itself, a list combining all of the above, etc.


Anyway, great job so far.  It looks like a major improvement so far.
-- 
Tye McQueen    Nothing is obvious unless you are overlooking something
         http://www.metronet.com/~tye/ (scripts, links, nothing fancy)


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

Date: Fri, 20 Aug 1999 23:01:36 GMT
From: dguzak@ci.glendora.ca.us
Subject: Re: Request for Comments: www.perl.com
Message-Id: <7pkmob$idn$1@nnrp1.deja.com>


>     What you like at www.perl.com

Clean look and feel.  I like how there is a good mix of newbie and
advanced questions answered right on the front page.  Keeps me coming
back.

>     What you don't like at www.perl.com

Quite a few dead links.

>     What you would like to see at www.perl.com

More Cookbook sections.

also, I would like a "stupid simple" module search or a FAQ of "Where
all the repositories are at and the best place to search the biggest
amount of them"  I understand the very nature of perl makes this
difficult.  This may be a bad newbie request, but... I'm a newbie.

>     What you might like to help with at www.perl.com

Everything, just give me time to learn Perl first.  I do have about 20
pounds of relevant O'Reilly books, so it shouldn't take toooo long.



Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.


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

Date: Fri, 20 Aug 1999 22:02:33 GMT
From: mcafee@waits.facilities.med.umich.edu (Sean McAfee)
Subject: Re: Shell vs Perl
Message-Id: <Zfkv3.2597$J72.532824@news.itd.umich.edu>

In article <7pkh1j$e79$1@nnrp1.deja.com>,  <kcounts@my-deja.com> wrote:
>The system administrator at my workplace doesn't believe
>that a  Perl program  can be written to mimic the functionality of the
>below shell script and still keep as simple as the shell script.

>!#/usr/bin/ksh
>if [ "$1" = "" ]
>    then sort -t: +2n -3 /etc/passwd
>else
>    grep "[:/]$1[:/]" /etc/passwd | sort -t: +2n -3
>fi

>He says it took him a page and a half in Perl.
>I know it can be more efficient.

#!/usr/local/bin/perl

@lines = do { local @ARGV = '/etc/passwd'; <> };
@lines = grep m|[:/] $ARGV[0] [:/]|x, @lines if $ARGV[0] ne "";
print map { $_->[0] }
     sort { $a->[1] <=> $b->[1] or $a->[2] cmp $b->[2] }
      map { [ $_, (split /:/)[2,0] ] } @lines;

I imagine it looks complicated to a beginner, but an intermediate to
advanced programmer ought to be able to apprehend it pretty quickly.  I've
used only established idioms.  In particular, the last three lines
constitute the "Schwartzian Transform"; see perlfaq4 for a full description
of how it works.

-- 
Sean McAfee                                                mcafee@umich.edu
print eval eval eval eval eval eval eval eval eval eval eval eval eval eval
q!q@q#q$q%q^q&q*q-q=q+q|q~q:q? Just Another Perl Hacker ?:~|+=-*&^%$#@!


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

Date: Fri, 20 Aug 1999 23:36:21 GMT
From: kcounts@my-deja.com
Subject: Re: Shell vs Perl
Message-Id: <7pkopk$k1f$1@nnrp1.deja.com>

Very nice Sean.

Thanks,
Kevin Counts

> #!/usr/local/bin/perl
>
> @lines = do { local @ARGV = '/etc/passwd'; <> };
> @lines = grep m|[:/] $ARGV[0] [:/]|x, @lines if $ARGV[0] ne "";
> print map { $_->[0] }
>      sort { $a->[1] <=> $b->[1] or $a->[2] cmp $b->[2] }
>       map { [ $_, (split /:/)[2,0] ] } @lines;
>
> Sean McAfee


Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.


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

Date: Fri, 20 Aug 1999 15:54:27 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Sort Files by Date and then Name
Message-Id: <MPG.12277c7f5f58df41989e83@nntp.hpl.hp.com>

In article <37BDC40F.7FD2BB20@cajunbro.com> on Fri, 20 Aug 1999 21:09:35 
+0000, Mark McCoy <mcking@cajunbro.com> says...
> Phillip Armitage wrote:
> > I'd like to put together a PERL routine which will read the names of
> > files in a given subdirectory, and then sort then by name and file
> > date.  eg. List all the files added to the directory today in
> > alphabetical order, then list the files added yesterday in
> > alphabetical order, and so on.
> > 
> > My currect code
> > 
> > @files=sort(map(uc($_),grep(m/$FILETYPE$/i,readdir(DIR))));
> > 
> > sorts by uppercase filename. I want to add in the date sorting
> > capability
> > 
> > If I were working in DOS I would obtain this kind of listing with the
> > command: DIR /O-DN *.*

Really?  That just sorts by date/time descending, and only files with 
identical date/times then get sorted by name.  Your problem 
specification wants all the files sorted by date only, and within each 
date sorted by name.

> > Anyone know if thiere exists a PERL function which will perform this
> > function. Otherwise, any suggestions on where to find or how to write
> > (pseudocode) this PERL code?

perldoc -f stat (to get the file-change date/time, which is the file-
creation date/time on Windows/DOS systems!)

perldoc -f localtime (to get the year and the day of the year, on which 
to base the primary sort)

perldoc -f sort

perlfaq4:  "How do I sort an array by (anything)?"

Tom Christiansen's FMTYEWTK about sorting.

Uri Guttman's and my ultimate paper on sorting, to be presented in 
Monterey on Monday, come one, come all.
<URL:http://www.hpl.hp.com/personal/Larry_Rosler/sort/>

> > I'm using Perl for Win32, running on a Windows 95C system
> > 
> > I look forward to your comments and suggestions.
> 
> hmm...you have the dos "dir" command and the nice `command` backtic operator.
> 
> Do I need to draw a picture?

Yes.  I think you should draw him a picture of me and many others 
throwing up at the use of a nonportable command that doesn't do the job 
requested in any case.

Oh, heck.  It was easy enough to write and test it, and to show everyone 
yet another example of the neat packed-default sorting techique.  Enjoy!


#!/usr/local/bin/perl -w
use strict;

my $dir = 'e:/sorting';
opendir DIR, $dir or die "Coudln't open '$dir'. $!\n";

print map { substr($_, 4) . "\n" }
      sort
      map {
          my ($year, $yday) = (localtime((stat "$dir/$_")[10]))[5, 7];
          pack('N' => -(366 * $year + $yday)) . uc
      } grep !/^\.\.?$/ # Stick your own grep here.
          => readdir DIR;

-- 
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


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

Date: Fri, 20 Aug 1999 16:08:24 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Sort Files by Date and then Name
Message-Id: <MPG.12277fc7bea98c43989e85@nntp.hpl.hp.com>

In article <xjg7lmqjezz.fsf@gamora.ndhm.gtegsc.com> on Fri, 20 Aug 1999 
21:53:20 GMT, Vincent Murphy <vmurphy@gamora.ndhm.gtegsc.com> says...
> >>>>> "Mark" == Mark McCoy <mcking@cajunbro.com> writes:
 ...
> opendir( DIR, $dir ) || die "can't open $dir: $\n";
> print map { "$_\n" } sort { -M "$dir/$b" cmp -M "$dir/$a" } readdir(DIR);
> closedir( DIR );

Your mother should have warned you about doing stat()s on files for each 
and every sort comparison.  Try that on a directory of, say, a thousand 
files, and go out for some coffee.

Mom: "Use the Schwartz, son!"  or, now, "Use the Packed-Default Sort!"

> For the today, yesterday, ... business you may want to consider the
> Date::Calc program module.  It may have what you need.

Gross overkill.  I posted how to do it.

-- 
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


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

Date: Fri, 20 Aug 1999 19:44:23 -0300
From: Arved_37@chebucto.ns.ca (Arved Sandstrom)
Subject: Re: The real reason people don't use CGI.pm
Message-Id: <Arved_37-2008991944230001@dyip-2.chebucto.ns.ca>

In article <GJiv3.13237$x04.800574@typ11.nn.bcandid.com>,
pacman@defiant.cqc.com (Alan Curry) wrote:

> Mainly, I think it's the documentation.
> 
In my case, the real reason is that I don't write any CGI's. Not in Perl,
shell or C. I also don't use Javascript, or PHP, or do Java servlets. I
program like a wild man, but contrary to popular opinion, it's possible to
write code and not even go near the Web. :-)

Arved Sandstrom
(another disgruntled scientific programmer)


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

Date: Fri, 20 Aug 1999 22:45:08 GMT
From: pacman@defiant.cqc.com (Alan Curry)
Subject: Re: The real reason people don't use CGI.pm
Message-Id: <UTkv3.13431$x04.814133@typ11.nn.bcandid.com>

In article <Arved_37-2008991944230001@dyip-2.chebucto.ns.ca>,
Arved Sandstrom <Arved_37@chebucto.ns.ca> wrote:
>In my case, the real reason is that I don't write any CGI's. Not in Perl,
>shell or C. I also don't use Javascript, or PHP, or do Java servlets. I
>program like a wild man, but contrary to popular opinion, it's possible to
>write code and not even go near the Web. :-)

Trade places with me. Please. :-)
-- 
Alan Curry    |Declaration of   | _../\. ./\.._     ____.    ____.
pacman@cqc.com|bigotries (should| [    | |    ]    /    _>  /    _>
--------------+save some time): |  \__/   \__/     \___:    \___:
 Linux,vim,trn,GPL,zsh,qmail,^H | "Screw you guys, I'm going home" -- Cartman


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

Date: 20 Aug 1999 22:16:42 GMT
From: tgy@chocobo.org (Neko)
Subject: Re: Why $|++ (was: Re: perl system())
Message-Id: <7pkk4a$32p$2@216.39.141.200>

On 20 Aug 1999 00:42:32 -0500, abigail@delanet.com (Abigail) wrote:

>David Cassell (cassell@mail.cor.epa.gov) wrote on MMCLXXX September
>MCMXCIII in <URL:news:37BC9BE1.C225EA2D@mail.cor.epa.gov>:
>## 
>## $|++;
>
>
>Why "$|++;"? I've seen this before, and frankly, it baffles me why
>someone would want to use this instead of "$| = 1;".

I saw this construct first in one of Randal's Web Techniques columns (or
maybe Unix Review).  I just looked at it for awhile.  I thought it was
unnecessarily obfuscated.  But now I've seen it so often, that it's
idiomatic.

Was Randal the first to do this?  Would he appreciate everyone calling it the
Schwartzian Autoflush? :)

>Would it be faster? No... a simple benchmark shows it's slower, 
>by almost a factor of 2.5:

There are better things to benchmark.  And I do not see how you got a factor
of 2.5.  Maybe 1.25?

>    Benchmark: timing 1000000 iterations of empty, plusplus, set...
>         empty: 13 secs (11.35 usr  0.00 sys = 11.35 cpu)
>      plusplus: 19 secs (17.32 usr  0.02 sys = 17.34 cpu)
>           set: 15 secs (13.81 usr  0.00 sys = 13.81 cpu)

-- 
Neko | tgy@chocobo.org | Will hack Perl for a moogle stuffy! =^.^=


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

Date: 1 Jul 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 1 Jul 99)
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" from
almanac@ruby.oce.orst.edu. The real FAQ, as it appeared last in the
newsgroup, can be retrieved with the request "send perl-users FAQ" from
almanac@ruby.oce.orst.edu. 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" from
almanac@ruby.oce.orst.edu. 

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 V9 Issue 606
*************************************


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