Re: help with (do $ENV{HOME})

2003-02-16 Thread Dave K
ktb, Wiggins,
Another perspective:

text.txt contains:
return 'My Full Name with middle initial';

#!/usr/bin/perl -w
use strict;
my $name = do "./text.txt";
print "$name\n";


prints:
My Full Name with middle initial

> > The problem I'm having is my print statement just prints a new line
> > without printing any text.  It was my understanding that the "do"
> > function would pull the scalars from "text" into my prog as if it was
> > part of the program.
> It may be doing just that, but with the line:
> my $name;
> After the 'do' you are resetting the variable. You should be using 'our'
> instead of 'my'.
> perldoc -f our
> perldoc -f my

Note also that I use the -w. (Not right or wrong, just warning you of
different behavior)

HTH



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: help with (do $ENV{HOME})

2003-02-16 Thread ktb
On Sun, Feb 16, 2003 at 12:05:57PM -0500, Wiggins d'Anconia wrote:
> 
> 
> ktb wrote:
> >I've read the faq on "do" and looked around the web but can't discover
> >what I'm doing wrong.
> >
> >I have a file named "text" with the following line it it -
> >$name = "kent";
> >
> >My prog contains the following -
> >#!/usr/bin/perl
> >use diagnostics;
> >use strict;
> >use warnings;
> >
> >do "$ENV{HOME}/scratch/address_book/text";
> >my $name;
> >print "$name\n";
> >
> >The problem I'm having is my print statement just prints a new line
> >without printing any text.  It was my understanding that the "do" 
> >function would pull the scalars from "text" into my prog as if it was 
> >part of the program.  
> >
> 
> It may be doing just that, but with the line:
> 
> my $name;
> 
> After the 'do' you are resetting the variable. You should be using 'our' 
> instead of 'my'.
> 
> perldoc -f our
> perldoc -f my
> 

Thanks much had not heard of "our" till now.  That did the trick:)
kent

-- 
To know the truth is to distort the Universe.
  Alfred N. Whitehead (adaptation)

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




RE: help with (do $ENV{HOME})

2003-02-16 Thread Beau E. Cox
Hi -

> -Original Message-
> From: ktb [mailto:[EMAIL PROTECTED]]
> Sent: Sunday, February 16, 2003 6:52 AM
> To: [EMAIL PROTECTED]
> Subject: help with (do $ENV{HOME})
> 
> 
> I've read the faq on "do" and looked around the web but can't discover
> what I'm doing wrong.
> 
> I have a file named "text" with the following line it it -
> $name = "kent";
> 
> My prog contains the following -
> #!/usr/bin/perl
> use diagnostics;
> use strict;
> use warnings;
> 
> do "$ENV{HOME}/scratch/address_book/text";
> my $name;
> print "$name\n";
> 
> The problem I'm having is my print statement just prints a new line
> without printing any text.  It was my understanding that the "do" 
> function would pull the scalars from "text" into my prog as if it was 
> part of the program.  
> 
> What am I doing wrong?
> Thanks,
> kent
> 

I think this type of 'do' reads the file and
evals it (you should check $@ to see if it evaled
OK). The eval returns whatever the script in the file
returns. So...

1) Change your file to contain only "kent";

2) load $name as follows:

  my $name = do "$ENV{HOME}/scratch/address_book/text";
  die "bad file (whatever): $@\n" if $@;

3) all done.

Aloha => Beau;


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: help with (do $ENV{HOME})

2003-02-16 Thread Wiggins d'Anconia


ktb wrote:

I've read the faq on "do" and looked around the web but can't discover
what I'm doing wrong.

I have a file named "text" with the following line it it -
$name = "kent";

My prog contains the following -
#!/usr/bin/perl
use diagnostics;
use strict;
use warnings;

do "$ENV{HOME}/scratch/address_book/text";
my $name;
print "$name\n";

The problem I'm having is my print statement just prints a new line
without printing any text.  It was my understanding that the "do" 
function would pull the scalars from "text" into my prog as if it was 
part of the program.  


It may be doing just that, but with the line:

my $name;

After the 'do' you are resetting the variable. You should be using 'our' 
instead of 'my'.

perldoc -f our
perldoc -f my

http://danconia.org


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



help with (do $ENV{HOME})

2003-02-16 Thread ktb
I've read the faq on "do" and looked around the web but can't discover
what I'm doing wrong.

I have a file named "text" with the following line it it -
$name = "kent";

My prog contains the following -
#!/usr/bin/perl
use diagnostics;
use strict;
use warnings;

do "$ENV{HOME}/scratch/address_book/text";
my $name;
print "$name\n";

The problem I'm having is my print statement just prints a new line
without printing any text.  It was my understanding that the "do" 
function would pull the scalars from "text" into my prog as if it was 
part of the program.  

What am I doing wrong?
Thanks,
kent

-- 
To know the truth is to distort the Universe.
  Alfred N. Whitehead (adaptation)

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re[2]: ENV & $HOME

2001-06-30 Thread Tim Musson

Hey Michael,

Wednesday, June 27, 2001, 3:17:32 AM, my MUA believes you used
(X-Mailer not set) to write:

MF> On Wed, Jun 27, 2001 at 02:37:55AM -0400, Adam Theo wrote:
>> i am looking for a way my perl program can automatically get the
>> home directory of the user.

>> linux, windows, mac, etc? also, what does ENV do for windows and
>> mac users, since those are not typically milti-user OSes? and
>> finally, while i have found the ENV, does anyone know of a better
>> way to do this? thank you for your time.

MF> I know Windows has environmental variables, and Perl can get to
MF> them. I'm not sure if $ENV{HOME} will have a sane value, or any
MF> value at all.

My Win32 machine has no "HOME" var (typical), it has
HOMEDRIVE=C:
HOMEPATH=\
Not what you are looking for I believe.

MF> There is no real concept of a home directory anyways, unless you
MF> count the primary hard drive, aka C.

If you are running in a "Domain" or "Active Directory" environment,
the admins could have set up a "home" dir on a network server, but I
don't think it will be set in the $ENV{HOME} variable... If
interested, I can check when at work monday. Let me know.

MF> I can't help you with Mac

Same here...

-- 
[EMAIL PROTECTED]
Using The Bat! eMail v1.53d
Windows NT 5.0.2195 (Service Pack 1)
Why get even, when you can get odd?




Re: ENV & $HOME

2001-06-26 Thread Michael Fowler

On Wed, Jun 27, 2001 at 02:37:55AM -0400, Adam Theo wrote:
> i am looking for a way my perl program can automatically get the home 
> directory of the user.

There is, of course, the HOME environmental variable.  There is also
(getpwuid $>)[7], which gets the home directory from the password database,
using the current UID.  There are variations, such as
(getpwnam $ENV{LOGNAME})[7] and (getpwnam $ENV{USER})[7].


> i have come accross the ENV module, and think it will work, but wish to
> know if it is a standard module with all perl distributions?

It is.  Env.pm is just a way for turning environmental variables into global
variables.  You can get to the values through the %ENV hash.


> linux, windows, mac, etc? also, what does ENV do for windows and mac
> users, since those are not typically milti-user OSes?  and finally, while
> i have found the ENV, does anyone know of a better way to do this?  thank
> you for your time.

I know Windows has environmental variables, and Perl can get to them.  I'm
not sure if $ENV{HOME} will have a sane value, or any value at all.  There
is no real concept of a home directory anyways, unless you count the primary
hard drive, aka C.   You could probably get away with checking $^O for some
variation on "Win32" and hard-coding your home directory based on that.

I can't help you with Mac, though Mac also doesn't have a concept of home
directory (AFAIK), so doing the bit with $^O would probably work there as
well.


Michael
--
Administrator  www.shoebox.net
Programmer, System Administrator   www.gallanttech.com
--



ENV & $HOME

2001-06-26 Thread Adam Theo


Hello, Adam Theo here;

i am looking for a way my perl program can automatically get the home 
directory of the user. i have come accross the ENV module, and think it 
will work, but wish to know if it is a standard module with all perl 
distributions? linux, windows, mac, etc? also, what does ENV do for 
windows and mac users, since those are not typically milti-user OSes? 
and finally, while i have found the ENV, does anyone know of a better 
way to do this?  thank you for your time.
--
   /\   Theoretic Solutions (www.Theoretic.com):
  //\\'Activism, Software, and Internet Services'
//--\\ Personal Homepage (www.Theoretic.com/adamtheo/):
   ][ 'Personal history, analysis, and favorites'
   ][   Birthright Online (www.Birthright.net):
  'Keeping the best role-playing game alive'
Email & Jabber:   Other:
-Professional: [EMAIL PROTECTED]  -AIM: AdamTheo2000
-General: [EMAIL PROTECTED]   -ICQ: 3617307
-Personal: [EMAIL PROTECTED]  -Phone: (850)8936047