efficient max() function from sort

2008-05-28 Thread Ramprasad A Padmanabhan

I use sort to give the max of an array something like this 

-
my @z = qw(12 24 67 89 77 91 44 5 10);
my $max = ((reverse sort{$a <=> $b} (@z))[0]);
print "MAX = $max\n";
---

but when I am interested only in a single max value, I need not sort the 
entire array 
Is there a more efficient alternative to this

PS: Posts via nntp to nntp.perl.org  appear after a long time
Is there a more preferred way of posting here 


Thanks
Ram



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




tracing "Subroutine ** redefined at " warnings

2006-10-20 Thread Ramprasad A Padmanabhan

I am getting warnings like ( when I run perl -wc )

Subroutine foo redefined at  bar.pm.
I am sure these functions are not redefined anywhere. I would like to 
trace the source of these warnings.


How do I do this.
BTW I am using perl 5.8.3 on linux


Thanks
Ram

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




SOAP::WSDL cant get a simple example working

2006-06-13 Thread Ramprasad A Padmanabhan

Hi,
  I have installed the example server script test.cgi from SOAP::Clean 
examples

Ref
http://backpan.perl.org/authors/id/S/ST/STODGHIL/SOAP-Clean-0.02.readme


Now I have a simple perl script just connecting to this server  , but it 
is failing


#!/usr/bin/perl
use SOAP::WSDL;
use strict;
my $url='http://192.168.2.105/rambin/test.cgi';
my $soap=SOAP::WSDL->new( wsdl => $url);
$soap->proxy('http://localhost');
$soap->servicename('arithmetic-test');
$soap->wsdlinit;

-
OUTPUT
SOAP::Schema->schema has been deprecated. Please use 
SOAP::Schema->schema_url instead. at 
/usr/lib/perl5/site_perl/5.8.5/SOAP/Lite.pm line 2885.
Error processing WSDL: cannot get  at 
/usr/lib/perl5/site_perl/5.8.5/SOAP/WSDL.pm line 62.




Can someone help me debug this ?
Thanks
Ram

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




Web Mail display library

2006-04-04 Thread Ramprasad A Padmanabhan

Hi,
   I want to implement an email reader thru a web browser. Is there a 
utility which can parse mails in the standard unix mail format and 
display it in a html page.


   I tried to write my own using MIME::Parser , but that seems to be 
exceedingly tedious. I have to decide on which multipart type to pickup, 
 ( preferrably html )  bother about encoded headers , bother about 
encoded bodies and all that. Since there are already so many webmail 
clients opensource, I believe there must also be a library like


Can someone help me

Thanks
Ram

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




Re: Expect script to install sshkey

2006-03-03 Thread Ramprasad A Padmanabhan

Wiggins d'Anconia wrote:

Ramprasad A Padmanabhan wrote:


Hi all,
  I have a perl Expect script that install rsa keys for ssh auto login.
When I run the script on command line it works fine.
Now when I run it inside a CGI the script simply gets stuck.  I can see
from the from the SSH server and also the expect logs that the login is
happenning. But After login nothing happens :-(
The commands I give to append the authorized_keys2 file are not executed
at all.



Are the keys readable by the web server user? Sounds like a permissions
problem.



The problem is not with permissions. Actually this is the part script 
where it hangs



..
# $exp is the expect object
$exp->expect(10,
 '-re' , $prompt , \&inter,
 '-re',"password:",sub {}) or die "Couldnt get pass 
prompt\n";

$exp->send("$password\r");
$exp->expect(10, -re , $prompt) or die "Couldnot login\n";

# Until here it is fine. I can see in the ssh logs that login has happened
# The foll commands work if run on commandline only
$exp->raw_pty(1);
$exp->send("\r");
my $cmd = "lynx -source http://192.168.2.32/rsakey.txt >> 
~/.ssh/authorized_keys2\r";

$exp->send($cmd);
$exp->send("\r");
$exp->send("sleep 1 && exit\r");

# The next step is compulsory else nothing works even on command line
#I dont understand why
$exp->interact();
exit(0);

###
I can attach my entire script if necessary



Thanks
Ram





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




Expect script to install sshkey

2006-03-02 Thread Ramprasad A Padmanabhan

Hi all,
   I have a perl Expect script that install rsa keys for ssh auto login.
When I run the script on command line it works fine.
Now when I run it inside a CGI the script simply gets stuck.  I can see 
from the from the SSH server and also the expect logs that the login is 
happenning. But After login nothing happens :-(
The commands I give to append the authorized_keys2 file are not executed 
at all.

Can someone help me ?

Thanks
Ram

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




why does a usenet post take so long to appear

2005-09-02 Thread Ramprasad A Padmanabhan
I posted to this group using usenet ( nntp.perl.org  ). My posts dont 
seem to appear any reason why ?


Thanks
Ram

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




Re: Numeric sort warning

2005-09-02 Thread Ramprasad A Padmanabhan

What do you get when you run perl -c 
Did you cut paste the program from some man page ?


Ram

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




Re: Net::SMTP and a hash of arrays

2005-09-02 Thread Ramprasad A Padmanabhan



  $email->recipient(@{ rcpts{$server} });


Thats the error IMHO
TRY @{$rcpts{$server}}

Ram

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




Re: $ or % For Associative Arrays?

2005-09-02 Thread Ramprasad A Padmanabhan

Please read a book, like the perl beginners patiently.
Anyway to explain in simple terms
% is used for denoting the entire hash ( associative array )
$ is used for accessing a single element

HTH
Ram

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




Re: Perl Expect .. getting output of command

2005-06-16 Thread Ramprasad A Padmanabhan

Randal L. Schwartz wrote:

"Ramprasad" == Ramprasad A Padmanabhan <[EMAIL PROTECTED]> writes:



Ramprasad> $exp->expect(1);

This means "wait at most 1 second for *any* output".



Yes I thought for a simple command like date that should be OK
even If I put $exp->expect(1,/.*2005.*/s) I get no output in the string

Thanks
Ram

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




Perl Expect .. getting output of command

2005-06-15 Thread Ramprasad A Padmanabhan
I am using perl Expect to spawn a shell, run date and get its output .. 
I am not getting the full output of date



Here is the script, can someone tell me where am I going wrong ?

#!/usr/bin/perl
use Expect;
my $exp = Expect->spawn('bash');
print $exp->send("date\r");
$exp->expect(1);
my $str = $exp->after();
print "STR = '$str'\n"; # $str is not complete output of date
$exp->send("exit\r");
$exp->hard_close();
print "Bye\n";
exit 0;

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




what is the MVC all about

2005-06-14 Thread Ramprasad A Padmanabhan

hi,
  I have been lately reading a lot of stuff about perl catalyst with MVC
I am still not clear about practical use of MVC's
Can someone provide pointers about MVC and where they are best used ?

Thanks
Ram

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




MIME::Lite send_by_smtp cant change the default port

2005-06-03 Thread Ramprasad A Padmanabhan
Hi ALL,

  I am trying to send a mail using MIME::Lite 
 I am trying to connect to port 26 of smtp server instead of 25 , but no
luck 
I am not able to see anything wrong in this script , I hope I could get
some inputs 

Thanks
Ram

-- My script is here
#!/usr/bin/perl
use strict;
use MIME::Lite;

my $str=  $ARGV[0],
From=> $ARGV[1],
Subject => 'Test Mail',
   Type=> 'multipart/related'
);

$msg->attach( Type => 'text/plain', Data => $str );
$msg->send_by_smtp("192.168.2.65",Port=>26);


---
This is the output I get 

Failed to connect to mail server: Bad file descriptor
at perl/smtp26 line 17





--
Netcore Solutions Pvt. Ltd.
Website:  http://www.netcore.co.in
Spamtraps: http://cleanmail.netcore.co.in/directory.html
--

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




Re: Emulate "tail -f" on file

2005-05-18 Thread Ramprasad A Padmanabhan
use File::Tail;


On Thu, 2005-05-19 at 11:37, Tielman Koekemoer (TNE) wrote:
> Hi All,
> 
> If I wanted to monitor a file in a way that would emulate "tail -f"
> (in the shell), how would I open the file? 
> 
> open(FILE, " filename |"); (?)
> 
> TIA


--
Netcore Solutions Pvt. Ltd.
Website:  http://www.netcore.co.in
Spamtraps: http://cleanmail.netcore.co.in/directory.html
--

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




Anyone installed Net::LDAPapi

2005-05-16 Thread Ramprasad A Padmanabhan
I am not able to install Net::LDAPapi , 
I looked up google, seems that the module is no longer supported.
Sad, I thought the interface of Net::LDAPapi is really gr8 

Ram


--
Netcore Solutions Pvt. Ltd.
Website:  http://www.netcore.co.in
Spamtraps: http://cleanmail.netcore.co.in/directory.html
--

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




getting filename in <>

2005-05-16 Thread Ramprasad A Padmanabhan
Hi all,
  I have a script that reads all input from the files specified in
commandline

like this 
while(<>){
 ...

}


Inside the loop can I get the filename of the file from which <> is
being read



Thanks
Ram



--
Netcore Solutions Pvt. Ltd.
Website:  http://www.netcore.co.in
Spamtraps: http://cleanmail.netcore.co.in/directory.html
--

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




Re: The last element

2005-05-07 Thread Ramprasad A Padmanabhan
On Sun, 2005-05-08 at 04:43, amr wrote:
> How can I call the last element in the array? 
> 
> I try the pop and it does the job but I think there is another way?
> 
>  
> 
$array[-1]


HTH
Ram


--
Netcore Solutions Pvt. Ltd.
Website:  http://www.netcore.co.in
Spamtraps: http://cleanmail.netcore.co.in/directory.html
--

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




Re: to fork process and use FIFO.

2005-04-30 Thread Ramprasad A Padmanabhan
On Sat, 2005-04-30 at 13:25, Sri Pen wrote:
> Need Help on how  to fork process and use FIFO.
> 
> I have 10 processes that I would like to fork form parent.
>  Each process reads a different file, processes it and returns a
> log.
> I Need to consolidate all the Logs from all 10 processes and write it out to
> a single file.
> 

when many processes write to a single log file there are bound to be
problems especially if the frequency of writes are high. I would suggest
you try using syslog utility ( if on a unix like environment)

Bye
Ram


--
Netcore Solutions Pvt. Ltd.
Website:  http://www.netcore.co.in
Spamtraps: http://cleanmail.netcore.co.in/directory.html
--

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




examples using Template::Plugin::Page

2005-04-27 Thread Ramprasad A Padmanabhan
Hi all,
  I have a html reports page that has now grown too large to manage. I
want to paginate my report. I am already using templates , similar to
Template.pm so I would like keep the presentation stuff outside my perl
code. 
   I was trying to use Data::Page with Template::Plugin::Page but I am
finding it difficult to understand without any examples. (IMHO these
module writers must also put examples :-) )

   Can anybody send me some examples on pagination with Templates

Thanks
Ram


--
Netcore Solutions Pvt. Ltd.
Website:  http://www.netcore.co.in
Spamtraps: http://cleanmail.netcore.co.in/directory.html
--

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




regex substitution

2005-04-27 Thread Ramprasad A Padmanabhan
Hi all,
  
  I want a regex to replace all continuous occurrences of '-' with
something else say 'x' except the first one 

These are some examples 

 "- Ram" ===> "- Ram"
 "-- bla"===> "-x blah"
 "bla ---"   ===> "bla -xxx"

And also
  "-- blah ---" ===>  "-x blah -xx"



What I am doing now is a workaround works fine but I think it is an
overkill

--
# The input string
$x="- -- blah --- blah2";


my $RANDOM='@@@';

# Replace the begining '-'s with @@@
$x=~s/(?http://www.netcore.co.in
Spamtraps: http://cleanmail.netcore.co.in/directory.html
--

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




Re: Script that spans multiple files

2005-04-20 Thread Ramprasad A Padmanabhan
On Thu, 2005-04-21 at 11:09, Daniel Kasak wrote:
> Hi all.
> 
> I have a large script ( 6000 lines ) that I'd like to break into logical
> units. Is there a way I can tell perl to 'append' a list of files into 1
> script so that I can call subs from any of the files and have them
> treated as if they were all from the same script ( ie all my variables
> will be visible )?
> 
> Thanks :)


Dont do that,
   IMHO creating a script at runtime and executing is plain stupid.
Debugging will be a nightmare and so will maintenance be.

Why cant you divide the logical units and put them into functions , in
different library files , if necessary. Pass all variables as function
arguments.


Thanks
Ram

  


--
Netcore Solutions Pvt. Ltd.
Website:  http://www.netcore.co.in
Spamtraps: http://cleanmail.netcore.co.in/directory.html
--

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




Anyone using AJAX

2005-04-14 Thread Ramprasad A Padmanabhan
Hi, 
  I am trying to learn using Ajax instead of form-oriented perl-cgi.
( fascinated with gmail :-) )
I have already started with  CPAN modules Catalyst::Plugin::Ajax and
HTML::Ajax.
Do we have any good documenation / tool that can help me

thanks
Ram



--
Netcore Solutions Pvt. Ltd.
Website:  http://www.netcore.co.in
Spamtraps: http://cleanmail.netcore.co.in/directory.html
--

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




RE: Command line parameters

2005-04-13 Thread Ramprasad A Padmanabhan
On Wed, 2005-04-13 at 12:32, Thomas BÃtzler wrote:
> Ramprasad A Padmanabhan <[EMAIL PROTECTED]> asked:
> > I want to write a perl script like "gnu less".
> > 
> > My perl script accepts input on STDIN or filename(s) as arguments. 
> > If both are missing it should print the error message. How do 
> > I do this ?
> 
> There is always input on STDIN - even a straight eof could be input,
> like in "cat empty_file | ramprasads_less". You should probably try
> and check for filename arguments and revert to STDIN processing if
> there are none, i.e.
> 
> my @files;
> 
> if( @ARGV ){
>   @files = @ARGV;
> } else {
>   @files = ("-");
> }
> 
> foreach my $file (@files){
>   # transparent gzip decompression
>   $file = "/usr/bin/gzip -d < $file|" if $file =~ m/\.gz$/;
> 
>   open( IN, $file ) or die "Cam't open '$file': $!";
>   # do something
>   close( IN );
> }
> 
> HTH,
> Thomas

That is perfectly ok .. but I require to print usage if there is no
input How do I do this ? 

Thanks
Ram


--
Netcore Solutions Pvt. Ltd.
Website:  http://www.netcore.co.in
Spamtraps: http://cleanmail.netcore.co.in/directory.html
--

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




Command line parameters

2005-04-12 Thread Ramprasad A Padmanabhan
I want to write a perl script like "gnu less".

My perl script accepts input on STDIN or filename(s) as arguments. 
If both are missing it should print the error message. How do I do this
? 
The pseudocode will be 

--
IF INPUT ON STDIN  ;then
   Process STDIN

ELSE IF ARGUMENT(S) is a file ;then
   Process content of file(s)

ELSE 
Show usage / help message

END IF 



Any ideas how this can be done in perl ? 

Thanks
Ram


--
Netcore Solutions Pvt. Ltd.
Website:  http://www.netcore.co.in
Spamtraps: http://cleanmail.netcore.co.in/directory.html
--

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




Maillog parser for postfix

2005-04-12 Thread Ramprasad A Padmanabhan
Hi,
  Is there a module for parsing maillogs created by the postfix smtp
server. I think there is one for sendmail .. but not for postfix.

  I am required to do some reporting using the maillog .. Should I just
go ahead an write my own parser ? 

Thanks
Ram


--
Netcore Solutions Pvt. Ltd.
Website:  http://www.netcore.co.in
Spamtraps: http://cleanmail.netcore.co.in/directory.html
--

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




Changing euid & egid of a perl process at runtime

2005-03-31 Thread Ramprasad A Padmanabhan
Hi,

  I want my script started as "root" to run as  user "postfix".
How do I change the uid & gid of the process

Thanks
Ram



--
Netcore Solutions Pvt. Ltd.
Website:  http://www.netcore.co.in
Spamtraps: http://cleanmail.netcore.co.in/directory.html
--

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




quick regex question

2005-03-31 Thread Ramprasad A Padmanabhan
Hi,

  I want to run a substitution for all instances of "_" with "." after
'@' in a string but "_" before "@" should not be touched.

eg 
$str = "[EMAIL PROTECTED]";

Should become  

[EMAIL PROTECTED]



Any suggestions
Thanks
Ram


--
Netcore Solutions Pvt. Ltd.
Website:  http://www.netcore.co.in
Spamtraps: http://cleanmail.netcore.co.in/directory.html
--

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




RE: db handles with fork()

2005-03-30 Thread Ramprasad A Padmanabhan

> I would strongly recommend you connect after the fork. Each process needs to
> have its own connection.

Thanks for the reply. 
   Even I had thought so, probably for efficiency I can use dbi
cached_connect


Ram



--
Netcore Solutions Pvt. Ltd.
Website:  http://www.netcore.co.in
Spamtraps: http://cleanmail.netcore.co.in/directory.html
--

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




db handles with fork()

2005-03-30 Thread Ramprasad A Padmanabhan
Hi,
   I am writing a perl application that connect to a database and then
does a fork()
The child completes the process and does a exit(), but the problem is it
closes the database connection which the parent would like to use.

Can I exit the child process without disconnecting the parent dbi handle

Thanks
Ram


--
Netcore Solutions Pvt. Ltd.
Website:  http://www.netcore.co.in
Spamtraps: http://cleanmail.netcore.co.in/directory.html
--

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




Re: When does a process become defunct

2005-03-28 Thread Ramprasad A Padmanabhan
On Mon, 2005-03-28 at 14:35, Steven Schubiger wrote:
> On 28 Mar, Ramprasad A Padmanabhan wrote:
> 
> > I am writing a daemon in perl , where the parent just forks on some
> > requests and the children take over. But I found many child processes
> > becoming defunct.
> 
> >   wait();
> 
> perldoc -f waitpid

I was not very clear on usefulness of waitpid() 
>From what I understand , I will have to do a waitpid for every fork I
do.  
Can you show me how I could use waitpid() in my script ( non blocking )

Thanks
Ram 


--
Netcore Solutions Pvt. Ltd.
Website:  http://www.netcore.co.in
Spamtraps: http://cleanmail.netcore.co.in/directory.html
--

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




When does a process become defunct

2005-03-27 Thread Ramprasad A Padmanabhan
Hi all,
  I am writing a daemon in perl , where the parent just forks on some
requests and the children take over. But I found many child processes
becoming defunct. I am not sure why. I am catching SIG_CHLD alright.

To reproduce the problem I have just written a skeleton of my script.
The parent process just forks 20 child processes which just sleep and
exit after some random seconds. When I run this too I find some defunct
processes, the problem is I do not get defunct processes everytime. So
this behaviour is not reproducible ( at least with my script :-) )

I am using perl 5.83  on linux ( fedora-3)

Can someone help me out avoiding these zombies

Thanks
Ram

 MY SCRIPT HERE -
use strict;
$GLOBAL::NUM_CH =0;
$|=1;
$SIG{CHLD}=\&count_ch;

foreach(1..20){
  unless(fork()){
sleep int(rand(20));
exit 0;
  }
  print "No of children running now " . ++$GLOBAL::NUM_CH . "\n";
  sleep 2;
}

foreach (1..100){ 
  print "PARENT CHECK LOOP: No of children running now " .
$GLOBAL::NUM_CH . "\n";
  exit(0) unless($GLOBAL::NUM_CH);
  sleep 5;
}

print "Oops : Something went wrong Not all children have quit\n";

sub count_ch { 
  print "1 CHILD QUIT: No of children running now " . --$GLOBAL::NUM_CH
. "\n";
  wait();
}

- END OF SCRIPT 


--
Netcore Solutions Pvt. Ltd.
Website:  http://www.netcore.co.in
Spamtraps: http://cleanmail.netcore.co.in/directory.html
--

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




Regex to remove non printable characters

2005-03-21 Thread Ramprasad A Padmanabhan
Hello All 
I want to remove all characters with ascii values > 127 from a string

Can someone show me a efficient way of doing this.
Currently what I am doing is reading the string char-by-char and check
its ascii value. I think there must be a better way.

Thanks
Ram


--
Netcore Solutions Pvt. Ltd.
Website:  http://www.netcore.co.in
Spamtraps: http://cleanmail.netcore.co.in/directory.html
--

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




Re: Calling a perl script within another

2005-03-18 Thread Ramprasad A Padmanabhan

After a small change This works perfectly fine thank you all

> { 
>  $scriptname = get_scriptname($recipient)
   local(@_)  = ($arg1,$arg2,$arg3);
   do($scriptname);

> 
>  $output = $global::output;
>  # This variable is set by the $scriptname
>  do_something($output); 
> }
> 
> I will try it right away Should work right? 
> 
> Thanks
> Ram
> 
> 
> 
> --
> Netcore Solutions Pvt. Ltd.
> Website:  http://www.netcore.co.in
> Spamtraps: http://cleanmail.netcore.co.in/directory.html
> --


--
Netcore Solutions Pvt. Ltd.
Website:  http://www.netcore.co.in
Spamtraps: http://cleanmail.netcore.co.in/directory.html
--

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




Re: Calling a perl script within another

2005-03-17 Thread Ramprasad A Padmanabhan
> Well, yes, but the way you've designed this, you already run that risk.
> 
> Now if you replaced get_scriptname() with get_subroutine(), and found a 
> way to abstract out the bits that are different for each $recipient, 
> then you could simplify things tremendously, and hopefully make your 
> resource needs go way down:
> 
> {
> $recipient = "[EMAIL PROTECTED]";  # This will come from the MTA
> $sub_name  = get_subroutine($recipient); # do this in one step
> 
> $sub_name->($arg1,$arg2,$arg3);
> }
> 
> This will do everything without making any external calls.
> 


So you are suggesting I write all the user scripts as diff subroutines
in a single module. That is almost impossible in my case, When I design
the SMTP server I have no idea how many users will be there

According to the current design , the user uses a UI which inturn
creates a file ( a perl script ). The Mailscanner Daemon  uses these
scripts when a mail is recvd for a user and takes actions.

Suppose even If I change the UI to write into a single module , the
Module may become a huge file , I dont want such a mess.


I have thought of a different Idea.  The user-wise perl script will set
the output in a variable with a global namespace. My main process will
do() the script and simply read the variable.

like
{ 
 $scriptname = get_scriptname($recipient)
 do("$scriptname $arg1 $arg2 $arg3");

 $output = $global::output;
 # This variable is set by the $scriptname
 do_something($output); 
}

I will try it right away Should work right? 

Thanks
Ram



--
Netcore Solutions Pvt. Ltd.
Website:  http://www.netcore.co.in
Spamtraps: http://cleanmail.netcore.co.in/directory.html
--

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




Re: Calling a perl script within another

2005-03-17 Thread Ramprasad A Padmanabhan

> Okay, so we're back to my other suggestion -- "require" it:
> 
> {
> $script = get_name_of_script(); # names matter! pick good ones!
> $output = require $script or
> die "Couldn't 'require' $script\n$!\n";
> do_something($output);
> }
> 

No I cant use require. Let me tell you why.
The actual application sits inside Mailscanner Daemon on the SMTP
server.
Depending on the email recipient , I wish to call a particular ruleset
which is stored in the user specific perl file.
There may be thousand diff email recipients with different users

for eg 

{ 
   $recipient = "[EMAIL PROTECTED]";  # This will come from the MTA 
   $scriptname = get_scriptname($recipient);
   
   # if I do require here 
require "$scriptname";

# HERE LIES THE PROBLEM 
somefunc($arg1,$arg2,$arg3)# somefunc is defined in $scriptname

} 

now for the next mail , the main process remains same so somefunc is
already defined. If $scriptname is different I will require a new perl
file with the same function somefunc() .. is that OK.

Also I cannot go on requiring files again and again, my process will hog
all the memory then. 


Thanks
Ram



--
Netcore Solutions Pvt. Ltd.
Website:  http://www.netcore.co.in
Spamtraps: http://cleanmail.netcore.co.in/directory.html
--

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




Re: Calling a perl script within another

2005-03-17 Thread Ramprasad A Padmanabhan

> If the code for $script is being generated by the foo() subroutine, then 
> why are you not just eval()ing on the spot?
> 
> {
> $script = foo();
> $output = eval{ $script } or
> die "Couldn't eval code: $script\n$!\n";
> do_something($output);
> }

I am sorry for having created the confusion.
foo() returns the filename  of the script 
so it is something like 

$script_filename=foo();
$output=`perl $script_filename $arg1 $arg2`;
..

Now can I do this  without a diff interpreter. would you suggest I read
the file into a string and eval it 

Thanks
Ram




--
Netcore Solutions Pvt. Ltd.
Website:  http://www.netcore.co.in
Spamtraps: http://cleanmail.netcore.co.in/directory.html
--

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




Calling a perl script within another

2005-03-17 Thread Ramprasad A Padmanabhan
Hi all,
  I have a requirement to call a  perl script  within another and take
the output

for example 

{ 

$script = foo();
$output = `perl $script $a $b $c `;
do_someting($output);
...
}

The above works fine , but I do not want to fork out a new perl process
every time. Is there a way I can avoid this. I would like to use do()
but how do I get the out from do();

Thanks
Ram


--
Netcore Solutions Pvt. Ltd.
Website:  http://www.netcore.co.in
Spamtraps: http://cleanmail.netcore.co.in/directory.html
--

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




Mail 2 sms module

2005-03-14 Thread Ramprasad A Padmanabhan
Hi all,

  Is there any module that can help me convert text or html mail to text
that can be sms-ed
I looked at the email2sms utility, but that does not provide any
includable module and doesnt work well with text & html mails.

Thanks
Ram


--
Netcore Solutions Pvt. Ltd.
Website:  http://www.netcore.co.in
Spamtraps: http://cleanmail.netcore.co.in/directory.html
--

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




Re: Best way to check if element exists

2005-03-11 Thread Ramprasad A Padmanabhan

> print "exists" if $hash{key};

Obviously. But If I am just checking key exists , Is it worth having a
DB_File Hash

Thanks
Ram


--
Netcore Solutions Pvt. Ltd.
Website:  http://www.netcore.co.in
Spamtraps: http://cleanmail.netcore.co.in/directory.html
--

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




Best way to check if element exists

2005-03-10 Thread Ramprasad A Padmanabhan
Hi All,
   Maybe this is OT , I am sorry for that.
 
   I have a specific email application , where I want to check if a
particular id exists or not in a file. 
Since this happens at real time I want the application to be as fast
as possible.
I am currently using DB_File hash, but that seems to be unnecessary
because DB_File hashes are for checking key value pairs, but my
requirement is just to find if a key exists.

Also note that my Hash list will be a really long list,but relatively
static ( No frequent additions/deletions  expected ) 


Thanks
Ram



--
Netcore Solutions Pvt. Ltd.
Website:  http://www.netcore.co.in
Spamtraps: http://cleanmail.netcore.co.in/directory.html
--

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




Re: DB_File Not getting hash values

2005-03-10 Thread Ramprasad A Padmanabhan
Ramprasad A Padmanabhan wrote:
Hi,
  I have a simple script that reads a hashDB  file into a tied hash.
When I do a Dumper , I get the hash values , but when I pring a value 
nothing is printed ... what am I doing wrong here ?


use DB_File;
use strict;
use Data::Dumper;
my %hash;
my $DATAFILE = "sample.db";
tie %hash,  'DB_File', $DATAFILE, O_RDONLY , 0666 , $DB_HASH;
print Dumper([\%hash]);
print "VALUE for a is '" . $hash{a}."' \n";
-
OUTPUT
---
$VAR1 = [
  {
'b' => '2',
'a' => '1',
'c' => '3'
  }
];
VALUE for a is ''
-
Thanks
Ram

Ok I got it , I must install the DBM filters for it
I put
$X->filter_fetch_key  ( sub { s/\0$//} ) ;
$X->filter_store_key  ( sub { $_ .= "\0" } ) ;
$X->filter_fetch_value( sub { s/\0$//} ) ;
$X->filter_store_value( sub { $_ .= "\0" } ) ;
Now things are working fine
Bye
Ram
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>



DB_File Not getting hash values

2005-03-10 Thread Ramprasad A Padmanabhan
Hi,
  I have a simple script that reads a hashDB  file into a tied hash.
When I do a Dumper , I get the hash values , but when I pring a value 
nothing is printed ... what am I doing wrong here ?


use DB_File;
use strict;
use Data::Dumper;
my %hash;
my $DATAFILE = "sample.db";
tie %hash,  'DB_File', $DATAFILE, O_RDONLY , 0666 , $DB_HASH;
print Dumper([\%hash]);
print "VALUE for a is '" . $hash{a}."' \n";
-
OUTPUT
---
$VAR1 = [
  {
'b' => '2',
'a' => '1',
'c' => '3'
  }
];
VALUE for a is ''
-
Thanks
Ram
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



DB_File Not getting hash values

2005-03-10 Thread Ramprasad A Padmanabhan
Hi, 

  I have a simple script that reads a hashDB  file into a tied hash. 
When I do a Dumper , I get the hash values , but when I pring a value
nothing is printed ... what am I doing wrong here ? 


 
use DB_File; 
use strict; 
use Data::Dumper; 

my %hash; 
my $DATAFILE = "sample.db"; 
tie %hash,  'DB_File', $DATAFILE, O_RDONLY , 0666 , $DB_HASH; 
print Dumper([\%hash]); 
print "VALUE for a is '" . $hash{a}."' \n"; 

- 


OUTPUT 
--- 
$VAR1 = [ 
  { 
'b' => '2', 
'a' => '1', 
'c' => '3' 
  } 
]; 
VALUE for a is '' 
- 


Thanks 
Ram 


--
Netcore Solutions Pvt. Ltd.
Website:  http://www.netcore.co.in
Spamtraps: http://cleanmail.netcore.co.in/directory.html
--

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




Re: 2 -D arry in perl

2005-03-09 Thread Ramprasad A Padmanabhan
Adam Saeed wrote:
hi i am some new to per;.
I want to get a day numbers by year and store them in e a 2 -d array,
getting data from mysql. i.e data[dayofyear][year] BUT I COULD NOT
GETTING THE DESIRE RESULT ... ANY HELP my snap code is:
...
...
@year  #have list of years
my $i=0;
my @dayofyear=([],[]);
my @data=([],[]);
my $old;
for $i (0 .. $yrtot)
{
$old = $dbh->prepare("SELECT
distinct(dayofyear(from_unixtime(datetime))) FROM table where
year(from_unixtime(datetime))='$year[$i]'");
  $old->execute();
  while (@dayofyear = $old->fetchrow_array())
{
 push (@data,@dayofyear);
This is not clear
Do you want @data to contain the 2-D result?
Then use
$data[$year[$i]] = [EMAIL PROTECTED]
   ( your push will create only a 1-D array not a 2-D )
You will get @data to be an array of
  $data[year][dayofyear]
and not
   $data[dayofyear][year]
I think this is what you would want
Use dumper to help you see the array. To visually see your data put a 
debug statement like

use Data::Dumper;
print Dumper([EMAIL PROTECTED]);

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



Re: How to remove everything after the last "." dot?

2005-03-08 Thread Ramprasad A Padmanabhan
Bastian Angerstein wrote:
I have a line:
  i.like.donuts.but.only.with.tea
now I want to remove everything that follows the last "."
including the last ".".
in this case ".tea"
Use Regex
To read the manual
perldoc perlre
Of course In your case you could simply do something like this
$line =~s/\.[^.]+$//;
Thanks
Ram
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



Re: AW: How to remove everything after the last "." dot?

2005-03-08 Thread Ramprasad A Padmanabhan
Bastian Angerstein wrote:
Hmmm...
use strict; use warnings;
my $a="i.like.donuts.but.only.with.tea";
$a=~s/\.\w+$//; # < maybe w+ not d+???
Better still
$a =~s/\.[^.]+$//;
Thanks
Ram
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



Re: reading an file

2005-03-08 Thread Ramprasad A Padmanabhan
E.Horn wrote:
Hello!
I want to read this file into an array.
How can i just get 4, 5, 6,7,8 into an array?
Post what you have already tried.  What you want to do is not very clear.
Thanks
Ram
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



Substitute Regex with 'e'

2005-02-14 Thread Ramprasad A Padmanabhan
Hi 

   I want to so a substititue a string Say 

   my %hash = ( 1130, "a" , 2100, "b");

$x = 'SOMEJUNK 1130';

# I want $x to be'1130a'

   # This regex does not work 
$x=~s/^(.*?) (\d+)/ $2 . { defined $hash{$2} ?  $hash{$2} :
'NOTFOUND' } /e;

Can someone fix the regex for me

Thanks
Ram


RE: using namespace

2005-01-27 Thread Ramprasad A Padmanabhan
On Thu, 2005-01-27 at 15:11, Manav Mathur wrote:
> use semantics internally do an import.
> By multiple files, do you mean multiple packages??
> see perldoc -f use
> 
> for the code that you have listed below, you'll have to 'use' Some::Module
> inside package MyLibModule.
> 
> for perldoc
> 
> The "import" is not a builtin--it's just an ordinary static method call into
> the "Module" package to tell the module to import the list of features back
> into the *current* package.
> 
> also see
> perldoc Exporter
> 
> Manav

I do not want to use Some::Module in my '.pm' file. Simple reason is
that the MyLibModule is being used by many scripts and every script does
not need functions from Some::Module. Why should I load the module
unneccarily then

In C++ I can do 
{
using namespace std;
cout << "Hi"; // Instead of std::cout << "HI";
}

Is there an equivalent in perl


Thanks
Ram





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




RE: using namespace

2005-01-27 Thread Ramprasad A Padmanabhan
Hi Manav,
 But still import does not work across multiple files.

for eg, 
main.pl-
#!/usr/bin/perl
#
use Some::Module qw(someFunction1);
require MyLibModule;

# This function will now work
someFunction1();

MyLibModule::someOtherFunction();

---END



--MyLibModule.pm--
#
#
#
sub someOtherFunction { 
   someFunction1() ; 
# WILL NOT WORK HERE 
# I have to write Some::Module::someFunction1()
}

1;
-END




Thanks
Ram



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




using namespace

2005-01-27 Thread Ramprasad A Padmanabhan
Is there anyway I can do a 
using namespace for a particular loop like in c++;
( for functions not exported )

FOr eg in a perl script 


use Some::Module

{ 
  using namespace Some::Module;   # Is this possible ? 
  
  someFuntion1();  # Instead of Some::Module::someFunction1()
  someFunction2(); # Instead of Some::Module::someFunction2()
}



Thanks
Ram





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




RE: How to find the Index of an element in array?

2005-01-27 Thread Ramprasad A Padmanabhan
On Thu, 2005-01-27 at 13:10, Mallik wrote:
> Hi,
> 
> Thanks for ur reply.
> 
> Is there any function instead of looping thru entire array.
> 
> Mallik.
> 

You can do fancy stuff like below, but this may not be necessarily
better. Can you post where you are trying to use this ? 
What is there is more than one match ? 

...
...
my $i=0;
grep { /^pqr$/ && print $i ; $i++ } @arr; 



Bye 
Ram



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




Regex lookahead problem

2005-01-11 Thread Ramprasad A Padmanabhan
I have a string

$X='#SOME_STRING END';

I want to remove the begining '#' and ending 'END' but retain everything
in between. 


This way works fine
$X=~s/^#(.*?) END$/$1/; # $X is now SOME_STRING

But this way does not 
s/^#(?=.*) END$//;   ## $X is still #SOME_STRING END



Any pointers why the lookahead ?= is not working

Thanks
Ram



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




RE: Checking if a scalar value is a number or not

2004-12-01 Thread Ramprasad A Padmanabhan
On Wed, 2004-12-01 at 19:04, Bob Showalter wrote:
> Ing. Branislav Gerzo wrote:
> > Mat Harris [MH], on Wednesday, December 1, 2004 at 12:19 (+)
> > contributed this to our collective wisdom:
> > 
> > > > Is there any special function for that job?
> > 
> > > personally I would use a rexex:
> > > if ($myunknownvalue =~ m/^\d*$/)
> > 
> > personally I would change this regex to:
> > if ($myunknownvalue =~ m/^\d+$/)
> > because regex given matches also empty set ('')
> 
> Your regex matches the string "123\n", if it matters.
> 
> A simpler approach is to invert the test:
> 
>$var !~ /\D/;

Again Fails for

$var=undef;
if($var !~/\D/){
  print "$var is a number\n";
}




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




Re: How to install LWP.pm module

2004-11-25 Thread Ramprasad A Padmanabhan
On Thu, 2004-11-25 at 11:43, Prabahar Mosas wrote:
>
> Dear All, 
>  
> I am using perl 5.00503.  In this perl lot of pm modules 
> are missing.  I want to add LWP.pm,Warnings.pm  in this perl. If 
> anybody know regarding this mail me. 

You will have to upgrade perl to get warnings working. Upgrade is in any
case unavoidable, a lot of modules will not get installed if you use old
perl. 

Ram




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




False warning by warnings.pm

2004-11-22 Thread Ramprasad A Padmanabhan
I am using  Net::Telnet  in one of my perl scripts. Problem is every
time it runs with use warnings It prints out  warnings like 

Unrecognized escape \s passed through at 

Where that line  is 
$t->waitfor("/ord\s*:\s*/");

Which is perfectly OK ( I think )
Can someone tell how to get rid of this warning ? 

Thanks
Ram




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




Re: Reconfiguring PERL

2004-11-22 Thread Ramprasad A Padmanabhan

On Mon, 2004-11-22 at 15:43, Richard Foley wrote:
> How do I reinitialize/reconfigure my PERL installation (v5.8)? I fear my
> initial configuration is flawed as I cannot install modules or upgrade
> Bundle::CPAN ... keep getting errors related to ncftp, etc.
> 
> Thank you.

Fix your CPAN first.

What I do is install URI and libwww  modules  first manually. CPAN would
automatically use these modules. Much better that ftp etc , because they
dont work easily behind firewalls or proxies.

Use the CPAN shell to do the rest of the work

HTH
Ram









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




RE: :SMTP change port

2004-11-19 Thread Ramprasad A Padmanabhan

On Fri, 2004-11-19 at 21:13, Bob Showalter wrote:
> Ramprasad A Padmanabhan wrote:
> > I am using Net::SMTP to send mails to an SMTP server.
> > If the server is running on a non std port how do I send mails to this
> > port
> 
> Not documented, but inspection of the Net::SMTP code shows that:
> 
>$smtp = Net::SMTP->new($host, Port => 1234);
> 
> should do the trick (replace 1234 with the actual port)
> 
> HTH

Thanks a lot. I too gave it a shot just after posting. It worked.

Ram



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




Net::SMTP change port

2004-11-19 Thread Ramprasad A Padmanabhan
I am using Net::SMTP to send mails to an SMTP server. 
If the server is running on a non std port how do I send mails to this
port

Thanks
Ram



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




Re: perl module - Statistical mean and sd

2004-11-18 Thread Ramprasad A Padmanabhan
Chris Devers wrote:
Please make an effort to use conventional spelling. 

"any1" isn't cute; it's annoying.
 

No offence intended , but I think that is still ok.  I think it is in 
the spirit of perl to reduce typing as much as possible.
After all we just are sharing knowledge, not writing a grammer test

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



Re: how to read header of messages on server using socket

2004-11-17 Thread Ramprasad A Padmanabhan
On Wed, 2004-11-17 at 17:36, supriya devburman wrote:
> hi can anybody tell me
> how to read header of 
> incoming messages on pop3
> mail server using 
> socket.
> 
> Thnx
> 

use Mail::POP3Client
http://search.cpan.org/~sdowd/POP3Client-2.13/POP3Client.pm

Ram



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




How to find if the script is running on a 32-bit machine

2004-11-02 Thread Ramprasad A Padmanabhan
In a particular script , that is used on multiple unix platforms, I need
to know if my perl script is being run on a 32 bit machine or a 64 bit
machine

Is there any way I can find this portably


Thanks
Ram



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




Re: Sourcing Configuration files

2004-11-02 Thread Ramprasad A Padmanabhan
On Tue, 2004-11-02 at 13:41, Gavin Henry wrote:
> Hi all,
> 
> What is the easiest way to move variable declarations out into a file in
> /etc/ and requiring a perl program to read them in at startup. If they are
> not there, then the program must complain.
> 
> Thanks.
> 

You cannot source shell style in perl. You can write a perl file and
"require" it. 
In order to set variables for use in your main.pl script you could
declare the variables with some scope resolution

eg 
# /etc/cfg.pl
$config::X = 12;
$config::Y = 14;
@config::cols = qw ( red green blue );


# MAIN 

require "/etc/cfg.pl";

# You could use a local variable 
my $x = $config::X; 

# Or directly use the global variable
print "X = " . $config::X;






HTH
Ram




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




LWP::Simple use proxy

2004-10-25 Thread Ramprasad A Padmanabhan
Hi All,

I am using LWP::Simple;
I want use of proxy  to be enabled from the environment.

In LWP::UserAgent there is a method env_proxy by which I can do this.
How can I do a similar thing for LWP::Simple;

Thanks
Ram



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




Re: Can do in 1 while loop?

2004-10-11 Thread Ramprasad A Padmanabhan
On Mon, 2004-10-11 at 06:26, loan tran wrote:
> Hello Perl Gurus,
> 
> I wrote a script to search for log suspends and
> bloking processes in a text file and send me email if
> it find either of them. My codes below work but it's
> not efficent. As you can see I open the file and go to
> while loop twice. Can someone suggest a better way?
> Thanks.
> (attached is the text file i open to search.)
> Below is my codes:
> 
> #!/bin/perl -w
> require "/home/sybase/tranl/pl/global.pl";
> 
> ## Search for blocking process
> 
> open (FILE,"<$whodo_out") or die ("Cannot open file:
> $!");
> while (my $line =){
> chomp($line);
> $line =~ s/^\s+//;
> next if ($line =~ /^\D/);
> my $blk = substr($line,40,3);
> print " $blk \n";
> if ($blk != 0){
> print 'Alert! Blocking processes';
> system("/usr/bin/mailx -s 'Alert Blocking
> Process' $receipients < $whodo_out");
> }
> print "\n $suspend \n";
> #exit ;
> }#end while
> 
> close (FILE);
> 
> # Search for LOG SUSPEND process
> 
> open (FILE,"<$whodo_out") or die ("Cannot open file:
> $!");
> while (my $line =){
> chomp($line);
> $line =~ s/^\s+//;
> next if ($line =~ /^\D/);
> my $log_suspend = substr($line,70,11);
> print  "$log_suspend \n";
> if ($log_suspend eq 'LOG SUSPEND'){
> print 'Alert! LOG SUSPEND processes';
> system("/usr/bin/mailx -s 'Alert LOG SUSPEND
> Process' $receipients < $whodo_out");
> }
> 
> }#end while
> 
> close FILE;
> 
> ##



I am not able to get it ? 
Why cant you put This inside your first while loop 

  my $log_suspend = substr($line,70,11);
print  "$log_suspend \n";
if ($log_suspend eq 'LOG SUSPEND'){
print 'Alert! LOG SUSPEND processes';
system("/usr/bin/mailx -s 'Alert LOG SUSPEND
Process' $receipients < $whodo_out");
}




Probably after 
"print "\n $suspend \n";"


Bye
Ram



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




Re: Line replace

2004-10-11 Thread Ramprasad A Padmanabhan
On Mon, 2004-10-11 at 16:23, Urs Wagner wrote:
> Hello
> 
> I should comment out lines in a text file. I have a lot of troubles to 
> realize this.
> 
> The lines
> Alpha(a, b, c)
> should be changed to
> # Alpha(a, b, c)
> 


perl -pli.BAK -e 's/(?=.*Alpha\(a, b ,c\))/#/' FILENAME

HTH
Ram



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




Course material for perl training

2004-10-11 Thread Ramprasad A Padmanabhan
Sorry for being OT here

Is there any good course material for a perl crash course. I am supposed
to take training in perl and prepare a syllabus , with exercises

Thanks
Ram



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




X11::GUITest sendkeys with keycode ?

2004-10-07 Thread Ramprasad A Padmanabhan
Hi All,

  I came across this excellent module X11::GUITest , by which I can send
inputs to X applications. My problem is I am not able to send special
keys like HOME END etc

Is there a way by which I can sendkeys using the keycode

Thanks
Ram



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




perl regex to array

2004-10-04 Thread Ramprasad A Padmanabhan
Hi,

I have slightly a tricky situation, in my large program. I am trying the
best to reproduce it


  I have a string like this 
$x='a{1}b{21}c{5}d';
# The numbers in the {} are random and are not of interest

I want to access all elements from the string 'a' 'b' 'c' & 'd' 
How do I do it best ? 

I am now doing this

$x .='{0}';  # So that the next regex works

while($x=~/(.+?)\{\d+\}/){ 
   print $1;
   ...
}


Is there a better way
Thanks
Ram










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




How to set default text on Tk::Text

2004-09-30 Thread Ramprasad A Padmanabhan
I am creating a TK widget with a TK::Text textbox. 

I want to set the default text value as "hi" like this 

$txt = $mw->Text(
 # -data =>"hi",  # This does not work 
 -width => '10', 
   -height => '10')->pack;


But this is not working. Any clues ? 

Thanks
Ram



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




Re: Need help with script

2004-09-29 Thread Ramprasad A Padmanabhan
On Wed, 2004-09-29 at 18:55, PerlDiscuss - Perl Newsgroups and mailing
lists wrote:
> I have a file with the following format
> 
> Object1
> "Description1"
> 
> Object2
> "Description"
> 
> Object3
> "Description"
> 
> I would like the output in the following format
> object1<...tab>Description1
> object2<...tab>Description2
> object3<...tab>Description3
> 
> Thanks
> 

perl -lne 'BEGIN{$/="\n\n";}s/\n/\t/;print' FILENAME

HTH
Ram



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




Re: regex help

2004-09-23 Thread Ramprasad A Padmanabhan
On Fri, 2004-09-24 at 11:01, Johnstone, Colin wrote:
> Gidday all,
> 
> Im trying to write a regex to convert spaces to underscores and ampersands to 'and'  
> can someone help.
> 
> $safeString = "News & Events";
> $safeString =~ s/&/and/g;
> $safeString =~ s/\s/_/g;
> 
> Regards
> 
> Colin 
> 

What you have written is perfectly fine .. why do you think it will not
work ? 
you may consider however writing '\&' instead of '&' 

Bye
Ram




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




command line option with -ne to print newline

2004-09-17 Thread Ramprasad A Padmanabhan
Quick question,

  I want to run 
  
   perl -ane '/REMARKS/ && print $F[1]' FILE1 FILE2 

the problem is that there is no newline at the end of the every print.

so I have to do 

perl -ane '/REMARKS/ && print $F[1] . "\n"' FILE1 FILE2 

I thought there is a switch in perl by which I could auto print newlines
I am not able to find any ? 

Thanks
Ram





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




How to skip all tests while using CPAN

2004-09-14 Thread Ramprasad A Padmanabhan
I am installing some perlmodules using CPAN on commandline. Since I am
doing this on multiple machines of the same architecture , I want to
avoid "make tests" in CPAN , how can I do this ? 

Thanks
Ram



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




Re: SMTP

2004-09-13 Thread Ramprasad A Padmanabhan
On Mon, 2004-09-13 at 14:36, Anish Kumar K. wrote:
> HI
> 
> I am using Active PERL for WINDOWS. How will I know
> SMTP is Installed on the system...Can you suggest a small program for SMTP
> 
> Anish
> 

You can find if smtp is "running" very easily. Just make a connection to
smtp port ( port 25 ) if you are able to make this connection it is
running.

But if you want to find out if it is "installed" (it may be up or down )
It will be more difficult

Bye
Ram



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




gmail api

2004-09-02 Thread Ramprasad A Padmanabhan
I tried the gmail api to send/recv mail 
Mail::Webmail::Gmail
WWW::Scraper::Gmail
WWW::GMail
but all the three failed to make a connection. The problem I feel is
that I am behind a http proxy 

Thanks
Ram



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




Re: OT: VIM perl indentaton

2004-08-27 Thread Ramprasad A Padmanabhan
On Fri, 2004-08-27 at 18:14, Chris Devers wrote:
> On Fri, 27 Aug 2004, Ramprasad A Padmanabhan wrote:
> 
> > On Fri, 2004-08-27 at 17:53, Gavin Henry wrote:
> >> Hi all,
> >>
> >> Kind of a perl question, how do I get VIM to indent perl code?
> >
> > Use emacs :-)
> 
> Har har har
> 
> > Anyway on a serious note , I dont think there is any auto indent 
> > possible in vi. You will have to set tab value and hit tabs as many 
> > times you want to indent.
> 
> Fortunately, he specifically said "VIM", not Vi.
> 
> Vim is a very nice improvement over traditional Vi that can do, among a 
> great many other things, syntax highlighting and automatic indentation.
> 
> Gavin -- what happens if you just put
> 
>  set autoindent
> 
> in your ~/.vimrc ? Does that not work ?

No Doesnt work for me , I am using vim 6.2 on linux ( redhat AS 3 ).
Any clue ? 

Thanks
Ram





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




Re: OT: VIM perl indentaton

2004-08-27 Thread Ramprasad A Padmanabhan
On Fri, 2004-08-27 at 17:53, Gavin Henry wrote:
> Hi all,
> 
> Kind of a perl question, how do I get VIM to indent perl code?
> 
> 
> -- 
> Just getting into the best language ever...
> Fancy a [EMAIL PROTECTED] Just ask!!!

Use emacs :-)

Anyway on a serious note , I dont think there is any auto indent
possible in vi. You will have to set tab value and hit tabs as many
times you want to indent.

Ram



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




Re: how can I |more output.

2004-08-26 Thread Ramprasad A Padmanabhan
On Thu, 2004-08-26 at 13:26, Etienne Ledoux wrote:
> My program starts with a menu with options. That being one of the options to 
> choose from. Once it is done it returns to the main menu again so you can run 
> other options again. I would like to be able to do this within my program 
> somehow if possible. If not, I guess I could run it with |more from the 
> command line then.
> 

In that case you will have to build that intelligence in your code
for eg If you are printing all elements of an array @ARRAY.
Let us say you print 20 lines in a page and wait for "enter"


$|=1;  # to prevent buffering
my $PAGESIZE = 20;
foreach(@ARRAY){
  do_printing($_);
  if( $. % $PAGESIZE == 0){ 
   print "\nPress Enter to continue ";
   ;
   }
}
__END__



HTH 
Ram



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




Re: how can I |more output.

2004-08-26 Thread Ramprasad A Padmanabhan
On Thu, 2004-08-26 at 12:28, Etienne Ledoux wrote:
> Greetings,
> 
> I have a program that does a search on a db and prints the output to the 
> screen. If there is a lot of output how can I a stop/continue displaying it. 
> like 'ls -l |more' would do. or anything |more for that matter.
> 
> tx
> 
> e.

why not |more 

Ram



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




How to get contents of the clipboard

2004-08-17 Thread Ramprasad A Padmanabhan
Hi all,

  I am trying to write a perl script that requires the content of the
clipboard. Is there  a way I can do this?

  I am using Redhat AS 3 linux with a KDE desktop and Klipper

Thanks
Ram



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




Re: COMPLEX ARRAY STRUCTURE

2004-08-10 Thread Ramprasad A Padmanabhan
Luis Daniel Lucio Quiroz wrote:
You are wrong,
I need some more flexible, 

I dont know what attributes will be added, that's why I need array be coded on 
fly,with somthin like this

$result = $ldap->add( 'cn=Barbara Jensen, o=University of Michigan,
c=US', attr =>$attrs);
so $attrs array is formed on user commands
:-P
LD
 

Luis, You still dont have to access the object directly. 
if $attrs is an object created from the users input , so be it.

#Create a hash array of all user inputs. say
%hash = get_user_input();
# Have an array of all possible optional fields like
@ALL_FIELDS =  qw ( mail l ou o .) ;
# Create your attrs array
$attrs = {};
foreach (@ALL_FIELDS ) {
  if($hash{$_}) {
   $$attrs{$_}  = $hash{$_};   # Just make sure your input is trimmed 
for leading spaces  and lagging spaces or remove them here
 }
}

# Now  add this to your ldap entries
$result = $ldap->add( $dn, attr =>$attrs);
IMHO that is simpler than poking at the structure and neater
HTH
Ram

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



Re: COMPLEX ARRAY STRUCTURE

2004-08-09 Thread Ramprasad A Padmanabhan
This seems to be the result of a Net::LDAP search. I would suggest you
better read the perldoc for the module , there are methods to directly
give you the cn, sn etc from the entry. 

That way even if you upgrade the module and if the structure of the
object changes you wont have to change any of your code. Anyway If you
*really* want to use messy calls to the object directly you could do
this. 

To make it look less confusing you could just remove one level of a
reference like 

my %hash = @{$a};
now access the elements at will 

$sn = $hash{sn}# If you are sure there can only be one sn 

if(ref($hash{cn}) eq 'ARRAY') { 
   @listof_cn = @{$hash{cn}};
} else { 
  $cn = $hash{cn};
}


HTH
Ram

On Mon, 2004-08-09 at 06:19, Luis Daniel Lucio Quiroz wrote:
> Hi,
> 
> $a = [
> 'cn'   => ['Barbara Jensen', 'Barbs Jensen'],
> 'sn'   => 'Jensen',
> 'mail' => '[EMAIL PROTECTED]',
> 'objectclass' => ['top', 'person',
> 'organizationalPerson',
>'inetOrgPerson' ],
>];
> 
> 
> I have this arrary structure, how should I read it?  For example how do I 
> acces to "inetOrgPerson' value or Jesen value?
> 
> Thanks
> 
> LD



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




Perl oneliner to delete lines from a file

2004-08-08 Thread Ramprasad A Padmanabhan
I want to write a command line perl 'script'  to delete one or more 
lines from a file , by line number


for eg in sed I can do the same in two steps 
 
  cat FILENAME | sed -e '1,10d' >FILENAME.TMP
  mv FILENAME.TMP FILENAME

The above mechanism has a  lot of pitfalls , like maintaining
permissions , making sure FILENAME.TMP  does not already exist etc.
That is why I want to do it with "perl -i " 
but I dont want to write a full script for this , because  I am going to
run it on remote machines ( automated ) , and I cant ftp the script
everywhere

Any suggestions
Thanks
Ram 



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




Re: reading log files in real time

2004-07-27 Thread Ramprasad A Padmanabhan
On Tue, 2004-07-27 at 19:50, Wiggins d Anconia wrote:
> Please bottom post, this thread is unreadable.
> 
> > 
> > Ramprasad,
> > 
> > thanks for the heads up on File::Tail;
> > 
> > unfortunatley the module isn't installed and we have a very tight
> > restricttions on what we can install on production servers (banks are like
> > that!!!).
> > 
> 
> Sillieness (I know), but still silly.
> 
> > so I'm back needing to find a way to do it with the tell and seek
> commands,
> > 
> 
> perldoc -q tail
> perldoc -f select
> 
> There are also several modules in IO:: on CPAN or part of core that can
> help with this, particularly IO::Select. Generally the 4 argument form
> of 'select' will get you where you are going
> 
> Network Programming with Perl has excellent examples related to reading
> from sockets (though any filehandle works the same) on how to use select
> effectively.
> 
> Give it a shot and post more questions if you get stuck,
> 
> http://danconia.org
> 
> 
> 
> > 
> > On Mon, 2004-07-26 at 18:19, Adrian Farrell wrote:
> > > Hi,
> > >
> > > I'm looking for a way to read log files in real time, so that each
> time a
> > > new entry appears in the file I can perform a search/query (whatever
> > > really!) on it.
> > >
> > > it's odd really, as I expected this to be a very common scenario and yet
> > I
> > > can find nothing on it!
> > >
> > > I think there maybe some way to achieve this using the seek and tell
> > > commands but I can't quite fathom it out.
> > >
> > > any suggestions?
> > >
> > > thanks,
> > > Ad
> > >
> 
> 


I think you should use CPAN modules instead of reinventing the wheel.
You can either convince the admin to install the modules for you ( After
all there are no security issues with File::Tail )  , or you can do a
special install as a non-root user.

Thanks
Ram




> 



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




Re: reading log files in real time

2004-07-26 Thread Ramprasad A Padmanabhan
use File::Tail;

Ram

On Mon, 2004-07-26 at 18:19, Adrian Farrell wrote:
> Hi,
> 
> I'm looking for a way to read log files in real time, so that each time a
> new entry appears in the file I can perform a search/query (whatever
> really!) on it.
> 
> it's odd really, as I expected this to be a very common scenario and yet I
> can find nothing on it!
> 
> I think there maybe some way to achieve this using the seek and tell
> commands but I can't quite fathom it out.
> 
> any suggestions?
> 
> thanks,
> Ad
> 
> 
>   <>
> This message contains confidential information and is intended only for the
> named individual.  If you are not the named addressee, you should not
> disseminate, distribute or copy this e-mail. Please notify the sender
> immediately by e-mail if you have received this message in error and delete
> this e-message from your system.
> 
> E-mail transmission cannot be guaranteed to be secure or error-free as
> information could be intercepted, corrupted, lost, destroyed, delayed in
> transmission, incomplete, or may contain viruses. The sender therefore does
> not accept liability for any errors or omissions in the contents of
> this message which arise as a result of e-mail transmission.  If
> verification is required please request a hard-copy version. This message
> is provided for informational purposes and should not be construed as a
> solicitation or offer to buy or sell any securities or related financial
> instruments.
> 
> 


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




Re: a sed equivelent

2004-07-26 Thread Ramprasad A Padmanabhan
This should do your work, as long as your strings dont have any special
chars. 
perl -pli.BAK -e 's/OLDSTRING/NEWSTRING/g' FILENAME

(You can also use it for multiple files and will create a .BAK file
incase you want to revert )

HTH
Ram


On Mon, 2004-07-26 at 17:21, Jerry M. Howell II wrote:
> hello all,
> 
>I'm just beginning to work with sed in shell scripts I was wondering
> if anyone has a simmilar script in perl they can send my way or what the
> perl equivelent of the sed /s would be. Here is the coresponding shell
> script if it'll help you understand what I'm trying to acomplish.
> 
> #!/bin/sh
> 
> # Need some information from you
> 
> echo "what word or string are we looking for?"
> read old
> echo ""
> echo "what do you wish to replace it with"
> read new
> for script in * 
> do  
> sed 's/'$old'/'$new'/g' <$script> outfile
> mv outfile $script  
> done
> 
> sometimes this script works and sometimes it just clears the file out
> leaving it empty. I need a viable alternative but don't even know where
> to start. Thanks for any help you can give me.
> 
> -- 
> Jerry M. Howell II
> 
> email admin: usalug.org
> 
> sys admin:   hostbyk
> 


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




Re: Perl <-> Expect

2004-07-25 Thread Ramprasad A Padmanabhan
 I dont think the ssh option is always available to everyone. Most
times these  hosts are non linux machines, so they dont come with ssh
servers by default. Now If you dont have root access , you cant install
ssh servers. But good old telnet is always available. ( I am not
bothered about someone snooping in my internal network )

Coming to the actual question , If you want to run a specific task
everytime, you can write a Net::Telnet script. But if you want a script
to just do the login stuff for you, I dont know how you can do it.
Infact I tried some stuff by *auto typing* using X11::GUITest on to my
xterm, but that is too much of a pain

Thanks
Ram

On Thu, 2004-07-15 at 17:11, [EMAIL PROTECTED] wrote:
> Hi,
> 
> >I need to telnet some hosts automatically without supplying password.
> >I can do it with Expect but I hardly know the language.
> >I wonder what you think of the Perl module Expect - if it's any good and
> >easy to use.
> >Also if you can think of another way to do the job this will also be
> great.
> 
> I use ssh for lots of this type of stuff. Set up keys for authentication,
> then you have autologin.
> Depending on what you need after you get into the remote host, this could
> be a good option.
> 
> I guess that had nothing to do with Perl :(
> 
> hth
> jeff
> 
> >Thanks
> 
> _
> Help STOP SPAM with the new MSN 8 and get 2 months FREE*
> http://join.msn.com/?page=features/junkmail
> 
> 
> --
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>  
> 
> 
> 
> 
> 
> 
> 



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




Re: search and replace array variables contents

2004-07-20 Thread Ramprasad A Padmanabhan
On Tue, 2004-07-20 at 15:42, Baskaran wrote:
> Dear sir,
> 
> 
> I have two array variables. I want to find $a[1] and replace $b[1] in a
> file.
> ($a[1],$b[1] are array variables)
> How to find and replace the variable contents.
> 
> for ($i=0;$i<$totalnum;$i++){
> s/$a[i]/$b[i]/g;
> }
> 


You have almost got it

#!/usr/bin/perl


# These  are your  arrays

my @a = (  );
my @b = (  );

my $filecontent;
if(open(IN,"FILENAME")){
local($/)=undef;
 $filecontent = ;
 close IN;
} else { 
die "error opening file $!";
}

# Now do the substitue
for ($i=0;$i<@a;$i++){
  $filecontent =~ s/$a[i]/$b[i]/g;
}

# Write back to file
open(OUT,">FILENAME") || die "blah";
print OUT $filecontent;
close OUT;

#Bye



HTH
Ram



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




Re: search text

2004-07-15 Thread Ramprasad A Padmanabhan

On Thu, 2004-07-15 at 05:04, manojkumar vajram wrote:
> Plz. help me . I am new to perl
> I want to accept a pattern from screen
> and search the pattern in my one or two text data base
> and print the details
> 
> The pattern from screen may consist spaces and special
> char. line / - etc.
> I use redhat linux 8.0
> I have coded like below but fetched no result
> code-->
> system( "echo -en 'Enter Pattern :\c'");
> $pat = ;
> open (FILEONE,"file1");
> while(){
> if($pat=~$_){print $_;}
> close(FILEONE);
> open (FILETWO,"file2");
> while(){
> if($pat=~$_){print $_;)
> close(FILETWO);
> 
> end of code--->

I think , it will really help if you spend some time learning perl.
Learning Perl , etc from Oreilly is a great starter. Perl is the easiest
to learn language I have seen. 

Coming back to your problem , What you seem to be doing is a simple
grep. If you are not on windows , you could say 
grep PATTERN file1 file2 

If you really want to use perl , you can use a commandline like
perl -ne '/PATTERN/ && print'   

Doing it in a seperate perl script is also simple. Just be careful about
the matching Regular expression


HTH
Bye 
Ram





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




Re: Permutations (and optimisations)

2004-07-13 Thread Ramprasad A Padmanabhan
Good effort.
But I use *Algorithm::Permute* 


Thanks
Ram
Robin wrote:
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1
Hey, I have written a function that maybe others will find useful to play 
with. It takes a list and then calls a specified function on that list. I'm 
wondering if anyone knows of anything to optimise the code, as there are a 
few list copies going on that allocate/deallocate many times. Is this a 
problem, or is Perl pretty smart about it?

(to be clearer, given a list ('a','b','c') it will call the function many 
times, each time giving one of: ('a','b','c'), ('a','c','b), ('b','a','c'),
('b','c','a'), ('c','a','b') and ('c','b','a'). It also prints progress on 
stderr, but that is more for my own benefit)

It can be called with something like:
permute { push @result, [EMAIL PROTECTED] } @inputList;
if you want to build a list of all the results in @result.
The function is:
# This function takes a list of values, and calls a referenced
# function on each permutation of the list. The first argument is the
# function, the second is the list (there is a third argument used
# internally only.) Note that there are going to be a lot of
# combinations, n!, where n is the number of items in the list.
sub permute(&\@;\@) {
   my $func = shift();
   my @srcList = @{ shift() };
   my @dstList;
   if (@_) {
   @dstList = @{ shift() };
   }
   if (@srcList) {
   # Copy the srcList, pop an entry off the copy, recurse with that
   # appended to the dstList.
   my @srcCopy = @srcList;
   while (@srcCopy) {
   if ([EMAIL PROTECTED]) {
   print STDERR @srcCopy."/"[EMAIL PROTECTED]"\n";
   }
   my $value = pop(@srcCopy);
   # Make another copy of srcList, and remove only the one that
   # we are moving. This copy will be passed on to the next
   # iteration.
   my @srcCopy2 = @srcList;
   splice(@srcCopy2, scalar @srcCopy, 1);
   my @tList = (@dstList, $value);
   permute(\&$func, @srcCopy2, @tList);
   }
   } else {
   # base case
   &$func(@dstList);
   }
}
- -- 
Robin <[EMAIL PROTECTED]> JabberID: <[EMAIL PROTECTED]>

Hostes alienigeni me abduxerunt. Qui annus est?
PGP Key 0x776DB663 = DD10 5C62 1E29 A385 9866 0853 CD38 E07A 776D B663
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.2.4 (GNU/Linux)
iD8DBQFA88QJzTjgendttmMRAkCvAJ0Vsy9oPCCU0AQJngntWojFR4ZymQCcDrIQ
7+vi4wbRFzMrELWdipAZoQw=
=Xhei
-END PGP SIGNATURE-
 


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



Re: Executing scripts from different directories

2004-07-09 Thread Ramprasad A Padmanabhan
On Fri, 2004-07-09 at 11:14, sudhindra k s wrote:
>   
> Hi
> 
> I have two scripts abc.pl and xyz.pl. Now abc.pl uses xyz.pl. i have implemented 
> this as below.
> 
> abc.pl
> {
> 
> 
> system("perl xyz.pl arg1 arg2"); 
> ...
> }
> 
> Now both abc.pl and xyz.pl are in the same directory c:\test\script. But now i want 
> abc.pl in some different directory, but xyz.pl remains in c:\test\script. And the 
> location of abc.pl need not be fixed. So how do i implement this requirement?


you can do 
my $dir = "c:\\test\\script";
system("perl $dir\\xyz.pl arg1 arg2"); 

If in  case inside xyz.pl you are accessing some other files , just make
sure you give the full path. 


but consider using do() instead of system(). Because when you use
system() you create a new instance of perl in the memory which is
totally unnecessary.

Thanks
Ram


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




Re: Help with @INC

2004-07-05 Thread Ramprasad A Padmanabhan
I dont know how to 'restore' your old @INC. Infact I too had a similar
problem with multiple perl installations. What I did was set the
environment variables
PERLLIB
and PERL5LIB 
to whatever your old installation in @INC. I hope you will get that from
somewhere

Thanks
Ram

On Mon, 2004-07-05 at 03:19, Issa Mbodji wrote:
> I have installed Oracle which comes with an Apache server. Now I have it 
> disabled so that I can use my old Apache server that I had installed a 
> while ago. I am trying to use LWP::Simple which I intalled too a while 
> ago, but it is giving me the following error message. Any idea how to 
> restore the old @INC?
> 
> Can't locate LWP/Simple.pm in @INC (@INC contains: 
> C:\oracle\ora90\Apache\Perl\5.00503\lib/MSWin32-x86 
> C:\oracle\ora90\Apache\Perl\5.00503\lib 
> C:\oracle\ora90\Apache\Perl\site\5.00503\lib/MSWin32-x86 
> C:\oracle\ora90\Apache\Perl\site\5.00503\lib .) at 
> c:\apache\cgi-bin\TESTAC~1.PL line 6.
> 
> Thanks.
> 



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




Re: IO::Socket for http download

2004-07-02 Thread Ramprasad A Padmanabhan
On Thu, 2004-07-01 at 18:24, Ramprasad A Padmanabhan wrote:
> I want to write a basic http download ( text/binary) script using
> IO::Socket. Does anyone have any examples anywhere.


Thanks all,
I found a basic and excellent example. ( It pays to be patient when
using google)
http://perl.active-venture.com/pod/perlipc-tcpclient.html

Thanks
Ram



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




Re: IO::Socket for http download

2004-07-02 Thread Ramprasad A Padmanabhan

> LWP requires none of those tools. It does exactly what you are 
> describing: it opens a socket and uses the HTTP protocol to talk to the 
> server.
> 
> Randy.
> 

Right. Do you have any sample http client script , using IO::Socket
If I get some sample script , my work will be reduced a lot 


Thanks
Ram



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




IO::Socket for http download

2004-07-01 Thread Ramprasad A Padmanabhan
I want to write a basic http download ( text/binary) script using
IO::Socket. Does anyone have any examples anywhere.


I know ,everyone must be wondering why I cant use ready modules like
LWP.
Well I want to auto transfer files to different remote machines. and
these machines ( in all flavors of unix/linux ) dont have tools like
LWP/ftp/wget/lynx etc and I cant install these on the machines

So I plan to 
run Apache http on my machine with these files
run a telnet script from my machine, that will login to these machines
and 'write' a simple perl script and then run it from the remote machine
and download the necessary files

Any suggestions ? 

Thanks
Ramprasad



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




Re: Assigning a variable to hash keys and values

2004-06-29 Thread Ramprasad A Padmanabhan
On Tue, 2004-06-29 at 12:19, Daniel Falkenberg wrote:
> Hello All,
> 
> I currently have a hash of a hash...
> 
> > %HoH = (
> > Key1=> {
> > Apple => "Green",
> > Banna => "Yellow",
> > },
> > Key2=> {
> > Carrot=> "Orange",
> > Tomoatoe  => "Red",
> > },
> >  );
> 
> 
> How can I assign Key2 to a variable?

I think you mean the value of Key2 to a variable right ?
If you want a hash variable use 
%hash = %{$HoH{Key2}}

Of course this way the hash is *copied* into %hash and now changing
%hash does not affect the %HoH data

Bye
Ram



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




Re: How to email my results to a group of people....

2004-06-29 Thread Ramprasad A Padmanabhan
If you do want to use perl, you can use dozens of perl modules.
Learn MIME::Parser that will help you in lot of projects.

But to be frank , just for sending attachments you dont need to write a
perl script ( Though it is fairly simple ) . Just use mutt


mutt -a attachment.file -f fromid -s "SUBJECT" toid < content.file

HTH
ram


On Tue, 2004-06-29 at 04:10, jason corbett wrote:
> I have a script that is automated every morning. 
> I want to send this out to the team without logging onto the network and emailing 
> the file from a shell script that i also wrote like this:
>  
> 
> `mailx -s "Email Header" [EMAIL PROTECTED] < filename.txt`;
> 
>  
> 
> so, I hear PEAL has emailing (in attachment format) capabilities? I down-loaded the 
> module MIME::Lite, but I am not sure how to get this going. Can anyone help? Or is 
> there a better (or other) way?
> 
> Regards,
> 
> JC
> 



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




Net::Telnet set terminal

2004-06-28 Thread Ramprasad A Padmanabhan
I have a problem with Net::Telnet ( again ) 
When I connect to a united linux machine the server does not recognize
terminaltype 'network' and the connection just hangs.


Can I use telnet with a terminal type "vt100" in Net::Telnet

Thanks
Ram



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




  1   2   3   4   >