Re: parsing a line

2008-08-20 Thread John W. Krahn

thunder wrote:

Hello all


Hello,


I have the following small file that i am parsing one line at a time
(each line consists of hex values)

line 1: 0d
line 2: 
line 3: 2000
line 4: 0064
line 5: 76d457ed462df78c7cfde9f9e33724c6
line 6: bded7a7b9f6d763e
line 7: 0059010081bb300597603b6f90ef4421
line 8: 001608427754e957a0d281bb30059760
line 9: a72f731c3be6


For line 5, for example, i want to break it up into chunks of 8 hex
charaters (ie for example 76d457ed, 462df78c etc).


$ echo 0d

2000
0064
76d457ed462df78c7cfde9f9e33724c6
bded7a7b9f6d763e
0059010081bb300597603b6f90ef4421
001608427754e957a0d281bb30059760
a72f731c3be6 |\
perl -lpe'$. == 5 and $_ = join  , /[[:xdigit:]]{0,8}/g'
0d

2000
0064
76d457ed 462df78c 7cfde9f9 e33724c6
bded7a7b9f6d763e
0059010081bb300597603b6f90ef4421
001608427754e957a0d281bb30059760
a72f731c3be6



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: using perl references from subroutine

2008-08-20 Thread Raymond Wan


Hi Noah,

Would defining $templateConfiguration outside of the for loop be 
sufficient for what you need?


i.e.,

my $templateConfiguation;
foreach my $templateConfigFilename (@templateConfigFilenames) {
   $templateConfigFilename = $TemplateDirectory/$templateConfigFilename;
   (my $sortedTemplateConfigFilename = $templateConfigFilename) =~ 
s/.(configuration.txt)/.sorted-$1/;

   push (my @sortedTemplateConfigFilenames, $sortedTemplateConfigFilename);

   # go read template files and save as sorted
   $templateConfiguation = readConfigTemplate($templateConfigFilename, 
$sortedTemplateConfigFilename);

}


You probably should give it some initial value or do some checking just 
in case nothing is assigned to it within the for-loop...


Ray



Noah wrote:
Okay I see why $templateConfiguration is defined inside a for loop.  
how can I make sure the referenced hash that is returned inside the 
for loop is passed to the main portion of the program.


Here is the for loop.

--- snip ---

foreach my $templateConfigFilename (@templateConfigFilenames) {
$templateConfigFilename = 
$TemplateDirectory/$templateConfigFilename;
(my $sortedTemplateConfigFilename = $templateConfigFilename) =~ 
s/.(configuration.txt)/.sorted-$1/;
push (my @sortedTemplateConfigFilenames, 
$sortedTemplateConfigFilename);


# go read template files and save as sorted
my $templateConfiguation = 
readConfigTemplate($templateConfigFilename, 
$sortedTemplateConfigFilename);

}




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




Re: Using match variable

2008-08-20 Thread Xavier Mas
El Tuesday 19 August 2008 21:15:27 Dr.Ruud va escriure:
 Xavier Mas schreef:
  Dr.Ruud:
  Xavier Mas:
  m#(pattern)#;
  $variable= $1.;
 
  That can be written as:
($variable) = /(pattern)/;
 
  Thank you for pointing that, Dr. Ruud but, what does mean
  ($variable)?.

   /(pattern1).*?(pattern2)/ returns the matches in list context, and the
 number of matches (so 0 or 2) in scalar context.

 Just try it with some test code.

 --
 Affijn, Ruud

 Gewoon is een tijger.

Thank you Ruud!.

-- 
Xavier Mas


__ 
LLama Gratis a cualquier PC del Mundo. 
Llamadas a fijos y móviles desde 1 céntimo por minuto. 
http://es.voice.yahoo.com


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




Re: timing a fork

2008-08-20 Thread John W. Krahn

Raymond Wan wrote:


Hi all,


Hello,

I'm trying to fork a process under modperl for a web server, but I've 
realized that  the problem / misunderstanding that I'm having is 
unrelated to modperl...I get the same problem under Perl.  What I want 
to do is to fork a child process (non-perl program), but also time how 
long it runs.  As I want the user time and not the real time, taking 


perldoc -f times

the time stamp when it starts and stops is possible, but not ideal.  So, 
I think the only way to do this is to time it from the operating system 
rather than within the program.  This is what I have:


-
#!/usr/bin/perl
use diagnostics;
use warnings;
use strict;
use POSIX 'setsid';

my $cmd = qq (/usr/bin/time --output=time.txt ls );

$ENV{'PATH'} = '/bin:/usr/bin';
delete @ENV{'IFS', 'CDPATH', 'ENV', 'BASH_ENV'};

$SIG{CHLD} = 'IGNORE';


Your problem appears to be this line.  When you run:

exec '/usr/bin/time --output=time.txt ls '

The '' at the end causes the whole line to be run in a shell which 
probably sets a SIGCHLD handler of its own.  If you run it without the 
'' at the end then perl runs it directly through execve(2) and 
/usr/bin/time then inherits perl's ignored SIGCHLD status.


When I tested it and changed that line to:

$SIG{ CHLD } = 'DEFAULT';

Or just remove the line altogether it works fine.



defined (my $kid = fork) or die Cannot fork: $!\n;
if ($kid) {
 print in parent whose kid is $kid\n;
}
else {
 print in child\n;

 setsid () or die Can't start a new session: $!;

 open STDIN, '/dev/null'   or die Can't read /dev/null: $!;
 open STDOUT, 'tmp.file' or die Can't write to tmpfile: $!;
 open STDERR, 'STDOUT'   or die Can't write to STDOUT: $!;

 exec $cmd or die Cannot execute exec: $!;
}
-

When I run it, this is printed to stdout:

in child
in parent whose kid is 7122

time.txt is empty; and tmp.file has this:

test.pl
time.txt
tmp.file
/usr/bin/time: error waiting for child process: No child processes

I guess I have a misunderstanding of what fork does...  Does anyone know 
how I can get around this?  I don't quite mind whether the time is 
written to time.txt or to tmp.file...either will do...  (Removing the 
 and/or replacing exec with system yields the same result.)




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/




Repeating the array

2008-08-20 Thread Arun
Hi,
I just wanted small help here, i want to repeat an array for every
30 seconds.
lets us keep i want to send an array for every 30 seconds and also
should be able to quit as per the user.


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




What is wrong with this script ??

2008-08-20 Thread Jyotishmaan Ray
Dear All,

I have a input file containing all the rolnos of 400 studenst. I have written a 
small perl script to create their home directories in the cluster server. 

everything worked fine except for the reason that, it shows up error message 
indicating that the following messages for example: 

when my input file rr.txt contains the following roll nos.:-


s08-1-5-095
s08-1-5-096
s08-1-5-097

the error messages displayed are :-

[EMAIL PROTECTED] perl]# perl h20.pl
chgrp: invalid group `s08-1-5-095'
chgrp: invalid group `s08-1-5-096'
chgrp: invalid group `s08-1-5-097'

The ls -l listing shows up the following :-


drwx-- 2 s08-1-5-095 root   4096 2008-08-20 17:28 s08-1-5-095
drwx-- 2 s08-1-5-096 root   4096 2008-08-20 17:28 s08-1-5-096
drwx-- 2 s08-1-5-097 root   4096 2008-08-20 17:28 s08-1-5-097


As shown above the group is shown as root, but i want each student to be the 
group itself, for example it should be :

drwx--2 s08-1-5-095 s08-1-5-095 4096 2008-08 17:28    
s08-1-5-095

The perl script is shown below:

Can anyone tell me what changes should I make in the script so as to make the 
group same as owner i.e., the roll no. itself.



#!/usr/local/bin/perl
$file = '/root/perl/rr.txt';
open(PWD, $file);
while(PWD)
{
($a)=split(/\s+/,$_);
#system(mkdir /root/perl/$a);
system(chmod 700 /root/perl/$a);
#system(chown   /root/perl/$a  $a);
system(chgrp  $a  /root/perl/$a );
}
close(PWD);
~   














Thanks, 
Jyotishmaan Ray Moderator Of Paradise Groups 
http://yahoogroups.com/group/Spirituality-Paradise Are You Spiritually Aware  
!!! Are You Enjoying Yourself  !!!  See What All You Had Been Missing 
Please Join Immediately By Sending A Blank Mail @  
[EMAIL PROTECTED] 
   


  

RE: What is wrong with this script ??

2008-08-20 Thread Andrew Curry
Depending on your server the error could be that the group doesn't exist i.e. 
on unix you would need to add the groups to /etc/group first. 

-Original Message-
From: Jyotishmaan Ray [mailto:[EMAIL PROTECTED] 
Sent: 20 August 2008 13:17
To: beginners@perl.org
Subject: What is wrong with this script ??

Dear All,

I have a input file containing all the rolnos of 400 studenst. I have written a 
small perl script to create their home directories in the cluster server. 

everything worked fine except for the reason that, it shows up error message 
indicating that the following messages for example: 

when my input file rr.txt contains the following roll nos.:-


s08-1-5-095
s08-1-5-096
s08-1-5-097

the error messages displayed are :-

[EMAIL PROTECTED] perl]# perl h20.pl
chgrp: invalid group `s08-1-5-095'
chgrp: invalid group `s08-1-5-096'
chgrp: invalid group `s08-1-5-097'

The ls -l listing shows up the following :-


drwx-- 2 s08-1-5-095 root   4096 2008-08-20 17:28 s08-1-5-095
drwx-- 2 s08-1-5-096 root   4096 2008-08-20 17:28 s08-1-5-096
drwx-- 2 s08-1-5-097 root   4096 2008-08-20 17:28 s08-1-5-097


As shown above the group is shown as root, but i want each student to be the 
group itself, for example it should be :

drwx--2 s08-1-5-095 s08-1-5-095 4096 2008-08 17:28
s08-1-5-095

The perl script is shown below:

Can anyone tell me what changes should I make in the script so as to make the 
group same as owner i.e., the roll no. itself.



#!/usr/local/bin/perl
$file = '/root/perl/rr.txt';
open(PWD, $file);
while(PWD)
{
($a)=split(/\s+/,$_);
#system(mkdir /root/perl/$a);
system(chmod 700 /root/perl/$a);
#system(chown   /root/perl/$a  $a);
system(chgrp  $a  /root/perl/$a );
}
close(PWD);
~   














Thanks,
Jyotishmaan Ray Moderator Of Paradise Groups 
http://yahoogroups.com/group/Spirituality-Paradise Are You Spiritually Aware  
!!! Are You Enjoying Yourself  !!!  See What All You Had Been Missing 
Please Join Immediately By Sending A Blank Mail @ [EMAIL PROTECTED] 
   


  

This e-mail is from the PA Group.  For more information, see www.thepagroup.com.
This e-mail may contain confidential information.  
Only the addressee is permitted to read, copy, distribute or otherwise use this 
email or any attachments.  
If you have received it in error, please contact the sender immediately.  
Any opinion expressed in this e-mail is personal to the sender and may not 
reflect the opinion of the PA Group.
Any e-mail reply to this address may be subject to interception or monitoring 
for operational reasons or for lawful business practices.


--
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-20 Thread Mr. Shawn H. Corey
On Wed, 2008-08-20 at 05:16 -0700, Jyotishmaan Ray wrote:
 Dear All,
 
 I have a input file containing all the rolnos of 400 studenst. I have written 
 a small perl script to create their home directories in the cluster server. 
 
 everything worked fine except for the reason that, it shows up error message 
 indicating that the following messages for example: 
 
 when my input file rr.txt contains the following roll nos.:-
 
 
 s08-1-5-095
 s08-1-5-096
 s08-1-5-097
 
 the error messages displayed are :-
 
 [EMAIL PROTECTED] perl]# perl h20.pl
 chgrp: invalid group `s08-1-5-095'
 chgrp: invalid group `s08-1-5-096'
 chgrp: invalid group `s08-1-5-097'

You have to create a group before you can change a file to it.  See `man
5 group`.


-- 
Just my 0.0002 million dollars worth,
  Shawn

Where there's duct tape, there's hope.

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: What is wrong with this script ??

2008-08-20 Thread Perry Smith


On Aug 20, 2008, at 7:20 AM, Mr. Shawn H. Corey wrote:


On Wed, 2008-08-20 at 05:16 -0700, Jyotishmaan Ray wrote:

Dear All,

I have a input file containing all the rolnos of 400 studenst. I  
have written a small perl script to create their home directories  
in the cluster server.


everything worked fine except for the reason that, it shows up  
error message indicating that the following messages for example:


when my input file rr.txt contains the following roll nos.:-


s08-1-5-095
s08-1-5-096
s08-1-5-097

the error messages displayed are :-

[EMAIL PROTECTED] perl]# perl h20.pl
chgrp: invalid group `s08-1-5-095'
chgrp: invalid group `s08-1-5-096'
chgrp: invalid group `s08-1-5-097'


You have to create a group before you can change a file to it.  See  
`man

5 group`.


You also are going to hit the same issue when you do chown.  You have  
to create a user too.  Just creating a home directory is not at all  
the same.



--
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-20 Thread Jyotishmaan Ray
Yes, a user uid has already been created in aLDAP server which does  
centralised authentication.

And these home directories were created on a clusetr server machine for 
students to work out theur assignments etc.

   

--- On Wed, 8/20/08, Perry Smith [EMAIL PROTECTED] wrote:
From: Perry Smith [EMAIL PROTECTED]
Subject: Re: What is wrong with this script ??
To: Mr. Shawn H. Corey [EMAIL PROTECTED]
Cc: [EMAIL PROTECTED], beginners@perl.org
Date: Wednesday, August 20, 2008, 6:00 PM

On Aug 20, 2008, at 7:20 AM, Mr. Shawn H. Corey wrote:

 On Wed, 2008-08-20 at 05:16 -0700, Jyotishmaan Ray wrote:
 Dear All,

 I have a input file containing all the rolnos of 400 studenst. I  
 have written a small perl script to create their home directories  
 in the cluster server.

 everything worked fine except for the reason that, it shows up  
 error message indicating that the following messages for example:

 when my input file rr.txt contains the following roll nos.:-


 s08-1-5-095
 s08-1-5-096
 s08-1-5-097

 the error messages displayed are :-

 [EMAIL PROTECTED] perl]# perl h20.pl
 chgrp: invalid group `s08-1-5-095'
 chgrp: invalid group `s08-1-5-096'
 chgrp: invalid group `s08-1-5-097'

 You have to create a group before you can change a file to it.  See  
 `man
 5 group`.

You also are going to hit the same issue when you do chown.  You have  
to create a user too.  Just creating a home directory is not at all  
the same.


-- 
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-20 Thread Mr. Shawn H. Corey
On Wed, 2008-08-20 at 06:11 -0700, Jyotishmaan Ray wrote:
 Yes, a user uid has already been created in aLDAP server which does  
 centralised authentication.
 
 And these home directories were created on a clusetr server machine for 
 students to work out theur assignments etc.

Then you have to change the user creation process to also create the
group.


-- 
Just my 0.0002 million dollars worth,
  Shawn

Where there's duct tape, there's hope.

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/




doubt

2008-08-20 Thread Irfan J Sayed (isayed)
Hi All,

Can you please tell me what is the value of $file. When i execute this
script . it says Can't open : No such file or directory

Please suggect.

Regards

Irf.

#!/usr/bin/perl

# file: count_lines.pl

# Figure 1.4: Count the lines of a file

use strict;

use IO::File;

my $file = shift;

my $counter = 0;

my $fh = IO::File-new($file) or die Can't open $file: $!\n;

while ( defined (my $line = $fh-getline) ) {

$counter++;

}

STDOUT-print(Counted $counter lines\n);



RE: doubt

2008-08-20 Thread Andrew Curry
Im going with empty string or null. 

-Original Message-
From: Irfan J Sayed (isayed) [mailto:[EMAIL PROTECTED] 
Sent: 20 August 2008 14:34
To: beginners@perl.org
Subject: doubt

Hi All,

Can you please tell me what is the value of $file. When i execute this
script . it says Can't open : No such file or directory

Please suggect.

Regards

Irf.

#!/usr/bin/perl

# file: count_lines.pl

# Figure 1.4: Count the lines of a file

use strict;

use IO::File;

my $file = shift;

my $counter = 0;

my $fh = IO::File-new($file) or die Can't open $file: $!\n;

while ( defined (my $line = $fh-getline) ) {

$counter++;

}

STDOUT-print(Counted $counter lines\n);


This e-mail is from the PA Group.  For more information, see www.thepagroup.com.
This e-mail may contain confidential information.  
Only the addressee is permitted to read, copy, distribute or otherwise use this 
email or any attachments.  
If you have received it in error, please contact the sender immediately.  
Any opinion expressed in this e-mail is personal to the sender and may not 
reflect the opinion of the PA Group.
Any e-mail reply to this address may be subject to interception or monitoring 
for operational reasons or for lawful business practices.


--
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-20 Thread Jyotishmaan Ray
Hello,

I created a user by importing a ldif as showb below:

Plz go through this  file. However this file  is located at the LDAP server and 
the homedirectories are to created in the cluster server.dn: 
uid=s08-1-5-097,ou=student,dc=nits,dc=ac,dc=in
uid: s08-1-5-097
cn:  s08-1-5-097
objectClass: account
objectClass: posixAccount
objectClass: top
objectClass: shadowAccount
userPassword: {crypt}$1$REie6fpE$5brEKmdMZlWzxStz7Kqed.
loginShell: /bin/bash
uidNumber: 3053
gidNumber: 3053
homeDirectory: /mnt/btech/s08-1-5-097
shadowLastChange:13458
shadowMin: 0
shadowMax: 99
shadowWarning: 7




I tried excuting the script like too, still the /etc/group was not updated , 
why ?  The script is shown below:





#!/usr/local/bin/perl

use strict;
use warnings;

open(FH,/mnt/btech/rr.txt);
while(FH)
 {
   chomp($_);
   my $homedir = /mnt/btech/$_;
   `groupadd $_`;
   `mkdir $homedir; chmod 700 $homedir;` if(! -e $homedir);
}
close(FH);

what could be wrong with the script ?


--- On Wed, 8/20/08, Mr. Shawn H. Corey [EMAIL PROTECTED] wrote:
From: Mr. Shawn H. Corey [EMAIL PROTECTED]
Subject: Re: What is wrong with this script ??
To: [EMAIL PROTECTED]
Cc: beginners@perl.org
Date: Wednesday, August 20, 2008, 7:01 PM

On Wed, 2008-08-20 at 06:11 -0700, Jyotishmaan Ray wrote:
 Yes, a user uid has already been created in aLDAP server which does 
centralised authentication.
 
 And these home directories were created on a clusetr server machine for
students to work out theur assignments etc.

Then you have to change the user creation process to also create the
group.


-- 
Just my 0.0002 million dollars worth,
  Shawn

Where there's duct tape, there's hope.

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




  

RE: doubt

2008-08-20 Thread Irfan J Sayed (isayed)
Do I need to really give the full pathname of the file and store in the
$file.
What does this line means
my $file = shift;

Regards
Irf.


-Original Message-
From: Andrew Curry [mailto:[EMAIL PROTECTED] 
Sent: Wednesday, August 20, 2008 7:06 PM
To: Irfan J Sayed (isayed); beginners@perl.org
Subject: RE: doubt

Im going with empty string or null. 

-Original Message-
From: Irfan J Sayed (isayed) [mailto:[EMAIL PROTECTED]
Sent: 20 August 2008 14:34
To: beginners@perl.org
Subject: doubt

Hi All,

Can you please tell me what is the value of $file. When i execute this
script . it says Can't open : No such file or directory

Please suggect.

Regards

Irf.

#!/usr/bin/perl

# file: count_lines.pl

# Figure 1.4: Count the lines of a file

use strict;

use IO::File;

my $file = shift;

my $counter = 0;

my $fh = IO::File-new($file) or die Can't open $file: $!\n;

while ( defined (my $line = $fh-getline) ) {

$counter++;

}

STDOUT-print(Counted $counter lines\n);


This e-mail is from the PA Group.  For more information, see
www.thepagroup.com.
This e-mail may contain confidential information.  
Only the addressee is permitted to read, copy, distribute or otherwise
use this email or any attachments.  
If you have received it in error, please contact the sender immediately.

Any opinion expressed in this e-mail is personal to the sender and may
not reflect the opinion of the PA Group.
Any e-mail reply to this address may be subject to interception or
monitoring for operational reasons or for lawful business practices.


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




Re: doubt

2008-08-20 Thread Mr. Shawn H. Corey
On Wed, 2008-08-20 at 19:03 +0530, Irfan J Sayed (isayed) wrote:
 Hi All,
 
 Can you please tell me what is the value of $file. When i execute this
 script . it says Can't open : No such file or directory
 
 Please suggect.
 
 Regards
 
 Irf.
 
 #!/usr/bin/perl
 
 # file: count_lines.pl
 
 # Figure 1.4: Count the lines of a file
 
 use strict;
 
 use IO::File;
 
 my $file = shift;

This is a shortcut for:

  my $file = shift @ARGV;

$file is assign the first command-line argument.  When you run the
script try placing the name of a file after it:

  perl count_lines.pl some_file.txt


-- 
Just my 0.0002 million dollars worth,
  Shawn

Where there's duct tape, there's hope.

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: doubt

2008-08-20 Thread Irfan J Sayed (isayed)
Thank you very much. Really helped.
Regards
Irfan.
 

-Original Message-
From: Mr. Shawn H. Corey [mailto:[EMAIL PROTECTED] 
Sent: Wednesday, August 20, 2008 7:35 PM
To: Irfan J Sayed (isayed)
Cc: beginners@perl.org
Subject: Re: doubt

On Wed, 2008-08-20 at 19:03 +0530, Irfan J Sayed (isayed) wrote:
 Hi All,
 
 Can you please tell me what is the value of $file. When i execute this

 script . it says Can't open : No such file or directory
 
 Please suggect.
 
 Regards
 
 Irf.
 
 #!/usr/bin/perl
 
 # file: count_lines.pl
 
 # Figure 1.4: Count the lines of a file
 
 use strict;
 
 use IO::File;
 
 my $file = shift;

This is a shortcut for:

  my $file = shift @ARGV;

$file is assign the first command-line argument.  When you run the
script try placing the name of a file after it:

  perl count_lines.pl some_file.txt


--
Just my 0.0002 million dollars worth,
  Shawn

Where there's duct tape, there's hope.

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: doubt

2008-08-20 Thread Mr. Shawn H. Corey
On Wed, 2008-08-20 at 19:42 +0530, Irfan J Sayed (isayed) wrote:
 Thank you very much. Really helped.
 Regards
 Irfan.

You can look up:
  perldoc -f shift
  pelrdoc perlvar (and search for @ARGV')


-- 
Just my 0.0002 million dollars worth,
  Shawn

Where there's duct tape, there's hope.

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: Repeating the array

2008-08-20 Thread Jeff Pang
On Wed, Aug 20, 2008 at 1:54 PM, Arun [EMAIL PROTECTED] wrote:
 Hi,
I just wanted small help here, i want to repeat an array for every
 30 seconds.
 lets us keep i want to send an array for every 30 seconds and also
 should be able to quit as per the user.

Hi,
You have described the things very unclearly.
what's send an array? send to where? what's to quit as per the user?

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




RE: How to convert UTF-8 to XML entities?

2008-08-20 Thread siegfried
Silly me! I should have anticipated the need to go back again! Can anyone
give me a little script to search for XML entities and convert them to my
choice of utf-8, utf-16 or utf-32?
Thanks!
Siegfried

 Does anyone have some perl (or emacs lisp) code that will convert the
UTF-8 chinese text in my XML file to entities that look like this: #23433;?
 
 Thanks!
 siegfried


#!/usr/bin/perl

use strict;
use warnings;

for my $file ( @ARGV ){
  open my $fh, ':utf8', $file or die cannot open file $file: $!;
  while( $fh ){
s/([\x7f-\x{ff}])/'#'.ord($1).';'/ge;
print;
  }
}

__END__


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




RE: How to convert UTF-8 to XML entities?

2008-08-20 Thread Mr. Shawn H. Corey
On Wed, 2008-08-20 at 08:28 -0700, siegfried wrote:
 Silly me! I should have anticipated the need to go back again! Can anyone
 give me a little script to search for XML entities and convert them to my
 choice of utf-8, utf-16 or utf-32?

The same thing only backward:

  s/\\#(\d+)\;/chr($1)/ge;  # convert XML entity to UTF-8


-- 
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: Perl Script Needed To Create The Home Drectories.

2008-08-20 Thread Jyotishmaan Ray

 created a user by importing a ldif as shown  below:

Plz go
through this  file. However this file  is located at the LDAP server
and the homedirectories are to created in the cluster server.

dn:
uid=s08-1-5-097,ou=student,dc=nits,dc=ac,dc=in
uid: s08-1-5-097
cn:  s08-1-5-097
objectClass: account
objectClass: posixAccount
objectClass: top
objectClass: shadowAccount
userPassword: {crypt}$1$REie6fpE$5brEKmdMZlWzxStz7Kqed.
loginShell: /bin/bash
uidNumber: 3053
gidNumber: 3053
homeDirectory: /mnt/btech/s08-1-5-097
shadowLastChange:13458
shadowMin: 0
shadowMax: 99
shadowWarning: 7




I tried excuting the script too, still the /etc/group was not updated , why ?  
The script is shown
 below:





#!/usr/local/bin/perl

use strict;
use warnings;

open(FH,/mnt/btech/rr.txt);
while(FH)
 {
   chomp($_);
   my $homedir = /mnt/btech/$_;
   `groupadd $_`;
   `mkdir $homedir; chmod 700 $homedir;` if(! -e $homedir);
}
close(FH);

what could be wrong with the script ?



While
the same script when i ran in another system where my ldap server is
running, I saw that three rollnos were added from the file-rr.txt into
the file /etc/group but again the ls-l command did nt show the changes
infact . Why??

The output of cat /etc/group command after running the script you had given:
[EMAIL PROTECTED] etc]# cat
 group
..
.
s08-1-5-095:x:500:
s08-1-5-096:x:501:
s08-1-5-097:x:502:
[EMAIL PROTECTED] etc]# 

And the output of the ls-l command is as below :-



-rw-r--r-- 1 root root   5124 2008-08-19 01:14 roll.txt
-rw-r--r-- 1 root root 37 2008-08-20 17:21 rr.txt
-rw-r--r-- 1 root root   5076 2008-08-19 20:22 r.txt
drwx-- 2 root root   4096 2008-08-20 18:44 s08-1-5-095
drwx-- 2 root root   4096 2008-08-20 18:44 s08-1-5-096
drwx-- 2 root root   4096 2008-08-20 18:44 s08-1-5-097

The output on running the script, 


Usage: groupadd [options] GROUP

Options:
  -f, --force   force exit with success status if the
 specified
    group already exists
  -r,   create system account
  -g, --gid GID use GID for the new group
  -h, --help    display this help message and exit
  -K, --key KEY=VALUE   overrides /etc/login.defs defaults
  -o, --non-unique  allow create group with
 duplicate
    (non-unique) GID

However
on my cluster server, I did get any such type of messages displyed on
running the script but at the same time ls -l command did not show up
the owner and group as the rollno, but it showed up as root a both
owner and the group.

Also the /etc/group file was not updated. why any pointers ??



No, , that the /etc/group file was not being
updated with the rollnos, from the file rr.txt, on running the script on the 
clsuter server, why what was
was wrong.

It adds to the file /ect/group but it does shows up the owner and the group as 
root only.

What is wrong ??

The output is shown below :-


drwxr-xr-x  2 s07-1-5-060 s07-1-5-060 3864 Jan 25  2008 s07-1-5-060
drwxr-xr-x  2 s07-1-5-061 s07-1-5-061 3864 Jan 25  2008 s07-1-5-061
drwxr-xr-x  2 root    root    3864 Aug 20 19:05 s08-1-5-095
drwxr-xr-x  2 root    root    3864
 Aug 20 19:05 s08-1-5-096
drwxr-xr-x  2 root    root    3864 Aug 19 23:58 s08-1-5-097
-rw-r--r--  1 root    root 239 Aug 20 19:05 s.pl

The owner and group should be the rollno. 

ANY POINTERS ??
  

--- On Wed, 8/20/08, Andrej Ricnik-Bay [EMAIL PROTECTED] wrote:
From: Andrej Ricnik-Bay [EMAIL PROTECTED]
Subject: Re: Perl Script Needed To Create The Home Drectories.
To: Marc Girod [EMAIL PROTECTED], Perl-LDAP Mailing List [EMAIL 
PROTECTED]
Date: Wednesday, August 20, 2008, 11:33 PM

On 20/08/2008, Marc Girod [EMAIL PROTECTED] wrote:

  But, questions like 'why is there a @ on line 4?' should be
  acceptable.
But you don't sign up for a power-sliding event and then
ask the people there what those pedals are for ... ?


  Marc
Cheers,
Andrej


-- 
Please don't top post, and don't use HTML e-Mail :}  Make your quotes
concise.

http://www.american.edu/econ/notes/htmlmail.htm



  

Re: What is wrong with this script ??

2008-08-20 Thread Jyotishmaan Ray


All the users have been created through LIDF files format being imported to the 
central LDAP server in the setup. The hopme directories are being created for 
the students to work on their asignements etc.

The why the ownsership are not shown or changed by the commnds given in the 
script ?

Whats wrong, do let me know ?

Any pointers ??
  

--- On Wed, 8/20/08, Perry Smith [EMAIL PROTECTED] wrote:
From: Perry Smith [EMAIL PROTECTED]
Subject: Re: What is wrong with this script ??
To: Mr. Shawn H. Corey [EMAIL PROTECTED]
Cc: [EMAIL PROTECTED], beginners@perl.org
Date: Wednesday, August 20, 2008, 6:00 PM

On Aug 20, 2008, at 7:20 AM, Mr. Shawn H. Corey wrote:

 On Wed, 2008-08-20 at 05:16 -0700, Jyotishmaan Ray wrote:
 Dear All,

 I have a input file containing all the rolnos of 400 studenst. I  
 have written a small perl script to create their home directories  
 in the cluster server.

 everything worked fine except for the reason that, it shows up  
 error message indicating that the following messages for example:

 when my input file rr.txt contains the following roll nos.:-


 s08-1-5-095
 s08-1-5-096
 s08-1-5-097

 the error messages displayed are :-

 [EMAIL PROTECTED] perl]# perl h20.pl
 chgrp: invalid group `s08-1-5-095'
 chgrp: invalid group `s08-1-5-096'
 chgrp: invalid group `s08-1-5-097'

 You have to create a group before you can change a file to it.  See  
 `man
 5 group`.

You also are going to hit the same issue when you do chown.  You have  
to create a user too.  Just creating a home directory is not at all  
the same.




  

Text search engine

2008-08-20 Thread Dermot
Hi,

This is a slighty OT query.

I am looking for a text search engine that has a Perl interface. I
have found a few, Lucene, OpenFTS and Swish-E. OpenFTS hasn't had a
release of the last 3 years. That makes me nervous about using it.
Lucene is java based. I have zero java experience but there is Perl
Module into a 'C++ port API of Lucene'. There is also a thread on
perlmonks about the performance penalty of tying Perl to Java. I am a
bit surprised that the there isn't a more native Perl text search
engine given Perl's agility with text strings.

Could anyone recommend any of the above or suggest an alternative?
Tia,
Dp.

-- 
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-20 Thread Rob Dixon
Jyotishmaan Ray wrote:
 
 All the users have been created through LIDF files format being imported to 
 the central LDAP server in the setup. The hopme directories are being created
 for the students to work on their asignements etc.
 
 The why the ownsership are not shown or changed by the commnds given in the
 script ?
 
 Whats wrong, do let me know ?
 
 Any pointers ??

- Please bottom-post your responses to this list, so that extended threads can
  remain comprehensible. Thank you.

- This isn't really a Perl problem is it. You're having problems setting up LDAP
  accounts. You could write a program in almost any language to do the same
  thing.

- You are trying to create a group (by shelling out to groupadd) for each user.
  I believe that is fruitless as groups exist only to allow joint access at a
  different level from the user's own. Since you have a umask of 0700 you may as
  well use a single group called 'student' or perhaps 'S08' or something
  similar.

- Try things at the command prompt. If they don't work there then coding a Perl
  program to do them en masse won't help at all.

Rob

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




Re: Text search engine

2008-08-20 Thread Rob Dixon
Dermot wrote:
 
 This is a slighty OT query.
 
 I am looking for a text search engine that has a Perl interface. I
 have found a few, Lucene, OpenFTS and Swish-E. OpenFTS hasn't had a
 release of the last 3 years. That makes me nervous about using it.
 Lucene is java based. I have zero java experience but there is Perl
 Module into a 'C++ port API of Lucene'. There is also a thread on
 perlmonks about the performance penalty of tying Perl to Java. I am a
 bit surprised that the there isn't a more native Perl text search
 engine given Perl's agility with text strings.
 
 Could anyone recommend any of the above or suggest an alternative?

Xapian?

  http://xapian.org/

HTH,

Rob

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




inserting unique records in an SQLite DB

2008-08-20 Thread Octavian Rasnita

Hi,

I have an SQLite database that has a field with a unique constraint and I 
want to be able to insert records as fast as possible.


The program works fine if I use

insert or ignore into table_name...

but the problem is that the primary key field which has autoincrement option 
skips the ID of each record which is not inserted because it is already in 
the database, and I don't want that.


So I have also tried using

eval {
... the query...
};

But the perl interpreter crashes and it appears an error window if the query 
gives an error.


I think that it would take too much time to verify each record if exists in 
the database before inserting it...


Do you have a recommendation for the best way of doing this?

Thank you.

Octavian


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




Re: inserting unique records in an SQLite DB

2008-08-20 Thread Rob Dixon
Octavian Rasnita wrote:
 
 I have an SQLite database that has a field with a unique constraint and I 
 want to be able to insert records as fast as possible.
 
 The program works fine if I use
 
 insert or ignore into table_name...
 
 but the problem is that the primary key field which has autoincrement option 
 skips the ID of each record which is not inserted because it is already in 
 the database, and I don't want that.
 
 So I have also tried using
 
 eval {
 ... the query...
 };
 
 But the perl interpreter crashes and it appears an error window if the query 
 gives an error.
 
 I think that it would take too much time to verify each record if exists in 
 the database before inserting it...
 
 Do you have a recommendation for the best way of doing this?

Since this is a Perl forum it is helpful to use the /full syntax/ of any SQL
that your Perl is using. (I assume you actually have some Perl behind all
this?) And in particular you should avoid abbreviating non-standard SQL, so
that at least we have s chance of looking it up.

Also this sentence

 The problem is that the primary key field which has autoincrement option
 skips the ID of each record which is not inserted because it is already in 
 the database, and I don't want that.

is long and badly expressed.

So what I think you're saying is that you have an SQLite database table whihc
has a field with the attribute

  INTEGER PRIMARY KEY AUTOINCREMENT

(By the way, I think the autoincrement is misleading, if this answer is 
correct.)

and you have found that

  INSERT ON CONFLICT IGNORE

works quickly enough, but some records with duplicate keys are left unchanged
when you want to replace them.

The short answer to that is that I think you want

  INSERT ON CONFLICT REPLACE

and everything will be fine. But I am still unsure of your question, so please
come back and correct me.

Also I'm confused about why you think eval() should help. It is intended to
allow you to handle errors at run time that would otherwise crash the Perl
program, and I don't think that is what is happening here.

I'm especially concerned to hear that it crashed Perl when you tried it. Can you
post the code that did that please, or diagnose the source of the problem
yourself and report it as a bug.

HTH,

Rob

-- 
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-20 Thread Mr. Shawn H. Corey
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


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




Re: Text search engine [OT]

2008-08-20 Thread Raymond Wan


Hi Dermot,

Off-topic, so I hope no one minds if I reply.

Perl is good at manipulating text strings, but that doesn't usually help 
search engine implementations.  A search engine (or information 
retrieval system) has to be fast and after it has tokenized the document 
collection or query, you're basically comparing integers (i.e., a lookup 
table that maps an integer to a word in a dictionary).  Actually, even 
during the initial mapping, a C-style strcmp would be sufficient.  I 
doubt a fast search engine would actual perform string matching using 
regular expressions.


Of course, a Perl implementation might be interesting as a learning tool 
for students.  But as an IR system that is suppose to be run in the 
real world and not in the class room...I don't think you will see a 
Perl system anytime soon.  I think if you wrote quick Perl and C/C++ 
implementations that merely tokenize a collection (let's say of the 
range in GBs), you'll know what I am talking about.  Of course, in the 
classroom, a lecturer might just want the students to play with 
something that is a MB or less...if so, I think Perl would be good and 
students might even prefer it...  :-)


Ray



Dermot wrote:

I am looking for a text search engine that has a Perl interface. I
have found a few, Lucene, OpenFTS and Swish-E. OpenFTS hasn't had a
release of the last 3 years. That makes me nervous about using it.
Lucene is java based. I have zero java experience but there is Perl
Module into a 'C++ port API of Lucene'. There is also a thread on
perlmonks about the performance penalty of tying Perl to Java. I am a
bit surprised that the there isn't a more native Perl text search
engine given Perl's agility with text strings.

Could anyone recommend any of the above or suggest an alternative?
  



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




Re: timing a fork

2008-08-20 Thread Raymond Wan


Hi John,

Thank you very much for your reply!  I've actually been stuck on this 
for a while...but with little knowledge about forking processes, I was a 
quite stuck.


John W. Krahn wrote:

perldoc -f times



Ah, didn't know about that.  I thought to get user time, you had to run 
something (say, /usr/bin/time) from a parent shell...i.e., you can't 
tell what is your own user time.  Thanks for this!





$SIG{CHLD} = 'IGNORE';


Your problem appears to be this line.  When you run:

exec '/usr/bin/time --output=time.txt ls '




Ah, I see.  I was following directions elsewhere 
(http://perldoc.perl.org/perlfaq8.html#How-do-I-start-a-process-in-the-background%3f), 
and its comments about Zombies.  I guess I wanted to reap the child 
processes, but in doing so, lost track of the process that I want to 
time?  (I'm not so sure about this statement...)


I gave what you suggested a try and it works, but I now have a Zombie 
process.  They also suggest a double fork solution, which seems like 
it will give the best of both worlds...no zombies and I should be able 
to time it...  I'll try that now...thanks a lot -- it did help me 
understand the code I had taken from the FAQ.


Ray





--
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-20 Thread Jyotishmaan Ray


Please find the answers of your questions/ confusions that you raised, as 
embedded below

   

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

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.

Answer:

No it does not work for an individual directory too, i have already tested.

What kind of system is this anyway?  That would help me a bit.

This is linux fedora, in a cluster server set-up. Authentication is being done 
centrally by a LDAP server.

I hope that helps to narrow down to find solution to my questions.


I suppose, there is a chance, that the authentication used by perl is not the 
same as what the command based chown, etc commands use.  I assume perl calls 
the system call directly.  On AIX, there are layers of libraries above the 
system call to set up the environment and other stuff to authenticate with.
Hope this helps...
On Aug 20, 2008, at 2:10 PM, Jyotishmaan Ray wrote:


All the users have been created through LIDF files format being imported to the 
central LDAP server in the setup. The hopme directories are being created for 
the students to work on their asignements etc.

The why the ownsership are not shown or changed by the commnds given in the 
script ?

Whats wrong, do let me know ?

Any pointers ??
  

--- On Wed, 8/20/08, Perry Smith [EMAIL PROTECTED] wrote:
From: Perry Smith [EMAIL PROTECTED]
Subject: Re: What is wrong with this script ??
To: Mr. Shawn H. Corey [EMAIL PROTECTED]
Cc: [EMAIL PROTECTED], beginners@perl.org
Date: Wednesday, August 20, 2008, 6:00 PM

On Aug 20, 2008, at 7:20 AM, Mr. Shawn H. Corey wrote:

 On Wed, 2008-08-20 at 05:16 -0700, Jyotishmaan Ray wrote:
 Dear All,

 I have a input file containing all the rolnos of 400 studenst. I  
 have written a small perl script to create their home directories  
 in the cluster server.

 everything worked fine except for the reason that, it shows up  
 error message indicating that the following messages for example:

 when my input file rr.txt contains the following roll nos.:-


 s08-1-5-095
 s08-1-5-096
 s08-1-5-097

 the error messages displayed are :-


 [EMAIL PROTECTED] perl]# perl h20.pl
 chgrp: invalid group `s08-1-5-095'
 chgrp: invalid group `s08-1-5-096'
 chgrp: invalid group `s08-1-5-097'

 You have to create a group before you can change a file to it.  See  
 `man
 5 group`.

You also are going to hit the same issue when you do chown.  You have  
to create a user too.  Just creating a home directory is not at all  
the same.


   
 PerryEase Software, Inc. ( http://www.easesoftware.com )
Low cost SATA Disk Systems for IBMs p5, pSeries, and RS/6000 AIX systems
 



  

Parl-Packer installation urgent help required

2008-08-20 Thread sanket vaidya
Hi all,

When I run makefile .pl while installing Parl::Packer 0.982. I
get this message.

Fetching 'PAR-Packer-0.982-MSWin32-x86-multi-thread-5.10.0.par' from
www.cpan.org... Fetching failed: No compiler found, won't generate
'script/parl.exe'! ...

 

So I downloaded 'PAR-Packer-0.982-MSWin32-x86-multi-thread-5.10.0.par.bin' 
installed it by typing

 

perl -MPAR::Dist
-einstall_par(''PAR-Packer-0.982-MSWin32-x86-multi-thread-5.10.0.par.bin')

 

I got the message

 

Writing D:\Perl\site\lib/auto/PAR/Packer/.packlist

 

Now again when I run makefile.pl I get the same message

 

Fetching 'PAR-Packer-0.982-MSWin32-x86-multi-thread-5.10.0.par' from
www.cpan.org... Fetching failed: No compiler found, won't generate
'script/parl.exe'! ...

 

I need to convert perl program to exe file urgently. Pl. suggest how to get
rid of this.

 

I use Active Perl 5.10.0 on Win Xp.

 

Thanks  Regards,

Sanket Vaidya 

 


http://www.patni.com
World-Wide Partnerships. World-Class Solutions. 
_ 

This e-mail message may contain proprietary, confidential or legally privileged 
information for the sole use of the person or entity to whom this message was 
originally addressed. Any review, e-transmission dissemination or other use of 
or taking of any action in reliance upon this information by persons or 
entities other than the intended recipient is prohibited. If you have received 
this e-mail in error kindly delete this e-mail from your records. If it appears 
that this mail has been forwarded to you without proper authority, please 
notify us immediately at [EMAIL PROTECTED] and delete this mail.
_