Re: Hi... Help regarding chdir

2007-12-20 Thread Chas. Owens
On Dec 19, 2007 2:05 PM, Tom Phoenix [EMAIL PROTECTED] wrote:
 On 12/19/07, Chas. Owens [EMAIL PROTECTED] wrote:

  On Dec 19, 2007 2:29 AM, Ravindra Ugaji [EMAIL PROTECTED] wrote:

   chdir ( '/opt/application') || die (Can't change directory: $!\n);
   tried this also
   chdir /opt/application || die Can't change directory: $!\n;

  In addition to what others have already said, never do the second*.
  The || operator has a higher precedence than function calls, so
 
  func string || die oops;
 
  is really saying
 
  func(string || die(oops));
 
  Since string is truthy, the die will never occur.

 You have the right idea about functions in general; but chdir() is a
 named unary operator, so it has higher precedence than the ||
 operator:

   chdir /any/wrong/path || die This will indeed die: $!;

 That means that the OP's code isn't so wrong as it may seem, even
 though there's surely a better way to write it.
snip

That is the reason I used func instead of chdir.  The don't use || in
that way, use or instead is more of a general warning not to use the
construct (because it will bite you).

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Hi... Help regarding chdir

2007-12-19 Thread Ravindra Ugaji
Hi Monks,
I am trying the following code to change the directory

chdir ( '/opt/application') || die (Can't change directory: $!\n);
tried this also
chdir /opt/application || die Can't change directory: $!\n;


But i am unable to change the directory to  /opt/application  from
present working directory

I am using perl 5.6.1 built for sun4-solaris-64int and it wont support
File::chdir  
can any one suggest the alternative solution for this problem?

:-)


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: Hi... Help regarding chdir

2007-12-19 Thread Roberto Etcheverry
It should work unless the user you are using to run the script doesn't
have the rights to chdir to that directory.

Ravindra Ugaji wrote:
 Hi Monks,
 I am trying the following code to change the directory

 chdir ( '/opt/application') || die (Can't change directory: $!\n);
 tried this also
 chdir /opt/application || die Can't change directory: $!\n;


 But i am unable to change the directory to  /opt/application  from
 present working directory

 I am using perl 5.6.1 built for sun4-solaris-64int and it wont support
 File::chdir  
 can any one suggest the alternative solution for this problem?

 :-)


   


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: Hi... Help regarding chdir

2007-12-19 Thread Tom Phoenix
On 12/18/07, Ravindra Ugaji [EMAIL PROTECTED] wrote:

 Hi Monks,

The Perl Monks are two doors down, on the left. But maybe we can help you here.

 I am trying the following code to change the directory

 chdir ( '/opt/application') || die (Can't change directory: $!\n);

 But i am unable to change the directory to  /opt/application  from
 present working directory

Do you get an error message? What does it say?

If there is no error message, perhaps you mean that, after the program
has finished running, you find that the shell is still using the
original working directory. That's a feature of your operating system,
not a bug. You can't change the working directory of another program
without that program's knowledge and consent, else programs would
unexpectedly find themselves working in the wrong directories and
wreaking havoc. This is covered in the Unix FAQ, question 2.8, among
other places; but the answer is about the same in principle on any
other OS.

http://www.faqs.org/faqs/unix-faq/faq/part2/
http://packetstormsecurity.org/unix-humor/awesome.unix.chdir.program.html

Check the documentation for your shell program, too, because it may
have a suggestion on how you can do what you want.

Hope this helps!

--Tom Phoenix
Stonehenge Perl Training

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: Hi... Help regarding chdir

2007-12-19 Thread Chas. Owens
On Dec 19, 2007 2:29 AM, Ravindra Ugaji [EMAIL PROTECTED] wrote:
 Hi Monks,
 I am trying the following code to change the directory

 chdir ( '/opt/application') || die (Can't change directory: $!\n);
 tried this also
 chdir /opt/application || die Can't change directory: $!\n;
snip

In addition to what others have already said, never do the second*.
The || operator has a higher precedence than function calls, so

func string || die oops;

is really saying

func(string || die(oops));

Since string is truthy, the die will never occur.  If you want to
avoid the use of parenthesis you can use the lower precedence or:

func string or die oops;

* unless, of course, it is what you really mean

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: Hi... Help regarding chdir

2007-12-19 Thread Tom Phoenix
On 12/19/07, Chas. Owens [EMAIL PROTECTED] wrote:

 On Dec 19, 2007 2:29 AM, Ravindra Ugaji [EMAIL PROTECTED] wrote:

  chdir ( '/opt/application') || die (Can't change directory: $!\n);
  tried this also
  chdir /opt/application || die Can't change directory: $!\n;

 In addition to what others have already said, never do the second*.
 The || operator has a higher precedence than function calls, so

 func string || die oops;

 is really saying

 func(string || die(oops));

 Since string is truthy, the die will never occur.

You have the right idea about functions in general; but chdir() is a
named unary operator, so it has higher precedence than the ||
operator:

  chdir /any/wrong/path || die This will indeed die: $!;

That means that the OP's code isn't so wrong as it may seem, even
though there's surely a better way to write it.

Cheers!

--Tom Phoenix
Stonehenge Perl Training

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: Hi... Help regarding chdir

2007-12-19 Thread Paul Lalli
On Dec 19, 2:29 am, [EMAIL PROTECTED] (Ravindra Ugaji) wrote:
 I am trying the following code to change the directory

 chdir ( '/opt/application') || die (Can't change directory: $!\n);
 tried this also
 chdir /opt/application || die Can't change directory: $!\n;

 But i am unable to change the directory to  /opt/application  from
 present working directory

What is your indication of that?  How do you know the directory has
not changed?  Do you get an error message, and if so, what is it?   Do
you have some code below this later that proves you're not in /opt/
application?

Or do you mean that when your program exits, you are back where you
started the program from?  That is, you are in /home/jsmith, you run
this program, and when the program exits, you're still in /home/
jsmith.   If that's the error you're talking about, please read:
perldoc -q directory
Found in /usr/lib/perl5/5.8/pods/perlfaq8.pod
   I {changed directory, modified my environment} in a perl
script.  How
   come the change disappeared when I exited the script?  How do I
get my
   changes to be visible?


Paul Lalli


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/