[8944] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 2562 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue May 12 01:09:40 1998

Date: Mon, 11 May 98 22:00:32 -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           Mon, 11 May 1998     Volume: 8 Number: 2562

Today's topics:
        @array(@range) possible?? <paulg@pc350.griffith.ca>
    Re: @array(@range) possible?? <zenin@bawdycaste.org>
    Re: Basic MacPERL (Martien Verbruggen)
    Re: Basic MacPERL (John Moreno)
    Re: bug in win95 read/sysread? (Martien Verbruggen)
    Re: bug in win95 read/sysread? <zenin@bawdycaste.org>
    Re: deleting first two lines of text file??? <zenin@bawdycaste.org>
    Re: deleting first two lines of text file??? (Martien Verbruggen)
        Did 'do' find it's file.... <hluchan@csi.com>
    Re: Does Perl have a IDE?I don't like command line. (I R A Aggie)
    Re: Does Perl have a IDE?I don't like command line. (I R A Aggie)
    Re: flock is not <zenin@bawdycaste.org>
    Re: function prototyping <mgregory@asc.sps.mot.com>
        Get file date <fuc@esquel.com>
        glob() function leaves behind a child process? <mgregory@asc.sps.mot.com>
    Re: How old is Perl? (Jobst Schmalenbach)
    Re: Learning Perl vs Programming Perl (Books) <angst@scrye.com>
        Modem Dial out <chinsn@stcs.com.sg>
        password (Miu Alex Wong)
        perl's NIS awareness defined at perl's compile time? (John Ruckstuhl)
    Re: Question about regular expression in perl script (Martien Verbruggen)
    Re: Scanning Perl scripts for Y2K problems (Stuart McDow)
    Re: Testing out CGI/Perl scripts on a PC with WIN95 (Sean Malloy)
        Tip: Filehandles Nathan Torkington <gnat@frii.com
    Re: Tip: Filehandles (Martien Verbruggen)
    Re: Translate UNIX shell script into Perl - $100 for be (Kevin Aylward)
    Re: updating passwd file with 600+ new accounts <webmaster@fccjmail.fccj.org>
    Re: What happenned to all the 1's. <info@purco.qc.ca>
        Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)

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

Date: 12 May 1998 03:04:58 GMT
From: Paul Griffith <paulg@pc350.griffith.ca>
Subject: @array(@range) possible??
Message-Id: <6j8e8q$qb$1@news.interlog.com>

I am trying he following example from "Perl in 21 Days" 
-----

#!/usr/local/bin/perl

@array = ("one", "two", "three", "four", "five");

@range = (1, 2, 3);
@subarray = @array(@range);
print ("The array slice is: @subarray\n");
------

Which should print: The array slice is: two three four

But I get the following error message:

syntax error at /home/paulg/bin/program5_8a.pl line 6, near "@array("
Execution of /home/paulg/bin/program5_8a.pl aborted due to compilation errors.

I am running perl v5.004_01 on FreeBSD v2.2.5

---------
paulg@interlog.com | Powered by FreeBSD


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

Date: 12 May 1998 03:44:19 GMT
From: Zenin <zenin@bawdycaste.org>
Subject: Re: @array(@range) possible??
Message-Id: <894945105.694272@thrush.omix.com>

Paul Griffith <paulg@pc350.griffith.ca> wrote:
: I am trying he following example from "Perl in 21 Days" 

	Ugh...sorry to hear that.  Pi21Days has got to be one of the
	all time worthless books for Perl.  It's much more likely to
	/hinder/ your learning of perl then it would help it.

: @subarray = @array(@range);

	The book is wrong.

  @subarray = @array[@range];
  @subarray = @array[1 .. 3];
  @subarray = @array[3 .. 1];  # backwards
  @subarray = @array[1,3,2];   # no one said it had to be in order.

-- 
-Zenin
 zenin@archive.rhps.org


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

Date: 12 May 1998 01:18:23 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: Basic MacPERL
Message-Id: <6j880v$set$2@comdyn.comdyn.com.au>

In article <35578703.216B@earthlink.net>,
	Michael Gagne <mkgagne@earthlink.net> writes:
> I'm having trouble opening a file with MacPERL.  I'm trying:
> open($ACCESS_LOG, "Tigger:Documents:Access-LOG.com")

Are you sure you meant that to be $ACCESS_LOG?

Did you try finding out why the open fails?

open(AAA, $file) || die "Cannot open $file: $!";

Martien
-- 
Martien Verbruggen                  | 
Webmaster www.tradingpost.com.au    | I think I think, therefore I think I
Commercial Dynamics Pty. Ltd.       | am.
NSW, Australia                      | 


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

Date: Tue, 12 May 1998 03:17:23 GMT
From: phenix@interpath.com (John Moreno)
Subject: Re: Basic MacPERL
Message-Id: <1d8w05p.8to6e61iqwvpcN@roxboro0-011.dyn.interpath.net>

Michael Gagne <mkgagne@earthlink.net> wrote:

> I'm having trouble opening a file with MacPERL.  I'm trying:
> open($ACCESS_LOG, "Tigger:Documents:Access-LOG.com")
> 
> It doesn't seem to recognize the file.  Please help with this most
> simple (yet frustrating) problem.  I don't have a problem opening a file
> in a UNIX PERL.

Well first off you should be checking to see why it doesn't work - you
should be using die and $!

Other than that - the first thing I see is that I find the $ACCESS_LOG
highly suspicious, highly.  Second thing - you haven't specified whether
this is for reading or for writing (actually you have, but I wouldn't
want to do it in that manner).

-- 
John Moreno  


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

Date: 12 May 1998 01:12:50 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: bug in win95 read/sysread?
Message-Id: <6j87mi$set$1@comdyn.comdyn.com.au>

In article <35564EA4.59C3A5F@cyberspc.mb.ca>,
	Trevor Cordes <trevor@cyberspc.mb.ca> writes:
> Is there a bug in the read/sysread functions on the Win95 ports
> of perl?  I've tried both binary distributions and they both
> fail on the following code that works great on my UNIX systems.

DOS/win95/NT thinks there's a difference between text files and binary
files. You have to use binmode on your file handle.

 # perldoc -f binmode

Martien
-- 
Martien Verbruggen                  | 
Webmaster www.tradingpost.com.au    | In a world without fences, who needs
Commercial Dynamics Pty. Ltd.       | Gates?
NSW, Australia                      | 


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

Date: 12 May 1998 02:26:23 GMT
From: Zenin <zenin@bawdycaste.org>
Subject: Re: bug in win95 read/sysread?
Message-Id: <894940429.823987@thrush.omix.com>

Martien Verbruggen <mgjv@comdyn.com.au> wrote:
	>snip<
: DOS/win95/NT thinks there's a difference between text files and binary
: files. You have to use binmode on your file handle.
:
:  # perldoc -f binmode

	Speaking of which, when the hell would anyone not want to be in
	binmode()?  I meen, shouldn't open() just implicitly call it for
	you?

-- 
-Zenin
 zenin@archive.rhps.org


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

Date: 12 May 1998 01:15:17 GMT
From: Zenin <zenin@bawdycaste.org>
Subject: Re: deleting first two lines of text file???
Message-Id: <894936163.375530@thrush.omix.com>

Andrew Specht <andrew@iaccess.com.au> wrote:
: HOw would i delete the first two lines of a text file using perl?
: the chop command doesn't work..

	perl -ni -e 'print if $. > 2' filename

	Reading the docs to make sure I didn't just feed you a line of perl
	that emails me your password file is your homework. :-)

-- 
-Zenin
 zenin@archive.rhps.org


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

Date: 12 May 1998 01:22:27 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: deleting first two lines of text file???
Message-Id: <6j888j$set$3@comdyn.comdyn.com.au>

In article <6j858l$rno@sleipnir.iaccess.com.au>,
	"Andrew Specht" <andrew@iaccess.com.au> writes:

> HOw would i delete the first two lines of a text file using perl?

# perldoc perlfaq5
     How do I change one line in a file/delete a line in a
     file/insert a line in the middle of a file/append to the
     beginning of a file?

> the chop command doesn't work..

Why would it? That is not what chop is for... Why in heaven's name did
you think it would do that? Did you try to read some documentation
about it before using it?

# perldoc perlfunc
# perldoc -f chop

Martien
-- 
Martien Verbruggen                  | 
Webmaster www.tradingpost.com.au    | Very funny Scotty, now beam down my
Commercial Dynamics Pty. Ltd.       | clothes.
NSW, Australia                      | 


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

Date: Mon, 11 May 1998 21:10:11 -0700
From: Sarah Hluchan <hluchan@csi.com>
Subject: Did 'do' find it's file....
Message-Id: <3557CBA3.C52@csi.com>

do "bogus filename";
die $@ if $@;

hmmm, there is no "bogus filename" in the filesystem, and that doesn't die.

I like that "do" will search @INC for me, and I may want to "do"
the same file a few times & have it parsed each time.  How can
I tell if "do" didn't find it's file?

-y


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

Date: Mon, 11 May 1998 21:32:00 -0500
From: fl_aggie@thepentagon.com (I R A Aggie)
Subject: Re: Does Perl have a IDE?I don't like command line.
Message-Id: <fl_aggie-1105982132010001@aggie.coaps.fsu.edu>

In article <6j7u8v$e29@mozo.cc.purdue.edu>, gebis@albrecht.ecn.purdue.edu
(Michael J Gebis) wrote:

+ gbacon@cs.uah.edu (Greg Bacon) writes:

+ }Perl would cease to be the language we know and love if we watered it
+ }down to meet the needs of the least common denominator.  An army of Ken
+ }Thompsons couldn't fully idiot-proof even the simplest program.

+ So basically, you're counting on people to suddenly get smart.  You
+ optimists make me sick.

No, we aren't. We're _requiring_ people to get smart. There is a 
difference.

James

-- 
Consulting Minister for Consultants, DNRC
The Bill of Rights is paid in Responsibilities - Jean McGuire
To cure your perl CGI problems, please look at:
<url:http://www.perl.com/CPAN-local/doc/FAQs/cgi/idiots-guide.html>


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

Date: Mon, 11 May 1998 21:40:00 -0500
From: fl_aggie@thepentagon.com (I R A Aggie)
Subject: Re: Does Perl have a IDE?I don't like command line.
Message-Id: <fl_aggie-1105982140000001@aggie.coaps.fsu.edu>

In article <ken-1105981624570001@news.swarthmore.edu>,
ken@forum.swarthmore.edu (Ken Williams) wrote:

+ In article <6j7iuk$q68$5@info.uah.edu>, Greg Bacon <gbacon@cs.uah.edu> wrote:

+ >Please give us three good reasons why we should stroke even one key to
+ >help people who refuse to use man, perldoc, or grep?  Perl requires at
+ >least that much of a clue.

+ Okay, tell me what's wrong with the following classroom teacher: 
+   "Class, I'm not going to lift one finger to help you if you can't read and 
+    understand a simple calculus textbook."

And how much is Randal, Tom C, Greg or anyone else on this newsgroup 
getting paid for their knowledge?

Besides, a calculus instructor's job is to teach calculus, not reading.
One can not proceed with if one does not have the baseline skills to be a
programmer. Period.

And I've come around to the point of view that perl is a miserable for
people who've never programmed before.

+ Michael's point was that in an IDE we'd have a chance to make an intuitive
+ help system.  What's wrong with that?  It could make more sense to
+ beginners.  If it meant that fewer people would bother you, why wouldn't
+ you like it?

And who is going to do it? you?

+ Of course, I don't have a clue about how one would proceed in writing an
+ IDE.

Guess not...maybe O'Reilly will commission someone to write one for
you, and then charge you for it. Would that be satisfactory? If so,
start a letter writing campaign.

James

-- 
Consulting Minister for Consultants, DNRC
The Bill of Rights is paid in Responsibilities - Jean McGuire
To cure your perl CGI problems, please look at:
<url:http://www.perl.com/CPAN-local/doc/FAQs/cgi/idiots-guide.html>


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

Date: 12 May 1998 02:23:41 GMT
From: Zenin <zenin@bawdycaste.org>
Subject: Re: flock is not
Message-Id: <894940267.458165@thrush.omix.com>

Martien Verbruggen <mgjv@comdyn.com.au> wrote:
	>snip<
: You can't get an exclusive lock on a file that you didn't open for write.

	This is incorrect.  Exclusive flock()s are available on any open
	file descriptor and under SysV are available on socket descriptors
	as well.  The options the descriptor was opened with are not
	important.

	Just because you're not writing to the file doesn't meen you want
	other people modifying the data as you're reading.

-- 
-Zenin
 zenin@archive.rhps.org


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

Date: 12 May 1998 11:40:23 +0930
From: Martin Gregory <mgregory@asc.sps.mot.com>
Subject: Re: function prototyping
Message-Id: <r8g1igkzn4.fsf@asc.sps.mot.com>

Tom Christiansen <tchrist@mox.perl.com> writes:

>  [courtesy cc of this posting sent to cited author via email]
> 
> In comp.lang.perl.misc, 
>     "matthew d. p. k. lanier" <lanier@shell6.ba.best.com> writes:
> :i'm considering the usefulness of prototyping my function calls.  
> 
> Until you can immediately tell what length(@a) returns
> when @a = (1 .. 1), don't use prototypes.

Why?

In otherwords, I knew that length(@a) is 1, but I don't feel any more
confident about function prototypes...

Martin.


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

Date: Tue, 12 May 1998 11:28:47 +0800
From: "Chris Fu" <fuc@esquel.com>
Subject: Get file date
Message-Id: <6j8fgi$n20$1@imsp009a.netvigator.com>

Hi everybody,

Anyone knows how to use script to fetch the file date?


Best rgds




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

Date: 12 May 1998 11:47:50 +0930
From: Martin Gregory <mgregory@asc.sps.mot.com>
Subject: glob() function leaves behind a child process?
Message-Id: <r8d8dkkzap.fsf@asc.sps.mot.com>


I was a bit concerned to find that:
 
 print "wait before glob: " . wait() . "\n";

 $a = glob('foo');

 print "wait after glob: " . wait() . "\n";

results in 

 wait before glob: -1
 wait after glob: 27332

I had rather hoped that the only process IDs that would come out of a
wait() call would be processes that I created myself (using fork() or
some such).

Is this an reasonable expectation?

(In which case this behaviour seems like a bug in glob()).

Thanks,

Martin.

(email copies of replies appreciated)


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

Date: 12 May 1998 04:40:58 GMT
From: jobst@senna.eng.monash.edu.au (Jobst Schmalenbach)
Subject: Re: How old is Perl?
Message-Id: <6j8jsq$1c2$1@towncrier.cc.monash.edu.au>

John Beadles <beadles@nortel.com> writes:

>Rosemary I H Powell wrote:
>> 
>> In article <355381E6.1BAD95E4@nortel.com>, John Beadles
>> <beadles@nortel.com> writes
>> >Tom Christiansen wrote:
>> >
>> >>
>> >> PUMPKIN?
>> >>
>> >>   [from Porting/pumpkin.pod in the Perl source code distribution]
>> >>
>> >>   Chip Salzenberg gets credit for that, with a nod to his cow orker,
>> >>   David Croy.  We had passed around various names (baton, token,
>> >>   hot potato) but none caught on. Then, Chip asked:
>> >>
>> >
>> >OK, so know we know what a pumpkin is.  What I want to know is what is
>> >a  cow orker?
>> >
>> >Come to think of it, maybe I don't want to know after all... ;-)
>> Yes you do - it's someone who orkes cows. Obviously.
>> :-)
>> Rosemary,
>> Just missing drowning her keyboard in coffee.

>Oh, thanks for the visualization - now I've got to go wash my mind out. 
>Got any mental floss on you? :-D

>From the Shorter Oxford:

ork: [In sense I f FR: orque (hell) IT: orco (demon) ...]
     1: Any of the various fericious sea creatures
     2: A devouring monster 


so it must be a cow monster???



cheers
jobst

--
|             __, Jobst Schmalenbach, Monash Uni, Melbourne, Australia |
|   _ _.--'-n_/   Electrical and Computer Systems Engineering          |
| -(_)------(_)=  email jobst@senna.eng.monash.edu.au    61-3-99055705 |
|                 http://senna.eng.monash.edu.au/~jobst  61-41-1611855 |


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

Date: 12 May 1998 01:10:39 GMT
From: angst <angst@scrye.com>
Subject: Re: Learning Perl vs Programming Perl (Books)
Message-Id: <6j87if$96f$1@jelerak.scrye.com>

matthew d. p. k. lanier <lanier@shell6.ba.best.com> wrote:
: programming perl is a pretty dense book, and i would recommend getting it
: concurrently to learning perl, but reading and trying to digest learning
: perl first.

I would modify this a little...I learned perl with the camel book, never
touched the llama book.  I would say, you need only the camel book if you
have some experience in programming any other free-form language previously
(such as C or Pascal, but not something like line-oriented BASIC), and
particularly if you've done anything with shell scripting.  If you are new
to programming (and scripting) in general, get the llama book first, then
the camel book (or use both side by side).

Or, just get both to be charitable to randall.

-- 
Erik Nielsen <eln@rmci.net>
solaris/perl/qmail/dns weenie
this post != views of anyone at all, really
"You are like...unix GOD" -- local tech support


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

Date: 12 May 1998 04:21:44 GMT
From: "Shaw" <chinsn@stcs.com.sg>
Subject: Modem Dial out
Message-Id: <01bd7d59$b6fe91a0$0a010aa8@ns_srv>

Recently I installed a network management station and need to set up some
paging function using modem. I have a C-class HP-UX-10.20. Anyone out here
has a neat shell script to initialize modem and ending the call? Page
different person for different type of network component and problem?


-- 
Shaw N, Chin
ST Computer Systems & Services Ltd
http:\\www.stcs.com.
Tel: 2403774   Fax: 2403110
 


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

Date: 12 May 1998 03:10:03 GMT
From: miuwong@blue.seas.upenn.edu (Miu Alex Wong)
Subject: password
Message-Id: <6j8eib$7ot$1@netnews.upenn.edu>


hi,

I need to have users type in their telnet account login name and passwd 
on the web and check them against the master password file see whether they
have typed in the correct one, is there any way to do that.

take care

alex

--
Computer Science and Finance
School of Engineering and Applied Science
of University of Pennsylvania
Tel: 215 387 3492


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

Date: Tue, 12 May 1998 01:09:00 GMT
From: ruck@netcom.com (John Ruckstuhl)
Subject: perl's NIS awareness defined at perl's compile time?
Message-Id: <ruckEstKJ0.99L@netcom.com>

On a system that I use (which is Solaris 2), several versions of perl 
exist.
Some know NIS is used for passwd, some don't:

    /apps/tools/bin/perl -le 'while(($n)=getpwent){print "$n"}'

looks only to the local /etc/passwd, while

    /apps/contrib/bin.sol2/perl5 -le 'while(($n)=getpwent){print "$n"}'

knows about NIS.  Is this awareness defined by the linking at compile
time for perl itself, or can it in some way influenced from within a 
perl-script itself.

(These examples are from the very same machine!)

I think I'd rather use /apps/tools/bin/perl, because it's v5.004_01,
but otoh, I want a perl that uses the same getpw that my system uses,
as Perl is documented to do, in e.g. "Learning Perl".

Thanks for any assistance,
John Ruckstuhl
PS -- I've got 2nd ed of llama and camel books, if it's easiest to just
refer me to the fine books.  I didn't build Perl, and I'm not anxious
to.
-- 
John Ruckstuhl                      ruck@netcom.com


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

Date: 12 May 1998 02:42:43 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: Question about regular expression in perl script
Message-Id: <6j8cv3$svd$1@comdyn.comdyn.com.au>

In article <355367F1.50903B7E@charlotte.infi.net>,
	Gary Nielson <gnielson@charlotte.infi.net> writes:

> perl -p -i.bak -e 's/[^x]\.htm/\.x\.htm/' *.htm
> 
> That definitely avoids adding a .x to any file that already has a .x
> before .htm. But now it deletes the last character before the .x. So
> test.htm becomes tes.x.htm. I am having trouble figuring out how to
> correct this.

This might also do odd things for file names like: a.htm.b.htm. maybe
you can anchor the regexp in some way?

Have a look at lookahead assertions in perlre. Something like
/(?!x)\.htm$/ should do the job. Beware of shells trying to do history
substitution on the !.

# perldoc perlre

Martien
-- 
Martien Verbruggen                  | 
Webmaster www.tradingpost.com.au    | I took an IQ test and the results were
Commercial Dynamics Pty. Ltd.       | negative.
NSW, Australia                      | 


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

Date: 12 May 1998 03:10:56 GMT
From: smcdow@arlut.utexas.edu (Stuart McDow)
Subject: Re: Scanning Perl scripts for Y2K problems
Message-Id: <6j8ek0$ha8$1@ns1.arlut.utexas.edu>

Randal Schwartz <merlyn@stonehenge.com> writes:
> >>>>> "Stuart" == Stuart McDow <smcdow@arlut.utexas.edu> writes:
> 
> localtime() itself is Y2K.

Well, shut ma mouth an' call me mumbles. Ya learn somthin' new ever
durn day.

:-)

> What are YOU saying?

localtime is Y2K, sure. But so what? Just because it is doesn't mean
that its use will me. Scan the script for localtime, and wherever it
pops up, make sure that (localtime)[5] is being used correctly.

Seemed obvious to me.

--
Stuart McDow                                     Applied Research Laboratories
smcdow@arlut.utexas.edu                      The University of Texas at Austin
            "Look for beauty in roughness, unpolishedness"


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

Date: 12 May 1998 00:17:37 EDT
From: malloy@concentric.net (Sean Malloy)
Subject: Re: Testing out CGI/Perl scripts on a PC with WIN95
Message-Id: <3557cbe1.170157464@news.concentric.net>

phil@ackltd.demon.co.uk wrote:

>I am trying to test some web pages which call CGI/Perl Scripts on a PC
>and having problems (HTTP 404). I have perl installed on my system and
>have tested the scripts in isolation but am not sure that the web
>server I'm using knows about it  (I'm using Microsoft Personal Web
>Server).
>
>Is the Microsoft Personal Web Server capable of running CGI scripts
>and if so, what do I need to do next. If not what server would you 
>recommend I use.

If I am remembering the procedure properly, this is how you set it up.

Fire up RegEdit. Go to:

	HKEY-LOCAL-MACHINE
	  \--System
	       \--Services
	            \--W3SVC
	                 \--Parameters
	                      \--Script Map

Create a new string value key named '.pl', and set its value to
"c:\perl\bin\perl.exe %s %s" (using whatever path you actually used to
install perl as the path to perl.exe, rather than the one above).
Close RegEdit and restart the server.

My memory is fuzzy; there may be one more level between 'Parameters'
and 'Script Map' -- but the rest of the path is correct, and you want
to add the key under 'Script Map'.

-- 
Sean R. Malloy               | American Non Sequitur
    Naval Medical Center     |       Society
    San Diego, CA 92134-5000 |
malloy@cris.com              | "We may not make sense,
srmalloy@snd10.med.navy.mil  |  but we do like pizza"
FORMAL NOTICE: unsolicited commercial email will be read
at a charge of $500 per item. Receipt of such email shall
be considered to constitute acceptance of contract, and 
will be billed immediately.


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

Date: 11 May 1998 14:52:41 -0600
From: Nathan Torkington <gnat@frii.com
Subject: Tip: Filehandles
Message-Id: <5q4sywcyxy.fsf_-_@prometheus.frii.com>

I used to use IO::File or FileHandle religiously to make filehandles.
No more!  I was confused by the many and various ways that you can
pass filehandles to subroutines or store them in variables, but now I
have seen the light.

Perl tries hard to make things work.  You can pass or store the string
"STDIN" and treat it as a filehandle, and Perl will try to do the
right thing (it will complain under "use strict", though).  The right
and simple way to do it, keeping "use strict" happy, is to use
typeglobs.  Typeglobs are when you prefix a symbol with a * to access
the innards of Perl's symbol table.

Don't stop reading!  This isn't hard!  The rule is simple: you only
have to use typeglobs when you pass a filehandle or copy it to a
variable:

    open(LOGFILE, ">> /var/log/misery.log")
	|| die "Couldn't open /var/log/misery.log for writing: $!\n";
    log(*LOGFILE, "Starting up");
    $lh = *LOGFILE;
    log($lh, "Still starting up");

We used a typeglob to pass the LOGFILE filehandle to the subroutine
log().  The log() subroutine gets the filehandle as an argument, and
can store it in a variable and print using that variable without
using typeglobs at all:

    sub log {
	my $fh = shift;

	print $fh scalar(localtime), @_, "\n";
    }

You can now make arrays of filehandles:

    @fh = ( *STDIN, *STDERR, *LOGFILE );

<> and print (where filehandles are built into the syntax of Perl,
rather than being mere arguments to functions like read) are picky.
They only want literal filehandles (LOGFILE) or simple scalar
variables ($fh).  Array subscripts, hash subscripts, function calls
returning filehandles ... all these are Right Out.  You can get around
it with print by using a block:

    print { $fh[2] } "This goes to LOGFILE\n";

But in general you should just assign to a temporary scalar variable:

    $temp = $fh[2];
    print $temp "This goes to LOGFILE\n";
    $temp = $fh[0];
    while (<$temp>) {
	chomp;
	print "Read $_ from STDIN\n";
    }

The only other time you need to use typeglobs with filehandles is when
you want a function or block to create a new anonymous filehandle:

    sub open_and_return {
	my $filename = shift;
	local (*FH);

	open(FH, "< $filename")	|| dir "Can't open $filename : $!\n";
	return *FH;
    }

    foreach (@files) {
	local *FH;
	open(FH, "< $filename")	|| dir "Can't open $filename : $!\n";
	push(@filehandles, *FH);
    }

There, that wasn't painful, was it?  And you saved yourself umpteen
thousands of lines of startup module loading.

Nat


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

Date: 12 May 1998 04:30:03 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: Tip: Filehandles
Message-Id: <6j8j8b$fk$1@comdyn.comdyn.com.au>

In article <5q4sywcyxy.fsf_-_@prometheus.frii.com>,
	Nathan Torkington <gnat@frii.com writes:

> I used to use IO::File or FileHandle religiously to make filehandles.
> No more!  I was confused by the many and various ways that you can
> pass filehandles to subroutines or store them in variables, but now I
> have seen the light.

[snip]

> Don't stop reading!  This isn't hard!  The rule is simple: you only
> have to use typeglobs when you pass a filehandle or copy it to a
> variable:

That is a very old fashioned way to do it, and hardly anything worth
drooling about.

You do realise that there is very likely a very good reason why perlfaq5
states the following?

# perldoc perlfaq5
[snip]
     How can I make a filehandle local to a subroutine?  How do I
     pass filehandles between subroutines?  How do I make an
     array of filehandles?

     You may have some success with typeglobs, as we always had
     to use in days of old:

         local(*FH);

     But while still supported, that isn't the best to go about
     getting local filehandles.  Typeglobs have their drawbacks.
     You may well want to use the FileHandle module, which
     creates new filehandles for you (see the FileHandle
     manpage):
[snip]

IOW: You were doing it right. You're doing it dangerously now.

Martien

PS. I used to use an electric drill to create holes in my wall, but I
got confused by all the buttons and thingies. I now have seen the
light! I use a hammer and a nail, and then pull the nail back out.

-- 
Martien Verbruggen                  | 
Webmaster www.tradingpost.com.au    | Very funny Scotty, now beam down my
Commercial Dynamics Pty. Ltd.       | clothes.
NSW, Australia                      | 


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

Date: Mon, 11 May 1998 22:14:31 -0400
From: kaylward@removethis.eicorp.net (Kevin Aylward)
Subject: Re: Translate UNIX shell script into Perl - $100 for best port
Message-Id: <MPG.fc17a8e39fb260498969a@news.clark.net>

As I suspected there were a few good folks out there who could answer the 
call.  Thanks to all who sent replies.  The code was provided by Andrew 
Johnson.  For the benefit of others the Perl'ized version and the 
original shell script version are shown below.

Note: Check the #! line for proper path to Perl, and line 4 for proper 
'news' directory.

New Perl Version
---------------- 

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

my $dir='/site/news/current';
my %months=('01'=>'January',
         '02'=>'February',
         '03'=>'March',
         '04'=>'April',
         '05'=>'May',
         '06'=>'June',
         '07'=>'July',
         '08'=>'August',
         '09'=>'September',
         '10'=>'October',
         '11'=>'November',
         '12'=>'December',
         );

opendir(DIR,$dir)||die "Can't open directory $dir $!";
my @files=map{$_}
          sort{$b->[1]<=>$a->[1]}
          map{[$_,substr($_,0,10)]}
          grep /\.prr$/,readdir DIR;
close DIR;

foreach (@files){
    my $month=$months{substr($_->[1],4,2)};
    my $year=substr($_->[1],0,4);
    my $day=substr($_->[1],6,2);
    my $file=$_->[0];
    open(FILE,"$dir/$file")||die "can't open $file $!";
    my $title=<FILE>;
    close FILE;
    chomp $title;
    print<<HTML;
<font color=#ff0000 size=2>
<b>&nbsp;<br>
$month $day, $year
<br>
</b>
</font><a href="news.shtml?$file">$title
</a>

HTML
}
__END__


The old pr.sh:
-------------- 

datestring ()
{
  datestryear=`echo $1 | cut -b1-4`
  datestrmonth=`echo $1 | cut -b5-6`
  datestrday=`echo $1 | cut -b7-8`

  case ${datestrmonth:=Bad_Month} in
    01)	datestr=January;;
    02)	datestr=February;;
    03)	datestr=March;;
    04)	datestr=April;;
    05)	datestr=May;;
    06)	datestr=June;;
    07)	datestr=July;;
    08)	datestr=August;;
    09)	datestr=September;;
    10)	datestr=October;;
    11)	datestr=November;;
    12)	datestr=December;;
    *)	datestr=${datestrmonth};;
  esac

  case ${datestrday:=Bad_Day} in
    0?) datestr="$datestr `echo $datestrday | cut -b2-2`";;
    *)  datestr="$datestr $datestrday";;
  esac

  datestr="${datestr}, ${datestryear:=Bad_Year}"

  echo $datestr
  printf "<br>\n"
}

prtitle ()
{
  printf "%s<br>\n" "`head -1 $1`"
}

pritem ()
{
  prfile=$1
  prname=`basename $1`

  if [ $currentdate -ne `echo $prname | cut -b1-8` ]
  then 
    printf "<font color=#ff0000 size=2>\n<b>"
    printf "&nbsp;<br>\n"
    datestring $prname
    printf "</b>\n</font>"
  fi
  currentdate=`echo $prname | cut -b1-8`

  printf "<a href=\"news.shtml?${prname}\">"
  prtitle $prfile
  printf "</a>\n"
}

prall ()
{
  printf "<font face=\"verdana,helvetica,arial\" color=#ff0000>\n"
  for f in `ls ${prdir}*.prr | sort -r`
  do
    printf "\n\n"
    pritem $f
  done
}

prpage ()
{
  prfile=$1
  prname=`basename $1`

  printf "<font face=\"verdana,helvetica,arial\" color=#990000 
size=2>\n<b>\n"

  datestring $prname

  printf "&nbsp;<br>\n\n<font color=#000099 size=3>"

  prtitle $prfile

  printf "&nbsp;<br>\n</b>\n</font></font>\n\n"

  tail +2 $prfile
}

prdir=/site/news/current/
bindir=/site/cgi-bin/
currentdate=abcdefgh

if [ $QUERY_STRING ]
  then prpage ${prdir}$QUERY_STRING 
  else prall
fi


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

Date: Tue, 12 May 1998 01:18:08 GMT
From: Bill 'Sneex' Jones <webmaster@fccjmail.fccj.org>
Subject: Re: updating passwd file with 600+ new accounts
Message-Id: <3557A181.FB3C9CE5@fccjmail.fccj.org>

Jennifer Telisky wrote:
> 
> I need to quickly update our system with 600+ new accounts.  I think the
> best way to do this would be with perl.  However, I'm extremely new to
> perl.  Can anyone give me any help on how to ge this done.
> 
> I have a dat file that contains the names, usernames, home dir, etc..
> I think the best way to start is to perform a "finger" on the username
> to make sure the account hasn't been created.  For already existing
> accounts, write the names out to a "bad file".  If the account doesn't
> exist , go ahead and create it.
> 
> Any snippets, tips, tricks out there would be helpful..
> 
> Jennifer Telisky

A pointer in the right direction:
http://webmaster.fccj.org/Webmaster/WebPass.html
(Requires TCL/Expect development system)
____________________________________________________________________________
Bill Jones | FCCJ Webmaster | Voice 1-904-632-3089 | Fax 1-904-632-3007
Florida Community College at Jacksonville | 501 W. State St. | Jax, FL 32202
mailto:webmaster@fccjmail.fccj.org | http://webmaster.fccj.org/Webmaster


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

Date: Tue, 12 May 1998 03:42:17 GMT
From: Leon Stepanian <info@purco.qc.ca>
Subject: Re: What happenned to all the 1's.
Message-Id: <3557C600.B8529D76@purco.qc.ca>



Leon Stepanian wrote:
> [snipped]

I have tested my main problem of reading in my html files into my perl script by
parsing the html and substituting certain strings with variable values.
My Perl code.
sub return_access_page_4
{
print "Content-type: text/html\n\n";
open(MAINFILE, "$basedir/accespage.txt");
while(<MAINFILE>) {
@mainpage=split(s/SCBDOPL/$FORM{accesscode}/, $_);
print (@mainpage);
   }
close<MAINFILE>;
}
My test html page has this general form;
<HTML>
<HEAD>
<META HTTP-EQUIV=\"Content-Type\" CONTENT=\"text/html; charset=iso-8859-1\">
<TITLE>WELCOME TO LEVEL 1 ACCESS</TITLE>
</HEAD>
<BODY>
<CENTER><B><FONT COLOR="#000099">Hello SCBDOPL - Enter Your Information. Test
number 2116.</FONT></B></CENTER>
CENTER><B><FONT COLOR="#FF6600"><FONT SIZE=+2>POINTS
212</FONT></FONT></B></CENTER>
</BODY></HTML>What I cannot undertstand is the following;
When $FORM{accesscode} holds a number like   254796
The html page is ok and shows 254796 instead of SCOOBEEDOO.
But, when $FORM{accesscode} holds a number like   214716
The html page is not ok and shows 2476 instead of SCOOBEEDOO.
Thus all the ones are removed. Also, I had written a test number in the same
html line as 2116, and this also shows as 26, every time, so the 1's were also
removed.

The funny part is the next line which contains POINTS 212 prints out ok.

It must have something to do with the fact that on the first line, there is a
call to the split function, whereas on the second line, there is no call to the
split function.

But why would only the 1's be removed and can this be fixed somehow, as this
approach to reading in html's with variables seems to be my best option.

Any hint would be a great help.

Leon Stepanian
Perl............from an ocean of human kinds.



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

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

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