[13037] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 447 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Aug 10 13:17:16 1999

Date: Tue, 10 Aug 1999 10:10:15 -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           Tue, 10 Aug 1999     Volume: 9 Number: 447

Today's topics:
        problems with POSIX::isatty() <paul.glidden@unisys.com>
    Re: Reading the Online Documentation? <sariq@texas.net>
    Re: require mylib.pl (Kvan)
    Re: search and match <chris.evans@tc.faa.gov>
    Re: search and match <chris.evans@tc.faa.gov>
    Re: Simple write routine (Eric Bohlman)
    Re: suggestions for CRAP <admin@futuristic.net>
    Re: why doesn't this work? (Mitchell Morris)
    Re: Why use Perl when we've got Python?! <aqumsieh@matrox.com>
    Re: Why use Perl when we've got Python?! (Graham Ashton)
        Digest Administrivia (Last modified: 1 Jul 99) (Perl-Users-Digest Admin)

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

Date: Tue, 10 Aug 1999 11:16:12 -0500
From: "Paul Glidden" <paul.glidden@unisys.com>
Subject: problems with POSIX::isatty()
Message-Id: <7opj78$k21$1@eanews1.unisys.com>

My goal is to determine whether or not the perl script that is currently
running has been called from a tty or from a job such as cron.

So in order to do this I am trying to use POSIX::isatty(). Unfortunately I
am not getting any return from the function nor an error.

Is it possible for a script to be able to find out whether or not itself is
connected to a tty.

I could be invoking the function incorrectly also, but I am assuming not as
I am not getting an error of any type.  The perldoc states that you are
suppose to pass in a filehandle.  I have tried both the name of the script
and the pid.

The manpage for the C func isatty shows an int should be passed into the
function, which would make me assume it should be the pid.  So in order to
do that I called the function like this.
POSIX::isatty(POSIX::getpid());  no return from the function.

I then tried the name of the script calling the function as such as:
POSIX::isatty("filename");

I am assuming that the function should return a 0 or 1 as does the C isatty.
Is this correct?
Am I not using this function correctly, or could there be a problem with my
perl installation.

thanks,
Paul




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

Date: Tue, 10 Aug 1999 09:58:57 -0500
From: Tom Briles <sariq@texas.net>
Subject: Re: Reading the Online Documentation?
Message-Id: <37B03E31.2C79F52C@texas.net>

Mesarchm wrote:
> 
> I am not argueing that the docs aren't the best place to look 1st.  But what I
> am saying is that if people turn to you for help, being willing to help.  The
> perfect example is Mr. Know it all (Just Another Larry) Rosler Hewlett-Packard
> Laboratories.

I can attest to at least one thing that Larry *doesn't* know.  So there!

>  He answers 90% of the posts on this newsgroup w/ "Read the Docs"

That's because 90% of the questions are *answered* in the docs.

>  Get a life.

That was a great show!  I've been a Chris Elliott fan since his first
appearances on David Letterman.

*plonk*

- Tom


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

Date: Tue, 10 Aug 1999 15:38:41 GMT
From: kvan@dis.dk (Kvan)
Subject: Re: require mylib.pl
Message-Id: <37b0468e.17475398@news.newsguy.com>

On 10 Aug 1999 14:53:31 GMT, "Nick Downey" <nead@neadwerx.com> wrote:

>My question is then: Is there a better way to define a file of (50-60)
>constant strings, that is used across several scripts, or should I ignore
>the previous lines?

There is, of course, More Than One Way To Do It.

Firstly, you could do what you've been doing, but use a hash instead
of separate strings. Secondly, you could make a module. How to do this
is detailed in the Camel, or if you lack such a beast:

perldoc perlmod
perldoc perlmodlib

HTH,
Kvan.

-------Casper Kvan Clausen------ | 'A *person* is smart. People are
---------<kvan@dis.dk>---------- |  dumb, panicky, dangerous animals
                                 |  and you know it.'
                                 |        - "K" in Men in Black.


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

Date: Tue, 10 Aug 1999 12:32:41 -0400
From: "Christian Evans" <chris.evans@tc.faa.gov>
Subject: Re: search and match
Message-Id: <7opk7h$609$1@faatcrl.faa.gov>

i know the following code could be written much simpler, but when i am gone,
a beginner needs to be able to follow the code structure.

the variable script path is determined in another module (dir_menu)


system("clear");
 print "Please enter the file whose records you wish to search.\n";
 $in_ = <STDIN>;
 chomp $in_;
 $use_file = ("$script_path" . "$in_");
 @months = qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec);
THEN I PRINT THE LIST OF MONTHS(WHICH DOES PRINT CORRECTLY)
print "Please enter the month of your choice at this time.\n";
 $mn = <STDIN>;
 chomp $mn;
 while (($mn < 1) || ($mn > 12)) {
  print "You have made an invalid selection. Please try again.\n";
  $mn = <STDIN>;
  chomp $mn;
 }
 $month_keep = ($months[($mn-1)]);
 print "\nPlease enter the day of the month.\n";
 $day = <STDIN>;
 chomp $day;
 while (($day < 1) || ($day >31)) {
  print "You have made an invlaid selection. Please try again.\n";
  $day=<STDIN>;
  chomp $day;
 }
 print "\n\nPlease enter the name of the file where you would like to save
the results.\n";
 print "Make sure the file name is not already used because all data in the
file being\n";
 print "written to will be overwritten.\n";
 $savein = <STDIN>;
 chomp $savein;
 if (length($savein)<1) {
  print "You have entered an invlaid selection.  You will now be
returned\n";
  print "to the main menu. Please press enter to continue\n";
  $continue_ = <STDIN>;
  dir_menu();
 }
 $save_in = ("$HOME" . "$savein");
 open (IN_FILE, "$use_file");
 open (OUT_FILE, ">>$save_in");
 $search_for = ("$month_keep " . "$day");
 $search_for2 = ("$month_keep  " . "$day");
 while (<IN_FILE>) {
  if((/$search_for/) || ($search_for2)) {
   print "$_">OUT_FILE;
  }
 }
 close (IN_FILE);
 close (OUT_FILE);
 print "\n\nThe report has been generated.  It is named $save_in \n";
 print "Please press enter to return to the main menu \n";
 $aa = <STDIN>;
 chomp $aa;
 dir_menu();
}





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

Date: Tue, 10 Aug 1999 12:58:15 -0400
From: "Christian Evans" <chris.evans@tc.faa.gov>
Subject: Re: search and match
Message-Id: <7oplnf$73a$1@faatcrl.faa.gov>

here is the code...let me know if you can help me out.  thanks

i know the following code could be written much simpler, but when i am gone,
a beginner needs to be able to follow the code structure.

the variable script path is determined in another module (dir_menu)


system("clear");
 print "Please enter the file whose records you wish to search.\n";
 $in_ = <STDIN>;
 chomp $in_;
 $use_file = ("$script_path" . "$in_");
 @months = qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec);
THEN I PRINT THE LIST OF MONTHS(WHICH DOES PRINT CORRECTLY)
print "Please enter the month of your choice at this time.\n";
 $mn = <STDIN>;
 chomp $mn;
 while (($mn < 1) || ($mn > 12)) {
  print "You have made an invalid selection. Please try again.\n";
  $mn = <STDIN>;
  chomp $mn;
 }
 $month_keep = ($months[($mn-1)]);
 print "\nPlease enter the day of the month.\n";
 $day = <STDIN>;
 chomp $day;
 while (($day < 1) || ($day >31)) {
  print "You have made an invlaid selection. Please try again.\n";
  $day=<STDIN>;
  chomp $day;
 }
 print "\n\nPlease enter the name of the file where you would like to save
the results.\n";
 print "Make sure the file name is not already used because all data in the
file being\n";
 print "written to will be overwritten.\n";
 $savein = <STDIN>;
 chomp $savein;
 if (length($savein)<1) {
  print "You have entered an invlaid selection.  You will now be
returned\n";
  print "to the main menu. Please press enter to continue\n";
  $continue_ = <STDIN>;
  dir_menu();
 }
 $save_in = ("$HOME" . "$savein");
 open (IN_FILE, "$use_file");
 open (OUT_FILE, ">>$save_in");
 $search_for = ("$month_keep " . "$day");
 $search_for2 = ("$month_keep  " . "$day");
 while (<IN_FILE>) {
  if((/$search_for/) || ($search_for2)) {
   print "$_">OUT_FILE;
  }
 }
 close (IN_FILE);
 close (OUT_FILE);
 print "\n\nThe report has been generated.  It is named $save_in \n";
 print "Please press enter to return to the main menu \n";
 $aa = <STDIN>;
 chomp $aa;
 dir_menu();
}



Tom Briles <sariq@texas.net> wrote in message
news:37B03BC8.8BA3F805@texas.net...
> Christian Evans wrote:
> >
> > I have a module in a perl script that allows users to search for a
record
> > with a field that matches a desired date.  The dates are in the format
with
> > the first three letter of the month (i.e. Jan) followed by one OR two
> > spaces, and the day of the month.  How can I write the script to search
for
> > all possible records.  I have tried many different possible choices and
> > can't seem to get any of them to work.
> >
> > It seems as though when I search, my script will match all records with
a
> > field with a given month, but I can't seem to match the month and the
date
> > at the same time.
> >
> > Thanks
>
> Christian -
>
> You may receive a reply from a certain unmentioned party stating that
> there is an 'error in line 17'.
>
> *Don't you believe it!*
>
> The error is on line 21!
>
> Seriously, we can't possibly tell you what's wrong with your code when
> we can't see it.  Cut-and-paste the smallest possible portion that
> illustrates the problem, and you may get some helpful responses.
>
> - Tom




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

Date: 10 Aug 1999 16:58:29 GMT
From: ebohlman@netcom.com (Eric Bohlman)
Subject: Re: Simple write routine
Message-Id: <7oplnl$occ@dfw-ixnews3.ix.netcom.com>

Ala Qumsieh (aqumsieh@matrox.com) wrote:
: 
: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) writes:
: 
: > I have rarely seen a check on close of an ordinary file.  Is there
: > any particular reason why you include it here?  Or just general
: > tidiness?
: 
: IMHO, it is best to check the return value of any Perl function that
: has a useful return value. close() is one of them. 
: 
: But I usually use warn() or die() depending on my program. For
: example, if the file associated with the filehandle to be close()d is
: to be re-opened again for reading, then I use a die():
: 
: 	close FILE or die "Error closing file: $!\n";
: 
: The reason is that if the close() failed, I am not guaranteed to have
: correct data in my file once I re-open it. OTOH, if I just want to
: close the filehandle and never re-open it again, then I do a
: warn(). All filehandles will be closed automatically once my program
: ends.

One case where it's *absolutely* essential to check the status of a 
close() is the one where you're modifying a file by copying its contents 
to a temporary file, deleting the old file and then renaming the 
temporary file.  In this case you *must not* proceed to delete the 
original file if something went wrong with writing the new file!  Of 
course, it's always safer to rename the original file to something.bak 
instead of deleting it, but even then plowing ahead after a failed 
close() would leave the last good data stuck in a place where other 
programs aren't going to be looking for it, and an incomplete file where 
they are.



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

Date: Tue, 10 Aug 1999 11:45:47 -0400
From: "James A Culp III" <admin@futuristic.net>
Subject: Re: suggestions for CRAP
Message-Id: <7ophsm$i1k$1@ffx2nh3.news.uu.net>

Tom Briles <sariq@texas.net> wrote in message
news:37B03874.DB1176EC@texas.net...
: Uri Guttman wrote:
: >
: > why are all the free cgi sites full of crappy code? doesn't anyone
who
: > knows how to use a module publish scripts on the web? is it a
requirement
: > to have a site of free code to have a room temp iq?
: >
: > here are some fun examples that pinyan's group can comment upon.
some
: > general notes:
:
: <snipped fun examples>
:
: > oh, well, i am sick of this. does someone know of a decently written
: > free cgi script of any sort out there? let alone a repository of
them? i
: > bet it is because all the decent perl hackers have plenty of real
work
: > to do or they focus on cpan and the core rather than cgi apps.
: >
: > maybe we should form a little project to create a web site with
quality
: > cgi (and other) scripts. if tom can raise support for the power
tools
: > project, this should be doable too. then we can finally direct folks
to
: > examples of cgi code we can be proud of. this crap is embarrassing
to
: > the perl community.
: >
: > uri
:
: This is a terrific idea.  I would love the opportunity to contribute
: code while being under the watchful eye of the Perl gods.  What better
: way to improve my skills?
:
: I certainly don't qualify as a reviewer; however, *you* do Uri.  Are
you
: volunteering?
:
: - Tom

I thought I posted this once about 7 hours ago but must have been
mistaken.  Sorry if it's a repost.

If you folks are serious I would be willing to host the site (e-mail,
web, and dns) and anything else that might be needed.  Hosted on a
linux machine that I own that sits on my isp's T1.  I however am not a
very good webpage designer unless you consider fuschia and sky blue nice
"matching" colors :).

If anyone would like to get something like this going and needs the
hosting drop me a line and we'll get things rolling.

Sincerely,
James A Culp III
http://www.futuristic.net/




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

Date: 10 Aug 1999 16:23:29 GMT
From: mgm@unpkhswm04.bscc.bls.com (Mitchell Morris)
Subject: Re: why doesn't this work?
Message-Id: <slrn7r0kg1.3hk.mgm@unpkhswm04.bscc.bls.com>

In article <37B01879.B09CA2D3@ccrs.nrcanDOTgc.ca>, Tom Kralidis wrote:
>Hi,
>
>I can't get this script to work properly.  It's desgined for a huge
>directory file system.  I've tested it on a smaller file structure and
>it worked.  But if I try it on the intended dirs, it doesn't work.  The
>files and their paths indeed exist, but the script does nothing when
>invoked, returning to the prompt.
>
>#!/public/bin/perl -w
>
>$finalDir = "/home/user/";
>chdir "$finalDir" or die "Can't cd to $finalDir: $!\n";
>foreach $File (<W*/N*/*.txt>)
                ^^^^^^^^^^^^^

This invokes a shell to do the globbing, which will then be subject to shell
limits on the length of command lines. I hypothesize that this is the source
of your problem from your comment that it works in sparsely populated
directories and does nothing (useful) in densely populated ones.

from "perldoc -f glob"
	
	=item glob EXPR

	=item glob

	Returns the value of EXPR with filename expansions such as the
	standard Unix shell F</bin/sh> would do.  This is the internal
	function implementing the C<E<lt>*.cE<gt>> operator, but you can use
	it directly.  If EXPR is omitted, C<$_> is used.  The
	C<E<lt>*.cE<gt>> operator is discussed in more detail in
	L<perlop/"I/O Operators">.

from "perldoc perlop" in the "I/O Operators" section:

	Because globbing invokes a shell, it's often faster to call readdir()
	yourself and do your own grep() on the filenames.  Furthermore, due
	to its current implementation of using a shell, the glob() routine
	may get "Arg list too long" errors (unless you've installed tcsh(1L)
	as /bin/csh).

[snip]
>Any ideas?
>
>Thanks alot
>
>..Tom	

"perldoc -q too long" has this to say:
	=head1 Found in /usr/local/lib/perl5/5.00502/pod/perlfaq5.pod

	=head2 Why do I sometimes get an "Argument list too long" when I use <*>?

	The C<E<lt>E<gt>> operator performs a globbing operation (see
	above).  By default glob() forks csh(1) to do the actual glob
	expansion, but csh can't handle more than 127 items and so gives the
	error message C<Argument list too long>.  People who installed tcsh
	as csh won't have this problem, but their users may be surprised by
	it.

	To get around this, either do the glob yourself with C<Dirhandle>s
	and patterns, or use a module like Glob::KGlob, one that doesn't use
	the shell to do globbing.

	(Note: "perldoc -q '<'" will return this block along with several
	other references)

Thus, I conclude you have to either (a) write your own using opendir/readdir
or (b) grab a module, perhaps Glob::KGlob, from CPAN.



Notice that there is a pattern to the answers here. I'll even add in the
pointer that they all start with "perldoc". Searching CPAN is left as an
exercise for the reader.

+Mitchell

-- 
Mitchell Morris

I wanna be like me when I grow up,
	-- Brent Curtis


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

Date: Tue, 10 Aug 1999 15:16:35 GMT
From: @l@ <aqumsieh@matrox.com>
Subject: Re: Why use Perl when we've got Python?!
Message-Id: <7opfo6$eoq$1@nnrp1.deja.com>

In article <37AAFAD1.A032765B@NOSPAM.strs.co.uk>,
  Ian Clarke <I.Clarke@NOSPAM.strs.co.uk> wrote:
> I know this sounds like flame-bait, but I am genuinely curious as to
> what Perl might have to offer that Python doesn't.

Ok. Here are my two cents.

I learnt Perl first, but then got interested in Python, and learnt it as
well, but I dumped it finally. There is a big difference between the two
(IMHO of course).

Perl was originally written for a specific purpose. It's goal was to get
things done quickly and efficiently. The following is an excerpt of the
manpage of the very first Perl release:

"Perl is a interpreted language optimized for scanning arbitrary text
files, extracting information from those text files, and printing
reports based on that information.
It's also a good language for many system management tasks.
The language is intended to be practical (easy to use, efficient,
complete) rather than beautiful (tiny, elegant, minimal)."

Please note the last sentence. Perl is practical, not elegant. It never
pretended to be elegant. It never pretended to be a universal language
that does everything. It never pretended to be a substitute for other
useful languages like C. It was written to make some aspects of life a
little bit simpler. Always keep that in mind.

Python on the other hand was written to be "tiny, elegant, minimal." I
am not saying this is bad. It is only different. It gives very good
insight into OO programming. But that's not what I, personally, want. I
want something to do the job, quickly and effectively.

As far as I can see (and I might be wrong, but this is the impression I
got), Python was written just for the sake of writing yet another nice,
elegant OO language, that has a much nicer and easier syntax than C++ or
even Java. To that extent, Guido has succeeded. But, I believe he should
have concentrated on more important issues.

> I have been using Python for some time now, I have occasionally looked
> at perl, but was but off by its seemingly counter-intuative, and
> over-complicated syntax.

That is pure FUD. Perl's syntax is very close to C's, which makes it
much easier to learn. I found Python's use of spaces a bit confusing,
but I got over it. You should try to do the same with Perl's syntax.

> Come on Perl people, you can do better than this!

If you really want to compare two languages, then you should learn them
both, and do the comparison yourself. I like the language which is most
useful to my specific set of applications. Those applications are,
almost surely, different from yours. So you might prefer a different
language.

Also, I could care less which language you are using. But I think you're
missing quite a lot of fun.

--Ala


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


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

Date: 10 Aug 1999 16:04:04 GMT
From: billynospam@mirror.bt.co.uk (Graham Ashton)
Subject: Re: Why use Perl when we've got Python?!
Message-Id: <slrn7r0jbm.3us.billynospam@wing.mirror.bt.co.uk>

In article <slrn7r0b2t.b2t.*@dragons.duesouth.net>, Matthew Bafford wrote:
>
>Ian is obviously more geared towards Python than Perl.

yes, and he's interested to know why so many others are biased the other
way.

>And, no matter what reasons we give, Ian will still see the language in
>the same way.

that's for him to decide.

-- 
Graham

P.S. <billynospam@mirror.bt.co.uk> is a fully working address...


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

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


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