Re: A simple way? A Perl way?

2004-08-31 Thread Bryan Harris


>> I am looking for a simple Perl way to decode the following, which can be any
>> grouping of number
>> 
>>2-8,9,11,18-21
>> 
>> Into
>>2,3,4,5,6,7,8,9,11,18,19,20,21
> 
> $ perl -le' print join ",", map /(\d+)-(\d+)/ ? $1 .. $2 : $_, split /,/,
> "2-8,9,11,18-21"'
> 2,3,4,5,6,7,8,9,11,18,19,20,21


Ouch, John, you turned my 9 lines into 1?!  Impressive.

- B



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




Re: A simple way? A Perl way?

2004-08-31 Thread John W. Krahn
Jerry Preston wrote:
Hi!
Hello,
I am looking for a simple Perl way to decode the following, which can be any
grouping of number 

   2-8,9,11,18-21
Into
   2,3,4,5,6,7,8,9,11,18,19,20,21
$ perl -le' print join ",", map /(\d+)-(\d+)/ ? $1 .. $2 : $_, split /,/, 
"2-8,9,11,18-21"'
2,3,4,5,6,7,8,9,11,18,19,20,21


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



Re: A simple way? A Perl way?

2004-08-31 Thread Bryan Harris



> From: Jerry Preston  wrote:
> 
> : I am looking for a simple Perl way to decode the
> : following, which can be any grouping of number
> : 
> :2-8,9,11,18-21
> : 
> : Into
> :2,3,4,5,6,7,8,9,11,18,19,20,21
> : 
> : Any Ideas?
> : 
> : Thanks for Your Time and Help,
> 
> This same question seems to pop up every quarter.
> Is this for a course in perl or something?


I just did this, out of curiosity what are you doing with it?  My method
handled all kinds of strings, but here's a starter for you:

$in = '2-8,9,11,18-21';

@inarray = split(',',$in);
@outarray = ();

foreach (@inarray) {
if (/^([\d.]+)-([\d.]+)$/) {
push @outarray, $1 .. $2;
}
else { push @outarray, $_; }
}

print join(",", @outarray), "\n";



Good luck.  (If this was homework, you owe me!)

- B



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




RE: A simple way? A Perl way?

2004-08-31 Thread Charles K. Clarkson
From: Jerry Preston  wrote:

: I am looking for a simple Perl way to decode the
: following, which can be any grouping of number
: 
:2-8,9,11,18-21
: 
: Into
:2,3,4,5,6,7,8,9,11,18,19,20,21
: 
: Any Ideas?
: 
: Thanks for Your Time and Help,

This same question seems to pop up every quarter.
Is this for a course in perl or something?




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




A simple way? A Perl way?

2004-08-31 Thread Jerry Preston
Hi!

I am looking for a simple Perl way to decode the following, which can be any
grouping of number 

   2-8,9,11,18-21

Into
   2,3,4,5,6,7,8,9,11,18,19,20,21

Any Ideas?

Thanks for Your Time and Help,

Jerry


RE: Perl Script for accessing XML file

2004-08-31 Thread Chris Devers
On Tue, 31 Aug 2004, Pothula, Giridhar wrote:
I have to read node values present in the XML file(residing on server)
from the ASP page using some scripting technology. As I am using Apache
web server, I have to use Perl scripting for this req. So, I am trying
to write server side script in the ASP page.
If you're using Apache, there's no reason to use ASP if you don't have 
to; this should work with straight Perl/CGI or mod_perl instead.

Would doing this as a regular CGI script be an option for you? You'll 
probably have much better luck finding help if you can do that...

(Also, it's "Perl" for the language, "perl" for the program that runs 
scripts written in the language, and never ever "PERL" for anything.)


--
Chris Devers  [EMAIL PROTECTED]
http://devers.homeip.net:8080/blog/
np: 'It's Not Easy Being Green (lo-fi midi version)'
 by Kermit
 from 'The Muppet Movie Soundtrack'
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



RE: Perl Script for accessing XML file

2004-08-31 Thread Pothula, Giridhar
Jenda,

I tried that but it didn't work. It is not recognizing keywords like
"use" and "my".

Let me tell you what my requirement is:

I have to read node values present in the XML file(residing on server)
from the ASP page using some scripting technology. As I am using Apache
web server, I have to use Perl scripting for this req. So, I am trying
to write server side script in the ASP page.

When the ASP engine parses, it should parse my script and give me back
the HTML with the values present in the XML file. 

And I know that this is possible using PERL, but I do not know the
syntax exactly. Any pointer would be appreciated.

-Original Message-
From: Jenda Krynicky [mailto:[EMAIL PROTECTED] 
Sent: Tuesday, August 31, 2004 4:26 PM
To: [EMAIL PROTECTED]; Pothula, Giridhar
Subject: Re: Perl Script for accessing XML file

From: "Pothula, Giridhar" <[EMAIL PROTECTED]>
> Problem: I would like to use PERL script to read the XML file (Text of
> the nodes). This is basically to customize the UI skins. All the skin
> values like color, images, font etc will be stored in an XML file. 
> 
> I would like to read from the XML file to generate the HTML code
> dynamically.

It would be much easier using XML::Simple.

...
use XML::Simple;

my $data = XMLin('CustomSkins.xml');
print $data->{to};
...

Jenda
(Code is untested but should be about right.)

= [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: Perl Script for accessing XML file

2004-08-31 Thread Jenda Krynicky
From: "Pothula, Giridhar" <[EMAIL PROTECTED]>
> Problem: I would like to use PERL script to read the XML file (Text of
> the nodes). This is basically to customize the UI skins. All the skin
> values like color, images, font etc will be stored in an XML file. 
> 
> I would like to read from the XML file to generate the HTML code
> dynamically.

It would be much easier using XML::Simple.

...
use XML::Simple;

my $data = XMLin('CustomSkins.xml');
print $data->{to};
...

Jenda
(Code is untested but should be about right.)

= [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: grabbing programs output for logfile

2004-08-31 Thread Wagner, David --- Senior Programmer Analyst --- WGO
Gavin Henry wrote:
> Hi again,
> 
> I thought I would make a new one for this:
> 
> my $backup = system( $rdiff, @args);
> 
system returns I believe success or failure. If you want the output, then use 
backticks to collect the output back to your variable.

Wags ;)

> Could I write $backup to my logfile?
> 
> Gavin.
> 
> 
> 
> --
> Kind Regards,
> 
> Gavin Henry.
> Managing Director.
> 
> T +44 (0) 1467 624141
> M +44 (0) 7930 323266
> F +44 (0) 1224 742001
> E [EMAIL PROTECTED]
> 
> Open Source. Open Solutions.
> 
> http://www.suretecsystems.com/



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




Re: Perl Script for accessing XML file

2004-08-31 Thread Chris Devers
On Tue, 31 Aug 2004, Pothula, Giridhar wrote:
Do I have use some modules for this to be executed successfully? I am 
getting a blank page when I run this asp file!
I don't know the first thing about ASP programming, sorry.
You can try the [EMAIL PROTECTED] list, but I don't know how much 
expertise they would have with ASP either...

--
Chris Devers  [EMAIL PROTECTED]
http://devers.homeip.net:8080/blog/
np: 'Movin' Right Along (lo-fi midi version)'
 by The Muppets
 from 'The Muppet Movie Soundtrack'
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



grabbing prpgrams output for logfile

2004-08-31 Thread Gavin Henry
Hi again,

I thought I would make a new one for this:

my $backup = system( $rdiff, @args);

Could I write $backup to my logfile?

Gavin.



-- 
Kind Regards,

Gavin Henry.
Managing Director.

T +44 (0) 1467 624141
M +44 (0) 7930 323266
F +44 (0) 1224 742001
E [EMAIL PROTECTED]

Open Source. Open Solutions.

http://www.suretecsystems.com/

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




Re: How to get config file via http

2004-08-31 Thread Tim Musson
Hey Chris, 

My MUA believes you used 
to write the following on Tuesday, August 31, 2004 at 3:20:50 PM.

CD> On Tue, 31 Aug 2004, Tim Musson wrote:

>> CD>  use LWP::Simple;
8< snip
>> Yep, I also noticed Net::HTTP. Any reason I should use one over the
>> other?

CD> The LWP bundle is the primary toolkit for client side web programming
CD> with Perl. Unless you're doing something more involved -- like the
CD> things that can be done with WWW::Mechanize and HTTP::Recorder -- the
CD> LWP toolkit is probably the place to start for this kind of work.

CD> I mean really, how much simpler can it be than "get($url)" ? :-)

CD> But read the perldoc for LWP (and the modules it bundles) to get a
CD> fuller idea of what you can do:

CD>  

Ok, thanks! I will check it out.

-- 
Tim Musson
Flying with The Bat! eMail v2.12.00
What's brown and sticky? ... A stick!


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




Re: Collecting Data in an Output File

2004-08-31 Thread Errin Larsen
On Tue, 31 Aug 2004 14:07:14 -0400 (EDT), Chris Devers
<[EMAIL PROTECTED]> wrote:
> On Tue, 31 Aug 2004, Errin Larsen wrote:
> 
> > I am collecting temperature data from the CPUs in my system.  

<>

> This is nitpicking, but have you considered inverting that? A format
> like this might be easier to work with:
> 
>  time,cpu1,cpu2,cpu3
>  Tue Aug 31 12:00:00 EDT 2004,65,65,64
>  Tue Aug 31 13:00:00 EDT 2004,63,64,65
>  Tue Aug 31 14:00:00 EDT 2004,62,64,66
>  Tue Aug 31 15:00:00 EDT 2004,64,62,64
> 
> This way, you can simply append to the file with the timestamp and the
> readings from each of the CPUs you're monitoring, rather than having to
> open the file and append to each line.
> 
> The downside is that if you add CPUs, the file falls apart because you
> need to add / change / remove a column. The fix for this is to just have
> one CPU per line, and identify it:
> 
>  time,cpu,temp
>  Tue Aug 31 12:00:00 EDT 2004,cpu1,65
>  Tue Aug 31 12:00:00 EDT 2004,cpu2,65
>  Tue Aug 31 12:00:00 EDT 2004,cpu3,64
>  ...
> 
> This is more verbose, obviously, but also more flexible.

The above is good stuff.  I'll work on this.  There are some problems,
but I'll get to them below.

> 
> > How can I read in all the lines into their on arrays and add some data
> > to the end?
> 
> For the one I've got above, it would be something like...
> 
>  while ( <> ) {
>  my ($ts, $cpu, $temp) = split("," $_);
>  push (@{ $processors{$cpu} }, $temp);
>  }
> 
> Then to get at the data, do something like
> 
>  foreach $cpu ( sort keys %processors ) {
>  print "$cpu: @{ $processors{ $cpu }}\n"
>  }
> 
> ...or something like that...

<>

Thanks Chris.  This is the sort of thing I was looking for!  Now I'll
go play with your suggestions some.  The problem I'm gonna have is
that the file format I suggested is really what I need.  HOWEVER, I
don't need that format when I'm collecting the data, just when I get
ready to use that data.  So I think I'll try collecting it as you
suggest in the 2nd suggestion above, and then work on a script that
will convert THAT file into the format I need.  Thanks again!

--Errin

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




Perl Script for accessing XML file

2004-08-31 Thread Pothula, Giridhar
Hi Chris,

Looking at your responses to other topics, I thought you could help me
resolving my problem.

Problem: I would like to use PERL script to read the XML file (Text of
the nodes). This is basically to customize the UI skins.
All the skin values like color, images, font etc will be stored in an
XML file. 

I would like to read from the XML file to generate the HTML code
dynamically.

Example: I have written a test asp page for the same. Please go through
the same and help me out in that? 

Do I have use some modules for this to be executed successfully? I am
getting a blank page when I run this asp file!

Thanks Much,
GP

 

Tove 
Jani 
Reminder 
Don't forget me this weekend! 



TEst.asp
Description: TEst.asp
-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 


Re: How to get config file via http

2004-08-31 Thread Chris Devers
On Tue, 31 Aug 2004, Tim Musson wrote:
CD>  use LWP::Simple;
CD>  $content = get($URL);
CD> Or to be more robust about it:
CD>  use LWP::Simple;
CD>  unless (defined ($content = get $URL)) {
CD>  die "could not get $URL\n";
CD>  }
CD> Make sense?
Yep, I also noticed Net::HTTP. Any reason I should use one over the
other?
The LWP bundle is the primary toolkit for client side web programming 
with Perl. Unless you're doing something more involved -- like the 
things that can be done with WWW::Mechanize and HTTP::Recorder -- the 
LWP toolkit is probably the place to start for this kind of work.

I mean really, how much simpler can it be than "get($url)" ? :-)
But read the perldoc for LWP (and the modules it bundles) to get a 
fuller idea of what you can do:


--
Chris Devers  [EMAIL PROTECTED]
http://devers.homeip.net:8080/blog/
np: 'Mahna Mahna!'
 by The Muppets
 from 'The Muppet Show'
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



Re: How to get config file via http

2004-08-31 Thread Tim Musson
Hey Chris, 

My MUA believes you used 
to write the following on Tuesday, August 31, 2004 at 3:03:33 PM.

>> Is this a Perl question?

CD> Duh, yes, it is -- you said "grab", not "serve". Ignore the last mail.

LOL, yep it is. :-)
Bigger picture. I am processing a list of Windows servers and doing a
"net view" on each to see if they respond - then presenting an html
table via a web page. I have the current perl bit on a handfull of
servers (I don't trust 'em, they are all MS.) I also have the .csv on
each server, and would like to have it on only a couple (have to have
redundancy! :-).

So I am trying to get my 'net_view' perl bit read the server list from
a web server.

CD> The simplest way to do this is in Perl with LWP:

CD>  use LWP::Simple;
CD>  $content = get($URL);

CD> Or to be more robust about it:

CD>  use LWP::Simple;
CD>  unless (defined ($content = get $URL)) {
CD>  die "could not get $URL\n";
CD>  }

CD> Make sense?

Yep, I also noticed Net::HTTP. Any reason I should use one over the
other?

btw all, thanks for the quick response!

-- 
Tim Musson
Flying with The Bat! eMail v2.12.00
-- A rock ---> me <- A hard place ---


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




Re: How to get config file via http

2004-08-31 Thread Chris Devers
On Tue, 31 Aug 2004, Chris Devers wrote:
On Tue, 31 Aug 2004, Tim Musson wrote:
Hey all, I want to grab a config file from a web server. Basically I need 
to pull a ServerList.csv from a web server so I don't have to distribute it 
all over.
Is this a Perl question?
Duh, yes, it is -- you said "grab", not "serve". Ignore the last mail.
The simplest way to do this is in Perl with LWP:
use LWP::Simple;
$content = get($URL);
Or to be more robust about it:
use LWP::Simple;
unless (defined ($content = get $URL)) {
die "could not get $URL\n";
}
Make sense?
--
Chris Devers  [EMAIL PROTECTED]
http://devers.homeip.net:8080/blog/
np: 'It's Not Easy Being Green (lo-fi midi version)'
 by Kermit
 from 'The Muppet Movie Soundtrack'
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



Re: How to get config file via http

2004-08-31 Thread Chris Devers
On Tue, 31 Aug 2004, Tim Musson wrote:
Hey all, I want to grab a config file from a web server. Basically I 
need to pull a ServerList.csv from a web server so I don't have to 
distribute it all over.
Is this a Perl question?
You could just put ServerList.csv into your web server's document root 
and serve it directly from Apache or whatever. If you want, you can have 
the web server put a password lock (etc) on the directory that the file 
lives in, or you can just drop it there and forget about it.

I'm unclear why you'd necessarily have to get Perl involved here.

--
Chris Devers  [EMAIL PROTECTED]
http://devers.homeip.net:8080/blog/
np: 'Sesame Street Theme Song'
 by Sesame Street
 from 'Sesame Street'
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



RE: How to get config file via http

2004-08-31 Thread John Pretti


-Original Message-
From: Tim Musson [mailto:[EMAIL PROTECTED] 
Sent: Tuesday, August 31, 2004 1:53 PM
To: [EMAIL PROTECTED]
Subject: How to get config file via http


Hey all, I want to grab a config file from a web server. Basically I
need to pull a ServerList.csv from a web server so I don't have to
distribute it all over.

What module should I use to do that? I did a search on CPAN, but keep
getting thousands of responses, and can't seem to find one to do what
I want...

Thanks!

-- 
Tim Musson
Flying with The Bat! eMail v2.12.00
Taxpayer:  Someone who doesn't have to take a public service exam to
work for the government.

You could simply do a system call to wget, assuming you are using a *nix
type machine. Other than that you may want to look at Net::SCP. HTH

http://search.cpan.org/~ivan/Net-SCP-0.07/SCP.pm

John




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




How to get config file via http

2004-08-31 Thread Tim Musson

Hey all, I want to grab a config file from a web server. Basically I
need to pull a ServerList.csv from a web server so I don't have to
distribute it all over.

What module should I use to do that? I did a search on CPAN, but keep
getting thousands of responses, and can't seem to find one to do what
I want...

Thanks!

-- 
Tim Musson
Flying with The Bat! eMail v2.12.00
Taxpayer:  Someone who doesn't have to take a public service exam to
work for the government.


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




RE: Perl Script for accessing XML file

2004-08-31 Thread Pothula, Giridhar
Can anybody help me out in finding errors in the following code? I am
not getting any output, when I am accessing the below asp page.

 

Asp Page code:

 



  





http://schemas.microsoft.com/intellisense/ie5";>

  

  

  

  

  <%

  $CCTVservice = $Server->CreateObject('MSXML2.DOMDocument.3.0');

  $xml_file  = Test.xml';

  $node_name = 'to';

  $CCTVservice->{async} = "False";

  $CCTVservice->{validateOnParse} = "False";

  $CCTVservice->Load($xml_file);

  $node_list = $CCTVservice->selectNodes($node_name);

  foreach $node (in $node_list) {

  print $node->{Text}, "\n";

  } 

  %>

  



 

XML File:

 

 



Tove 

Jani 

Reminder 

Don't forget me this weekend! 



 

Thanks Much,

GP

 

-Original Message-
From: Bob Showalter [mailto:[EMAIL PROTECTED] 
Sent: Tuesday, August 31, 2004 11:32 AM
To: Pothula, Giridhar; [EMAIL PROTECTED]
Subject: RE: Perl Script for accessing XML file

 

Pothula, Giridhar wrote:

 

Hi. Top-post please.
http://home.in.tum.de/~jain/software/outlook-quotefix/

 

> Sorry...That was a typo. I would like to use PERL script to read the

> XML file (Text of the nodes). This is basically to customize the UI

> skins. All the skin values like color, images, font etc will be

> stored in an XML file.

> 

> I would like to read from the XML file to generate the HTML code

> dynamically.

 

OK, well the faq I pointed you to will give you some ideas of the
overall

topic of parsing XML with Perl. Lots of ways to approach it, so get an

overview before diving in.

 

> 

> -Original Message-

> From: Bob Showalter [mailto:[EMAIL PROTECTED]

> Sent: Tuesday, August 31, 2004 11:16 AM

> To: Pothula, Giridhar; [EMAIL PROTECTED]

> Subject: RE: Perl Script for accessing XML file

> 

> Pothula, Giridhar wrote:

> > Hi All,

> > 

> > I am trying to get a code snippet for the client side Perl script in

> > an ASP page which accesses XML file residing on the server.

> 

> Hmm, not sure what you mean by "client side". Both ASP and Perl are

> server-side technologies.

> 

> Anyway, you might want to start at

> http://perl-xml.sourceforge.net/faq/ 

 

 



Re: Collecting Data in an Output File

2004-08-31 Thread Chris Devers
On Tue, 31 Aug 2004, Errin Larsen wrote:
I am collecting temperature data from the CPUs in my system.  I want
to write this data into a comma-seperated text file, like so:
CPU1,65,63,62,64
CPU2,65,64,64,62
CPU3,64,65,66,64
Each line represents one CPU's temperature readings.  Each column 
represents the time the reading was taken.  So, if I was taking the 
readings once an hour, the above sample would be, for example, 12 
Noon, 1pm, 2pm and 3pm.
This is nitpicking, but have you considered inverting that? A format 
like this might be easier to work with:

time,cpu1,cpu2,cpu3
Tue Aug 31 12:00:00 EDT 2004,65,65,64
Tue Aug 31 13:00:00 EDT 2004,63,64,65
Tue Aug 31 14:00:00 EDT 2004,62,64,66
Tue Aug 31 15:00:00 EDT 2004,64,62,64
This way, you can simply append to the file with the timestamp and the 
readings from each of the CPUs you're monitoring, rather than having to 
open the file and append to each line.

The downside is that if you add CPUs, the file falls apart because you 
need to add / change / remove a column. The fix for this is to just have 
one CPU per line, and identify it:

time,cpu,temp
Tue Aug 31 12:00:00 EDT 2004,cpu1,65
Tue Aug 31 12:00:00 EDT 2004,cpu2,65
Tue Aug 31 12:00:00 EDT 2004,cpu3,64
...
This is more verbose, obviously, but also more flexible.
How can I read in all the lines into their on arrays and add some data 
to the end?
For the one I've got above, it would be something like...
while ( <> ) {
my ($ts, $cpu, $temp) = split("," $_);
push (@{ $processors{$cpu} }, $temp);
}
Then to get at the data, do something like
foreach $cpu ( sort keys %processors ) {
print "$cpu: @{ $processors{ $cpu }}\n"
}
...or something like that...

--
Chris Devers  [EMAIL PROTECTED]
http://devers.homeip.net:8080/blog/
np: 'The Muppet Show Theme'
 by The Muppets
 from 'The Muppet Show'
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



RE: Perl Script for accessing XML file

2004-08-31 Thread Bob Showalter
Pothula, Giridhar wrote:

Hi. Top-post please. http://home.in.tum.de/~jain/software/outlook-quotefix/

> Sorry...That was a typo. I would like to use PERL script to read the
> XML file (Text of the nodes). This is basically to customize the UI
> skins. All the skin values like color, images, font etc will be
> stored in an XML file.
> 
> I would like to read from the XML file to generate the HTML code
> dynamically.

OK, well the faq I pointed you to will give you some ideas of the overall
topic of parsing XML with Perl. Lots of ways to approach it, so get an
overview before diving in.

> 
> -Original Message-
> From: Bob Showalter [mailto:[EMAIL PROTECTED]
> Sent: Tuesday, August 31, 2004 11:16 AM
> To: Pothula, Giridhar; [EMAIL PROTECTED]
> Subject: RE: Perl Script for accessing XML file
> 
> Pothula, Giridhar wrote:
> > Hi All,
> > 
> > I am trying to get a code snippet for the client side Perl script in
> > an ASP page which accesses XML file residing on the server.
> 
> Hmm, not sure what you mean by "client side". Both ASP and Perl are
> server-side technologies.
> 
> Anyway, you might want to start at
> http://perl-xml.sourceforge.net/faq/ 


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




RE: Perl Script for accessing XML file

2004-08-31 Thread Charles K. Clarkson
From: Bob Showalter  wrote:

: Pothula, Giridhar wrote:
: : Hi All,
: : 
: : I am trying to get a code snippet for the client side Perl
: : script in an ASP page which accesses XML file residing on the
: : server. 
: 
: Hmm, not sure what you mean by "client side". Both ASP and Perl
: are server-side technologies. 
: 
: Anyway, you might want to start at
: http://perl-xml.sourceforge.net/faq/

Perlscript can also be run as a client side script like
Javascript and VBscript. It just seems like an unlikely
scenario.

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 Script for accessing XML file

2004-08-31 Thread Pothula, Giridhar
Sorry...That was a typo. I would like to use PERL script to read the XML
file (Text of the nodes). This is basically to customize the UI skins.
All the skin values like color, images, font etc will be stored in an
XML file. 

I would like to read from the XML file to generate the HTML code
dynamically.

Thanks Much,
Giridhar

-Original Message-
From: Bob Showalter [mailto:[EMAIL PROTECTED] 
Sent: Tuesday, August 31, 2004 11:16 AM
To: Pothula, Giridhar; [EMAIL PROTECTED]
Subject: RE: Perl Script for accessing XML file

Pothula, Giridhar wrote:
> Hi All,
> 
> I am trying to get a code snippet for the client side Perl script in
> an ASP page which accesses XML file residing on the server.

Hmm, not sure what you mean by "client side". Both ASP and Perl are
server-side technologies.

Anyway, you might want to start at http://perl-xml.sourceforge.net/faq/

-- 
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: Could this be made shorter and cleaner?

2004-08-31 Thread Bob Showalter
Gavin Henry wrote:
> P.S. I am now a programmer or a scripter, I am not sure is perl is
> programming or scripting? I think programming.

You are a programmer. No such thing as a "scripter".

You're using a scripting language, which simply means you don't have to use
a compiler and linker to produce an executable; you just feed your script to
perl and it runs.

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




RE: Perl Script for accessing XML file

2004-08-31 Thread Bob Showalter
Pothula, Giridhar wrote:
> Hi All,
> 
> I am trying to get a code snippet for the client side Perl script in
> an ASP page which accesses XML file residing on the server.

Hmm, not sure what you mean by "client side". Both ASP and Perl are
server-side technologies.

Anyway, you might want to start at http://perl-xml.sourceforge.net/faq/

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




RE: Questions regarding use: "optional" modules, and "refreshing" modules

2004-08-31 Thread Ed Christian
Wiggins d Anconia wrote:
>> Folks,
>> 
>> I've run into a couple of issues with use and was hoping someone
>> could help me come up with a solution.
>> 
>> First, I use a specific module in a work environment to set some
>> global variables. I want to re-use my code in another environment
>> which doesn't have the specific configuration module. I don't want to
>> have to keep two separate copies of the code. What I currently use in
>> the work environment is of the format:
>> 
>> use lib '/path/to/work/modules';
>> use Prefs;
>> 
>> my $config = Prefs->new();
>> my $param1 = $config->get("PARAM1");
>> 
>> I'd like to something of the format:
>> 
>> my $param1;
>> if (-f '/path/to/work/modules/Prefs.pm') {
>>  use lib '/path/to/work/modules';
>>  use Prefs;
>> 
>>  my $config = Prefs->new();
>>  $param1 = $config->get("PARAM1");
>> }
>> else {
>>  $param1 = "default value here";
>> }
>> 
>> Is something like this possible?
>> 
> 
> perldoc -f eval  (2nd form)
> 
> Generally you use 'eval' to wrap a segment of code that can die, then
> just catch the error and set your default when an error occurs. So in
> this case if the module isn't available, can't be loaded (think
> syntax error in it), or causes some other error, then the failure
> will be caught and you can move on gracefully.
> 
> If the examples in the doc aren't sufficient, come back and someone
> will provide a good example. 
> 
>> Also, some of the config-style modules I use store their
>> configuration values with the module itself. Using the above example
>> Prefs.pm, the function $config->get("PARAM1") might look like:
>> 
>> my $self = shift;
>> my $val = shift;
>> return $self->{DATA}{$val};
>> 
>> I have code which runs daemonized (using Proc::Daemon) that begins by
>> using the Prefs config module. It's quite possible that the
>> parameters in the Prefs config module get modified. I may need my
>> daemonized code to "refresh" its copy of the Prefs config module to
>> pull in the new parameters. Can this be done, or do I have to stop
>> the daemon and restart it? 
>> 
>> Thanks all!
>> - Ed
>> 
> 
> perldoc -f do
> 
> There is an example of this very thing in that doc. In the case of
> your daemon, usually you would set up a signal handler, catch the
> signal (usually HUP) and re-init the config information when that
> signal is received.   
> 
> perldoc perlipc (for more about signal handling)
> 
> There is excellent information about daemons in the Network
> Programming with Perl book, I highly recommend it if you have the
> resources and will be writing code of this nature.  
> 
> http://danconia.org

Wiggins,

Thanks for the help! I was hung-up on the notion that every module I
loaded had to be loaded at compile-time. By using the "do" function, I
can optionally load and/or reload my modules at run-time. My code now
looks like:

my $setting = 'localhost';

if (-f '/usr/local/PerlModules/Prefs.pm') {
do '/usr/local/PerlModules/Prefs.pm';
my $config = Prefs->new();
$setting = $config->read('DB_SERVER');
}

print "$setting\n";

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




Re: Could this be made shorter and cleaner?

2004-08-31 Thread Shawn
On Tue, 2004-08-31 at 10:57 -0400, Daniel Staal wrote:
> --As of Tuesday, August 31, 2004 10:07 AM +0100, Gavin Henry is alleged to 
> have said:
> 
> > P.S. I am now a programmer or a scripter, I am not sure is perl is
> > programming or scripting? I think programming.
> 
> --As for the rest, it is mine.
> 
> Short answer: Yes.  (It is at least one of the two.)  ;)
> 
> Long answer...  You honestly don't want to get into it.  You start 
> devolving into arguments over what is 'scripting' versus what is 
> 'programming', and from there what is best...

I would say Perl is at least both. Allow me to devolve..

The act of writing a perl program is script in in that you're simply (or
not so simply) instructing /usr/bin/perl to do stuff based on you
"script". You're running the source code with an interpreter, so to
speak.

Perl programing is programing in that the word "programing" is loosely
defined enough such that even COBOL is a programming language. So long
as the "language" has constructs that allow you to tell the machine it's
running on to do something and not just a parsing specification, I'd say
you'd be hard pressed to argue it's not a language. Whoever said that
just because your handiwork isn't converted to a format that the kernel
itself parses into machine code which it then feeds to a CPU that you're
code isn't a program? What's java? It has an interpreter, and it isn't
machine code, right? Oh yeah, it's a "run time system"... Oh, I forgot.

There. Hopefully that made enough sense, and will end all devolving.



signature.asc
Description: This is a digitally signed message part


Re: Questions regarding use: "optional" modules, and "refreshing" modules

2004-08-31 Thread Wiggins d Anconia
> Folks,
> 
> I've run into a couple of issues with use and was hoping someone could
> help me come up with a solution.
> 
> First, I use a specific module in a work environment to set some global
> variables. I want to re-use my code in another environment which doesn't
> have the specific configuration module. I don't want to have to keep two
> separate copies of the code. What I currently use in the work
> environment is of the format:
> 
> use lib '/path/to/work/modules';
> use Prefs;
> 
> my $config = Prefs->new();
> my $param1 = $config->get("PARAM1");
> 
> I'd like to something of the format:
> 
> my $param1;
> if (-f '/path/to/work/modules/Prefs.pm') {
>   use lib '/path/to/work/modules';
>   use Prefs;
> 
>   my $config = Prefs->new();
>   $param1 = $config->get("PARAM1");
> }
> else {
>   $param1 = "default value here";
> }
> 
> Is something like this possible?
>

perldoc -f eval  (2nd form)

Generally you use 'eval' to wrap a segment of code that can die, then
just catch the error and set your default when an error occurs. So in
this case if the module isn't available, can't be loaded (think syntax
error in it), or causes some other error, then the failure will be
caught and you can move on gracefully.

If the examples in the doc aren't sufficient, come back and someone will
provide a good example.
 
> Also, some of the config-style modules I use store their configuration
> values with the module itself. Using the above example Prefs.pm, the
> function $config->get("PARAM1") might look like: 
> 
> my $self = shift;
> my $val = shift;
> return $self->{DATA}{$val};
> 
> I have code which runs daemonized (using Proc::Daemon) that begins by
> using the Prefs config module. It's quite possible that the parameters
> in the Prefs config module get modified. I may need my daemonized code
> to "refresh" its copy of the Prefs config module to pull in the new
> parameters. Can this be done, or do I have to stop the daemon and
> restart it?
> 
> Thanks all!
> - Ed
> 

perldoc -f do

There is an example of this very thing in that doc. In the case of your
daemon, usually you would set up a signal handler, catch the signal
(usually HUP) and re-init the config information when that signal is
received.

perldoc perlipc (for more about signal handling)

There is excellent information about daemons in the Network Programming
with Perl book, I highly recommend it if you have the resources and will
be writing code of this nature.

http://danconia.org

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




Perl Script for accessing XML file

2004-08-31 Thread Pothula, Giridhar
Hi All,

 

I am trying to get a code snippet for the client side Perl script in an
ASP page which accesses XML file residing on the server.

 

Any pointers regarding the same would be appreciated.

 

Thanks and Regards,

Giridhar



RE: How do i run shell command

2004-08-31 Thread Charles K. Clarkson
From: Radhika Sambamurti  wrote:

: thanks,
: radhika
: 
: :  If you're not reading from any other files, you don't
: :  need the $count variable in this case. The special
: :  variable $. holds the number of lines read since a
: : filehandle was last explicitly closed: 
: : 
: :  1 while ;
: :  $count = $.;
: : 
: :  This reads all the records in the file and discards them.
: : 
: Hi,
: was trying to reproduce the code [above].
: I was wondering what the 1 is doing before the while. Is
: it the exit status of the while, that is until eof is
: reached and exit code = 1 ?


'while' can be used as a statement modifier. When used
that way, it places each successive value in the $_ variable
and the line number of the file in the variable $. (And a
number of other things.)

If the statement doesn't do anything with $_ and doesn't
produce any other effect, it becomes irrelevant. 1 and 0
won't raise errors under strict and warnings.

0;
1;
2; # <--- raises a constant in void context warning.


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 Binary

2004-08-31 Thread Chris Devers
On Tue, 31 Aug 2004, Eduardo Vázquez Rodríguez wrote:
I am looking for a way of creating a "perl binary", my intention is 
that no one can read the scripts in a human readable way.
There is no reliable way to do this.
There is a product called perl2exe, which can make Windows executable 
programs out of Perl scripts, but it is not very hard to get back to 
regular Perl code from the file that perl2exe produces.

There is a program called perlcc which can make executables out of Perl 
scripts, but it should be considered experimental, and again, obscuring 
your program source cannot be depended upon.

If you really want to keep your code away from prying eyes, keep it on a 
machine where you know and trust everyone that has login access. If 
people can poke at your program, they can always reverse engineer it; 
this is generally true no matter what language you're dealing with.

--
Chris Devers  [EMAIL PROTECTED]
http://devers.homeip.net:8080/blog/
np: 'Fraggle Rock Theme Song (in German / auf Deutsch)'
 by Fraggles
 from 'Fraggle Rock'
-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 


Questions regarding use: "optional" modules, and "refreshing" modules

2004-08-31 Thread Ed Christian
Folks,

I've run into a couple of issues with use and was hoping someone could
help me come up with a solution.

First, I use a specific module in a work environment to set some global
variables. I want to re-use my code in another environment which doesn't
have the specific configuration module. I don't want to have to keep two
separate copies of the code. What I currently use in the work
environment is of the format:

use lib '/path/to/work/modules';
use Prefs;

my $config = Prefs->new();
my $param1 = $config->get("PARAM1");

I'd like to something of the format:

my $param1;
if (-f '/path/to/work/modules/Prefs.pm') {
use lib '/path/to/work/modules';
use Prefs;

my $config = Prefs->new();
$param1 = $config->get("PARAM1");
}
else {
$param1 = "default value here";
}

Is something like this possible?

Also, some of the config-style modules I use store their configuration
values with the module itself. Using the above example Prefs.pm, the
function $config->get("PARAM1") might look like: 

my $self = shift;
my $val = shift;
return $self->{DATA}{$val};

I have code which runs daemonized (using Proc::Daemon) that begins by
using the Prefs config module. It's quite possible that the parameters
in the Prefs config module get modified. I may need my daemonized code
to "refresh" its copy of the Prefs config module to pull in the new
parameters. Can this be done, or do I have to stop the daemon and
restart it?

Thanks all!
- Ed

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




RE: grabbing programs output for logfile

2004-08-31 Thread Gavin Henry
Jim said:
>
>> -Original Message-
>> From: Gavin Henry [mailto:[EMAIL PROTECTED]
>> Sent: Tuesday, August 31, 2004 10:11 AM
>> To: [EMAIL PROTECTED]
>> Subject: grabbing programs output for logfile
>>
>> Hi all,
>>
>> I thought I'd start a new thread for this one:
>>
>> my $backup = system( $rdiff, @args);
>>
>> Could I use $backup to write to my logfile?
>>
>> Gavin.
>>
>
> I think you are asking if $backup will contain the output of your sytem
> command? It won't. It will only contain the return code. You want back
> ticks
> or the the qx operator
>
> $backup = `$cmd`;
>  or
> $info = qx(ps -ef);
>
>  perldoc -f system
>
>

Thanks. I actually shouldn't of asked this, as I should have read the docs
and the cookbook first. Sorry.

>
>
> ---
> Outgoing mail is certified Virus Free.
> Checked by AVG anti-virus system (http://www.grisoft.com).
> Version: 6.0.745 / Virus Database: 497 - Release Date: 8/27/2004
>
>
>


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




Collecting Data in an Output File

2004-08-31 Thread Errin Larsen
Hi Perl Gurus!

I am collecting temperature data from the CPUs in my system.  I want
to write this data into a comma-seperated text file, like so:

CPU1,65,63,62,64
CPU2,65,64,64,62
CPU3,64,65,66,64

Each line represents one CPU's temperature readings.  Each column
represents the time the reading was taken.  So, if I was taking the
readings once an hour, the above sample would be, for example, 12
Noon, 1pm, 2pm and 3pm.

I have successfully coded some Perl that pulls that data from the
system, but now I need to be able to a) determine if the file is empty
and, if so, start the file by adding the CPUx output. b) if the file
is not empty, add the next set of readings to the end of each line.

for a), I know I can do:

  if( -e )

that's no problem.  My problem is b).  How can I read in all the lines
into their on arrays and add some data to the end?

my @wholefile = ;

Puts all the lines, one line per array element (with "\n" at the end).
 So, I can easily iterate through and chomp the "\n" out, then I can
add the latest temperature reading onto the end.

Ok, maybe I answered my own question.

So, let me take it a step further.  What if I wanted to read a
particular time's data out of the file; or add one into the middle? 
Can I get an array of arrays, Where one Array holds other arrays, each
other array holding the data (split into elements) of one line?

--Thanks

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




Re: Could this be made shorter and cleaner?

2004-08-31 Thread Gavin Henry
Daniel Staal said:
> --As of Tuesday, August 31, 2004 10:07 AM +0100, Gavin Henry is alleged to
> have said:
>
>> P.S. I am now a programmer or a scripter, I am not sure is perl is
>> programming or scripting? I think programming.
>
> --As for the rest, it is mine.
>
> Short answer: Yes.  (It is at least one of the two.)  ;)
>
> Long answer...  You honestly don't want to get into it.  You start
> devolving into arguments over what is 'scripting' versus what is
> 'programming', and from there what is best...
>
> To me, scripting is a sub-class of programming anyway, so why should it
> matter?  ;)
>

Yeah, I'm a programmer ;-)

-- 
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: Perl Binary

2004-08-31 Thread Jenda Krynicky
From: Eduardo Vázquez Rodríguez <[EMAIL PROTECTED]>
> Hello everybody out there using Perl- Im doing a perl scripts, which
> objective is to parse text.
>
> I am looking for a way of creating a "perl binary", my intention is
> that no one can read the scripts in a human readable way.

You can't.
You can make it unreadable to most, you can make it more or less hard
to others, but you can't do anything to prevent a seasoned Perl
hacker to get to see your code.

You want to go to
http://www.perlmonks.org/index.pl?node=Super%20Search
and search for "hide script source". This has been discussed quite a
few times on PerlMonks.

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: Could this be made shorter and cleaner?

2004-08-31 Thread Daniel Staal
--As of Tuesday, August 31, 2004 10:07 AM +0100, Gavin Henry is alleged to 
have said:

P.S. I am now a programmer or a scripter, I am not sure is perl is
programming or scripting? I think programming.
--As for the rest, it is mine.
Short answer: Yes.  (It is at least one of the two.)  ;)
Long answer...  You honestly don't want to get into it.  You start 
devolving into arguments over what is 'scripting' versus what is 
'programming', and from there what is best...

To me, scripting is a sub-class of programming anyway, so why should it 
matter?  ;)

Daniel T. Staal
---
This email copyright the author.  Unless otherwise noted, you
are expressly allowed to retransmit, quote, or otherwise use
the contents for non-commercial purposes.  This copyright will
expire 5 years after the author's death, or in 30 years,
whichever is longer, unless such a period is in excess of
local copyright law.
---
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



RE: Could this be made shorter and cleaner?

2004-08-31 Thread Gavin Henry
stat is a new one for me,  am only on Chapter 7 in Learning Perl.

I will have to come back to this script when I get a bit further.

All good though :-)




-- 
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: Could this be made shorter and cleaner?

2004-08-31 Thread Gavin Henry
Thanks for your time Chris.

I will do the same when I get a bit better for others.

Let me digest this and get back to you.

Gavin.

Chris Devers said:
> On Tue, 31 Aug 2004, Gavin Henry wrote:
>
>> I have split the options up tp $option1 and $option2:
>>
>> http://www.perl.me.uk/downloads/rdiff-script
>>
>> Is this messy?
>
> It's not bad, but it still has a lot of repeated code, which should be a
> warning flag: if you have a lot of code repetition, it should probably
> be moved out into a subroutine.
>
> Hence, instead of this (with adjusted whitespace):
>
>  if ($backup == 0) {
>  my %mails = (
>  To  => "$to",
>  From=> "$from",
>  Subject => "Remote backup complete from $ENV{HOSTNAME} on
> $time",
>  Message => "The remote backup has been completed on
> $ENV{HOSTNAME}"
>  . " on $time with the command:\n\n $rdiff
> @args\n"
>  );
>  sendmail(%mails);
>  # Success finish message
>  print "\n", $sep, "Remote backup complete on $time. E-mail sent
> with details.\n", $sep;
>
>
>  # Create a success logfile
>  open LOG, ">>$datestamp-rdiff-backup-success.log"
>or die "Cannot create logfile: $!";
>  print LOG "Remote backup completed on $time, with the
> command:\n\n$rdiff @args\n\nAn e-mail has been sent.\n";
>  close LOG;
>  print "Logfile created on $time.\n\n";
>
>  } else {  # Failure
>  my %mailf = (
>  To  => "$to",
>  From=> "$from",
>  Subject => "Remote backup failed from $ENV{HOSTNAME} on
> $time",
>  Message => "The remote backup has failed on $ENV{HOSTNAME}"
>  . " on $time with the command:\n\n$rdiff @args\n"
>  );
>  sendmail(%mailf);
>  # Failure finish message
>  print "\n", $sep, "Remote backup failed on $time. E-mail sent
> with details.\n", $sep;
>
>  # Create a failure logfile
>  open LOG, ">>$datestamp-rdiff-backup-failed.log"
>or die "Cannot create logfile: $!";
>  print LOG "Remote backup failed on $time, with the
> command:\n\n$rdiff @args\n\nAn e-mail has been sent.\n";
>  close LOG;
>  print "Logfile created on $time.\n\n";
>  die "Backup exited funny: $?" unless $backup == 0;
>  }
>
> Try this:
>
>  my $to   = $to;
>  my $from = $from;
>  my ( $subject, $message, $log, $logmessage, %stat );
>  if ( $backup == 0 ) {
>  # The backup worked
>  $subject= "Remote backup complete from $ENV{HOSTNAME} on
> $time";
>  $message= "The remote backup has been completed on
> $ENV{HOSTNAME}"
>  . " on $time with the command:\n\n $rdiff @args\n"
>  $log= "$datestamp-rdiff-backup-success.log";
>  $logmessage = "Remote backup completed on $time, with the
> command:\n\n"
>  . "$rdiff @args\n\nAn e-mail has been sent.\n";
>  $stat{now}  = "complete";
>  $stat{then} = "completed";
>  } else {
>  # The backup failed
>  $subject= "Remote backup failed from $ENV{HOSTNAME} on
> $time";
>  $message= ""The remote backup has failed on $ENV{HOSTNAME}"
>  . " on $time with the command:\n\n$rdiff @args\n";
>  $log= "$datestamp-rdiff-backup-failed.log";
>  $logmessage = "Remote backup failed on $time, with the
> command:\n\n"
>  . "$rdiff @args\n\nAn e-mail has been sent.\n";
>  $stat{now}  = "fail";
>  $stat{then} = "failed";
>  }
>
>  # Report status to console, send a status report, write to log
>  print "\n", $sep, $message, $sep;
>  sendmail(
>  To  => "$to",
>  From=> "$from",
>  Subject => "$subject",
>  Message => "$message"
>  );
>
>  open  LOG, ">>$log" or die "Cannot open logfile $log for writing:
> $!";
>  print LOG $logmessage;
>  close LOG;
>  print "Logfile $log created on $time.\n\n";
>  die "Backup exited funny: $?" unless $backup == 0;
>
>
> By keeping the if { ... } else { ... } construct as short as I could get
> it, the code should become easier to read. Because the section that
> actually does work at the end isn't duplicated, I've reduced the chances
> of introducing typos.
>
> You could even (debatably) make things a bit more terse & clear by using
> the %stat variable I introduced, with, e.g.
>
>  # Report status to console, send a status report, write to log
>  print "\n", $sep, $message, $sep;
>  sendmail(
>  To  => "$to",
>  From=> "$from",
>  Subject => "$subject",
>  Message => "The remote backup has $stat{now} on $ENV{HOSTNAME}"
>   . " on $time with the command:\n\n $rdiff @args\n"
>  );
>
>  open  LOG, ">>$log" or die "Cannot o

RE: Could this be made shorter and cleaner?

2004-08-31 Thread Chris Devers
On Tue, 31 Aug 2004, Gavin Henry wrote:
I have split the options up tp $option1 and $option2:
http://www.perl.me.uk/downloads/rdiff-script
Is this messy?
It's not bad, but it still has a lot of repeated code, which should be a 
warning flag: if you have a lot of code repetition, it should probably 
be moved out into a subroutine.

Hence, instead of this (with adjusted whitespace):
if ($backup == 0) {
my %mails = (
To  => "$to",
From=> "$from",
Subject => "Remote backup complete from $ENV{HOSTNAME} on $time",
Message => "The remote backup has been completed on $ENV{HOSTNAME}"
. " on $time with the command:\n\n $rdiff @args\n"
);
sendmail(%mails);
# Success finish message
print "\n", $sep, "Remote backup complete on $time. E-mail sent with 
details.\n", $sep;
# Create a success logfile
open LOG, ">>$datestamp-rdiff-backup-success.log"
  or die "Cannot create logfile: $!";
print LOG "Remote backup completed on $time, with the command:\n\n$rdiff 
@args\n\nAn e-mail has been sent.\n";
close LOG;
print "Logfile created on $time.\n\n";
} else {  # Failure
my %mailf = (
To  => "$to",
From=> "$from",
Subject => "Remote backup failed from $ENV{HOSTNAME} on $time",
Message => "The remote backup has failed on $ENV{HOSTNAME}"
. " on $time with the command:\n\n$rdiff @args\n"
);
sendmail(%mailf);
# Failure finish message
print "\n", $sep, "Remote backup failed on $time. E-mail sent with 
details.\n", $sep;
# Create a failure logfile
open LOG, ">>$datestamp-rdiff-backup-failed.log"
  or die "Cannot create logfile: $!";
print LOG "Remote backup failed on $time, with the command:\n\n$rdiff @args\n\nAn 
e-mail has been sent.\n";
close LOG;
print "Logfile created on $time.\n\n";
die "Backup exited funny: $?" unless $backup == 0;
}
Try this:
my $to   = $to;
my $from = $from;
my ( $subject, $message, $log, $logmessage, %stat );
if ( $backup == 0 ) {
# The backup worked
$subject= "Remote backup complete from $ENV{HOSTNAME} on $time";
$message= "The remote backup has been completed on $ENV{HOSTNAME}"
. " on $time with the command:\n\n $rdiff @args\n"
$log= "$datestamp-rdiff-backup-success.log";
$logmessage = "Remote backup completed on $time, with the command:\n\n"
. "$rdiff @args\n\nAn e-mail has been sent.\n";
$stat{now}  = "complete";
$stat{then} = "completed";
} else {
# The backup failed
$subject= "Remote backup failed from $ENV{HOSTNAME} on $time";
$message= ""The remote backup has failed on $ENV{HOSTNAME}"
. " on $time with the command:\n\n$rdiff @args\n";
$log= "$datestamp-rdiff-backup-failed.log";
$logmessage = "Remote backup failed on $time, with the command:\n\n"
. "$rdiff @args\n\nAn e-mail has been sent.\n";
$stat{now}  = "fail";
$stat{then} = "failed";
}
# Report status to console, send a status report, write to log
print "\n", $sep, $message, $sep;
sendmail(
To  => "$to",
From=> "$from",
Subject => "$subject",
Message => "$message"
);
open  LOG, ">>$log" or die "Cannot open logfile $log for writing: $!";
print LOG $logmessage;
close LOG;
print "Logfile $log created on $time.\n\n";
die "Backup exited funny: $?" unless $backup == 0;
By keeping the if { ... } else { ... } construct as short as I could get 
it, the code should become easier to read. Because the section that 
actually does work at the end isn't duplicated, I've reduced the chances 
of introducing typos.

You could even (debatably) make things a bit more terse & clear by using 
the %stat variable I introduced, with, e.g.

# Report status to console, send a status report, write to log
print "\n", $sep, $message, $sep;
sendmail(
To  => "$to",
From=> "$from",
Subject => "$subject",
Message => "The remote backup has $stat{now} on $ENV{HOSTNAME}"
 . " on $time with the command:\n\n $rdiff @args\n"
);
open  LOG, ">>$log" or die "Cannot open logfile $log for writing: $!";
print LOG "Remote backup $stat{then} on $time, with the command:\n\n"
. "$rdiff @args\n\nAn e-mail has been sent.\n";
close LOG;
print "Logfile $log created on $time.\n\n";
die "Backup exited funny: $?" unless $backup == 0;
The main benefit of this is that you can then eliminate the $message and 
$logmessage variables, so the "if { ... } else { ... }" block gets even 
shorter, and you move even closer to having the common c

RE: How do i run shell command

2004-08-31 Thread Wiggins d Anconia
> 
> 
> Chris,
> 
> You are exactly right, that is a useless use of cat, old habits die
> hard. And of course you are correct in that it can be done entirely in
> perl, the availability of the shell cmd wc makes us lazy, and we don't
> want to code what we can just call from the system.
> 
> Chris Hood
> 

Except laziness is a virtue, this is just insufficient code, not the
"good" laziness. If you coded it up the way it *should* be done for
portability, security, proper error handling, etc. it would in the end
be longer.

my @array;
tie @array, 'Tie::File', $filename or die "Can't tie file: $!";
my $length = @array;

Tough to beat

http://danconia.org

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




Perl Binary

2004-08-31 Thread Eduardo Vázquez Rodríguez
Hello everybody out there using Perl- Im doing a perl scripts, which 
objective is to parse text.

I am looking for a way of creating a "perl binary", my intention is that 
no one can read the scripts in a human readable way.

Thanks in advance
--
Eduardo Vázquez Rodríguez <[EMAIL PROTECTED]>
Consultoría Implantación
Tel. 5322 5200
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



grabbing programs output for logfile

2004-08-31 Thread Gavin Henry
Hi all,

I thought I'd start a new thread for this one:

my $backup = system( $rdiff, @args);

Could I use $backup to write to my logfile?

Gavin.

-- 
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: How do i run shell command

2004-08-31 Thread Radhika Sambamurti
Hi,
was trying to reproduce the code below.
I was wondering what the 1 is doing before the while. Is it the exit
status of the while, that is until eof is reached and exit code = 1 ?

thanks,
radhika

>  If you're not reading from any other files, you don't need the
> $count
>  variable in this case. The special variable $. holds the number of
>  lines read since a filehandle was last explicitly closed:
>
>  1 while ;
>  $count = $.;
>
>  This reads all the records in the file and discards them.
>
> But if you really do need to do this via a system command -- you don't,
> but I'll play along -- then the command as you've given it is what is
> known as a Useless Use Of Cat.
>
> This command --
>
>  cat file | wc -l
>
> -- is equivalent to this one --
>
>  wc -l file
>
> -- but the latter invokes less overhead, and so should be a bit faster.
>
> Unless you really are conCATenating a chain of files together, most
> commands of the form "cat foo | cmd" can be rewritten as "cmd foo" or,
> maybe, "cmd < foo".
>
>
>
> --
> Chris Devers  [EMAIL PROTECTED]
> http://devers.homeip.net:8080/blog/
>
> np: 'It's Not Easy Being Green (lo-fi midi version)'
>   by Kermit
>   from 'The Muppet Movie Soundtrack'
>
>
>
>
> Chris,
>
> You are exactly right, that is a useless use of cat, old habits die
> hard. And of course you are correct in that it can be done entirely in
> perl, the availability of the shell cmd wc makes us lazy, and we don't
> want to code what we can just call from the system.
>
> Chris Hood
>
>
>
>
> --
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>  
>
>
>


-- 
It's all a matter of perspective. You can choose your view by choosing
where to stand.
Larry Wall
---

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




RE: delete all lines in a file save it come out

2004-08-31 Thread Jim
 
> 
> On Aug 31, Jim said:
> 
> >open (FILE, "+>",  $file) or die "cannot open $file: $!";
> 
> I think you want "+>>" there, or else it will overwrite the 
> contents of the file and you won't be able to determine how 
> many lines there were originally.

Thanks.  I was not sure what he was trying to do. 

> 
> >flock (FILE, 2) or die "cannot flock $file: $!";
> 
> For safety's sake, use Fcntl's flock() constants.

I ususally do, but got a little lazy on the answer :)
Thanks


---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.745 / Virus Database: 497 - Release Date: 8/27/2004
 


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




RE: Could this be made shorter and cleaner?

2004-08-31 Thread Gavin Henry
> Since there's more than one argument to system(), the shell is bypassed,
> and
> execve(2) sees a single file name "/etc/services /etc/protocols" instead
> of
> two separate file names. Hence, the error message.
>

I have split the options up tp $option1 and $option2:

http://www.perl.me.uk/downloads/rdiff-script

Is this messy?

Gavin.


-- 
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: Could this be made shorter and cleaner?

2004-08-31 Thread Gavin Henry
Bob Showalter said:
> Gavin Henry wrote:
>> On Tuesday 31 Aug 2004 01:51, you wrote:
>> > 2. The way you're calling system() looks odd. You're using more
>> > than one arg, which is a signal to bypass the shell. But your
>> > second arg looks like it needs shell processing. Does this actually
>> > work?
>>
>> Yup, out of the cookbook.
>
> Odd. Which cookbook?

2 and 3:

Recipe 16.2 in version ":

To avoid the shell, call system with a list of arguments:

$status = system($program, $arg1, $arg);
die "$program exited funny: $?" unless $status == 0;

The returned status value is not just the exit value: it includes the
signal number (if any) that the process died from. This is the same value
that wait sets $? to. See Recipe 16.19 to learn how to decode this value.

>
> Here's a simple illustration of what I'm talking about.
>
> Consider a simple command like
>
>head /etc/services /etc/protocols
>
> This works, as it passes the command line to the shell for processing
>
>$ perl -e 'system "head /etc/services /etc/protocols"'
>
> This also works, as I'm splitting the arguments myself:
>
>$ perl -e 'system "head", "/etc/services", "/etc/protocols"'
>
> But this (which is similar to what you're doing) doesn't work:
>
>$ perl -e 'system "head", "/etc/services /etc/protocols"'
>head: /etc/services /etc/protocols: No such file or directory
>
> Since there's more than one argument to system(), the shell is bypassed,
> and
> execve(2) sees a single file name "/etc/services /etc/protocols" instead
> of
> two separate file names. Hence, the error message.

I get you now. rdiff-backup thinks -v5 --print-statistics in one arg, not
two.

>
> --
> 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: How do i run shell command

2004-08-31 Thread christopher . l . hood



-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] 
Sent: Tuesday, August 31, 2004 12:10 AM
To: [EMAIL PROTECTED]
Subject: Re: How do i run shell command


It works for me . Thanks

Sudhakar Gajjala





Chris Devers <[EMAIL PROTECTED]> on 08/30/2004 10:47:55 PM

Please respond to [EMAIL PROTECTED]

To:Sudhakar Gajjala/C/[EMAIL PROTECTED]
cc:[EMAIL PROTECTED]
Subject:Re: How do i run shell command


On Mon, 30 Aug 2004 [EMAIL PROTECTED] wrote:

> I was trying to run System command from my perl Script . As i have
pipe
( |
> Anybody help me how to run shell command in Perl
>
> Here is the command :  system "cat $filename | wc -l";

You realize, of course, that this can be done entirely in Perl ?

Quoting from the excellent _Perl Cookbook_:

 [...] you can emulate wc by opening up and reading the file
yourself:

 open(FILE, "< $file") or die "can't open $file: $!";
 $count++ while ;
 # $count now holds the number of lines read

 Another way of writing this is:

 open(FILE, "< $file") or die "can't open $file: $!";
 for ($count=0; ; $count++) { }

 If you're not reading from any other files, you don't need the
$count
 variable in this case. The special variable $. holds the number of
 lines read since a filehandle was last explicitly closed:

 1 while ;
 $count = $.;

 This reads all the records in the file and discards them.

But if you really do need to do this via a system command -- you don't,
but I'll play along -- then the command as you've given it is what is
known as a Useless Use Of Cat.

This command --

 cat file | wc -l

-- is equivalent to this one --

 wc -l file

-- but the latter invokes less overhead, and so should be a bit faster.

Unless you really are conCATenating a chain of files together, most
commands of the form "cat foo | cmd" can be rewritten as "cmd foo" or,
maybe, "cmd < foo".



--
Chris Devers  [EMAIL PROTECTED]
http://devers.homeip.net:8080/blog/

np: 'It's Not Easy Being Green (lo-fi midi version)'
  by Kermit
  from 'The Muppet Movie Soundtrack'




Chris,

You are exactly right, that is a useless use of cat, old habits die
hard. And of course you are correct in that it can be done entirely in
perl, the availability of the shell cmd wc makes us lazy, and we don't
want to code what we can just call from the system.

Chris Hood




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




RE: delete all lines in a file save it come out

2004-08-31 Thread Jeff 'japhy' Pinyan
On Aug 31, Jim said:

>open (FILE, "+>",  $file) or die "cannot open $file: $!";

I think you want "+>>" there, or else it will overwrite the contents of
the file and you won't be able to determine how many lines there were
originally.

>flock (FILE, 2) or die "cannot flock $file: $!";

For safety's sake, use Fcntl's flock() constants.

-- 
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: delete all lines in a file save it come out

2004-08-31 Thread Jeff 'japhy' Pinyan
On Aug 31, [EMAIL PROTECTED] said:

>Well if all you want to do is count the number of lines in the file then
>zero out the file, the easiest way that I can think of would be to use a
>couple of system calls like this.

No, there is no reason to make any system calls at all.

  open FILE, "< $file" or die "can't read $file: $!";
  1 while ;
  my $lines = $.;
  close FILE;

That's one of a couple ways to do it.

The code you've posted has NUMEROUS errors.

>$logfile = myfile.txt;

You should have quoted that.

>$numlines = system(`cat $logfile |wc -l`)|| die "Cannot get number of
>lines\n";

That doesn't work at all.  You've combined system() with ``, and on top of
that, you're using || with system(), which is the wrong logical operator
to use.

  chomp(my $lines = `cat $logfile | wc -l`);

That works, but it's still more work that it's worth.  You can't use
system() for this task, because it does NOT return the output of the
command to you.

>system(`cp /dev/null $logfile`) || die "Cannot zero load file\n";

Again, same errors.  And when you DO use system(), you want to use &&
instead of ||:

  system("some system command") && die "system failed: $!";

or else

  system("some system command") == 0 || die "system failed: $!";

-- 
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: delete all lines in a file save it come out

2004-08-31 Thread Jeff 'japhy' Pinyan
On Aug 31, [EMAIL PROTECTED] said:

>open(FILE, "> $logfile") or die "Couldn't open $logfile : $!\n";   # This 
> logfile keeps appending in a linux m/c
>flock(FILE,2);
>while (sysread FILE, $buffer, 4096) {
>   $lines += ($buffer =~ tr/\n//);
>}

This makes NO sense.  You've opened the file for *writing*, not reading.
I think what you want to do is:

  use Fcntl;

  open FILE, "+>> $logfile" or die "can't r/w append to $logfile: $!";
  flock FILE, LOCK_EX;
  seek FILE, 0, 0;  # you need to go to the front first
  1 while ;
  $lines = $.;
  seek FILE, 0, 0;
  truncate FILE, 0;
  print FILE "whatever\n";
  close FILE;

-- 
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: Could this be made shorter and cleaner?

2004-08-31 Thread Bob Showalter
Gavin Henry wrote:
> On Tuesday 31 Aug 2004 01:51, you wrote:
> > 2. The way you're calling system() looks odd. You're using more
> > than one arg, which is a signal to bypass the shell. But your
> > second arg looks like it needs shell processing. Does this actually
> > work? 
> 
> Yup, out of the cookbook.

Odd. Which cookbook?

Here's a simple illustration of what I'm talking about.

Consider a simple command like 

   head /etc/services /etc/protocols

This works, as it passes the command line to the shell for processing

   $ perl -e 'system "head /etc/services /etc/protocols"'

This also works, as I'm splitting the arguments myself:

   $ perl -e 'system "head", "/etc/services", "/etc/protocols"'

But this (which is similar to what you're doing) doesn't work:

   $ perl -e 'system "head", "/etc/services /etc/protocols"'   
   head: /etc/services /etc/protocols: No such file or directory

Since there's more than one argument to system(), the shell is bypassed, and
execve(2) sees a single file name "/etc/services /etc/protocols" instead of
two separate file names. Hence, the error message.

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




Re: Could this be made shorter and cleaner?

2004-08-31 Thread Gunnar Hjalmarsson
Jenda Krynicky wrote:
From: Chris Devers <[EMAIL PROTECTED]>
Just say no to mailing list attachments -- if you have a document
longer than can reasonably fit into an email, put it on the web
& post a URL.
Not everyone has his own pages to put that to and registering on a
free web hosting just to be able to ask for help on a script looks
a bit too much to me.
Does it? To me it does not.
Anyway if the code is too long to fit in the body of the email it's
too long for people to read.
True in most cases. But for those rare occations when it's motivated
to make a long script available, it's reasonable to require that the
person who seeks help make sufficient efforts to make it both easy and
secure to assist.
( I did change my mind, didn't I? :) )
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



RE: delete all lines in a file save it come out

2004-08-31 Thread Jim
 
> Hi ,
> I have a problem in deleting all the lines in a file and saving it .
> Actually my log file keep appending all the messages for that 
> i need to clean it up i.e delete all lines in it save it . 
> when i do this initially file shows zero bytes , but as soon 
> as the next message appends ,, file sizes jumps to the actual 
> size and not from zero . I tried this with
> flock() option also . for Somereasons it is not working I 
> could see some junk characters like this in the file
> 
>
> [EMAIL PROTECTED]@[EMAIL PROTECTED]@[EMAIL PROTECTED]@[EMAIL PROTECTED]@[EMAIL 
> PROTECTED]@^  Because of these characters, file size 
> will not go to zero bytes.
> 
> here is my script... Can somebody help on this ..
> 
> for my $logfile (@filelist) {
> $lines = 0;
> open(FILE, "> $logfile") or die "Couldn't open 
> $logfile : $!\n";   # This logfile keeps appending in a linux m/c
> flock(FILE,2);
> while (sysread FILE, $buffer, 4096) {
>$lines += ($buffer =~ tr/\n//);
> }
>print FILE Sudhakar;
> flock(FILE,8);
> close(FILE);
> print "No. of lines in $logfile", $lines, "\n";
> # system "vi $logfile +delete$lines +wq"; # Delete 
> all the lines in the file  ...  This command will never work 
> for me. Dont know }
> 

Not quit sure what you are asking. AND you may have a race condition going
on as well. As far as zeroing the file, have you tried truncate? Something
like this maybe?

open (FILE, "+>",  $file) or die "cannot open $file: $!";  
flock (FILE, 2) or die "cannot flock $file: $!";
 Do stuff
seek FILE, 0, 0;
truncate FILE, 0;
. Do stuff


Also read up on some docs
perldoc -f open
perldoc -f flock
perldoc -f sysopen



---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.745 / Virus Database: 497 - Release Date: 8/27/2004
 


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




Re: Could this be made shorter and cleaner?

2004-08-31 Thread Gavin Henry
John W. Krahn said:
> Gavin Henry wrote:
>>>It looks like 99% of the code in both blocks is exactly the same.  You
>>>should
>>>factor out duplicated code.
>>>
>>>my $msg = $backup ? 'failed' : 'completed';
>>>
>>>my %mails = (
>>> To  => $to,
>>> From=> $from,
>>> Subject => "Remote backup $msg from $ENV{HOSTNAME} on $time",
>>> Message => "The remote backup has $msg on $ENV{HOSTNAME} on $time
>>>with
>>>the command:\n\n $rdiff @args\n"
>>> );
>>>sendmail( %mails );
>>># finish message
>>>print "\n", $separator, "Remote backup $msg on $time. E-mail sent with
>>>details.\n", $separator;
>>
>> Thanks John and Chris. Chris, I have gone for John method of using the
>> $seperator, as I will use that more in this script when I add more
>> features, thanks for the pointer on here documents though.
>>
>> I have taken on board all your suggestions, but I still have two
>> questions:
>>
>> 1. How does the above code get the return code from rdiff to tell if it
>> failed or passed?
>
> The same way it did before.
>
>> Is this the $backup ? part, i.e. failed first, then
>> completed second?
>
> It seems like you may be confused by the conditional operator.  The
> statement:
>
> my $msg = $backup ? 'failed' : 'completed';
>
> Is short for:
>
> my $msg;
> if ( $backup == 0 ) {
>  $msg = 'completed';
>  }
> else {
>  $msg = 'failed';
>  }

Ah, got it. Do I just expand on the failure and completed message and add
in what I had before?

>
>> 2. use POSIX qw(strftime); I got this from Perl Cookbook. I take it this
>> is calling the POSIX strftime and putting it in a list,
>
> No, this is telling perl that the only function we want to import from the
> POSIX module is 'strftime'.

Got it.

>> so when I select
>> %T etc. it is picking it from the list? Why does it fail if I put use
>> POSIX; and put qw(strftime); somewhere else.
>
> Because the list of function names must follow the module name.
>
> perldoc -f use
>

Will do.

Lastly, the scripts fails when I uncomment $options, saying verbosity
needs a number, when I have it -v5 --print-statistics. Is this the wrong
way to pass the option?

Gavin.


-- 
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: delete all lines in a file save it come out

2004-08-31 Thread christopher . l . hood


-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] 
Sent: Tuesday, August 31, 2004 6:50 AM
To: [EMAIL PROTECTED]
Subject: delete all lines in a file save it come out

Hi ,
I have a problem in deleting all the lines in a file and saving it .
Actually my log file keep appending all the messages for that i need to
clean it up i.e delete all lines in it save it . when i do this
initially
file shows zero bytes , but as soon as the next message appends ,, file
sizes jumps to the actual size and not from zero . I tried this with
flock() option also . for Somereasons it is not working I could see some
junk characters like this in the file

[EMAIL PROTECTED]@[EMAIL PROTECTED]@[EMAIL PROTECTED]@[EMAIL PROTECTED]@[EMAIL 
PROTECTED]@^
[EMAIL PROTECTED]@[EMAIL PROTECTED]@[EMAIL PROTECTED]@[EMAIL PROTECTED]@[EMAIL 
PROTECTED]@^
[EMAIL PROTECTED]@[EMAIL PROTECTED]@[EMAIL PROTECTED]@[EMAIL PROTECTED]@[EMAIL 
PROTECTED]@^
[EMAIL PROTECTED]@[EMAIL PROTECTED]@[EMAIL PROTECTED]@[EMAIL PROTECTED]@[EMAIL 
PROTECTED]@^  Because of these characters, file size will not
go to zero bytes.
[EMAIL PROTECTED]@[EMAIL PROTECTED]@[EMAIL PROTECTED]@[EMAIL PROTECTED]@[EMAIL 
PROTECTED]@^
[EMAIL PROTECTED]@[EMAIL PROTECTED]@[EMAIL PROTECTED]@[EMAIL PROTECTED]@[EMAIL 
PROTECTED]@^
[EMAIL PROTECTED]@[EMAIL PROTECTED]@[EMAIL PROTECTED]@[EMAIL PROTECTED]@[EMAIL 
PROTECTED]@^

here is my script... Can somebody help on this ..

for my $logfile (@filelist) {
$lines = 0;
open(FILE, "> $logfile") or die "Couldn't open $logfile : $!\n";
# This logfile keeps appending in a linux m/c
flock(FILE,2);
while (sysread FILE, $buffer, 4096) {
   $lines += ($buffer =~ tr/\n//);
}
   print FILE Sudhakar;
flock(FILE,8);
close(FILE);
print "No. of lines in $logfile", $lines, "\n";
# system "vi $logfile +delete$lines +wq"; # Delete all the lines
in the file  ...  This command will never work for me. Dont know
}


Sudhakar Gajjala


Well if all you want to do is count the number of lines in the file then
zero out the file, the easiest way that I can think of would be to use a
couple of system calls like this.

$logfile = myfile.txt;

$numlines = system(`cat $logfile |wc -l`)|| die "Cannot get number of
lines\n";

print $numlines;

system(`cp /dev/null $logfile`) || die "Cannot zero load file\n";

Of course since you seem to have a list of files you will have to modify
this, but the general idea is there.

And of course this script is dependent on your machine being a unix box,
which you didn't mention what kind of OS you were running.



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




Re: Could this be made shorter and cleaner?

2004-08-31 Thread John W. Krahn
Gavin Henry wrote:
It looks like 99% of the code in both blocks is exactly the same.  You
should
factor out duplicated code.
my $msg = $backup ? 'failed' : 'completed';
my %mails = (
To  => $to,
From=> $from,
Subject => "Remote backup $msg from $ENV{HOSTNAME} on $time",
Message => "The remote backup has $msg on $ENV{HOSTNAME} on $time
with
the command:\n\n $rdiff @args\n"
);
sendmail( %mails );
# finish message
print "\n", $separator, "Remote backup $msg on $time. E-mail sent with
details.\n", $separator;
Thanks John and Chris. Chris, I have gone for John method of using the
$seperator, as I will use that more in this script when I add more
features, thanks for the pointer on here documents though.
I have taken on board all your suggestions, but I still have two questions:
1. How does the above code get the return code from rdiff to tell if it
failed or passed?
The same way it did before.
Is this the $backup ? part, i.e. failed first, then
completed second?
It seems like you may be confused by the conditional operator.  The statement:
my $msg = $backup ? 'failed' : 'completed';
Is short for:
my $msg;
if ( $backup == 0 ) {
$msg = 'completed';
}
else {
$msg = 'failed';
}
2. use POSIX qw(strftime); I got this from Perl Cookbook. I take it this
is calling the POSIX strftime and putting it in a list,
No, this is telling perl that the only function we want to import from the 
POSIX module is 'strftime'.

so when I select
%T etc. it is picking it from the list? Why does it fail if I put use
POSIX; and put qw(strftime); somewhere else.
Because the list of function names must follow the module name.
perldoc -f use

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



delete all lines in a file save it come out

2004-08-31 Thread Sudhakar . Gajjala
Hi ,
I have a problem in deleting all the lines in a file and saving it .
Actually my log file keep appending all the messages for that i need to
clean it up i.e delete all lines in it save it . when i do this initially
file shows zero bytes , but as soon as the next message appends ,, file
sizes jumps to the actual size and not from zero . I tried this with
flock() option also . for Somereasons it is not working I could see some
junk characters like this in the file

[EMAIL PROTECTED]@[EMAIL PROTECTED]@[EMAIL PROTECTED]@[EMAIL PROTECTED]@[EMAIL 
PROTECTED]@^
[EMAIL PROTECTED]@[EMAIL PROTECTED]@[EMAIL PROTECTED]@[EMAIL PROTECTED]@[EMAIL 
PROTECTED]@^
[EMAIL PROTECTED]@[EMAIL PROTECTED]@[EMAIL PROTECTED]@[EMAIL PROTECTED]@[EMAIL 
PROTECTED]@^
[EMAIL PROTECTED]@[EMAIL PROTECTED]@[EMAIL PROTECTED]@[EMAIL PROTECTED]@[EMAIL 
PROTECTED]@^  Because of these characters, file size will not go to zero bytes.
[EMAIL PROTECTED]@[EMAIL PROTECTED]@[EMAIL PROTECTED]@[EMAIL PROTECTED]@[EMAIL 
PROTECTED]@^
[EMAIL PROTECTED]@[EMAIL PROTECTED]@[EMAIL PROTECTED]@[EMAIL PROTECTED]@[EMAIL 
PROTECTED]@^
[EMAIL PROTECTED]@[EMAIL PROTECTED]@[EMAIL PROTECTED]@[EMAIL PROTECTED]@[EMAIL 
PROTECTED]@^

here is my script... Can somebody help on this ..

for my $logfile (@filelist) {
$lines = 0;
open(FILE, "> $logfile") or die "Couldn't open $logfile : $!\n";   # This 
logfile keeps appending in a linux m/c
flock(FILE,2);
while (sysread FILE, $buffer, 4096) {
   $lines += ($buffer =~ tr/\n//);
}
   print FILE Sudhakar;
flock(FILE,8);
close(FILE);
print "No. of lines in $logfile", $lines, "\n";
# system "vi $logfile +delete$lines +wq"; # Delete all the lines in the file  
...  This command will never work for me. Dont know
}


Sudhakar Gajjala





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




Re: Could this be made shorter and cleaner?

2004-08-31 Thread Jenda Krynicky
From: Chris Devers <[EMAIL PROTECTED]>
> On Tue, 31 Aug 2004, Gunnar Hjalmarsson wrote:
> 
> > Chris Devers wrote:
> >> Don't send attachments?
> >> 
> >> There's no telling what an attachment contains these days;
> >
> > A simple check of the message source is sufficient to preclude virus
> > etc.
> 
> But why should people have to do that? A simple check of the source
> in, say, Outlook might be enough to fire off a worm these days -- why
> make people risk it when inline plain text isn't a question at all?

Previewing the message could fire of a worm in Outlook, whether there 
is an attachment or not is irrelevant.

- Don't use Outlook
- Install an antivirus
 
> Just say no to mailing list attachments -- if you have a document
> longer than can reasonably fit into an email, put it on the web & post
> a URL.

Not everyone has his own pages to put that to and registering on a 
free web hosting just to be able to ask for help on a script looks a 
bit too much to me.

Besides ... how do you know the URL doesn't point to a malevolent 
page that'll abuse a hole in the browser and install a worm or 
something?

Anyway if the code is too long to fit in the body of the email it's 
too long for people to read. We are all busy people here and if 
someone posts a ten pages long script few people will care to read 
it.

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: Could this be made shorter and cleaner?

2004-08-31 Thread Gavin Henry
> It looks like 99% of the code in both blocks is exactly the same.  You
> should
> factor out duplicated code.
>
> my $msg = $backup ? 'failed' : 'completed';
>
> my %mails = (
>  To  => $to,
>  From=> $from,
>  Subject => "Remote backup $msg from $ENV{HOSTNAME} on $time",
>  Message => "The remote backup has $msg on $ENV{HOSTNAME} on $time
> with
> the command:\n\n $rdiff @args\n"
>  );
> sendmail( %mails );
> # finish message
> print "\n", $separator, "Remote backup $msg on $time. E-mail sent with
> details.\n", $separator;
>

Thanks John and Chris. Chris, I have gone for John method of using the
$seperator, as I will use that more in this script when I add more
features, thanks for the pointer on here documents though.

I have taken on board all your suggestions, but I still have two questions:

1. How does the above code get the return code from rdiff to tell if it
failed or passed? Is this the $backup ? part, i.e. failed first, then
completed second?

2. use POSIX qw(strftime); I got this from Perl Cookbook. I take it this
is calling the POSIX strftime and putting it in a list, so when I select
%T etc. it is picking it from the list? Why does it fail if I put use
POSIX; and put qw(strftime); somewhere else.


Oh, and I have the bug now :-) It's a great felling when your script works!!!

You will be seeing much more of my code in here, so hopefully I will be
learning and not pasting the same mistakes.

P.S. I am now a programmer or a scripter, I am not sure is perl is
programming or scripting? I think programming.

Gavin.

Would anyone actually like a [EMAIL PROTECTED] e-mail address?



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




Problem in output to a process

2004-08-31 Thread Sanjay Upadhyay
Hi All,
greetings.
I am trying to get a kerberos ticket with the help of a perl script, so 
that it is automated. The script works in Redhat however in Suse, I am 
encountering problem, where the kinit process waits for user input, however 
the requirement is that it should not wait as I am writing the password to 
STDIN of the process.
Here is my code, as I am quite new, I must not be doing the right thing 
here. ne help would be most thankfull.
==
#!/usr/bin/env perl
use warnings;

open (WTR, "| kinit [EMAIL PROTECTED] 2> error.txt");
print WTR "password\n";
print WTR "\n";
close WTR;
==
regards
Sanjay Upadhyay
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]