Unable to install module from CPAN

2011-10-23 Thread Punit Jain
Hi ,

I tried to install ExtUtils-CBuilder from CPAN however I get this error :-

  CPAN.pm: Going to build D/DA/DAGOLDEN/ExtUtils-CBuilder-0.280202.tar.gz

ExtUtils::MakeMaker version 6.31 required--this is only version 6.30 at 
Makefile.PL line 7.
BEGIN failed--compilation aborted at Makefile.PL line 7.
Running make test
  Make had some problems, maybe interrupted? Won't test
Running make install

How do I get to upgrade my MakeMaker from 6.30 to 6.31 ?

Really appreciate your help and ideas how to fix it.

Regards,
Punit

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




Re: Unable to install module from CPAN

2011-10-24 Thread Punit Jain
Yes I did. See the erorrs below:-

Removing previously used /root/.cpan/build/ExtUtils-MakeMaker-6.59

  CPAN.pm: Going to build M/MS/MSTROUT/ExtUtils-MakeMaker-6.59.tar.gz

Using included version of ExtUtils::Manifest (1.58) as it is newer than the 
installed version (1.46).
Using included version of CPAN::Meta (2.112150) because it is not already 
installed.
Using included version of Version::Requirements (0.101020) because it is not 
already installed.
Using included version of CPAN::Meta::YAML (0.003) because it is not already 
installed.
Using included version of File::Copy::Recursive (0.38) because it is not 
already installed.
Using included version of ExtUtils::Install (1.52) as it is newer than the 
installed version (1.33).
Using included version of File::Temp (0.22) as it is newer than the installed 
version (0.16).
Using included version of JSON::PP (2.27104) because it is not already 
installed.
Using included version of JSON::PP::Compat5006 (1.09) because it is not already 
installed.
Using included version of Parse::CPAN::Meta (1.4401) because it is not already 
installed.
Using included version of version (0.88) because it is not already installed.
Using included version of ExtUtils::Command (1.16) as it is newer than the 
installed version (1.09).
Checking if your kit is complete...
Looks good
Writing Makefile for ExtUtils::MakeMaker
Writing MYMETA.yml and MYMETA.json
-- NOT OK
Running make test
  Can't test without successful make
Running make install
  make had returned bad status, install seems impossible


Regards,
Punit


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




Re: Unable to install module from CPAN

2011-10-24 Thread Punit Jain
Any help ? I am unable to install it.

Regards,
Punit


- Original Message -
From: "Punit Jain" 
To: "Rob Dixon" 
Cc: beginners@perl.org
Sent: Monday, October 24, 2011 9:16:40 PM
Subject: Re: Unable to install module from CPAN

Yes I did. See the erorrs below:-

Removing previously used /root/.cpan/build/ExtUtils-MakeMaker-6.59

  CPAN.pm: Going to build M/MS/MSTROUT/ExtUtils-MakeMaker-6.59.tar.gz

Using included version of ExtUtils::Manifest (1.58) as it is newer than the 
installed version (1.46).
Using included version of CPAN::Meta (2.112150) because it is not already 
installed.
Using included version of Version::Requirements (0.101020) because it is not 
already installed.
Using included version of CPAN::Meta::YAML (0.003) because it is not already 
installed.
Using included version of File::Copy::Recursive (0.38) because it is not 
already installed.
Using included version of ExtUtils::Install (1.52) as it is newer than the 
installed version (1.33).
Using included version of File::Temp (0.22) as it is newer than the installed 
version (0.16).
Using included version of JSON::PP (2.27104) because it is not already 
installed.
Using included version of JSON::PP::Compat5006 (1.09) because it is not already 
installed.
Using included version of Parse::CPAN::Meta (1.4401) because it is not already 
installed.
Using included version of version (0.88) because it is not already installed.
Using included version of ExtUtils::Command (1.16) as it is newer than the 
installed version (1.09).
Checking if your kit is complete...
Looks good
Writing Makefile for ExtUtils::MakeMaker
Writing MYMETA.yml and MYMETA.json
-- NOT OK
Running make test
  Can't test without successful make
Running make install
  make had returned bad status, install seems impossible


Regards,
Punit


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




Re: Unable to install module from CPAN

2011-10-27 Thread Punit Jain

> Looks good
> Writing Makefile for ExtUtils::MakeMaker
> Writing MYMETA.yml and MYMETA.json
> -- NOT OK

>This is not good. How are you running cpan? Are you running it as a non-root
>user? What is your operating system, distribution and version? Are you using
>the system's built-in perl? Are you using local::lib .

>You've been awfully short on details.


I am running CPAN as :-

perl -MCPAN -e 'shell'


and this is run as root user. OS details - 
cat /etc/redhat-release 
CentOS release 5.5 (Final)

perl -v

This is perl, v5.8.8 built for x86_64-linux-thread-multi

Copyright 1987-2006, Larry Wall

  @INC:
/usr/lib64/perl5/site_perl/5.8.8/x86_64-linux-thread-multi
/usr/lib/perl5/site_perl/5.8.8
/usr/lib/perl5/site_perl
/usr/lib64/perl5/vendor_perl/5.8.8/x86_64-linux-thread-multi
/usr/lib/perl5/vendor_perl/5.8.8
/usr/lib/perl5/vendor_perl
/usr/lib64/perl5/5.8.8/x86_64-linux-thread-multi
/usr/lib/perl5/5.8.8


Regards,
Punit

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




Rsync doesnot work

2012-02-13 Thread Punit Jain
Hi ,

I have a quick question on Rsync.

I am doing a rsync to remote server using code below : -

use File::Rsync;
my $source= "/backup/$TodaysDate";
my $ssh_server = '192.168.0.xxx';
my $destination = '/backup/data/';


my $rsync_obj = File::Rsync->new ( {
'rsync-path'=> $rsync,
'archive'   => 1,
'recursive' => 1,
} );

my $dest_dir = $ssh_server.':'.$destination;
print "$dest_dir";
my $zmrsyncstat = $rsync_obj->exec ( {
src =>  "$source",
dest=>  "$dest_dir"
} );

   if ( $zmremrsyncstat ) {
print OUTPUTFILE "Remote Rsync: Successfully created $destination\n";
}
else {
print OUTPUTFILE  " $! : Remote Rsync: Some Problem Occurred. Please 
check.\n";
}

This works manually if I run this script however under crontab it doesnot. 

Any clue what could be the issue ?

Thanks and Regards.

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




Re: Rsync doesnot work

2012-02-14 Thread Punit Jain
I Jeff,

Sorry but script doesnot run from command line as well.

I changed the script to also include rsh => '/usr/local/bin/ssh', 'rsync-path' 
=> '/usr/local/bin/rsync' 

for rsh over ssh and created passwordless login. But still doesnot work.

Any clues ?

Regards,
Punit



- Original Message -
From: "Jeff Peng" 
To: beginners@perl.org
Sent: Tuesday, February 14, 2012 11:11:18 AM
Subject: Re: Rsync doesnot work

于 2012-2-14 13:14, Punit Jain 写道:
> This works manually if I run this script however under crontab it doesnot.
>
> Any clue what could be the issue ?


How about the environment variables?
For example, you maybe have setup the value of RSYNC_PASSWORD in the 
shell, but the value becomes not effective in the crontab.

HTH.

-- 
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/




Module error

2012-02-15 Thread Punit Jain
Hi,

I am running my perl script and using some perl modules like below :-

use File::Path qw(mkpath);
use File::Rsync;
my $rsync = '/opt/zimbra/rsync/bin/rsync';


when I run the script using 
perl scriptname --> then it runs fine, however when I run through crontab, it 
get this error : -

Can't locate File/Rsync.pm in @INC (@INC contains:/etc/perl 
/usr/local/lib/perl/5.8.8 /usr/local/share/perl/5.8.8 /usr/lib/perl5 
/usr/share/perl5 /usr/lib/perl/5.8 /usr/share/perl/5.8 /usr/local/lib/site_perl 
.) at /opt/zimbra/lbin/backup.pl line 8.

Any clues ?


Best Regards.

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




Query regarding Parallel::ForkManager

2012-03-30 Thread punit jain
Hi ,

I am using ForkManager module for multiprocessing in my code below : -

use Parallel::ForkManager;

  $pm = new Parallel::ForkManager($MAX_PROCESSES);

  foreach $data (@all_data) {
# Forks and returns the pid for the child:
my $pid = $pm->start and next;

... do some work with $data in the child process ...

$pm->finish; # Terminates the child process
  }


Under # do some work ..
I read a file to see if it exists or not. If it exists then perform some
action. Same is repeated for every process by checking that file existence
as primary thing.I run below code in child

 my $file = "/tmp/test";
die "\n Killed as filed doesnot exist \n" if(-e $file);

 However what happens is child creation  doesnot stop and it it gets
created and prints "Killed as filed doesnot exist" and exists

What I require is to exit the parent as well BUT handle it gracefully. I
dont want that if I kill parent, children also die abruptlyand cause data
inconsistency.

I was thinking of using run_on_finish() callback ,however how to handle it
so that all process gracefully exits and also parent doesnot spawn any new
child ?


Thanks and Regards,
Punit


Concatenation in Perl

2012-07-19 Thread punit jain
Hi ,

I am doing a concat operation in Perl  for a string like below : -

if( @folders ) {

map {$query .= "not in:$_ and"; } @folders;
print "\n $query \n";

}

@folders contain - Inbox, Sent

Output from above is - *not in:Inbox and not in:Sent and*
Expected is = *not in:Inbox and not in:Sent* > ie without extra and
after Sent

I tried this with join as well as :-

my $query="";
foreach my $folder ( @folders )
{
$query = join "and" "not in:$folder" "$query";
}

but still same result and this time extra "and" in beginning.

 Any idea how to do this ?


Best Regards.


Storage using Storable

2012-07-20 Thread punit jain
Hi ,

I have a multiple processes which are modifying hash of hash of array. For
multiprocessing I am using Parallel::ForkManager

The requirement is I set Max processes to say 5. Each process is fired by
the script and max 5 parallel process runs and it performs some actions on
a complex datastructure like each process after performing a task based on
success moves user entry from pending hash key to completed hash key.

Now this task needs to be run on around 10K users and I need not run this
more than 1 hr after which I need to store the state disc which I can
revisit and start from point where I left.

I am planning to use Storable module for storing and retrieve later.

My question is do I need to implement locks on write operation as multiple
Procs will be writing data to same complex datastructure ? or just using
store() in each process will take care of simultaneous writes ?

Any pointers to some code will be helpful.

Thanks and Regards,
Puneet


Re: Storage using Storable

2012-07-21 Thread punit jain
Thanks!!!  really helpful


Time based processes

2012-07-21 Thread punit jain
Hi,

I have a requirement where I need to run my perl script for x hours ( which
should be configurable ).
Since the script processes thousand's of accounts, it will definitely take
more than x hrs.

There are 2 parts of question : -


*(A) How to stop after x hours. I cannot run under crontab as X is variable
and set as per admin req. ? *

Can I use $SIG{ALRM} to be invoked after x hrs ? Is this recommended ?

*(B) How do I stop the script graceful without killing the processes and
stop from other sunbprocesses being spanned ?*

Here is my code snippet : -

use Parallel::ForkManager;
  my $pmgr  = Parallel::ForkManager->new($MAX_PROC);

foreach my $acct (@$accts) {
$pmgr-> run_on_start(
sub { my ($pid,$ident)=@_;
  print "** $ident started, pid: $pid **\n";
  }
);
$pmgr->start($acct) and next;

--
--
--
Here comes my specific task for subprocess
--
--
$pmgr->finish();
  }
$pmgr->wait_all_children();
return \%data;
}

Since at a time I am running X- Processes, I dont want them to hardkill  as
each thread is doing critical atomic operation.
How can I stop after x hours from spanning any new subprocess and let the
running process to complete.

Regards,
Punit


Re: Time based processes

2012-07-21 Thread punit jain
For the case which you mentioned :-

>You can let the ALRM-sub simply set a global variable, like $STOP.
Your process should check this before starting a next iteration.

I suppose this needs to be set in parent process which means Signal needs
to be invoked in parent. Is my understanding correct ? Will any new
subprocess that is going to get started will have access to this Global
variable ?

Thanks and Regards.


Re: Time based processes

2012-07-21 Thread punit jain
Also for :-

> for my $step ( @steps ) {
   last if $STOP;

I would think the issue here is if the list is 30K long and we are still at
2K why would be really like to process whole list ?
We can die or handle exit of the script gracefully in my understanding.


Re: Time based processes

2012-07-21 Thread punit jain
>
> > for my $step ( @steps ) {
>last if $STOP;
>
>
> I would think the issue here is if the list is 30K long and we are still
> at 2K why would be really like to process whole list ?
> We can die or handle exit of the script gracefully in my understanding.
>
> Is my understanding correct here  ?


Re: Storage using Storable

2012-07-23 Thread punit jain
Another query, might sound stupid, however if my sub-processes are changing
different key values for a hash where one subprocess key is different from
the other, does it still cound under multiple writer ? Dov we need to worry
on multiple writers to same datastructure or same field in a datastructure
? Sorry for the silly question


Re: Time based processes

2012-07-25 Thread punit jain
Hi

Below is my script where alarm is generated after 15 sec and changes the
global variable in parent from 0 to 1. Is there any mistake in my
multiprocess approach with time-based stop ?

#!/usr/bin/perl
use strict;
use warnings;
use Parallel::ForkManager;

my $MAX_PROC=2;
$|++;
my $stopFlag=0;

main();

sub main {

preprocess(@ARGV);
multiproc($MAX_PROC, @ARGV);

}
sub multiproc {

my $proc=shift;
my $argu = $ARGV[0];

open(USRFILE, "$argu") or die "cant open $!";
my $pmgr  = Parallel::ForkManager->new($proc);

$pmgr->run_on_finish(
   sub { my ($pid, $exit_code, $ident) = @_;
   print "** $ident just got out of the pool ** with PID $pid and
parent pid as $$ exit code: $exit_code\n";
   }
 );
   $pmgr-> run_on_start(
   sub { my ($pid,$ident)=@_;
 print "** $ident started, pid: $pid **\n";
   }
 );

$SIG{ALRM} = sub { $stopFlag = 1; };
alarm(16);

while(my $user = ) {
chomp($user);
print "value of Stop Flag in parent $0 is $stopFlag\n";
if($stopFlag == 1) {
print "stop flag has been set\n";
last;
}
my $id = $pmgr->start($user) and next;
print "value of Stop Flag in child $id is $stopFlag\n";
sleep(7);

$pmgr->finish($user);
  }
print "Waiting for all children to exit\n";
$pmgr->wait_all_children();
alarm(0);
print "All children completed\n";
}


This is what I get output : -

perl mprocess.pl /tmp/list1
value of Stop Flag in parent mprocess.pl is 0
value of Stop Flag in child 0 is 0
** te...@test.com started, pid: 21777 **
value of Stop Flag in parent mprocess.pl is 0
value of Stop Flag in child 0 is 0
** te...@test.com started, pid: 21778 **
value of Stop Flag in parent mprocess.pl is 0
** te...@test.com just got out of the pool ** with PID 21777 and parent pid
as 21776 exit code: 0
** te...@test.com just got out of the pool ** with PID 21778 and parent pid
as 21776 exit code: 0
value of Stop Flag in child 0 is 0
** te...@test.com started, pid: 21811 **
value of Stop Flag in parent mprocess.pl is 0
value of Stop Flag in child 0 is 0
** te...@test.com started, pid: 21812 **
value of Stop Flag in parent mprocess.pl is 0
** te...@test.com just got out of the pool ** with PID 21811 and parent pid
as 21776 exit code: 0
** te...@test.com just got out of the pool ** with PID 21812 and parent pid
as 21776 exit code: 0
value of Stop Flag in child 0 is 0
** te...@test.com started, pid: 21832 **
value of Stop Flag in parent mprocess.pl is 0
value of Stop Flag in child 0 is 0
** te...@test.com started, pid: 21833 **
value of Stop Flag in parent mprocess.pl is 0
** te...@test.com just got out of the pool ** with PID 21832 and parent pid
as 21776 exit code: 0
** te...@test.com just got out of the pool ** with PID 21833 and parent pid
as 21776 exit code: 0
value of Stop Flag in child 0 is 1
** te...@test.com started, pid: 22030 **
value of Stop Flag in parent mprocess.pl is 1
stop flag has been set
Waiting for all children to exit
** te...@test.com just got out of the pool ** with PID 22030 and parent pid
as 21776 exit code: 0
All children completed

The only concern here is I see value of stopflag as 1 for child before the
parent which is a bit wierd:-

value of Stop Flag in child 0 is 1
** te...@test.com started, pid: 22030 **
value of Stop Flag in parent mprocess.pl is 1

Thanks and Regards.


Multiprocessing script

2012-07-25 Thread punit jain
Hi,

Below is my script where alarm is generated after 15 sec and changes the
global variable in parent from 0 to 1. Is there any mistake in my
multiprocess approach with time-based stop ?

#!/usr/bin/perl
use strict;
use warnings;
use Parallel::ForkManager;

my $MAX_PROC=2;
$|++;
my $stopFlag=0;

main();

sub main {

preprocess(@ARGV);
multiproc($MAX_PROC, @ARGV);

}
sub multiproc {

my $proc=shift;
my $argu = $ARGV[0];

open(USRFILE, "$argu") or die "cant open $!";
my $pmgr  = Parallel::ForkManager->new($
proc);

$pmgr->run_on_finish(
   sub { my ($pid, $exit_code, $ident) = @_;
   print "** $ident just got out of the pool ** with PID $pid and
parent pid as $$ exit code: $exit_code\n";
   }
 );

   $pmgr-> run_on_start(
   sub { my ($pid,$ident)=@_;
 print "** $ident started, pid: $pid **\n";
   }
 );

$SIG{ALRM} = sub { $stopFlag = 1; };
alarm(16);

while(my $user = ) {
chomp($user);
print "value of Stop Flag in parent $0 is $stopFlag\n";
if($stopFlag == 1) {
print "stop flag has been set\n";
last;
}
my $id = $pmgr->start($user) and next;
print "value of Stop Flag in child $id is $stopFlag\n";
sleep(7);

$pmgr->finish($user);
  }
print "Waiting for all children to exit\n";
$pmgr->wait_all_children();
alarm(0);
print "All children completed\n";
}


This is what I get output : -

perl mprocess.pl /tmp/list1
value of Stop Flag in parent mprocess.pl is 0
value of Stop Flag in child 0 is 0
** te...@test.com started, pid: 21777 **
value of Stop Flag in parent mprocess.pl is 0
value of Stop Flag in child 0 is 0
** te...@test.com started, pid: 21778 **
value of Stop Flag in parent mprocess.pl is 0
** te...@test.com just got out of the pool ** with PID 21777 and parent pid
as 21776 exit code: 0
** te...@test.com just got out of the pool ** with PID 21778 and parent pid
as 21776 exit code: 0
value of Stop Flag in child 0 is 0
** te...@test.com started, pid: 21811 **
value of Stop Flag in parent mprocess.pl is 0
value of Stop Flag in child 0 is 0
** te...@test.com started, pid: 21812 **
value of Stop Flag in parent mprocess.pl is 0
** te...@test.com just got out of the pool ** with PID 21811 and parent pid
as 21776 exit code: 0
** te...@test.com just got out of the pool ** with PID 21812 and parent pid
as 21776 exit code: 0
value of Stop Flag in child 0 is 0
** te...@test.com started, pid: 21832 **
value of Stop Flag in parent mprocess.pl is 0
value of Stop Flag in child 0 is 0
** te...@test.com started, pid: 21833 **
value of Stop Flag in parent mprocess.pl is 0
** te...@test.com just got out of the pool ** with PID 21832 and parent pid
as 21776 exit code: 0
** te...@test.com just got out of the pool ** with PID 21833 and parent pid
as 21776 exit code: 0
value of Stop Flag in child 0 is 1
** te...@test.com started, pid: 22030 **
value of Stop Flag in parent mprocess.pl is 1
stop flag has been set
Waiting for all children to exit
** te...@test.com just got out of the pool ** with PID 22030 and parent pid
as 21776 exit code: 0
All children completed

The concern here is I see value of stopflag as 1 for child before the
parent which is a bit wierd:-

value of Stop Flag in child 0 is 1
** te...@test.com started, pid: 22030 **
value of Stop Flag in parent mprocess.pl is 1

Thanks and Regards.


Re: Multiprocessing script

2012-07-26 Thread punit jain
Thanks everyone. This is really helpful. Major concern was in situation
where we use multiprocessing I don't end up creating zombies. If the logic
is correct I think I can go ahead with Shlomi's advice to fix other parts.

Best Regards.


updating variable in Parent using Parallel::ForkManager

2012-07-30 Thread punit jain
Hi,


I am facing an issue. Below is code snippet : -

my $pm = new Parallel::ForkManager(10);

 my $count=0;

foreach my $user (@users) {

   $pm->start($user) and next;

   my $result;

 --- do some processing ---

   $pm->finish(0, \$result);

}



$pm->wait_all_children;


However the final value of count is not correct. Is there some race
condition on same variable updation by the processes ?

Regards,
Punit



pm -> run_on_finish (

   sub {

   my $result = @;

   if (defined($result)) {

   my $count += $result;

   }

   }


However I


tie an existing hash with BerkleyDB

2012-08-06 Thread punit jain
Hi,

I have a program where a subroutine creates a hash. I want to later tie it
to BerkleyDB.

my $users = {};
my $entry = {};
my $env =  new BerkeleyDB::Env
-Home => $tmp_dir,
-Flags => DB_CREATE|DB_INIT_CDB|DB_INIT_MPOOL
or die "cannot open environment: $BerkeleyDB::Error\n";
my $berkeleydb_temp_file = "/tmp/tmp.berkeleydb";
my $sdat = searchfunc(  $users, $entry ); # sdat is a reference to hash of
hash of hash

my $db = tie %$sdat, 'BerkeleyDB::Hash',
-Filename => $berkeleydb_temp_file,
-Flags=> DB_CREATE,
-Env  => $env
or die "Cannot create file: $! $BerkeleyDB::Error\n";

this doesnot seem to work and I cannot retrieve anything from $db.

Any ideas ?

Regards,
Punit


Re: tie an existing hash with BerkleyDB

2012-08-06 Thread punit jain
>First of all, one should note that BerkeleyDB can only handle hashes where
the keys and the values are all strings

I saw DBM::Deep but not sure it would be a better option for such
situation. Anyone recommends using that module for such situations ?


DBM::Deep dilemma

2012-08-07 Thread punit jain
I am using DBM::Deep for the reason it support multilevel hashes, however I
ended up in situation where I am getting error while retrieving values from
keys :-

Can't use string ("test1") as a HASH ref while "strict refs"

use Parallel::ForkManager;
use DBM::Deep;
   my $db = new DBM::Deep(
 file => "userdata.db",
 locking => 1,
 autoflush => 1
);

passed this ref to a subroutine...

where I input the values as :-

$entry->{'name'} = $name;
$entry->{'id'} = $id;
$users->{'pending'}->{$entry->{'name'}}->{'email'}=$name;
$users->{'pending'}->{$entry->{'name'}}->{'id'}=$id;
 return $users;

and in other routine I get values :

foreach my $acct (keys %{$users->{pending}}) {
print $acct->{id};
}

However I get error saying :-

Can't use string ("user1") as a HASH ref while "strict refs" in use

The Dumper o/p of $db is :-

$VAR1 = bless( {
 'pending' => bless( {
   'user1' => bless( {

'email' => 'us...@test.com',

'id' => '123'
   },
'DBM::Deep::Hash' ),
   'user2' => bless( {

'email' => 'us...@test.com',

'id' => '343'

}, 'DBM::Deep::Hash' ),
   'user3' => bless( {

'email' => 'us...@test.com',

'id' => '443'

}, 'DBM::Deep::Hash' ),
  },
'DBM::Deep::Hash' )
 }, 'DBM::Deep::Hash' ),
   }, 'DBM::Deep::Hash' );

Is there something I am  doing wrong ?

Thanks and Regards.


Using existing db in DBM::Deep

2012-08-08 Thread punit jain
Hi ,

I am using DBM::Deep to store my HoH.

 my $db = new DBM::Deep(
 file => "hash.db",
 locking => 1,
 autoflush => 1
);

I want to reuse the same hash.db next time I run rather than recreate
hash.db from scratch using new. Is it possible to do so ?

Regards,
Punit


Re: DBM::Deep dilemma

2012-08-08 Thread punit jain
Thanks Rob, I was using wrong syntax.

I now have another issue :-

my $db = new DBM::Deep(
 file => "hash.db",
 locking => 1,
 autoflush => 1
);

I want to reuse the same hash.db next time I run rather than recreate
hash.db from scratch using new. Is it possible to do so ? I couldnot find
any connect or something similar method to connect to existing db

Regards,
Punit


Regex help

2012-12-22 Thread punit jain
Hi,

I have a file like below : -

BEGIN:VCARD
VERSION:2.1
EMAIL:te...@test.com
FN:test1
REV:20101116T030833Z
UID:644938456.1419.
END:VCARD

>From <>(S___-0003) Tue Nov 16 03:10:15 2010
content-class: urn:content-classes:person
Date: Tue, 16 Nov 2010 11:10:15 +0800
Subject: test
Message-ID: <644938507.1420>
MIME-Version: 1.0
Content-Type: text/x-vcard; charset="utf-8"

BEGIN:VCARD
VERSION:2.1
EMAIL:te...@test.com
FN:test2
REV:20101116T031015Z
UID:644938507.1420
END:VCARD



My requirement is to get all text between BEGIN:VCARD and END:VCARD and all
the instances. So o/p should be :-

BEGIN:VCARD
VERSION:2.1
EMAIL:te...@test.com
FN:test1
REV:20101116T030833Z
UID:644938456.1419.
END:VCARD

BEGIN:VCARD
VERSION:2.1
EMAIL:te...@test.com
FN:test2
REV:20101116T031015Z
UID:644938507.1420
END:VCARD

I am using below regex  :-

my $fh = IO::File->new("$file", "r");
my $script = do { local $/; <$fh> };
close $fh;
if (
   $script =~ m/
(^BEGIN:VCARD\s*(.*)
^END:VCARD\s+)/sgmix
){
print OUTFILE $1."\n";
}

However it just prints 1st instance and not all.

Any suggestions ?

Regards,
Punit


grouping in regex

2012-12-23 Thread punit jain
Hi,

I am doing grouping but seeing some weird behavior :-

the strings in a file are like :-
AccessModes =
(18,Mail,POP,IMAP,PWD,WebMail,WebSite,Relay,Mobile,FTP,MAPI,TLS,LDAP,WebCAL);

...
.
multiple lines

I am seeing which lines have both POP and Webmail as below :-

if( $line =~ /AccessModes\s*=\s*.*(WebMail)*.*(POP).*(WebMail)*.*/ ) {
if(defined $2) {
print "$2 $1"."$line"."\n";
}
}


However I get these below :-

  POPUse of uninitialized value in concatenation (.) or string at
test.plline 283,  line 2.
  POPUse of uninitialized value in concatenation (.) or string at
test.plline 283,  line 2.
  POPUse of uninitialized value in concatenation (.) or string at
test.plline 283,  line 2.

Any clue why ?

Regards.


Regex issue

2013-01-03 Thread punit jain
Hi,

I am facing issues in parsing using Regex. The problem definition is as
below : -

A file with data :-

BEGIN
country Japan
passcode 1123
listname sales
contact ch...@example.com
contact m...@example.com
END

BEGIN
country Namibia
passcode 9801
listname dept
contact l...@example.com
END

BEGINDL
country US
passcode 4123
listname Investment
member a...@example.com
member b...@example.com
ENDDL

BEGIN
country US
passcode 4432
listname testing
contact lore...@test.com
contact a...@test.com
END
..
.
...
..
.

I want to parse it in such a way that  all data with BEGIN and END goes in
one file and BEGINDL and ENDDL goes in other with kind of processing I want
to so.

I am using below code but doesnot work : -

#!/usr/bin/perl
my $file=shift;
open( FH , "$file" ) or die("open failed: $!\n");
open ($fh1, ">/tmp/a");
open ($fh2, ">/tmp/b");
my $check=0;
while () {
#next unless /BEGIN/ .. /END/ || /BEGINDL/ .. /ENDDL/ || eof;
if($_ =~ /BEGIN$/ || ($check == 0) ) {
print $fh1 $_;
$check = 0;
if($_ =~ /END$/) {
$check = 2;
}
}elsif($_ =~ /BEGINDL/ || ($check == 1)) {
print $fh2 $_;
$check = 1;
if($_ =~ /ENDDL/) {
$check = 2;
}
}
next unless($check == 2);
}

Any better suggestion ?

Regards.


Regex help needed

2013-01-08 Thread punit jain
Hi ,

I have a file as below : -

{
test = ("test123");
test = ("test123","abc");
test = ("test123","abc","xyz");
}
{
test1 = ("passfile");
test1 = ("passfile","pasfile1");
test1 = ("passfile","pasfile1","user");
}

and so on 

The requirement is to have the file parsing so that final output is  :-

test = ("test123","abc","xyz");
test1 = ("passfile","pasfile1","user");

So basically only pick the lines with maximum number of options for each
type.

Regards.


File::Find help

2013-01-10 Thread punit jain
Hi,

I have a requirement where I have directory structure like : -

test --> test/user1/files, test/user2/files, test/user3/files etc.
under sub-directories with usernames I have file with name usersettings.

So the final structure as : -

test / user1 / usersettings

 user2 / usersettings
 user3 / usersettings
 user4 / usersettings

I need to


File:: Find help

2013-01-10 Thread punit jain
Hi,

I have a requirement where I have directory structure like : -

test --> test/user1/files/, test/user2/files/, test/user3/files/ etc.
under sub-directories with usernames I have file with name usersettings.

So the final structure as : -

test / user1 / usersettings
  /files/
 user2 / usersettings
   /files/
 user3 / usersettings
  /files/
 user4 / usersettings

etc

I need to get all the subdirectories of test and then read the file
usersettings under that later on to do some processing. I wrote code below
:-
#!/usr/bin/perl
use strict;
use warnings;
use File::Basename qw(basename dirname);
use File::Find qw(find);
use File::Find::Rule;
my $indir = shift;
my $Users = {};
my @userdirs=File::Find::Rule->maxdepth(1)->directory->in($indir);

# this will give me user directories which I want only to depth 1.

foreach my $dir(@userdirs){
next if($dir eq "$indir");

# I need to skip parent directory

my $user = basename($dir);
print "$user"."\n";
find( sub {
print $File::Find::name;
if ($File::Find::name =~ /Contacts/ && -s $File::Find::name > 0
) {
print "$File::Find::name";

  # do some processing
  }
 }, $dir);

}

However I get :-

Use of uninitialized value in print at new.pl line 21.
Use of uninitialized value in pattern match (m//) at new.pl line 22.

I think the issue is it is still using depth as 1. How do I reset it ?

Regards.


Re: File:: Find help

2013-01-10 Thread punit jain
I think the issue is as you mentioned exporting find from  File::Find::Rule.
However File::Find I am not sure I will get that flexibility to search only
1 level depth.


On Thu, Jan 10, 2013 at 6:07 PM, David Precious wrote:

> On Thu, 10 Jan 2013 17:56:18 +0530
> punit jain  wrote:
>
> > I need to get all the subdirectories of test and then read the file
> > usersettings under that later on to do some processing. I wrote code
> > below :-
> > #!/usr/bin/perl
> > use strict;
> > use warnings;
> > use File::Basename qw(basename dirname);
> > use File::Find qw(find);
> > use File::Find::Rule;
> [...]
> > find( sub {
> > print $File::Find::name;
> > if ($File::Find::name =~ /Contacts/ && -s
> > $File::Find::name > 0 ) {
> > print "$File::Find::name";
> >
> >   # do some processing
> >   }
> >  }, $dir);
> >
> > }
> >
> > However I get :-
> >
> > Use of uninitialized value in print at new.pl line 21.
> > Use of uninitialized value in pattern match (m//) at new.pl line 22.
>
> I suspect the issue is likely to be that you're mixing File::Find and
> File::Find::Rule - the latter also exports a find() method, so you may
> be inadvertently calling File::Find::Rule's find() method, which
> doesn't set $File::Find::name.
>
> I would recommend changing your code to simply use File::Find::Rule
> exclusively.  Alternatively, call File::Find::find() instead of just
> find().
>
>
> --
> David Precious ("bigpresh") 
> http://www.preshweb.co.uk/ www.preshweb.co.uk/twitter
> www.preshweb.co.uk/linkedinwww.preshweb.co.uk/facebook
> www.preshweb.co.uk/cpanwww.preshweb.co.uk/github
>
>
>
> --
> To unsubscribe, e-mail: beginners-unsubscr...@perl.org
> For additional commands, e-mail: beginners-h...@perl.org
> http://learn.perl.org/
>
>
>


Regex not working correctly

2013-12-11 Thread punit jain
Hi,

I have a requirement where I need to capture phone number from different
strings.

The strings could be :-


1. COMP TEL NO 919369721113  for computer science

2. For Best Discount reach 092108493, from 6-9

3. Your booking Confirmed, 9210833321

4. price for free consultation call92504060

5. price for free consultation call92504060number

I created a regex as below :-

#!/usr/bin/perl

my $line= shift @ARGV;

if($line =~
/(?:(?:\D+|\s+)(?:(91\d{10}|0\d{10}|[7-9]\d{9}|0\d{11})|(?:(?:ph|cal)(\d+|(?:(?:(91\d{10}|0\d{10}|[7-9]\d{9}|0\d{11})|(?:(?:ph|cal)(\d+)))(?:\D+|\s+))/)
{

print "one = $1";


}
It works fine for 1, 2,3 and prints number however for 4 and 5 one I get
number in $2 rather than $1 tough I have pipe operator to check it.

Any clue how to fix this ?


Re: Regex not working correctly

2013-12-11 Thread punit jain
Thanks Shlomi, thats a good idea. However at the same time I was trying to
understand if something is wrong in my regex. Why would $2 capture the
number as I have used :-

(?:(91\d{10}|0\d{10}|[7-9]\d{9}|0\d{11})|(?:(?:ph|cal)(\d+)))

This would in my understanding match either number with regex
91\d{10}|0\d{10}|[7-9]\d{9}|0\d{11}
or with call followed by digits.

In my case 4 ( price for free consultation call92504060) why would $1 store
an empty string and $2 actually stores the number part ?

Regards,
Punit


Re: Regex not working correctly

2013-12-11 Thread punit jain
That answers my question.

Thanks Robert


Log4Perl query

2014-03-28 Thread punit jain
Hi,

I have a requirement where I need different appenders writing to same log
file for different layout patterns.

Below is my log4Perl config file :-

log4perl.logger.timestamp   = INFO, LOG1
log4perl.appender.LOG1   = Log::Log4perl::Appender::File
log4perl.appender.LOG1.filename  = /tmp/status
log4perl.appender.LOG1.mode  = append
log4perl.appender.LOG1.layout= Log::Log4perl::Layout::PatternLayout
log4perl.appender.LOG1.layout.ConversionPattern =* %d %p %m%n*

# second logger points to the same file but with different level
log4perl.logger.message = INFO, LOG2
log4perl.appender.LOG2   = Log::Log4perl::Appender::File
log4perl.appender.LOG2.filename  = /tmp/status
log4perl.appender.LOG2.mode  = append
log4perl.appender.LOG2.layout= Log::Log4perl::Layout::PatternLayout
log4perl.appender.LOG2.layout.ConversionPattern = *%m%n*

My code uses them like below  :-

*my $logger = Log::Log4perl->get_logger('LOG1');*
$logger->info("CPU DETAILS");
$logger->info("===");
$logger->info("Number of cores for the system are: $num_cores");
$logger->info("Operating System is $os");

*$logger->get_logger('LOG2');*
my @cpuresult = `/usr/bin/sar -q`;
$logger->info("@cpuresult");

However when I execute the code I get error :-


Attempt to bless into a reference at
/root/scripts/bin/../lib/Log/Log4perl/Logger.pm line 143.

Any clues ?

Regards,
Punit


Problem with regex

2014-10-06 Thread punit jain
Hi,

I have a regex problem. My current working program is like this :-


#!/usr/bin/perl

*$str='ldap:///uid=user1,ou=People,o=test.com
,mailto:us...@test.com
,ldap:///uid=user2,ou=People,o=test.com
,ldap:///uid=user3,ou=People,o=test.com
';*

while($str=~/^(?:mailto:|ldap:\/\/\/)(.*?),(?:mailto:|ldap:\/\/\/)/){
print "first = $1"."\n";

   # Process user for send email
 ProcessUser($first);
if($str =~ /^(?:ldap:\/\/\/.+?|mailto:.+?),(ldap.*|mailto.*)/) {
print "remain = $1"."\n";
$str=$1;
}
}

However when I have input string as :-

'ldap:///uid=user1,ou=People,o=test.com,a...@test.com*,t...@test.com
,r...@test.com *,ldap:///uid=user2,ou=People,o=
test.com,ldap:///uid=user3,ou=People,o=test.com'

it breaks. I tried multiple regex, however could not get it working.
Any clue on regex changes to accomodate this ?


Regards,
Punit


Re: Problem with regex

2014-10-06 Thread punit jain
Thanks Paul. However I think I couldnot explain the problem.

The issue is when I have mailid's as well as a part of input stream.

 Input stream ---> $str="ldap:///uid=user1,ou=People,o=test.com,a...@test.com
,t...@test.com,r...@test.com,ldap:///uid=user2,ou=People,o=test.com
,ldap:///uid=user3,ou=People,o=test.com";

current output
===
*first = uid=user1,ou=People,o=test.com ,a...@test.com
,t...@test.com ,r...@test.com *
first = uid=user2,ou=People,o=test.com
first = uid=user3,ou=People,o=test.com

expected output

first=uid=user1,ou=People,o=test.com
first=a...@test.com
first=t...@test.com
first=r...@test.com
first = uid=user2,ou=People,o=test.com
first = uid=user3,ou=People,o=test.com

Regards,
Punit


XML Sructure creation not working

2015-11-20 Thread Punit Jain
Hi,

I am facing an issue with my script while creating a XML .

Below is required structure :-



  

  xyz
  true
  Distri
  123

  



However I am getting below o/p


  

  xyz
  true
  Distri
  123

  



My current code is :-

#!/usr/bin/perl

  use strict;
  use warnings;
  use FindBin qw();
  use lib "$FindBin::Bin/../lib";
  use IO::Handle;
  use XML::Simple;
use Data::Dumper ;

  my $xmls = XML::Simple->new(ForceArray => 1);

  my $contents = { rule =>{appliedToList=> { appliedTo => [ ] } } };

  push @{ $contents->{rule}->{appliedToList}->{appliedTo} }, {
  name => ['test'],
  value => ['123'],
  name => [ 'xyz' ],
  type => ['Distri'],
  isValid => [ 'true' ],
  };

  open my $xml, '>', "output.xml" or die $!;
  $xml->print($xmls->XMLout($contents));
  $xml->close();

Any insights on what I am doing wrong ?

Regards,
Punit


Extracting value from regex

2016-06-09 Thread Punit Jain
Hi ,

Below is the problem I am facing :

#!/usr/bin/perl

my @str = ('mailto:y...@gmail.com','ldap:///uid=user1,ou=People,o=test.com
');

foreach (@str) {

# split off ldaps and mailtos

my @addr = $_ =~

  /ldap:\/\/\/(.+)|mailto:(.+)/;

 print $1;

}


When i run this I get  uid=user1,ou=People,o=test.com as output however
don't get y...@gmail.com printed.

Can anyone point me to single regex to achieve this ? I know how to handle
it with different regex checks but need a single regex.


Regards,

Punit