[19161] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 1356 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Jul 23 00:10:42 2001

Date: Sun, 22 Jul 2001 21:10:12 -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: <995861412-v10-i1356@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Sun, 22 Jul 2001     Volume: 10 Number: 1356

Today's topics:
        problems with chdir <lapenta_jm@yahoo.com>
    Re: problems with chdir <tony_curtis32@yahoo.com>
    Re: problems with chdir <krahnj@acm.org>
    Re: problems with chdir <lapenta_jm@yahoo.com>
    Re: problems with chdir <lapenta_jm@yahoo.com>
    Re: problems with chdir <godzilla@stomp.stomp.tokyo>
    Re: Redirecting STDERR <no@mail.addr>
    Re: Removing Tags <no@mail.addr>
        tiny perl <fabian@miczek.de>
        use attributes; subs : lvalue { return $this->{anyvar}  <murat.uenalan@gmx.de>
    Re: what is the defer form "my" to "local"? <no@mail.addr>
    Re: what is the defer form "my" to "local"? <no@mail.addr>
    Re: Who can help me about the confused (..) operator? <no@mail.addr>
    Re: Who can help me about the confused (..) operator? <no@mail.addr>
    Re: Who can help me about the confused (..) operator? (Eric Bohlman)
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Sun, 22 Jul 2001 21:04:42 -0400
From: Jason LaPenta <lapenta_jm@yahoo.com>
Subject: problems with chdir
Message-Id: <3B5B782A.53F8F833@yahoo.com>

hello,


I'm trying to change to a subdirectory with 

chdir "./$dir" or print "can't change to directory ./$dir\n";

why doesn't this work? How to I get it to work?

Thanks
Jason

 S+P+A+M_lapenta_jm@yahoo.com


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

Date: 22 Jul 2001 20:12:13 -0500
From: Tony Curtis <tony_curtis32@yahoo.com>
Subject: Re: problems with chdir
Message-Id: <87elr8tpn6.fsf@limey.hpcc.uh.edu>

>> On Sun, 22 Jul 2001 21:04:42 -0400,
>> Jason LaPenta <lapenta_jm@yahoo.com> said:

> hello, I'm trying to change to a subdirectory with

> chdir "./$dir" or print "can't change to directory
> ./$dir\n";

> why doesn't this work? How to I get it to work?

$!

 . is not what you think it is.

hth
t
-- 
Beep beep!  Out of my way, I'm a motorist!


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

Date: Mon, 23 Jul 2001 01:21:56 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: problems with chdir
Message-Id: <3B5B7C34.9687B417@acm.org>

Jason LaPenta wrote:
> 
> hello,
> 
> I'm trying to change to a subdirectory with
> 
> chdir "./$dir" or print "can't change to directory ./$dir\n";
> 
> why doesn't this work? How to I get it to work?

Let perl tell you why it didn't work, include the $! variable in your
error message. By the way a period (.) is an abbreviation for the
current directory so ./$dir is the same as $dir

chdir $dir or print "can't change to directory $dir: $!";



John
-- 
use Perl;
program
fulfillment


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

Date: Sun, 22 Jul 2001 21:37:58 -0400
From: Jason LaPenta <lapenta_jm@yahoo.com>
Subject: Re: problems with chdir
Message-Id: <3B5B7FF6.FC598AF1@yahoo.com>

Hi

Well I tried..

chdir $dir or print "can't change to directory $dir $!\n";

and I get at the output

can't change to directory Projects No such file or directory

and I know for a fact this directory exists. So I still don't know why
it isn't working.

Thanks
Jason



"John W. Krahn" wrote:
> 
> Jason LaPenta wrote:
> >
> > hello,
> >
> > I'm trying to change to a subdirectory with
> >
> > chdir "./$dir" or print "can't change to directory ./$dir\n";
> >
> > why doesn't this work? How to I get it to work?
> 
> Let perl tell you why it didn't work, include the $! variable in your
> error message. By the way a period (.) is an abbreviation for the
> current directory so ./$dir is the same as $dir
> 
> chdir $dir or print "can't change to directory $dir: $!";
> 
> John
> --
> use Perl;
> program
> fulfillment


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

Date: Sun, 22 Jul 2001 21:41:47 -0400
From: Jason LaPenta <lapenta_jm@yahoo.com>
Subject: Re: problems with chdir
Message-Id: <3B5B80DB.7C9C656C@yahoo.com>

Ok, now I understand... I really needed at ../$dir

thxs


"John W. Krahn" wrote:
> 
> Jason LaPenta wrote:
> >
> > hello,
> >
> > I'm trying to change to a subdirectory with
> >
> > chdir "./$dir" or print "can't change to directory ./$dir\n";
> >
> > why doesn't this work? How to I get it to work?
> 
> Let perl tell you why it didn't work, include the $! variable in your
> error message. By the way a period (.) is an abbreviation for the
> current directory so ./$dir is the same as $dir
> 
> chdir $dir or print "can't change to directory $dir: $!";
> 
> John
> --
> use Perl;
> program
> fulfillment


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

Date: Sun, 22 Jul 2001 20:41:50 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: problems with chdir
Message-Id: <3B5B9CFE.881634F7@stomp.stomp.tokyo>

Jason LaPenta wrote:

> I'm trying to change to a subdirectory with
 
> chdir "./$dir" or print "can't change to directory ./$dir\n";
 
> why doesn't this work? How to I get it to work?
 

Others have provided an explanation.

Use of shortcuts for Perl, such dot syntax for
directories and changing directories is ok, much
like writing obfuscated short code is ok. Most
often, however, this is a display of an unhealthy
ego and a display of poor programming practices.
It is a display of an unhealthy ego by attempting
to impress others with obfuscated code. It is
a poor programming practice because it often
leads to mistakes such as you have made.

Verbose code written in plain English is most
superior code and, surprisingly for some geeks,
is frequently faster more efficient code. Give
thought to writing your code in plain English
which includes full directory paths rather than
dot syntax. You will rarely go wrong if you use
good logic and good wording rather than allow
your ego to lead you around by your nose.

My test script includes the Cwd module although not
needed and is considered overkill. Nonetheless it
does work well for confirmation testing while you
are developing a script. I don't suggest using this
module under other circumstances; it has flaws.
Read about and research the Cwd module. The author
is wise enough to document these flaws. This type
of displayed wisdom is exceptionally rare amongst
Perl 5 geeks. This module is easily replaced with
quick efficient if - else logic.

You really don't need to kill your script if a
directory change fails. You may print a message
and provide for alternative program branching
although this requires careful planning and skill.
A classic alternative would be to print an error
message and "skip over" a bad directory reference,
then continue on processing other directories.
Killing a program is for Sissified Geeks.

If you wish to be a good programmer, wish to write
programs which are easy to understand and truly
impressive, avoid these typical Perl 5 Cargo Cult
shortcuts; use old fashion plain English.


Godzilla!
--

TEST SCRIPT:
____________


#!perl

use Cwd;

print "Content-type: text/plain\n\n";

$base_directory = "c:/apache";


$sub_directory = "/users";

&Change_Directory;


print "\n\n";


$sub_directory = "/users/callgirl";

&Change_Directory;


print "\n\n";


$sub_directory = "/does_not/exist";

&Change_Directory;


sub Change_Directory
 {
  if (chdir ("$base_directory$sub_directory"))
   { 
    print "Current Directory: $base_directory$sub_directory\n";
    print "        Confirmed: ", cwd, "\n";
   }
  else
   { 
    print "Cannot Change To Directory: $base_directory$sub_directory\n";
    print "         Current Directory: ", cwd, "\n";
   }
 }

exit;


PRINTED RESULTS:
________________

Current Directory: c:/apache/users
        Confirmed: c:/apache/users


Current Directory: c:/apache/users/callgirl
        Confirmed: c:/apache/users/callgirl


Cannot Change To Directory: c:/apache/does_not/exist
         Current Directory: c:/apache/users/callgirl


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

Date: Mon, 23 Jul 2001 09:03:01 +0800
From: MMX166+2.1G HD <no@mail.addr>
Subject: Re: Redirecting STDERR
Message-Id: <pneklto1l08f5tt6rjrns1eg0dfron4nrd@4ax.com>

I try it on my win98se machine, and it dosen't work :(
--
On Fri, 20 Jul 2001 18:17:32 -0700, in comp.lang.perl.misc "$Bill
Luebkert" <dbe@wgn.net> wrote:

>Fred wrote:
>> 
>> Hi,
>> 
>> I am trying to redirect the errors generated by one script on win32. I use
>
>There are lots of Win32 OS's - be specific.
>
>> the following command:
>> 
>>   scriptname > out.txt 2>&1
>> 
>> If the STDOUT is correctly redirected, none of the error messages are sent
>> to the file.
>> 
>> Any idea why??
>
>If you're using command.com (9x) instead of cmd.exe (NT/2k), you can't do it.



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

Date: Mon, 23 Jul 2001 09:03:00 +0800
From: MMX166+2.1G HD <no@mail.addr>
Subject: Re: Removing Tags
Message-Id: <06ekltokom5r80iikktltma6n4gpkas4ri@4ax.com>

Maybe u forgot the + 
try this:
/(<[^>]+>)/g

--
On Fri, 20 Jul 2001 09:37:07 +0100, in comp.lang.perl.misc "Lee
Osborne" <osbornelee@hotmail.com> wrote:

>
>/(<[^>]>)/g



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

Date: Sun, 22 Jul 2001 22:33:42 +0200
From: root <fabian@miczek.de>
Subject: tiny perl
Message-Id: <3B5B38A6.400EECEA@miczek.de>

Hi,
I currently writing a plugin for a windows programm
in C and want to embed perl into it. That works fine
so far, but the perl.dll which I have to pack to the
plugin is too big. Is there any possibility the compile
a very small perl where only the basic functions are 
included ?

Thanks in advance
Fabian


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

Date: Mon, 23 Jul 2001 01:06:42 +0200
From: "Murat Uenalan" <murat.uenalan@gmx.de>
Subject: use attributes; subs : lvalue { return $this->{anyvar} } question
Message-Id: <9jfm57$nm3uf$1@ID-71895.news.dfncis.de>

I want to create attribute handlers which could be written like:

$this->name = 'Murat';

The perlsub.pod states i can "use attributes" with attribute : lvalue for
this:

__START__

package Foo;

sub name : lvalue
{
   my $this = shift;

return @_ ? $this->{name} = shift : $this->{name};
};

sub new { bless { name => 'somebody else' } }

package main;

    my $obj = new Foo;

    $obj->name = 'Murat';

    print "You are: ", $obj->name;

__END__

This fails ??? Why ??? This states i am "somebody else", but not Murat ?!

Thanks for any suggestions,
Murat


This would have worked, but this is not what i want.

    $obj->name( 'Murat' );

    print "You are: ", $obj->name;





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

Date: Mon, 23 Jul 2001 10:07:28 +0800
From: MMX166+2.1G HD <no@mail.addr>
Subject: Re: what is the defer form "my" to "local"?
Message-Id: <eq0nlt0btmlvkdg5qggavfvstins3u80s1@4ax.com>

??who? me?
--
On Sat, 21 Jul 2001 20:11:37 -0700, in comp.lang.perl.misc "Godzilla!"
<godzilla@stomp.stomp.tokyo> wrote:

>
>
>You are dead wrong.
>



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

Date: Mon, 23 Jul 2001 10:07:29 +0800
From: MMX166+2.1G HD <no@mail.addr>
Subject: Re: what is the defer form "my" to "local"?
Message-Id: <551nlts4ve58voeabibjrfv7bg1pqocl91@4ax.com>

"my" is a "*new variable* that is only visible in the current
subroutine" == private variable
"local" "assigns a *new value* for the duration of the subroutine" ==
temporary value
right? I think I got it.
>The short version:
>
>   my() good
>
>   local() bad
sorry I don't think so. just use the correct one as you need.
--
On Sat, 21 Jul 2001 22:15:39 -0400, in comp.lang.perl.misc
tadmc@augustmail.com (Tad McClellan) wrote:

>MMX166+2.1G HD <no@mail.addr> wrote:
>
>>they all work like the C auto, but what's the deference?
>
>Perl FAQ, part 7:
>
>   "What's the difference between dynamic and lexical (static) scoping?  
>    Between local() and my()?"
>
>
>The short version:
>
>   my() good
>
>   local() bad



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

Date: Mon, 23 Jul 2001 09:02:55 +0800
From: MMX166+2.1G HD <no@mail.addr>
Subject: Re: Who can help me about the confused (..) operator?
Message-Id: <76fklt8rbn1fftu8sp58thfjir2q6ra0ba@4ax.com>

On Sat, 21 Jul 2001 04:55:03 GMT, in comp.lang.perl.misc
mjd@plover.com (Mark Jason Dominus) wrote:

>
>        @colors = qw(red crimson orange yellow charteuse 
>                     green aqua blue indigo violet);
>        
>        for $i (@colors) {
>         if ($i eq 'orange' .. $i eq 'green') {
>           print "$i\n";
>         }
>        }
result:
>orange
>yellow
>charteuse
>green
I understand. It's false if "left" is false, It's true if "left" is
true. The "left" is not evaluated when the operator is true but the
"right" is. when "right" turn to "true". the operator return true, and
reevaluate the "left"'s value, and so on...(looks like a loop) is it
right?


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

Date: Mon, 23 Jul 2001 10:07:24 +0800
From: MMX166+2.1G HD <no@mail.addr>
Subject: Re: Who can help me about the confused (..) operator?
Message-Id: <ikvmlt80s4a39verj2n4f0ll7iocq7rrk5@4ax.com>

yeah, It's OK :) but if I use "for" instead of "while", it's failed
now I know:
while: well done!
for: go away!
:)

--
On Sun, 22 Jul 2001 03:45:56 GMT, in comp.lang.perl.misc
clintp@geeksalad.org (Clinton A. Pierce) wrote:

>while(<DATA>) {
>        print if (1..10);
>}
>__END__
>Zero
>One
>Two
>Three
>Four
>Five
>Six
>Seven
>Eight
>Nine
>Ten
>Eleven
>Twelve



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

Date: 23 Jul 2001 03:27:06 GMT
From: ebohlman@omsdev.com (Eric Bohlman)
Subject: Re: Who can help me about the confused (..) operator?
Message-Id: <9jg5ia$872$1@bob.news.rcn.net>

[please post you comments *after* the stuff you're commenting on.  I had 
to rearrange things so my reply would make sense in context]

MMX166+2.1G HD <no@mail.addr> wrote:
> On Sun, 22 Jul 2001 03:45:56 GMT, in comp.lang.perl.misc
> clintp@geeksalad.org (Clinton A. Pierce) wrote:

>>while(<DATA>) {
>>        print if (1..10);
>>}

> yeah, It's OK :) but if I use "for" instead of "while", it's failed
> now I know:
> while: well done!
> for: go away!

That's because using for() reads the entire content of the file into a 
list before iterating over it.  Once it's done reading, $. is set to the 
number of the last line in the file and it will never match your range 
condition.  perl does *not* keep track of the index when you're iterating 
over a list.  Using <HANDLE> in a for loop should raise some eyebrows; it 
almost always means you're doing something that could be done more 
efficiently by reading a line at a time, and it deprives you of the 
ability to use $. and the range operator.



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

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


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