Re: output record separator in one liner

2009-04-13 Thread John W. Krahn

Rick wrote:



perl -lane' print "$F[0] ", "$F[4]" , " $F[5]";'

Is there anyway to incoporate $\ <- output record separtor to do this 
instead of printing out w/ manual spaces beteween the variables?


The Output Record Separator is what comes at the end of the record (or 
line in this case), in other words at the end of the print statement. 
You are thinking of a Field Separator, but Perl doesn't have an Output 
Field Separator, just an Input Field Separator (see the -F switch.)


You could just print out a single string:

perl -lane'print "$F[0] $F[4] $F[5]"'



John
--
Those people who think they know everything are a great
annoyance to those of us who do.-- Isaac Asimov

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: output record separator in one liner

2009-04-13 Thread Chas. Owens
On Mon, Apr 13, 2009 at 15:39, Rick  wrote:
>
>
> perl -lane' print "$F[0] ", "$F[4]" , " $F[5]";'
>
> Is there anyway to incoporate $\ <- output record separtor to do this
> instead of printing out w/ manual spaces beteween the variables?
snip

No, you want to use $, or $".  Since $" is already set to a space, you
should probably use it:

perl -lane 'print "@F[0,4,5]"'

You can get it even shorter using -p:

perl -lape '$_="@F[0,4,5]"'


-- 
Chas. Owens
wonkden.net
The most important skill a programmer can have is the ability to read.

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




output record separator in one liner

2009-04-13 Thread Rick



perl -lane' print "$F[0] ", "$F[4]" , " $F[5]";'

Is there anyway to incoporate $\ <- output record separtor to do this 
instead of printing out w/ manual spaces beteween the variables?


--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: how to add support of Msql and CGI in Apache.

2009-04-13 Thread Gunnar Hjalmarsson

Gunnar Hjalmarsson wrote:

Raheel Hassan wrote:

I am facing problems in executing cgi programs, on Apache web server, can
any body tell me how i can configure my Apache server so that it can 
support

CGI and Msql. I also wanted to enable ssl support in the Apache server.


http://httpd.apache.org/docs/2.0/howto/cgi.html

http://httpd.apache.org/docs/2.0/ssl/

AFAIK, MySQL is not an HTTP server configuration thing.

(Do you have a Perl question?)


Btw, if you are on Windows, I recommend that you install the bundle at 
http://www.indigostar.com/indigoampp.html


--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: how to add support of Msql and CGI in Apache.

2009-04-13 Thread Gunnar Hjalmarsson

Raheel Hassan wrote:

I am facing problems in executing cgi programs, on Apache web server, can
any body tell me how i can configure my Apache server so that it can support
CGI and Msql. I also wanted to enable ssl support in the Apache server.


http://httpd.apache.org/docs/2.0/howto/cgi.html

http://httpd.apache.org/docs/2.0/ssl/

AFAIK, MySQL is not an HTTP server configuration thing.

(Do you have a Perl question?)

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




how to add support of Msql and CGI in Apache.

2009-04-13 Thread Raheel Hassan
Hello,

I am facing problems in executing cgi programs, on Apache web server, can
any body tell me how i can configure my Apache server so that it can support
CGI and Msql. I also wanted to enable ssl support in the Apache server.
Thanks in advance.


Regards,
Raheel.


Re: Text::Unidecode behaves differently on two machines

2009-04-13 Thread Chas. Owens
On Mon, Apr 13, 2009 at 09:43, Dr.Ruud  wrote:
> Kelly Jones wrote:
>>
>> I "cpan Text::Unidecode" on 2 machines and then ran this code:
>>
>> use utf8;
>> use Text::Unidecode;
>> print unidecode("\x{5317}\x{4EB0}")."\n";
>> print unidecode("\xd0\x90\xd0\xbb")."\n";
>> print unidecode("\xe3\x82\xa2")."\n";
>>
>> On both machines, the first line correctly prints "Bei Jing", the
>> author's test case.
>>
>> Second line: "Al" on one machine (correct), "DD>>" on the other.
>>
>> Third line: "a" on one machine (correct), "aC/" on the other.
>>
>> Thoughts?
>
> By putting in "use utf8;", you sign a contract that your source file is
> UTF-8 encoded. Why would you need that?
snip

That is the way the docs for Text::Unidecode tell you to do it. I thought
it was odd as well, but I assume they are thinking that you may have UTF-8
characters in your file if you are working with it.  There isn't anything
wrong with using the utf-8 pragma (unless your script is using a different
encoding), but I don't see much of a benefit either (since all of my code
is 7-bit clean).

-- 
Chas. Owens
wonkden.net
The most important skill a programmer can have is the ability to read.

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Text::Unidecode behaves differently on two machines

2009-04-13 Thread Dr.Ruud

Kelly Jones wrote:

I "cpan Text::Unidecode" on 2 machines and then ran this code:

use utf8;
use Text::Unidecode;
print unidecode("\x{5317}\x{4EB0}")."\n";
print unidecode("\xd0\x90\xd0\xbb")."\n";
print unidecode("\xe3\x82\xa2")."\n";

On both machines, the first line correctly prints "Bei Jing", the
author's test case.

Second line: "Al" on one machine (correct), "DD>>" on the other.

Third line: "a" on one machine (correct), "aC/" on the other.

Thoughts?


By putting in "use utf8;", you sign a contract that your source file is 
UTF-8 encoded. Why would you need that?


--
Ruud

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: killing a forked process

2009-04-13 Thread Chas. Owens
On Mon, Apr 13, 2009 at 04:49, Michael Alipio  wrote:
snip
> my $pid = fork ();

You must check to see if $pid is defined.  If it isn't
then fork failed.  The parentheses are oddly placed and
unnecessary.

> if ($pid == 0){
>  exec ("top");

Again with the odd parentheses placement.  Function
calls should look like this

func($blah, $blah);

Control structures should look like this

while (1) {
if ($it_is_true) {

That space is one of the ways humans use to tell
function calls and control structures apart.

> }else{

There is no need to make this an else statement, exec
replaces the current process, so the child can never
reach the rest of the code

>   my $time = 0

You are missing a semi-colon at the end of this statement.

>   while (<1>){

You are trying to read from a non-existent filehandle
named 1, I assume you meant to say

while (1) {

to get an infinite loop.  This is also why your script
will never end: this while loop has no exit condition
and no calls to last in its body.

>     sleep 1;
>     $time++;
>     if ($time == 10){

Why all of this mess instead of a simple sleep 10?

>         kill 9, $pid;

SIGKILL is the kill of last resort, try SIGTERM instead.
It is also a good idea to reap the child with waitpid at
this point.  Right after this statement is where a call
to last should go.

>     }
>   }
> }

It might be a good idea to run "stty sane" to fix the
terminal (top leaves it in a bad state if killed).

#!/usr/bin/perl

use strict;
use warnings;

die "could not fork" unless defined(my $pid = fork);

if ($pid == 0) {
exec "top";
die "could not exec top";
}

sleep 3;

kill 15, $pid;
waitpid $pid, 0;

#fix the terminal after killing top
system "stty", "sane";

-- 
Chas. Owens
wonkden.net
The most important skill a programmer can have is the ability to read.

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: killing a forked process (external programs always detach from child process)

2009-04-13 Thread Michael Alipio

Hi,

I'm trying to launch and external program using fork.



my $pid = fork()

if ($pid == 0){

system ("top");
exit (0);
}else{
waitpid ($pid, 0)
}

print "External Program died!";


The problem is "top", or the program i'm actually going to run always detaches 
to the child perl process I have forked. If I open another terminal while my 
script is running and kill the child's PID, (usually the one with higher number 
because there are two perls running), the external program still keeps running..

How do i tell it to stick to the child process so that when i kill the child, 
the external program will die. Is there a way to capture the PID of the 
external program? I tried using "open" to launch it but open quickly exits the 
program after assigning it to a variable, e.g my $extern_pid = open TOP, "top 
|" or die $!;


 




--- On Mon, 4/13/09, Michael Alipio  wrote:

> From: Michael Alipio 
> Subject: killing a forked process
> To: "begginers perl.org" 
> Date: Monday, April 13, 2009, 4:49 PM
> Hi,
> 
> 
> My program looks like this:
> 
> my $pid = fork ();
> if ($pid == 0){
>   exec ("top");
> }else{
>my $time = 0
>while (<1>){
>  sleep 1;
>  $time++;
>  if ($time == 10){
>  kill 9, $pid;
>  }
>}
> }
> 
> 
> That is, after running the forked "top" process
> for 10 seconds, the main program will end it.
> 
> Any idea why it's not working for me?
> 
> Thanks
> 
> 
> 
> 
>   
> 
> -- 
> To unsubscribe, e-mail: beginners-unsubscr...@perl.org
> For additional commands, e-mail: beginners-h...@perl.org
> http://learn.perl.org/


  

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: escaping regex to do math on backreferences

2009-04-13 Thread Chas. Owens
On Mon, Apr 13, 2009 at 06:12, Gunnar Hjalmarsson  wrote:
snip
>> Also, if you make that change you need to check the for loop as well:
>>
>> for my $i (0 .. 10) {
>
> Actually no.
>
> $ perl -wle '
> @rank = qw/A 2 3 4 5 6 7 8 9 10 J Q K A/;
> print map $_."[cdhs]", @rank[10..10+4];
> '
> Use of uninitialized value $_ in concatenation (.) or string at -e line 3.
snip

Ahha, my original had the same off-by-one error.  How did I miss that?

-- 
Chas. Owens
wonkden.net
The most important skill a programmer can have is the ability to read.

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: escaping regex to do math on backreferences

2009-04-13 Thread Gunnar Hjalmarsson

Chas. Owens wrote:

On Sun, Apr 12, 2009 at 21:58, Gunnar Hjalmarsson  wrote:

Chas. Owens wrote:

my @rank = qw/ 2 3 4 5 6 7 8 9 10 J Q K A /;

   my @rank = qw/A 2 3 4 5 6 7 8 9 10 J Q K A /;
--^

snip

That depends on who you play with.


Ok.


Also, if you make that change you need to check the for loop as well:

for my $i (0 .. 10) {


Actually no.

$ perl -wle '
@rank = qw/A 2 3 4 5 6 7 8 9 10 J Q K A/;
print map $_."[cdhs]", @rank[10..10+4];
'
Use of uninitialized value $_ in concatenation (.) or string at -e line 3.
J[cdhs]Q[cdhs]K[cdhs]A[cdhs][cdhs]
$

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




killing a forked process

2009-04-13 Thread Michael Alipio

Hi,


My program looks like this:

my $pid = fork ();
if ($pid == 0){
  exec ("top");
}else{
   my $time = 0
   while (<1>){
 sleep 1;
 $time++;
 if ($time == 10){
 kill 9, $pid;
 }
   }
}


That is, after running the forked "top" process for 10 seconds, the main 
program will end it.

Any idea why it's not working for me?

Thanks




  

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/