Re: Current directory?



On Thu, 29 Sep 2005 gustav@xxxxxxxxxxxxxx wrote:

> I want to get the current environment variable (current directory), and I
> type like this:
>
> $currentpath = %ENV;

Why do you expect this to do anything useful?

You're assigning the contents of a hash into a single scalar.

That will almost never do anything useful.

As others noted, if you want a specific element from a hash, you have to
name it explicitly --

$currentpath = $ENV{PWD};

-- or, as another person noted, use the Cwd module to do this in a more
guaranteed to be portable way.

But in any case, assigning a (full) hash to a scalar will never work :-)



--
Chris Devers

6f9A/
.



Relevant Pages

  • Re: What dont I understand about hash assigments?
    ... numeric codes with the codes starting with "H..." ... What don't I understand about assigning values to a hash? ... But then when you get to the print statement, ...
    (perl.beginners)
  • Re: perl inbuilt function each may be having a bug
    ... This code is not working and assigning values to '', ... Use of uninitialized value in concatenation or string at each- ... Why are you using a two-level hash to demonstrate the behavior? ... that will start iterating again. ...
    (comp.lang.perl.misc)
  • Re: %a = {}; What is this?
    ... But you're assigning that to the hash ... %a is a hash, not a reference. ... Some versions of Perl will give no ...
    (perl.beginners)
  • Re: Question about arrays of hashes
    ... light for me on weirdness I'm seeing when trying to access a particular hash from an array-of-hashes. ... I had a lot of difficulty assigning a particular element to its own variable, but after some experimentation I found that this works: ... I have to first create the variable in scalar context, then do a funky dereferencing thing while changing the context to hash. ...
    (comp.lang.perl.misc)
  • Re: Time Calculations
    ... I do not appear to have any trouble with ... > Ideally I do not want to ann in date and times. ... Prev by Date: ...
    (microsoft.public.excel.worksheet.functions)