[19110] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 1305 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Jul 14 11:05:33 2001

Date: Sat, 14 Jul 2001 08:05:08 -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: <995123108-v10-i1305@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Sat, 14 Jul 2001     Volume: 10 Number: 1305

Today's topics:
        Can Perl be compiled, instead of translated? <mickymouse@disney.net.cn>
    Re: Can Perl be compiled, instead of translated? nobull@mail.com
    Re: easy multi-file find & replace? (Craig Berry)
        FAQ: How do I do (anything)? <faq@denver.pm.org>
        FAQ: What is perl.com? Perl Mongers? pm.org? perl.org? <faq@denver.pm.org>
    Re: file comparison problem <ds@ss.com>
    Re: file comparison problem <goldbb2@earthlink.net>
    Re: How do I execute an executable on Windows NT? <bart.lateur@skynet.be>
    Re: How to resolve multi process issue??? nobull@mail.com
    Re: newbe question <krahnj@acm.org>
    Re: perl debugger <SEE_MY_SIG@nospam.demon.co.uk>
        Recommendation for a book covering MySQL and Perl <g.soper@soundhouse.co.uk>
    Re: Replacing a word in a file (BUCK NAKED1)
    Re: Replacing a word in a file <cpryce@pryce.net>
    Re: Shouldn't -e return FALSE instead of UNDEFINED on n <krahnj@acm.org>
    Re: Shouldn't -e return FALSE instead of UNDEFINED on n <uri@sysarch.com>
    Re: Shouldn't -e return FALSE instead of UNDEFINED on n <qumsieh@sympatico.ca>
    Re: Sockets: What am I doing wrong? nobull@mail.com
    Re: vvp:CGI.pm printing vs executing statments? nobull@mail.com
    Re: warn() does not use a localized STDERR filehandle,  nobull@mail.com
    Re: Why is socket timeout not working? nobull@mail.com
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Sat, 14 Jul 2001 17:54:41 +0800
From: "micky" <mickymouse@disney.net.cn>
Subject: Can Perl be compiled, instead of translated?
Message-Id: <9ip4nd$a46$1@news.ctimail.com>

Would any one tell me whether we can write an application program in Perl,
which is like VB and C++, without the usage of the translator?




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

Date: 14 Jul 2001 13:55:04 +0100
From: nobull@mail.com
Subject: Re: Can Perl be compiled, instead of translated?
Message-Id: <u98zhrisbb.fsf@wcl-l.bham.ac.uk>

"micky" <mickymouse@disney.net.cn> writes:

> Would any one tell me whether we can write an application program in Perl,
> which is like VB and C++, without the usage of the translator?

See FAQ: "How can I compile my Perl program into byte code or C?"

You are supposed to consult the FAQ _before_ you post.

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


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

Date: Sat, 14 Jul 2001 06:17:20 -0000
From: cberry@cinenet.net (Craig Berry)
Subject: Re: easy multi-file find & replace?
Message-Id: <tkvovg9ufb4af9@corp.supernews.com>

Frank Nospam (yahoo_com@francis.uy) wrote:
:  cberry@cinenet.net (Craig Berry) wrote:
: >   find public_html -name '*.html' -exec perl -pi -e 's/foobar/fubar/' {} \;
: 
: Thanks much Craig, that's exactly the syntax I needed.
:  Now I ought learn what those switches mean, but I can
:  get that from the man.

'find' is pretty arcane, but well worth learning.

-- 
   |   Craig Berry - http://www.cinenet.net/~cberry/
 --*--  "Brute force done fast enough looks slick."
   |             - William Purves


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

Date: Sat, 14 Jul 2001 12:17:03 GMT
From: PerlFAQ Server <faq@denver.pm.org>
Subject: FAQ: How do I do (anything)?
Message-Id: <3LW37.132$T3.209145856@news.frii.net>

This message is one of several periodic postings to comp.lang.perl.misc
intended to make it easier for perl programmers to find answers to
common questions. The core of this message represents an excerpt
from the documentation provided with every Standard Distribution of
Perl.

+
  How do I do (anything)?

    Have you looked at CPAN (see the perlfaq2 manpage)? The chances are that
    someone has already written a module that can solve your problem. Have
    you read the appropriate man pages? Here's a brief index:

            Basics          perldata, perlvar, perlsyn, perlop, perlsub
            Execution       perlrun, perldebug
            Functions       perlfunc
            Objects         perlref, perlmod, perlobj, perltie
            Data Structures perlref, perllol, perldsc
            Modules         perlmod, perlmodlib, perlsub
            Regexes         perlre, perlfunc, perlop, perllocale
            Moving to perl5 perltrap, perl
            Linking w/C     perlxstut, perlxs, perlcall, perlguts, perlembed
            Various         http://www.perl.com/CPAN/doc/FMTEYEWTK/index.html
                            (not a man-page but still useful)

    A crude table of contents for the Perl man page set is found in the
    perltoc manpage.

- 

Documents such as this have been called "Answers to Frequently
Asked Questions" or FAQ for short.  They represent an important
part of the Usenet tradition.  They serve to reduce the volume of
redundant traffic on a news group by providing quality answers to
questions that keep coming up.

If you are some how irritated by seeing these postings you are free
to ignore them or add the sender to your killfile.  If you find
errors or other problems with these postings please send corrections
or comments to the posting email address or to the maintainers as
directed in the perlfaq manual page.

Answers to questions about LOTS of stuff, mostly not related to
Perl, can be found by pointing your news client to

    news:news.answers

or to the many thousands of other useful Usenet news groups.

Note that the FAQ text posted by this server may have been modified
from that distributed in the stable Perl release.  It may have been
edited to reflect the additions, changes and corrections provided
by respondents, reviewers, and critics to previous postings of
these FAQ. Complete text of these FAQ are available on request.

The perlfaq manual page contains the following copyright notice.

  AUTHOR AND COPYRIGHT

    Copyright (c) 1997-1999 Tom Christiansen and Nathan
    Torkington.  All rights reserved.

This posting is provided in the hope that it will be useful but
does not represent a commitment or contract of any kind on the part
of the contributers, authors or their agents.

                                                           03.01
-- 
    This space intentionally left blank


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

Date: Sat, 14 Jul 2001 06:17:00 GMT
From: PerlFAQ Server <faq@denver.pm.org>
Subject: FAQ: What is perl.com? Perl Mongers? pm.org? perl.org?
Message-Id: <wtR37.131$T3.192949248@news.frii.net>

This message is one of several periodic postings to comp.lang.perl.misc
intended to make it easier for perl programmers to find answers to
common questions. The core of this message represents an excerpt
from the documentation provided with every Standard Distribution of
Perl.

+
  What is perl.com? Perl Mongers? pm.org? perl.org?

    The Perl Home Page at http://www.perl.com/ is currently hosted on a T3
    line courtesy of Songline Systems, a software-oriented subsidiary of
    O'Reilly and Associates. Other starting points include

        http://language.perl.com/
        http://conference.perl.com/
        http://reference.perl.com/

    Perl Mongers is an advocacy organization for the Perl language which
    maintains the web site http://www.perl.org/ as a general advocacy site
    for the Perl language.

    Perl Mongers uses the pm.org domain for services related to Perl user
    groups, including the hosting of mailing lists and web sites. See the
    Perl user group web site at http://www.pm.org/ for more information
    about joining, starting, or requesting services for a Perl user group.

    Perl Mongers also maintain the perl.org domain to provide general
    support services to the Perl community, including the hosting of mailing
    lists, web sites, and other services. The web site http://www.perl.org/
    is a general advocacy site for the Perl language, and there are many
    other sub-domains for special topics, such as

        http://bugs.perl.org/
        http://history.perl.org/
        http://lists.perl.org/
        http://news.perl.org/
        http://use.perl.org/

- 

Documents such as this have been called "Answers to Frequently
Asked Questions" or FAQ for short.  They represent an important
part of the Usenet tradition.  They serve to reduce the volume of
redundant traffic on a news group by providing quality answers to
questions that keep coming up.

If you are some how irritated by seeing these postings you are free
to ignore them or add the sender to your killfile.  If you find
errors or other problems with these postings please send corrections
or comments to the posting email address or to the maintainers as
directed in the perlfaq manual page.

Answers to questions about LOTS of stuff, mostly not related to
Perl, can be found by pointing your news client to

    news:news.answers

or to the many thousands of other useful Usenet news groups.

Note that the FAQ text posted by this server may have been modified
from that distributed in the stable Perl release.  It may have been
edited to reflect the additions, changes and corrections provided
by respondents, reviewers, and critics to previous postings of
these FAQ. Complete text of these FAQ are available on request.

The perlfaq manual page contains the following copyright notice.

  AUTHOR AND COPYRIGHT

    Copyright (c) 1997-1999 Tom Christiansen and Nathan
    Torkington.  All rights reserved.

This posting is provided in the hope that it will be useful but
does not represent a commitment or contract of any kind on the part
of the contributers, authors or their agents.

                                                           03.00
-- 
    This space intentionally left blank


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

Date: Sat, 14 Jul 2001 04:13:18 GMT
From: GunneR <ds@ss.com>
Subject: Re: file comparison problem
Message-Id: <bp52lt0lbu0ovmcfpovmfk3orcu832mctb@4ax.com>

Looks like that might do the trick. But i'd like to know how to do it
without a fancy module :)

Ive retooled the code and about half of it works. It prints out the
lines that matched (yay!) but it doesnt print out the lines that do
not match... :(

open(FILE1, "c:/perl/1.txt");
open(FILE2, "c:/perl/2.txt");

foreach $line (<FILE1>) {
	while ($line2, <FILE2>) {
		if ($line2 = $line) { #this works (prints matched)
		print "Found matching $line in file 2!\n"; 
		last;
		}
		elsif ($line2 != $line) { #doesnt work (never prints
when lines are different)
		print "$line not found in file 2\n";
		next;
		}
	}
}

TIA for any help...

R


On 13 Jul 2001 22:10:50 -0500, Tony Curtis <tony_curtis32@yahoo.com>
wrote:

>>> On Sat, 14 Jul 2001 02:41:21 GMT,
>>> GunneR <ds@ss.com> said:
>
>> Trying to compare two files and print out any
>> differences between the two.
>
>http://search.cpan.org/
>
>look for "diff".
>
>hth
>t



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

Date: Sat, 14 Jul 2001 03:59:01 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: file comparison problem
Message-Id: <3B4FFBC5.D12843EA@earthlink.net>

GunneR wrote:
> 
> Trying to compare two files and print out any differences between the
> two.
> 
> open(FILE1, "c:/perl/1.txt");
> open(FILE2, "c:/perl/2.txt");
> 
> foreach $line (<FILE1>) {
>         if ($line =~ <FILE2>) { #prob is here
>                 print "Found matching line in file 2!\n";
>         }
>         else { print "$line not found in file 2\n";
>         }
> }
> 
> I know my problem is with the $line =~ <FILE2> but im not sure what to
> use. Thanks for any help :)

The =~ operator binds the lhs to $_ for matching, substitution, and
translation.  You want eq, for string equality.

open(FILE1, "c:/perl/1.txt") or die "Couldn't open 1.txt: $!\n";
open(FILE2, "c:/perl/2.txt") or die "Couldn't open 2.txt: $!\n";

my ($line1, $line2);
do {
	$line1 = <FILE1>;
	$line2 = <FILE2>;
	if( defined( $line1 ) != defined( $line2 ) ) {
		print "Files are unequal lengths.\n";
		print "File 1 is longer.\n" if defined($line1);
		print "File 2 is longer.\n" if defined($line2);
	}
	last unless (defined($line1) && defined($line2));
	if( $line1 ne $line2 ) {
		print "Lines $. differ:\n";
		print "File 1 contains $line1"; # $line1 includes \n
		print "File 2 contains $line2"; # $line1 includes \n
		last;
	}
}
close FILE1; close FILE2;

Note that this only shows the first line which differs.  For stuff more
complicated, you may want to look for a "diff" module on CPAN.

-- 
The longer a man is wrong, the surer he is that he's right.


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

Date: Sat, 14 Jul 2001 11:51:49 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: How do I execute an executable on Windows NT?
Message-Id: <9kc0lt4b4uce4304kh61mncq7d1r2dck1j@4ax.com>

Gregory Toomey wrote:

>> The code I'm trying to execute is given below:
>>
>> $execute = "program.exe file.txt";
>> system($execute);
>...
>
>Are you in the right directory?
>Maybe you need: $execute = "C:\path\program.exe file.txt";

Same problem with "file.txt". So a chdir might be easier:

	chdir 'c:/path';
	system('program.exe', 'file.txt');

-- 
	Bart.


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

Date: 14 Jul 2001 13:53:30 +0100
From: nobull@mail.com
Subject: Re: How to resolve multi process issue???
Message-Id: <u9bsmnisdx.fsf@wcl-l.bham.ac.uk>

gururaj@powertec.com (Gururaj Upadhye) writes:

> gnari <gnarinn@hotmail.com> wrote in message news:<995021225.499611284118146.gnarinn@hotmail.com>...
> > In article <23c54ab6.0107121536.536df790@posting.google.com>,
> > Gururaj Upadhye <gururaj@powertec.com> wrote:
> > >nobull@mail.com wrote in message news:<u9g0c284ei.fsf@wcl-l.bham.ac.uk>...
> > >> gururaj@powertec.com (Gururaj Upadhye) writes:
> > >> 
> > 
> > (snipped problem with mod_perl)

> > >The script that is producing this result is user_manage.cgi. I
> > >
> > can you provide a link to this script? i did not find it
> 
> Here it is
> http://stein.cshl.org/~lstein/user_manage/ documentation and to download use
> http://stein.cshl.org/WWW/software/user_manage/user_manage.tar.gz

As it happens I am already familar with this script.

Not all CGI scripts can be run under mod_perl's Apache::Registry
without modification.

Scripts run under CGI can assume that all global variables are reset
between calls and that all files are automatically closed at the end
of the script.  This assumption does not hold when running under mod_perl.

ISTR that in this particular case this script cannot be run under
mod_perl because it fails to close and unlock the password database.

FWIW the other major cause of CGI scripts not working under mod_perl
is because Apache::Registry effectively turns your script into a
subroutine.  If your script declares any file-scoped lexical variables
then these become subroutine-scoped instead leading to the following
problem as described in perldiag....

       Variable ""%s"" will not stay shared
           (W closure) An inner (nested) named subroutine is
           referencing a lexical variable defined in an outer
           subroutine.

           When the inner subroutine is called, it will probably
           see the value of the outer subroutine's variable as it
           was before and during the *first* call to the outer
           subroutine; in this case, after the first call to the
           outer subroutine is complete, the inner and outer
           subroutines will no longer share a common value for
           the variable.  In other words, the variable will no
           longer be shared.

           Furthermore, if the outer subroutine is anonymous and
           references a lexical variable outside itself, then the
           outer and inner subroutines will never share the given
           variable.

           This problem can usually be solved by making the inner
           subroutine anonymous, using the `sub {}' syntax.  When
           inner anonymous subs that reference variables in outer
           subroutines are called or referenced, they are
           automatically rebound to the current values of such
           variables.

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


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

Date: Sat, 14 Jul 2001 05:07:04 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: newbe question
Message-Id: <3B4FD37B.EDB2AB50@acm.org>

James Warpup wrote:
> 
> infact, this is my first script.
> and already i can't find the answer.
> 
> first, this is going to be a handy little tool that i'll use to grab the
> mask off a mask length.  here is a sample $line
> 
> 2        255.192.0.0    /10            2            4194302
> (bits    mask               length        subnets    hosts)
> here's the script....
> 
> #!perl;

#!perl -w
use strict;

All upper case for variable names is frowned upon.

> $FILE = 'mask.txt';
> $NUM = 0;
> print "What is the part of the mask you know?";
> $DoSearch = <STDIN>;
> $WHO = $DoSearch;

You are not using $DoSearch anywhere else and there is no point in
chomp-ing $WHO every time through the loop so:

chomp( $WHO = <STDIN> );


> open (INFO, $FILE);

You should _always_ check the return value of open()

open INFO, $FILE or die "Cannot read from $FILE: $!";


> while ($line = <INFO>) {
>     $_ = $line;

You are not using $line anywhere else and $_ is the default anyways:

while ( <INFO> ) {


>     chomp $WHO;
>     chomp;

You don't really need the chomp because your regular expression extracts
only the digits.


>     $NUM = $NUM + 1;

$NUM += 1;
# OR
$NUM++;

>      if (/(\d*)\s(...\....\..+\..+)\s\/(\d*)\s(\d*)\s(\d*)/) {

This regular expression doesn't match the data supplied above

     if ( /(\d+)\s+(\d+\.\d+\.\d+\.\d+)\s+\/(\d+)\s+(\d+)\s+(\d+)/ ) {

>      $BIT =$1;
>      $MASK = $2;
>      $LENGTH = $3;
>      $NETS = $4;
>      $HOSTS = $5;
>       if ($WHO == $BIT){
>        print "1 Bytes:$BIT\n"."Mask: $MASK\n"."Lenght: \/$LENGTH\n"."Number
> of Subnets: $NETS,\n"."Number of hosts: $HOSTS\n";
>        }
>       elsif ($WHO == $MASK){
>        print "2 Bytes:$BIT\n"."Mask: $MASK\n"."Lenght: \/$LENGTH\n"."Number
> of Subnets: $NETS,\n"."Number of hosts: $HOSTS\n";
>        }
>       elsif ($WHO == $LENGTH){
>        print "3 Bytes:$BIT\n"."Mask: $MASK\n"."Lenght: \/$LENGTH\n"."Number
> of Subnets: $NETS,\n"."Number of hosts: $HOSTS\n";
>        }
>       elsif ($WHO == $NETS){
>        print "4 Bytes:$BIT\n"."Mask: $MASK\n"."Lenght: \/$LENGTH\n"."Number
> of Subnets: $NETS,\n"."Number of hosts: $HOSTS\n";
>        }
>       elsif ($WHO == $HOSTS){
>        print "5 Bytes:$BIT\n"."Mask: $MASK\n"."Lenght: \/$LENGTH\n"."Number
> of Subnets: $NETS,\n"."Number of hosts: $HOSTS\n";
>        }
>      }
>     }
> #print "$BIT, $MASK, $LENGTH $NETS, $HOSTS, 1\n";
> 
> here's the problem,   i need to figure out how to set a unique identifier
> for each number variable so that i can tell the script which piece of
> information i have.
> 
> for example, lets say i know that it's a 2 bit mask.
> 
> i run the program, it asks "What is the part of the mask you know?"
> 
> i say 2, and it pulls any record with that matches  =~ /2/  (in mask.txt
> that means 2 values)
> 
> what i would like to do is be able to say "2 bits" and have it pull only
> records that match =~ /2 bits/

What are the other options besides "bits"?


> but i can't figure it out.... Help please!
> 
> also, as a side note, if else is one or the other, while if elsif is maybe 1
> then maybe 2 ect... ad nausim.  how do you do more than 2 statements that
> folow this pattern,
> if (statement 1 )  (action)
> ifnot (statement 1) but (statement 2) then (action 2)
> ifnot (statment 1) or (statemnt 2) then (action 3)  ect....

Are you looking for something like a switch statement?

http://search.cpan.org/search?dist=Switch




John
-- 
use Perl;
program
fulfillment


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

Date: Sat, 14 Jul 2001 11:36:28 +0100
From: James Taylor <SEE_MY_SIG@nospam.demon.co.uk>
Subject: Re: perl debugger
Message-Id: <ant141028d07fNdQ@oakseed.demon.co.uk>

In article <3b549a35.23305062@enews.newsguy.com>,
Chad Yoshikawa <m_010@yahoo.com> wrote:
> 
> I found programming in perl is hard since It don't have a nice
> debugger.  What do you guys think?

I think you must have the wrong approach to programming.

I produce working Perl code, and I don't use a debugger.
Those two things are not unrelated: I don't use a debugger
and *therefore* I produce working Perl code.

-- 
James Taylor <james (at) oakseed demon co uk>
Based in Southam, Cheltenham, UK.
PGP key available ID: 3FBE1BF9
Fingerprint: F19D803624ED6FE8 370045159F66FD02



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

Date: Sat, 14 Jul 2001 15:29:14 +0100
From: "Geoff Soper" <g.soper@soundhouse.co.uk>
Subject: Recommendation for a book covering MySQL and Perl
Message-Id: <9ipkj1$man$1@uranium.btinternet.com>

In the past I've written a simple database for a web site from scratch using
Perl, now I need to add more features to the database and a lot more records
so I'd like something faster and more robust. MySQL has been recommended and
we have a MySQL database provided on our server. I am very happy using Perl
so would like to continue doing so.

I know nothing of MySQL and very little of databases so I wonder if anyone
can recommend a book that would give me a grounding in MySQL from a Perl
angle. I was looking at the MySQL & mSQL book from O'reilly but it was badly
reviewed on Amazon. There seems to be plenty on MySQL and PHP but little
that mentions Perl.

I know there is plenty of information on-line but I'm a little old fashioned
and still prefer a book!

Many thanks!

Geoff






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

Date: Sat, 14 Jul 2001 01:48:33 -0500 (CDT)
From: dennis100@webtv.net (BUCK NAKED1)
Subject: Re: Replacing a word in a file
Message-Id: <20054-3B4FEB41-101@storefull-245.iap.bryant.webtv.net>

Thanks to all of you for pointing me in the
right direction. I meant to post my last response and accidentally
emailed Tad instead from the 'puter with the wrong username. With his
email help, I decided to use this...

`perl -p -i -e 's/$original/$replacement/g' $tmpfile`; 

 .. and that works great! It's so much simpler. Gotta start learnin'
those one liners! 

Otherwise, it appears that you have to open a file twice or make 2
copies just to replace a word; but maybe I misunderstand the docs in
that regard??? I even tried using sysopen. I do wonder why that FAQ
about deleting a line, and inserting... uses such a bloated example,
though.

and Tad: I didn't state something clearly (as usual). I wasn't trying
the same code for hours. I changed it a bit every time before I tested
it.

Regards,
--Dennis



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

Date: Sat, 14 Jul 2001 14:03:13 GMT
From: Christopher <cpryce@pryce.net>
Subject: Re: Replacing a word in a file
Message-Id: <B775BB8E.1C055%cpryce@pryce.net>

in article 20054-3B4FEB41-101@storefull-245.iap.bryant.webtv.net, BUCK
NAKED1 at dennis100@webtv.net wrote on 07/14/2001 1:48 AM:

> I do wonder why that FAQ about deleting a line, and inserting... uses such a
> bloated example, though.

That one liner _is_ in the FAQ.

cp




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

Date: Sat, 14 Jul 2001 04:20:23 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: Shouldn't -e return FALSE instead of UNDEFINED on non-existant file?
Message-Id: <3B4FC8D5.3191C469@acm.org>

pt wrote:
> 
> Tad McClellan wrote:
> 
> > pt <mnemotronic@yahoo.com> wrote:
> > >The generic description for the file test operators says they return 1
> > >for TRUE and '' for FALSE.  The -e (file exists) does not return FALSE
> > >if the file doesn't exist, it returns UNDEFINED, as do the other -X
> > >operators.
> > >   I know I'm picking at nano-nits while rowing upstream amd pissing
> > >into the wind here, but it makes sense (to me) for this operator to
> > >actually return TRUE or FALSE.
> > >   Is it possible for -e to ever return the FALSE value ('') ???
> >                                          ^^^^^^^^^^^^^^^
> >
> > -e *does* return a false value.
> >
> > Perl does not have _the_ false value. It has several false values.
> >
> 
>    Ok, what am I missing here???
>     This code
> 
> print 'file exists=',-e "xyzzy.plugh","\n";
> 
>     causes this
> 
> file exists=Use of uninitialized value in print at f2.pl line 64 (#1)
> 
>     The "-e "filename" should be either '1' or '', so the printed result
> should be either 'file exists=1' or 'file exists=', right???  It seems to
> be necessary to check for 'defined(-e "filename")'.

$ perl -we 'print "file ", -e "xyzzy.plugh" ? "exists" : "does not
exist", "\n"'
file does not exist
$ perl -we 'print "file ", -e "text.txt" ? "exists" : "does not exist",
"\n"'
file exists



John
-- 
use Perl;
program
fulfillment


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

Date: Sat, 14 Jul 2001 04:25:21 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: Shouldn't -e return FALSE instead of UNDEFINED on non-existant file?
Message-Id: <x7u20gw30u.fsf@home.sysarch.com>

>>>>> "p" == pt  <mnemotronic@mind\no-spam/spring.com> writes:

  p>    Ok, what am I missing here???
  p>     This code

  p> print 'file exists=',-e "xyzzy.plugh","\n";

  p>     causes this

  p> file exists=Use of uninitialized value in print at f2.pl line 64 (#1)

  p>     The "-e "filename" should be either '1' or '', so the printed result
  p> should be either 'file exists=1' or 'file exists=', right???  It seems to
  p> be necessary to check for 'defined(-e "filename")'.

that is the oddest use of -e i have ever seen. -e is a file test, not a
function that is defined to returned something that can be printed. it
is meant to be used in boolean contexts, period.

if you want something to print, convert it. it is trivial and had been
shown to you.

uri

-- 
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: Sat, 14 Jul 2001 00:49:44 -0400
From: "Ala Qumsieh" <qumsieh@sympatico.ca>
Subject: Re: Shouldn't -e return FALSE instead of UNDEFINED on non-existant file?
Message-Id: <%9Q37.41465$RX6.3315532@news20.bellglobal.com>


"pt" <mnemotronic@mind\no-spam/spring.com> wrote in message
news:3B4FBF0A.6EDF0AD@mindspring.com...
>
>
> Tad McClellan wrote:

> > -e *does* return a false value.
> >
> > Perl does not have _the_ false value. It has several false values.
> >
>
>    Ok, what am I missing here???

Did you read the documentation in perlfunc? Here's what it says:

    *-X* EXPR
    *-X*    A file test, where X is one of the letters listed below. This
            unary operator takes one argument, either a filename or a
            filehandle, and tests the associated file to see if something is
            true about it. If the argument is omitted, tests "$_", except
            for "-t", which tests STDIN. Unless otherwise documented, it
            returns "1" for true and "''" for false, or the undefined value
            if the file doesn't exist.

So, the undefined value is returned if -e fails.

>     This code
>
> print 'file exists=',-e "xyzzy.plugh","\n";
>
>     causes this
>
> file exists=Use of uninitialized value in print at f2.pl line 64 (#1)
>
>     The "-e "filename" should be either '1' or '', so the printed result
> should be either 'file exists=1' or 'file exists=', right???  It seems to
> be necessary to check for 'defined(-e "filename")'.

No. It is not necessary. As the documentation says, if the file doesn't
exist, an undefined value is returned, not the empty string. (Both of these
values are false in Perl, along with the number zero). Your code should read
like this:

    print "file exists = ", -e "xyzzy.plugh" ? 1 : 0, "\n";

To test for the existence of a file, you can simply do:

    if (-e "filename") {
        ...
    }

No need for defined().

--Ala





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

Date: 14 Jul 2001 13:37:21 +0100
From: nobull@mail.com
Subject: Re: Sockets: What am I doing wrong?
Message-Id: <u9hewfit4u.fsf@wcl-l.bham.ac.uk>

Vit Hotarek <xhotarek@fi.muni.cz> writes:

> when I run the script below, it produces
> desired output: response from the
> $remote_host on port $port.
> 
> But the problem is, that it doesn't
> end. I really have no idea how to
> solve it, i tried everything.

If you have tried everything then obviously there is no solution.

Personally I doubt that you've actually tried everything.

For instance, have you tried anything that might cause the thing at
the other end of the socket connection to close() (or at least
shutdown()) the socket?  That's what your code is waiting for.

>   use Socket;

Do you have a particular reason for no using IO::Socket?

>     while($line = <SOCK>)

This will loop until an EOF condition exists on SOCK.

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


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

Date: 14 Jul 2001 14:25:56 +0100
From: nobull@mail.com
Subject: Re: vvp:CGI.pm printing vs executing statments?
Message-Id: <u9y9prhcbf.fsf@wcl-l.bham.ac.uk>

"Prasad, Victor [FITZ:K500:EXCH]" <vprasad@americasm01.nt.com> writes:

> I have a litte piece of code - where the first to lines in the if
> statement just print to the screen -whereas the elsif actually execustes
> a statement - they are very much the same.  How do I make the first if
> execute - not display?

You are not showing us tha actual code.  I can tell this because 
comments in Perl are introduced with '#' not '<--'.  I'm fairly
confident that in transcribing fro code by hand you also eliminated
the typos that were responsible for your problems.

> I am using backquotes on each statement

Are you sure.  Are you really sure?

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


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

Date: 14 Jul 2001 14:08:11 +0100
From: nobull@mail.com
Subject: Re: warn() does not use a localized STDERR filehandle, how come?
Message-Id: <u966cvirpg.fsf@wcl-l.bham.ac.uk>

nico@arzoon.com (nico gianniotis) writes:

> Does anyone know why localizing STDERR, before reopening it, causes
> unexpected results from warn()? For example,

I believe warn() writes to the true standard error stream - i.e. file
descriptor 2.  If you do open(STRERR) in Perl wihout localizing
*STDERR then STDERR remains associated witn fd 2. If you localise
*STDERR then the original file handle remains assocuiated with fd 2
and the localized one gets a new fd.

Note: I'm only 70% confident that the above explaination is valid.

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


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

Date: 14 Jul 2001 13:42:30 +0100
From: nobull@mail.com
Subject: Re: Why is socket timeout not working?
Message-Id: <u9elrjisw9.fsf@wcl-l.bham.ac.uk>

"Haim Lichaa" <haim.lichaa@intel.com> writes:

> I'm using this perl snipit on a Solaris 2.51 box running Perl 5.00403
> 
> my($s)=IO::Socket::INET->new(
>   PeerAddr        => $host,
>   PeerPort        => $port,
>   Proto           =>'tcp',
>   Type            => SOCK_STREAM,
>   Timeout         => $to);
> 
> and any $to value has no affect on the Timeout. It remains constat @ ~4mins.
> Any body know why and how I can fix it?

I vaguely recall that the version of IO::Socket::INET that shipped
with 5.00403 didn't implement timouts properly.

Are you sure that it's the socket connect that's timing out not the
name lookup?

-- 
     \\   ( )
  .  _\\__[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 1305
***************************************


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