[8952] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 2570 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue May 12 17:10:00 1998

Date: Tue, 12 May 98 14:00:40 -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           Tue, 12 May 1998     Volume: 8 Number: 2570

Today's topics:
        ambiguous use resolved ? <prl2@lehigh.edu>
    Re: chdir-command <rootbeer@teleport.com>
    Re: converting non-printable characters <rootbeer@teleport.com>
    Re: CPAN & Module gripes (was Re: Ever Wonder...?) <p-ciccone@usa.net>
    Re: Does Perl have a IDE?I don't like command line. <tchrist@mox.perl.com>
    Re: Does Perl have a IDE?I don't like command line. <birgitt@order.booktraders.com>
    Re: Does Perl have a IDE?I don't like command line. <birgitt@order.booktraders.com>
    Re: Does Perl have a IDE?I don't like command line. <birgitt@order.booktraders.com>
    Re: Does Perl have a IDE?I don't like command line. (Bart Lateur)
    Re: Does Perl have a IDE?I don't like command line. <tchrist@mox.perl.com>
    Re: Does Perl have a IDE?I don't like command line. <birgitt@order.booktraders.com>
    Re: ERROR: odbc.pm, &AutoLoader::AUTOLOAD David@iqtexas.com
        FMTEYEWTK on Indirect Filehandles <tchrist@mox.perl.com>
    Re: glob() function leaves behind a child process? <tchrist@mox.perl.com>
    Re: How can you break out of a 'while... ' loop in a fu <tchrist@mox.perl.com>
    Re: How can you break out of a 'while... ' loop in a fu <tchrist@mox.perl.com>
    Re: how to create name for temporary file <yong@shell.com>
    Re: Insecure $ENV <rootbeer@teleport.com>
        Is if ($a="something") a bad style? <yong@shell.com>
        PROFESSIONAL PERL TRAINING <rwilliams@altavista.net>
    Re: Randomly sorting an array (Chip Salzenberg)
    Re: Randomly sorting an array <tchrist@mox.perl.com>
        Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)

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

Date: Tue, 12 May 1998 15:39:56 -0400
From: "Phil R Lawrence" <prl2@lehigh.edu>
Subject: ambiguous use resolved ?
Message-Id: <6ja8i7$215g@fidoii.cc.Lehigh.EDU>

I received an error:
Ambiguous use of {params} resolved to {"params"} at blah blah...

for the following line of code:
    my $params = $self->{SQL}{params};

and a similiar error for bind in the following:
    if (defined $param_hash->{$_}{bind}) {


Blue Camel says of this error mssg:
"You said something that may not be interpreted the way you thought."

Why wasn't {SQL} similarly complained about in the first example?  I don't have
any barewords lying around that might confuse Perl.  Any ideas?

--
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Phil R Lawrence               phone: 610-758-3051
Programmer / Analyst      e-mail: prl2@lehigh.edu
194 Lehigh University Computing Center
E.W. Fairchild - Martindale, Bldg. 8B
Bethlehem, PA  18018
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~





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

Date: Tue, 12 May 1998 20:33:34 GMT
From: Tom Phoenix <rootbeer@teleport.com>
To: Dennis Kowalski <dennis.kowalski@daytonoh.ncr.com>
Subject: Re: chdir-command
Message-Id: <Pine.GSO.3.96.980512133011.21974M-100000@user2.teleport.com>

On Tue, 12 May 1998, Dennis Kowalski wrote:

> If it is off of the command line via ARGV[##] and it was the last
> argument on the command line, make sure you chomp($newdir) to remove the
> new line character. 

The OS shouldn't include the newline. What system were you using that did
this? Maybe you should complain to the vendor.

-- 
Tom Phoenix       Perl Training and Hacking       Esperanto
Randal Schwartz Case:     http://www.rahul.net/jeffrey/ovs/



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

Date: Tue, 12 May 1998 20:28:09 GMT
From: Tom Phoenix <rootbeer@teleport.com>
To: Matthew Glogowski <matthewg@bu.edu>
Subject: Re: converting non-printable characters
Message-Id: <Pine.GSO.3.96.980512132315.21974L-100000@user2.teleport.com>

On Tue, 12 May 1998, Matthew Glogowski wrote:

> i've tried $newfile =~ tr/[\W]/$replacement/; but it doesn't work.

tr/// works fine, when you use it as it's documented. :-)

    tr/a-zA-Z_0-9/_/c;		# evil chars to underscores

It's worth noting that you can't interpolate variables into a tr///. (But
you may use eval STRING to get around this restriction.) Hope this helps! 

-- 
Tom Phoenix       Perl Training and Hacking       Esperanto
Randal Schwartz Case:     http://www.rahul.net/jeffrey/ovs/



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

Date: 12 May 1998 13:52:45 -0700
From: Paolo Ciccone <p-ciccone@usa.net>
Subject: Re: CPAN & Module gripes (was Re: Ever Wonder...?)
Message-Id: <wk3eeftdnm.fsf@usa.net>

>>>>> "RS" == Randal Schwartz <merlyn@stonehenge.com> writes:

>>>>> "eryq" == eryq  <eryq@zeegee.com> writes:

    RS> I just did this:

    RS>     $ cat cpr 
    RS>     #!/home/merlyn/bin/perl
    RS>     use CPAN; 
    RS>     CPAN::Shell->r; 
    RS>     shell; $

    RS> This rocks.  Run it every morning.  See what is new in the

It does indeed ! Thanks.

--Paolo


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

Date: 12 May 1998 19:55:52 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: Does Perl have a IDE?I don't like command line.
Message-Id: <6ja9g8$j68$1@csnews.cs.colorado.edu>

 [courtesy cc of this posting sent to cited author via email]

In comp.lang.perl.misc, 
    ilya@math.ohio-state.edu (Ilya Zakharevich) writes:
:Is somebody twisting your hands to force you make fool of yourself?

Stop wasting so much time at the mirror, Ilya.

:Next time you will recommend me use pfind to read DOCs...


I recommend using things like find+grep, or tcgrep, or linux man with its
-K flag, or my man with -g or its lqtext support, or agrep with errors,
or gnu grep with -C, etc.  Then of course there's glimpse, which is
hard to fault.  The possibilities are limited only by the imagination
of the programmer.  The system is replete with power tools just waiting
for your attention.  It is risible in the extreme that you're talking
about how ostensible difficult it is to locate information in the Perl
documentation, considering of course that facile manipulation of text
and files is the heart and soul of Perl itself.  Amongst the first
programming task for every Perl programmer should be to write a better
perl documentation grepper.  If they can't do that, they don't get to
write in Perl.  It's like those "you must be this tall" bars at amusement
parks.  Those who cannot cope with Perl's documentation don't deserve it.

Despite the confusion of the webblies, Perl has never been nor ever shall
be a consumerist toy for the programmatically challenged.  It is a power
programming tool, made by programmers for programmers.  Nonprogrammers
should stop complaining that it doesn't fit their worldview.  It isn't
supposed to.

You're a programmer, Ilya.  I don't understand what your problem is.


--tom
-- 
There is a need to keep from being locked into Open Systems. --IBM sales rep


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

Date: Tue, 12 May 1998 15:53:11 -0400
From: Birgitt Funk <birgitt@order.booktraders.com>
Subject: Re: Does Perl have a IDE?I don't like command line.
Message-Id: <3558A8A7.D1D37D9@order.booktraders.com>

Greg Bacon wrote:
> 
> In article <rdm-1205980112530001@140.174.42.30>,
>         rdm@cfcl.com (Rich Morin) writes:
> : In article <fl_aggie-1105982140000001@aggie.coaps.fsu.edu>,
> : fl_aggie@thepentagon.com (I R A Aggie) wrote:
> :
> : > And I've come around to the point of view that perl is a miserable
> : > [language] for people who've never programmed before.
> :
> : An opinion we have tried to disprove in "MacPerl: Power and Ease".  We
> : first explain fundamental programming concepts (three chapters), then
> : introduce a subset of Perl (four chapters).  Time will tell if this is
> : enough background to allow the readers to wade into the "cookbook"
> : and reference chapters that follow.  (We *do*, in any case, point to
> : the appropriate (generally ORA) books as ways to fill in the gaps...)
> 
> It would take nothing short of pedagogical genius to teach programming
> in but three chapters of a book.
> 
> : >>>>> "Ken" == Ken Williams <ken@forum.swarthmore.edu> writes:
> : Ken> The point is that beginners often lack some basic concepts that never
> : Ken> would have occurred to the people that wrote the man pages.
> :
> : Unfortunately, books on programming languages often skip over basic
> : concepts, as well.  This saves space, to be sure, but makes it hard for
> : beginners to climb on board.  We decided to assume that our readers are
> : intelligent and motivated, but not necessarily programmers; hence, our
> : chapters on programming concepts.  By the same token, we decided not to
> : attempt a recapitulation of the ORA offerings (why be silly?).
> 
> If everyone included the basics in every book about programming
> languages, we'd need much larger bookshelves. :-)  Learning to program
> is a lot like learning a natural language.  We first teach babies to
> speak (even if there sentences are very short and simple).

I don't agree, you don't teach any baby to speak a motherlanguage,
it learns it by itsself (unless you set out your baby in the jungle
with apes and it still learns to speak and UNDERSTAND "ape's talk",
if it survives at all). 

There are big difference in how you learn to speak and how you learn
to read and write. I asked in another thread if you learn programming
(your first programming language) by writing code or by reading code. 

Without the learning the underlying grammar, syntax and phonetics 
of a language you don't learn to read, spell and write any language,
(but you can speak and understand it). The same thing, even more
heavily so, is true for reading, writing and understanding a programming 
language.(which you will hopefully never 'speak').

> Once they
> have a fair grasp on expressing themselves, we teach them the
> fundamentals of spelling, grammar, etc.  Learning to program usually
> involves a teaching language (since practical experience seems to be the
> most helpful). 

That is not accurate enough: 

   1.You never speak a programming language (if you do you
     might have a slight problem, don't you think ? 8-).

   2.Case 1: you know the structure of programming, because you
             have already learned it in the seventies and eighties
             with Fortran, Cobol, Basics, C or what have you.
             a. you learn a new programming language faster
                because you have only to grasp the new syntax and
                functions and 'spelling', but you know your
                underlying grammar and come equipped with a foundation
                of tools to help yourself learning the new stuff
                of a new language faster with these tools. These
                people can and will profit from what I would
                call the "total immersion approach" ...but only
                because they have had a serious 'grammar'
background.                        
     Case 2: you don't know the structure of programming, because
             you have never been taugt or have never learned it
             before. You learn your first programming language.
             And this language will be Perl. 
             a. with 'total immersion' and a lot of 'hmm,
                if you are so stooopid...' the newcomer will
                speak "Pidgin", read "Mickey Mouse" and write nothing
                worth reading.         


> > fl_aggie@thepentagon.com (I R A Aggie) writes:
> >
> > And I've come around to the point of view that perl is a miserable
> > for people who've never programmed before.

Why ?


> Well, sure it is. And so is C, sh, awk, sed, BASIC, FORTRAN, Lisp,
> etc.

O.K., so what language is then left to the new incoming generation 
of programming students ? Why should I learn Fortran or Cobol first
when, from all I hear, I can do so many things with Perl as well 
and better ? Why can't Perl be a first language ?

> To this I would have to say -- "No kidding."  I think any programming
> language would be hard to grasp if the would be programmer doesn't know the
> first thing about for loops and such...  

Sure thing.

> I think it could be wise to throw Perl in with C as a language NOT to teach
> to an aspiring programmer first...

Which one is then and why not Perl ?

> I learned how to program in COBOL and Assembler. I wish perl was around
> back then.

> I honestly think that anyone with a head on their shoulders could easily
> learn perl by reading "Learning Perl" from cover to cover a couple of
> times.

Before I don't hear a clear reason why not, I sincerely hope that there 
are no real reasons why Perl couldn't be your first programming language
to learn programming with.

Birgitt Funk


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

Date: Tue, 12 May 1998 15:51:15 -0400
From: Birgitt Funk <birgitt@order.booktraders.com>
Subject: Re: Does Perl have a IDE?I don't like command line.
Message-Id: <3558A833.D5633632@order.booktraders.com>

I R A Aggie wrote:

[snip]

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


Why ?

Birgitt Funk


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

Date: Tue, 12 May 1998 15:52:10 -0400
From: Birgitt Funk <birgitt@order.booktraders.com>
Subject: Re: Does Perl have a IDE?I don't like command line.
Message-Id: <3558A86A.46C84F51@order.booktraders.com>

Stuart McDow wrote:
> 
> fl_aggie@thepentagon.com (I R A Aggie) writes:
> >
> > And I've come around to the point of view that perl is a miserable
> > for people who've never programmed before.
> 
> Well, sure it is. And so is C, sh, awk, sed, BASIC, FORTRAN, Lisp,
> etc.
> 

So, which language is then left for the new generation of incoming
programming students ?

Birgitt Funk


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

Date: Tue, 12 May 1998 21:00:34 GMT
From: bart.mediamind@tornado.be (Bart Lateur)
Subject: Re: Does Perl have a IDE?I don't like command line.
Message-Id: <3559b854.1174735@news.tornado.be>

Greg Bacon wrote:

>Programming languages aren't and should never be everyday things.

Oops. I program everyday.

	Bart.


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

Date: 12 May 1998 20:24:19 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: Does Perl have a IDE?I don't like command line.
Message-Id: <6jab5j$lpr$5@csnews.cs.colorado.edu>

 [courtesy cc of this posting sent to cited author via email]

In comp.lang.perl.misc, Greg Bacon <gbacon@cs.uah.edu> writes:
:Tuits are far too
:precious to waste on trying to cater to such a low denominator.

The bottom five percent will always take 150% of your time.  
Just say no.

--tom
-- 
"Premature optimisation is the root of all evil."
    --Knuth


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

Date: Tue, 12 May 1998 16:25:30 -0400
From: Birgitt Funk <birgitt@order.booktraders.com>
Subject: Re: Does Perl have a IDE?I don't like command line.
Message-Id: <3558B03A.CD158651@order.booktraders.com>

Tom Christiansen wrote:


> 
> Despite the confusion of the webblies, Perl has never been nor ever shall
> be a consumerist toy for the programmatically challenged.  It is a power
> programming tool, made by programmers for programmers.  Nonprogrammers
> should stop complaining that it doesn't fit their worldview.  It isn't
> supposed to.

So, I repeat my question, can Perl be the first programming language
to learn programming with or not ?

Isn't any programming student by definition programmatically challenged
?

There a nonprogramming programming students who want to learn
programming
and use Perl as their first programming language. They don't necessarily
complain, nor see it as a consumerist toy. 


Birgitt Funk


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

Date: Tue, 12 May 1998 20:20:41 GMT
From: David@iqtexas.com
Subject: Re: ERROR: odbc.pm, &AutoLoader::AUTOLOAD
Message-Id: <6jaauq$tc1$1@nnrp1.dejanews.com>

<Hide>
    I found my stupid case sensitivity error .... grrrr
</Hide>

BUT!!!, I now get a null for driver ID.  In the ODBC manger I set it to 25,
but when it is accessed via the web, it is reset to null.

Any ideas?

-David

In article <6j9k5j$4r$1@nnrp1.dejanews.com>,
  David@iqtexas.com wrote:
>
> RE: odbc, sql
>
> I am attempting to print the contents of an Access DB.
> The script fails @ Fetchrow.  The DB appears to be setup correctly in ODBC
> manager.
>
> The output is below, then the script.
>
> The DB was created by the ODBC manager.  I then went into access to create
> the table 'logon'.
>
> Thanks for any help,
> -David
>
> >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
> OUTPUT__________________________________
>
> Content-Type: text/html
>
> <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
> <HTML><HEAD><TITLE>Untitled Document</TITLE>
> </HEAD><BODY><HR><table>
> Goto undefined subroutine &AutoLoader::AUTOLOAD at D:\Perl\lib/Win32/ODBC.pm
> line 861.
>
> SCRIPT___________________________________
> # logon.mdb test
>
> use CGI qw(:standard);
> use Win32::ODBC;
>
> print header;
> print start_html(),hr();
>
> $dsn="NetData";
> if (!($db=new Win32::ODBC($dsn,"Internet","odbc"))){
>     print "Error connecting to $DSN\n";
>     print "Error: ",Win32::ODBC::Error(),"\n";
>     print hr(),end_html;
>     exit;
> }
>
> $db->Sql(" SELECT * FROM [logon] ");
>
> print "<table>\n";
>
> $i=0;
> while ($db->Fetchrow()) {
> 	$i++;
> 	print "<OK here $i>\n";
> 	%data=$db->Datahash();
> 	print qq~
> <tr>
>   <td>$data{logon}</td>
>   <td>$data{password}</td>
> </tr>
> ~;
> }
>
> print "</table>";
>
> $db->close();
>
> print hr(),end_html;
>
> -----== Posted via Deja News, The Leader in Internet Discussion ==-----
> http://www.dejanews.com/   Now offering spam-free web-based newsreading
>


-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/   Now offering spam-free web-based newsreading


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

Date: 12 May 1998 20:35:18 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: FMTEYEWTK on Indirect Filehandles
Message-Id: <6jabq6$lpr$6@csnews.cs.colorado.edu>

You want to use a filehandle like a normal variable so you can
pass it to or return it from a function, store it in a data
structure, and so on. The solution is to use indirect filehandles
by storing strings, typeglobs, typeglob references, or IO objects
into scalar variables:

    $fh =   SOME_FH;       # bareword is strict-subs hostile
    $fh =  "SOME_FH";      # strict-refs hostile; same package only
    $fh =  *SOME_FH;       # typeglob
    $fh = \*SOME_FH;       # ref to typeglob (bless-able)
    $fh =  *SOME_FH{IO};   # blessed IO::Handle from *SOME_FH typeglob

Or to use the `new' method from the FileHandle or IO modules to
create an anonymous filehandle, store that in a scalar variable,
and use it as though it were a normal filehandle.

    use FileHandle;
    $fh = FileHandle->new();

    use IO::Handle;                     # 5.004 or higher
    $fh = IO::Handle->new();

Then use any of these as you would a normal filehandle.

Here's how this works:

Anywhere that Perl is expecting a filehandle, an indirect
filehandle may be used instead. An indirect filehandle is just a
scalar variable that contains a filehandle. Functions like
`print', `open', `seek', or the functions or the `<FH>' diamond
operator will accept either a read filehandle or a scalar variable
containing one:

    ($ifh, $ofh, $efh) = (*STDIN, *STDOUT, *STDERR);
    print $ofh "Type it: ";
    $got = <$ifh>
    print $efh "What was that: $got";

In the spirit of there being more than one way to do it, here are
seven ways to produce an indirect filehandle. Don't be
intimidated: numbers 3, 6 and 7 are the most common (and 6 and 7
are really the same thing):

1. Barewords
    The first, SOME_FH is rather dubious, because it's not merely a
    string, but a bareword string. It won't be allowed if `use strict
    'subs'' is in effect. Other than that, everything in the next entry
    also applies.

2. Strings
    `"SOME_FH"' is still a string, but at least it's quoted. The big
    problem with this is that it doesn't have package information, so
    if you used it to call a function compiled in a different package,
    that function could get confused unless it were one of the ubiquitous
    handles, like ARGV, STDIN, STDOUT, and STDERR.  You could add the
    package manually, saying perhaps `"main::SOME_FH"'. It won't be
    allowed if `use strict 'refs'' is in effect. The function in question
    can fix it up using the `Symbol::qualify' function, which adds in
    the package. Its cousin, `Symbol::qualify_to_ref', does this and
    produces a reference, silencing the complaints from `strict refs'.

	use Symbol;
	sub function_taking_filehandle_argument {
	    my $fh = shift;
		    # produce typeglob
	    $fh = qualify($fh, scalar caller);          

	# or else this one:

		    # produce typeglob ref
	    $fh = qualify_to_ref($fh, scalar caller);   
	    ...
	}

    The `Symbol::qualify' function produces something useful for
    passing to the `readline' function as described below.

3. Typeglobs
    The `*SOME_FH' notation is a typeglob, an entry in a package
    symbol table. Typeglobs are often nominated as Perl's deepest
    and blackest magic. If you see a star in front of an
    identifier, there are typeglobs involved, and you know you
    have entered a wizardly realm where even gurus fear to tread.

    Unlike the string versions of filehandles shown previously,
    you can do nearly anything with a typeglob you'd like--if not
    a good bit more. They're extremely convenient and useful, once
    you get the hang of them. You don't have to fight with
    packages or any stricture. And although it's not `bless'able
    because it's not a reference, it can be effectively returned
    from functions. A reference to a typeglob can't.

    Here's how typeglobs are typically used for I/O:

	#!/usr/bin/perl
	# demoglob - show how to return local filehandles

	sub ropen {
	    my $path = shift;
	    local *FH;
	    open(FH, $path) || die $!;
	    return *FH;
	}

	$f = ropen("/etc/motd");
	$g = ropen("/etc/termcap");
	print scalar(<$f>), scalar(<$g>);

    >>> Welcome to www.perl.com, the Perl Homepage >>> ########
    TERMINAL TYPE DESCRIPTIONS SOURCE FILE

    If a typeglob is passed in, it can be assigned to a local
    filehandle using a typeglob. After that, normal operations
    like `<>' or any I/O function can be applied to it.

	sub read_N_lines using
	    local *FH = shift;
	    my $count = shift;
	    my @lines = ();
	    while (--$count > 0) {
		push @lines, scalar <FH>;
		last if eof(FH);
	    }
	    return @lines;
	}

	open(TCAP, "/etc/termcap") || die $!;
	@some = read_N_lines(*TCAP, 3);
	print @some;

    >>> ######## TERMINAL TYPE DESCRIPTIONS SOURCE FILE >>> # >>>
    # Version 9.12.0

    It turns out that it also works if the caller forgets to star
    the filehandle or passes it as a string, effectively using
    techniques 1 and 2 from this list. It works only so long as
    they're in the same package as the function in question and
    `strict refs' isn't enabled, though.

	@some = read_N_lines('TCAP', 5);

    That's because assigning a string to a typeglob promotes the
    string to a typeglob of that name, like this:

	*newname = *oldname;        
	*newname = 'oldname';       
		# magically same; promote string to typeglob!

    A careful function would have done either this to qualify its
    filehandle argument:

	use Symbol;
	local *FH = qualify(shift, caller);

    Or prototyped the function to take a typeglob, which
    implicitly does the same thing:

	sub read_N_lines(*$) {
	    # same definition
	}

    Once such a prototype is visible, a call like this:

	@some = read_N_lines(TCAP, 5);

    is really treated as though it were

	@some = &read_N_lines(*TCAP, 5);

4. Typeglob references
    The ` \*SOME_FH' notation produces a reference to a typeglob.
    It can be used to create an object by blessing the reference;
    this is what the FileHandle and IO modules use. Don't try
    passing one of these back from a function, though, because it
    doesn't work. Instead, if you would like an anonymous one of
    these, use the Symbol module.

	use Symbol;
	sub ropen {
	    my $path = shift;
	    my $fh = gensym();
	    open($fh, $path) || die $!;
	    return $fh;
	}

5. IO handles
    The curious `*SOME_FH{IO}' construct is explained in greater
    detail in perlref(1). It accesses the internal IO object
    associated with the handle called SOME_FH. This is a real
    object; it's already blessed even though it's built-in to
    Perl.

	printf "I have %s\n", *STDIN{IO};
    >>> I have IO::Handle=IO(0x80784b8)

    The only issue here is that it can't be used to generate a new
    filehandle the way `Symbol::gensym' can. But if you've already
    accessed the symbol as a filehandle, that's ok. This works
    fine:

	sub ropen {
	    my $path = shift;
	    local *FH;
	    open(FH, $path) || die $!;
	    return *FH{IO};
	}

6. FileHandle
    The standard FileHandle module can be used to create a new filehandle
    to use indirectly. It's just a bit expensive to load; as of the
    5.004 release, merely saying `use FileHandle' loads fifteen text
    files plus several shared libraries, plodding through nearly four
    thousand lines of source code.

	use FileHandle;
	sub ropen {
	    my $path = shift;
	    my $fh = FileHandle->new();
	    open($fh, $path) || die $!;
	    return $fh;
	}

7. IO::Handle
    This is works the same as the FileHandle module, except that
    its name is different. The FileHandle module is really just a
    front-end to this one.  It's still just as crazily expensive.

There's a catch with these indirect filehandles. Only a simple scalar
variable, not part of an array or hash or larger expression, can be
used for things like `print', `printf', or the diamond operator. This
is illegal and won't even compile:

    @fd = (*STDIN, *STDOUT, *STDERR);
    print $fd[1] "Type it: ";                           # WRONG
    $got = <$fd[0]>                                     # WRONG
    print $fd[2] "What was that: $got";                 # WRONG

With `print', you can get around this problem by using a block and
an expression:

    print  { $fd[1] } "funny stuff\n";
    printf { $fd[1] } "Pity the poor %x.\n", 3_735_928_559;
>>> Pity the poor deadbeef.

or even this, which sends the message out to one of two places:

    $ok = -x "/bin/cat";                
    print { $ok ? $fd[1] : $fd[2] } "cat stat $ok\n";
    print { $fd[ 1+ ($ok || 0) ]  } "cat stat $ok\n";           

This kind of thing doesn't work for the diamond operator. In some
cases, though, you may be in luck. The angle bracket notation is
mostly just an interface to the built-in function named
`readline'. You may call it directly--providing that you pass it a
typeglob. Not a string. Not a reference to a typeglob. Just a
typeglob. Given the initialization of @fd above, this would work:

    $got = readline($fd[0]);

But if those had been typeglob references or strings instead of
globs, `readline' wouldn't have worked.

All this monkeying around will probably get to you eventually. If
so, it may well be time to load the FileHandle module (or its
newer alias, IO::Handle), which simplifies much of this. It has a
`new' method to provide an anonymous filehandle, as we saw above.
And it has `print' and `getline' methods (Yes, that's `getline' as
a method, but `readline' when a function. I don't know what I was
thinking when I wrote it.):

    use FileHandle;
    @fd = ( *STDIN{IO}, *STDOUT{IO}, *STDERR{IO} );
    $fd[1]->print("Type it: ");
    print { $fd[1] } ("Type it: ");      # same, but *much* faster
    $got = $fd[0]->getline();
    $fd[2]->print("What was that: $got");

See also the `open' entry in perlfunc(1) (or Camel:3), FileHandle(3)
(or Camel:7), the perlref(1) manpage's treatment of the so-called
`*foo{THING}' syntax, and the IO modules.

-- 
Hi, this is Ken. What's the root password?


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

Date: 12 May 1998 20:21:47 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: glob() function leaves behind a child process?
Message-Id: <6jab0r$lpr$4@csnews.cs.colorado.edu>

 [courtesy cc of this posting sent to cited author via email]

In comp.lang.perl.misc, 
    Martin Gregory <mgregory@asc.sps.mot.com> writes:
: $a = glob('foo');

glob in scalar context is a very bad idea.  

$ man perlop

   A glob evaluates its (embedded) argument only when it is starting a
   new list.  All values must be read before it will start over.  In 
   list context this isn't important, because you automatically get them
   all anyway.  In scalar context, however, the operator returns the
   next value each time it is called, or a FALSE value if you've just
   run out.  Again, FALSE is returned only once.  So if you're expecting
   a single value from a glob, it is much better to say

       ($file) = <blurch*>;

   than

       $file = <blurch*>;

   because the latter will alternate between returning a filename
   and returning FALSE.

--tom
-- 
    Because . doesn't match \n.  [\0-\377] is the most efficient way to match
    everything currently.  Maybe \e should match everything.  And \E would
    of course match nothing.   :-) --Larry Wall in <9847@jpl-devvax.JPL.NASA.GOV>


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

Date: 12 May 1998 20:19:07 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: How can you break out of a 'while... ' loop in a function?
Message-Id: <6jaarr$lpr$3@csnews.cs.colorado.edu>

 [courtesy cc of this posting sent to cited author via email]

In comp.lang.perl.misc, 
    tina@tech.scandinaviaonline.se writes:
:  To me, though I am admittedly strange, they translate to goto... there
:*is* some good advice in not breaking out of while-loops - or any other
:loops - in more than one place.

Larry has declared that line of reasoning to be bull.

--tom
-- 
There's going to be no serious problem after this.  --Ken Thompson


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

Date: 12 May 1998 20:18:32 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: How can you break out of a 'while... ' loop in a function?
Message-Id: <6jaaqo$lpr$2@csnews.cs.colorado.edu>

 [courtesy cc of this posting sent to cited author via email]

In comp.lang.perl.misc, stu-w@usa.net writes with a now despammed
address available for all to see,

:A simple question, but all the pearl FAQs are useless.

What is Pearl?

You failed to read the perlsyn manpage, qui tollit peccata tui.
Shame on you.

--tom
-- 
	  "And I don't like doing silly things (except on purpose)."
		--Larry Wall in <1992Jul3.191825.14435@netlabs.com>


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

Date: Tue, 12 May 1998 15:28:44 -0500
From: Yong Huang <yong@shell.com>
Subject: Re: how to create name for temporary file
Message-Id: <3558B0FC.E1CFC0ED@shell.com>

Why not tell the guy asking the original question to use $$ (the process
number) or something combined with it (mytmp.$$)? That's the typical way to
create unique temporary filenames in Shell scripting.

But this is a problem on any platform other than UNIX. On Win95 e.g., $$
gives me a negative number every time the same. I know in C, you can use
tmpnam function. I don't know how that's implemented in C compilers for PCs.
Another possible way is to use $^T and it also works on PC. But if the script
is executed twice within one second, the result is the same. A problem. In
that case, you may consider locking it somehow.

Yong Huang

Martien Verbruggen wrote:

> In article <35532DF5.BEF2F206@matrox.com>,
>         Ala Qumsieh <aqumsieh@matrox.com> writes:
>
> > Why bother? A file is as temporary as you want it to be!
> >
> > Just create a file (I would call it MYFILE.TEMP or whatever),
>
> What if you have 40 concurrent processes trying to access that file?
> This might, for example, be the case if the processes are CGI
> programs.
>
> You really need to be more careful with temporary file names. One day
> it will bite you, if you aren't, and just assume things.
>
> Martien
> --
> Martien Verbruggen                  |
> Webmaster www.tradingpost.com.au    | If it isn't broken, it doesn't have
> Commercial Dynamics Pty. Ltd.       | enough features yet.
> NSW, Australia                      |





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

Date: Tue, 12 May 1998 20:42:18 GMT
From: Tom Phoenix <rootbeer@teleport.com>
To: "Ronald A. Andersen" <ronandersen@hotmail.com>
Subject: Re: Insecure $ENV
Message-Id: <Pine.GSO.3.96.980512134114.21974P-100000@user2.teleport.com>

On Tue, 12 May 1998, Ronald A. Andersen wrote:

> When I execute a the following Perl script with the SUID set, I receive
> the following message. What does it mean?

When perl gives you an unfamiliar diagnostic message, the perldiag manpage
is a good resource. It lists all of Perl's messages along with an
explanation of why they may appear. Does that tell you what you need to
know? Hope this helps!

-- 
Tom Phoenix       Perl Training and Hacking       Esperanto
Randal Schwartz Case:     http://www.rahul.net/jeffrey/ovs/



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

Date: Tue, 12 May 1998 15:43:23 -0500
From: Yong Huang <yong@shell.com>
Subject: Is if ($a="something") a bad style?
Message-Id: <3558B46B.C6ED1244@shell.com>

In C, we often say
if (a="something")
But in Perl, a warning is given. I want to shorten

$a="something";    #"something" could be &mysub which may return nothing

if ($a) {...

into one statement:

if ($a="something") {...

Is this a bad style? Thanks for advice.

Yong
Email:yong@shell.com



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

Date: Tue, 12 May 1998 20:44:52 GMT
From: "Mr. D" <rwilliams@altavista.net>
Subject: PROFESSIONAL PERL TRAINING
Message-Id: <3558b317.0@204.101.95.15>

I am searching for a professional institution in the Indiana or Ohio states
that offers beginning to advanced Perl Training.  I have been looking around
the web for about 2 weeks and haven't found anything even close.  Does
anyone out there know of such an organization that offers this type of
training.




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

Date: Tue, 12 May 1998 20:48:26 GMT
From: chip@mail.atlantic.net (Chip Salzenberg)
Subject: Re: Randomly sorting an array
Message-Id: <6jaclq$u6s$1@cyprus.atlantic.net>
Keywords: adieu codebreak staple worthwhile

Tom Phoenix  <rootbeer@teleport.com> wrote:
>    sub shuffle {
>	# returns a random shuffle of a given list
>	my @list = @_;			# private copy
>	for my $i (1..$#list) {		# Yes, start at 1!
>	    my $j = rand($i+1);		# pick one at or before $i
>	    @list[$i,$j] = @list[$j,$i];  # swap
>	}
>	@list;
>    }

A simpler approach:

    sub shuffle {
        my @new;
        push @new, $_[rand @_] while @_;
	@new;
    }

-- 
Chip Salzenberg                - a.k.a. -               <chip@pobox.com>
"I brought the atom bomb.  I think it's a good time to use it."  //MST3K
           ->  Ask me about Perl training and consulting  <-
     Like Perl?  Want to help out?  The Perl Institute: www.perl.org


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

Date: 12 May 1998 20:54:16 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: Randomly sorting an array
Message-Id: <6jacto$peb$1@csnews.cs.colorado.edu>
Keywords: adieu codebreak staple worthwhile

 [courtesy cc of this posting sent to cited author via email]

In comp.lang.perl.misc, chip@mail.atlantic.net (Chip Salzenberg) writes:
:A simpler approach:
:    sub shuffle {
:        my @new;
:        push @new, $_[rand @_] while @_;
:	@new;
:    }

And when were you expecting @_ to go false?

--tom
-- 
    You can't set a breakpoint on a subroutine that hasn't been
    defined yet (yet).  This is a topic for ongoing research...  :-)
	--Larry Wall in <1994Feb25.192042.17196@netlabs.com>


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

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

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