[19010] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 1205 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Jun 27 14:09:08 2001

Date: Wed, 27 Jun 2001 11:05:09 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <993665109-v10-i1205@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Wed, 27 Jun 2001     Volume: 10 Number: 1205

Today's topics:
        ANNOUNCE: eps2png 2.2 convert EPS to PNG/JPG/GIF (Johan Vromans)
    Re: Browser interface to Perl program? (Cameron Laird)
        Calling package subroutines (^CooL^)
    Re: Calling package subroutines <pne-news-20010627@newton.digitalspace.net>
    Re: Calling package subroutines (Anno Siegel)
    Re: Can't spawn-NOWAIT: (Rick Kasten)
        cant modify $_[x] ???? <patelnavin@icenet.net>
    Re: cant modify $_[x] ???? (Anno Siegel)
    Re: cant modify $_[x] ???? nobull@mail.com
        Compile perl on Solaris (Sourisseau)
    Re: Convert DD-MM-YYYY to age <holland@origo.ifa.au.dk>
        expression match help <greg_j_miller@agilent.com>
        Help: How to make a hash global viscido@u.washington.edu
    Re: Help: How to make a hash global <pne-news-20010627@newton.digitalspace.net>
    Re: image resampling <dwilga-MUNGE@mtholyoke.edu>
    Re: Interacting prompts with perl (Anno Siegel)
    Re: Interacting prompts with perl <nospam@newsranger.com>
    Re: Interacting prompts with perl (Anno Siegel)
        mod_perl simulate Apache #include virtual <webstuff@aopa.net>
        PERL and CGI under NT IIS <nospamdd0001@yahoo.com>
    Re: Perl-Mysql - inserting long fields (isterin)
    Re: Scanning a file in CGI <gnarinn@hotmail.com>
    Re: Script stops on multiple question marks (Darren Spidell)
    Re: string tokenization <derail.REMOVE@this.routergod.com>
    Re: string tokenization (Anno Siegel)
    Re: Unix filepath completion within perl? (Anno Siegel)
    Re: Upgrading a File Lock (What do you think this is, a <bart.lateur@skynet.be>
    Re: why are reference addresses not the same in C and P <dan@tuatha.sidhe.org>
    Re: why are reference addresses not the same in C and P (J.A.P.H.)
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: 27 Jun 2001 18:06:04 +0200
From: JVromans@Squirrel.nl (Johan Vromans)
Subject: ANNOUNCE: eps2png 2.2 convert EPS to PNG/JPG/GIF
Message-Id: <tjk18378iptf62@corp.supernews.com>

eps2png converts files from EPS format (Encapsulated PostScript) to
PNG (Portable Network Graphics), JPEG or GIF formats.

It uses Ghostscript to produce the images. Since modern GhostScript
programs do not support GIF due to copyright issues, GIF images are
produced via an additional Portable BitMap converter (PBM-package).

This program is distributed under the Perl Artistic License and the GPL.

NEW IN RELEASE 2.2
------------------

Support for antialiasing (enabled by default).
New -width and -height options.
Enhanced documentation.
Install tests (make test).

Previous release was 1.8.

PREREQUISITES
-------------

Perl5.004 or better.

Unix (although it is rumoured to work on Windows).

A GhostScript installation that can handle the desired output
formats (use `gs -h' to get a list of supported formats).

If you want GIF format and your GhostScript cannot produce this,
the Portable BitMap package (pbmplus or netpbm).

AVAILABILITY
------------

eps2png:

  http://search.cpan.org/search?mode=dist&query=eps2png
  http://www.squirrel.nl/people/jvromans/sw_eps2png.html

Ghostscript:

  http://www.ghostscript.org (GNU Ghostscript)
  http://sourceforge.net/projects/ghostscript (AFPL Ghostscript)

portable bitmap package:

  These packages (libgr from RedHat, netpbm and pbmplus) seems so
  abundant that I couldn't find any official web links ;-).

----------------------------------------------------------------------------
Johan Vromans                                           jvromans@squirrel.nl
Squirrel Consultancy                                Haarlem, the Netherlands
http://www.squirrel.nl                http://www.squirrel.nl/people/jvromans
PGP Key 2048/4783B14D     http://www.squirrel.nl/people/jvromans/pgpkey.html
----------------------- "Arms are made for hugging" ------------------------




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

Date: 27 Jun 2001 13:23:19 -0500
From: claird@starbase.neosoft.com (Cameron Laird)
Subject: Re: Browser interface to Perl program?
Message-Id: <BDBD07D874469F38.7D5AC04646203496.9B95FAAB98E6236D@lp.airnews.net>

In article <9haboq$kju$00$3@news.t-online.com>,
Buggs  <buggs-clpm@splashground.de> wrote:
>David Coppit wrote:
>
>> I'd like add a cross-platform GUI interface to my Perl program.
>> Perl/Tk is... well... ugly. AFAICT, there's no way to get Perl/Tk to
>> use platform-specific widgets.
>> 
>> So... I'd like to use an HTML interface. Unfortunately, I can't assume
>> that a web server is running on the machine. If I want an HTML
>> interface, it seems to me that I need to embed a web server in my
>> application (**shiver**). Can anyone think of another solution? If
>> not, has anyone written a simple embedded web server with a CGI
>> interface?
>> 
>
>
>There is HTTP::Daemon.
>Doesn't give you CGI.
			.
			.
			.
tclhttpd <URL: http://tcl.activestate.com/software/tclhttpd/ >
is a tiny, surprisingly high-performance Web server which
supports CGI, along with "microscripting".  As you already have
experience with Tk, perhaps use of a component which requires
Tcl will be compatible with your aims.  Incidentally, TclKit
<URL: http://starbase.neosoft.com/~claird/comp.lang.tcl/tclkit.html >
is a project which wraps up such stuff as this into a single-
file executable.  Note that several Tcl extensions make it
possible to interpret Perl source directly.
-- 

Cameron Laird <claird@NeoSoft.com>
Business:  http://www.Phaseit.net
Personal:  http://starbase.neosoft.com/~claird/home.html


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

Date: 27 Jun 2001 08:16:00 -0700
From: cool133@hotmail.com (^CooL^)
Subject: Calling package subroutines
Message-Id: <211c8e3f.0106270716.20f52c45@posting.google.com>

Hi.

I have created a package called Conf.pm, in which I intend to put
certain initialisation routines and configuration variables.

Here is an extract of the code in Conf.pm


package Dir::Conf;
use strict; # I am using mod_perl.

BEGIN {
  use Exporter ();

  @Dir::Conf::ISA       = qw(Exporter);
  @Dir::Conf::EXPORT    = qw();
  @Dir::Conf::EXPORT_OK = qw(%config @connectionPool);
}

# Global variables
use vars qw(%config @connectionPool);

sub initialise {
  ....
}


Now, in the script that uses this package, I write:


use lib qw(..); # Script is in directory 'Dir/Admin' while package is
in 'Dir'

# Import Global Variables
use vars qw(%config @connectionPool);
*config = \%Conf::config;
*connectionPool = \%Conf::connectionPool;

# Call init sub from package
Conf::initialise();


On running this script, I get the following error message:
  Undefined subroutine &Conf::initialise called at ./start.cgi

How on earth could this be??

Any help will be most appreciated, as I am a bit of a newbie with Perl
and I need this urgently!!

Regards,
Clyde.


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

Date: Wed, 27 Jun 2001 17:24:13 +0200
From: Philip Newton <pne-news-20010627@newton.digitalspace.net>
Subject: Re: Calling package subroutines
Message-Id: <3dujjt4ncee60302jc2grqavqesl6gkhtu@4ax.com>

On 27 Jun 2001 08:16:00 -0700, cool133@hotmail.com (^CooL^) wrote:
> I have created a package called Conf.pm

I doubt it. Looks like you have a *file* called Conf.pm which declares a
*package* called Dir::Conf. See:

> package Dir::Conf;

[snip]
> On running this script, I get the following error message:
>   Undefined subroutine &Conf::initialise called at ./start.cgi
> 
> How on earth could this be??

I didn't see you 'use Dir::Conf;', so the subroutine never got defined.

Also, you shouldn't have to do this:

> # Import Global Variables
> use vars qw(%config @connectionPool);
> *config = \%Conf::config;
> *connectionPool = \%Conf::connectionPool;

, as Dir::Conf will export those variables for you if you ask nicely,
thanks to Exporter:

>   @Dir::Conf::EXPORT_OK = qw(%config @connectionPool);

So 'use Dir::Conf qw(%config @connectionPool);' should work.

You'll probably also have to change "use lib qw(..)" to "use lib
qw(../..)" since "use Dir::Conf" will look for "Dir/Conf.pm" not just
"Conf.pm".

But even then, Conf.pm declared the package Dir::Conf and not Conf, so
the subroutine will be Dir::Conf::initialise.

Cheers,
Philip

Cheers,
Philip
-- 
Philip Newton <nospam.newton@gmx.li>
Yes, that really is my address; no need to remove anything to reply.
If you're not part of the solution, you're part of the precipitate.


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

Date: 27 Jun 2001 16:52:53 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Calling package subroutines
Message-Id: <9hd315$i3a$2@mamenchi.zrz.TU-Berlin.DE>

According to ^CooL^ <cool133@hotmail.com>:
> Hi.
> 
> I have created a package called Conf.pm, in which I intend to put
> certain initialisation routines and configuration variables.
> 
> Here is an extract of the code in Conf.pm
> 
> 
> package Dir::Conf;
> use strict; # I am using mod_perl.

"use strict" needs no justification.  You should also "use warnings".

> BEGIN {
>   use Exporter ();
> 
>   @Dir::Conf::ISA       = qw(Exporter);
>   @Dir::Conf::EXPORT    = qw();
>   @Dir::Conf::EXPORT_OK = qw(%config @connectionPool);
> }
> 
> # Global variables
> use vars qw(%config @connectionPool);
> 
> sub initialise {
>   ....
> }
> 
> 
> Now, in the script that uses this package, I write:
> 
> 
> use lib qw(..); # Script is in directory 'Dir/Admin' while package is
> in 'Dir'

This is not a good idea.  You are (apparently) assuming that initially
the current directory is where the script itself resides.  That can
be so, but doesn't have to.  Use the standard module FindBin, that
way you can reliable (well, more reliably) find the location of
your script.

> # Import Global Variables
> use vars qw(%config @connectionPool);
> *config = \%Conf::config;
> *connectionPool = \%Conf::connectionPool;

This operation is exactly what Exporter does for you ... if you let
it.  Instead of doing these symbol table manipulation yourself, just

  use Conf qw( %config @connectionPool);

This will load the file (something that didn't happen at all in
your code so far) and import the named variables.

> # Call init sub from package
> Conf::initialise();

Well, your package is "Dir::Conf", so that should be

  Dir::Conf::initialise();

Now (after use()-ing the module) this call should work.  Of course,
you could as well import initialize to your current package too.



[rest snipped]

Anno



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

Date: 27 Jun 2001 09:41:39 -0700
From: rckjr@yahoo.com (Rick Kasten)
Subject: Re: Can't spawn-NOWAIT:
Message-Id: <4ecf6f35.0106270841.3e0713ec@posting.google.com>

I actually just figured this out about an hour ago.  Add 

waitpid $pid, 0;

to your script when you are done with each individual call to
IO::Pipe.  That frees up the resource that is hanging onto a dead
process.  open2 can only handle a limited number of processes (128 or
64), so you have to unleash the process by waiting for it to close
itself (waitpid).

Rick

ddrewrey@extensis.com (Darin Drewrey) wrote in message news:<76ce08a4.0106261601.43cad21d@posting.google.com>...
> I'm receiving an error every so often while accessing a Cybercash
> library (CCMckDirectLib3_2.pm) with ActivePerl 5.6.1.626 for Windows
> 2000 Server.
> 
> open2: IO::Pipe: Can't spawn-NOWAIT: Resource temporarily unavailable
> at CCMckDirectLib3_2.pl line 432.
> 
> I saw that another use had this problem with Win98 but didn't see a
> fix. Any ideas?
> 
> Thanks in advance.


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

Date: Wed, 27 Jun 2001 21:13:48 +0530
From: "Aman Patel" <patelnavin@icenet.net>
Subject: cant modify $_[x] ????
Message-Id: <9hd2q3$d8mjf$1@ID-93885.news.dfncis.de>

why cant we modify $_[1...infinity] in a subroutine ? i am getting a waring
saying something like:

can't modify read-only value at line x

example:

&doRemovePipes( $text );

sub doRemovePipes {
    $_[0] =~ s/\|//g;
    return $_[0];
}

can we make it so that we can override the warning. (I know other ways of
the above subroutine, that would make it work, but i want to use the same
code, but without failing if possible).




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

Date: 27 Jun 2001 17:07:53 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: cant modify $_[x] ????
Message-Id: <9hd3t9$i3a$3@mamenchi.zrz.TU-Berlin.DE>

According to Aman Patel <patelnavin@icenet.net>:
> why cant we modify $_[1...infinity] in a subroutine ? i am getting a waring
> saying something like:
> 
> can't modify read-only value at line x
> 
> example:
> 
> &doRemovePipes( $text );
> 
> sub doRemovePipes {
>     $_[0] =~ s/\|//g;

This particular substitution would perhaps better be written as

      $_[0] =~ tr/|//d;

but the problem would be the same.

>     return $_[0];
> }
> 
> can we make it so that we can override the warning. (I know other ways of
> the above subroutine, that would make it work, but i want to use the same
> code, but without failing if possible).

Your code works fine, provided $text has been assigned some value.

The error you have seen happens when you call the subroutine with
a read-only parameter, such as "doRemovePipes( 'aaa|bbb')" or
"doRemovePipes( $1)".  The possibility of this error is the price
you pay for a sub that modifies its arguments.  It can always happen
that it is fed something unmodifiable.  You don't want to ignore that
case, do you?

Anno


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

Date: 27 Jun 2001 18:23:15 +0100
From: nobull@mail.com
Subject: Re: cant modify $_[x] ????
Message-Id: <u9zoatzvjw.fsf@wcl-l.bham.ac.uk>

"Aman Patel" <patelnavin@icenet.net> writes:

> why cant we modify $_[1...infinity] in a subroutine ?

In general you can, unless of course they contain read-only values.
(Remember the elements of @_ are _aliases_ for the arguments not
copies of the arguments).

> i am getting a waring saying something like:

Never post "something like" - always post the actual error message.
 
> can't modify read-only value at line x

That's not a warning.

If it were a warning then execution would continue.

> example:
> 
> &doRemovePipes( $text );
> 
> sub doRemovePipes {
>     $_[0] =~ s/\|//g;
>     return $_[0];
> }

That's not an example.

If it were an example the running it would reproduce the error.

For that to be an example you'd have to prepend something to make
$text become read-only.

example:

*text = \"This|is|a|constant";

&doRemovePipes( $text );

sub doRemovePipes {
    $_[0] =~ s/\|//g;
    return $_[0];
}


> can we make it so that we can override the warning.

There is no warning.  I could tell you how to trap errors but I don't
really think that's what you want to know.

> (I know other ways of the above subroutine, that would make it work,
> but i want to use the same code, but without failing if possible).

Well if you really insist that you don't want to modify &doRemovePipes
such that it does not treat it's first argument as an lvalue to be
modified you must only ever pass it modifyable lvalues.

e.g. 
&doRemovePipes( my $modifyable_copy_of_text = $text );

Now, what is it you really wanted to know?

-- 
     \\   ( )
  .  _\\__[oo
 .__/  \\ /\@
 .  l___\\
  # ll  l\\
 ###LL  LL\\


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

Date: 27 Jun 2001 10:28:43 -0700
From: pascal.sourisseau@businessobjects.com (Sourisseau)
Subject: Compile perl on Solaris
Message-Id: <c9434ed2.0106270928.73fd8c96@posting.google.com>

Hi,
We would compile perl on Solaris 2.6 but...........
we try to understand where there is an error... but we don't.
If somebody has an idea or can help you,


Perl Distribution : 5.6.1
Solaris 2.6 with already an perl 5.6 
cc : Forte 6 Update 1

we launch Configure, we think that we have readen INSTALL,
README.SOLARIS  and so on readen .. a lot of times...
but always there is an error...what error ? we don't know.
This is what we see :


          CCCMD =  cc -DPERL_CORE -c  -D_LARGEFILE_SOURCE
-D_FILE_OFFSET_BITS=64
          CCCMD =  cc -DPERL_CORE -c  -D_LARGEFILE_SOURCE
-D_FILE_OFFSET_BITS=64
          CCCMD =  cc -DPERL_CORE -c  -D_LARGEFILE_SOURCE
-D_FILE_OFFSET_BITS=64
          CCCMD =  cc -DPERL_CORE -c  -D_LARGEFILE_SOURCE
-D_FILE_OFFSET_BITS=64
make[2]: *** [Makefile] Error 255
make[2]: *** [Makefile] Error 255
make[1]: [_cleaner1] Error 2 (ignored)
rmdir: directory "lib/B": Directory not empty
rmdir: directory "lib/Data": Directory not empty
rmdir: directory "lib/IO/Socket": Directory not empty
rmdir: directory "lib/IO": Directory not empty
rmdir: directory "lib/Sys": Directory not empty
rmdir: directory "lib/Thread": Directory not empty
make[1]: [_cleaner2] Error 2 (ignored)
make: [_mopup] Error 1 (ignored)
make: [_mopup] Error 1 (ignored)
make: *** No rule to make target `realclean'.  Stop.
make: *** No targets.  Stop.


It seems that no binary files are made..
thanks 
Pascal



this is myconfig file :
#!/bin/sh

# This script is designed to provide a handy summary of the
configuration
# information being used to build perl. This is especially useful if
you
# are requesting help from comp.lang.perl.misc on usenet or via mail.

# Note that the text lines /^Summary of/ .. /^\s*$/ are copied into
Config.pm.
cat <<'!NO!SUBS!'
Summary of my perl5 (revision 5.0 version 6 subversion 1)
configuration:
  Platform:
    osname=solaris, osvers=2.6, archname=sun4-solaris
    uname='sunos aldebaran 5.6 generic_105181-20 sun4u sparc
sunw,ultra-250 '
    config_args='-Dprefix=/export/home/tcourant/BOPerl/perl
-Dinstallprefix=/export/home/tcourant/BOPerl/perl/install
-Dsiteprefix=/export/home/tcourant/BOPerl/perl/site
-Dvendorprefix=/export/home/tcourant/BOPerl/perl/vsite
-Uinstallusrbinperl -Uusedl -Uuseposix -Ui_gdbm -Uusethreads
-Uuse5005threads -Uusemymalloc -Uuseshrplib
-Dloclibpth=/space/WS6U1/SUNWspro/WS6U1/lib /usr/lib /usr/ccs/lib'
    hint=recommended, useposix=undef, d_sigaction=define
    usethreads=undef use5005threads=undef useithreads=undef
usemultiplicity=undef
    useperlio=undef d_sfio=undef uselargefiles=define usesocks=undef
    use64bitint=undef use64bitall=undef uselongdouble=undef
  Compiler:
    cc='cc', ccflags =' -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64',
    optimize=' ',
    cppflags=''
    ccversion='Sun WorkShop 6 update 1 C 5.2 2000/09/11',
gccversion='', gccosandvers=''
    intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=4321
    d_longlong=define, longlongsize=8, d_longdbl=define,
longdblsize=16
    ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t',
lseeksize=8
    alignbytes=8, usemymalloc=n, prototype=define
  Linker and Libraries:
    ld='ld', ldflags =' -L/space/WS6U1/SUNWspro/WS6U1/lib -L/usr/lib
-L/usr/ccs/lib '
    libpth=/space/WS6U1/SUNWspro/WS6U1/lib /usr/lib /usr/ccs/lib
    libs=-lsocket -lnsl -lm -lc
    perllibs=-lsocket -lnsl -lm -lc
    libc=/lib/libc.a, so=a, useshrplib=false, libperl=libperl.a
  Dynamic Linking:
    dlsrc=dl_none.xs, dlext=none, d_dlsymun=undef, ccdlflags=''
    cccdlflags='', lddlflags=''

!NO!SUBS!


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

Date: 27 Jun 2001 18:16:49 +0200
From: Steve Holland <holland@origo.ifa.au.dk>
Subject: Re: Convert DD-MM-YYYY to age
Message-Id: <w477kxxrj7y.fsf@origo.ifa.au.dk>

Batara Kesuma <bkesuma@REMOVE.CAPITALS.yahoo.com> writes:

> I am trying to convert DD-MM-YYYY to the age of the person now. I
> tried to change the birthday to epoch second with timelocal, and
> then change the time now to epoch second, and then subsctract it,
> and change the seconds to years. But it doesn't work fot birthday
> before 1970. Is there any other way to do this? Thank you very much.

     The best way is to convert DD-MM-YYYY to a Julian date, convert
the current date to a Julian date and subtract.  You can use the
Time::JulianDay module to do this, but I don't know if this module
works properly or not.  Julian date routines are notorious for
containing subtle errors since calendars, and converting between
different calendar systems, are non-trivial things.  I don't trust any
Julian date routine that I didn't write.  There is a reliable (at
least as far as I have tested it) javascript Julian date routine at
"http://aa.usno.navy.mil/AA/data/docs/JulianDate.html" if you don't
want to use the perl module.


=====================================================================
               To find out who and where I am look at:
               http://www.nd.edu/~sholland/index.html
=====================================================================


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

Date: Wed, 27 Jun 2001 10:31:37 -0700
From: Greg Miller <greg_j_miller@agilent.com>
Subject: expression match help
Message-Id: <3B3A1879.E0940EF7@agilent.com>

I want to match the expression below for "=" but *not* "==", "!=", or
">="

pcamsndt =((nlev==4)*cam4s+(nlev!=5)*cam5s+(nlev>=6)*cam6s)

I've come up with a few ugly expressions but I would like to have a more
elegant way of doing it - any experts out there have a good way?

Thanks!

-Greg




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

Date: 27 Jun 2001 08:54:04 -0700
From: viscido@u.washington.edu
Subject: Help: How to make a hash global
Message-Id: <m366dhly03.fsf@fiddler.u.washington.edu>


I am working with a tied hash, call it %db, using the MLDBM module. At
the top of the script I'm running, I tie %db through MLDBM to
data.db. Now, I want to call a subroutine in a module I made, and have
that subroutine perform some operations on %db. So for instance,
perhaps I have a printsort.pm module, which contains the printsort()
subroutine... and printsort()'s job is to take all the items in %db,
sort by key, and then print out the key and value of those items in
sorted order, using a special format that's designed just for
printsort(). 

Now, I know how to pass the hash into the subroutine as a hash, with

printsort(\%db)

However, suppose that printsort is designed, specifically, to always
sort and print %db, never anything else. Suppose further that
printsort might take other arguments, so that it's getting unwieldy,
something like

printsort($a, $b, $c, $d, \@e, \@f, \%db)

and I'd rather, since printsort ALWAYS sorts through and prints %db,
and never anything else, just have %db be "global" (if that's the
right word for it). In other words, I want to tie %db to data.db at
the top of the perlscript, and then never have to pass it to any other
module -- just have it exist as a global so that any module called by
the perlscript automatically has access to %db, without having to pass
it.

It seems to me there should be a fairly easy way to do this, and I
have the impression that "our" and some fancy footwork with use,
require, and package, might get the job done, but I'm at a loss to
figure out how. The books I have pretty much seem to indicate that
"There is no such thing as a real global in perl", and while that may
be the case, such statements aren't helping me accomplish the task at
hand. 

Can anyone offer any suggestions on how to do this?

Steve

-- 
Steven Viscido [viscido@u.washington.edu]
Department of Zoology, Box 351800 Kincaid Hall
University of Washington
Seattle, WA 98195	Tel: 206-221-6893


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

Date: Wed, 27 Jun 2001 18:15:57 +0200
From: Philip Newton <pne-news-20010627@newton.digitalspace.net>
Subject: Re: Help: How to make a hash global
Message-Id: <je1kjt420pgq9rcv36ik2t4a83oah6rqmj@4ax.com>

On 27 Jun 2001 08:54:04 -0700, viscido@u.washington.edu wrote:

> I want to tie %db to data.db at the top of the perlscript, and then
> never have to pass it to any other module -- just have it exist as a
> global so that any module called by the perlscript automatically has
> access to %db, without having to pass it.

Scope of the variable depends on how you declare it, not where you tie
it.

If you use 'our %db;', then you created a package global variable with
lexical scope. Then you can say 'our %db;' in another source file, and
the %db in that file will be the same as the %db in your file, providing
both files are in the same package.

If your modules live in a different package, it's probably easiest to
fully qualifiy the variable -- for example, as %::db or %main::db if you
want it to live in package 'main'.

Then if you tie %::db and later, subroutine 'printsort' in package
'Flirble::Flubble' access %::db, it'll get the same variable.

(And if you always fully qualify it, you don't need to predeclare it
with 'my', 'our', or 'use vars'.)

Cheers,
Philip
-- 
Philip Newton <nospam.newton@gmx.li>
Yes, that really is my address; no need to remove anything to reply.
If you're not part of the solution, you're part of the precipitate.


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

Date: Wed, 27 Jun 2001 15:38:52 GMT
From: Dan Wilga <dwilga-MUNGE@mtholyoke.edu>
Subject: Re: image resampling
Message-Id: <dwilga-MUNGE-268D7C.11385027062001@nap.mtholyoke.edu>

As a last resort, it *is* possible to use a module on a machine for which you 
can't do a real "make install". You just "make" the source and refer to the 
resulting .pm's directory in the @INC:

  BEGIN {
    push( @INC, '/wherever/pm/is/stored' );
  }

You will have to fudge this a little if there are implicit folders in the 
module's name, meaning if you are building Image::Magick, then you have to 
make sure the .pm is in a folder called Image and that you "push" a path which 
doesn't include Image at the end.

-- 
Dan Wilga          dwilga-MUNGE@mtholyoke.edu
** Remove the -MUNGE in my address to reply **


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

Date: 27 Jun 2001 16:13:36 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Interacting prompts with perl
Message-Id: <9hd0ng$e7p$2@mamenchi.zrz.TU-Berlin.DE>

According to Drew Myers  <nospam@newsranger.com>:
> >open (TAPES,"|/opt/omni/bin/omnirpt -report used_media  -timeframe 24 24")
> >open pipe to the program.
> >Then
> >
> >print TAPES ".....";  
> >feeds commands to it.
> 
> Ilya, that works great, thank you!  I've got another question though.  What if I
> want to capture the output from each of the commands I issue?  For instance,
> this doesn't work:
> 
> open (SILO,"|/opt/omni/lbin/uma -ioctl /dev/scsi/robot -barcode") || die "Can't close SILO: $!\n";

The operation is "open", but the die message speaks of "close".
Something's amiss.

The appropriateness of error messages is always worth an extra check.
If it's wrong, it can be very confusing, and the error won't turn up
during functional testing.

> print SILO "stat d\n";
> my @silostat=<SILO>;
> 
> I'm thinking there's probably a simple way to do this that I'm over-looking.

The problem is that Perl doesn't allow you to open both ends of a
command pipe, as it were.  You can either provide its STDIN or capture
its STDOUT, but not both.  The standard module IPC::Open2 overcomes
this limitation.

Anno


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

Date: Wed, 27 Jun 2001 17:29:48 GMT
From: Drew Myers <nospam@newsranger.com>
Subject: Re: Interacting prompts with perl
Message-Id: <gKo_6.866$f4.12237@www.newsranger.com>

>> open (SILO,"|/opt/omni/lbin/uma -ioctl /dev/scsi/robot -barcode") || die "Can't close SILO: $!\n";

Sorry about that.  That was a simple typo on my part.  The die should read
"Can't open SILO: $!\n";

>The operation is "open", but the die message speaks of "close".
>Something's amiss.
>The problem is that Perl doesn't allow you to open both ends of a
>command pipe, as it were.  You can either provide its STDIN or capture
>its STDOUT, but not both.  The standard module IPC::Open2 overcomes
>this limitation.
>
>Anno

My understanding of IPC::Open2 and IPC::Open3 is it really only works if I'm
passing to a command that "knows" how to handle pipes, like bc.  From the docs
"Programs like sort that read their entire input stream first ... are quite apt
to cause deadlock".

Am I misunderstanding the application of the Open2 module?  It seems like it
provides the same functionality as open(FH,"| foo |") but is limited to only
those commands that can handling being piped in the first place.

Thanks,
Drew




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

Date: 27 Jun 2001 17:53:28 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Interacting prompts with perl
Message-Id: <9hd6io$kd8$1@mamenchi.zrz.TU-Berlin.DE>

According to Drew Myers  <nospam@newsranger.com>:
> >> open (SILO,"|/opt/omni/lbin/uma -ioctl /dev/scsi/robot -barcode") ||
> die "Can't close SILO: $!\n";
> 
> Sorry about that.  That was a simple typo on my part.  The die should read
> "Can't open SILO: $!\n";
> 
> >The operation is "open", but the die message speaks of "close".
> >Something's amiss.
> >The problem is that Perl doesn't allow you to open both ends of a
> >command pipe, as it were.  You can either provide its STDIN or capture
> >its STDOUT, but not both.  The standard module IPC::Open2 overcomes
> >this limitation.
> >
> >Anno
> 
> My understanding of IPC::Open2 and IPC::Open3 is it really only works if I'm
> passing to a command that "knows" how to handle pipes, like bc.  From the docs
> "Programs like sort that read their entire input stream first ... are quite apt
> to cause deadlock".
> 
> Am I misunderstanding the application of the Open2 module?  It seems like it
> provides the same functionality as open(FH,"| foo |") but is limited to only
> those commands that can handling being piped in the first place.

There is no special requirement (at least under Unix) for a command
to be able to handle pipes, they all do.  Even the sort command can be
used with Open2 if you give it all its input (and close the filehandle)
before trying to read something from it.

If you want to perform a kind of dialog with the command, sending
it some data, then reading the response and so on, you must have a
command that supports this.  dc is one of those.

Anno


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

Date: Wed, 27 Jun 2001 14:02:32 -0400
From: "Brian" <webstuff@aopa.net>
Subject: mod_perl simulate Apache #include virtual
Message-Id: <g9p_6.27169$f4.1211266@e420r-atl1.usenetserver.com>

I'm using mod_perl to create a PerlHandler routine, and would like that
routine to be able to emulate Apache <!-- #include
virtual="/cgi-bin/some.cgi"-->, (which is currently in use generating ad
banners).

I successfully did this in the PerlHandler using LWP and code like:

my $adBanner = get ('http://server/cgi-bin/some.cgi');
$r->print($adBanner);

But, is this optimal?  If I use backticks (or fork/exec), am I gaining or
losing performance?

Any other suggestions welcome.

Brian





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

Date: Wed, 27 Jun 2001 17:09:45 GMT
From: David <nospamdd0001@yahoo.com>
Subject: PERL and CGI under NT IIS
Message-Id: <3B3A1359.936CD6B6@yahoo.com>

I've been incorporating PERL into some of my web sites, and I'm having
some basic problems just opening data files.

These scripts are running on internal sites at my company.

They work on some servers but not others, and the NT administration folk
don't have a quick answer, although I think it has to do with
permissions.

Are there any experts out there running CGI scripts under NT?

Sample:

# -- Testing PERL - does it work on this server?
print "Content-type:text/html\n\n";
use English; # English language OS error message module

print <<EOF;
<html>
<head>
<title>Test Script</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<p><font size="4">This is a page to test PERL under IIS.</font></p>
EOF

$testData = "testdata.dat";
# ----- Subroutines -----
sub crash
{ print "Crashed: @_<BR>"; exit; 
};

open (TESTDATA, $testData) or &crash ("Can't open $testData:
$OS_ERROR");

($line = <TESTDATA>) or &crash ("Can't even read $testData: $OS_ERROR");
print "<BR>read $testData and got: $line<BR>";

print '<p><font size="4">', $string, '</font></p>';
print '</body>';
print '</html>';

testdata.dat is in the same folder and contains:

now is the time for all good men to get their PERL scripts running


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

Date: 27 Jun 2001 08:46:50 -0700
From: isterin@hotmail.com (isterin)
Subject: Re: Perl-Mysql - inserting long fields
Message-Id: <db67a7f3.0106270746.7663b1bd@posting.google.com>

"Gregory Toomey" <gtoomey@usa.net> wrote in message news:<5si_6.3857$e5.22261@newsfeeds.bigpond.com>...
> Hi everyone. I'm sure that this has been asked lots of times before but bear
> with me!
> 
> I just upgraded my web hosting to get Perl and mysql.
> 
> I want a general Perl script to insert/update mysql tables. I have found a
> script called Mysqledb http://www.solution4web.com/mysqlwdb/ which works but
> is very basic.
> The problem is that the browser fields in this script are about 16 chars
> long. I have some "text" fields my my database (length to 64K), and may need
> to write a small essay!
> 
> Are there any Perl scripts that allow allow insert/update of mysql tables,
> and will accommodate long text fields?
> 

Definitelly.  First the database needs to be set up with Long or BLOB
fields.
Then you can write a very simple script.  Hint - you must use
placeholders to insert Longs or LOB fields.

Ilya


> Thanks
> 
> Gregory Toomey


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

Date: Wed, 27 Jun 2001 16:23:33 +0000
From: gnari <gnarinn@hotmail.com>
Subject: Re: Scanning a file in CGI
Message-Id: <993659013.862498253583908.gnarinn@hotmail.com>

In article <3B39C5FC.C717C181@alcatel.be>,
Danny Hendrickx  <daniel.hendrickx@alcatel.be> wrote:
>
>This time I took your advice and ran the program without CGI and it
>worked. However, under CGI it doesn't. What I'm seeing is that the
>s1ccou.txt file never gets updated (or only once the first time) and
>that the s1docs.txt never gets appended to.
>

Then you should check environment and privileges.
When YOU test the script from command line, it inherits your
environment and privileges. in particular:
your path, your current directory, 
and read/write/execution privilege on your files

When the script is run as a CGI, it typically is run as user nobody and
no (or minimal) path, and with a current directory I would not depend on.
your files may not be writable by user 'nobody'

have you tested these things?

gnari


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

Date: 27 Jun 2001 10:31:54 -0700
From: dspidell@mta.ca (Darren Spidell)
Subject: Re: Script stops on multiple question marks
Message-Id: <f5d27ac9.0106270931.2c1fcd30@posting.google.com>

sweth+perl@gwu.edu (Sweth Chandramouli) wrote in message news:<YF1_6.16300$Ga.2338395@news1.rdc1.md.home.com>...
> In article <m3n16v73wz.fsf@dhcp9-173.support.tivoli.com>,
> Ren Maddox  <ren@tivoli.com> wrote:
> >I'm confused... if "etre???" should only match "etre" then what is the
> >point of the "?"-s?
>  [snip]
> >I'm still not clear on exactly what you are trying to achieve.  If you
> >want to ignore question marks, just use "tr/?//d" to strip them out.
> >If you want to match literal question marks, change your regex to
> >"/< */\Q$temp_response\E *>/".  If you want something different,
> >please elaborate.
> 	I think that his problem is that the question marks are 
> coming in from user input (e.g. a student who isn't sure of his answer 
> typing "etre???" at the prompt); he would like for that to not match, but
> instead his script hangs.  
That is exactly what is happening.

Normally, when faced with that string 
> interpolated into a regex, perl should die with something like
> 
> /etre???/: nested *?+ in regexp at -e line 1.
> 
> 	, unless the OP is somehow catching that error and not 
> dealing with it properly.  From what he gives us, though, I can't see any
> reason that that would be happening.
> 
> 	-- Sweth.

I disabled metachars, as Ren suggested in an earlier post, and it is
working fine now. Thanks to all who responded. I realize I have a lot
to learn about regular expressions.

Darren


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

Date: Wed, 27 Jun 2001 08:46:10 -0700
From: "Darryl H. Thomas" <derail.REMOVE@this.routergod.com>
Subject: Re: string tokenization
Message-Id: <20010627.084604.1001243552.6624@dhthomaslnx.mcafee.com>

In article <3B311892.81657E17@lbl.gov>, "Matthew Zhang da LBNL"
<lfzhang@lbl.gov> wrote:
 
> I want to read this file one line at a time, then basically extract the
> email address so that I can email another text file out... I am new to

perldoc perlfunc	and
perldoc perlre	would help you out with this one.

the jist is this:
# Get a file handle
open(FILE, "filename");
# Read the file into a list
my @LIST = <FILE>;
close FILE;
my $line;
foreach $line (@LIST) {
	# lose the newline
	chomp $line;
	# Extract the 'tokens'
	if ($line =~ /(\w+)\s(\w+)\s(\w+)/) {
		my $email = $1;
		my $first = $2;
		my $last = $3;
		# Do something with the address
		print $email . "\n";
	}
}

Be sure to read up on regular expressions (perldoc perlre), it will help
immensely.

Darryl H. Thomas


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

Date: 27 Jun 2001 17:28:15 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: string tokenization
Message-Id: <9hd53f$jie$1@mamenchi.zrz.TU-Berlin.DE>

According to Darryl H. Thomas <derail.REMOVE@this.routergod.com>:
> In article <3B311892.81657E17@lbl.gov>, "Matthew Zhang da LBNL"
> <lfzhang@lbl.gov> wrote:
>  
> > I want to read this file one line at a time, then basically extract the
> > email address so that I can email another text file out... I am new to
> 
> perldoc perlfunc	and
> perldoc perlre	would help you out with this one.
> 
> the jist is this:
> # Get a file handle
> open(FILE, "filename");

Always check the return value of open().  Especially when you give
advice to a beginner.

> # Read the file into a list
> my @LIST = <FILE>;
> close FILE;

Why on earth would you do that?  There is no reason whatsoever
to read all of the file at once. You can process each line as it
is read.

> my $line;
> foreach $line (@LIST) {

Just make that "while ( $line = <FILE> ) {"

> 	# lose the newline
> 	chomp $line;
> 	# Extract the 'tokens'
> 	if ($line =~ /(\w+)\s(\w+)\s(\w+)/) {

This assumes that the tokens are separated by exactly one whitespace
character.  I'm not sure what the OP specified (if anything) but it
would be more robust to allow \s+ between tokens.

Actually, most people would have used the split function here.

> 		my $email = $1;
> 		my $first = $2;
> 		my $last = $3;

These can be done in one go:

                my ( $email, $first, $last) = ( $1, $2, $3);

> 		# Do something with the address
> 		print $email . "\n";
> 	}
> }
> 
> Be sure to read up on regular expressions (perldoc perlre), it will help
> immensely.
> 
> Darryl H. Thomas

Putting everything together, I would modify your code as follows
(untested):

    open( FILE, $file) or die "Can't read $file: $!\n";
    while ( <FILE> ) {
        chomp;
        my ( $email, $first, $last) = split;
        # do something with the address
        print "$email\n";
    }

Anno


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

Date: 27 Jun 2001 15:24:51 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Unix filepath completion within perl?
Message-Id: <9hcts3$e7p$1@mamenchi.zrz.TU-Berlin.DE>

According to George Stevens  <george.stevens@baesystems.com>:
> Ok, hopefully someone is still reading this thread!
> 
> I've sort of got some file completion going using the following program:
> 
> use Term::Complete;
> 
> my @filenames;
> my $file;
> my $dir;
> 
> opendir(FILELIST, '.');
> while( defined ($file = readdir( FILELIST)))
> {
>    push(@filenames, "$dir/$file");
> };
> closedir( FILELIST);
> 
> my $input = Complete('enter file name > ', @filenames);
> 
> 
> This seems to work ok for /firstlevel, when you run it from the root.  However
> if you have /firstlevel/secondlevel, it can't find secondlevel, because
> @filenames was only filled the once at root level.
> So is there a way that I can feedback that the user has typed /firstlevel/s
> and now seeks a new list of @filenames?
> 
> I hope that I've explained that ok.

It doesn't look like you can do that using Term::Complete.  You would
have to you change the completion list on the fly when the user inputs
a "/" (and change it back when they backspace over it).  Complete
doesn't provide for that.

You will probably have to do it yourself, possibly starting from the
code in Complete.pm (it still won't be easy).

There may be a way to use a shell that does file completion to do
the input (and echo back the result), but I haven't thought about
that much.

Anno


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

Date: Wed, 27 Jun 2001 15:31:12 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Upgrading a File Lock (What do you think this is, a Holiday Inn?)
Message-Id: <htujjtssldqonvu2j9afkupd0d9q9r1l9h@4ax.com>

nobull@mail.com wrote:

>> There's the problem: the script can't get an exclusive lock while it currently
>> has a shared-lock
>
>It can on every OS I've used so long as it tries to upgrade the lock
>on same filehandle rather than opening a new one and trying to take a
>new lock on that.

See the thread that ctcgag pointed to. Abigail posted an example that
clearly shows that this is not how it works. I posted a possible
workaround, but you need to "announce" your intent to upgrade the lock,
if ever you plan to do so.

-- 
	Bart.


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

Date: Wed, 27 Jun 2001 15:40:45 GMT
From: Dan Sugalski <dan@tuatha.sidhe.org>
Subject: Re: why are reference addresses not the same in C and Perl?
Message-Id: <18n_6.117386$v5.8872710@news1.rdc1.ct.home.com>

J.A.P.H. <dont@mailme.com> wrote:

> My perl program calls a constructor in an XS file which returns a
> reference to a new object. Out of curiosity, I placed the following
> statement in the CODE section of the XS function 'new': 

> printf("Address from C:%x",RETVAL);

> In perl, once the the object is created, with something like

> $reference = package->new;

> I added this line:

> print "Address from perl: $reference\n";

> The two addresses I get back are not the same.

And they shouldn't be. The number perl prints is the address of
the reference scalar, while the address that the XS code
prints is for the actual XS data structure. Perl's basically
wrapping your pointer with a perl data structure so it
can deal with it safely.

					Dan


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

Date: Wed, 27 Jun 2001 15:54:52 GMT
From: dont@mailme.com (J.A.P.H.)
Subject: Re: why are reference addresses not the same in C and Perl?
Message-Id: <3b3a0021.1360028257@news.erols.com>

On Wed, 27 Jun 2001 15:40:45 GMT, Dan Sugalski <dan@tuatha.sidhe.org>
wrote:

>J.A.P.H. <dont@mailme.com> wrote:
>
>> My perl program calls a constructor in an XS file which returns a
>> reference to a new object. Out of curiosity, I placed the following
>> statement in the CODE section of the XS function 'new': 
>
>> printf("Address from C:%x",RETVAL);
>
>> In perl, once the the object is created, with something like
>
>> $reference = package->new;
>
>> I added this line:
>
>> print "Address from perl: $reference\n";
>
>> The two addresses I get back are not the same.
>
>And they shouldn't be. The number perl prints is the address of
>the reference scalar, while the address that the XS code
>prints is for the actual XS data structure. Perl's basically
>wrapping your pointer with a perl data structure so it
>can deal with it safely.
>					Dan

Jeez -- do I feel dumb. Of course $reference wouldn't be the correct
address. $$reference, on the other hand, does return the same address
as the XS code. It's the value of $reference that holds the address,
after all. I don't know how I managed to forget that...

Dan, thanks for the pointing me in the right direction.



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

Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 6 Apr 01)
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.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.

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 V10 Issue 1205
***************************************


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