RE: rename and move multiple files

2005-10-24 Thread Timothy Johnson
 
The only change you might have to do for windows (and most of the Perl 
functions will let you slide on this) is that in Windows the delimiter for 
directories is the backslash.
 
To search the entire hard drive, the OP might also want to look into File::Find.
 

-Original Message- 
From: John W. Krahn [mailto:[EMAIL PROTECTED] 
Sent: Sun 10/23/2005 11:19 PM 
To: Perl Beginners 
Cc: 
Subject: Re: rename and move multiple files




UNTESTED (sorry I don't use Windows):


my $dir = '/renoutput';
mkdir $dir or die "mkdir '$dir' $!";

my $count = 1;

for my $file ( glob '/*/output.txt' ) {
rename $file, "$dir/output" . $count++ . '.txt'
or die "Cannot rename '$file' to '$dir/output$count.txt' $!";
}





CPAN module for file upload/download

2005-10-24 Thread Dhanashri Bhate
Hello All!

We have a website, which allows me to upload or download dictionary file.

I am trying to write a perl program to automate the tests for this file
upload/download functionality.

 

Actually on CPAN I looked at the modules by name "HTTP",  some looked useful
( URI::HTTP/HTTPS, LWP::Protocol::HTP/HTTPS) 

but i/m not clear which will be best for me.

 

Could anyone please suggest what module is available on CPAN for this?

 

Thanks,

Dhanashri

 



RE: delete file after on week

2005-10-24 Thread José Pedro Silva Pinto
Hi, ZHAO,

If your system is  Unix or similar, you can use cron (See cron). If Windows, 
you can use task manager

José Pinto

-Original Message-
From: ZHAO, BING [mailto:[EMAIL PROTECTED] 
Sent: domingo, 23 de Outubro de 2005 7:28
Cc: beginners@perl.org
Subject: delete file after on week

Hi:
 I need to delete files older than one week old, I know how to code 
that(with the help 
of many kind people on this list):
 But it only happens when I run the program, there is a chance I 
will not be running 
the program for more than a week. And the dir keeps getting larger(downloading 
files from 
website), I need those files older than 1 week all gone WITHOUT having to type 
./do_it.pl on unix 
command line.
 Any idea on this? It seems pretty unreasonle to me, even. Let me 
know if this is 
something impossible.
 thank you.

bing

-- 
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: CPAN module for file upload/download

2005-10-24 Thread Chris Devers

On Mon, 24 Oct 2005, Dhanashri Bhate wrote:


Could anyone please suggest what module is available on CPAN for this?


Take a look at WWW::Mechanize.



--
Chris Devers

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




RE: Module subclassing

2005-10-24 Thread Charles K. Clarkson
Peter Rabbitson  wrote:


[snipped helpful code]
: And all is well if I create a new number and print it back,
: both bstr() and fmtstr() work just as expected. However any
: arithmetics fails with an "Unknown round mode ''" error. I
: looked at Math::Currency which is a rather simple module
: and I still can't figure out what am I doing wrong.

Can you show us your test cases script, so we can see
it fail?


HTH,

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


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




Re: map/array performance

2005-10-24 Thread Frank Bax

At 10:07 PM 10/23/05, Jeff 'japhy' Pinyan wrote:


On Oct 23, Frank Bax said:

   my $aval=''; map { $aval=$aval.sprintf("%4d",$aSuit{$a}{$_}); } 
@f_seq;


   my $aval=''; foreach $f (@f_seq) { 
$aval=$aval.sprintf("%4d",$aSuit{$a}{$f}); }


You should be using $aval .= here, instead of $aval = $aval .   And as 
John has shown, join() is even better.



Right, but I wasn't able to integrate sprintf and join together (I've 
figured it out since).  This code (from John) runs in 115 seconds (map was 
160, foreach was 195)!


my $format = '%4d' x @f_seq;
sprintf( $format, @{ $aSuit{ $a } }{ @f_seq } ) cmp sprintf( $format, 
@{ $aSuit{ $b } }{ @f_seq } );


THANKS - It has syntax elements that are new to me - I would never have 
come up with this on my own.



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




Re: Module subclassing

2005-10-24 Thread Peter Rabbitson
> [snipped helpful code]
> : And all is well if I create a new number and print it back,
> : both bstr() and fmtstr() work just as expected. However any
> : arithmetics fails with an "Unknown round mode ''" error. I
> : looked at Math::Currency which is a rather simple module
> : and I still can't figure out what am I doing wrong.
> 
> Can you show us your test cases script, so we can see
> it fail?

Certainly. It's a simple as:

use Tools::Currency;
my $one = Tools::Currency->new ('1');
print ($one + 1);

which yields:

perl ./test
Unknown round mode '' at ./test line 3

Changing the two occurences of Tools::Currency to Math::Currency makes 
it work just fine

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




HUP vs signal 9

2005-10-24 Thread Christopher Spears
What is the difference between

kill 1, SIGNAL

and 

kill 9, SIGNAL ?

By reading books and talking to people, I figured out
that kill 1 is the HUP (hang up signal) and kill 9 is
the  kill signal.  Don't they do the same thing (i.e.
terminate a program)?  I was told that kill 1 is a
"nicer" way to end a program than kill 9.


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




RE: Module subclassing

2005-10-24 Thread Charles K. Clarkson
Peter Rabbitson  wrote:

: Charles asked:
:
: : Can you show us your test cases script, so we can see
: : it fail?
: 
: Certainly. It's a simple as:
: 
: use Tools::Currency;
: my $one = Tools::Currency->new ('1');
: print ($one + 1);
: 
: which yields:
: 
: perl ./test
: Unknown round mode '' at ./test line 3
: 
: Changing the two occurences of Tools::Currency to Math::Currency
: makes it work just fine

I think the problem is in the way Math::Currency handles
subclasses. I tried your example with the lines commented out
on your module and got the same result.

package Tools::Currency;

use base qw(Math::Currency);
#use overload '""' => \&bstr;
#
#sub bstr {
#my $self = shift;
#return (Math::BigFloat::bstr ($self));
#}
#
#sub fmtstr {
#my $self = shift;
#return (Math::Currency::bstr ($self));
#}

1;


So, the problem is in the subclassing, not your code. The
difference is in the class name. Look at Math::Currency::new()
to see what is happening when $class equals 'Tools::Currency'
instead of 'Math::Currency'.


HTH,

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


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




Re: HUP vs signal 9

2005-10-24 Thread Wiggins d'Anconia
Christopher Spears wrote:
> What is the difference between
> 
> kill 1, SIGNAL
> 
> and 
> 
> kill 9, SIGNAL ?
> 
> By reading books and talking to people, I figured out
> that kill 1 is the HUP (hang up signal) and kill 9 is
> the  kill signal.  Don't they do the same thing (i.e.
> terminate a program)?  I was told that kill 1 is a
> "nicer" way to end a program than kill 9.
> 
> 

HUP is a catchable signal. Meaning the program receives notification
that a signal has occurred and which signal. This allows the program to
then act in a certain appropriate manner. For example, HUP is often used
to restart a server application such as Apache. Generally the server
will clear its configuration, re-read its configuration, and then
re-perform any startup like stuffs. The KILL (9) signal is not catchable
and causes an immediate death without proper cleanup. It is usually
reserved for a runaway process that can't be killed with one of the
other catchable kill signals like TERM or QUIT.

perldoc perlipc

For more about signals and their handling in Perl.

man -s 7 signal

For more about Unix/POSIX signals.

http://danconia.org

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




Troubles getting a value out of an XML object

2005-10-24 Thread Dave Adams
I am having troubles getting a value out of an XML object.

*Here is my object:*
my $xml = new XML::Simple;
my $data = $xml->XMLin($ResponseDoc);

*Here is the script asking for a snippet of data:*

print Dumper($data->{CreateLock});
**
*Here is the output:*

$VAR1 = { 'DatabaseId' => 'db1', 'RecordNumber' => '23617', 'Id' => 'test'
};
*Question:* How do I get the value of RecordNumber?
 Thanks in advance.
Dave Adams


RE: delete file after on week

2005-10-24 Thread Steve Bertrand

>  I need to delete files older than one week old, 
> I know how to code that(with the help of many kind people on 
> this list):

Here is a single command that will blow files older than 48 hours away
from given directory. You can put as many of these in a single sh script
as you want, then put it in your crontab:

# find /home/me/mydirectory -mtime +48h -type f | xargs rm

Your crontab entry might look like this:

20 22 * * * /home/steve/scripts/rmmail.pl

Which would run the script at 10:20 PM, every day.

HTH,

Steve


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




Re: Troubles getting a value out of an XML object

2005-10-24 Thread Jeff 'japhy' Pinyan

On Oct 24, Dave Adams said:


my $xml = new XML::Simple;
my $data = $xml->XMLin($ResponseDoc);



print Dumper($data->{CreateLock});



$VAR1 = { 'DatabaseId' => 'db1', 'RecordNumber' => '23617', 'Id' => 'test'
};



*Question:* How do I get the value of RecordNumber?


You knew how to get 'CreateLock' from $data, but you don't know how to get 
'RecordNumber' from $data->{CreateLock}?


  my $rec = $data->{CreateLock}->{RecordNumber};

  # or, without the extra ->
  my $rec = $data->{CreateLock}{RecordNumber};

The object is merely a hash of hashrefs (of hashrefs, etc.).

--
Jeff "japhy" Pinyan%  How can we ever be the sold short or
RPI Acacia Brother #734%  the cheated, we who for every service
http://www.perlmonks.org/  %  have long ago been overpaid?
http://princeton.pm.org/   %-- Meister Eckhart

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




Re: rename and move multiple files

2005-10-24 Thread perlwannabe
<>

>> So I suppose I want to do a locate, rename, move.  1)  locate all
>> "output.txt" files on the hard drive; 2) rename each "output.txt" to
>> something unique, and 3) move each renamed file from its original
>> location
>> to a single directory.
>>
>> I have tried a few ways with no success.  Thanks for the help.
>>
>
> It's hard to imagine that you spend  multiple days looking at such an
> easy problem and can't come up with a single line of code to show the
> list. To get you started here's a solution of your problem in bash (you
> do have bash installed on your windows box ?)


WOW!  I didn't "show code" because I have about 4 or 5 different concepts
going, none of which worked.  However, I suppose this "easy problem"  was
too complex for my simple mind.  If you look at the archives, you will
notice that I seldom request help, and am always courteous and thankful
for the assistance.  Perhaps with a simple mind comes common courtesy, and
with a complex mind, such as yours, comes demeaning remarks and rampant
superiority.  I'll take the simple mind any day.


>
> Create a test environment:
> [EMAIL PROTECTED]:~/vuilbak$ for i in 1 2 3 4 5 6 7; do mkdir $i; touch
<>

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




Re: rename and move multiple files

2005-10-24 Thread perlwannabe
<>

>>
>> So I suppose I want to do a locate, rename, move.  1)  locate all
>> "output.txt" files on the hard drive; 2) rename each "output.txt" to
>> something unique, and 3) move each renamed file from its original
>> location
>> to a single directory.
>>
>> I have tried a few ways with no success.  Thanks for the help.
>
> UNTESTED (sorry I don't use Windows):
>
>
> my $dir = '/renoutput';
> mkdir $dir or die "mkdir '$dir' $!";
>
> my $count = 1;
>
> for my $file ( glob '/*/output.txt' ) {
> rename $file, "$dir/output" . $count++ . '.txt'
> or die "Cannot rename '$file' to '$dir/output$count.txt' $!";
> }
>
>

ARRG  OMG!!!  I had code that was very close to this... but I was
using the wildcard (*) in an attempt to rename the file.  Basically, where
you have " . . . "$count++ . '.txt' ..." I was using "$count++ .
'outp*.txt'. . ."  When I removed the wildcard, everything worked
perfectly.  I now have a directory named c:/renoutput with 522 files
numbered output1 through output 522.

Thanks a million.  Worked great and my project is close to getting done.



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




Re: Module subclassing (solved)

2005-10-24 Thread Peter Rabbitson
> I am trying to subclass Math::Currency to change the default bstr() and 
> move it to a different function, so my numbers are not formatted by 
> default (I am unable to just strip existing formatting in a certain 
> situation).
> ...
> However any arithmetics fails with an "Unknown round mode ''" error.

Crap, it was all written in the POD of Math::BigInt under Subclassing. 
Adding the following globals to the class package solved the problem:

our $accuracy = undef;
our $precision = -2;
our $round_mode = 'even';
our $div_scale = 40;



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




Re: Module subclassing (solved)

2005-10-24 Thread Jeff 'japhy' Pinyan

On Oct 24, Peter Rabbitson said:


I am trying to subclass Math::Currency to change the default bstr() and
move it to a different function, so my numbers are not formatted by
default (I am unable to just strip existing formatting in a certain
situation).
...
However any arithmetics fails with an "Unknown round mode ''" error.


Crap, it was all written in the POD of Math::BigInt under Subclassing.
Adding the following globals to the class package solved the problem:

our $accuracy = undef;
our $precision = -2;
our $round_mode = 'even';
our $div_scale = 40;


That's poor planning, in my opinion.  Those should be set up as methods of 
the object. :(


The idiom:

  package Class::Subclass;
  use base 'Class';
  1;

should be universal, no?

--
Jeff "japhy" Pinyan%  How can we ever be the sold short or
RPI Acacia Brother #734%  the cheated, we who for every service
http://www.perlmonks.org/  %  have long ago been overpaid?
http://princeton.pm.org/   %-- Meister Eckhart

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




Re: HUP vs signal 9

2005-10-24 Thread John W. Krahn
Christopher Spears wrote:
> What is the difference between
> 
> kill 1, SIGNAL
> 
> and 
> 
> kill 9, SIGNAL ?
> 
> By reading books and talking to people, I figured out
> that kill 1 is the HUP (hang up signal) and kill 9 is
> the  kill signal.  Don't they do the same thing (i.e.
> terminate a program)?  I was told that kill 1 is a
> "nicer" way to end a program than kill 9.

Actually SIGTERM is the "nicer" way to end a program and if that doesn't work
then use SIGKILL.  SIGHUP is usually used to tell a program to reread its
configuration files and start anew.


John
-- 
use Perl;
program
fulfillment

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




extract zip file

2005-10-24 Thread Pant, Hridyesh
Hi All,
How to extract zip file using perl program...

Thanks
Hridyesh

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




Re: extract zip file

2005-10-24 Thread Chris Devers

On Tue, 25 Oct 2005, Pant, Hridyesh wrote:


How to extract zip file using perl program...


Write the program, then run it.

Have you tried writing it yet?

Have you tried searching CPAN for helpful modules?


--
Chris Devers

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




Re: extract zip file

2005-10-24 Thread Tommy Nordgren


Oct 25, 2005 kl. 6:21 AM skrev Pant, Hridyesh:


Hi All,
How to extract zip file using perl program...

Thanks
Hridyesh

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





system '/usr/bin/unzip',@OPTIONS,$zipfile;

-
This sig is dedicated to the advancement of Nuclear Power
Tommy Nordgren
[EMAIL PROTECTED]




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




Create a file

2005-10-24 Thread M. Lewis
I'm trying to create a file of a certain size. Specifically 15MB for 
some testing purposes. I want this file to have random characters. I'm 
sure it would be easier (faster) to use the same character. What I'm 
finding is my code is terribly slow to create a 15MB file.


Is there a better / more efficient way ?

Thanks,
Mike


#!/usr/bin/perl

use strict;
use warnings;

#PURPOSE - Create a file of a certain size (random characters)

my $file = './test.txt';
my $size = 15728640;   # 15MB

open (OUT,">$file") || die "Cannot open $file :$!";

print OUT (map+chr(ord('a')+rand 26),1..$size);

close OUT;


--

 Avoid the Fortran arithmetic IF (or better yet, just avoid Fortran).
  00:45:04 up 3 days,  7:56,  5 users,  load average: 1.92, 1.58, 0.92

 Linux Registered User #241685  http://counter.li.org

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




RE: extract zip file

2005-10-24 Thread Pant, Hridyesh
Thanks..
Now I want to change the string in file.
orgtext="C:\\test";
newtext="/bin/old";
I tired $intext =~ s/$orgtext/$newtext/ms; but this is not working..
Any help..
Regards
Hridyesh


-Original Message-
From: Chris Devers [mailto:[EMAIL PROTECTED] 
Sent: 25 October 2005 10:21
To: Pant, Hridyesh
Cc: beginners@perl.org
Subject: Re: extract zip file


On Tue, 25 Oct 2005, Pant, Hridyesh wrote:

> How to extract zip file using perl program...

Write the program, then run it.

Have you tried writing it yet?

Have you tried searching CPAN for helpful modules?


-- 
Chris Devers

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