Re: help with zip files and file sizes

2011-01-31 Thread Parag Kalra
You should probably use a Zip parser -

http://search.cpan.org/search?mode=module&query=Archive%3A%3AZip

~Parag



On Mon, Jan 31, 2011 at 11:15 PM, Balachandran Sivakumar <
benignb...@gmail.com> wrote:

> Hi,
>
> I have 2 versions of a zip file(same archive, but with updates.).
> I need to compare the 2 versions. I adopted the following approach.
> The files are v1.zip and v2.zip.
>
> 1) extract to /tmp/v1 and /tmp/v2
> 2) Get the list of files in /tmp/v1 and store to @files_v1
> 3) Get the list of files in /tmp/v2 and store to @files_v2
> 4) Using List::Compare, I got the files added/removed.
>
> But I need to compare the sizes of files that are common to both
> archives. How can I do that ? Thanks
>
> --
> Thank you
> Balachandran Sivakumar
>
> Arise Awake and stop not till the goal is reached.
>
> Mail: benignb...@gmail.com
> Blog: http://benignbala.wordpress.com/
>
> --
> To unsubscribe, e-mail: beginners-unsubscr...@perl.org
> For additional commands, e-mail: beginners-h...@perl.org
> http://learn.perl.org/
>
>
>


Re: Renaming with a specific spec

2011-01-31 Thread John W. Krahn

Jim Gibson wrote:


You are not likely to find such a specific tool. However, you can
develop your own tool.

Here is a renaming program adapted from the one in the Perl Cookbook,
Recipe 9.9:

#!/usr/bin/perl
#
# rename
#
# perl script to rename files
#
# Usage:
#
# rename perlexpr [files]
#

($op = shift) ||
die
"Usage: rename perlexpr [filenames]
where perlexpr is any perl expression that modifies \$\_:
's/old/new/'
'\$\_ .= \".ext\"'
'tr[A-Z][a-z]'\n";


You should use a here doc so you don't have to backslash everything:

my $op = shift or die <<'USAGE';
Usage: rename perlexpr [filenames]
where perlexpr is any perl expression that modifies $_:
   's/old/new/'
   '$_ .= ".ext"'
   'tr/A-Z/a-z/'
USAGE



if( !@ARGV ) {
@ARGV = ;
chop( @ARGV );


You should use chomp instaed of chop:

chomp( @ARGV =  );



}
for( @ARGV ) {
$was = $_;
eval $op;
die $@ if $@;
rename($was,$_) unless $was eq $_;
}


That looks a lot like Larry's rename script which is distributed with 
some versions of Linux.




John
--
Any intelligent fool can make things bigger and
more complex... It takes a touch of genius -
and a lot of courage to move in the opposite
direction.   -- Albert Einstein

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




help with zip files and file sizes

2011-01-31 Thread Balachandran Sivakumar
Hi,

 I have 2 versions of a zip file(same archive, but with updates.).
I need to compare the 2 versions. I adopted the following approach.
The files are v1.zip and v2.zip.

1) extract to /tmp/v1 and /tmp/v2
2) Get the list of files in /tmp/v1 and store to @files_v1
3) Get the list of files in /tmp/v2 and store to @files_v2
4) Using List::Compare, I got the files added/removed.

But I need to compare the sizes of files that are common to both
archives. How can I do that ? Thanks

-- 
Thank you
Balachandran Sivakumar

Arise Awake and stop not till the goal is reached.

Mail: benignb...@gmail.com
Blog: http://benignbala.wordpress.com/

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




sorting report

2011-01-31 Thread Chris Stinemetz
I would like to sort my final report in the following order:

$data[31],$data[32],$data[38]

How would I add this into my following program to get the report sorted this 
way?

Thanks in advance.

Chris

#!/usr/bin/perl

use warnings;
#use strict;
use FileHandle;
use IO::Handle;

RAW->format_lines_per_page(100);


format RAW_TOP =
@|||
"##--> Smart Phone report. <--##",
Market  ESN/MIN  Mobile CellSectorCarrier Bytes

.


format RAW =
@ @|| @|| @ @ @||| @
$mkt,$mtype,$smartPhone,$cell,$sector,$carrier,$rlptxat
.

# SmartPhone type Hash based on ESN or MEID HEX number
my %smartPhone = (
   "CURVE850a" => { start => "a01ca64E38",
   end   => "a0255c29c0", },
   "KYOM6000" => { start => "a012b71b00",
   end   => "a012fef1a0", },
   "CURVE850" => { start => "001388",
   end   => "001770", },
#   "Huawei"   => { start => "a0130fa7d0",
#   end   => "001770", },
);

 Market assignment Hash based on cell number
my %marketInfo = (
MCI => { start => 1,
 end   => 299, },
STL => { start => 300,
 end   => 599, },
ICT => { start => 800,
 end   => 850, },
);

sub getSmartPhone
{

   my $val = shift;
   foreach my $k (keys %smartPhone)
   {
  my ($start, $end) = @{$smartPhone{$k}}{qw/start end/};
  return $k if $start ge $val and $val le $end;
   }

   return "";
}


sub getMarket
{

   my $val = shift;
   foreach my $k (keys %marketInfo)
   {
 my ($start, $end) = @{$marketInfo{$k}}{qw/start end/};
 return $k if $start <= $val and $val <= $end;
   }

   return "";
}

open(RAW, ">test.rpt");
while (<>) {
   chomp;
   if (/;/) {
  @data = split /;/;
   if ($data[31] =~ m/^-?\d+$/) {   regular expression for real numerical 
value
  $mkt = getMarket($data[31]);
   }
   else
   {
  $mkt = "";
   }

   if ( length($data[5]) > 12) {
  $smartPhone = getSmartPhone(substr($data[5],2,14));
   }
   else
   {
  $smartPhone = "";
   }


 ($mtype,$cell,$sector,$carrier,$rlptxat) = 
($data[5],$data[31],$data[32],$data[38],$data[44]);
# print "$mkt\t  $mtype\t $smartPhone\t  $cell\t  $sector\t  $rlptxat\n";
   write(RAW);
   }
}
select(RAW);
close(RAW);




Re: Renaming with a specific spec

2011-01-31 Thread Jim Gibson

At 8:41 PM -0600 1/31/11, Harry Putnam wrote:

Looking for a renaming tool with certain capabilities, but when
googling or searching cpan its quite hard to tell if the tool can or
not satisfy them.  So, I hope someone can tell me right off the top of
their head if there is a renaming tool on cpan or anywhere else for
that matter that can handle ny specifications:

(This tool will be used against images with fixed extensions)

1) Handle windows style names with spaces, but not itself create such
   names.

2) Generate random names for each file with the least number of
   characters possible to generate a given number of names.
   Names can be alph-numeric and should be no longer than necessary to
   generate the needed number of names (Which will be known in advance)

I've seen quite a few different renaming tools, not necessarily perl
tools, but they seem to all stick to something of a certain set of
options for Image naming.  These revolve around various numbering
schemes, mostly some kind of sequential with varying number of digits,
insert specific text, and keep extension either upper or lower case.

I have need of generating names that are random, no sequence, but of
course the extension would remain the same.

So in summary, a renaming tool that can handle windows file naming
conventions and generate random names (except the extension)

Can anyone suggest a tool they know to be capable of the above?


You are not likely to find such a specific tool. However, you can 
develop your own tool.


Here is a renaming program adapted from the one in the Perl Cookbook, 
Recipe 9.9:


#!/usr/bin/perl
#
# rename
#
# perl script to rename files
#
# Usage:
#
#rename  perlexpr [files]
#

($op = shift) ||
  die
"Usage: rename perlexpr [filenames]
where perlexpr is any perl expression that modifies \$\_:
   's/old/new/'
   '\$\_ .= \".ext\"'
   'tr[A-Z][a-z]'\n";

if( !@ARGV ) {
  @ARGV = ;
  chop( @ARGV );
}
for( @ARGV ) {
  $was = $_;
  eval $op;
  die $@ if $@;
  rename($was,$_) unless $was eq $_;
}


The perlexpr can be as complicated as you want it, using the s///e 
modifier to introduce arbitrary Perl code into your replacement 
string. Of course, if you have some method for renaming files, it 
would be easier to use if you programmed it into your script.


I would add a test to see if a file already exists with the target 
name before renaming the file and overwriting an existing file.



--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Renaming with a specific spec

2011-01-31 Thread Harry Putnam
Looking for a renaming tool with certain capabilities, but when
googling or searching cpan its quite hard to tell if the tool can or
not satisfy them.  So, I hope someone can tell me right off the top of
their head if there is a renaming tool on cpan or anywhere else for
that matter that can handle ny specifications:

(This tool will be used against images with fixed extensions)

1) Handle windows style names with spaces, but not itself create such
   names.

2) Generate random names for each file with the least number of
   characters possible to generate a given number of names.
   Names can be alph-numeric and should be no longer than necessary to
   generate the needed number of names (Which will be known in advance)

I've seen quite a few different renaming tools, not necessarily perl
tools, but they seem to all stick to something of a certain set of
options for Image naming.  These revolve around various numbering
schemes, mostly some kind of sequential with varying number of digits,
insert specific text, and keep extension either upper or lower case.

I have need of generating names that are random, no sequence, but of
course the extension would remain the same.

So in summary, a renaming tool that can handle windows file naming
conventions and generate random names (except the extension)

Can anyone suggest a tool they know to be capable of the above?


-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: custom module and lib

2011-01-31 Thread Rob Dixon

On 31/01/2011 09:27, a b wrote:


Making it more clear.

I want to make tar ball which contains my perl  scripts and no other
dependencies required. like Net::Rsh,Net::Telnet etc
once user untar it, he should be able to run it from anywhere without any
extra perl modules. I am thinking that might be Net::Rsh etc is not
available on target m/c

With above requirement, i want Net::Rsh like modules to be in my lib. Not
sure if i need to modify Rsh module to get rid of scoping Net::

I want to simply use this module as "use Rsh;"

Can some body let me know if i can make these modules to my lib :0

help much appeciated!!!


Do you have a special reason for wanting to rename Net::Rsh to Rsh? It 
is a dangerous thing to do, as there may well be code that relies on the 
name of the module being unchanged. In particular you will have to edit 
the Rsh.pm file to say 'package Rsh', and it thereby becomes 
non-standard and so a maintenance problem.


It is worth noting that, by default, the last entry in @INC is '.' - the 
current directory - so perl will ultimately look in the same directory 
as the calling program for all modules if they are not found elsewhere. 
So you can simple bundle Net::Rsh in the same place as your main program 
and any other modules.


HTH,

Rob

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: date handle

2011-01-31 Thread John Delacour

At 22:17 -0800 30/01/2011, John W. Krahn wrote:



p...@mail.nsbeta.info wrote:

$ perl -MTime::Local -le 'print timelocal(0,0,0,1,1,1900)'
Cannot handle date (0, 0, 0, 1, 1, 1900) at -e line 1

why Time::Local can't handle the date of 1900?


Unix time starts at 1 Jan. 1970 so a time in 1900 is invalid.


Time for someone to RTFM I think!


#!/usr/local/bin/perl
use Time::Local 'timelocal_nocheck';
print scalar localtime timelocal_nocheck 0,0,0,1,1,1900;

JD


--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: custom module and lib

2011-01-31 Thread Octavian Rasnita

From: "a b" 

Thanks much for your response!!

Making it more clear.

I want to make tar ball which contains my perl  scripts and no other
dependencies required. like Net::Rsh,Net::Telnet etc
once user untar it, he should be able to run it from anywhere without any
extra perl modules. I am thinking that might be Net::Rsh etc is not
available on target m/c

With above requirement, i want Net::Rsh like modules to be in my lib. Not
sure if i need to modify Rsh module to get rid of scoping Net::

I want to simply use this module as "use Rsh;"

Can some body let me know if i can make these modules to my lib :0

help much appeciated!!!

Regards,
a b




This is not possible if those dependencies use C code, because they must be 
compiled differently depending on the platform they are running on.
This is the same no matter the programming language you use. If a module 
needs a .so file, under Windows it should be compiled as a .dll file.


If they are pure Perl, then you can bundle them in that tarball as a part of 
that distribution.


If you want to bundle more compiled Perl modules that use C code and use 
them under a specific platform and you don't need them to be portable, then 
you might be interested to create/install them as .deb or .rpm packages.


I don't know (and maybe others know more about this) if it is possible to 
compile Perl modules that use C code and then install them on the target 
platform by just copying them on a custom location.


Octavian




--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: custom module and lib

2011-01-31 Thread a b
Thanks much for your response!!

Making it more clear.

I want to make tar ball which contains my perl  scripts and no other
dependencies required. like Net::Rsh,Net::Telnet etc
once user untar it, he should be able to run it from anywhere without any
extra perl modules. I am thinking that might be Net::Rsh etc is not
available on target m/c

With above requirement, i want Net::Rsh like modules to be in my lib. Not
sure if i need to modify Rsh module to get rid of scoping Net::

I want to simply use this module as "use Rsh;"

Can some body let me know if i can make these modules to my lib :0

help much appeciated!!!

Regards,
a b

On Sun, Jan 30, 2011 at 9:07 PM, Rob Dixon  wrote:

> On 30/01/2011 14:09, a b wrote:
>
>>
>> I have a query regarding using lib modules
>>
>> 1) I've some custom modules which uses various default routines like
>> "Net::rsh" etc
>>
>> Now, i want to pack all default routines into my lib and use that lib
>> in my custom modules i.e
>>
>> package MyModule;
>>
>> use lib "lib/test";(here i am placing my Rsh.pm etc modules and some of my
>> custom modules)
>> use Rsh;
>>
>>
>> Is this possible???
>>
>> Please let me know how to go with this approach
>>
>> My motive is to create a main PM file which will call all small PM
>> files(custom and defaults)
>>
>
> I'm not clear what you need to do. What is a 'default routine'?
>
> At a guess you want to be able to access Net::Rsh as well as your own
> custom modules, in which case you probably don't understand how 'use lib'
> works, which is simply to add the path(s) you specify to the end of the list
> in @INC where perl will search for the modules you use. That means that,
> even after you have done 'use lib "lib/test"' you can still 'use Net::Rsh'
> and it will be found, as its location is still in @INC.
>
> For instance, something like
>
>  use warnings;
>  use strict;
>
>  use lib 'lib/test';
>
>  use Net::Rsh;
>  use SpecialModule;
>
> will find Net/Rsh.pm whereever it is on your machine, as well as
> lib/test/SpecialModule.pm
>
> If this isn't what you're looking for then please post again.
>
> HTH,
>
> Rob
>