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: I think I need another regex...

2005-03-17 Thread Renqilong
Got it!Thanks a lot,John!

On Thu, 17 Mar 2005 20:38:21 -0800
"John W. Krahn" <[EMAIL PROTECTED]> wrote:

> Renqilong wrote:
> > On Thu, 17 Mar 2005 12:55:02 -0800
> > "John W. Krahn" <[EMAIL PROTECTED]> wrote:
> > 
> >>Chris Knipe wrote:
> >>
> >>>I tried to do this with split(), but it's not working good at all
> >>>
> >>>The string:
> >>>interface=something very long with spaces and all 
> >>>mac-address=00:02:6F:36:2D:31 ap=no wds=no rx-rate=11Mbps tx-rate=11Mbps 
> >>>packets=12623,18377 bytes=10829240,2009327 frames=12623,18377
> >>>(the above is one line, wrapped for email).
> >>>
> >>>I need to grab the values for all the options
> >>
> >>$ perl -le'
> >>use Data::Dumper;
> >>my $string = q/interface=something very long with spaces and all 
> >>mac-address=00:02:6F:36:2D:31 ap=no wds=no rx-rate=11Mbps tx-rate=11Mbps 
> >>packets=12623,18377 bytes=10829240,2009327 frames=12623,18377/;
> >>my %hash = $string =~ /(\S+)=([^=]+)(?:\s+|$)/g; 
> > 
> > => would you kindly explain how this (?:\s+|$) works?
> 
> Sure.  (?:) are non-capturing parentheses so the pattern inside will not be
> returned in list context like normal capturing parentheses.  The pattern says
> to match EITHER \s+ (one or more whitespace characters) OR $ (the end of the
> line.)
> 
> 
> John
> -- 
> use Perl;
> program
> fulfillment
> 
> -- 
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>  
> 
> 
> 


-- 
Whatever you do will be insignificant,but 
the important is you do it!

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




Re: I think I need another regex...

2005-03-17 Thread John W. Krahn
Renqilong wrote:
On Thu, 17 Mar 2005 12:55:02 -0800
"John W. Krahn" <[EMAIL PROTECTED]> wrote:
Chris Knipe wrote:
I tried to do this with split(), but it's not working good at all
The string:
interface=something very long with spaces and all 
mac-address=00:02:6F:36:2D:31 ap=no wds=no rx-rate=11Mbps tx-rate=11Mbps 
packets=12623,18377 bytes=10829240,2009327 frames=12623,18377
(the above is one line, wrapped for email).

I need to grab the values for all the options
$ perl -le'
use Data::Dumper;
my $string = q/interface=something very long with spaces and all 
mac-address=00:02:6F:36:2D:31 ap=no wds=no rx-rate=11Mbps tx-rate=11Mbps 
packets=12623,18377 bytes=10829240,2009327 frames=12623,18377/;
my %hash = $string =~ /(\S+)=([^=]+)(?:\s+|$)/g; 
=> would you kindly explain how this (?:\s+|$) works?
Sure.  (?:) are non-capturing parentheses so the pattern inside will not be
returned in list context like normal capturing parentheses.  The pattern says
to match EITHER \s+ (one or more whitespace characters) OR $ (the end of the
line.)
John
--
use Perl;
program
fulfillment
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



Re: I think I need another regex...

2005-03-17 Thread Renqilong
On Thu, 17 Mar 2005 12:55:02 -0800
"John W. Krahn" <[EMAIL PROTECTED]> wrote:

> Chris Knipe wrote:
> > Lo all,
> 
> Hello,
> 
> > I tried to do this with split(), but it's not working good at all
> > 
> > The string:
> > interface=something very long with spaces and all 
> > mac-address=00:02:6F:36:2D:31 ap=no wds=no rx-rate=11Mbps tx-rate=11Mbps 
> > packets=12623,18377 bytes=10829240,2009327 frames=12623,18377
> > (the above is one line, wrapped for email).
> > 
> > 
> > I need to grab the values for all the options
> 
> $ perl -le'
> use Data::Dumper;
> my $string = q/interface=something very long with spaces and all 
> mac-address=00:02:6F:36:2D:31 ap=no wds=no rx-rate=11Mbps tx-rate=11Mbps 
> packets=12623,18377 bytes=10829240,2009327 frames=12623,18377/;
> my %hash = $string =~ /(\S+)=([^=]+)(?:\s+|$)/g; 

=> would you kindly explain how this (?:\s+|$) works?

> print Dumper \%hash;
> '
> $VAR1 = {
>'bytes' => '10829240,2009327',
>'mac-address' => '00:02:6F:36:2D:31',
>'packets' => '12623,18377',
>'frames' => '12623,18377',
>'wds' => 'no',
>'interface' => 'something very long with spaces and all',
>'rx-rate' => '11Mbps',
>'ap' => 'no',
>'tx-rate' => '11Mbps'
>  };
> 
> 
> 
> John
> -- 
> use Perl;
> program
> fulfillment
> 
> -- 
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>  
> 
> 
> 


-- 
Whatever you do will be insignificant,but 
the important is you do it!

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




RE: Use of uninitialized value

2005-03-17 Thread Charles K. Clarkson
[EMAIL PROTECTED]  wrote:
 
: The idiom I use every single day:
: 
: #!/usr/bin/perl
: 
: use strict;
: use warnings;
: use diagnostics;

My idiom, which is used a lot for testing code on
various beginner lists, is this. I never did care for the
verbose output of diagnostics.pm.

#!/usr/bin/perl

use strict;
use warnings;

#use Data::Dumper 'Dumper';
#use CGI;

__END__


 I also have a few editor macros on hand like this one
for file opening.

CTRL+ALT+F:

my $file = '';
open FH, $file or die qq(Cannot open "$file": $!);

close FH;


HTH,

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


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




Re: ActivePerl repositories

2005-03-17 Thread Jenda Krynicky
From: Peter Rabbitson <[EMAIL PROTECTED]>
> I have a general question concerning module availability for
> ActiveState Perl. I asked on this list several month ago where to get
> the DateTime suite modules, and somebody pointed me to a certain
> repository at the University of Winnipeg. Now I am in need of
> HTTP::Cookies and instead being pinpointed to a certain place I would
> like to know is there a general routine for finding modules listed on
> CPAN but not available through ppm? Or is it that the win32 perl
> community does not have a centralized network like cpan and it is
> pretty much up to the good will of someone to compile a certain module
> and and serve it from a local server?

ActiveStates do have an automated process downloading and compiling 
CPAN modules, but of course they can't have everything and they don't 
have the manpower to handle all problems for all modules that do not 
build out of the box. So the rest depends on the goodwill of various 
developers and their own repositories. Much smaller than the 
ActiveState one, but filling in the gaps.

There is a module PPM::Repositories on CPAN and the ActiveState 
repository that contains the addresses of the "known" repositories 
and allows you to add them to the list kept by PPM. Fetch it, install 
it, read the docs, add the repositories :-)

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: Use of uninitialized value

2005-03-17 Thread Lawrence Statton
> Hi all.
> if ($value) {
> if ($value eq "some_value_to_compare_to") {
># stuff
> } else {
># other stuff
> }
> } else {
># same as other stuff above
> }
> 
> But this makes things look overly complicated, increases the size of my 
> code, and I assume slows things down because I'm doing an extra 
> comparison that I honestly don't need to be doing.
> 

It is a terrible thing, not because it's slower: On a modern machine
(especially now that speculative execution is a pretty much Solved
Problem) a single branch not taken adds at WORST a nanosecond to
your program.  Even on a vintage 1988 Sun3 a single branch-not-taken
is going to add maybe 50 nanoseconds.

If there were one thing I could beat into the brains of all the
beginners on this list:  

Do not write code that you think will be
fast.  Write code that you think will work.

The reason it is a terrible thing is because you must have two
copies of "other stuff", and the odds of those two copies remaining
identical grows slimmer each day.

> Is there any way to prevent 'Use of uninitialized value' warnings 
> without doing an extra test as above ( and still keeping warnings turned 
> on )?

The idiom I use every single day:

#!/usr/bin/perl

use strict;
use warnings;
use diagnostics;


my $value;

if ($value && $value eq 'spring' ) {
print "Flowers are in bloom\n";
} else {
print "No flowers here!\n";
}

-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
Lawrence Statton - [EMAIL PROTECTED] s/aba/c/g
Computer  software  consists of  only  two  components: ones  and
zeros, in roughly equal proportions.   All that is required is to
sort them into the correct order.

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




Re: Use of uninitialized value

2005-03-17 Thread Randy W. Sims
Wagner, David --- Senior Programmer Analyst --- WGO wrote:
Daniel Kasak wrote:
Hi all.
I'm after people's thoughts on Perl's warnings about 'Use of
uninitialized value' in various situations ( string comparisons,
subroutine entries, etc ).
I understand what the warning is for.
In my code, it's perfectly OK for my variables to be uninitialised,
and is beyond my control anyway - the data is coming from a database,
and an undef value is perfectly legal ( NULL fields ).
I can make Perl stop complaining about it by placing if() statements
around everything, eg:
if you are using :
use warnings;
Then you can use 'no warnings;' just like you would use 'use warnings' to turn off. Then you can use 'use warnings' to get it goint again.  The better point might be to surround what you want within {}'s and use your 'no warnings' and once you hit the ending }, then will return to using warnings again.
You can be a little more specific with:
no warnings qw( uninitialized ); # see `perldoc perllexwarn`
You could also use a default value;
my $value = fetch_value() || '';
or what most seem to do is combine the tests:
if ( defined( $value ) && $value eq 'some_value' ) { ... }
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



Re: ActivePerl repositories

2005-03-17 Thread Bob Showalter
Peter Rabbitson wrote:
I have a general question concerning module availability for
ActiveState Perl. I asked on this list several month ago where to get
the DateTime suite modules, and somebody pointed me to a certain
repository at the University of Winnipeg. Now I am in need of
HTTP::Cookies and instead being pinpointed to a certain place I would
like to know is there a general routine for finding modules listed on
CPAN but not available through ppm? Or is it
that the win32 perl community does not have a centralized network like
cpan and it is pretty much up to the good will of someone to compile a
certain module and and serve it from a local server?
There are a couple of 3rd party repositories for PPM packages that you 
should add to your PPM configuration. See the ppm docs for how to add them. 
The uwinnepeg.ca one is Randy Kobes'. The other is Dave Roth's at 
http://www.roth.net/perl/packages/

Also, if a CPAN module (like HTTP::Cookies) is pure perl, you can use 
CPAN.pm to install it without too much trouble. You need to find nmake 
somwhere, since that's what ActiveState uses. See perldoc perlmodinstall for 
details.

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



RE: Use of uninitialized value

2005-03-17 Thread Wagner, David --- Senior Programmer Analyst --- WGO
Daniel Kasak wrote:
> Hi all.
> 
> I'm after people's thoughts on Perl's warnings about 'Use of
> uninitialized value' in various situations ( string comparisons,
> subroutine entries, etc ).
> I understand what the warning is for.
> In my code, it's perfectly OK for my variables to be uninitialised,
> and is beyond my control anyway - the data is coming from a database,
> and an undef value is perfectly legal ( NULL fields ).
> 
> I can make Perl stop complaining about it by placing if() statements
> around everything, eg:
> 
if you are using :
use warnings;

Then you can use 'no warnings;' just like you would use 'use warnings' to turn 
off. Then you can use 'use warnings' to get it goint again.  The better point 
might be to surround what you want within {}'s and use your 'no warnings' and 
once you hit the ending }, then will return to using warnings again.

Wags ;)

> if ($value) {
> if ($value eq "some_value_to_compare_to") {
># stuff
> } else {
># other stuff
> }
> } else {
># same as other stuff above
> }
> 
> But this makes things look overly complicated, increases the size of
> my code, and I assume slows things down because I'm doing an extra
> comparison that I honestly don't need to be doing.
> 
> Is there any way to prevent 'Use of uninitialized value' warnings
> without doing an extra test as above ( and still keeping warnings
> turned on )?
> 
> Thanks :)
> 
> --
> Daniel Kasak
> IT Developer
> NUS Consulting Group
> Level 5, 77 Pacific Highway
> North Sydney, NSW, Australia 2060
> T: (+61) 2 9922-7676 / F: (+61) 2 9922 7989
> email: [EMAIL PROTECTED]
> website: http://www.nusconsulting.com.au



***
This message contains information that is confidential
and proprietary to FedEx Freight or its affiliates.
It is intended only for the recipient named and for
the express purpose(s) described therein.
Any other use is prohibited.
***


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




Use of uninitialized value

2005-03-17 Thread Daniel Kasak
Hi all.
I'm after people's thoughts on Perl's warnings about 'Use of 
uninitialized value' in various situations ( string comparisons, 
subroutine entries, etc ).
I understand what the warning is for.
In my code, it's perfectly OK for my variables to be uninitialised, and 
is beyond my control anyway - the data is coming from a database, and an 
undef value is perfectly legal ( NULL fields ).

I can make Perl stop complaining about it by placing if() statements 
around everything, eg:

if ($value) {
   if ($value eq "some_value_to_compare_to") {
  # stuff
   } else {
  # other stuff
   }
} else {
  # same as other stuff above
}
But this makes things look overly complicated, increases the size of my 
code, and I assume slows things down because I'm doing an extra 
comparison that I honestly don't need to be doing.

Is there any way to prevent 'Use of uninitialized value' warnings 
without doing an extra test as above ( and still keeping warnings turned 
on )?

Thanks :)
--
Daniel Kasak
IT Developer
NUS Consulting Group
Level 5, 77 Pacific Highway
North Sydney, NSW, Australia 2060
T: (+61) 2 9922-7676 / F: (+61) 2 9922 7989
email: [EMAIL PROTECTED]
website: http://www.nusconsulting.com.au
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



Re: ActivePerl repositories

2005-03-17 Thread Offer Kaye
On Thu, 17 Mar 2005 18:39:53 -0500, Peter Rabbitson wrote:
> and it is pretty much up to the good will of someone to compile a
> certain module and and serve it from a local server?
> 

That's pretty much the situation. Of course, there's always Google :-)
In any case, for HTTP::Cookies you don't have to go far - it is
documented on ActiveState's site, so you should be able to find it on
the default repository:
http://aspn.activestate.com/ASPN/CodeDoc/libwww-perl/HTTP/Cookies.html

Hope this helps,
-- 
Offer Kaye

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




ActivePerl repositories

2005-03-17 Thread Peter Rabbitson
I have a general question concerning module availability for ActiveState 
Perl. I asked on this list several month ago where to get the DateTime suite 
modules, and somebody pointed me to a certain repository at the University 
of Winnipeg. Now I am in need of HTTP::Cookies and instead being pinpointed 
to a certain place I would like to know is there a general routine for 
finding modules listed on CPAN but not available through ppm? Or is it 
that the win32 perl community does not have a centralized network like 
cpan and it is pretty much up to the good will of someone to compile a 
certain module and and serve it from a local server?

Thanks

Peter

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




Re: changing selected values in optionmenus in perl tk

2005-03-17 Thread Offer Kaye
On Thu, 17 Mar 2005 12:56:33 -0500, BJ <[EMAIL PROTECTED]> wrote:
> Is it possible to change the selected value through software and have
> the results change on the screen? A very simple example would be if I
> had a form with optionmenu's that I was using for data entry, and I
> wanted to reset all the optionmenu's to their default value after the
> "submit" button is pressed. Is there a way that this can be done? Does
> anyone have a link to a good tutorial? The oreilly book on perl tk
> doesnt discuss this. Also, along the same path, does anyone have an
> exampke or a suggestion as to how I could have the options in one menu
> depend on the choice made in another? Thank you very much for your help.
> I tried to read teh manuals, but couldnt find what I was looking to do. ~BJ
> 

It sounds like you need to learn about callbacks and how to use them.
Basically, they are subroutines that you bind a widget to be "called
back" when an event that is related to that widget happens (e.g. a
button being pressed).
Since you have the Oreilly book, you should be fine - just start
reading at the beginning, everything you need to know is covered
there.
Meanwhile I took the example from the Tk::Optionmenu pod page
(http://search.cpan.org/dist/Tk/pod/Optionmenu.pod) and modified it by
adding a button that resets the option menu in the example. Hopefully
this will help you get started:
### begin code 
use Tk;
my $mw = MainWindow->new();

my ($var, $tvar);
my $opt = $mw->Optionmenu(
   -options => [[jan=>1], [feb=>2], [mar=>3], [apr=>4]],
   -command => sub { print "got: ", shift, "\n" },
   -variable => \$var,
   -textvariable => \$tvar
  )->pack;

my $f = $mw->Frame(-relief=>'groove', -borderwidth => 2)->pack;
$f->Label(-textvariable=>\$tvar)->pack(-side => 'left');
$f->Label(-text => " -> ")->pack(-side => 'left');
$f->Label(-textvariable=>\$var)->pack(-side => 'left');

$mw->Button(-text=>'Done Selecting!', 
  -command=>sub{
 $var = 1; $tvar = "jan";
 $opt->configure(
   -variable => \$var,
   -textvariable => \$tvar
 );
  })->pack;
$mw->Button(-text=>'Exit', -command=>sub{$mw->destroy})->pack;

MainLoop;
### end code 

Hope this helps,
-- 
Offer Kaye

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




Re: I think I need another regex...

2005-03-17 Thread John W. Krahn
Chris Knipe wrote:
Lo all,
Hello,
I tried to do this with split(), but it's not working good at all
The string:
interface=something very long with spaces and all 
mac-address=00:02:6F:36:2D:31 ap=no wds=no rx-rate=11Mbps tx-rate=11Mbps 
packets=12623,18377 bytes=10829240,2009327 frames=12623,18377
(the above is one line, wrapped for email).

I need to grab the values for all the options
$ perl -le'
use Data::Dumper;
my $string = q/interface=something very long with spaces and all 
mac-address=00:02:6F:36:2D:31 ap=no wds=no rx-rate=11Mbps tx-rate=11Mbps 
packets=12623,18377 bytes=10829240,2009327 frames=12623,18377/;
my %hash = $string =~ /(\S+)=([^=]+)(?:\s+|$)/g; 

print Dumper \%hash;
'
$VAR1 = {
  'bytes' => '10829240,2009327',
  'mac-address' => '00:02:6F:36:2D:31',
  'packets' => '12623,18377',
  'frames' => '12623,18377',
  'wds' => 'no',
  'interface' => 'something very long with spaces and all',
  'rx-rate' => '11Mbps',
  'ap' => 'no',
  'tx-rate' => '11Mbps'
};

John
--
use Perl;
program
fulfillment
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



Re: Taking Multiple Files in Pairs and Run it Iteratively

2005-03-17 Thread John W. Krahn
Edward Wijaya wrote:
On Tue, 15 Mar 2005 02:29:06 +0800, John W. Krahn <[EMAIL PROTECTED]> wrote:
Edward Wijaya wrote:
[snip]
Here is one way to do it:
my %files;
for ( @ARGV ) {
 next unless /(.+)\.(?:fa|rs)$/;
 push @{ $files{ $1 } }, $_;
 }
for my $base ( keys %files ) {
 if ( @{ $files{ $base } } != 2 ) {
 warn "Error: only one file '@{$files{$base}}'.\n";
 next;
 }
 die "Cannot open files '@{$files{$base}}'.\n"
 unless open F, '<', $files{ $base }[ 0 ]
and open G, '<', $files{ $base }[ 1 ];
 print "$base\n>\n";
 while ( my $f =  and my $g =  ) {  # LINE 32
 print $f + $g, "\n";
   ## BTW I can just do my other funky stuff here right?
Right.
 }
 }

I encounter this error:
"
Value of  construct can be "0"; test with defined() at 
thecode.pl  line 32.
thecode.pl syntax OK "
That warning can be fixed like this:
while ( defined( my $f =  ) and defined( my $g =  ) ) {
print $f + $g, "\n";

John
--
use Perl;
program
fulfillment
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



Re: Type-globbing filehandles

2005-03-17 Thread Offer Kaye
On Thu, 17 Mar 2005 12:54:23 -0600, Dave Kettmann wrote:
> Here is the whole first part. Snipped part is just declaration of variables.
> 

Okay, here is the problem:

>
> use File::Remote qw(:replace);
> 

The problem is, when you use the ":replace" tag, File::Remote imports
new "open" and "close" functions into your namespace, that override
the core functions. This is the reason for the error messages you get.
Twisted, isn't it?

To see the new "open" and "close" functions, open File/Remote.pm in
your text editor, e.g.:
vim `perldoc -l File::Remote`

Anyway, possible solutions are:
1. Simply move the line "use File::Remote qw(:replace);" below your while loop.
2. Replace "open" with "CORE::open" and "close" with "CORE::close".
3. Use either the ":standard" tag or the OO interface, instead of the
":replace" tag. Read "perldoc File::Remote" for the details.

Cheers,
-- 
Offer Kaye

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




RE: Type-globbing filehandles

2005-03-17 Thread Dave Kettmann
Here is the whole first part. Snipped part is just declaration of variables. 

The reason I'm 'reinventing the wheel' is for compatibility across systems that 
dont have the module installed. I'm trying to get away with installing as few 
extra modules as possible.



#!/usr/bin/perl

# March 10, 2005

use strict;
use warnings;
use Sys::Hostname;
use Time::localtime;
use File::Remote qw(:replace);

setrsh('/usr/bin/ssh');
setrcp('/usr/bin/scp');
settmp('/tmp');

my (%User_Preferences, $var, $value);
my @directories;
my $ext = ".tar.bz";
my $host = hostname;
my $t = localtime();
my $mday = $t->mday;
my $mon = $t->mon;
my $year = $t->year;
$year= $year + 1900;
my $date = "$mon.$mday.$year";
my $tarprg;
my $cfg_file = "/etc/backup.conf";


open (*CFG, $cfg_file) or die "Can't open config file: $!\n";
  while () {
chomp;
s/#.*//;
s/^\s_//;
s/\s+$//;
next unless length;
   ($var, $value) = split(/\s*=\s*/, $_, 2);
$User_Preferences{$var} = $value;
  }
close *CFG;





Thanks again for help.

Dave Kettmann
NetLogic
314-266-4000

> -Original Message-
> From: Offer Kaye [mailto:[EMAIL PROTECTED]
> Sent: Thursday, March 17, 2005 9:14 AM
> To: Perl Beginners
> Subject: Re: Type-globbing filehandles
> 
> 
> On Thu, 17 Mar 2005 08:46:55 -0600, Dave Kettmann wrote:
> > 
> > 
> > 
> > open (CFG, "/etc/backup.conf") or die "Can't open config 
> file: $!\n";
> >   while () {
> >   }
> > close CFG;
> > 
> > 
> > 
> > Ok so when I run my program like this .. it complains on 
> the the open() line and the close() line. 
> > It says:
> > 
> > Bareword "CFG" not allowed while "strict subs" in use at 
> backup-client.pl line 27.
> > Bareword "CFG" not allowed while "strict subs" in use at 
> backup-client.pl line 37.
> > 
> 
> Hi Dave,
> The code looks okay (read "perldoc -f open" to prove to yourself that
> CFG is allowed where you put it), so it must be a problem in another
> part of the code. Could you show the part you snipped?
> 
> One other comment- you seem to be rolling your own
> "configuration-file-reader" solution. Why re-invent the wheel? The are
> many good configuration-related modules on CPAN. I suggest
> Config::Auto for its simplicity of use:
>  begin perl code #
> use Config::Auto;
> my $User_Preferences = Config::Auto::parse("/etc/backup.conf");
> # $User_Preferences is now a reference to a hash holding your 
> configuration data
>  end perl code #
> 
> To install Config::Auto, write on the command-line:
> $ perl -MCPAN -e shell
> 
> and inside the CPAN shell write:
> cpan> install Config::Auto
> 
> Hope this helps.
> -- 
> Offer Kaye
> 
> -- 
> 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]
 




changing selected values in optionmenus in perl tk

2005-03-17 Thread BJ
Is it possible to change the selected value through software and have 
the results change on the screen? A very simple example would be if I 
had a form with optionmenu's that I was using for data entry, and I 
wanted to reset all the optionmenu's to their default value after the 
"submit" button is pressed. Is there a way that this can be done? Does 
anyone have a link to a good tutorial? The oreilly book on perl tk 
doesnt discuss this. Also, along the same path, does anyone have an 
exampke or a suggestion as to how I could have the options in one menu 
depend on the choice made in another? Thank you very much for your help. 
I tried to read teh manuals, but couldnt find what I was looking to do. ~BJ

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



Re: Calling a perl script within another

2005-03-17 Thread Offer Kaye
On Thu, 17 Mar 2005 11:19:39 -0500, Jay Savage wrote:
>
>my $loopscript = $scripts{the_one_I_need} ;
>my ($loadargv1, $loadargv2, $loadargv3)  = ($var1, $var2, $var3) ;
>$loopscript =~ s/^(.+)/[EMAIL PROTECTED] = \($loadargv1, $loadargv2, 
> $loadargv3\);/;
>exec $loopscript ;
> 
> Or something to that effect.  The above is untested, but it should work.
>

Err... no it won't. At best, it will run the script as an external
process and exit the calling script, which I think is not what the
original question called for. But I don't think this code will even do
that. Can you explain what you were trying to do in the s/// line?

Hope this helps,
-- 
Offer Kaye

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




Re: Calling a perl script within another

2005-03-17 Thread Offer Kaye
On Thu, 17 Mar 2005 11:40:10 -0500, zentara wrote:
> >
> >{
> >
> >$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();
> 
> You might be able to use the piped form of open, but I find
> it easier to use IPC::Open3.
> 

Since the original question was "I do not want to fork out a new perl
process", I don't see how your solution helps, as the open *will* fork
out a new process.

I do think that the "do" solution should work. For example, assume you
have a perl script called foo.pl where a single sub, foo(), is
defined:
 foo.pl #
use strict;
use warnings;

sub foo {
   my $sum = 0;
   $sum += $_ for (@_);
   return $sum;
}
 end foo.pl #

Now from your calling script, all you need is:
 calling_script.pl #
my $name = "foo";
do "$name.pl";
my $result = foo(1,2,3); # must use the () version of calling foo!!
print "$result\n";
 end calling_script.pl #

See "perldoc -f do" for details of using "do EXPR".

Hope this helps,
-- 
Offer Kaye

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




Re: I think I need another regex...

2005-03-17 Thread Dave Gray
On Thu, 17 Mar 2005 11:32:23 -0500, Dave Gray <[EMAIL PROTECTED]> wrote:
> > I tried to do this with split(), but it's not working good at all
> >
> > The string:
> > interface=something very long with spaces and all
> > mac-address=00:02:6F:36:2D:31 ap=no wds=no rx-rate=11Mbps tx-rate=11Mbps
> > packets=12623,18377 bytes=10829240,2009327 frames=12623,18377
> > (the above is one line, wrapped for email).
> >
> > I need to grab the values for all the options
> 
> #!/usr/bin/perl
> use strict;
> use warnings;
> use Data::Dumper;
> 
> my $data = 'your=data goes=here';
> my %opts = ();
> $opts{$1} = $2 while $data =~ /([^= ]+)=([^=]+)(?= [\w-]+=)/g;
> print Dumper(\%opts);

Er, that should be:

$opts{$1} = $2 while $data =~ /([^= ]+)=([^=]+)(?:(?= [\w-]+=)|$)/g

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




Re: I think I need another regex...

2005-03-17 Thread Dave Gray
> I tried to do this with split(), but it's not working good at all
> 
> The string:
> interface=something very long with spaces and all
> mac-address=00:02:6F:36:2D:31 ap=no wds=no rx-rate=11Mbps tx-rate=11Mbps
> packets=12623,18377 bytes=10829240,2009327 frames=12623,18377
> (the above is one line, wrapped for email).
> 
> I need to grab the values for all the options

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

my $data = 'your=data goes=here';
my %opts = ();
$opts{$1} = $2 while $data =~ /([^= ]+)=([^=]+)(?= [\w-]+=)/g;
print Dumper(\%opts);

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




Re: Calling a perl script within another

2005-03-17 Thread Jay Savage
On Thu, 17 Mar 2005 09:32:43 -0500 (EST), Chris Devers
<[EMAIL PROTECTED]> wrote:
> On Thu, 17 Mar 2005, Ramprasad A Padmanabhan wrote:
> 
> > > 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.
> 
> ...maybe that would have been helpful at the outset :-)
> 
> > 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
> > }
> 
> Okay, so now we're back to my other original suggestion -- use a module:
> 
> {
> $recipient  = "[EMAIL PROTECTED]";  # This will come from the MTA
> $scriptname = get_scriptname($recipient);
> 
> use $scriptname qw( somefunc );
> 
> somefunc($arg1,$arg2,$arg3) # somefunc is defined in $scriptname
> }
> 
> And now you just have to see that $scriptname exports somefunc().
> 
> If this gets called a lot, you may need to wrap it in an eval() so that
> the namespace doesn't get clobbered. (I think, I'm a little confused as
> to what would happen in that case, but it seems like an eval should
> smooth out many glitches...).
> 
> > Also I cannot go on requiring files again and again, my process will
> > hog all the memory then.
> 
> 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.
> 
> --
> Chris Devers

I take it the issue here is that his users have scripts (looks like
mail filters?), and he wants to write a script that will iterate
through them all and run them using parameters he provides.  If every
user has a customized script and there are many users, rewriting all
the scripts as modules would be impractical.  Apparently users share
scripts, but he's still indicating that there is a potentially large
number of scripts.  And if he did rewrite them as modules, it would
solve his issue, but break them for the users, unless he renamed them
and provided scripts with the existing names as interfaces to the new
modules.

This is a nasty little situation.  My quick and dirty solution--while
I sat down and made some policy decisions to improve my programming
life--would be the following:

1) Read the external scripts into variables.  Storing them in a hash
declared outside the loop would make the most sense, so that I could
hang onto them for later use.  Using DB_File or storing them to temp
files and keeping the hash as an index of paths would save on memory;
I leave the implementation as an exercise for the reader.

2) Within the loop, once I've fiured out which script I'm going to use:

   my $loopscript = $scripts{the_one_I_need} ;
   my ($loadargv1, $loadargv2, $loadargv3)  = ($var1, $var2, $var3) ;
   $loopscript =~ s/^(.+)/[EMAIL PROTECTED] = \($loadargv1, $loadargv2, 
$loadargv3\);/;
   exec $loopscript ;

Or something to that effect.  The above is untested, but it should work.

HTH,

--jay

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




Re: Determining standard perl modules

2005-03-17 Thread Offer Kaye
On Thu, 17 Mar 2005 10:48:30 -0500, Chris Charley wrote:
> 
> > Dear all,
> >
> > How/where do I find out the standard bundled perl modules
> 
> Hello Gavin,
> 
> perldoc perlmodlib
> 
> and then scroll to Standard Modules
> 
> Chris
> 

Or on the web, see: "http://search.cpan.org/dist/perl-/", e.g. :
http://search.cpan.org/dist/perl-5.8.0/

For access from inside a Perl script, see Module::CoreList -
http://search.cpan.org/dist/Module-CoreList/

Hope this helps,
-- 
Offer Kaye

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




Re: Determining standard perl modules

2005-03-17 Thread Chris Charley
- Original Message - 
From: "Gavin Henry" <[EMAIL PROTECTED]>
Newsgroups: perl.beginners
To: 
Sent: Thursday, March 17, 2005 4:05 AM
Subject: Determining standard perl modules


Dear all,
How/where do I find out the standard bundled perl modules
Hello Gavin,
perldoc perlmodlib
and then scroll to Standard Modules
Chris
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



Re: Type-globbing filehandles

2005-03-17 Thread Offer Kaye
On Thu, 17 Mar 2005 08:46:55 -0600, Dave Kettmann wrote:
> 
> 
> 
> open (CFG, "/etc/backup.conf") or die "Can't open config file: $!\n";
>   while () {
>   }
> close CFG;
> 
> 
> 
> Ok so when I run my program like this .. it complains on the the open() line 
> and the close() line. 
> It says:
> 
> Bareword "CFG" not allowed while "strict subs" in use at backup-client.pl 
> line 27.
> Bareword "CFG" not allowed while "strict subs" in use at backup-client.pl 
> line 37.
> 

Hi Dave,
The code looks okay (read "perldoc -f open" to prove to yourself that
CFG is allowed where you put it), so it must be a problem in another
part of the code. Could you show the part you snipped?

One other comment- you seem to be rolling your own
"configuration-file-reader" solution. Why re-invent the wheel? The are
many good configuration-related modules on CPAN. I suggest
Config::Auto for its simplicity of use:
 begin perl code #
use Config::Auto;
my $User_Preferences = Config::Auto::parse("/etc/backup.conf");
# $User_Preferences is now a reference to a hash holding your configuration data
 end perl code #

To install Config::Auto, write on the command-line:
$ perl -MCPAN -e shell

and inside the CPAN shell write:
cpan> install Config::Auto

Hope this helps.
-- 
Offer Kaye

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




Type-globbing filehandles

2005-03-17 Thread Dave Kettmann
Hi all,

I think I am using the term (Type-globbing) correctly but we will see...

I have a program I am making that needs to read lines from a file. Here is a 
snip of code to show what I'm doing...

#/usr/bin/perl

use strict;
use warnings;

my (%User_Preferences, $var, $value);



open (CFG, "/etc/backup.conf") or die "Can't open config file: $!\n";
  while () {
chomp;
s/#.*//;
s/^\s_//;
s/\s+$//;
next unless length;
   ($var, $value) = split(/\s*=\s*/, $_, 2);
$User_Preferences{$var} = $value;
  }
close CFG;

(More code that isnt important)



Ok so when I run my program like this .. it complains on the the open() line 
and the close() line. It says:

Bareword "CFG" not allowed while "strict subs" in use at backup-client.pl line 
27.
Bareword "CFG" not allowed while "strict subs" in use at backup-client.pl line 
37.

But ... if I change the CFG to *CFG only in the open and close lines, then it 
looks like it works. If I recall correctly, I should have to put the * in front 
of the filehandle, I dont remember having to do that in the past.

I guess I'm looking more for an explanation of the reasoning unless I am doing 
something syntactically(sp) wrong.

Thanks in advance for the help and comments,

Dave Kettmann
NetLogic
314-266-4000

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




I think I need another regex...

2005-03-17 Thread Chris Knipe
Lo all,
I tried to do this with split(), but it's not working good at all
The string:
interface=something very long with spaces and all 
mac-address=00:02:6F:36:2D:31 ap=no wds=no rx-rate=11Mbps tx-rate=11Mbps 
packets=12623,18377 bytes=10829240,2009327 frames=12623,18377
(the above is one line, wrapped for email).

I need to grab the values for all the options
--
Chris.
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



Re: Calling a perl script within another

2005-03-17 Thread Chris Devers
On Thu, 17 Mar 2005, Ramprasad A Padmanabhan wrote:

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

...maybe that would have been helpful at the outset :-)

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

Okay, so now we're back to my other original suggestion -- use a module:

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

use $scriptname qw( somefunc );
 
somefunc($arg1,$arg2,$arg3) # somefunc is defined in $scriptname
} 

And now you just have to see that $scriptname exports somefunc().

If this gets called a lot, you may need to wrap it in an eval() so that 
the namespace doesn't get clobbered. (I think, I'm a little confused as 
to what would happen in that case, but it seems like an eval should 
smooth out many glitches...).

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

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.



-- 
Chris Devers

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




Re: Taking Multiple Files in Pairs and Run it Iteratively

2005-03-17 Thread Edward Wijaya
On Tue, 15 Mar 2005 02:29:06 +0800, John W. Krahn <[EMAIL PROTECTED]> wrote:
Edward Wijaya wrote:

[snip]
Here is one way to do it:
my %files;
for ( @ARGV ) {
 next unless /(.+)\.(?:fa|rs)$/;
 push @{ $files{ $1 } }, $_;
 }
for my $base ( keys %files ) {
 if ( @{ $files{ $base } } != 2 ) {
 warn "Error: only one file '@{$files{$base}}'.\n";
 next;
 }
 die "Cannot open files '@{$files{$base}}'.\n"
 unless open F, '<', $files{ $base }[ 0 ]
and open G, '<', $files{ $base }[ 1 ];
 print "$base\n>\n";
 while ( my $f =  and my $g =  ) {  # LINE 32
 print $f + $g, "\n";
   ## BTW I can just do my other funky stuff here right?
 }
 }

John,
I encounter this error:
"
Value of  construct can be "0"; test with defined() at thecode.pl  
line 32.
thecode.pl syntax OK "

What could be the problem?
Thanks so much for your time.
--
Edward WIJAYA
Singapore
--
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 Chris Devers
On Thu, 17 Mar 2005, Ramprasad A Padmanabhan wrote:

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

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);
}

There's still no need to call on a second instance of perl for this.

> Now can I do this  without a diff interpreter. would you suggest I read
> the file into a string and eval it 
 
I think that may be substantially what "require" does, but for most 
purposes you shouldn't have to worry about how it's implemented -- just 
call it, run your script, and go back to what you were doing. 

-- 
Chris Devers

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




RE: platform independant log

2005-03-17 Thread Moon, John
Subject: platform independant log

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") ;


Here's another way (I think) to do what you want...

perl -e '$cmd=qx{ls -l}; open LOG, ">>log.txt";  print LOG $cmd, "\n"; close
LOG;'

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




Re: Calling a perl script within another

2005-03-17 Thread Chris Devers
On Thu, 17 Mar 2005, Ramprasad A Padmanabhan wrote:

>   I have a requirement to call a perl script within another and take 
> the output

Okay. 

The typical way to do this would be to make a module out of it, or at 
least a "require" call, but it looks like you may be generating the code 
dynamically rather than just running the contents of another file.

That's fine, Perl can do that, too.
 
> for example 
> 
> { 
> 
> $script = foo();
> $output = `perl $script $a $b $c `;
> do_someting($output);
> ...
> }

No. Don't do it that way, that's just silly :-)

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);
}

There's no reason to go out and call Perl again; you already have a 
perfectly good Perl interpreter running where you are at this point :-)

 

-- 
Chris Devers

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




Re: WWW::Mechanize java navigation (Answer)

2005-03-17 Thread Peter Rabbitson
On Thu, Feb 24, 2005 at 12:45:01PM -0500, Peter Rabbitson wrote:
> Hello list. I had very good luck using the WWW::Mechanize object for various
> automated data collectors until I stumbled over
> http://www.mymerchantview.net. As you can imagine the problems begin when I
> do my first ->follow_link after which the script blows with something about
> unsupported java. What can I use that would be as functional as
> WWW::Mechanize while at the same time compatible with the site mentioned
> above. It would be more than appreciated if somebody can submit along a few
> lines of code showing a "click" on the 'Log In' tab, a "click" on 'Continue'
> over at the next page and submittal of three types of authentication info on
> the successive screen. 
> 
> 
> Thanks everyone.
> 
> Peter
> 
> -- 
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>  
> 
> 

To answer my own question almost a month later, maybe someone would find 
this useful while googling. Since in my case relying on MSIE to do the 
navigation sounded like a joke, I spent a good deal of time debugging the 
login process with Netscape 7.2. Although the interface is way beyond 
retarded, there is a wonderful feature that allows you to see your current 
cookie jar. So basically after each screen I had to examine the cookie 
jar state and with some reading into the java script returned with every 
page I was able to reconstruct the entire login process. It works, although 
intermittenly at places but with the additional checks it pretty much had no 
failures in the past 2 weeks. Note that in real-life there is twice the 
amount of cookies, however with some trial and error I was able to eliminate 
half of them, as they were used by the client-side java applets.

It would still be nice, however, if mozilla firefox could do external
scripting, and parse the java properly for me without the juggling below, so
the entire thing could reside worry-free on a linux box, but oh well...


my $uid = uc $sources{$method}{user};
my $pwd = uc $sources{$method}{pass};
my $mch = $sources{$method}{merchant_num};

my $mmv_cookies = HTTP::Cookies->new;

my $mmv_crawl = WWW::Mechanize->new(cookie_jar => $mmv_cookies);
$mmv_crawl->agent_alias('Windows IE 6');

my $jsession;
my $golden_cookie;
my $merchnum_cookie;

recertification:
while (!$golden_cookie and !$merchnum_cookie) {

$mmv_cookies->clear;
$mmv_crawl->get('https://mymerchantview.net/mmv/Enrollment?directive=enrollUserInfoReIssue');
$mmv_cookies->scan(sub {
  if ($_[1] eq 'JSESSIONID') {
 $jsession = $_[2];
  }
});

unless ($jsession) {
  sleep 5;
  next recertification;
}

sleep 10;   #those sleeps are mandatory - why... I have no idea
   
$mmv_crawl->get("https://mymerchantview.net/mmv/Enrollment?USER_ACID=$uid&USER_PW=$pwd&MERCH_NUM=$mch&directive=enrollUserConfirmReIssue";);

$mmv_cookies->scan(sub {
  if ($_[1] eq 'JSESSIONID') {
 $jsession = $_[2];
  }
});

if ($jsession !~ /^0002/) {
  sleep 5;
  next recertification;
}

sleep 10;

$mmv_crawl->get('https://mymerchantview.net/mmv/Enrollment?directive=enrollIdGenReIssue');
  

$mmv_cookies->scan(sub {
  if ( ($_[1] eq 'MMV') and ($_[4] eq 'mymerchantview.net') ) {
 $golden_cookie = 1;
  }
});

unless ($golden_cookie) {
  sleep 5;
  next recertification;
}

$mmv_crawl->get('https://mymerchantview.net/mmv/Operations?directive=mmvPortal');

$mmv_crawl->get("https://mymerchantview.net/mmv/Operations?USER_ACID=$uid&USER_PW=$pwd&directive=mmvAccessVerification&DIAMOND_APPNAME=MyMerchantView";);

$mmv_cookies->scan(sub {
  if ( ($_[1] eq 'MMVMERCHNO') and ($_[4] eq 'mymerchantview.net') ) {
 $merchnum_cookie = 1;
  }
});

unless ($merchnum_cookie) {
  sleep 5;
  next recertification;
}

sleep 10;

}

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




Determining standard perl modules

2005-03-17 Thread Gavin Henry
Dear all,

How/where do I find out the standard bundled perl modules, like:

use DirHandle;
use Cwd;
use Getopt::Std;
use File::Path;
use File::stat;
use POSIX


I am building some RPMS, and need to know if I have to explicitly define
the module requirements, as they might already come with a standard perl
install

-- 
Just getting into the best language ever...
Fancy a [EMAIL PROTECTED] Just ask!!!

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




Re: Simple HASH query

2005-03-17 Thread perlmails
- Original Message - 
From: "SG Edwards" <[EMAIL PROTECTED]>
To: 
Sent: Wednesday, March 16, 2005 10:10 AM
Subject: Simple HASH query


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)
I suspect that your flat file does not contain sequence with *primary_id* 
in it.
From bioperl 1.4: => look for ** below,
Title   : primary_id
Usage   : $unique_key = $obj->primary_id;
Function: Returns the unique id for this object in this
  implementation. This allows implementations to manage their
  own object ids in a way the implementaiton can control
  clients can expect one id to map to one object.
  ** For sequences with no natural primary id, this method
   should return a stringified memory location.
Returns : A string
Args: A string (optional, for setting)

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]
 


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