Re: Send both parts of a multipart email

2008-08-22 Thread Jeff Pang
On Fri, Aug 22, 2008 at 8:02 AM, David Allender <[EMAIL PROTECTED]> wrote:

>
> send an email to a person with text/enriched text at the top of the
> email, and text/html at the bottom of the email.

Yes, MIME::Lite can do that.

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




Re: timing a fork

2008-08-22 Thread Rob Dixon
Raymond Wan wrote:
> Rob Dixon wrote:
>>
>> use strict;
>> use warnings;
>>
>> $|++; # autoflush
>>
>> $SIG{CHLD} = 'IGNORE';
>>
>> my $kid = fork;
>>
>> if ($kid) {
>>   print "in parent whose kid is $kid\n";
>>   sleep 10;
>>   my $running = kill(0, $kid);
>>   print "Child process ", $running ? "still running\n" : "terminated\n";
>> }
>> elsif ($kid == 0) {
>>
>>   print "In child\n";
>>
>>   my ($user, $system, $cuser, $csystem);
>>
>>   ($user, $system, $cuser, $csystem) = times;
>>   printf "user: %f cuser: %f\n", $user, $cuser;
>>
>>   system('myprogram') == 0 or die "myprog failed: $?";
>>
>>   ($user, $system, $cuser, $csystem) = times;
>>   printf "user: %f cuser: %f\n", $user, $cuser;
>>
>>   exit;
>> }
>> else {
>>   die "Cannot fork: $!\n";
>> }
> 
> Yes, I am running this on a Linux system.  So, as I said, this is 
> running under modperl/mason for a web server.  What I want to do is to 
> start off a running C++ program and have the main process immediately 
> come back and show something to the user.  That is the reason why I have 
> that line there in the first place.  Yes, without it, the child would be 
> reaped, but the downside is that the main process is (I think) going to 
> wait for the C++ program to run...and I don't want that.  Especially 
> since in a web server setting, I guess the client will just see that a 
> web page is trying to load and almost certainly will click "Reload" 
> uncontrollably...  :-)
>
> That is why I want the child process to be detached.  Wanting that 
> causes them to be zombies, so then the problem gets bigger and bigger.
>
> To be honest, I started by searching for "modperl" and "starting a 
> process" on the web and found some lines of code resembling what I first 
> posted and have since been modifying that.  I haven't taken a long, hard 
> look at each individual line to see if it is correct or not applicable 
> for my problem.  (No code I have found on the Net has addressed the 
> issue of timing that process, though.)
> 
> Thanks for the source code!  I'll play with it; someone I am working 
> with also proposed something similar just yesterday...obviously, my 
> double-forking is raising eyebrows, so I should take a good look at what 
> I am doing. 
> 
> Actually, the double-forking does work...I got it working a couple of 
> days ago.  But, I'm new to modperl, and I think a fork doesn't copy the 
> perl interpreter, but a copy of the whole apache process...so, yes, a 
> single fork is going to be a performance hit, so one is better than 2, 
> if I can get away with it...  Thanks a lot!

A mixture of misunderstandings here.

- I was saying that

$SIG{CHLD} = 'IGNORE';

  was helpful. What it does is say that the parent isn't interested in
  explicitly reaping the forked child processes and they will be reaped
  automatically when they complete. Without it they will stay active until the
  parent calls wait or waitpid.

- Once a parent process has forked it can carry on on its own while the child
  process does its thing. Only when it does a wait or waitpid is it held up
  waiting for the child. In fact what a call to 'system' does is to fork a child
  process and then immediately wait for that child to complete.

- So the simple combination of

$SIG{CHLD} = 'IGNORE';
my $kid = fork;

if (not defined $kid) {
  warn "Unable to fork";
}
elsif ($kid == 0) {
  system('myprogram') == 0 or die "myprog failed: $?";
}

  starts a child process that doesn't need reaping when it completes, and leaves
  the parent process free to continue executing. At least that is what is
  supposed to happen but wouldn't work on Windows.

And by the way, a child process doesn't actually get a /copy/ of the
interpreter: it simply has the same copy mapped at the same place in its address
space. In general this is true of any read-only segments, and it is only the
variable data space that must be duplicated so that a child process can execute
independently of its parent. Even so you should not make your program
unnecessarily complex, and I believe the code above does what you want. There
isn't even a need for any action on the parent side of the fork (child process
ID is non-zero).

HTH,

Rob

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




Re: timing a fork

2008-08-22 Thread Raymond Wan


Hi Rob,


Rob Dixon wrote:

Raymond Wan wrote:
  

Rob Dixon wrote:


What do you need to accomplish that something as simple as the code below won't 
do?

use strict;
use warnings;

my $kid = fork;

if ($kid) {
  print "in parent whose kid is $kid\n";
}
elsif ($kid == 0) {
  print "In child\n";
  my ($usertime) = times;
  print "$usertime seconds\n";
}
else {
  die "Cannot fork: $!\n";
}
  
H, true -- I may be adding and adding code unnecessarily... 

What the forked process does is run a C++ program and it is that program 
that needs to be timed.  Would the code below accomplish that?  I mean, 
having "times" in the Perl script that calls that C++ program will give 
the user time of that (spawned) Perl process.  But that is a close 
enough estimation of the C++ program's user time provided all I do is 
run that program?


Also, this is within modperl/mason and I would like the parent process 
to be completely detached from the child (so that a web page can be 
shown) and not care when the child completes...



Please bottom-post your replies to this list, so that extended threads can
remain comprehensible. Thanks.
  



Oh, alright then.  Since most mail readers thread mails very well, I 
tend to not pay enough attention to how I reply...  Sorry!




I have tried to do some experimentation with calls to fork and times, but I
suspect I am failing because they are not implemented fully on my Windows
systems. But I suggest that you do the same yourself, and also remember that a
call to times returns four values including the user time for both the current
process and its children.

I also believe there is no need to fully detach your child process, as setting

  $SIG{CHLD} = 'IGNORE';

should cause the child processes to be reaped automatically and the parent
process need have nothing more to do with them. Presumably their mere existence
as child processes is of no concern?

So I suggest you experiment with something like the slight modification below.
As stated this will not work for me but I believe that is because of the
imperfect emulation of fork on a Windows platform.

HTH,

Rob



use strict;
use warnings;

$|++; # autoflush

$SIG{CHLD} = 'IGNORE';

my $kid = fork;

if ($kid) {
  print "in parent whose kid is $kid\n";
  sleep 10;
  my $running = kill(0, $kid);
  print "Child process ", $running ? "still running\n" : "terminated\n";
}
elsif ($kid == 0) {

  print "In child\n";

  my ($user, $system, $cuser, $csystem);

  ($user, $system, $cuser, $csystem) = times;
  printf "user: %f cuser: %f\n", $user, $cuser;

  system('myprogram') == 0 or die "myprog failed: $?";

  ($user, $system, $cuser, $csystem) = times;
  printf "user: %f cuser: %f\n", $user, $cuser;

  exit;
}
else {
  die "Cannot fork: $!\n";
}

  



Yes, I am running this on a Linux system.  So, as I said, this is 
running under modperl/mason for a web server.  What I want to do is to 
start off a running C++ program and have the main process immediately 
come back and show something to the user.  That is the reason why I have 
that line there in the first place.  Yes, without it, the child would be 
reaped, but the downside is that the main process is (I think) going to 
wait for the C++ program to run...and I don't want that.  Especially 
since in a web server setting, I guess the client will just see that a 
web page is trying to load and almost certainly will click "Reload" 
uncontrollably...  :-)


That is why I want the child process to be detached.  Wanting that 
causes them to be zombies, so then the problem gets bigger and bigger.


To be honest, I started by searching for "modperl" and "starting a 
process" on the web and found some lines of code resembling what I first 
posted and have since been modifying that.  I haven't taken a long, hard 
look at each individual line to see if it is correct or not applicable 
for my problem.  (No code I have found on the Net has addressed the 
issue of timing that process, though.)


Thanks for the source code!  I'll play with it; someone I am working 
with also proposed something similar just yesterday...obviously, my 
double-forking is raising eyebrows, so I should take a good look at what 
I am doing. 

Actually, the double-forking does work...I got it working a couple of 
days ago.  But, I'm new to modperl, and I think a fork doesn't copy the 
perl interpreter, but a copy of the whole apache process...so, yes, a 
single fork is going to be a performance hit, so one is better than 2, 
if I can get away with it...  Thanks a lot!


Ray






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




Re: "use constant" as hash key

2008-08-22 Thread John W. Krahn

Rob Dixon wrote:

Moon, John wrote:

How can I use a "constant" as a hash key?

$ perl -e 'use constant CAT=>A;

$hash{CAT} = q{Bobby};
$hash{"CAT"} = q{Muffy};
$hash{'CAT'} = q{Fluffy};
$hash{qq{CAT}} = q{Tuffy};
print "$_ = $hash{$_}\n" foreach (keys %hash);'

CAT = Tuffy
$

Want...

A=Bobby


If you remember that constants are implemented as subroutines then all you have
to do is write the hash key as an expression that forces the subroutine to be
called. So

  use constant CAT => 'A';

is equivalent to

  sub CAT { 'A' }


It is actually equivalent to:

   sub CAT () { 'A' }

See the "Constant Functions" section of perlsub.pod

perldoc perlsub



John
--
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order.-- Larry Wall

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




Re: "use constant" as hash key

2008-08-22 Thread Rob Dixon
Moon, John wrote:
>
> How can I use a "constant" as a hash key?
> 
> $ perl -e 'use constant CAT=>A;
>> $hash{CAT} = q{Bobby};
>> $hash{"CAT"} = q{Muffy};
>> $hash{'CAT'} = q{Fluffy};
>> $hash{qq{CAT}} = q{Tuffy};
>> print "$_ = $hash{$_}\n" foreach (keys %hash);'
> CAT = Tuffy
> $
> 
> Want...
> 
> A=Bobby

If you remember that constants are implemented as subroutines then all you have
to do is write the hash key as an expression that forces the subroutine to be
called. So

  use constant CAT => 'A';

is equivalent to

  sub CAT { 'A' }

and you can access the hash element with an expression like

  $hash{CAT()} = 'Daffy';
  $hash{CAT} = 'Duffy';
  $hash{CAT.''} = 'Dippy';
  $hash{0 || CAT} = 'Depot';

HTH,

Rob


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




Re: Makefile.PL

2008-08-22 Thread Rob Dixon
Patrick Dupre wrote:
>> Patrick Dupre wrote:
>>> On Fri, 22 Aug 2008, Rob Dixon wrote:
 Patrick Dupre wrote:
>
> How can I modify my Makefile.PL to have a Makefile which can make
> cc -o test.o -c test.c `perl -MExtUtils::Embed -e ccopts`
>
> Thank

 Makefile.PL is a program written using ExtUtils::MakeMaker to generate a
 makefile for building a Perl /extension/ module.

 ExtUtils::Embed is a module that will generate C code and compile/link 
 options
 for /embedding/ a perl interpreter into a C program.

 Extending and embedding Perl are two very different, almost opposite ideas.

 Since it looks like you have a program called test.c I assume you want to 
 embed
 a perl interpreter into that program, and if so you can forget about
 Makefile.PL. But in that case what are you asking? You clearly know how to
 compile test.c as you have written it in your post, and it is 
 straightforward to
 write a makefile to do that if you want to.

 So what help do you need from us?

>>> In fact, I have a Makefile.Pl because I am using ExtUtils to generate
>>> c for perl (with xs), but I also need to call a perl subroutine for c !!
>>> I know, it may be not elegant, but it is where I am !!
>>>
>>> So I need the Makefile.PL correct to generate the lib for perl
>>> and to compile the c to have it be able to call perl.
>>
>> So you are embedding a perl interpreter into an XS extension because you 
>> need to
>> call a Perl subroutine from that extension. Is that right? If so then you 
>> should
>> just be able to manipulate the Perl stack and make the call using call_sv or
>> similar. Take a look at
>>
>>  perldoc perlcall
>>
>> for help on this. Or let me know if I'm not understanding you correctly.
> 
> So, you do not have any solution for me ?

Yes I do. Let me explain myself a little more.

If you are using the standard perl interpreter to run a program that loads an
extension module you have written using XS then there is no point in linking yet
another copy of the interpreter into the process. All you need to do is to code
the subroutine call in your XS code and it should work. As I said, if you read

  perldoc perlcall

then you should find an example of what you want to do.

Obviously I can't be more specific without knowing more about your requirement.
Are you trying to execute a callback subroutine that was passed in the original
call to your extension? Or is it just that you want to do something that is
neater and more concise written in Perl?

HTH,

Rob

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




Re: "use constant" as hash key

2008-08-22 Thread John W. Krahn

Moon, John wrote:

How can I use a "constant" as a hash key?

$ perl -e 'use constant CAT=>A;

$hash{CAT} = q{Bobby};
$hash{"CAT"} = q{Muffy};
$hash{'CAT'} = q{Fluffy};
$hash{qq{CAT}} = q{Tuffy};
print "$_ = $hash{$_}\n" foreach (keys %hash);'

CAT = Tuffy
$

Want...

A=Bobby


See the "Not-so-symbolic references" section of the perlref.pod man page 
for some hints:


perldoc perlref



John
--
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order.-- Larry Wall

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




Re: Makefile.PL

2008-08-22 Thread Patrick Dupre

Hello Bob,

So, you do not have any solution for me ?

Regards.



Patrick Dupre wrote:

On Fri, 22 Aug 2008, Rob Dixon wrote:


Patrick Dupre wrote:

How can I modify my Makefile.PL to have a Makefile which can make
cc -o test.o -c test.c `perl -MExtUtils::Embed -e ccopts`

Thank

Makefile.PL is a program written using ExtUtils::MakeMaker to generate a
makefile for building a Perl /extension/ module.

ExtUtils::Embed is a module that will generate C code and compile/link options
for /embedding/ a perl interpreter into a C program.

Extending and embedding Perl are two very different, almost opposite ideas.

Since it looks like you have a program called test.c I assume you want to embed
a perl interpreter into that program, and if so you can forget about
Makefile.PL. But in that case what are you asking? You clearly know how to
compile test.c as you have written it in your post, and it is straightforward to
write a makefile to do that if you want to.

So what help do you need from us?



In fact, I have a Makefile.Pl because I am using ExtUtils to generate
c for perl (with xs), but I also need to call a perl subroutine for c !!
I know, it may be not elegant, but it is where I am !!

So I need the Makefile.PL correct to generate the lib for perl
and to compile the c to have it be able to call perl.


So you are embedding a perl interpreter into an XS extension because you need to
call a Perl subroutine from that extension. Is that right? If so then you should
just be able to manipulate the Perl stack and make the call using call_sv or
similar. Take a look at

 perldoc perlcall

for help on this. Or let me know if I'm not understanding you correctly.

Rob



--
---
==
 Patrick DUPRÉ  |   |
 Department of Chemistry|   |Phone: (44)-(0)-1904-434384
 The University of York |   |Fax:   (44)-(0)-1904-432516
 Heslington |   |
 York YO10 5DD  United Kingdom  |   |email: [EMAIL PROTECTED]
==
-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Send both parts of a multipart email

2008-08-22 Thread David Allender
Hello all,

I was wondering if i can send both parts of a multipart email.
Basically what im trying to do is,

send an email to a person with text/enriched text at the top of the
email, and text/html at the bottom of the email.  The reason being is
so:  Its a cgi that handles a form, and i need it to be text/enriched
above because i want to keep the formatting of what the user inputs in
the form, while keeping the ability to make the words bold, etc.  and
i need the email part because i am basically appending an html file to
the bottom.  The client needs to see both of them in the email.  Any
ideas?

Thanks,
David


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




Re: LWP and authentication

2008-08-22 Thread Rob Dixon
ssinn wrote:
>
> I am currently writing a script that will connect to a URL,
> authenticate itself and GET information to the site.
> I am using this code out of the Perl & LWP book but it is failing.
> 
> #!/usr/bin/perl -w
> 
> use strict;
> use warnings;
> use LWP;
> use URI;
> 
> # This authenticates
> my $browser = LWP::UserAgent->new;
> $browser->credentials(
> 'http://10.1.0.8:80',
> 'index',
> 'test'=>'password'
> );
> 
> my $url = 'http://10.1.0.8';
> my $response = $browser->get($url);
> die "Error: ", $response->header('WWW-Authenticate') ||
> 'Error accessing',
> #  ('WWW-Authenticate' is the realm-name)
> "\n ", $response->status_line, "\n at $url\n Aborting"
> unless $response->is_success;
> 
> 
> The error message returned is
> 
> Error: Basic realm="index"
>  401 Authorization Required
>  at http://10.1.0.8
>  Aborting at ./new_push_mac.pl line 18.
> 
> What am I doing wrong?

I'm pretty sure the netloc parameter of your call to credentials has the wrong
format: it should just be a host and a port number, and I've never seen it
include the scheme (http) as well. Try like this

  $browser->credentials(
'10.1.0.8:80', 'index',
'test', 'password'
  );

HTH,

Rob


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




Re: Could anyone point me to a good site for pearl compiler download.

2008-08-22 Thread Rob Dixon
rich murphy wrote:
>
> Could anyone point me to a good site for pearl compiler download.

The short answer is here

  http://www.perl.org/

But it depends on what platform you are working on, and whether you know what
the perl compiler is.

Tell us more about what you want to do if this doesn't answer your question.

Rob

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




Re: condition in a single line

2008-08-22 Thread Robert Citek
An alternate version:

my $value = ( $t1lsq{$interfaceName} >= 4) ? 4 : $t1lsq{$interfaceName};

and a test:

$ perl -le '
$t1lsq{$interfaceName}=2 ;
my $value = ( $t1lsq{$interfaceName} >= 4) ? 4 : $t1lsq{$interfaceName};
print $value
'
2

$ perl -le '
$t1lsq{$interfaceName}=5 ;
my $value = ( $t1lsq{$interfaceName} >= 4) ? 4 : $t1lsq{$interfaceName};
print $value
'
4

Regards,
- Robert

On Fri, Aug 22, 2008 at 12:05 AM, Raymond Wan <[EMAIL PROTECTED]> wrote:
>
> Hi Noah,
>
> The ?: operator would do the trick:
>  http://www.perl.com/doc/manual/html/pod/perlop.html#Conditional_Operator
>
> I think what you need would be this, but I haven't tried it:
>
> (my $value > 4) ? ($value = 4) : ($value = $t1lsq{$interfaceName});
>
> Ray
>
>
>
> Noah wrote:
>>
>> Hi there,
>>
>> Is there a way to simplify the following to one line?
>>
>>
>> ---
>>
>>my $value = $t1lsq{$interfaceName};
>>$value = 4 if $value > 4;

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




LWP and authentication

2008-08-22 Thread ssinn
I am currently writing a script that will connect to a URL,
authenticate itself and GET information to the site.
I am using this code out of the Perl & LWP book but it is failing.

#!/usr/bin/perl -w

use strict;
use warnings;
use LWP;
use URI;

# This authenticates
my $browser = LWP::UserAgent->new;
$browser->credentials(
'http://10.1.0.8:80',
'index',
'test'=>'password'
);

my $url = 'http://10.1.0.8';
my $response = $browser->get($url);
die "Error: ", $response->header('WWW-Authenticate') ||
'Error accessing',
#  ('WWW-Authenticate' is the realm-name)
"\n ", $response->status_line, "\n at $url\n Aborting"
unless $response->is_success;


The error message returned is

Error: Basic realm="index"
 401 Authorization Required
 at http://10.1.0.8
 Aborting at ./new_push_mac.pl line 18.

What am I doing wrong?


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




Could anyone point me to a good site for pearl compiler download.

2008-08-22 Thread rich murphy
Could anyone point me to a good site for pearl compiler download.


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




"use constant" as hash key

2008-08-22 Thread Moon, John
How can I use a "constant" as a hash key?

$ perl -e 'use constant CAT=>A;
> $hash{CAT} = q{Bobby};
> $hash{"CAT"} = q{Muffy};
> $hash{'CAT'} = q{Fluffy};
> $hash{qq{CAT}} = q{Tuffy};
> print "$_ = $hash{$_}\n" foreach (keys %hash);'
CAT = Tuffy
$

Want...

A=Bobby

John W Moon


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




Re: What is wrong with this script ??

2008-08-22 Thread Perry Smith
I'm going to not CC beginners@perl.org after this point since I don't  
think this is a perl question right now.  Please speak up if you want  
to be included in this thread.


I'm not sure you understood my previous question.  I was asking if  
such things as chgrp, chown, etc work from the shell -- not from perl.


Two questions right now:

1) Does everything else work except the chgrp command?  For example,  
does the chown work? (assuming you are logged in as root or you use  
sudo).


2) Pick a user name that is in the LDAP server list s08-1-5-093 and do  
"id usersId" e.g. "id s08-1-5-093" .. let me see the results.


The users are probably all in the same group.  I'm hoping the id  
command will give me that group.  Some systems it will, others it will  
not.


Lets suppose the output from id is something like this:

uid=503(pedzan) gid=20(staff) groups=20(staff), 
103(com.apple.sharepoint.group.3),98(_lpadmin), 
102(com.apple.sharepoint.group.2),501(perry), 
101(com.apple.sharepoint.group.1)


In this case the numeric value of the id is 503 and the numeric value  
of the group is 20.  Find your values for one of your users.  Then (as  
root) try this:


cd /tmp
touch foo
chown 503 foo
chgrp 20 foo
ls -l foo

(the 20 and 503 will be replaced with the numbers you have).  See if  
the ls shows the proper owner/group.



On Aug 21, 2008, at 2:04 AM, Jyotishmaan Ray wrote:

Give some pointers as such to sort out this problem in my cluster  
servers (fedora-linux) ?






--- On Thu, 8/21/08, Mr. Shawn H. Corey <[EMAIL PROTECTED]> wrote:
From: Mr. Shawn H. Corey <[EMAIL PROTECTED]>
Subject: Re: What is wrong with this script ??
To: "Perry Smith" <[EMAIL PROTECTED]>
Cc: [EMAIL PROTECTED], beginners@perl.org
Date: Thursday, August 21, 2008, 4:07 AM

On Wed, 2008-08-20 at 17:25 -0500, Perry Smith wrote:
> I would first verify that you can do what you need to do
 with one
> individual directory from the shell.  i.e. make sure you can chown,
> chgrp, and chmod -- what ever other commands you are needing to do.

On many *NIX systems, commands like chown and chgrp are restricted so
that you cannot steal quotas.  Only sudo users can run them.


--
Just my 0.0002 million dollars worth,
  Shawn

"Where there's duct tape, there's hope."
Cross Time Cafe

"Perl is the duct tape of the Internet."
Hassan Schroeder, Sun's first webmaster






Re: What is wrong with this script ??

2008-08-22 Thread Jyotishmaan Ray

Dear All,

Thanks a lot for providing me the pointers.

Now i could create the homedirectories of 420 students with explicit chown and 
chgrp privilgeses.

The thing was that the groups didnt exist so was not accepted in the chown 
command.

Now that i have solved my problem, Thanks a zillion!!!


jmaan
 

--- On Thu, 8/21/08, Mr. Shawn H. Corey <[EMAIL PROTECTED]> wrote:
From: Mr. Shawn H. Corey <[EMAIL PROTECTED]>
Subject: Re: What is wrong with this script ??
To: "Perry Smith" <[EMAIL PROTECTED]>
Cc: [EMAIL PROTECTED], beginners@perl.org
Date: Thursday, August 21, 2008, 4:07 AM

On Wed, 2008-08-20 at 17:25 -0500, Perry Smith wrote:
> I would first verify that you can do what you need to do with one
> individual directory from the shell.  i.e. make sure you can chown,
> chgrp, and chmod -- what ever other commands you are needing to do.

On many *NIX systems, commands like chown and chgrp are restricted so
that you cannot steal quotas.  Only sudo users can run them.


--


  

Re: Makefile.PL

2008-08-22 Thread Patrick Dupre

On Fri, 22 Aug 2008, Rob Dixon wrote:


Patrick Dupre wrote:

On Fri, 22 Aug 2008, Rob Dixon wrote:


Patrick Dupre wrote:

How can I modify my Makefile.PL to have a Makefile which can make
cc -o test.o -c test.c `perl -MExtUtils::Embed -e ccopts`

Thank

Makefile.PL is a program written using ExtUtils::MakeMaker to generate a
makefile for building a Perl /extension/ module.

ExtUtils::Embed is a module that will generate C code and compile/link options
for /embedding/ a perl interpreter into a C program.

Extending and embedding Perl are two very different, almost opposite ideas.

Since it looks like you have a program called test.c I assume you want to embed
a perl interpreter into that program, and if so you can forget about
Makefile.PL. But in that case what are you asking? You clearly know how to
compile test.c as you have written it in your post, and it is straightforward to
write a makefile to do that if you want to.

So what help do you need from us?



In fact, I have a Makefile.Pl because I am using ExtUtils to generate
c for perl (with xs), but I also need to call a perl subroutine for c !!
I know, it may be not elegant, but it is where I am !!

So I need the Makefile.PL correct to generate the lib for perl
and to compile the c to have it be able to call perl.


So you are embedding a perl interpreter into an XS extension because you need to
call a Perl subroutine from that extension. Is that right? If so then you should
just be able to manipulate the Perl stack and make the call using call_sv or
similar. Take a look at

 perldoc perlcall

for help on this. Or let me know if I'm not understanding you correctly.

Yes.

--
---
==
 Patrick DUPRÉ  |   |
 Department of Chemistry|   |Phone: (44)-(0)-1904-434384
 The University of York |   |Fax:   (44)-(0)-1904-432516
 Heslington |   |
 York YO10 5DD  United Kingdom  |   |email: [EMAIL PROTECTED]
==
-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Re: condition in a single line

2008-08-22 Thread Peter Scott
On Fri, 22 Aug 2008 07:15:49 -0700, John W. Krahn wrote:
> Peter Scott wrote:
>>  my $value = max( 4, $t1lsq{$interfaceName} );
> 
> s/max/min/
>
> :-)

Wow, they are different.  Maybe that explains my overdraft...

-- 
Peter Scott
http://www.perlmedic.com/
http://www.perldebugged.com/


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




Re: Makefile.PL

2008-08-22 Thread Rob Dixon
Patrick Dupre wrote:
> On Fri, 22 Aug 2008, Rob Dixon wrote:
> 
>> Patrick Dupre wrote:
>>> How can I modify my Makefile.PL to have a Makefile which can make
>>> cc -o test.o -c test.c `perl -MExtUtils::Embed -e ccopts`
>>>
>>> Thank
>> Makefile.PL is a program written using ExtUtils::MakeMaker to generate a
>> makefile for building a Perl /extension/ module.
>>
>> ExtUtils::Embed is a module that will generate C code and compile/link 
>> options
>> for /embedding/ a perl interpreter into a C program.
>>
>> Extending and embedding Perl are two very different, almost opposite ideas.
>>
>> Since it looks like you have a program called test.c I assume you want to 
>> embed
>> a perl interpreter into that program, and if so you can forget about
>> Makefile.PL. But in that case what are you asking? You clearly know how to
>> compile test.c as you have written it in your post, and it is 
>> straightforward to
>> write a makefile to do that if you want to.
>>
>> So what help do you need from us?
>>
> 
> In fact, I have a Makefile.Pl because I am using ExtUtils to generate
> c for perl (with xs), but I also need to call a perl subroutine for c !!
> I know, it may be not elegant, but it is where I am !!
> 
> So I need the Makefile.PL correct to generate the lib for perl
> and to compile the c to have it be able to call perl.

So you are embedding a perl interpreter into an XS extension because you need to
call a Perl subroutine from that extension. Is that right? If so then you should
just be able to manipulate the Perl stack and make the call using call_sv or
similar. Take a look at

  perldoc perlcall

for help on this. Or let me know if I'm not understanding you correctly.

Rob

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




Re: file manipulation

2008-08-22 Thread Rob Dixon
John W. Krahn wrote:
> Rob Dixon wrote:
>>
>> There is no write function.
> 
> I beg to differ:
> 
> perldoc -f write
>  write FILEHANDLE
>  write EXPR
>  write   Writes a formatted record (possibly multi-line) to the
>  specified FILEHANDLE, using the format associated with that
>  file.  By default the format for a file is the one having
>  the same name as the filehandle, but the format for the
>  current output channel (see the "select" function) may be
>  set explicitly by assigning the name of the format to the $~
>  variable.

Of course. I blame a Freudian blank spot covering anything related to format :)

Thanks John

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




Re: Makefile.PL

2008-08-22 Thread Patrick Dupre

On Fri, 22 Aug 2008, Rob Dixon wrote:


Patrick Dupre wrote:


How can I modify my Makefile.PL to have a Makefile which can make
cc -o test.o -c test.c `perl -MExtUtils::Embed -e ccopts`

Thank


Makefile.PL is a program written using ExtUtils::MakeMaker to generate a
makefile for building a Perl /extension/ module.

ExtUtils::Embed is a module that will generate C code and compile/link options
for /embedding/ a perl interpreter into a C program.

Extending and embedding Perl are two very different, almost opposite ideas.

Since it looks like you have a program called test.c I assume you want to embed
a perl interpreter into that program, and if so you can forget about
Makefile.PL. But in that case what are you asking? You clearly know how to
compile test.c as you have written it in your post, and it is straightforward to
write a makefile to do that if you want to.

So what help do you need from us?



In fact, I have a Makefile.Pl because I am using ExtUtils to generate
c for perl (with xs), but I also need to call a perl subroutine for c !!
I know, it may be not elegant, but it is where I am !!

So I need the Makefile.PL correct to generate the lib for perl
and to compile the c to have it be able to call perl.

--
---
==
 Patrick DUPRÉ  |   |
 Department of Chemistry|   |Phone: (44)-(0)-1904-434384
 The University of York |   |Fax:   (44)-(0)-1904-432516
 Heslington |   |
 York YO10 5DD  United Kingdom  |   |email: [EMAIL PROTECTED]
==
-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Re: Makefile.PL

2008-08-22 Thread Rob Dixon
Patrick Dupre wrote:
> 
> How can I modify my Makefile.PL to have a Makefile which can make
> cc -o test.o -c test.c `perl -MExtUtils::Embed -e ccopts`
> 
> Thank

Makefile.PL is a program written using ExtUtils::MakeMaker to generate a
makefile for building a Perl /extension/ module.

ExtUtils::Embed is a module that will generate C code and compile/link options
for /embedding/ a perl interpreter into a C program.

Extending and embedding Perl are two very different, almost opposite ideas.

Since it looks like you have a program called test.c I assume you want to embed
a perl interpreter into that program, and if so you can forget about
Makefile.PL. But in that case what are you asking? You clearly know how to
compile test.c as you have written it in your post, and it is straightforward to
write a makefile to do that if you want to.

So what help do you need from us?

Rob

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




Re: condition in a single line

2008-08-22 Thread John W. Krahn

Peter Scott wrote:

On Thu, 21 Aug 2008 21:55:46 -0700, Noah wrote:

Is there a way to simplify the following to one line?

 my $value = $t1lsq{$interfaceName};
 $value = 4 if $value > 4;


If you happen to already have

use List::Util qw(max);

in your code (or don't mind adding it) then you can do

my $value = max( 4, $t1lsq{$interfaceName} );


s/max/min/

:-)


John
--
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order.-- Larry Wall

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




Re: condition in a single line

2008-08-22 Thread Peter Scott
On Thu, 21 Aug 2008 21:55:46 -0700, Noah wrote:
> Is there a way to simplify the following to one line?
> 
>  my $value = $t1lsq{$interfaceName};
>  $value = 4 if $value > 4;

If you happen to already have

use List::Util qw(max);

in your code (or don't mind adding it) then you can do

my $value = max( 4, $t1lsq{$interfaceName} );

-- 
Peter Scott
http://www.perlmedic.com/
http://www.perldebugged.com/


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




Re: condition in a single line

2008-08-22 Thread Rob Dixon
Noah wrote:
> 
> Is there a way to simplify the following to one line?
> 
> 
> ---
> 
>  my $value = $t1lsq{$interfaceName};
>  $value = 4 if $value > 4;

I'm wondering why you want to do that?

Depending on your reasons, perhaps this would do?

  my $value = $t1lsq{$interfaceName}; $value = 4 if $value > 4;

Rob

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




Re: timing a fork

2008-08-22 Thread Rob Dixon
Raymond Wan wrote:
> Rob Dixon wrote:
>>
>> What do you need to accomplish that something as simple as the code below 
>> won't do?
>>
>> use strict;
>> use warnings;
>>
>> my $kid = fork;
>>
>> if ($kid) {
>>   print "in parent whose kid is $kid\n";
>> }
>> elsif ($kid == 0) {
>>   print "In child\n";
>>   my ($usertime) = times;
>>   print "$usertime seconds\n";
>> }
>> else {
>>   die "Cannot fork: $!\n";
>> }
> 
> H, true -- I may be adding and adding code unnecessarily... 
> 
> What the forked process does is run a C++ program and it is that program 
> that needs to be timed.  Would the code below accomplish that?  I mean, 
> having "times" in the Perl script that calls that C++ program will give 
> the user time of that (spawned) Perl process.  But that is a close 
> enough estimation of the C++ program's user time provided all I do is 
> run that program?
> 
> Also, this is within modperl/mason and I would like the parent process 
> to be completely detached from the child (so that a web page can be 
> shown) and not care when the child completes...

Please bottom-post your replies to this list, so that extended threads can
remain comprehensible. Thanks.

I have tried to do some experimentation with calls to fork and times, but I
suspect I am failing because they are not implemented fully on my Windows
systems. But I suggest that you do the same yourself, and also remember that a
call to times returns four values including the user time for both the current
process and its children.

I also believe there is no need to fully detach your child process, as setting

  $SIG{CHLD} = 'IGNORE';

should cause the child processes to be reaped automatically and the parent
process need have nothing more to do with them. Presumably their mere existence
as child processes is of no concern?

So I suggest you experiment with something like the slight modification below.
As stated this will not work for me but I believe that is because of the
imperfect emulation of fork on a Windows platform.

HTH,

Rob



use strict;
use warnings;

$|++; # autoflush

$SIG{CHLD} = 'IGNORE';

my $kid = fork;

if ($kid) {
  print "in parent whose kid is $kid\n";
  sleep 10;
  my $running = kill(0, $kid);
  print "Child process ", $running ? "still running\n" : "terminated\n";
}
elsif ($kid == 0) {

  print "In child\n";

  my ($user, $system, $cuser, $csystem);

  ($user, $system, $cuser, $csystem) = times;
  printf "user: %f cuser: %f\n", $user, $cuser;

  system('myprogram') == 0 or die "myprog failed: $?";

  ($user, $system, $cuser, $csystem) = times;
  printf "user: %f cuser: %f\n", $user, $cuser;

  exit;
}
else {
  die "Cannot fork: $!\n";
}


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




Re: get external IP address

2008-08-22 Thread John W. Krahn

William wrote:

Hello,


Hello,


if I want to make an application to allow user find their WAN IP
address, what are the available options in Perl ? I have searched
around.


perldoc -q "How do I find out my hostname, domainname, or IP address?"


John
--
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order.-- Larry Wall

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




Unit testing

2008-08-22 Thread Vyacheslav Karamov

Hi All!

I need to add unit tests to my project which I will start soon.
I'm using latest ActivePerl in Win32 (because I have to) and I installed
Test::Unit::Lite through ppm.bat.
But! When I tried to run example test:

#!/usr/bin/perl -w
 use strict;
 use warnings;

 use File::Basename;
 use File::Spec;
 use Cwd;

 BEGIN {
 chdir dirname(__FILE__) or die "$!";
 chdir '..' or die "$!";

 unshift @INC, map { /(.*)/; $1 } split(/:/, $ENV{PERL5LIB}) if
${^TAINT};

 my $cwd = ${^TAINT} ? do { local $_=getcwd; /(.*)/; $1 } : '.';
 unshift @INC, File::Spec->catdir($cwd, 'inc');
 unshift @INC, File::Spec->catdir($cwd, 'lib');
 }

 use Test::Unit::Lite;

 local $SIG{__WARN__} = sub { require Carp; Carp::confess("Warning:
$_[0]") };

 all_tests;

Warning: Can't stat t\tlib: No such file or directory
at C:/Perl/site/lib/Test/Unit/Lite.pm line 775
at C:\Slavik\Projects\PerlProjects\SuccessText.pl line 22
   main::__ANON__('Can\'t stat t\tlib: No such file or directory\x{a}
at C:/Perl/sit...') called at C:/Perl/lib/Carp.pm line 46
   Carp::carp('Can\'t stat t\tlib: No such file or directory\x{a}')
called at C:/Perl/lib/warnings.pm line 499
   warnings::warnif() called at C:/Perl/lib/File/Find.pm line 712
   File::Find::_find_opt('HASH(0x19e71c4)', 't\tlib') called at
C:/Perl/lib/File/Find.pm line 1286
   File::Find::find('HASH(0x19e71c4)', 't\tlib') called at
C:/Perl/site/lib/Test/Unit/Lite.pm line 775
   Test::Unit::Lite::AllTests::suite('Test::Unit::Lite::AllTests')
called at C:/Perl/site/lib/Test/Unit/Lite.pm line 680

Test::Unit::TestRunner::start('Test::Unit::TestRunner=HASH(0x229cd4)',
'Test::Unit::Lite::AllTests') called at
C:/Perl/site/lib/Test/Unit/Lite.pm line 116
   Test::Unit::Lite::all_tests() called at
C:\Slavik\Projects\PerlProjects\SuccessText.pl line 24



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




Makefile.PL

2008-08-22 Thread Patrick Dupre

Hello,

How can I modify my Makefile.PL to have a Makefile which can make
cc -o test.o -c test.c `perl -MExtUtils::Embed -e ccopts`

Thank

--
---
==
 Patrick DUPRÉ  |   |
 Department of Chemistry|   |Phone: (44)-(0)-1904-434384
 The University of York |   |Fax:   (44)-(0)-1904-432516
 Heslington |   |
 York YO10 5DD  United Kingdom  |   |email: [EMAIL PROTECTED]
==
-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


get external IP address

2008-08-22 Thread William
Hello, if I want to make an application to allow user find their WAN IP 
address, what are the available options in Perl ? I have searched around.


Thank you,
William 



  New Email names for you! 
Get the Email name you've always wanted on the new @ymail and @rocketmail. 
Hurry before someone else does!
http://mail.promotions.yahoo.com/newdomains/aa/

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




Re: condition in a single line

2008-08-22 Thread Mr. Shawn H. Corey
On Thu, 2008-08-21 at 21:55 -0700, Noah wrote:
> Hi there,
> 
> Is there a way to simplify the following to one line?
> 
> 
> ---
> 
>  my $value = $t1lsq{$interfaceName};
>  $value = 4 if $value > 4;
> 
> 
> 
> 
> 

Simple in a Rube Goldberg's kind of way ;)

( $value ) = sort { $a <=> $b } ( 4, $t1lsq{$interfaceName} );


-- 
Just my 0.0002 million dollars worth,
  Shawn

"Where there's duct tape, there's hope."
Cross Time Cafe

"Perl is the duct tape of the Internet."
Hassan Schroeder, Sun's first webmaster


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




Re: condition in a single line

2008-08-22 Thread Dr.Ruud
Noah schreef:

> Is there a way to simplify the following to one line?
>
>my $value = $t1lsq{$interfaceName};
>$value = 4 if $value > 4;

Not really. You might not want to get $t1lsq{$interfaceName} twice,
because of side effects for example, one being that it is just slower to
do things twice.

  my $value = do{my $v=$t1lsq{$interfaceName};$v>4?4:$v};

  my $value = $t1lsq{$interfaceName};$value=4 if $value>4;


Pretty alternative:

  sub min { $_[0] < $_[1] ? $_[0] : $_[1] };

  my $value = min 4, $t1lsq{$interfaceName};

-- 
Affijn, Ruud

"Gewoon is een tijger."


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




RE: About the error message in Perl : "Missing right curly braces"

2008-08-22 Thread Stewart Anderson

> -Original Message-
> From: Peter Scott [mailto:[EMAIL PROTECTED]
> Sent: 21 August 2008 20:14
> To: beginners@perl.org; "Amit Saxena"
> Subject: Re: About the error message in Perl : "Missing right curly
> braces"
> 
> On Thu, 21 Aug 2008 17:48:00 +0530, Amit Saxena wrote:
> >> Load the code into Emacs.  Ensure cperl-mode is enabled.  Mark the
> whole
> >> buffer (control-space at the beginning, then move point to the
end).
> >> Execute M-x indent-region,  Look to see where the indentation goes
> "off".
> >>
> > How can we enable indentation with in  "vi" (and not "vim") on
Solaris
> for
> > Perl code?
> 
> Oh, I am the wrong person to ask about deviant editors with arcane
modal
> interfaces :-) :-)
> 
> Maybe you have just found a use case to come over to the path of
> righteousness :-) :-) :-)
> 
> Seriously, perltidy is a good suggestion given your parameters.
> 
> --
> Peter Scott
> http://www.perlmedic.com/
> http://www.perldebugged.com/
> 
> 
> --
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> http://learn.perl.org/
> 

[Stewart Anderson] ohoh  EMACS preacher proximity alert just went off :)


Information in this email including any attachments may be privileged, 
confidential and is intended exclusively for the addressee. The views expressed 
may not be official policy, but the personal views of the originator. If you 
have received it in error, please notify the sender by return e-mail and delete 
it from your system. You should not reproduce, distribute, store, retransmit, 
use or disclose its contents to anyone. Please note we reserve the right to 
monitor all e-mail communication through our internal and external networks. 
SKY and the SKY marks are trade marks of British Sky Broadcasting Group plc and 
are used under licence. British Sky Broadcasting Limited (Registration No. 
2906991), Sky Interactive Limited (Registration No. 3554332), Sky-In-Home 
Service Limited (Registration No. 2067075) and Sky Subscribers Services Limited 
(Registration No. 2340150) are direct or indirect subsidiaries of British Sky 
Broadcasting Group plc (Registration No. 2247735). All of the companies 
mentioned in this paragraph are incorporated in England and Wales and share the 
same registered office at Grant Way, Isleworth, Middlesex TW7 5QD.

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




Re: doubt in code

2008-08-22 Thread Dr.Ruud
"Irfan J Sayed (isayed)" schreef:


Irfan, trim your postings. Cut out any piece of text that is no longer
relevant. You quoted all the nonsense that Stewart Anderson thinks he
needs to include. Clean up your act.


> Agree, but where is the file name??
> $server will just store the server name right?

There is no file involved. Did you read `perldoc IO::Socket`?

-- 
Affijn, Ruud

"Gewoon is een tijger."


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