platform independant log

2005-03-16 Thread Nishi Prafull
Hi :
The following program needs to print the output of the cmd run to a
log file, it takes care of the directory separator issue, so the log
file could be created on any platform depending on where the program
is run.
But there is something missing ie the log file i am creating via this
program does not really get created after the program is done
execution. Does the file need to be physically present on the system?
can I create it on fly via the program.

#!/usr/local/bin/perl5.6 -w
#!/bin/tcsh

use strict;
use Cwd;
use File::Spec::Functions;

my $curdir = getcwd();
my $cmd1 = 'ls -l';
my $newlog = catfile(curdir(), $curdir, 'automate.log');
system("$cmd1 | tee -a $newlog") ;

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




Re: inplace editing

2005-03-16 Thread Chris Charley
- Original Message - 
From: "Hendrik Maryns" <[EMAIL PROTECTED]>
Newsgroups: perl.beginners
To: 
Sent: Wednesday, March 16, 2005 5:35 PM
Subject: inplace editing


Hi,
some time ago I asked for some help to eliminate certain lines from a 
file.  Someone suggested a solution with
{ local ( $^I, @ARGV ) = ( '', <*.log> );
For unix systems, I think you can do inplace editing w/out specifying an 
extension for a backup file, (and thus no backup is created). On a Windows 
machine, this is not the case. The line above would need to be be something 
like:

   { local ( $^I, @ARGV ) = ( '.bak', <*.log> );
Here, it would create a backup file of the original with the extension .bak.
now when I run this I get the error "Can't do inplace edit without backup 
at lexmorf_ruisweg2.pl line 12."

So I'm not sure that I understand what $^I does (I read about the -i 
switch), and I'm rather sure I don't understand what assigning <*.log> to 
@ARGV does.  If I get it right, the <> later on reads from <*.log>, but 
don't I have to open the files in some way first?
$^I does in a script what -i does on the command line. It tells perl that 
you are going to do inplace editing with some extension added as a suffix to 
your original file. <*.log> is the glob operator, and, in this instance, 
finds all files in the current working directory with an extension of .log 
and assigns them to @ARGV (so that when using the angle input operator in 
the while loop, it will get its files to edit from @ARGV). <> later on does 
not read from <*.log>, but from @ARGV.

Here's my code so far:
#! C:\Program Files\Perl\bin perl
use strict;
use warnings;
{ local ( $^I, @ARGV ) = ( '', <*.log> );
while ( <> ) {
s{\[\d+/\d+/\d+\s\d+:\d+\]\s}{}; #remove timestamp
next unless /^<.*>|^\*/; #remove information line
next if /^<.*>\s!/; #remove bot commands
s/\*(.*)\s/<$1> / if /^\*/;  #replace *nick with 
print;
}
}
__END__
The log files contain data of the following form:
[23/02/2005 19:20] =-= SnoopyD is now known as SnoopyDke
[23/02/2005 19:21]  in zen vel zekers als ze hem ni gestroopt 
hemme :p
[23/02/2005 19:21]  ej ma hebde da geleze van diene man die zijn 
ma zo had gestroopt ?
[23/02/2005 19:21]  en dan zo met da vel over hem rond liep ?
[23/02/2005 19:21]  i
[23/02/2005 19:21]  :p
[23/02/2005 19:22] -->| nutty ([EMAIL PROTECTED]) has 
joined #chat2chat
[23/02/2005 19:23] -->| magali ([EMAIL PROTECTED]) has 
joined #chat2chat
[23/02/2005 19:23]  eh SnoopyDke :p
[23/02/2005 19:23]  hebde da geleze
[23/02/2005 19:23]  :p
[23/02/2005 19:23]  !sex Pietje
[23/02/2005 19:23]  lieveke- sleurt Pietje eens mee de bosjes in 
om er donder en bliksem mee te maken...*rr*

Thanks for any help, H.
--
Hendrik Maryns
Interesting websites:
www.lieverleven.be (I cooperate)
www.eu04.com European Referendum Campaign
aouw.org The Art Of Urban Warfare

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



Re: inplace editing

2005-03-16 Thread Jeff 'japhy' Pinyan
On Mar 16, Hendrik Maryns said:
some time ago I asked for some help to eliminate certain lines from a file. 
Someone suggested a solution with
{ local ( $^I, @ARGV ) = ( '', <*.log> );

now when I run this I get the error "Can't do inplace edit without backup at 
lexmorf_ruisweg2.pl line 12."
Windows doesn't let you do in-place editing without making a backup file. 
Therefore, $^I can't be "".  Make it ".bak", and you'll be fine.

--
Jeff "japhy" Pinyan %  How can we ever be the sold short or
RPI Acacia Brother #734 %  the cheated, we who for every service
http://japhy.perlmonk.org/  %  have long ago been overpaid?
http://www.perlmonks.org/   %-- Meister Eckhart
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



RE : build perl modules

2005-03-16 Thread Jose Nyimi


> -Message d'origine-
> De : Charles K. Clarkson [mailto:[EMAIL PROTECTED]
> Envoyé : mercredi 16 mars 2005 19:27
> À : beginners@perl.org
> Objet : RE: build perl modules
> 
> What you are describing is called "exporting" (or "importing" --
> depending on how you look at it.). There is a module which probably
> came with your perl distribution. It is named Exporter.pm and it will
> ease building modules like the one you describe. Read its
> documentation for more details.
> 
> 
> Let's begin writing our new module with a subroutine we will
> probably rarely use, but hate to have to rewrite each time we need
> it. The truth is, it is not hard to write, just hard to remember.
> 
> sub Identity {
> return @_;
> }
> 
> Wow. That's a long one. We are now ready to create the module.
> 
> package SpecialSubs;
> 
> sub Identity {
> return @_;
> }
> 
> 1;
> 
> This module is all we really need. Create a file like this
> and name it "SpecialSubs.pm". Come back when your done. The "1;" at
> the end is very important. It is needed on all modules.
> 
> =
> 
> Okay, you're back. Now let's create a script in our favorite
> editor and run it.
> 
> #!/usr/bin/perl
> 
> use strict;
> use warnings;
> 
> use SpecialSubs;
> 
> print SpecialSubs::Identity( 'foo' );
> 
> __END__
> 
> 
> Prefixing every sub with "SpecialSubs::" could get old quick.
> When we "use" a module a series of events occur. One of those events
> is running a subroutine named "import" if it is present.
> 
> Let's go back to the module and add an "import" sub
> 
> package SpecialSubs;
> 
> sub import {
>   print "This is the import sub running automatically\n";;
> }
> 
> 
> sub Identity {
> return  @_;
> }
> 
> 1;
> 
> We'll also change our script.
> 
> #!/usr/bin/perl
> 
> use strict;
> use warnings;
> 
> use SpecialSubs;
> 
> __END__
> 
> Run this and you'll see that the import sub is called
> automatically. We can use the import sub to "import"
> subroutines into your script.
> 
> 
> The caller() function from perl will tell us the details
> about how this module was called.
> 
> package SpecialSubs;
> 
> sub import {
> my( $name_space, $script, $line_number ) = caller();
> printf qq(%s "use"d by %s on line %s in package "%s".\n),
> 'SpecialSubs::import()',
> $script,
> $line_number,
> $name_space;
> }
> 
> 
> sub Identity {
> return  @_;
> }
> 
> 1;
> 
> Running our script now reveals which package has called
> SpecialSubs.pm. We can get just the name space of the caller
> with this.
> 
> package SpecialSubs;
> 
> sub import {
> my $name_space = caller();
> print $name_space;
> }
> 
> 
> sub Identity {
> return  @_;
> }
> 
> 1;
> 
> Knowing the name space of the caller, we can import items
> into it's name space. We need to use symbolic references here.
> Usually, new perl programmers should avoid symbolic references.
> 
> package SpecialSubs;
> 
> sub import {
> my $caller = caller();
> *{$caller . '::Identity'} = \&Identity;
> }
> 
> 
> sub Identity {
> return  @_;
> }
> 
> 1;
> 
> If there were 100 subs in the module this could get a
> little long and sometimes we need more control. For example,
> we might need just two subs and are now stuck with 98 subs we
> don't need. We also didn't do any error checking.
> 
> Exporter.pm comes to the rescue. Using this module to
> build our modules makes life more simple.
> 
> 
> package SpecialSubs;
> 
> require Exporter;
> @ISA = qw(Exporter);
> 
> @EXPORT_OK = qw( Identity );
> 
> sub Identity {
> return  @_;
> }
> 
> 1;
> 
> 
> 
> #!/usr/bin/perl
> 
> use strict;
> use warnings;
> 
> use SpecialSubs qw( Identity );
> 
> print Identity( 'foo' );
> 
> __END__
> 
> 
> If you'd rather use strict and warnings in the module
> you'll need this.
> 
> package SpecialSubs;
> 
> use strict;
> use warnings;
> 
> use vars qw( @ISA @EXPORT_OK );
> 
> require Exporter;
> @ISA = qw(Exporter);
> 
> @EXPORT_OK = qw( Identity );
> 
> sub Identity {
> return  @_;
> }
> 
> 1;
> 
> 
> OR:
> 
> package SpecialSubs;
> 
> use strict;
> use warnings;
> 
> our( qw( @ISA @EXPORT_OK ) );
> 
> require Exporter;
> @ISA = qw(Exporter);
> 
> @EXPORT_OK = qw( Identity );
> 
> sub Identity {
> return  @_;
> }
> 
> 1;
> 
> 
> HTH,
> 
> Charles K. Clarkson
> --
> Mobile Homes Specialist
> 254 968-8328

+1
Nicely explained ;)

Someone who want to avoid writing inheritance (@ISA) from Exporter,
can write something like:

package SpecialSubs;

use strict;
use warnings;
use UNIVERSAL::exports;

@EXPORT_OK = qw( Identity );

sub Identity {
return  @_;
}

1;

for more info, see:
http://search.cpan.org/~mschwern/UNIVERSAL-exports-0.03


José.



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




inplace editing

2005-03-16 Thread Hendrik Maryns
Hi,
some time ago I asked for some help to eliminate certain lines from a 
file.  Someone suggested a solution with
{ local ( $^I, @ARGV ) = ( '', <*.log> );

now when I run this I get the error "Can't do inplace edit without 
backup at lexmorf_ruisweg2.pl line 12."

So I'm not sure that I understand what $^I does (I read about the -i 
switch), and I'm rather sure I don't understand what assigning <*.log> 
to @ARGV does.  If I get it right, the <> later on reads from <*.log>, 
but don't I have to open the files in some way first?

Here's my code so far:
#! C:\Program Files\Perl\bin perl
use strict;
use warnings;
{ local ( $^I, @ARGV ) = ( '', <*.log> ); 
while ( <> ) {
s{\[\d+/\d+/\d+\s\d+:\d+\]\s}{}; #remove timestamp
next unless /^<.*>|^\*/;  #remove information line
next if /^<.*>\s!/;   #remove bot commands
s/\*(.*)\s/<$1> / if /^\*/;  #replace *nick with 
print;
}
}
__END__
The log files contain data of the following form:
[23/02/2005 19:20] =-= SnoopyD is now known as SnoopyDke
[23/02/2005 19:21]  in zen vel zekers als ze hem ni gestroopt 
hemme :p
[23/02/2005 19:21]  ej ma hebde da geleze van diene man die 
zijn ma zo had gestroopt ?
[23/02/2005 19:21]  en dan zo met da vel over hem rond liep ?
[23/02/2005 19:21]  i
[23/02/2005 19:21]  :p
[23/02/2005 19:22] -->| nutty ([EMAIL PROTECTED]) has 
joined #chat2chat
[23/02/2005 19:23] -->| magali ([EMAIL PROTECTED]) has 
joined #chat2chat
[23/02/2005 19:23]  eh SnoopyDke :p
[23/02/2005 19:23]  hebde da geleze
[23/02/2005 19:23]  :p
[23/02/2005 19:23]  !sex Pietje
[23/02/2005 19:23]  lieveke- sleurt Pietje eens mee de bosjes 
in om er donder en bliksem mee te maken...*rr*

Thanks for any help, H.
--
Hendrik Maryns
Interesting websites:
www.lieverleven.be  (I cooperate)
www.eu04.comEuropean Referendum Campaign
aouw.orgThe Art Of Urban Warfare
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



Re: log output

2005-03-16 Thread Nishi Prafull
I just tried using the tctee program as follows:

#!/usr/local/bin/perl5.6 -w
use strict;

my $logFile ='/automateLabelPush.log'; //line 5
my $tee_cmd = '/tctee.pl';
my $cmd1 = qq{ };
system("$cmd1 | $tee_cmd -a $logFile") ;

at the end of the execution, I still get
sh: syntax error at line 5: "|" unexpected 


On Wed, 16 Mar 2005 16:14:06 -0500 (EST), Chris Devers
<[EMAIL PROTECTED]> wrote:
> On Wed, 16 Mar 2005, Paul Ohashi wrote:
> 
> > I can't see enough to determine why your script is failing, but
> > the four lines below work as expected:
> >
> > #!/usr/local/bin/perl
> > $logFile = '/home/paulo/mylog.log';
> > $myCmd = 'ls -l';
> > system ("$myCmd | tee -a $logFile");
> >
> > Hope this helps...
> 
> Is there some reason that everyone has latched onto the system `tee`
> command rather than doing this in Perl?
> 
> The "tctee" program shown in _Perl Cookbook_ (either edition) shows how
> to do this directly in Perl. The program in question can be downloaded
> from the book's site (click on "examples")  --
> 
> 
> 
> 
>  -- or from this Sourceforge page --
> 
> 
> 
> There's no clear reason to prefer an external program to do this job.
> 
> --
> Chris Devers
>

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




Re: Math::BigInt

2005-03-16 Thread JupiterHost.Net
my $x = Math::BigFloat->new(2);
Math::BigFloat->precision(5);   # 5 digits max
my $y = $x->copy()->bdiv(3);   # will give 0.6

print Dumper $y;
The docs says "will give 0.6" so how does one get $y to give you that?
That is what I can't seem to find and the Dump of $y doesn't seem to
contain any part of the answer...

I'm not sure where in the docs you found the Data::Dumper hint, but
it's probably not what you want.
I was just doing that to see what $y is :) since I can't get the result 
from bdiv, IE "will give 0.6" but how do you get 0.6 from it?

What are you trying to do here?  Do you really need Math::BigFloat? 
wholenumber / wholenumber = whatever
Do you need to specify precision for the calculations, or just for the
output? and are you looking for the result to be truncared (0.6)
the two numbers being divided will always be whole numbers, so just for 
the output.

I have the sprintf idea up to 14 decimals with plain perl, but what if I 
want

1/3 up to 50 decimal places?
or rounded (0.7)?  Based on what you've shown us so far, I'd say
your best bet would be:
   my $x = 2;
   my $y = $x/3;
   printf "%.7s\n", $y;   # truncated
   # printf "%.5f\n', $y   # rounded
You can control your precision by storing your variables with sprintf,
too, if you need to.  If you realy need Math::BigFloat, see if
accuracy() and bround() will do what you need, e.g.:
   $y->bround(5) ;
Ok, but how do I get 0.33 from 1/3 into a 
variable :)

print $y->bround(5) and any other function just prints "inf",
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



Re: Sending mail from perl with content having hyperlink

2005-03-16 Thread Wiggins d'Anconia
Nilay Puri, Noida wrote:
Hi All,
I want to send mail thru perl.
And the content is supposed to have hyperlink.
Just one word lke, "FAQ" is supposed to have link to some url.
I am trying like this, but I am not getting hyperlink on word FAQ.
Can any one help here ?
Thank You.
sub send_mail
{
  my ($to_email, $subject, $message) = @_;
open(MAIL, "|/bin/mailx -t");
print MAIL <<"EOM";
To: $to_email
from: [EMAIL PROTECTED]
Subject: $subject
EOM
  print MAIL "\n$message\n";
  print MAIL "\n For questions about OnTrac,please contact Product
Information or review our http://pubsys.pearsoned.com/groups/product_information/OnTrac/ontrac_f
aq.html">FAQ" ;
 \n" ;
  close MAIL;
  return 0;
}
You have not set a proper mime/type for the email client to recognize 
that the message is HTML, assuming it can. This is only one of the 
problems with sending mail in this manner, 1. as HTML, 2. as a piped in 
message on the command line.

If you are going to send HTMLized e-mail, then do it properly.  If you 
are going to do it properly, you are definitely going to want to use a 
module that will do it properly for you.  There are lots of them 
available.  And you will most likely need to read tutorials on how to 
send HTML mail.

http://danconia.org
[snip annoying pointless disclaimer]
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



Sending mail from perl with content having hyperlink

2005-03-16 Thread Nilay Puri, Noida
Hi All,

I want to send mail thru perl.
And the content is supposed to have hyperlink.
Just one word lke, "FAQ" is supposed to have link to some url.

I am trying like this, but I am not getting hyperlink on word FAQ.

Can any one help here ?

Thank You.


sub send_mail
{
  my ($to_email, $subject, $message) = @_;

open(MAIL, "|/bin/mailx -t");
print MAIL <<"EOM";
To: $to_email
from: [EMAIL PROTECTED]
Subject: $subject
EOM
  print MAIL "\n$message\n";
  print MAIL "\n For questions about OnTrac,please contact Product
Information or review our http://pubsys.pearsoned.com/groups/product_information/OnTrac/ontrac_f
aq.html">FAQ" ;
 \n" ;
  close MAIL;
  return 0;
}


Disclaimer: 

This message and any attachment(s) contained here are information that is
confidential,proprietary to HCL Technologies and its customers, privileged
or otherwise protected by law.The information is solely intended for the
individual or the entity it is addressed to. If you are not the intended
recipient of this message, you are not authorized to read, forward,
print,retain, copy or disseminate this message or any part of it. If you
have received this e-mail in error, please notify the sender immediately by
return e-mail and delete it from your computer.



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




Re: Math::BigInt

2005-03-16 Thread Jay Savage
On Wed, 16 Mar 2005 13:39:34 -0600, JupiterHost.Net
<[EMAIL PROTECTED]> wrote:
> Hello,
> 
> My goal is to divide two whole numbers and get the results to a given
> number of decimals.

[cut]

> #!/usr/bin/perl
> 
> use strict;
> use warnings;
> use Math::BigFloat;
> use Data::Dumper;

[cut]

> my $x = Math::BigFloat->new(2);
> Math::BigFloat->precision(5);   # 5 digits max
> my $y = $x->copy()->bdiv(3);   # will give 0.6

> print Dumper $y;
> 
> The docs says "will give 0.6" so how does one get $y to give you that?
> 
> That is what I can't seem to find and the Dump of $y doesn't seem to
> contain any part of the answer...
> 

I'm not sure where in the docs you found the Data::Dumper hint, but
it's probably not what you want.

What are you trying to do here?  Do you really need Math::BigFloat? 
Do you need to specify precision for the calculations, or just for the
output? and are you looking for the result to be truncared (0.6)
or rounded (0.7)?  Based on what you've shown us so far, I'd say
your best bet would be:

   my $x = 2;
   my $y = $x/3;
   printf "%.7s\n", $y;   # truncated
   # printf "%.5f\n', $y   # rounded

You can control your precision by storing your variables with sprintf,
too, if you need to.  If you realy need Math::BigFloat, see if
accuracy() and bround() will do what you need, e.g.:

   $y->bround(5) ;

HTH,

--jay

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




RE: log output

2005-03-16 Thread Chris Devers
On Wed, 16 Mar 2005, Paul Ohashi wrote:

> I can't see enough to determine why your script is failing, but
> the four lines below work as expected:
> 
> #!/usr/local/bin/perl
> $logFile = '/home/paulo/mylog.log';
> $myCmd = 'ls -l';
> system ("$myCmd | tee -a $logFile");
> 
> Hope this helps...

Is there some reason that everyone has latched onto the system `tee` 
command rather than doing this in Perl?

The "tctee" program shown in _Perl Cookbook_ (either edition) shows how 
to do this directly in Perl. The program in question can be downloaded 
from the book's site (click on "examples")  --




 -- or from this Sourceforge page --



There's no clear reason to prefer an external program to do this job.



-- 
Chris Devers

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




RE: log output

2005-03-16 Thread Paul Ohashi
I can't see enough to determine why your script is failing, but
the four lines below work as expected:

#!/usr/local/bin/perl
$logFile = '/home/paulo/mylog.log';
$myCmd = 'ls -l';
system ("$myCmd | tee -a $logFile");

Hope this helps...
Paul


-Original Message-
From: Nishi Prafull [mailto:[EMAIL PROTECTED]
Sent: Wednesday, March 16, 2005 12:02 PM
To: Paul Ohashi
Cc: beginners@perl.org
Subject: Re: log output


I tried this 
system("$cmd1 | tee -a $logFile") ;
but I get 
sh: syntax error at line 5: `|' unexpected

where line 5 is the line in which I declare the var for the output log

my $logFile ="/automateLabelPush.log";

On Wed, 16 Mar 2005 10:59:31 -0800, Paul Ohashi <[EMAIL PROTECTED]> wrote:
> What if you piped your system command to tee, like:
> 
> system("$cmd1 | tee -a outfile.log") ;
> 
> 
> -Original Message-
> From: Nishi Prafull [mailto:[EMAIL PROTECTED]
> Sent: Wednesday, March 16, 2005 10:55 AM
> To: beginners@perl.org
> Subject: log output
> 
> Hi:
> I am running a perl script as part of a cron job and I want to log the
> execution of the script(for sucess, failure).
> In my script, I make calls to external software on the machine to run
> certain tasks.
> How can I direct the output of these tasks to a local log on my
> machine during the execution of the script as part of the cron job.
> 
> #!/usr/local/bin/perl5.6 -w
> 
> use strict;
> my $label = "SOME_" ;
> my $emd = "dcat.emd";
> my $cmd1 = qq{ ade useview atview -exec 'ade label_product \\
>-l $label -config_spec_file dcat.cs \\
>-output_emd $emd -prod dc' -exec 'intg -t ADE:push \\
> -l $label --ADE_EMD $emd --ADE_New_Series 1'
>   };
> system($cmd1) ;
> 
> --
> 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]
>  
> 
>

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




Re: Math::BigInt

2005-03-16 Thread JupiterHost.Net

Peter Rabbitson wrote:
AFAIK perl will handle up to 15 (14 to be exact) precision without any 
helpers like Math::BigFloat. Then you just use sprintf ('%.Xf', $var) where 
X is the precision you want. Keep in mind that standard rounding is enforced 
(.4 - .5 as breakpoint)
Thanks Peter I think I will use that instead, unless someone can help me 
decifer what Math::BigFloat is doing :)

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



Re: Math::BigInt

2005-03-16 Thread Peter Rabbitson
AFAIK perl will handle up to 15 (14 to be exact) precision without any 
helpers like Math::BigFloat. Then you just use sprintf ('%.Xf', $var) where 
X is the precision you want. Keep in mind that standard rounding is enforced 
(.4 - .5 as breakpoint)

Peter


> Hello,
> 
> My goal is to divide two whole numbers and get the results to a given 
> number of decimals.
> 
> $ perl -e 'print 2/3,"\n";'
> 0.667
> $
> 
> #!/usr/bin/perl
> 
> use strict;
> use warnings;
> use Math::BigFloat;
> use Data::Dumper;
> 

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




Re: log output

2005-03-16 Thread Nishi Prafull
I tried this 
system("$cmd1 | tee -a $logFile") ;
but I get 
sh: syntax error at line 5: `|' unexpected

where line 5 is the line in which I declare the var for the output log

my $logFile ="/automateLabelPush.log";

On Wed, 16 Mar 2005 10:59:31 -0800, Paul Ohashi <[EMAIL PROTECTED]> wrote:
> What if you piped your system command to tee, like:
> 
> system("$cmd1 | tee -a outfile.log") ;
> 
> 
> -Original Message-
> From: Nishi Prafull [mailto:[EMAIL PROTECTED]
> Sent: Wednesday, March 16, 2005 10:55 AM
> To: beginners@perl.org
> Subject: log output
> 
> Hi:
> I am running a perl script as part of a cron job and I want to log the
> execution of the script(for sucess, failure).
> In my script, I make calls to external software on the machine to run
> certain tasks.
> How can I direct the output of these tasks to a local log on my
> machine during the execution of the script as part of the cron job.
> 
> #!/usr/local/bin/perl5.6 -w
> 
> use strict;
> my $label = "SOME_" ;
> my $emd = "dcat.emd";
> my $cmd1 = qq{ ade useview atview -exec 'ade label_product \\
>-l $label -config_spec_file dcat.cs \\
>-output_emd $emd -prod dc' -exec 'intg -t ADE:push \\
> -l $label --ADE_EMD $emd --ADE_New_Series 1'
>   };
> system($cmd1) ;
> 
> --
> 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]
>  
> 
>

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




Math::BigInt

2005-03-16 Thread JupiterHost.Net
Hello,
My goal is to divide two whole numbers and get the results to a given 
number of decimals.

$ perl -e 'print 2/3,"\n";'
0.667
$
#!/usr/bin/perl
use strict;
use warnings;
use Math::BigFloat;
use Data::Dumper;
# from 
http://search.cpan.org/~tels/Math-BigInt-1.74/lib/Math/BigFloat.pm with 
my() added,
# my $x = Math::BigFloat->new(11);

my $x = Math::BigFloat->new(2);
Math::BigFloat->precision(5);   # 5 digits max
my $y = $x->copy()->bdiv(3);   # will give 0.6
# $ perl -e 'print 2/3,"\n";'
# 0.667
# $
print Dumper $y;
The docs says "will give 0.6" so how does one get $y to give you that?
That is what I can't seem to find and the Dump of $y doesn't seem to 
contain any part of the answer...

TIA

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



Re: [PBML] Query about perl modules

2005-03-16 Thread Dave Gray
> blade:~/personal/perl > cat -n check.p
>  1  #!/usr/bin/perl
>  2
>  3  use Net::Telnet;
>  4
>  5  $timeout = 10;
>  6  $obj=new Net::Telnet( [Timeout => $timeout,] );
>  7
> blade:~/personal/perl > perl check.p
> unknown remote host: ARRAY(0x22494) at check.p line 6
> blade:~/personal/perl >

[Timeout => $timeout.] creates an array reference, which when printed
out, in your case gave 'ARRAY(0x22494)'. If you check the docs for
Net::Telnet[1], I think you'll find the answer to your problem in the
first example.

[1] 

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




RE: log output

2005-03-16 Thread Paul Ohashi
What if you piped your system command to tee, like:

system("$cmd1 | tee -a outfile.log") ;


-Original Message-
From: Nishi Prafull [mailto:[EMAIL PROTECTED]
Sent: Wednesday, March 16, 2005 10:55 AM
To: beginners@perl.org
Subject: log output


Hi:
I am running a perl script as part of a cron job and I want to log the
execution of the script(for sucess, failure).
In my script, I make calls to external software on the machine to run
certain tasks.
How can I direct the output of these tasks to a local log on my
machine during the execution of the script as part of the cron job.

#!/usr/local/bin/perl5.6 -w

use strict;
my $label = "SOME_" ;
my $emd = "dcat.emd";
my $cmd1 = qq{ ade useview atview -exec 'ade label_product \\
-l $label -config_spec_file dcat.cs \\
-output_emd $emd -prod dc' -exec 'intg -t ADE:push \\
 -l $label --ADE_EMD $emd --ADE_New_Series 1' 
   };
system($cmd1) ;

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




log output

2005-03-16 Thread Nishi Prafull
Hi:
I am running a perl script as part of a cron job and I want to log the
execution of the script(for sucess, failure).
In my script, I make calls to external software on the machine to run
certain tasks.
How can I direct the output of these tasks to a local log on my
machine during the execution of the script as part of the cron job.

#!/usr/local/bin/perl5.6 -w

use strict;
my $label = "SOME_" ;
my $emd = "dcat.emd";
my $cmd1 = qq{ ade useview atview -exec 'ade label_product \\
-l $label -config_spec_file dcat.cs \\
-output_emd $emd -prod dc' -exec 'intg -t ADE:push \\
 -l $label --ADE_EMD $emd --ADE_New_Series 1' 
   };
system($cmd1) ;

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




RE: build perl modules

2005-03-16 Thread Charles K. Clarkson
Mahantesh Hongal  wrote:
: 
: Just I want to place all my subs (functions) in one file i.e., module
: and want to refer as and when it is needed. I can use 'require' for
: this purpose but in require technique code will be included at
: runtime and even if our script is working fine and the sub function
: which we are including through require is having error and then whole
: script will be stopped. So, I want code in such a way that which will
: run indipended of the modules (subs). 

What you are describing is called "exporting" (or "importing" --
depending on how you look at it.). There is a module which probably
came with your perl distribution. It is named Exporter.pm and it will
ease building modules like the one you describe. Read its
documentation for more details.


Let's begin writing our new module with a subroutine we will
probably rarely use, but hate to have to rewrite each time we need
it. The truth is, it is not hard to write, just hard to remember.

sub Identity {
return @_;
}

Wow. That's a long one. We are now ready to create the module.

package SpecialSubs;

sub Identity {
return @_;
}

1;

This module is all we really need. Create a file like this
and name it "SpecialSubs.pm". Come back when your done. The "1;" at
the end is very important. It is needed on all modules.

=

Okay, you're back. Now let's create a script in our favorite
editor and run it.

#!/usr/bin/perl

use strict;
use warnings;

use SpecialSubs;

print SpecialSubs::Identity( 'foo' );

__END__


Prefixing every sub with "SpecialSubs::" could get old quick.
When we "use" a module a series of events occur. One of those events
is running a subroutine named "import" if it is present.

Let's go back to the module and add an "import" sub

package SpecialSubs;

sub import {
print "This is the import sub running automatically\n";;
}


sub Identity {
return  @_;
}

1;

We'll also change our script.

#!/usr/bin/perl

use strict;
use warnings;

use SpecialSubs;

__END__

Run this and you'll see that the import sub is called
automatically. We can use the import sub to "import"
subroutines into your script.


The caller() function from perl will tell us the details
about how this module was called.

package SpecialSubs;

sub import {
my( $name_space, $script, $line_number ) = caller();
printf qq(%s "use"d by %s on line %s in package "%s".\n),
'SpecialSubs::import()',
$script,
$line_number,
$name_space;
}


sub Identity {
return  @_;
}

1;

Running our script now reveals which package has called
SpecialSubs.pm. We can get just the name space of the caller
with this.

package SpecialSubs;

sub import {
my $name_space = caller();
print $name_space;
}


sub Identity {
return  @_;
}

1;

Knowing the name space of the caller, we can import items
into it's name space. We need to use symbolic references here.
Usually, new perl programmers should avoid symbolic references.

package SpecialSubs;

sub import {
my $caller = caller();
*{$caller . '::Identity'} = \&Identity;
}


sub Identity {
return  @_;
}

1;

If there were 100 subs in the module this could get a
little long and sometimes we need more control. For example,
we might need just two subs and are now stuck with 98 subs we
don't need. We also didn't do any error checking.

Exporter.pm comes to the rescue. Using this module to
build our modules makes life more simple.


package SpecialSubs;

require Exporter;
@ISA = qw(Exporter);

@EXPORT_OK = qw( Identity );

sub Identity {
return  @_;
}

1;



#!/usr/bin/perl

use strict;
use warnings;

use SpecialSubs qw( Identity );

print Identity( 'foo' );

__END__


If you'd rather use strict and warnings in the module
you'll need this.

package SpecialSubs;

use strict;
use warnings;

use vars qw( @ISA @EXPORT_OK );

require Exporter;
@ISA = qw(Exporter);

@EXPORT_OK = qw( Identity );

sub Identity {
return  @_;
}

1;


OR:

package SpecialSubs;

use strict;
use warnings;

our( qw( @ISA @EXPORT_OK ) );

require Exporter;
@ISA = qw(Exporter);

@EXPORT_OK = qw( Identity );

sub Identity {
return  @_;
}

1;


HTH,

Charles K. Clarkson
-- 
Mobile Homes Specialist
254 968-8328























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




Re: Simple HASH query

2005-03-16 Thread Jenda Krynicky
From: SG Edwards <[EMAIL PROTECTED]>
> I am using bioperl to get the primary id of a protein out of a flat
> file as follows:
> 
> 
> while ($seq_obj = $seqio_obj->next_seq){
> my $primary_id = $seq_obj->primary_id;
> print $primary_id;
> }
> 
> exit;
> 
> However, this returns:
> 
> Bio::Seq::RichSeq=HASH(0xa1a1b7c)
> 
> How do I get the actual value I want out of the hash?

Try to 

use Data::Dumper;
print Dumper($primary_id);

and maybe also

print Dumper($seq_obj);

maybe the $seq_obj is not the class you think it is.

Jenda
= [EMAIL PROTECTED] === http://Jenda.Krynicky.cz =
When it comes to wine, women and song, wizards are allowed 
to get drunk and croon as much as they like.
-- Terry Pratchett in Sourcery


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




Re: Question on Arrays

2005-03-16 Thread Robert
This was one of those "your moron" moments where I posted, then tried 
something, and the something worked.  : )

Robert 



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




Re: build perl modules

2005-03-16 Thread Mahantesh Hongal

"Charles K. Clarkson" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> Mahantesh Hongal  wrote:
>
> : Can anybody let me know how to create our own modules in perl.
>
> What would you like to place inside the modules? You can
> limit yourself to just subs or you can add data, methods, and
> objects. What is your intended end use of this module?
>
>
> HTH,
>
> Charles K. Clarkson
> -- 
> Mobile Homes Specialist
> 254 968-8328
>

Just I want to place all my subs (functions) in one file i.e., module and
want to refer as and when it is needed. I can use 'require' for this purpose
but in require technique code will be included at runtime and even if our
script is working fine and the sub function which we are including through
require is having error and then whole script will be stopped. So, I want
code in such a way that which will run indipended of the modules (subs).



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




RE: Perl Analyzing Maillog

2005-03-16 Thread Charles K. Clarkson
Nick Chettle  wrote:

: I am not 100% sure what this line does.
: 
: push @{ $msgids->{$1} }, $_;
: 
: Is the @{} surrounding the hash used to make push work with a hash?

No. We cannot push items onto a hash. We need an array for
that. "$msgids->{$1}" is an array reference. It refers to an
array reference inside a hash which is, in turn, referenced by
a hash reference ("$msgids").

"$msgids->{$1}" is an array reference. The "@{}" allows us
to de-reference the reference. As you may recall, an array is a
list of items.

my @animals = ( 'cat', 'dog' );



Sometimes it is more convenient to use a scalar variable than
an array variable.

my $animals_ref = [EMAIL PROTECTED];

In fact, we don't really need the original array. We can create
the reference and operate on just it. We use "[]" to define an array
without a name.

my $animals_ref = [ 'cat', 'dog' ];


To add an item to the end of an array, we use "push".

my @animals = ( 'cat', 'dog' );
push @animals, 'horse';

my $animals_ref = [ 'cat', 'dog' ];
push @{ $animals_ref }, 'horse';

We could have pushed everything onto the array.

my @animals;
push @animals, 'cat';
push @animals, 'dog';
push @animals, 'horse';

my $animals_ref;
push @{ $animals_ref }, 'cat';
push @{ $animals_ref }, 'dog';
push @{ $animals_ref }, 'horse';

my $msgids;
push @{ $msgids->{Fred} }, 1005;
push @{ $msgids->{Fred} }, 1058;
push @{ $msgids->{Fred} }, 2587;





In the example above, there exists a reference to a hash named
"$msgids". Autovivification allows the hash to add keys when a new
one is used. So, if $1 is a new key it will be added to the hash,
otherwise we will use an existing key.

Since $msgids is a reference hash of arrays. But hashes can
only contain scalar values, you say. No problem, the arrays we
store in the hash are actually array references.

So technically, $msgids is a reference to a hash of array
references. Pretty complicated, huh? Read perlref for an intro
to perl data structures.


: Also, why do you need ->

Because the author chose to use a hash reference to a hash.

my $msgids;
while () {
 if (/$email/) {
 if (/([A-Z1-9]{8})/) {
 push @{ $msgids->{$1} }, $_;
}
 }
}

: and can't just do $msgids{$1}, $_; ?

my %msgids;
while () {
 if (/$email/) {
 if (/([A-Z1-9]{8})/) {
 push @{ $msgids{$1} }, $_;
}
 }
}



 
: I made a slight change to make your addition work in that I added ()
: around the regex so that $1 would work - is there any reason to use
: this over $&?
: 
: So, AFAICS, your addition creates a hash (Using the message id's as
: the key) and puts the associated line from the log in the hash. So I
: thought I could simply do:
: 
: for (sort keys %msgids) {
:  print $msgids{$_};
: }
:
: To print each line found. For some reason this returns nothing.


You didn't turn on strict or warnings. There is no %msgids.
You would get all sorts of warnings otherwise. This should work.

#!/usr/bin/perl

use strict;
use warnings;

print "Please enter an e-mail address: ";
chomp( my $email =  );

my $file = '/var/log/maillog';
open MAILLOG, $file or die qq(Cannot open "$file": $!);

my %msgids;
while () {
 if (/$email/) {
 if (/([A-Z1-9]{8})/) {
 push @{ $msgids->{$1} }, $_;
}
 }
}

close MAILLOG;

foreach my $key (sort keys %{ $msgids } ) {
print $msgids->{ $key };
}

__END__

OR:

#!/usr/bin/perl

use strict;
use warnings;

print "Please enter an e-mail address: ";
chomp( my $email =  );

my $file = '/var/log/maillog';
open MAILLOG, $file or die qq(Cannot open "$file": $!);

my %msgids;
while () {
 if (/$email/) {
 if (/([A-Z1-9]{8})/) {
 push @{ $msgids{$1} }, $_;
}
 }
}

close MAILLOG;

foreach my $key (sort keys %msgids) {
print $msgids{ $key };
}

__END__


HTH,

Charles K. Clarkson
-- 
Mobile Homes Specialist
254 968-8328



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




Simple HASH query

2005-03-16 Thread SG Edwards
Hi,

I am using bioperl to get the primary id of a protein out of a flat file as
follows:


while ($seq_obj = $seqio_obj->next_seq){
my $primary_id = $seq_obj->primary_id;
print $primary_id;
}

exit;

However, this returns:

Bio::Seq::RichSeq=HASH(0xa1a1b7c)

How do I get the actual value I want out of the hash?

Thanks

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




Re: Perl Analyzing Maillog

2005-03-16 Thread mgoland


- Original Message -
From: Nick Chettle <[EMAIL PROTECTED]>
Date: Wednesday, March 16, 2005 10:01 am
Subject: Re: Perl Analyzing Maillog

> Hi, Thanks, that seems a far better way to do it. A few things though:
> 
> I am not 100% sure what this line does.
$msgids is a referance to a hash, this hash is a referance to an array. So you 
are adding an array elemant to a-bit fancy data structur.
> 
> push @{ $msgids->{$1} }, $_;
> 
> Is the @{} surrounding the hash used to make push work with a 
> hash? 
yes, because you need to specify what type of a variable $msgids->{$1} is [ 
it's an array ref ].

> Also, why do you need -> and can't just do $msgids{$1}, $_; ?

. '->' means a referance, so here it's just a referance to a hash  

> 
> I made a slight change to make your addition work in that I added ()
> around the regex so that $1 would work - is there any reason to 
> use this 
> over $&?

not sure, my personal preferance I guess.

> 
> So, AFAICS, your addition creates a hash (Using the message id's 
> as the 
> key) and puts the associated line from the log in the hash. So I 
> thought 
> I could simply do:
> 
> for (sort keys %msgids) {
> print $msgids{$_};
> }
> 
> To print each line found. For some reason this returns nothing.
That is because $msgids is not a hash, it's a referance to a hash. I thought 
you where using strictures ?? Try this

  for (sort keys %{ $msgids } ) {
 print "Key = $_\n";
 print "Hash Value: ", join ":",$msgids->{$_},"\n";
 print "Array contains\n", join "\n",@{$msgids->{$_}};
 }

> 
> Thanks for your help. Hope my questions aren't too simple!
> 
> Nick
> 
> [EMAIL PROTECTED] wrote:
> > 
> > - Original Message -
> > From: Nick Chettle <[EMAIL PROTECTED]>
> > Date: Wednesday, March 16, 2005 7:02 am
> > Subject: Perl Analyzing Maillog
> > 
> > 
> >>Hi All,
> > 
> > Hello,
> > 
> > 
> >>I am trying to write a simple script that will analyze a Postfix 
> >>maillog. The basic idea is that you give it an e-mail address 
> and 
> >>it 
> >>will print all the relevant lines. In order to achieve this, you 
> >>first 
> >>need a message ID, you can then search for the id and bring all 
> >>the 
> >>relevant information.
> >>
> >>This is what I have so far:
> >>
> >>#!/usr/bin/perl
> >>
> >>print "Please enter an e-mail address: ";
> >>chomp($email = );
> >>
> >>open MAILLOG, "/var/log/maillog";
> >>
> >>while () {
> >>if (/$email/) {
> >>if (/[A-Z1-9]{8}/) {
> >>$msgids[$_] = $&;
> >>}
> >>}
> >>}
> >>
> >>This works fine and it builds an array of all the message id's. 
> I 
> >>now 
> >>need an efficient way of searching through the log again and 
> >>pulling out 
> >>all lines that contain a message id.
> > 
> >You are already doing it, why not keep the results first time 
> around ?? One was it to create a Ref to Hash Ref of Array's [ I 
> prefer this, others may simply do a HoA ]
> > 
> > while () {
> >  if (/$email/) {
> >  if (/[A-Z1-9]{8}/) {
> >  push @{ $msgids->{$1} }, $_;
> > }
> >  }
> > }
> > 
> > 
> > 
> > 
> >>I can do this with:
> >>
> >>for (@msgids) {
> >>  system "cat /var/log/maillog | grep $_";
> >>}
> >>
> >>But it's certainly not a very Perl way of doing it and it's less 
> >>than 
> >>efficient as I have to cat the entire maillog  for each message id.
> >>
> >>I've been trying to open the filehandle again and then somehow 
> get 
> >>foreach to go through it but haven't had much sucess. Can anyone 
> >>advise 
> >>if I'm looking along the right lines or if there is a better way 
> >>of 
> >>doing it?
> >>
> >>Thanks, Nick
> >>
> >>-- 
> >>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: build perl modules

2005-03-16 Thread Wiggins d'Anconia
Peter Scott wrote:
On Wed, 16 Mar 2005 08:54:33 -0500, Steve Bertrand wrote: 

Can anybody let me know how to create our own modules in perl.
Another good book is _Learning Perl Objects, References and Modules_,
Schwartz and Phoenix.  I've owned the book for almost a year, and I
still refer to it all the time.
I second this book wholeheartedly. Google is also a very good starting
point.

Also "Creating Perl Modules for CPAN", by Tregar.
(I think this may have already been mentioned here but if not) it was 
just opened for free download.

http://www.apress.com/free/index.html
I agree about each mentioned.
http://danconia.org
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



Re: build perl modules

2005-03-16 Thread Peter Scott
On Wed, 16 Mar 2005 08:54:33 -0500, Steve Bertrand wrote: 
 Can anybody let me know how to create our own modules in perl.
>> Another good book is _Learning Perl Objects, References and Modules_,
>>  Schwartz and Phoenix.  I've owned the book for almost a year, and I
>> still refer to it all the time.
> 
> I second this book wholeheartedly. Google is also a very good starting
> point.

Also "Creating Perl Modules for CPAN", by Tregar.

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


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




Re: Perl Analyzing Maillog

2005-03-16 Thread Zeus Odin
"Nick Chettle" <[EMAIL PROTECTED]> wrote in message ...
> Hi All,

Hi, Nick.

> #!/usr/bin/perl

This is a very good start. Never forget:

  use warnings;
  use strict;

These are two of the most important lines in the script :-)
If you had used these simple two lines, you would have found a major problem 
with your script. You are using an entire line of text as an index for an 
array. That doesn't make sense.

The line:

  $msgids[$_] = $&;

attempts to use the entire line contained in the variable $_ as an index for 
the array @msgids. Also, it is more efficient to capture want you want by 
using parentheses in your reg exp and subsequently use $1 instead of $&. Not 
a huge deal but worth noting.

> print "Please enter an e-mail address: ";
> chomp($email = );
>
> open MAILLOG, "/var/log/maillog";
>
> while () {
> if (/$email/) {
> if (/[A-Z1-9]{8}/) {
> $msgids[$_] = $&;
> }
> }
> }

Again this is a great start. You definitely don't want to use an array, you 
should use a hash instead. This should solve your delimma.

I am unfamiliar with the format of the Postfix mail log. However, you have 
two choices, you can make the key of your hash the email address or the 
message id. I am assuming that the message id is unique for each message. I 
also assume that the email address is not. Both are good assumptions I hope.

BEGIN CODE
#!/usr/bin/perl
use warnings;
use strict;
use Data::Dumper;

print "Please enter an e-mail address: ";
chomp(my $email = );
open MAILLOG, "/var/log/maillog";

my %msgids;
# If you want to record only one email address, uncomment
# the next 5 lines
#while () {
#  if ( my($addr) = /($email)/ and my($id) = /([A-Z1-9]{8})/ ) {
#$msgids{$addr}{$id} = $_;
#  }
#}

# If you want to record all email addresses with the ability
# to go back and look at other email addresses
while () {
  # It is almost impossible to accurately match all valid
  # email addresses. The next line is a very poor attempt. Apologies.
  # See Jeffrey Friedl's "Mastering Regular Expressions" for more info.
  if ( my($addr) = /([\w.&[EMAIL PROTECTED])/ and my($id) = /([A-Z1-9]{8})/ ) {
$msgids{$addr}{$id} = $_;
  }
}

foreach my $id(keys %{ $msgids{$email} }) {
  print $msgids{$email}{$id};
}
print "\n" x 3;
print Dumper \%msgids;
-END CODE-

Please note that if your mail log file is huge, it might take a signicant 
amount of time and memory to add all of its lines to the %msgids hash. You 
have been warned.

Good luck,
ZO 



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




Re: Perl Analyzing Maillog

2005-03-16 Thread Nick Chettle
Hi, Thanks, that seems a far better way to do it. A few things though:
I am not 100% sure what this line does.
push @{ $msgids->{$1} }, $_;
Is the @{} surrounding the hash used to make push work with a hash? 
Also, why do you need -> and can't just do $msgids{$1}, $_; ?

I made a slight change to make your addition work in that I added ()
around the regex so that $1 would work - is there any reason to use this 
over $&?

So, AFAICS, your addition creates a hash (Using the message id's as the 
key) and puts the associated line from the log in the hash. So I thought 
I could simply do:

for (sort keys %msgids) {
print $msgids{$_};
}
To print each line found. For some reason this returns nothing.
Thanks for your help. Hope my questions aren't too simple!
Nick
[EMAIL PROTECTED] wrote:
- Original Message -
From: Nick Chettle <[EMAIL PROTECTED]>
Date: Wednesday, March 16, 2005 7:02 am
Subject: Perl Analyzing Maillog

Hi All,
Hello,

I am trying to write a simple script that will analyze a Postfix 
maillog. The basic idea is that you give it an e-mail address and 
it 
will print all the relevant lines. In order to achieve this, you 
first 
need a message ID, you can then search for the id and bring all 
the 
relevant information.

This is what I have so far:
#!/usr/bin/perl
print "Please enter an e-mail address: ";
chomp($email = );
open MAILLOG, "/var/log/maillog";
while () {
   if (/$email/) {
   if (/[A-Z1-9]{8}/) {
   $msgids[$_] = $&;
   }
   }
}
This works fine and it builds an array of all the message id's. I 
now 
need an efficient way of searching through the log again and 
pulling out 
all lines that contain a message id.
   You are already doing it, why not keep the results first time around ?? 
One was it to create a Ref to Hash Ref of Array's [ I prefer this, others may 
simply do a HoA ]
while () {
 if (/$email/) {
 if (/[A-Z1-9]{8}/) {
 push @{ $msgids->{$1} }, $_;
}
 }
}



I can do this with:
for (@msgids) {
 system "cat /var/log/maillog | grep $_";
}
But it's certainly not a very Perl way of doing it and it's less 
than 
efficient as I have to cat the entire maillog  for each message id.

I've been trying to open the filehandle again and then somehow get 
foreach to go through it but haven't had much sucess. Can anyone 
advise 
if I'm looking along the right lines or if there is a better way 
of 
doing it?

Thanks, Nick
--
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: build perl modules

2005-03-16 Thread Charles K. Clarkson
Mahantesh Hongal  wrote:

: Can anybody let me know how to create our own modules in perl.

What would you like to place inside the modules? You can
limit yourself to just subs or you can add data, methods, and
objects. What is your intended end use of this module?


HTH,

Charles K. Clarkson
-- 
Mobile Homes Specialist
254 968-8328


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




Re: Perl Analyzing Maillog

2005-03-16 Thread mgoland


- Original Message -
From: Nick Chettle <[EMAIL PROTECTED]>
Date: Wednesday, March 16, 2005 7:02 am
Subject: Perl Analyzing Maillog

> Hi All,
Hello,

> 
> I am trying to write a simple script that will analyze a Postfix 
> maillog. The basic idea is that you give it an e-mail address and 
> it 
> will print all the relevant lines. In order to achieve this, you 
> first 
> need a message ID, you can then search for the id and bring all 
> the 
> relevant information.
> 
> This is what I have so far:
> 
> #!/usr/bin/perl
> 
> print "Please enter an e-mail address: ";
> chomp($email = );
> 
> open MAILLOG, "/var/log/maillog";
> 
> while () {
> if (/$email/) {
> if (/[A-Z1-9]{8}/) {
> $msgids[$_] = $&;
> }
> }
> }
> 
> This works fine and it builds an array of all the message id's. I 
> now 
> need an efficient way of searching through the log again and 
> pulling out 
> all lines that contain a message id.
   You are already doing it, why not keep the results first time around ?? One 
was it to create a Ref to Hash Ref of Array's [ I prefer this, others may 
simply do a HoA ]

while () {
 if (/$email/) {
 if (/[A-Z1-9]{8}/) {
 push @{ $msgids->{$1} }, $_;
}
 }
}



> 
> I can do this with:
> 
> for (@msgids) {
>   system "cat /var/log/maillog | grep $_";
> }
> 
> But it's certainly not a very Perl way of doing it and it's less 
> than 
> efficient as I have to cat the entire maillog  for each message id.
> 
> I've been trying to open the filehandle again and then somehow get 
> foreach to go through it but haven't had much sucess. Can anyone 
> advise 
> if I'm looking along the right lines or if there is a better way 
> of 
> doing it?
> 
> Thanks, Nick
> 
> -- 
> 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: build perl modules

2005-03-16 Thread Steve Bertrand

>>> Can anybody let me know how to create our own modules in perl.
>>>
>>
>> Yes.
>>
>>
>> (Hint, try Google, try introductory books (_Learning Perl_), try
>> advanced books (_Object-Oriented Perl_), try examining other
>> modules.)
>>
>
> Another good book is _Learning Perl Objects, References and Modules_,
>  Schwartz and Phoenix.  I've owned the book for almost a year, and I
> still refer to it all the time.

I second this book wholeheartedly. Google is also a very good starting
point.

Steve



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




instaling MySQL

2005-03-16 Thread Octavian Rasnita
Hi,

Please tell me what could mean the following errors I get when trying to
install  DBD::mysql for MySQL 4.1.1 under Fedora Core 2.

I am fighting for a day to install DBD::mysql, but without success. I have
also tried to install it by downloading the tar ball and compiling, but with
no luck.

Help!

Thank you.

Teddy

dbdimp.c:2144: error: dereferencing pointer to incomplete type
dbdimp.c:2146: error: dereferencing pointer to incomplete type
dbdimp.c:2148: error: dereferencing pointer to incomplete type
dbdimp.c:2153: error: dereferencing pointer to incomplete type
dbdimp.c:2160: error: dereferencing pointer to incomplete type
dbdimp.c:2165: error: dereferencing pointer to incomplete type
dbdimp.c:2170: error: dereferencing pointer to incomplete type
dbdimp.c:2172: error: dereferencing pointer to incomplete type
dbdimp.c:2174: error: dereferencing pointer to incomplete type
dbdimp.c:2179: error: dereferencing pointer to incomplete type
dbdimp.c: In function `mysql_bind_ph':
dbdimp.c:2242: error: dereferencing pointer to incomplete type
dbdimp.c:2254: error: dereferencing pointer to incomplete type
dbdimp.c: In function `mysql_db_reconnect':
dbdimp.c:2273: error: `MYSQL' undeclared (first use in this function)
dbdimp.c:2273: error: syntax error before "save_socket"
dbdimp.c:2282: error: dereferencing pointer to incomplete type
dbdimp.c:2282: error: `CR_SERVER_GONE_ERROR' undeclared (first use in this
function)
dbdimp.c:2287: error: dereferencing pointer to incomplete type
dbdimp.c:2287: error: dereferencing pointer to incomplete type
dbdimp.c:2300: error: `save_socket' undeclared (first use in this function)
dbdimp.c:2300: error: dereferencing pointer to incomplete type
dbdimp.c:2301: error: dereferencing pointer to incomplete type
dbdimp.c:2302: error: dereferencing pointer to incomplete type
dbdimp.c:2302: error: dereferencing pointer to incomplete type
dbdimp.c:2302: error: dereferencing pointer to incomplete type
dbdimp.c:2302: error: dereferencing pointer to incomplete type
dbdimp.c:2302: error: dereferencing pointer to incomplete type
dbdimp.c:2302: error: dereferencing pointer to incomplete type
dbdimp.c:2302: error: dereferencing pointer to incomplete type
dbdimp.c:2302: error: dereferencing pointer to incomplete type
dbdimp.c:2302: error: dereferencing pointer to incomplete type
dbdimp.c:2302: error: dereferencing pointer to incomplete type
dbdimp.c:2305: error: dereferencing pointer to incomplete type
dbdimp.c:2305: error: dereferencing pointer to incomplete type
dbdimp.c:2305: warning: passing arg 3 of `mysql_dr_error' makes pointer from
integer without a cast
dbdimp.c:2306: error: dereferencing pointer to incomplete type
dbdimp.c:2307: error: dereferencing pointer to incomplete type
dbdimp.c:2310: error: dereferencing pointer to incomplete type
dbdimp.c: In function `mysql_db_quote':
dbdimp.c:2446: error: dereferencing pointer to incomplete type
make: *** [dbdimp.o] Error 1
  /usr/bin/make  -- NOT OK
Running make test
  Can't test without successful make
Running make install
  make had returned bad status, install seems impossible
cpan>

Teddy


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




Re: build perl modules

2005-03-16 Thread Nicholas . Montpetit
Chris Devers <[EMAIL PROTECTED]> wrote on 03/16/2005 06:27:42 AM:

> On Wed, 16 Mar 2005, Mahantesh Hongal wrote:
> 
> > Can anybody let me know how to create our own modules in perl.
> 
> Yes.
> 
> (Hint, try Google, try introductory books (_Learning Perl_), try 
> advanced books (_Object-Oriented Perl_), try examining other modules.)
> 

Another good book is _Learning Perl Objects, References and Modules_, 
Schwartz and Phoenix.  I've owned the book for almost a year, and I still 
refer to it all the time. 

RE: build perl modules

2005-03-16 Thread Moon, John
Hi,

Can anybody let me know how to create our own modules in perl.



Thanks in advance...

Mahantesh V H


The simple answer is:

Create a file for the "sub" and save as a ".pm"...

To include it in you main program...

use lib "where/you/saved/the/sub";
use sub_you_saved;
&sub_use_saved;

That should get you started...

There is more discussed in the Camel book and:

http://search.cpan.org/dist/perl/pod/perlsub.pod

http://search.cpan.org/dist/perl/pod/perlmod.pod


jwm

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




Re: build perl modules

2005-03-16 Thread Chris Devers
On Wed, 16 Mar 2005, Mahantesh Hongal wrote:

> Can anybody let me know how to create our own modules in perl.

Yes.

(Hint, try Google, try introductory books (_Learning Perl_), try 
advanced books (_Object-Oriented Perl_), try examining other modules.)

 

-- 
Chris Devers

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




RE: Question on Arrays

2005-03-16 Thread Moon, John
@districts = qw/ elldev elldev2 icedev prodev /;

$app = "M:\\Path\\app.exe ";

foreach $dist ( @districts ) {
print $app, $dist,"\n";  # modifying this to a system call like 
system( $app, $dist );
}

I am going to change the print statement above with a system one so that 
$app will run with the @districts one after another. What I would like to do

is add a print statement before each one runs like:

NOW UPDATING ELLDEV...

NOW UPDATING ELLDEV2...

etc. for each district...

How would I go about that?


Looks like you have already done it... 

Print "Now updating <$dist>\n";

jwm

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




Perl Analyzing Maillog

2005-03-16 Thread Nick Chettle
Hi All,
I am trying to write a simple script that will analyze a Postfix 
maillog. The basic idea is that you give it an e-mail address and it 
will print all the relevant lines. In order to achieve this, you first 
need a message ID, you can then search for the id and bring all the 
relevant information.

This is what I have so far:
#!/usr/bin/perl
print "Please enter an e-mail address: ";
chomp($email = );
open MAILLOG, "/var/log/maillog";
while () {
if (/$email/) {
if (/[A-Z1-9]{8}/) {
$msgids[$_] = $&;
}
}
}
This works fine and it builds an array of all the message id's. I now 
need an efficient way of searching through the log again and pulling out 
all lines that contain a message id.

I can do this with:
for (@msgids) {
  system "cat /var/log/maillog | grep $_";
}
But it's certainly not a very Perl way of doing it and it's less than 
efficient as I have to cat the entire maillog  for each message id.

I've been trying to open the filehandle again and then somehow get 
foreach to go through it but haven't had much sucess. Can anyone advise 
if I'm looking along the right lines or if there is a better way of 
doing it?

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



build perl modules

2005-03-16 Thread Mahantesh Hongal
Hi,

Can anybody let me know how to create our own modules in perl.



Thanks in advance...

Mahantesh V H



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




Question on Arrays

2005-03-16 Thread Robert
@districts = qw/ elldev elldev2 icedev prodev /;

$app = "M:\\Path\\app.exe ";

foreach $dist ( @districts ) {
print $app, $dist,"\n";  # modifying this to a system call like 
system( $app, $dist );
}

I am going to change the print statement above with a system one so that 
$app will run with the @districts one after another. What I would like to do 
is add a print statement before each one runs like:

NOW UPDATING ELLDEV...

NOW UPDATING ELLDEV2...

etc. for each district...

How would I go about that?

Robert 



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