[11327] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4927 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Feb 18 10:07:31 1999

Date: Thu, 18 Feb 99 07:00:43 -0800
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Thu, 18 Feb 1999     Volume: 8 Number: 4927

Today's topics:
    Re: "Timeout" on opening a device? <aqumsieh@matrox.com>
        Change URL Displays <rjardin@golfway.com>
    Re: delete line? <aqumsieh@matrox.com>
        DEMO: dynamic scoping and typeglob trickery <tchrist@mox.perl.com>
        DEMO: File locking <tchrist@mox.perl.com>
        DEMO: separating stderr <tchrist@mox.perl.com>
        DOC: perlmodinstall.pod for 5.005_55 <tchrist@mox.perl.com>
        Special: Digest Administrivia (Last modified: 12 Dec 98 (Perl-Users-Digest Admin)

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

Date: Wed, 17 Feb 1999 15:50:14 -0500
From: Ala Qumsieh <aqumsieh@matrox.com>
Subject: Re: "Timeout" on opening a device?
Message-Id: <x3yogms69h5.fsf@tigre.matrox.com>


Claudio Strizzolo <Claudio.Strizzolo@trieste.infn.it> writes:

> identified as available by "who". When I try to "open" the connection 
> to such a terminal, it hangs and stays there forever.
> I am looking for a way to avoid this. Maybe a kind of timeout
> on the "open" function? Any hints?

Yeah .. the FAQs are your friend. From perlfaq8:

     non-blocking input
         If you are doing a blocking read() or sysread(), you'll
         have to arrange for an alarm handler to provide a
         timeout (see the alarm entry in the perlfunc manpage).
         If you have a non-blocking open, you'll likely have a
         non-blocking read, which means you may have to use a 4-
         arg select() to determine whether I/O is ready on that
         device (see the section on select in the perlfunc
         manpage.

Hope this helps,
Ala



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

Date: Thu, 18 Feb 1999 15:15:41 +0100
From: Ricardo Jardin <rjardin@golfway.com>
Subject: Change URL Displays
Message-Id: <36CC208D.16881F40@golfway.com>


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

I am a beginner at using Perl, and I have a question for anyone who can
help me.

I would like to mask or hide the URL that is automatically displayed by
Netscape and Internet Explorer.

For example :
http://www.golfway.com/epga.shtml   I would like the people not to see
the portion of epga.shtml.

I would like to accomplish this using Perl, if anyone can help me with
this I would greatly appreciate it.


--------------AC96899488C64257D9BF41C3
Content-Type: text/html; charset=us-ascii
Content-Transfer-Encoding: 7bit

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
I am a beginner at using Perl, and I have a question for anyone who can
help me.
<P>I would like to mask or hide the URL that is automatically displayed
by Netscape and Internet Explorer.
<P><B><I>For example :</I></B>
<BR><A HREF="http://www.golfway.com/epga.shtml">http://www.golfway.com/epga.shtml</A>&nbsp;&nbsp; I would like the people
not to see the portion of epga.shtml.
<P>I would like to accomplish this using Perl, if anyone can help me with
this I would greatly appreciate it.
<BR>&nbsp;</HTML>

--------------AC96899488C64257D9BF41C3--



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

Date: Wed, 17 Feb 1999 13:19:21 -0500
From: Ala Qumsieh <aqumsieh@matrox.com>
Subject: Re: delete line?
Message-Id: <x3ysoc46ggm.fsf@tigre.matrox.com>


dan <nospam-seallama@mailcity.com> writes:

> lets say i have the following in a file:
> 
> a
> b
> c
> d
> 
> and i pass a variable through. the variable contains "b", how do i get
> rid of the line that b is on instead of replacing it with ""? so the
> file contains:
> 
> a
> c
> d

Aha .. easy enough. What have you tried to do? Did you write any code?
Are you expecting someone to hand you the script? I won't. But I will
point you to where you could learn to do it yourself.

In 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?

Read it.

Ala

PS. comp.lang.perl doesn't exist. Don't post to it anymore.



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

Date: 18 Feb 1999 07:18:26 -0700
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: DEMO: dynamic scoping and typeglob trickery
Message-Id: <36cc2132@csnews>

Once you understand this program, you'll understand a great deal about
dynamic scoping, typeglobs, and why local isn't.  

--tom


$fmt = "a27 A9 A8 a*";
while (<DATA>) {
    ($pre, $login, $group, $post) = unpack($fmt, $_);
    print pack($fmt, $pre, id(login), id(group), $post);
} 

sub id { local *id = $_[0];
    defined $id{$id} ? $id{$id} : ($id{$id} = id);
} 

sub login { getpwnam($id) } 
sub group { getgrnam($id) } 

__END__
 18047    1 -rwxr-xr-x   1 root     root          395 Aug  5  1998 /bin/true
 18058   62 -rwxr-xr-x   1 root     mail        63116 Sep 11 11:39 /bin/mail
 18071   13 -rwxr-xr-x   1 root     bin         12624 Jun 20  1998 /bin/setserial
 31415   13 -rwxr-xr-x   1 daemon   bin          2121 Jun 16  1998 /bin/nonesuch
-- 
    last|perl -pe '$_ x=/(..:..)...(.*)/&&"'$1'"ge$1&&"'$1'"lt$2'
    That's gonna be tough for Randal to beat...  :-)
            --Larry Wall in  <1991Apr29.072206.5621@jpl-devvax.jpl.nasa.gov>


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

Date: 18 Feb 1999 07:25:49 -0700
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: DEMO: File locking
Message-Id: <36cc22ed@csnews>

1. Here's how to get a blocking shared lock on a file,
   typically used for reading:

    use 5.004;
    use Fcntl qw(:DEFAULT :flock);
    open(FH, "< filename") 	    or die "can't open filename: $!";
    flock(FH, LOCK_SH) 		    or die "can't lock filename: $!";
    # now read from FH

You can get a non-blocking lock by using

    flock(FH, LOCK_SH | LOCK_NB)    or die "can't lock filename: $!";

2. Here's how to get a blocking exclusive lock on a file,
   typically used for writing:

    use 5.004;
    use Fcntl qw(:DEFAULT :flock);
    sysopen(FH, "filename", O_WRONLY | O_CREAT)
				    or die "can't open filename: $!";
    flock(FH, LOCK_EX) 		    or die "can't lock filename: $!";
    truncate(FH, 0)		    or die "can't truncate filename: $!";
    # now write to FH

You can get a nonblocking version using 

    flock(FH, LOCK_EX | LOCK_NB)    or die "can't lock filename: $!";

3.  Here's how to update a file:

    use 5.004;
    use Fcntl qw(:DEFAULT :flock);

    sysopen(FH, "numfile", O_RDWR|O_CREAT)
				    or die "can't open numfile: $!";
    $ofh = select(FH); $| = 1; select ($ofh);
    flock(FH, LOCK_EX) 		    or die "can't write-lock numfile: $!";

    $num = <FH> || 0;
    seek(FH, 0, 0) 		    or die "can't rewind numfile : $!";
    print FH $num+1, "\n" 	    or die "can't write numfile: $!";

    truncate(FH, tell(FH)) 	    or die "can't truncate numfile: $!";
    close(FH)			    or die "can't close numfile: $!";

4.  Here's how to check for a lock:

    use 5.004;
    use Fcntl qw(:flock);
    unless (flock(FH, LOCK_EX|LOCK_NB)) {
	warn "Waiting for lock";
	flock(FH, LOCK_EX) 	    or die "can't lock filename: $!";
    } 
-- 
    Interestingly enough, since subroutine declarations can come anywhere,
    you wouldn't have to put BEGIN {} at the beginning, nor END {} at the
    end.  Interesting, no?  I wonder if Henry would like it. :-) --lwall 


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

Date: 18 Feb 1999 07:06:10 -0700
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: DEMO: separating stderr
Message-Id: <36cc1e52@csnews>

This is not in the current FAQ:

    open (CMD,
      "(cmd args | sed 's/^/STDOUT:/') 2>&1 |");

    while (<CMD>) {
      if (s/^STDOUT://)  {
	  print "line from stdout: ", $_;
      } else {
	  print "line from stderr: ", $_;
      }
    }

--tom
-- 
Under no circumstances should program the way I say because I say to;
program the way you think expresses best what you're trying to accomlish
in the program.  And do so consistently and ruthlesly.  --Rob Pike


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

Date: 18 Feb 1999 07:00:04 -0700
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: DOC: perlmodinstall.pod for 5.005_55
Message-Id: <36cc1ce4@csnews>

=head1 NAME

perlmodinstall - Installing CPAN Modules

=head1 DESCRIPTION

You can think of a module as the fundamental unit of reusable Perl
code; see L<perlmod> for details.  Whenever anyone creates a chunk of
Perl code that they think will be useful to the world, they register
as a Perl developer at http://www.perl.com/CPAN/modules/04pause.html
so that they can then upload their code to the CPAN.  The CPAN is the
Comprehensive Perl Archive Network and can be accessed at
http://www.perl.com/CPAN/.

This documentation is for people who want to download CPAN modules
and install them on their own computer.

=head2 PREAMBLE

You have a file ending in .tar.gz (or, less often, .zip).  You know
there's a tasty module inside.  There are four steps you must now
take:

=over 5

=item B<DECOMPRESS> the file

=item B<UNPACK> the file into a directory

=item B<BUILD> the module (sometimes unnecessary)

=item B<INSTALL> the module.

=back

Here's how to perform each step for each operating system.  This is
I<not> a substitute for reading the README and INSTALL files that
might have come with your module!

Also note that these instructions are tailored for installing the
module into your system's repository of Perl modules.  But you can
install modules into any directory you wish.  For instance, where I
say C<perl Makefile.PL>, you can substitute C<perl
Makefile.PL PREFIX=/my/perl_directory> to install the modules
into C</my/perl_directory>.  Then you can use the modules
from your Perl programs with C<use lib
"/my/perl_directory/lib/site_perl";> or sometimes just C<use
"/my/perl_directory";>.  

=over 4

=item *

B<If you're on Unix,>

You can use Andreas Koenig's CPAN module 
( http://www.perl.com/CPAN/modules/by-module/CPAN ) 
to automate the following steps, from DECOMPRESS through INSTALL.

A. DECOMPRESS 

Decompress the file with C<gzip -d yourmodule.tar.gz>

You can get gzip from ftp://prep.ai.mit.edu/pub/gnu. 

Or, you can combine this step with the next to save disk space:

     gzip -dc yourmodule.tar.gz | tar -xof -

B. UNPACK

Unpack the result with C<tar -xof yourmodule.tar>

C. BUILD

Go into the newly-created directory and type:

      perl Makefile.PL
      make
      make test

D. INSTALL

While still in that directory, type:

      make install

Make sure you have the appropriate permissions to install the module
in your Perl 5 library directory.  Often, you'll need to be root.

That's all you need to do on Unix systems with dynamic linking.
Most Unix systems have dynamic linking -- if yours doesn't, or if for
another reason you have a statically-linked perl, B<and> the
module requires compilation, you'll need to build a new Perl binary
that includes the module.  Again, you'll probably need to be root.

=item *

B<If you're running Windows 95 or NT with the ActiveState port of Perl>

   A. DECOMPRESS

You can use the shareware Winzip ( http://www.winzip.com ) to
decompress and unpack modules.

   B. UNPACK

If you used WinZip, this was already done for you.

   C. BUILD

Does the module require compilation (i.e. does it have files
that end in .xs, .c, .h, .y, .cc, .cxx, or .C)?  If it does, you're on
your own.  You can try compiling it yourself if you have a C compiler.
If you're successful, consider uploading the resulting binary to the
CPAN for others to use.  If it doesn't, go to INSTALL.

   D. INSTALL

Copy the module into your Perl's I<lib> directory.  That'll be one
of the directories you see when you type 

   perl -e 'print "@INC"'

=item *

B<If you're running Windows 95 or NT with the core Windows distribution of Perl,>

   A. DECOMPRESS

When you download the module, make sure it ends in either
C<.tar.gz> or C<.zip>.  Windows browsers sometimes
download C<.tar.gz> files as C<_tar.tar>, because
early versions of Windows prohibited more than one dot in a filename.

You can use the shareware WinZip ( http://www.winzip.com ) to
decompress and unpack modules.

Or, you can use InfoZip's C<unzip> utility (
http://www.cdrom.com/pub/infozip/Info-Zip.html ) to uncompress
C<.zip> files; type C<unzip yourmodule.zip> in
your shell.

Or, if you have a working C<tar> and C<gzip>, you can
type

   gzip -cd yourmodule.tar.gz | tar xvf -

in the shell to decompress C<yourmodule.tar.gz>.  This will
UNPACK your module as well.

   B. UNPACK

All of the methods in DECOMPRESS will have done this for you.

   C. BUILD

Go into the newly-created directory and type:

      perl Makefile.PL
      dmake
      dmake test

Depending on your perl configuration, C<dmake> might not be
available.  You might have to substitute whatever C<perl
-V:make> says. (Usually, that will be C<nmake> or
C<make>.)

   D. INSTALL

While still in that directory, type:

      dmake install

=item *

B<If you're using a Macintosh,>

A. DECOMPRESS

In general, all Macintosh decompression utilities mentioned here
can be found in the Info-Mac Hyperarchive
( http://hyperarchive.lcs.mit.edu/HyperArchive.html ).
Specificly the "Commpress & Translate" listing
( http://hyperarchive.lcs.mit.edu/HyperArchive/Abstracts/cmp/HyperArchive.html ).


You can either use the shareware StuffIt Expander 
( http://hyperarchive.lcs.mit.edu/HyperArchive/Archive/cmp/stuffit-expander-401.hqx ) 
in combination with I<DropStuff with Expander Enhancer>
( http://hyperarchive.lcs.mit.edu/HyperArchive/Archive/cmp/drop-stuff-with-ee-40.hqx ) 
or the freeware MacGzip (
http://persephone.cps.unizar.es/general/gente/spd/gzip/gzip.html ).


B. UNPACK

If you're using DropStuff or Stuffit, you can just extract the tar
archive.  Otherwise, you can use the freeware I<suntar> 
( http://hyperarchive.lcs.mit.edu/HyperArchive/Archive/cmp/suntar-221.hqx )
or I<Tar> ( http://hyperarchive.lcs.mit.edu/HyperArchive/Archive/cmp/tar-40b.hqx ).

C. BUILD

Does the module require compilation? 

1. If it does,

Overview: You need MPW and a combination of new and old CodeWarrior
compilers for MPW and libraries.  Makefiles created for building under
MPW use the Metrowerks compilers.  It's most likely possible to build
without other compilers, but it has not been done successfully, to our
knowledge.  Read the documentation in MacPerl: Power and Ease (
http://www.ptf.com/macperl/ ) on porting/building extensions, or find
an existing precompiled binary, or hire someone to build it for you.

Or, ask someone on the mac-perl mailing list (mac-perl@iis.ee.ethz.ch)
to build it for you.  To subscribe to the mac-perl mailing list, send
mail to mac-perl-request@iis.ee.ethz.ch.

2. If the module doesn't require compilation, go to INSTALL.

D. INSTALL

Make sure the newlines for the modules are in Mac format, not Unix format.
If they are not then you might have decompressed them incorrectly.  Check
your decompression and unpacking utilities settings to make sure they are
translating text files properly.
As a last resort, you can use the perl one-liner:  perl -i.bak -pe 
's/(?:\015)?\012/\015/g' <filenames> on the source files.

Move the files manually into the correct folders.

Move the files to their final destination: This will
most likely be in C<$ENV{MACPERL}site_lib:> (i.e.,
C<HD:MacPerl folder:site_lib:>).  You can add new paths to
the default C<@INC> in the Preferences menu item in the
MacPerl application (C<$ENV{MACPERL}site_lib:> is added
automagically).  Create whatever directory structures are required
(i.e., for C<Some::Module>, create
C<$ENV{MACPERL}site_lib:Some:> and put
C<Module.pm> in that directory).

Run the following script (or something like it):

     #!perl -w
     use AutoSplit;
     my $dir = "${MACPERL}site_perl";
     autosplit("$dir:Some:Module.pm", "$dir:auto", 0, 1, 1);

Eventually there should be a way to automate the installation process; some
solutions exist, but none are ready for the general public yet.

=item *

B<If you're on the DJGPP port of DOS,>

   A. DECOMPRESS

djtarx ( ftp://ftp.simtel.net/pub/simtelnet/gnu/djgpp/v2/ )
will both uncompress and unpack.  

   B. UNPACK

See above.

   C. BUILD

Go into the newly-created directory and type:

      perl Makefile.PL
      make
      make test

You will need the packages mentioned in C<Readme.dos>
in the Perl distribution.

   D. INSTALL

While still in that directory, type:

     make install	
     
You will need the packages mentioned in Readme.dos in the Perl distribution.

=item *

B<If you're on OS/2,>

Get the EMX development suite and gzip/tar, from either Hobbes (
http://hobbes.nmsu.edu ) or Leo ( http://www.leo.org ), and then follow
the instructions for Unix.

=item *

B<If you're on VMS,>

When downloading from CPAN, save your file with a C<.tgz>
extension instead of C<.tar.gz>.  All other periods in the
filename should be replaced with underscores.  For example,
C<Your-Module-1.33.tar.gz> should be downloaded as
C<Your-Module-1_33.tgz>.

A. DECOMPRESS

Type 

    gzip -d Your-Module.tgz

or, for zipped modules, type 

    unzip Your-Module.zip

Executables for gzip, zip, and VMStar ( Alphas:
http://www.openvms.digital.com/cd/000TOOLS/ALPHA/ and Vaxen:
http://www.openvms.digital.com/cd/000TOOLS/VAX/ ).  

gzip and tar
are also available at ftp://ftp.digital.com/pub/VMS.

Note that GNU's gzip/gunzip is not the same as Info-ZIP's zip/unzip
package.  The former is a simple compression tool; the latter permits
creation of multi-file archives.

B. UNPACK

If you're using VMStar:

     VMStar xf Your-Module.tar

Or, if you're fond of VMS command syntax:

     tar/extract/verbose Your_Module.tar

C. BUILD 

Make sure you have MMS (from Digital) or the freeware MMK ( available from MadGoat at  http://www.madgoat.com ).  Then type this to create the
DESCRIP.MMS for the module: 

    perl Makefile.PL

Now you're ready to build:

    mms
    mms test

Substitute C<mmk> for C<mms> above if you're using MMK.

D. INSTALL

Type 

    mms install

Substitute C<mmk> for C<mms> above if you're using MMK.

=item *

B<If you're on MVS>,

Introduce the .tar.gz file into an HFS as binary; don't translate from
ASCII to EBCDIC.

A. DECOMPRESS 

      Decompress the file with C<gzip -d yourmodule.tar.gz>

      You can get gzip from 
      http://www.s390.ibm.com/products/oe/bpxqp1.html.

B. UNPACK

Unpack the result with 

     pax -o to=IBM-1047,from=ISO8859-1 -r < yourmodule.tar

The BUILD and INSTALL steps are identical to those for Unix.  Some
modules generate Makefiles that work better with GNU make, which is
available from http://www.mks.com/s390/gnu/index.htm.

=back

=head1 HEY

If you have any suggested changes for this page, let me know.  Please
don't send me mail asking for help on how to install your modules.
There are too many modules, and too few Orwants, for me to be able to
answer or even acknowledge all your questions.  Contact the module
author instead, or post to comp.lang.perl.modules, or ask someone
familiar with Perl on your operating system.

=head1 AUTHOR

Jon Orwant 

orwant@tpj.com

The Perl Journal, http://tpj.com

with invaluable help from Brandon Allbery, Charles Bailey, Graham
Barr, Dominic Dunlop, Jarkko Hietaniemi, Ben Holzman, Tom Horsley,
Nick Ing-Simmons, Tuomas J. Lukka, Laszlo Molnar, Chris Nandor, Alan
Olsen, Peter Prymmer, Gurusamy Sarathy, Christoph Spalinger, Dan
Sugalski, Larry Virden, and Ilya Zakharevich.

July 22, 1998

=head1 COPYRIGHT

Copyright (C) 1998 Jon Orwant.  All Rights Reserved.

Permission is granted to make and distribute verbatim copies of this
documentation provided the copyright notice and this permission notice are
preserved on all copies.

Permission is granted to copy and distribute modified versions of this
documentation under the conditions for verbatim copying, provided also
that they are marked clearly as modified versions, that the authors'
names and title are unchanged (though subtitles and additional
authors' names may be added), and that the entire resulting derived
work is distributed under the terms of a permission notice identical
to this one.

Permission is granted to copy and distribute translations of this
documentation into another language, under the above conditions for
modified versions.

-- 
    "I will always write it the second way, so if you're optimizing for
    contrariness, it's obviously better to do it the second way."
    	--Larry Wall


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

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


Administrivia:

Well, after 6 months, here's the answer to the quiz: what do we do about
comp.lang.perl.moderated. Answer: nothing. 

]From: Russ Allbery <rra@stanford.edu>
]Date: 21 Sep 1998 19:53:43 -0700
]Subject: comp.lang.perl.moderated available via e-mail
]
]It is possible to subscribe to comp.lang.perl.moderated as a mailing list.
]To do so, send mail to majordomo@eyrie.org with "subscribe clpm" in the
]body.  Majordomo will then send you instructions on how to confirm your
]subscription.  This is provided as a general service for those people who
]cannot receive the newsgroup for whatever reason or who just prefer to
]receive messages via e-mail.

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

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