[18660] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 828 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu May 3 14:05:59 2001

Date: Thu, 3 May 2001 11:05:11 -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: <988913110-v10-i828@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Thu, 3 May 2001     Volume: 10 Number: 828

Today's topics:
    Re: [OT: language religion ] Re: Should Perl be first? <flavell@mail.cern.ch>
    Re: [OT: language religion ] Re: Should Perl be first? (Abigail)
        ANNOUNCE: Lingua::Romana::Perligata 0.50 (Damian Conway)
        fork <a.v.a@home.nl>
    Re: fork <dassing@wettzell.ifag.de>
    Re: fork <a.v.a@home.nl>
    Re: fork (Mark Jason Dominus)
        FTP->new <ravi@farelogix.com>
    Re: FTP->new <miltonroad@btinternet.com>
    Re: GBDM flush (Anno Siegel)
    Re: How do I find the OS? <barce@slip.net>
    Re: HTML::LinkExtor (installing perl modules) <bjoern@hoehrmann.de>
    Re: Is it possible to find the position of a mismatch u (Abigail)
    Re: Is it possible to find the position of a mismatch u (Rafael Garcia-Suarez)
    Re: Is it possible to find the position of a mismatch u <ren@tivoli.com>
    Re: MIME::Lite ??? <msolomon@3s-technology.com>
        Need help installing Apache::Session::mysql <kristoffer@bastad.com>
    Re: newbie question <ren@tivoli.com>
    Re: Own module: how to export constants/subroutines of  nobull@mail.com
    Re: Posting Guidelines for comp.lang.perl.misc ($Revisi <henryhartley@westat.com>
    Re: Posting Guidelines for comp.lang.perl.misc ($Revisi (Tad McClellan)
    Re: Posting Guidelines for comp.lang.perl.misc ($Revisi (Christian Kaufhold)
    Re: Posting Guidelines for comp.lang.perl.misc ($Revisi <uri@sysarch.com>
        prevent empty message being sent? <bing-du@tamu.edu>
    Re: prevent empty message being sent? <andras@mortgagestats.com>
    Re: Prevent warning: check for open file handle? (Avinash Chopde; <avinash@acm.org>)
    Re: Problem with File::stat() mode <henryhartley@westat.com>
    Re: Problem with File::stat() mode (Gwen)
    Re: Problem with the subroutine (closure?) for the "sor nobull@mail.com
    Re: Problem with the subroutine (closure?) for the "sor <ren@tivoli.com>
        Question about scope of variables <andrew@mvt.ie>
    Re: Question about scope of variables nobull@mail.com
    Re: Question about scope of variables (Craig Berry)
    Re: Question about scope of variables (Anno Siegel)
    Re: re-evaluate as a scalar <ren@tivoli.com>
    Re: re-evaluate as a scalar nobull@mail.com
        Removing attributes <hamel@hotmail.com>
    Re: size information of sequences? (Anno Siegel)
    Re: size information of sequences? (Craig Berry)
    Re: size information of sequences? nobull@mail.com
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Thu, 3 May 2001 17:18:33 +0200
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: [OT: language religion ] Re: Should Perl be first?
Message-Id: <Pine.LNX.4.30.0105031716020.8651-100000@lxplus003.cern.ch>

On Thu, 3 May 2001, Martien Verbruggen wrote:

> On Wed, 2 May 2001 18:29:01 +0200,
> 	Rudolf Polzer <eins@durchnull.de> wrote:

> > Of course. On UNIX Perl is 1st choice.
>
> On Unix the most appropriate language is my first choice

Indeed.  And Unix has so many appropriate languages.

I found it far easier on MS Windows to feel sure that Perl was
the right choice  ;-))


[though I did once have a reasonably working REXX interpreter on MS-W]



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

Date: Thu, 3 May 2001 17:28:15 +0000 (UTC)
From: abigail@foad.org (Abigail)
Subject: Re: [OT: language religion ] Re: Should Perl be first?
Message-Id: <slrn9f359f.9k0.abigail@tsathoggua.rlyeh.net>

Alan J. Flavell (flavell@mail.cern.ch) wrote on MMDCCCII September
MCMXCIII in <URL:news:Pine.LNX.4.30.0105031716020.8651-100000@lxplus003.cern.ch>:
:)  On Thu, 3 May 2001, Martien Verbruggen wrote:
:)  
:) > On Wed, 2 May 2001 18:29:01 +0200,
:) > 	Rudolf Polzer <eins@durchnull.de> wrote:
:)  
:) > > Of course. On UNIX Perl is 1st choice.
:) >
:) > On Unix the most appropriate language is my first choice
:)  
:)  Indeed.  And Unix has so many appropriate languages.
:)  
:)  I found it far easier on MS Windows to feel sure that Perl was
:)  the right choice  ;-))


I'd phrase that as "Unix the the appropriate choice".



Abigail
-- 
:$:=~s:$":Just$&another$&:;$:=~s:
:Perl$"Hacker$&:;chop$:;print$:#:


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

Date: 3 May 2001 03:56:09 GMT
From: damian@cs.monash.edu.au (Damian Conway)
Subject: ANNOUNCE: Lingua::Romana::Perligata 0.50
Message-Id: <tf2thlolml23d2@corp.supernews.com>
Keywords: perl, module, release

==============================================================================
             Release of version 0.50 of Lingua::Romana::Perligata
==============================================================================


NOMEN

    Lingua::Romana::Perligata -- Perl in Latin

DESCRIPTIO

    The Lingua::Romana::Perligata makes it makes it possible to write Perl
    programs in Latin. (If you have to ask "Why?", then the answer probably
    won't make any sense to you either.)

    The linguistic principles behind Perligata are described in:

            http://www.csse.monash.edu.au/~damian/papers/HTML/Perligata.html

    The module is `use'd at the start of the program, and installs a filter
    which allows the rest of the program to be written in (modified) Latin,
    as described in the accompanying documentation.

EXEMPLUM

	#! /usr/bin/perl -w
        use Lingua::Romana::Perligata;

	adnota Illud Cribrum Eratothenis

        maximum tum val inquementum tum biguttam tum stadium egresso scribe.
        vestibulo perlegementum da meo maximo.
        maximum tum novumversum egresso scribe.
        da II tum maximum conscribementa meis listis.
        dum damentum nexto listis decapitamentum fac sic
               lista sic hoc tum nextum recidementum cis vannementa da listis.
               next tum biguttam tum stadium tum nextum tum novumversum
                        scribe egresso.
        cis.


SCRIPTOR

    Damian Conway (damian@conway.org)


IUS TRANSCRIBENDI

    Copyright (c) 2000, Damian Conway. All Rights Reserved.

    This module is free software. It may be used, redistributed and/or
    modified under the terms of the Perl Artistic License
    (see http://www.perl.com/perl/misc/Artistic.html)


==============================================================================

CHANGES IN VERSION 0.50

	- Fixed handling of 'posterus', 'ultimus' etc.

	- Fixed handling of 'si' (thanks James)

	- Added 'itera' for 'x' (thanks James)

	- Added the 'dictum sic..cis' construct for q{...} (thanks Peter)

	- Added "consocia" for &, "interseca" for |, and "discerne" for ^.

	- Add "cum" as precedence disambiguator

	- Fixed "sere" so that it doesn't space what it joins (thanks Philip)

	- Numerous documentation patches (thanks Todd and Philip)

	- Added "come" to convert numbers to roman numerals (thanks Anselm)

	- Added roman numerals up to 9,999,999,999 (thanks Anselm)


==============================================================================

AVAILABILITY

Lingua::Romana::Perligata has been uploaded to the CPAN
and is also available from:

	http://www.csse.monash.edu.au/~damian/CPAN/Lingua-Romana-Perligata.tar.gz

==============================================================================




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

Date: Thu, 03 May 2001 15:49:51 GMT
From: AvA <a.v.a@home.nl>
Subject: fork
Message-Id: <3AF15616.217C9C30@home.nl>

hi all,

i need to fork a program but i just cant figure fork() out.

i want to exec ("mpg123", $somesong);

could someone show me how fork works

thanks



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

Date: Thu, 03 May 2001 18:14:01 +0200
From: Reiner Dassing <dassing@wettzell.ifag.de>
To: AvA <a.v.a@home.nl>
Subject: Re: fork
Message-Id: <3AF183C9.2D8CE2C@wettzell.ifag.de>

AvA wrote:
> 
> hi all,
> 
> i need to fork a program but i just cant figure fork() out.
> 
> i want to exec ("mpg123", $somesong);
> 
> could someone show me how fork works
> 
> thanks

A simple start would be:

my $pid = fork();
if ( $pid < 0 ) {
   print STDERR "No Fork possible!\n";
   exit;
}
if ( $pid == 0 ) {
   print STDERR "Start Son!\n";
   son();
} else {
   print STDERR "Start Father!\n";
   father($pid);
}

--
Mit freundlichen Gruessen / With best regards
   Reiner Dassing


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

Date: Thu, 03 May 2001 16:24:27 GMT
From: AvA <a.v.a@home.nl>
Subject: Re: fork
Message-Id: <3AF15E32.A5124BEB@home.nl>

thats too abstract for me..could you show me an example that does
something?

thanks

Reiner Dassing wrote:

> AvA wrote:
> >
> > hi all,
> >
> > i need to fork a program but i just cant figure fork() out.
> >
> > i want to exec ("mpg123", $somesong);
> >
> > could someone show me how fork works
> >
> > thanks
>
> A simple start would be:
>
> my $pid = fork();
> if ( $pid < 0 ) {
>    print STDERR "No Fork possible!\n";
>    exit;
> }
> if ( $pid == 0 ) {
>    print STDERR "Start Son!\n";
>    son();
> } else {
>    print STDERR "Start Father!\n";
>    father($pid);
> }
>
> --
> Mit freundlichen Gruessen / With best regards
>    Reiner Dassing



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

Date: Thu, 03 May 2001 17:43:53 GMT
From: mjd@plover.com (Mark Jason Dominus)
Subject: Re: fork
Message-Id: <3af198d5.6ba6$7e@news.op.net>

In article <3AF15616.217C9C30@home.nl>, AvA  <a.v.a@home.nl> wrote:
>hi all,
>
>i need to fork a program but i just cant figure fork() out.

Don't use fork() directly.  Instead, use

        system("mpg123", $somsong);

This does the fork() internally to create a new process; then the new
process exec()'s msp123, while the main process waits for it to finish.

If you want the main process to continue with your code without
waiting, use

        system("mpg123 $somsong &");

fork() is only for unusual circumstances.

-- 
@P=split//,".URRUU\c8R";@d=split//,"\nrekcah xinU / lreP rehtona tsuJ";sub p{
@p{"r$p","u$p"}=(P,P);pipe"r$p","u$p";++$p;($q*=2)+=$f=!fork;map{$P=$P[$f^ord
($p{$_})&6];$p{$_}=/ ^$P/ix?$P:close$_}keys%p}p;p;p;p;p;map{$p{$_}=~/^[P.]/&&
close$_}%p;wait until$?;map{/^r/&&<$_>}%p;$_=$d[$q];sleep rand(2)if/\S/;print


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

Date: Thu, 3 May 2001 11:09:01 -0400
From: "Ravi Krishna" <ravi@farelogix.com>
Subject: FTP->new
Message-Id: <9crsbs$f4qi1$1@ID-75254.news.dfncis.de>

I am using perl FTP.

 my $ftp = Net::FTP->new($machineName,Timeout => 300) ;

The timeout is in minutes right. So the default of 120 is 2 hours.

Thanks.




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

Date: Thu, 3 May 2001 18:24:24 +0100
From: Milton Road <miltonroad@btinternet.com>
Subject: Re: FTP->new
Message-Id: <988910653.437263@dionysos>

Ravi Krishna wrote:

> I am using perl FTP.
> 
>  my $ftp = Net::FTP->new($machineName,Timeout => 300) ;
> 
> The timeout is in minutes right. So the default of 120 is 2 hours.

Your timeout is in seconds, Ravi.  Therefore the default of 120 is two 
minutes.  

Amazingly, the Net::FTP docs on the constructor don't seem to specify 
seconds - possibly because its reasonably self-explanatory.

Anyway, you know now.

Milton







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

Date: 3 May 2001 16:41:29 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: GBDM flush
Message-Id: <9cs1np$csu$2@mamenchi.zrz.TU-Berlin.DE>
Keywords: gbdm flush buffer

[posted and mailed]

According to Diana McCarthy <dianam@cogs.susx.ac.uk>:
> 
> I know I can do
> select("FILE");
> $| = 1;
> 
> but how can one use $| with output that goes to a dbm file, from within perl.

You don't, and you shouldn't have to.  Databases do their own buffer
management.

> I posted this already, having checked FAQ. Somehow it disappeared. Since I am
> new to newsgroups can any reply be posted here and emailed to
> dianam@cogs.susx.ac.uk. Also any advice on why my query disappeared before.

It didn't disappear, my server has it.  Depending on setup, it may
take a while until your articles are visible on your server.

Anno


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

Date: Wed, 02 May 2001 19:56:15 GMT
From: James Barcelona <barce@slip.net>
Subject: Re: How do I find the OS?
Message-Id: <zDZH6.3$oG3.153@news2.dnvrcoidc.firstworld.net>

Stuart Moore <stumo@bigfoot.com> wrote:
> How can I most easily find the OS from within a Perl script?

here's one way:
	print $ENV{"OSTYPE"}; 

--
http://www.slip.net/~barce



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

Date: Thu, 03 May 2001 19:58:20 +0200
From: Bjoern Hoehrmann <bjoern@hoehrmann.de>
Subject: Re: HTML::LinkExtor (installing perl modules)
Message-Id: <3af19c21.44214707@news.bjoern.hoehrmann.de>

* zaki wrote in comp.lang.perl.misc:
>I went to CPAN and downloaded the module it was complaining about and it
>worked. Only a small detail bothers me. i couldnt follow the intructions
>for installing the modules. It gave me an error message about the
>command 'make', so i just copied the file 'Tagset.pm' to the HTML
>directory in lib folder and it worked...so whats the difference between
>installing and copying modules...i never installed a module in linux, i
>used to use PPM in windows or just copy the module where it will be seen
>by perl...Whats the difference?

Take some time to read `perldoc perlmodinstall`
-- 
Björn Höhrmann { mailto:bjoern@hoehrmann.de } http://www.bjoernsworld.de
am Badedeich 7 } Telefon: +49(0)4667/981028 { http://bjoern.hoehrmann.de
25899 Dagebüll { PGP Pub. KeyID: 0xA4357E78 } http://www.learn.to/quote/


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

Date: Thu, 3 May 2001 17:30:43 +0000 (UTC)
From: abigail@foad.org (Abigail)
Subject: Re: Is it possible to find the position of a mismatch using regular    expressions in Perl?
Message-Id: <slrn9f35e3.9k0.abigail@tsathoggua.rlyeh.net>

Craig Manley (c.manley@_NOREPLY_chello.nl) wrote on MMDCCCII September
MCMXCIII in <URL:news:3AF17111.662D2DF0@_NOREPLY_chello.nl>:
**  Hi all,
**  
**  I've got this simple regular expression that checks the syntax of a
**  string of comma seperated phonenumbers starting with 00. The problem is
**  - if the string doesn't match my regex, then I don't know where the
**  mismatch occured. Is there a practical solution to this problem?


Parse::RecDescent.


Abigail


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

Date: 3 May 2001 15:32:58 GMT
From: rgarciasuarez@free.fr (Rafael Garcia-Suarez)
Subject: Re: Is it possible to find the position of a mismatch using regular  expressions in Perl?
Message-Id: <slrn9f2uiu.l2v.rgarciasuarez@rafael.kazibao.net>

Craig Manley wrote in comp.lang.perl.misc:
} Hi all,
} 
} I've got this simple regular expression that checks the syntax of a
} string of comma seperated phonenumbers starting with 00. The problem is
} - if the string doesn't match my regex, then I don't know where the
} mismatch occured. Is there a practical solution to this problem?

It's difficult to define "the place where the mismatch occured". A
string matches a regexp (at some position), or doesn't match at all.

} my $req = '0031615015032,0031655388294,0031620075361';
} if ($req =~ /^00\d{7,14}(,00\d{7,14}){0,999}$/) {

However in your case I suggest another approach : use split() to get an
array of phone numbers, and check the elements of this array to find out
whether some of them don't match /^00\d{7,14}$/ : you can then get their
indexes into the array.

Another (probably more effective) approach is to try to match only the
beginning of $req :

  if ($req =~ /^(00\d{7,14}(,00\d{7,14}){0,999})/) {
    if (length $1 != length $req) {
      # The regexp matched until the ($req - $1)th character and failed
      # to match the remaining string
    }
    ...
  } else {
    # There's no correct phone number at all
  }

but you will only have the 1st incorrect phone number.

-- 
Rafael Garcia-Suarez / http://rgarciasuarez.free.fr/


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

Date: 03 May 2001 10:40:39 -0500
From: Ren Maddox <ren@tivoli.com>
Subject: Re: Is it possible to find the position of a mismatch using regular  expressions in Perl?
Message-Id: <m37kzyl9u0.fsf@dhcp9-172.support.tivoli.com>

On Thu, 03 May 2001, c.manley@_NOREPLY_chello.nl wrote:

> Hi all,
> 
> I've got this simple regular expression that checks the syntax of a
> string of comma seperated phonenumbers starting with 00. The problem
> is - if the string doesn't match my regex, then I don't know where
> the mismatch occured. Is there a practical solution to this problem?

I'm not sure how practical this is, but you can use a zero-width code
assertion (experimental!) to keep track of progress.  The biggest thing
you have to watch-out for is that you put the assertion somewhere
where back-tracking doesn't mess it up.

#!/usr/bin/perl -w
use strict;
my $req = '0031615015032,0031655388294,0031620075361,bad,002342343';
my $num;
if ($req =~ /^00\d{7,14}(,(?{$num++})00\d{7,14}){0,999}$/) {
 print "Match\n";
}
else {
 print "Match failed at number $num!\n";
 # but at which character position did the matching go wrong?
}
__END__

An alternative would be to simply split on comma and match the numbers
individually, keeping track of progress.

-- 
Ren Maddox
ren@tivoli.com


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

Date: Thu, 3 May 2001 11:52:44 +0100
From: "Mike Solomon" <msolomon@3s-technology.com>
Subject: Re: MIME::Lite ???
Message-Id: <9crd9t$bur$1@taliesin.netcom.net.uk>

http://www.cpan.org/authors/id/ERYQ/MIME-Lite-2.111.tar.gz

Regards


Mike

"Hendrik Danz" <hendrik.danz@gmx.net> wrote in message
news:9crbrc$5m9$1@koroth.muc.eurocyber.net...
> hi,
> i'm looking for mime-lite module but can't find it anywhere.
> does anybody have a link?
>
> thnx
> hendrik
>
>




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

Date: Thu, 3 May 2001 18:40:24 +0200
From: "Kristoffer Malvefors" <kristoffer@bastad.com>
Subject: Need help installing Apache::Session::mysql
Message-Id: <LQfI6.2903$vR1.10020@nntpserver.swip.net>

Hi,

Software installed:
- Win32(Windows ME)
- ActiveState perl v 5.6.0 build 620
- Apache/1.3.19
- MySQL 3.23.37

I tried to install the Apache::Session::MySQL module
with the PPM but it couldnt find the PPD file.

So after searching some discussion areas I found a post telling me
to use the perl -MCPAN shell and then install Apache::Session::MySQL.

But im still uncertain of the proper way to do this and then how to use the
module.

regards
Kristoffer Malvefors
kristoffer@bastad.com










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

Date: 03 May 2001 09:44:50 -0500
From: Ren Maddox <ren@tivoli.com>
Subject: Re: newbie question
Message-Id: <m3g0emlcf1.fsf@dhcp9-172.support.tivoli.com>

On Thu, 03 May 2001, hpya78@postoffice.pacbell.net wrote:

> How to add up two numbers together?

Umm... "+".

But seriously, see the thread "Plz help a newbie add up elements of an
array", for a discussion of almost this exact question.

-- 
Ren Maddox
ren@tivoli.com


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

Date: 03 May 2001 17:44:49 +0100
From: nobull@mail.com
Subject: Re: Own module: how to export constants/subroutines of other modules
Message-Id: <u9g0emtm9q.fsf@wcl-l.bham.ac.uk>

"Alexander Farber (EED)" <eedalf@eed.ericsson.se> writes:

> I have grouped the variables and subroutines shared by
> several scripts into my own module. I wonder however,
> how to make avalailable some constants from other
> modules

The easiest thing to do is just do it.  Import the symbols into your
module's symbol table exactly as you normally would and then export
them from your module exactly as you normally would.

For a less simple approach see perldoc Exporter/"Exporting without
using Export's import method".

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


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

Date: Thu, 03 May 2001 11:05:56 -0400
From: Henry Hartley <henryhartley@westat.com>
Subject: Re: Posting Guidelines for comp.lang.perl.misc ($Revision: 1.1 $)
Message-Id: <3AF173D4.7BE1E931@westat.com>

clpmisc@dfw.pm.org wrote:
> 
>    Posting to comp.lang.perl.misc
>       Is there a better place to ask your question?
>        - Question should be about Perl, not about the application area

In the discussion of this, would it be helpful to actually list some of
the newsgroups where these OT posts should most commonly be directed? 
The two that come to mind quickly are:

comp.infosystems.www.authoring.cgi
comp.infosystems.www.servers.unix

but there are probably others that could be listed here.


>        - Count to ten before composing a followup when you are upset
>        - Count to ten after composing and before posting when you are upset

These two are not strictly speaking faux pas, they are good ideas.  So
perhaps either move them to the previous section (Posting to
comp.lang.perl.misc) or phrase them in the negative:

        - Not counting to ten before composing a follow-up when you are
upset
        - Not counting to ten after composing and before posting when
you are upset

I like this document a lot and will add a link to it from the dc.pm.org
page (if you don't mind).

-- 
Henry Hartley


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

Date: Thu, 3 May 2001 10:10:57 -0400
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Posting Guidelines for comp.lang.perl.misc ($Revision: 1.1 $)
Message-Id: <slrn9f2pnh.pb7.tadmc@tadmc26.august.net>

clpmisc@dfw.pm.org <clpmisc@dfw.pm.org> wrote:

>Posting Guidelines for comp.lang.perl.misc ($Revision: 1.1 $)

>[snip for testing]


Oh crud!

This was supposed to be going to a 'test' newsgroup.

I messed up. Sorry.



P.S. The Real Thing (autoposting) should begin next week if all
     goes according to plan...

-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


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

Date: Thu, 3 May 2001 18:06:15 +0200
From: usenet@chka.de (Christian Kaufhold)
Subject: Re: Posting Guidelines for comp.lang.perl.misc ($Revision: 1.1 $)
Message-Id: <8t3af1817ai28dn64@simia.chka.de>

clpmisc@dfw.pm.org wrote:

[...]
>      Social faux pas to avoid
>       - Asking a Frequently Asked Question
>       - Asking a question easily answered by a cursory doc search
>       - Asking for emailed answers
>       - Beware of saying "doesn't work"
>       - Count to ten before composing a followup when you are upset
>       - Count to ten after composing and before posting when you are upset


Isn't the logic of the last two items strange? Shouldn't they rather
listed under *what to do*?


Christian


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

Date: Thu, 03 May 2001 18:02:11 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: Posting Guidelines for comp.lang.perl.misc ($Revision: 1.1 $)
Message-Id: <x7ae4ue2fb.fsf@home.sysarch.com>

>>>>> "c" == clpmisc  <clpmisc@dfw.pm.org> writes:

  c>        - Do not type in Perl code
                    ^hand enter
		or   hand type.

it should say "instead cut and paste it" to be constructive.



-- 
Uri Guttman  ---------  uri@sysarch.com  ----------  http://www.sysarch.com
SYStems ARCHitecture and Stem Development ------ http://www.stemsystems.com
Learn Advanced Object Oriented Perl from Damian Conway - Boston, July 10-11
Class and Registration info:     http://www.sysarch.com/perl/OOP_class.html


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

Date: Thu, 03 May 2001 12:11:07 -0500
From: Bing Du <bing-du@tamu.edu>
Subject: prevent empty message being sent?
Message-Id: <3AF1912B.B53C1CAC@tamu.edu>

Hi,

In the following snippet of code, if RESULT is closed normally, then the
stuff printed to it can get sent out.  What if the script aborts before
close(RESULT), so RESULT will still be closed, but this time, an empty
message will be sent to user@tamu.edu.
How should I do to prevent empty message being sent?

open(RESULT,"|/usr/sbin/mailx -s 'a test message' user\@tamu.edu");
# print stuff to RESULT
close(RESULT);

Thanks,

Bing




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

Date: Thu, 03 May 2001 13:48:06 -0400
From: Andras Malatinszky <andras@mortgagestats.com>
Subject: Re: prevent empty message being sent?
Message-Id: <3AF199D6.E6C7B4B1@mortgagestats.com>



Bing Du wrote:

> Hi,
>
> In the following snippet of code, if RESULT is closed normally, then the
> stuff printed to it can get sent out.  What if the script aborts before
> close(RESULT), so RESULT will still be closed, but this time, an empty
> message will be sent to user@tamu.edu.
> How should I do to prevent empty message being sent?
>
> open(RESULT,"|/usr/sbin/mailx -s 'a test message' user\@tamu.edu");
> # print stuff to RESULT
> close(RESULT);
>
> Thanks,
>
> Bing

How's this?

#Put the stuff you want to send out in a variable called $message
#Check if $message is in a decent enough shape to be sent out, and send only
if
#yes, e.g.

if  ($message){
open(RESULT,"|/usr/sbin/mailx -s 'a test message' user\@tamu.edu");
# print stuff to RESULT
close(RESULT)};


#or maybe

if  ($message=~m/\S/){
open(RESULT,"|/usr/sbin/mailx -s 'a test message' user\@tamu.edu");
# print stuff to RESULT
close(RESULT)};



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

Date: Thu, 03 May 2001 17:14:45 GMT
From: achopde@BLACKHOLE.nyx.net (Avinash Chopde; <avinash@acm.org>)
Subject: Re: Prevent warning: check for open file handle?
Message-Id: <988909812.637351@irys.nyx.net>

In article <9cq2r0$pfa$2@mamenchi.zrz.TU-Berlin.DE>,
Anno Siegel <anno4000@lublin.zrz.tu-berlin.de> wrote:
>According to Greg Bacon <gbacon@hiwaay.net>:
>> In article <988824646.149539@irys.nyx.net>,
>>     Avinash Chopde; <avinash@acm.org> <avinash@acm.org> wrote:
>> 
>> : Is there a way to check if a filehandle is valid in perl?
>> : print FH "xxx" if (FH is valid);
>> : 
>> IO::Handle has an opened() method to check this:

This is cool - but looks like this works only because
IO::Handle's backward compatibility needs, and this is
listed as a feature in the "BUGS" section  of the IO::Handle
manpage - worries me that it may go away someday!

>Alternatively, "defined fileno FH" can be used.
>
>Normally you
>wouldn't install a signal handler in %SIG before everything is
>set up for it to run (which would include opening the file).
>Likewise, you'd remove the handler before you close the file.
>Anno

Not possible in my case, have multiple file handles, and
any method I come up with relies on variables that keep track
of whether a file open succeeded - much better just to check
if filepointer == NULL or similar in perl.
I could make some complicated logic just to handle this
so the sighandler does not need to know file handle status - 
but I need to maintain this code for a while, myself, so I don't want
to make it too complicated!

-- 
Avinash Chopde  
e-mail: avinash@acm.org
home page: http://www.aczone.com/ 



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

Date: Thu, 03 May 2001 11:29:05 -0400
From: Henry Hartley <henryhartley@westat.com>
Subject: Re: Problem with File::stat() mode
Message-Id: <3AF17941.F0459381@westat.com>

Gwen wrote:
> 
> -rwxr--r--  which I make a numerical value of 0744
> 
> When I use the File::stat module to get the mode I get a value of
> 33252 returned

Interestingly, octal 100744 equals decimal 33252.

Try:

foreach my $name (@check_extn) {
  my $stats = stat($name);
  my $mode = ($stats->mode);
  printf "%04o\n", $mode & 07777; 
}

-- 
Henry Hartley


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

Date: Thu, 03 May 2001 15:33:09 GMT
From: pettigrewg@cf.ac.uk (Gwen)
Subject: Re: Problem with File::stat() mode
Message-Id: <3af179bb.23991317@netnews.cf.ac.uk>

On Thu, 03 May 2001 11:29:05 -0400, Henry Hartley
<henryhartley@westat.com> wrote:

>Gwen wrote:
>> 
>> -rwxr--r--  which I make a numerical value of 0744
>> 
>> When I use the File::stat module to get the mode I get a value of
>> 33252 returned
>
>Interestingly, octal 100744 equals decimal 33252.
>
>Try:
>
>foreach my $name (@check_extn) {
>  my $stats = stat($name);
>  my $mode = ($stats->mode);
>  printf "%04o\n", $mode & 07777; 
>}
>
>-- 
>Henry Hartley

Thanks Henry.  I did think it may have been an octal number but when I
converted it, it didnt make sense.  

Thanks Again


###################################
Gwen Pettigrew
Cardiff Marine Institute

Crisis? What crisis? This is normal
###################################


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

Date: 03 May 2001 17:42:40 +0100
From: nobull@mail.com
Subject: Re: Problem with the subroutine (closure?) for the "sort"
Message-Id: <u9hez2tmdb.fsf@wcl-l.bham.ac.uk>

"Alexander Farber (EED)" <eedalf@eed.ericsson.se> writes:

> Subject: Problem with the subroutine (closure?) for the "sort"

Your problem has nothing to do with any of that.

The odd thing is that you wisely put a debugging print statment in
your code to help localise the problem and then appear to have ignored
what it is telling you.

>     sub sort_sub ($$)
>     {
>         my $path   = shift;
>         my $hohref = shift;
> 
>         if ($path =~ /\/PATH$/)                           # sort alphab. by path
>         {
>             return sub { $hohref -> {$a} -> {PATH} cmp $hohref -> {$b} -> {PATH} };
>         }   
>     
>         if ($path =~ /\/STAT$/)                           # sort alphab. by status
>         {
>            return sub { $hohref -> {$a} -> {STAT} cmp $hohref -> {$b} -> {STAT} };
>         }   
>     
>         print 'DEBUG';
>     
>         return sub { $a cmp $b };                         # sort by subsystem names
>     }
> 
> ...
>     my $sort = sort_sub ($query -> path_info, $hohref); # the sorting subroutine
> 
>     for my $sub (sort $sort keys %$hohref)
>     {
> ...
> 
> But it doesn't work: I always see the 'DEBUG' printed,

This means that either the return() function is broken (improbable) or
the two conditions in the if stements must be evaluating to false even
when you where hoping they'd evaluate to true.  This is what you
should investigate, and ingore all the stuff to do with sort
comparitors which is clearly not part of your immediate problem.

> and I also suspect that $a and $b are undefined anyway...

This is another problem.  $a and $b are package variables providing
sort_sub() is defined in the same package as the call to sort()
there's no problem.

If you want sort to use a comparison routine in another package then
see thread "Using a comparison routine in another package" from last
November or more recently "efficient comparators (namespaces for $a and
$b)" a few weeks ago.

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


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

Date: 03 May 2001 11:17:51 -0500
From: Ren Maddox <ren@tivoli.com>
Subject: Re: Problem with the subroutine (closure?) for the "sort"
Message-Id: <m33daml840.fsf@dhcp9-172.support.tivoli.com>

On Thu, 03 May 2001, eedalf@eed.ericsson.se wrote:

>     if ($query -> path_info =~ /\/PROJ$/)             # sort alphab. by projects
[snip]
>     elsif ($query -> path_info =~ /\/TCMPROJ$/)       # sort alphab. by TCMPROJ
[snip]
> 
>         if ($path =~ /\/PATH$/)                           # sort alphab. by path
[snip]
>         if ($path =~ /\/STAT$/)                           # sort alphab. by status
[snip]
> 
> But it doesn't work: I always see the 'DEBUG' printed,
> which means, I always get the last "sub { $a cmp $b }"
> and I also suspect that $a and $b are undefined anyway...

I would very much suspect that your patterns are not matching.
Actually, it is certainly true that your patterns are not matching.
Add some printing of $path to verify that it really ends with "PATH"
or "STAT".

Your strategy is sound, so it should be fine once you get the patterns
to match.

-- 
Ren Maddox
ren@tivoli.com


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

Date: Thu, 3 May 2001 17:43:22 +0100
From: "Andrew" <andrew@mvt.ie>
Subject: Question about scope of variables
Message-Id: <9cs1r5$tgl$1@kermit.esat.net>

Which is the better way of scoping variables in subroutines?  Should all
variables in that subroutine be declared towards the top, or should ones
that are only used in a loop within the subroutine be scoped to the smallest
loop in which they're needed.

I've knocked together an example (below) to illustrate my question.  In the
process_file subroutine, would it be better practise to put the initial
definitions of @x and $y in the subroutine rather than in the while loop, or
is it even much of an issue?

Thanks,

Andrew

Code:

#!/usr/bin/perl
use strict;
use warnings;

my $value = process_file("test.txt");
print $value;

sub process_file
{
    my $filename = $_[0];
    my $biggest = 0;
    open(INPUT,"$filename") || die "Can't open $filename for input.\n";
    while(<INPUT>)
    {
        chomp;
        my @x = split /\s+/;
        my $y = $x[0];
        if($y >= $biggest)
        {
            $biggest = $y;
        }
    }
    close(INPUT);
    return $biggest;
}






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

Date: 03 May 2001 17:58:49 +0100
From: nobull@mail.com
Subject: Re: Question about scope of variables
Message-Id: <u9d79qtlme.fsf@wcl-l.bham.ac.uk>

"Andrew" <andrew@mvt.ie> writes:

> Which is the better way of scoping variables in subroutines?  Should all
> variables in that subroutine be declared towards the top, or should ones
> that are only used in a loop within the subroutine be scoped to the smallest
> loop in which they're needed.

All other considerations being equal, the latter.  This has very
little to do with Perl - it is the same in any programming language
that has concepts analagous to Perl's my() and/or local() - which is
just about every non-trivial language you'll ever meet except dialects
of Pascal.

There maybe a small performance hit in re-initialising the variable
each time round the loop but if run-time performace was that crucial
you wouldn't be using Perl.

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


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

Date: Thu, 03 May 2001 17:38:08 -0000
From: cberry@cinenet.net (Craig Berry)
Subject: Re: Question about scope of variables
Message-Id: <tf35s0mbjp543f@corp.supernews.com>

Andrew (andrew@mvt.ie) wrote:
: Which is the better way of scoping variables in subroutines?  Should all
: variables in that subroutine be declared towards the top, or should ones
: that are only used in a loop within the subroutine be scoped to the smallest
: loop in which they're needed.

I prefer the latter.  In general, I declare variables in as small a scope
as possible, and wait until I can assign their initial value as part of
the declaration whenever that's convenient.  Doing this reduces semantic
clutter while trying to understand what the code is doing.

: I've knocked together an example (below) to illustrate my question.  In the
: process_file subroutine, would it be better practise to put the initial
: definitions of @x and $y in the subroutine rather than in the while loop, or
: is it even much of an issue?

It's an issue for human readers of your code far more than it is for perl
itself.  And as I said above, I prefer the least-scope, just-in-time
declaration approach.

-- 
   |   Craig Berry - http://www.cinenet.net/~cberry/
 --*--  "God becomes as we are that we may be as he is."
   |               - William Blake


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

Date: 3 May 2001 18:03:09 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Question about scope of variables
Message-Id: <9cs6gt$is7$1@mamenchi.zrz.TU-Berlin.DE>

According to Andrew <andrew@mvt.ie>:
> Which is the better way of scoping variables in subroutines?  Should all
> variables in that subroutine be declared towards the top, or should ones
> that are only used in a loop within the subroutine be scoped to the smallest
> loop in which they're needed.

[...]

Definitely the latter.  Keep the scope of all variables as small
as possible, and declare them as close as possible to their first
use.  Long lists of declarations at the beginning of a subroutine
were once enforced by some compilers, presumably to help save a
(-nother) compilation pass.  In severely types languages[1] it
may even make some sense to have one place to look up the declarations.
With Perl, there is rarely something in the declaration that can't
be inferred at the place of use as well.

This isn't meant to say that all variables that are used with a
loop (for instance) ought to be declared inside.  Sometimes you
must transport information out of a loop, which means you need a
variable whose scope is larger than the loop body.  It is still
advisable to declare it just before the loop, like so:

    my $found;
    while ( there_is_still_a_chance ) {
       ...
       $found = this_is_the_one;
       ...
    }
    if ( $found ) {
        ...
    }

These constructs are quite common.

Anno

[1] You are in a twisty maze of little types, all incompatible.


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

Date: 03 May 2001 10:03:22 -0500
From: Ren Maddox <ren@tivoli.com>
Subject: Re: re-evaluate as a scalar
Message-Id: <m3bspalbk5.fsf@dhcp9-172.support.tivoli.com>

On Thu, 03 May 2001, "relaxedrob@optushome.com.au" wrote:

> I want to have scalar that includes another scalar:
> 
> use strict;
> my $one = "";
> $two = "Isn't this a nice $one!";
> 
> I want to assign a particular value to $one whenever I need and then
> output $two so it will contain a 'dynamic' value of $one.

See the FAQ entry "How can I expand variables in text strings?".  You
should be able to get this via:

perldoc -q "expand variables"

-- 
Ren Maddox
ren@tivoli.com


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

Date: 03 May 2001 18:43:33 +0100
From: nobull@mail.com
Subject: Re: re-evaluate as a scalar
Message-Id: <u94rv2tjju.fsf@wcl-l.bham.ac.uk>

"Rob" <"relaxedrob@optushome.com.au"> writes:

FAQ: "How can I expand variables in text strings?"

You are expected to check the FAQ _before_ you post.

Actually I don't much like the answer in the FAQ so I recommend you
see also the last few dozen threads on this subject.

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


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

Date: Thu, 3 May 2001 11:37:15 -0400
From: "Philippe Hamel" <hamel@hotmail.com>
Subject: Removing attributes
Message-Id: <tf2up1evf07q6b@corp.supernews.com>

Hi,

I'm trying to delete attributes from an LDAP entry using perl and associated
modules.  I've figured out how to remove whole entries, but if I just want
to delete attributes from an entry, how do I do that?

Thank you!

--
Philippe Hamel
Bureau :
Courriel : phamel@logisil.com
Maison :
Courriel : philippe.hamel@apiiq.qc.ca





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

Date: 3 May 2001 16:24:51 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: size information of sequences?
Message-Id: <9cs0oj$csu$1@mamenchi.zrz.TU-Berlin.DE>

According to Joerg Behrens  <jbehren@gwdg.de>:
> Yet another fine-tune question:
> 
> Do strings and arrays carry information about their actual size?
> And if so, does it mean that expressions containing lots of
> 
> $#array, scalar @array, length($string)
> 
> are at least not slower than expressions where all size info
> has been copied to local scalars first (assuming constant sizes)?

Yes.

Anno


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

Date: Thu, 03 May 2001 17:16:03 -0000
From: cberry@cinenet.net (Craig Berry)
Subject: Re: size information of sequences?
Message-Id: <tf34ij3tddvjd7@corp.supernews.com>

Joerg Behrens (jbehren@gwdg.de) wrote:
: Do strings and arrays carry information about their actual size?

Yes.

: And if so, does it mean that expressions containing lots of
: 
: $#array, scalar @array, length($string)
: 
: are at least not slower than expressions where all size info
: has been copied to local scalars first (assuming constant sizes)?

Yes.

-- 
   |   Craig Berry - http://www.cinenet.net/~cberry/
 --*--  "God becomes as we are that we may be as he is."
   |               - William Blake


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

Date: 03 May 2001 18:43:08 +0100
From: nobull@mail.com
Subject: Re: size information of sequences?
Message-Id: <u966fitjkj.fsf@wcl-l.bham.ac.uk>

Joerg Behrens <jbehren@gwdg.de> writes:

> Yet another fine-tune question:

Ever heard of Benchmark?

> Do strings and arrays carry information about their actual size?

Yes.

> And if so, does it mean that expressions containing lots of
> 
> $#array, scalar @array, length($string)
> 
> are at least not slower than expressions where all size info
> has been copied to local scalars first (assuming constant sizes)?

Dunno, use Benchmark.

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


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

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


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