Re: Simple encoding function

2005-03-30 Thread Ing. Branislav Gerzo
John W. Krahn [JWK], on Wednesday, March 30, 2005 at 12:56 (-0800)
thoughtfully wrote the following:

JWK> You could use the Math::BaseCalc module:
JWK> http://search.cpan.org/~kwilliams/Math-BaseCalc-1.011/

thanks, it is nice module, really easy to use. And also thanks to your
program, but I have some questions:

- my goal is 'convert' numbers to characters, so:
my @digits = ( "a" .. "z", "A" .. "Z", 0 .. 9, "-", "_" );
1 => 'a'
63 => '_'
64 => 'aa'
65 => 'ab'
and so on.

That module, and also your nice program get these result:
64 => 'ba'
65 => 'bb'

I understand why it is so...
So that means I lost some combination via base module like 'a*' and so
on. I want this stuff to encode URLs, I have in database some numbers,
get max number, encode it via this function, and have 'new url'. I
know, there is lots stuff like this on the net, but I'd like to code
my own for my project (it is not about compressing url, it is only
feature:)
So, if you could be so kind and if you have time, you can rewrite my
program (surely could be improved) to get same results, here is the
latest version I just wrote, also I did same speed improvements:

use strict;
use warnings;

my $num = 10_000_000; # $a >= 0
my @chars = ( 'a' .. 'z', 'A' .. 'Z', 0 .. 9, '-', '_' );
my $all = @chars;

print my $out = reverse(fn($num));

sub fn {
my $num = shift;
my $tmp = ($num/$all)-1;
my $out = $chars[$num % $all];
$out .= $tmp >= $all ? fn($tmp) : $chars[$tmp] if $tmp >= 0;
return $out;
}

-- 

 ...m8s, cu l8r, Brano.

[Dahlmer on cooking : Moo Goo Guy-In-A-Pan; Biscuits and G]



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




Re: General questions

2005-03-30 Thread Offer Kaye
On Thu, 31 Mar 2005 11:28:04 +0530, [EMAIL PROTECTED] wrote:
> 
> Use strict is used to enforce declaration of variables before we use
> them.
> Here IN_FILE1 is file pointer variable which u are using and which is
> not declared before ,
> That is the reason it is working fine when u have removed the use strict
> construct.
> 

Not true. Save the following code in a file called "test.pl" and run
it with "perl -w test.pl":
 begin code
use strict;
open(IN_FILE1,"test.pl");
while() {print}
 end code

As you can see, this code runs without any warnings or errors.
IN_FILE1 is a FILEHANDLE, not a "file pointer variable" (whatever the
heck that is). More to the point, it is not a variable at all, and so
is not affected by "use strict;".

-- 
Offer Kaye

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




RE: General questions

2005-03-30 Thread arjun.mallik

Hi Kumaran,

Use strict is used to enforce declaration of variables before we use
them.
Here IN_FILE1 is file pointer variable which u are using and which is
not declared before ,
That is the reason it is working fine when u have removed the use strict
construct.

Thanks
Arjun

Deserve before you desire







-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
Sent: Wednesday, March 30, 2005 1:28 PM
To: M.L. PERL BEG
Subject: General questions


Hello,

1.  I read on many Perl/CGI tutorial/articles that it is best to place
and use CGI files in /cgi-bin/ directory than anywhere else, due to
avoid many problems.  Buy in our website, we have several subdomain and
those are all use the same /cgi-bin/ directory, so now there are a lot
of files populated there.  So now what I have to do to reduce the
management/maintanence problems.


2. I used "use strict", and I get error for the statement open(IN_FILE1,
">>test_records.txt");

Here the error is
Bareword "IN_FILE1" not allowed while "strict subs" in use 

But if I remove "use strict", the program works well.  So should I
definately do not use "use strict" if the program want to handle I/O
files?


Thank you all.

Greetings,
R. Kumaran



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





Confidentiality Notice

The information contained in this electronic message and any attachments to 
this message are intended
for the exclusive use of the addressee(s) and may contain confidential or 
privileged information. If
you are not the intended recipient, please notify the sender at Wipro or [EMAIL 
PROTECTED] immediately
and destroy all copies of this message and any attachments.

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




Re: Uniq from array ?

2005-03-30 Thread Chris Devers
On Wed, 30 Mar 2005, Peter Rabbitson wrote:

> Anyway my 2c - I myself use the [$elided] archives quite a bit, which 
> does not prevent me from owning hard prints of the Cookbook, the 
> Pocket Ref and recently Object Oriented Perl. It however prevents from 
> owning 2 pcs of each of those not-so-slim books so I could equally 
> easy refer to this or that at work and at home.

More to the point, it prevents you purchasing copies of the CD Bookshelf 
series from O'Reilly that the site you mention has posted copies of. 
Carrying around all these books might be a pain, but carrying around 
your own, legal, copy of the CD would be fine. 

I believe that Manning has also provided _Object-Oriented Perl_ in an 
electronic form that has been pirated on sites like this, but I haven't 
seen that one. 

So... your point doesn't really stand up to scrutiny. It *IS* a form of 
theft, no matter how much you would prefer to whitewash that fact. If 
the site were legit, it wouldn't need to hide on a Ukranian server.

> Michael made a solid point - he found it via google.

And I can't & won't stop Google from finding & indexing sites of varying 
levels of legality & ethical acceptability. On the other hand, if a site 
is ethically questionable -- as these sites clearly are -- then at a 
minimum it would be wise to at least not give them any publicity, and by 
so doing encourage other people to also pirate these books. 

These sites have come up before on this list and other ones, and pretty 
much every time they do, at least one noted Perl author speaks up saying 
that these sites are effectively stealing from him, that he does not 
condone this, and that he's personally offended that people are passing 
this stuff around. I sympathize with that. It takes a lot of care and 
effort to write a technical book, and even then the authors don't really 
earn a whole lot for their efforts. To repay that effort by encouraging 
piracy is, in a very real sense, a way of saying "please stop publishing 
these books, we're not interested in buying them anyway."

Please step back from this whole "information wants to be free" nonsense 
and think about the consequences of what you're advocating. 



That said, if anyone else wants to discuss this, it should probably be 
done off list. I'm not trying to encourage a flame war here; I'm trying 
to discourage advocacy of something that should have no place here.

 

-- 
Chris Devers

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




Re: Uniq from array ?

2005-03-30 Thread Peter Rabbitson
> 
> Not that I see why this came up in the first place...
> 



How funny... By very same talking you can bring a gun to a social meeting 
and 10 minutes later yell "Huh?! WTF did this come from?!". Anyway my 2c - I 
myself use the unix.org.ua archives quite a bit, which does not prevent me 
from owning hard prints of the Cookbook, the Pocket Ref and recently Object 
Oriented Perl. It however prevents from owning 2 pcs of each of those 
not-so-slim books so I could equally easy refer to this or that at work and 
at home. Michael made a solid point - he found it via google. If you want to 
be such a purist - why not contact google for indexing obviously stolen 
content? Or why not go further and sue the guy who invented OCR (I believe 
he is still alive and in good health). Throw in a lawsuit against 
Frauenhofer Institute along the way. 
Excuse my harsh tone but the entire thread sounds too DMCA-ish, in other 
words: We will place content all over the place in the most easily 
accessible form and we will make sure we rip you off for each and every 
instance of it (maybe repeatedly after Fritz takes off). And "Don't you dare 
to complain!" since we will be waiting for you at the nearest courthouse.



Peter


P.S. Probably this is not much perl related... I apologise for me stirring 
up this thread.

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




Re: Uniq from array ?

2005-03-30 Thread JupiterHost.Net
As in free beer :) 
Thats mighty nice of you :)
I like Guinness, I can send you my address off list :)
Oh and I'd like you to do help on a project next week, 40 hours sound 
ok? I'll send the info you need so you can buy a plane ticket and get a 
hotel to come "share knowledge" for free...

I appreciate your philosophy that *everything* should be free :)
Not sure how you make ends meet working for free but I like it!
:)
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



Re: Uniq from array ?

2005-03-30 Thread Chris Devers
On Wed, 30 Mar 2005, Michael Gale wrote:

> Besides I am not sure where you are going with this ? Are you saying
> that the content on the web page if pirated so I should not view it ?

That's debatable, but you *definitely* shouldn't publicize it. 

> Information should be free, I believe all books and information
> resources should be free. 
> 
> As in free beer :) 

That's fine, as long as the author of the work in question agrees.

In many cases, especially with open source systems like Perl, the work 
in question *will* be freely available with the author's blessing -- 
usually right on their own web site. 

But if the material in question is being republished somewhere else 
without the author's consent -- typically from a jurisdiction with lax 
copyright law enforcement -- then that's *definitely* not right.

The word "theft" may be overused by the strict copyright camp, but in 
this case, it pretty clearly applies. It was taken from the author 
without consent or compensation and provided to others in a way that was 
in most cases explicitly not permitted. That's stealing.

Without a proper respect for & understanding of copyright, free software 
licenses wouldn't be possible. It's useful to understand the difference 
between, say, the GPL -- which uses copyright provisions to mandate that 
the material should be made available to all -- and materials in the 
public domain -- which aren't governed by much of anything and there is 
no protection of the right to share the material.

Being dismissive of all this is not a good habit for open source users.




Not that I see why this came up in the first place...

 


-- 
Chris Devers

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



Re: Uniq from array ?

2005-03-30 Thread Michael Gale

Google returned the page from a search result, where it gets the pages
from is not my fault. 

Besides I am not sure where you are going with this ? Are you saying
that the content on the web page if pirated so I should not view it ?

Information should be free, I believe all books and information
resources should be free. 

As in free beer :) 

How do we expect people to grow and learn by restricting the resources
that we have.

Libraries should be moved online, with free or next to free access for
all. Save some trees :)

Michael.

On Thu, 2005-03-31 at 10:28 +1000, Alfred Vahau wrote:
> Michael,
> I noted from your original posting that you quoted from a URL which is
> controversial
> in that the Perl-related books from O'Reilly are actually pirated
> copies. This was pointed out by one of  the
> subscribers to this list in a recent thread.
> 
> Alfred,
> 
> 
> Michael Gale wrote:
> > Hello,
> > 
> > I fixed it, the string would initially contain special characters such
> > as % signs. I strip out all the characters before the check, instead of
> > after.
> > 
> > Michael.
> > 
> > 
> > 
> > On Wed, 2005-03-30 at 16:19 -0700, Michael Gale wrote:
> >   
> > > Hello,
> > > 
> > >   I tried your example, it worked as expected, here is the entire code:
> > > 
> > > --snip--
> > > 
> > > my @servers;
> > > my $each_server;
> > > my $each_host;
> > > my %seen = ( );
> > > 
> > > print "List of systems being performance monitored\n";
> > > print "Please select a host\n";
> > > 
> > > opendir(RRDDIR,"/home/nagios/network-monitor/nagiosgraph/rrd")
> > > || die "Can't find servers";
> > > @servers = readdir(RRDDIR);
> > > closedir RRDDIR;
> > > 
> > > sub show_host{
> > > my($each_host) = @_;
> > > my $thost;
> > > $each_host  =~ /(.*)_(.*)_/;
> > > $thost = $1;
> > > $thost =~ s/\%2D/ /g;
> > > #print "$thost\n";
> > > print "$thost\n";
> > > }
> > > 
> > > print " > > method=GET>\n";
> > > print "\n";
> > > 
> > > foreach my $each_server(@servers)
> > > {
> > > unless ($seen{$each_server}) {
> > > $seen{$each_server} = 1;
> > > show_host($each_server);
> > > }
> > > }
> > > 
> > > print "\n";
> > > print "\n";
> > > 
> > > --snip--
> > > 
> > > On Wed, 2005-03-30 at 18:12 -0500, Offer Kaye wrote:
> > > 
> > > > On Wed, 30 Mar 2005 15:53:25 -0700, Michael Gale wrote:
> > > >   
> > > > > But it is not working as expected, even if the array has the first 
> > > > > three
> > > > > entries the same, the function "show_host" gets called three time ?
> > > > > 
> > > > >  foreach $each_server(@servers)
> > > > > {
> > > > > unless ($seen{$each_server}) {
> > > > > $seen{$each_server} = 1;
> > > > > show_host($each_server);
> > > > > }
> > > > > }
> > > > > 
> > > > > 
> > > > The code is okay. Try just the following in a standalone file:
> > > > ## begin code
> > > > use strict;
> > > > use warnings;
> > > > my @servers = qw/a a a b c d/;
> > > > my %seen;
> > > > foreach my $each_server(@servers) {
> > > >unless ($seen{$each_server}) {
> > > >   $seen{$each_server} = 1;
> > > >   show_host($each_server);
> > > >}
> > > > }
> > > > sub show_host {
> > > >print "$_[0]\n";
> > > > }
> > > > ## end code
> > > > If you run it, you will see it just prints "a" once, not 3 times.
> > > > So the problem is in some other code you are not showing us.
> > > > -- 
> > > > Offer Kaye
> > > > 
> > > >   
> > 
> >   

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



Re: Uniq from array ?

2005-03-30 Thread Alfred Vahau
Michael,
I noted from your original posting that you quoted from a URL which is 
controversial
in that the Perl-related books from O'Reilly are actually pirated 
copies. This was pointed out by one of  the
subscribers to this list in a recent thread.

Alfred,
Michael Gale wrote:
Hello,
I fixed it, the string would initially contain special characters such
as % signs. I strip out all the characters before the check, instead of
after.
Michael.

On Wed, 2005-03-30 at 16:19 -0700, Michael Gale wrote:
 

Hello,
I tried your example, it worked as expected, here is the entire code:
--snip--
my @servers;
   my $each_server;
   my $each_host;
   my %seen = ( );
   print "List of systems being performance monitored\n";
   print "Please select a host\n";
   opendir(RRDDIR,"/home/nagios/network-monitor/nagiosgraph/rrd")
|| die "Can't find servers";
   @servers = readdir(RRDDIR);
   closedir RRDDIR;
   sub show_host{
   my($each_host) = @_;
   my $thost;
   $each_host  =~ /(.*)_(.*)_/;
   $thost = $1;
   $thost =~ s/\%2D/ /g;
   #print "$thost\n";
   print "$thost\n";
   }
   print "\n";
   print "\n";
   foreach my $each_server(@servers)
   {
   unless ($seen{$each_server}) {
   $seen{$each_server} = 1;
   show_host($each_server);
   }
   }
   print "\n";
   print "\n";
   
--snip--

On Wed, 2005-03-30 at 18:12 -0500, Offer Kaye wrote:
   

On Wed, 30 Mar 2005 15:53:25 -0700, Michael Gale wrote:
 

But it is not working as expected, even if the array has the first three
entries the same, the function "show_host" gets called three time ?
foreach $each_server(@servers)
   {
   unless ($seen{$each_server}) {
   $seen{$each_server} = 1;
   show_host($each_server);
   }
   }
   

The code is okay. Try just the following in a standalone file:
## begin code
use strict;
use warnings;
my @servers = qw/a a a b c d/;
my %seen;
foreach my $each_server(@servers) {
  unless ($seen{$each_server}) {
 $seen{$each_server} = 1;
 show_host($each_server);
  }
}
sub show_host {
  print "$_[0]\n";
}
## end code
If you run it, you will see it just prints "a" once, not 3 times.
So the problem is in some other code you are not showing us.
--
Offer Kaye
 

 



Re: Uniq from array ?

2005-03-30 Thread Michael Gale
Hello,

I fixed it, the string would initially contain special characters such
as % signs. I strip out all the characters before the check, instead of
after.

Michael.



On Wed, 2005-03-30 at 16:19 -0700, Michael Gale wrote:
> Hello,
> 
>   I tried your example, it worked as expected, here is the entire code:
> 
> --snip--
> 
> my @servers;
> my $each_server;
> my $each_host;
> my %seen = ( );
> 
> print "List of systems being performance monitored\n";
> print "Please select a host\n";
> 
> opendir(RRDDIR,"/home/nagios/network-monitor/nagiosgraph/rrd")
> || die "Can't find servers";
> @servers = readdir(RRDDIR);
> closedir RRDDIR;
> 
> sub show_host{
> my($each_host) = @_;
> my $thost;
> $each_host  =~ /(.*)_(.*)_/;
> $thost = $1;
> $thost =~ s/\%2D/ /g;
> #print "$thost\n";
> print "$thost\n";
> }
> 
> print " method=GET>\n";
> print "\n";
> 
> foreach my $each_server(@servers)
> {
> unless ($seen{$each_server}) {
> $seen{$each_server} = 1;
> show_host($each_server);
> }
> }
> 
> print "\n";
> print "\n";
> 
> --snip--
> 
> On Wed, 2005-03-30 at 18:12 -0500, Offer Kaye wrote:
> > On Wed, 30 Mar 2005 15:53:25 -0700, Michael Gale wrote:
> > > 
> > > But it is not working as expected, even if the array has the first three
> > > entries the same, the function "show_host" gets called three time ?
> > > 
> > >  foreach $each_server(@servers)
> > > {
> > > unless ($seen{$each_server}) {
> > > $seen{$each_server} = 1;
> > > show_host($each_server);
> > > }
> > > }
> > > 
> > 
> > The code is okay. Try just the following in a standalone file:
> > ## begin code
> > use strict;
> > use warnings;
> > my @servers = qw/a a a b c d/;
> > my %seen;
> > foreach my $each_server(@servers) {
> >unless ($seen{$each_server}) {
> >   $seen{$each_server} = 1;
> >   show_host($each_server);
> >}
> > }
> > sub show_host {
> >print "$_[0]\n";
> > }
> > ## end code
> > If you run it, you will see it just prints "a" once, not 3 times.
> > So the problem is in some other code you are not showing us.
> > -- 
> > Offer Kaye
> > 
> 

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



Re: Uniq from array ?

2005-03-30 Thread Michael Gale
Hello,

I tried your example, it worked as expected, here is the entire code:

--snip--

my @servers;
my $each_server;
my $each_host;
my %seen = ( );

print "List of systems being performance monitored\n";
print "Please select a host\n";

opendir(RRDDIR,"/home/nagios/network-monitor/nagiosgraph/rrd")
|| die "Can't find servers";
@servers = readdir(RRDDIR);
closedir RRDDIR;

sub show_host{
my($each_host) = @_;
my $thost;
$each_host  =~ /(.*)_(.*)_/;
$thost = $1;
$thost =~ s/\%2D/ /g;
#print "$thost\n";
print "$thost\n";
}

print "\n";
print "\n";

foreach my $each_server(@servers)
{
unless ($seen{$each_server}) {
$seen{$each_server} = 1;
show_host($each_server);
}
}

print "\n";
print "\n";

--snip--

On Wed, 2005-03-30 at 18:12 -0500, Offer Kaye wrote:
> On Wed, 30 Mar 2005 15:53:25 -0700, Michael Gale wrote:
> > 
> > But it is not working as expected, even if the array has the first three
> > entries the same, the function "show_host" gets called three time ?
> > 
> >  foreach $each_server(@servers)
> > {
> > unless ($seen{$each_server}) {
> > $seen{$each_server} = 1;
> > show_host($each_server);
> > }
> > }
> > 
> 
> The code is okay. Try just the following in a standalone file:
> ## begin code
> use strict;
> use warnings;
> my @servers = qw/a a a b c d/;
> my %seen;
> foreach my $each_server(@servers) {
>unless ($seen{$each_server}) {
>   $seen{$each_server} = 1;
>   show_host($each_server);
>}
> }
> sub show_host {
>print "$_[0]\n";
> }
> ## end code
> If you run it, you will see it just prints "a" once, not 3 times.
> So the problem is in some other code you are not showing us.
> -- 
> Offer Kaye
> 

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



Re: Uniq from array ?

2005-03-30 Thread Offer Kaye
On Wed, 30 Mar 2005 15:53:25 -0700, Michael Gale wrote:
> 
> But it is not working as expected, even if the array has the first three
> entries the same, the function "show_host" gets called three time ?
> 
>  foreach $each_server(@servers)
> {
> unless ($seen{$each_server}) {
> $seen{$each_server} = 1;
> show_host($each_server);
> }
> }
> 

The code is okay. Try just the following in a standalone file:
## begin code
use strict;
use warnings;
my @servers = qw/a a a b c d/;
my %seen;
foreach my $each_server(@servers) {
   unless ($seen{$each_server}) {
  $seen{$each_server} = 1;
  show_host($each_server);
   }
}
sub show_host {
   print "$_[0]\n";
}
## end code
If you run it, you will see it just prints "a" once, not 3 times.
So the problem is in some other code you are not showing us.
-- 
Offer Kaye

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



Re: db handles with fork()

2005-03-30 Thread Felix Geerinckx
On 30/03/2005, Ramprasad A Padmanabhan wrote:

>I am writing a perl application that connect to a database and then
> does a fork()
> The child completes the process and does a exit(), but the problem is
> it closes the database connection which the parent would like to use.
> 
> Can I exit the child process without disconnecting the parent dbi
> handle

Have you read the 'InactiveDestroy' entry in perldoc DBI?

-- 
felix

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



Re: My own die message

2005-03-30 Thread Felix Geerinckx
On 30/03/2005, Ankur Gupta wrote:

> I have the following code :
> 
> eval{
> require "file" or die "unable to find file"; 
> };
> print "$@";
> 
> But it always prints "Can't locate file in @INC. blah blah "
> 
> I want $@ to contain "unable to find file". What am I doing wrong or
> it is not possible to override [EMAIL PROTECTED]

The require fails before you die. You will need something like this:

eval {
require "file";
}
print "Your message" if $@ && $@ =~ m/^Can't locate file/;

-- 
felix

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



Uniq from array ?

2005-03-30 Thread Michael Gale
Hello,

I have using the following lines to run through an array (@servers) and
run a function on each one. But I want to avoid running the function
twice if an entry exist twice.

I got the following from
http://www.unix.org.ua/orelly/perl/cookbook/ch04_07.htm

But it is not working as expected, even if the array has the first three
entries the same, the function "show_host" gets called three time ?


 foreach $each_server(@servers)
{
unless ($seen{$each_server}) {
$seen{$each_server} = 1;
show_host($each_server);
}
}

Michael.

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



Re: Simple encoding function

2005-03-30 Thread John W. Krahn
John W. Krahn wrote:
Or if you really want to do it yourself:
$ perl -le'
my $num = 123456789;
{   my @digits = ( "a" .. "z", "A" .. "Z", 0 .. 9, "-", "_" );
sub fn {
my $in = shift;
my $res = "";
while ( $in ) {
substr $res, 0, 0, $digits[ $in % @digits ];
$in = int( $in / @digits );
}
return $res;
}
}
my $out = fn( $num );
print $out;
'
hw80v
Oops, small correction, that should be:
{   my @digits = ( "a" .. "z", "A" .. "Z", 0 .. 9, "-", "_" );
sub fn {
my $in = shift;
my $res = "";
do {
substr $res, 0, 0, $digits[ $in % @digits ];
$in = int( $in / @digits );
} while $in;
return $res;
}
}

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



RE: Need first line of Excel Spreadsheet

2005-03-30 Thread Wagner, David --- Senior Programmer Analyst --- WGO
Alfred Vahau wrote:
> The Spreadsheet::ParseExcel will dump all the worksheets one after the
> other into one big file. Is this your observation.
> The first line of the file will be the first row of worksheet 1. From
> this the last column can be extracted which contains the
> file name.
> 
> If the user still insists on the files retained as excel files, then
> Spreadsheet::WriteExcel can write the results back as excel files.
> 
> In Windows, Win32::OLE is used to do this kind of work.
> 
> HTH,
> 
> Alfred,
Thanks, Alfred, but the email from David Van Ginneken concerning an 
email on PerlMonks got me the first line and also out of the file in quick 
order.

I do appreciate the followup though.

Wags ;)
> 
> 
> 
> Kevin Old wrote:
> 
>> On Tue, 29 Mar 2005 13:30:57 -0800, Wagner, David --- Senior
>> Programmer Analyst --- WGO <[EMAIL PROTECTED]> wrote:
>> 
>> 
>>>I have a directory which has output reports in them.  The
>>> big problem is that they are just a bunch of letters and numbers
>>> like 2781424330fdac47c916.xls.  So the user would like a more
>>> recognizable file name.   
>>> 
>>>This is to run on Solaris w/ Perl 5.8.3.  I have tried the
>>> following two modules on my PC using ActiveState 5.8.3
>>> under XP: Spreadsheet::ParseExcel ( 15 minutes plus to read 4 files
>>> size 4 to 12 meg) and Spreadsheet::ParseExcel::Simple ( 4 minutes
>>> for the same files as ParseExcel )   
>>> 
>>>I am running my first test on Solaris using Simple and the
>>> first file took 5 minutes to process.  Still have 3 to do. 
>>> 
>>>Any suggestions on what to do?  The key for naming the file
>>> is ( believe it or not ) the last column of the first row on
>>> worksheet 1.  
>>> 
>>> Any questions and/or problems, please let me know.
>>> 
>>> 
>> 
>> Hey Wags,
>> 
>> I'm kind of confused on what you're asking help for.  Are you asking
>> for help on getting the last column of the first row on worksheet 1
>> for each file you have? 
>> 
>> If so, my suggestion is to use File::Find to parse down through your
>> directory and use a regex to identify the files you want, then use
>> Spreadsheet::ParseExcel to read the first worksheet and get the
>> first row. 
>> 
>> Use the code on
>> http://search.cpan.org/~kwitknr/Spreadsheet-ParseExcel-0.2603/ParseExcel.pm
>> in the Synopsis section and play around with the for loops to have
>> it break after the first row. 
>> 
>> Here's a great column on using File::Find.
>> http://www.stonehenge.com/merlyn/LinuxMag/col45.html
>> 
>> Sorry for the lack of syntax, but if you need some later, let me
>> know! 
>> 
>> Hope this helps,
>> Kevin



***
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: Need first line of Excel Spreadsheet

2005-03-30 Thread Alfred Vahau
The Spreadsheet::ParseExcel will dump all the worksheets one after the 
other into one big file. Is this your observation.
The first line of the file will be the first row of worksheet 1. From 
this the last column can be extracted which contains the
file name.

If the user still insists on the files retained as excel files, then 
Spreadsheet::WriteExcel can write the results back as excel files.

In Windows, Win32::OLE is used to do this kind of work.
HTH,
Alfred,

Kevin Old wrote:
On Tue, 29 Mar 2005 13:30:57 -0800, Wagner, David --- Senior
Programmer Analyst --- WGO <[EMAIL PROTECTED]> wrote:
 

   I have a directory which has output reports in them.  The big problem is 
that they are just a bunch of letters and numbers like 
2781424330fdac47c916.xls.  So the user would like a more recognizable file name.
   This is to run on Solaris w/ Perl 5.8.3.  I have tried the following two 
modules on my PC using ActiveState 5.8.3 under XP:
Spreadsheet::ParseExcel ( 15 minutes plus to read 4 files size 4 to 12 
meg) and Spreadsheet::ParseExcel::Simple ( 4 minutes for the same files as 
ParseExcel )
   I am running my first test on Solaris using Simple and the first file 
took 5 minutes to process.  Still have 3 to do.
   Any suggestions on what to do?  The key for naming the file is ( believe 
it or not ) the last column of the first row on worksheet 1.
Any questions and/or problems, please let me know.
   

Hey Wags,
I'm kind of confused on what you're asking help for.  Are you asking
for help on getting the last column of the first row on worksheet 1
for each file you have?
If so, my suggestion is to use File::Find to parse down through your
directory and use a regex to identify the files you want, then use
Spreadsheet::ParseExcel to read the first worksheet and get the first
row.
Use the code on
http://search.cpan.org/~kwitknr/Spreadsheet-ParseExcel-0.2603/ParseExcel.pm
in the Synopsis section and play around with the for loops to have it
break after the first row.
Here's a great column on using File::Find.
http://www.stonehenge.com/merlyn/LinuxMag/col45.html
Sorry for the lack of syntax, but if you need some later, let me know!
Hope this helps,
Kevin
 

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



RE: My own die message

2005-03-30 Thread Ankur Gupta
> -Original Message-
> From: Offer Kaye [mailto:[EMAIL PROTECTED]
> Sent: Thursday, March 31, 2005 2:21 AM
> To: Ankur Gupta; Perl Beginners
> Subject: Re: My own die message
> 
> On Thu, 31 Mar 2005 00:18:14 +0530, Ankur Gupta wrote:
> > Hi,
> >
> > I have the following code :
> >
> > eval{
> >
> >  require "file" or die "unable to find file";
> >
> > };
> >
> > print "$@";
> >
> > But it always prints "Can't locate file in @INC. blah blah "
> >
> > I want $@ to contain "unable to find file". What am I doing wrong or it
> is
> > not possible to override [EMAIL PROTECTED]
> >
> > Thanks,
> >
> > Ankur
> >
> >
> 
> Hi Ankur,
> Other people gave you good answers, I just wanted to claify to you why
> your code didn't act as you expected.
> Basically, you have the right idea - a die inside an eval will return
> its argument in the $@ variable. The problem in your code is, your die
> never gets executed! The "require", when it fails, dies itself, with
> its own error message - it doesn't return false, so your die never
> gets a chance to execute.
> 
> The solution, as other people have said, is simply to handle the
> string outside the eval. Simply put:
> eval {require "file"};
> print "Unable to find file!\n" if $@;
> 
> See "perldoc perlvar" for details about $@, "perldoc -f eval" for more
> info about "eval" and "perldoc -f require" for more "require" info.
> 
> Hope this helps,
> --
> Offer Kaye
> 
> --
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>  
> 
Thanks Kaye and all,

This helps... 

--
Ankur



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




Re: Simple encoding function

2005-03-30 Thread John W. Krahn
Ing. Branislav Gerzo wrote:
Hi pals,
Hello,
I'd like to code my own encode function, I have @list of allowed
characters, my input is number, and I'd like to 'convert' number to
characters. Here is script I coded, but I'm sure it could be really
better. This script should work, but there are too much conditions and
isn't so clear as I think it could be:
use strict;
use warnings;
my $a = 123456789; # $a >= 0
my @list = ( 'a' .. 'z', 'A' .. 'Z', 0 .. 9, '-', '_' );
print my $out = reverse(fn($a));
sub fn {
my $a = shift;
my $out = shift || '';
$out .= $list[$a % @list];
my $b = ($a/@list)-1;
if ( $b >= @list ) { $out .= fn($b) }
$out .= $list[$b] if $list[$b] and $b >= 0; 
return $out;
}
__END__

prints: gv7Zv
So if anyone helps me, how to clear it, I will be glad.
You could use the Math::BaseCalc module: 
http://search.cpan.org/~kwilliams/Math-BaseCalc-1.011/

$ perl -le'
use Math::BaseCalc;
my $calc = new Math::BaseCalc( digits => [ "a" .. "z", "A" .. "Z", 0 .. 9, 
"-", "_" ] );
my $num = 123456789;
my $out = $calc->to_base( $num );
print $out;
'
hw80v

Or if you really want to do it yourself:
$ perl -le'
my $num = 123456789;
{   my @digits = ( "a" .. "z", "A" .. "Z", 0 .. 9, "-", "_" );
sub fn {
my $in = shift;
my $res = "";
while ( $in ) {
substr $res, 0, 0, $digits[ $in % @digits ];
$in = int( $in / @digits );
}
return $res;
}
}
my $out = fn( $num );
print $out;
'
hw80v

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



Re: My own die message

2005-03-30 Thread Offer Kaye
On Thu, 31 Mar 2005 00:18:14 +0530, Ankur Gupta wrote:
> Hi,
> 
> I have the following code :
> 
> eval{
> 
>  require "file" or die "unable to find file";
> 
> };
> 
> print "$@";
> 
> But it always prints "Can't locate file in @INC. blah blah "
> 
> I want $@ to contain "unable to find file". What am I doing wrong or it is
> not possible to override [EMAIL PROTECTED]
> 
> Thanks,
> 
> Ankur
> 
> 

Hi Ankur, 
Other people gave you good answers, I just wanted to claify to you why
your code didn't act as you expected.
Basically, you have the right idea - a die inside an eval will return
its argument in the $@ variable. The problem in your code is, your die
never gets executed! The "require", when it fails, dies itself, with
its own error message - it doesn't return false, so your die never
gets a chance to execute.

The solution, as other people have said, is simply to handle the
string outside the eval. Simply put:
eval {require "file"};
print "Unable to find file!\n" if $@;

See "perldoc perlvar" for details about $@, "perldoc -f eval" for more
info about "eval" and "perldoc -f require" for more "require" info.

Hope this helps,
-- 
Offer Kaye

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




RE: Need first line of Excel Spreadsheet

2005-03-30 Thread Wagner, David --- Senior Programmer Analyst --- WGO
David Van Ginneken wrote:
> This node may help you.
> 
> http://www.perlmonks.org/index.pl?node_id=379743
> 
> Basically you create a custom cell handler.  The one I use looks
> something like this.

David responded but only to me, but if you need to work with Excel and 
only need to search and be selective about it, then this code is a great time 
saver.

I looked at your code and that was good, but when I went and took a 
look at the messge at the url above, then I found about also getting out as 
soon as I found what I was looking for. From about 38 minutes to less than a 
minute for the same four files.  

Thanks.

Wags ;)
> 
> sub cell_handler {
>my $workbook= $_[0];
>my $sheet_index = $_[1];
>my $row = $_[2];
>my $col = $_[3];
>my $cell= $_[4];
>return unless (($col == 2)||($col == 3)); # Only take the 3rd and
> 4th columns.
>return if $row == 0; # Ignore the header row
>$row = sprintf("%05s" , $row);
>$col = sprintf("%05s" , $col);
>$tmpcallmap{$row}{$col} = $cell->{_Value};
> }
> 
> Which populates a hash with the columns I wanted from the report
> skipping the 1st row.  You could easily adapt something like this to
> ignore other worksheets, rows, columns, etc..
> 
> 
> 
> On Wed, 30 Mar 2005 09:04:23 -0800, Wagner, David --- Senior
> Programmer Analyst --- WGO <[EMAIL PROTECTED]> wrote:
>> Kevin Old wrote:
>>> On Tue, 29 Mar 2005 13:30:57 -0800, Wagner, David --- Senior
>>> Programmer Analyst --- WGO <[EMAIL PROTECTED]> wrote:
 I have a directory which has output reports in them.  The
 big problem is that they are just a bunch of letters and numbers
 like 2781424330fdac47c916.xls.  So the user would like a more
 recognizable file name. 
 
 This is to run on Solaris w/ Perl 5.8.3.  I have tried the
  following two modules on my PC using ActiveState 5.8.3
 under XP: Spreadsheet::ParseExcel ( 15 minutes plus to read 4 files
 size 4 to 12 meg) and Spreadsheet::ParseExcel::Simple ( 4 minutes
 for the same files as ParseExcel )
 
 I am running my first test on Solaris using Simple and the
 first file took 5 minutes to process.  Still have 3 to do.
 
 Any suggestions on what to do?  The key for naming the file
 is ( believe it or not ) the last column of the first row on
 worksheet 1. 
 
 Any questions and/or problems, please let me know.
>>> 
>>> Hey Wags,
>>> 
>>> I'm kind of confused on what you're asking help for.  Are you asking
>>> for help on getting the last column of the first row on worksheet 1
>>> for each file you have? 
>>> 
>>> If so, my suggestion is to use File::Find to parse down through your
>>> directory and use a regex to identify the files you want, then use
>>> Spreadsheet::ParseExcel to read the first worksheet and get the
>>> first row.
>> Sorry for not being clear.  I can find the files I want, but
>> to open them takes way too long.  On my test node, to open the four
>> files and get the first line of worksheet 1 took almost 38 minutes. 
>> Any other file processing would be over almost before it got
>> started, but with the MS setup it does not work that way.  Like I
>> stated, I have tried both ParseExcel and parseExcel::Simple and each
>> for some reason reads in the whole file at once.  
>> 
>> Is there a way to tell either of these modules to just open
>> and allow me to read what I need and then stop.  Also it can take up
>> to another 5 to 10 minutes after my program says it is done, for the
>> prompt to return also.   
>> 
>> Thanks for the reply, but is there any way to easily read
>> something from MS and NOT have the overhead of the whole file being
>> stuffed into memory.  
>> 
>> Wags ;)
>>> 
>>> Use the code on
>>> http://search.cpan.org/~kwitknr/Spreadsheet-ParseExcel-0.2603/ParseExcel.pm
>>> in the Synopsis section and
>  play around with the for loops to have it
>>> break after the first row.
>>> 
>>> Here's a great column on using File::Find.
>>> http://www.stonehenge.com/merlyn/LinuxMag/col45.html
>>> 
>>> Sorry for the lack of syntax, but if you need some later, let me
>>> know! 
>>> 
>>> Hope this helps,
>>> Kevin
>> 
>> ***
>> 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]
>>  


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




RE: My own die message

2005-03-30 Thread Chris Devers
On Thu, 31 Mar 2005, Ankur Gupta wrote:

> No I do not [want to] die so fast.. I want to do some processing based 
> on the died message.

Fine then.

eval {
risky_action();
}

if $@ {
my $status = $@;
my $result = do_some_processing();
die "Got $status, did some processing: $result\n";
}

This should work. 


-- 
Chris Devers

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




RE: My own die message

2005-03-30 Thread Ankur Gupta
No I do not wanna die so fast.. I want to do some processing based on the
died message.

--
Ankur

-Original Message-
From: Todd de Gruyl [mailto:[EMAIL PROTECTED] 
Sent: Thursday, March 31, 2005 12:24 AM
To: Ankur Gupta
Cc: beginners@perl.org
Subject: Re: My own die message

On 03/30/2005 01:48 PM, Ankur Gupta wrote:
 > eval{
 >
 >  require "file" or die "unable to find file";
 >
 > };
 >
 > print "$@";
 >
 >
 >
 > But it always prints "Can't locate file in @INC. blah blah "

If you actually want to die, try moving the die outside of the eval:

eval { require "file";} or die "unable to find file $@";

-- 
Todd de Gruyl

-- 
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: My own die message

2005-03-30 Thread Todd de Gruyl
On 03/30/2005 01:48 PM, Ankur Gupta wrote:
> eval{
>
>  require "file" or die "unable to find file";
>
> };
>
> print "$@";
>
>
>
> But it always prints "Can't locate file in @INC. blah blah "
If you actually want to die, try moving the die outside of the eval:
eval { require "file";} or die "unable to find file $@";
--
Todd de Gruyl
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



My own die message

2005-03-30 Thread Ankur Gupta
Hi,

 

I have the following code :

 

eval{

 require "file" or die "unable to find file";

};

print "$@";

 

But it always prints "Can't locate file in @INC. blah blah "

 

I want $@ to contain "unable to find file". What am I doing wrong or it is
not possible to override [EMAIL PROTECTED]

 

Thanks,

Ankur



A strange solution to warnings about uninitialized variables

2005-03-30 Thread Walter A Poor Jr
This is my third note on this subject, and I hope no-one objects.

My questions (and those of other members) were why perl sometimes claims 
some variables have not been initialized, even when direct investigation 
proves that the variables in fact have valid real values.  Several people 
suggested helpful ideas, but none of them worked.

But then my PC tech installed a program to find and locate spyware on my 
PCs.  The problem with Perl's strange warnings went away instantly, and 
have never returned.  Nothing else changed:  same input files, same 
program, and same version of Perl.

Does this make sense to anyone?  Would anyone have predicted this 
behavior?

Thanks,
Walt

Re: Perl Vulnerablity

2005-03-30 Thread Kaysee Long
Do I have to install the AIX apar for this vulnerablity too(AIX 5.2 and
5.3)  - or is it just the version that comes with precompiled with the OS?

I have a version I compiled myself... thank you inadvance.Kaysee







   
 Jay Savage
 <[EMAIL PROTECTED] 
 l.com> To 
   Kaysee Long/White Plains/[EMAIL 
PROTECTED], 
 03/30/2005 12:28  Perl Beginners  
 PM cc 
   
   Subject 
 Please respond to Re: Perl Vulnerablity   
Jay Savage 
   
   
   
   
   




On Thu, 24 Mar 2005 14:21:32 -0500, Kaysee Long <[EMAIL PROTECTED]> wrote:
> I have a question about something that was sent to me, I couldn't find
> anything on the website (but it could be me):
>
> http://www.securityfocus.com/bid/12426
>
>  bugtraq id
>  12426
>  object
>
>  class
>  Unknown
>  cve
>  CAN-2005-0155, CAN-2005-0156
>  remote
>  No
>  local
>  Yes
>  published
>  Feb 02, 2005
>  updated
>  Feb 28, 2005
>  vulnerable
>  IBM AIX 5.2
>  IBM AIX 5.3
>  Larry Wall Perl 5.8
>  Larry Wall Perl 5.8.1
>  Larry Wall Perl 5.8.3
> + Gentoo Linux

What's your question?

--jay

--
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: Need first line of Excel Spreadsheet

2005-03-30 Thread Offer Kaye
On Wed, 30 Mar 2005 09:04:23 -0800, Wagner, David --- Senior
Programmer Analyst --- WGO wrote:
> 
> Sorry for not being clear.  I can find the files I want, but to open 
> them takes way too long.  
> On my test node, to open the four files and get the first line of worksheet 1 
> took almost 38 
> minutes.  Any other file processing would be over almost before it got 
> started, but with the MS 
> setup it does not work that way.  Like I stated, I have tried both ParseExcel 
> and 
> parseExcel::Simple and each for some reason reads in the whole file at once.
> 
> Is there a way to tell either of these modules to just open and allow 
> me to read what I 
> need and then stop.  Also it can take up to another 5 to 10 minutes after my 
> program says it is 
> done, for the prompt to return also.
> 
> Thanks for the reply, but is there any way to easily read something 
> from MS and NOT 
> have the overhead of the whole file being stuffed into memory.
> 
> Wags ;)

Hi Wags,
The following code, when reading a 3Meg file, took 21 seconds to run
on a strong Linux machine, so figure x4 the time since you're running
on Solaris, and another x4 for your 12Meg files, for a total of about
5 and a half minutes worst case. Here's the code:
## begin code
use strict;
use warnings;
use Spreadsheet::ParseExcel::Simple;

my $xls_file = "filename.xls";
my $xls = Spreadsheet::ParseExcel::Simple->read($xls_file)
   or die "Couldn't read $xls_file: $!\n";
my $sheet = ($xls->sheets)[0]; # Sheet 1
my $data = ($sheet->next_row)[-1]; # last col of row 1

print "The name is: $data\n";
## end code

I'd be interested in hearing what your runtime is.

-- 
Offer Kaye

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




Re: Perl Vulnerablity

2005-03-30 Thread Jay Savage
On Thu, 24 Mar 2005 14:21:32 -0500, Kaysee Long <[EMAIL PROTECTED]> wrote:
> I have a question about something that was sent to me, I couldn't find
> anything on the website (but it could be me):
> 
> http://www.securityfocus.com/bid/12426
> 
>  bugtraq id
>  12426
>  object
> 
>  class
>  Unknown
>  cve
>  CAN-2005-0155, CAN-2005-0156
>  remote
>  No
>  local
>  Yes
>  published
>  Feb 02, 2005
>  updated
>  Feb 28, 2005
>  vulnerable
>  IBM AIX 5.2
>  IBM AIX 5.3
>  Larry Wall Perl 5.8
>  Larry Wall Perl 5.8.1
>  Larry Wall Perl 5.8.3
> + Gentoo Linux 

What's your question?

--jay

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




RE: Need first line of Excel Spreadsheet

2005-03-30 Thread Wagner, David --- Senior Programmer Analyst --- WGO
Kevin Old wrote:
> On Tue, 29 Mar 2005 13:30:57 -0800, Wagner, David --- Senior
> Programmer Analyst --- WGO <[EMAIL PROTECTED]> wrote:
>> I have a directory which has output reports in them.  The
>> big problem is that they are just a bunch of letters and numbers
>> like 2781424330fdac47c916.xls.  So the user would like a more
>> recognizable file name.   
>> 
>> This is to run on Solaris w/ Perl 5.8.3.  I have tried the
>>  following two modules on my PC using ActiveState 5.8.3
>> under XP: Spreadsheet::ParseExcel ( 15 minutes plus to read 4 files
>> size 4 to 12 meg) and Spreadsheet::ParseExcel::Simple ( 4 minutes
>> for the same files as ParseExcel )   
>> 
>> I am running my first test on Solaris using Simple and the
>> first file took 5 minutes to process.  Still have 3 to do. 
>> 
>> Any suggestions on what to do?  The key for naming the file
>> is ( believe it or not ) the last column of the first row on
>> worksheet 1.  
>> 
>> Any questions and/or problems, please let me know.
> 
> Hey Wags,
> 
> I'm kind of confused on what you're asking help for.  Are you asking
> for help on getting the last column of the first row on worksheet 1
> for each file you have?
> 
> If so, my suggestion is to use File::Find to parse down through your
> directory and use a regex to identify the files you want, then use
> Spreadsheet::ParseExcel to read the first worksheet and get the first
> row.
Sorry for not being clear.  I can find the files I want, but to open 
them takes way too long.  On my test node, to open the four files and get the 
first line of worksheet 1 took almost 38 minutes.  Any other file processing 
would be over almost before it got started, but with the MS setup it does not 
work that way.  Like I stated, I have tried both ParseExcel and 
parseExcel::Simple and each for some reason reads in the whole file at once.  

Is there a way to tell either of these modules to just open and allow 
me to read what I need and then stop.  Also it can take up to another 5 to 10 
minutes after my program says it is done, for the prompt to return also.

Thanks for the reply, but is there any way to easily read something 
from MS and NOT have the overhead of the whole file being stuffed into memory.

Wags ;)
> 
> Use the code on
> http://search.cpan.org/~kwitknr/Spreadsheet-ParseExcel-0.2603/ParseExcel.pm
> in the Synopsis section and play around with the for loops to have it
> break after the first row.
> 
> Here's a great column on using File::Find.
> http://www.stonehenge.com/merlyn/LinuxMag/col45.html
> 
> Sorry for the lack of syntax, but if you need some later, let me know!
> 
> Hope this helps,
> Kevin



***
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: Need first line of Excel Spreadsheet

2005-03-30 Thread Kevin Old
On Tue, 29 Mar 2005 13:30:57 -0800, Wagner, David --- Senior
Programmer Analyst --- WGO <[EMAIL PROTECTED]> wrote:
> I have a directory which has output reports in them.  The big problem 
> is that they are just a bunch of letters and numbers like 
> 2781424330fdac47c916.xls.  So the user would like a more recognizable file 
> name.
> 
> This is to run on Solaris w/ Perl 5.8.3.  I have tried the following 
> two modules on my PC using ActiveState 5.8.3 under XP:
>  Spreadsheet::ParseExcel ( 15 minutes plus to read 4 files size 4 to 
> 12 meg) and Spreadsheet::ParseExcel::Simple ( 4 minutes for the same files as 
> ParseExcel )
> 
> I am running my first test on Solaris using Simple and the first file 
> took 5 minutes to process.  Still have 3 to do.
> 
> Any suggestions on what to do?  The key for naming the file is ( 
> believe it or not ) the last column of the first row on worksheet 1.
> 
> Any questions and/or problems, please let me know.

Hey Wags,

I'm kind of confused on what you're asking help for.  Are you asking
for help on getting the last column of the first row on worksheet 1
for each file you have?

If so, my suggestion is to use File::Find to parse down through your
directory and use a regex to identify the files you want, then use
Spreadsheet::ParseExcel to read the first worksheet and get the first
row.

Use the code on
http://search.cpan.org/~kwitknr/Spreadsheet-ParseExcel-0.2603/ParseExcel.pm
in the Synopsis section and play around with the for loops to have it
break after the first row.

Here's a great column on using File::Find.
http://www.stonehenge.com/merlyn/LinuxMag/col45.html

Sorry for the lack of syntax, but if you need some later, let me know!

Hope this helps,
Kevin
-- 
Kevin Old
[EMAIL PROTECTED]

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




Win32::Setupsup menu item enumeration

2005-03-30 Thread Peter Rabbitson
Hi everyone, I got stuck with the inability of Setupsup::EnumChildWindows or
Setupsup::GetWindowProperties to generate a list of available choices in a
regular menu (the one you get when you do 'open file' for example). I do not
know a thing about MFC, and perl/windows integration is not as well
documented as it could have been.  So here is my situation - I have a list
of 5 items in this menu box. The highlight is placed on the item which was
opened last - hence it is arbitrarily random. This can be somewhat avoided
by sending an excessive number of UP arrows that will make sure I am at the
first one and then do the descend of N steps. However it is possible that in
the future the amount of items will change (e.g. 6 or 7 or even more) which
will render the subroutine useless unless new values are plugged in for each
items position. So the question is if there is a way that I am overlooking
to dump the entire list in an array. Then finding the index of the text in 
question and descend index times from the top and then hit enter would be 
trivial. I am attaching a piece of code and the output it produced - maybe 
it will help someone to give me a better answer:

Thank you

Peter


#=== Code 
# $active_window is the handle of the main window of the app
# there are 4 visible fields, the upper left (company name) with 
# the list in question, then a directory tree next to it, two 
# drop down menus on the bottom, and ok, cancel, help, network 
# buttons on the right

my @children;

EnumChildWindows ($active_window, [EMAIL PROTECTED]);

foreach my $win (@children) {

my %prop;

print "** $win\n";

GetWindowProperties($win, ['menu', 'text', 'wndproc', 'classmenu'], 
\%prop);

print Dumper (%prop);
print "\n";
}



#  Output =

** 19399254
$VAR1 = 'text';
$VAR2 = '';
$VAR3 = 'menu';
$VAR4 = 1039;
$VAR5 = 'classmenu';
$VAR6 = 0;

** 25821678
$VAR1 = 'text';
$VAR2 = 'Company &Name';
$VAR3 = 'menu';
$VAR4 = 1090;
$VAR5 = 'classmenu';
$VAR6 = 0;

** 20251090
$VAR1 = 'text';
$VAR2 = '';
$VAR3 = 'menu';
$VAR4 = 1152;
$VAR5 = 'classmenu';
$VAR6 = 0;

** 22610276
$VAR1 = 'text';
$VAR2 = '';
$VAR3 = 'menu';
$VAR4 = 1120;
$VAR5 = 'classmenu';
$VAR6 = 0;

** 15598048
$VAR1 = 'text';
$VAR2 = '&Directories:';
$VAR3 = 'menu';
$VAR4 = 65535;
$VAR5 = 'classmenu';
$VAR6 = 0;

** 18612702
$VAR1 = 'text';
$VAR2 = 'z:\\ph77px~s';
$VAR3 = 'menu';
$VAR4 = 1088;
$VAR5 = 'classmenu';
$VAR6 = 0;

** 23069314
$VAR1 = 'text';
$VAR2 = '';
$VAR3 = 'menu';
$VAR4 = 1121;
$VAR5 = 'classmenu';
$VAR6 = 0;

** 15401522
$VAR1 = 'text';
$VAR2 = 'List Companies of &Type:';
$VAR3 = 'menu';
$VAR4 = 1089;
$VAR5 = 'classmenu';
$VAR6 = 0;

** 2359640
$VAR1 = 'text';
$VAR2 = '';
$VAR3 = 'menu';
$VAR4 = 1136;
$VAR5 = 'classmenu';
$VAR6 = 0;

** 21299780
$VAR1 = 'text';
$VAR2 = 'Dri&ves:';
$VAR3 = 'menu';
$VAR4 = 1091;
$VAR5 = 'classmenu';
$VAR6 = 0;

** 20120036
$VAR1 = 'text';
$VAR2 = '';
$VAR3 = 'menu';
$VAR4 = 1137;
$VAR5 = 'classmenu';
$VAR6 = 0;

** 27328916
$VAR1 = 'text';
$VAR2 = '&OK';
$VAR3 = 'menu';
$VAR4 = 1;
$VAR5 = 'classmenu';
$VAR6 = 0;

** 20644394
$VAR1 = 'text';
$VAR2 = '&Cancel';
$VAR3 = 'menu';
$VAR4 = 2;
$VAR5 = 'classmenu';
$VAR6 = 0;

** 22938002
$VAR1 = 'text';
$VAR2 = 'Network...';
$VAR3 = 'menu';
$VAR4 = 1037;
$VAR5 = 'classmenu';
$VAR6 = 0;

** 18219564
$VAR1 = 'text';
$VAR2 = '&Help';
$VAR3 = 'menu';
$VAR4 = 9;
$VAR5 = 'classmenu';
$VAR6 = 0;

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




Re: .pm and .pl files.

2005-03-30 Thread Chris Devers
On Wed, 30 Mar 2005, Randal L. Schwartz wrote:

> > "Chris" == Chris Devers <[EMAIL PROTECTED]> writes:
> 
> Chris> By convention, the .pm extension denotes Perl modules -- libraries
> Chris> used by other scripts but not run directly -- and .pl denotes Perl
> Chris> scripts --  programs that *are* meant to be run directly.
> 
> Not scripts.  Libraries.  Scripts don't get extensions, unless you're
> on brain-dead redmond-generated remote distributed virus loaders.
 
That "unless" seems to be the common case these days though... :-/

Or at least, it appears to be on this list, which is what matters here.

 

-- 
Chris Devers

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




Re: [PBML] Finding index of given value in an array

2005-03-30 Thread Randal L. Schwartz
> "Offer" == Offer Kaye <[EMAIL PROTECTED]> writes:

Offer> In this specific case I had no way to know what the OP has as data,
Offer> numbers or strings, so I assumed the general case.

No, the point here is that THERE IS NO GENERAL CASE.

You either want numeric comparisons, or string comparisons.  You can't
use string comparisons for "both".

That's why I keep correcting you.

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
 http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!

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




Re: .pm and .pl files.

2005-03-30 Thread Randal L. Schwartz
> "Chris" == Chris Devers <[EMAIL PROTECTED]> writes:

Chris> By convention, the .pm extension denotes Perl modules -- libraries used 
Chris> by other scripts but not run directly -- and .pl denotes Perl scripts -- 
Chris> programs that *are* meant to be run directly.

Not scripts.  Libraries.  Scripts don't get extensions, unless you're
on brain-dead redmond-generated remote distributed virus loaders.

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
 http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!

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




RE: db handles with fork()

2005-03-30 Thread Ramprasad A Padmanabhan

> I would strongly recommend you connect after the fork. Each process needs to
> have its own connection.

Thanks for the reply. 
   Even I had thought so, probably for efficiency I can use dbi
cached_connect


Ram



--
Netcore Solutions Pvt. Ltd.
Website:  http://www.netcore.co.in
Spamtraps: http://cleanmail.netcore.co.in/directory.html
--

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




RE: db handles with fork()

2005-03-30 Thread Bob Showalter
Ramprasad A Padmanabhan wrote:
> Hi,
>I am writing a perl application that connect to a database and then
> does a fork()
> The child completes the process and does a exit(), but the problem is
> it closes the database connection which the parent would like to use.
> 
> Can I exit the child process without disconnecting the parent dbi
> handle 

I would strongly recommend you connect after the fork. Each process needs to
have its own connection.

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




db handles with fork()

2005-03-30 Thread Ramprasad A Padmanabhan
Hi,
   I am writing a perl application that connect to a database and then
does a fork()
The child completes the process and does a exit(), but the problem is it
closes the database connection which the parent would like to use.

Can I exit the child process without disconnecting the parent dbi handle

Thanks
Ram


--
Netcore Solutions Pvt. Ltd.
Website:  http://www.netcore.co.in
Spamtraps: http://cleanmail.netcore.co.in/directory.html
--

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




Simple encoding function

2005-03-30 Thread Ing. Branislav Gerzo
Hi pals,

I'd like to code my own encode function, I have @list of allowed
characters, my input is number, and I'd like to 'convert' number to
characters. Here is script I coded, but I'm sure it could be really
better. This script should work, but there are too much conditions and
isn't so clear as I think it could be:

use strict;
use warnings;

my $a = 123456789; # $a >= 0
my @list = ( 'a' .. 'z', 'A' .. 'Z', 0 .. 9, '-', '_' );

print my $out = reverse(fn($a));

sub fn {
my $a = shift;
my $out = shift || '';
$out .= $list[$a % @list];
my $b = ($a/@list)-1;
if ( $b >= @list ) { $out .= fn($b) }
$out .= $list[$b] if $list[$b] and $b >= 0; 
return $out;
}
__END__

prints: gv7Zv

So if anyone helps me, how to clear it, I will be glad.

Thanks.

/Brano


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




Re: General questions

2005-03-30 Thread Offer Kaye
On Wed, 30 Mar 2005 09:57:38 +0200, GR Kumaran wrote:
> 
> 2. I used "use strict", and I get error for the statement
> open(IN_FILE1, ">>test_records.txt");
> 
> Here the error is
> Bareword "IN_FILE1" not allowed while "strict subs" in use 
> 
> But if I remove "use strict", the program works well.  So should I
> definately do not use "use strict" if the program want to handle I/O
> files?
> 

The line you gave is okay even under "use strict;", so the problem
must be in some code before this line. One problem I saw in the past
was that a module that was used overloaded the "open" function. To
check if this is the case, change your line to:
CORE::open(IN_FILE1, ">>test_records.txt");

Oh, and you should definitly "use strict; use warnings;" everywhere,
in every script you write!!!

-- 
Offer Kaye

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




General questions

2005-03-30 Thread GR Kumaran
Hello,

1.  I read on many Perl/CGI tutorial/articles that it is best to place
and use CGI files in /cgi-bin/ directory than anywhere else, due to
avoid many problems.  Buy in our website, we have several subdomain
and those are all use the same /cgi-bin/ directory, so now there are a
lot of files populated there.  So now what I have to do to reduce the
management/maintanence problems.


2. I used "use strict", and I get error for the statement
open(IN_FILE1, ">>test_records.txt");

Here the error is
Bareword "IN_FILE1" not allowed while "strict subs" in use 

But if I remove "use strict", the program works well.  So should I
definately do not use "use strict" if the program want to handle I/O
files?


Thank you all.

Greetings,
R. Kumaran



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




Re: [PBML] Finding index of given value in an array

2005-03-30 Thread Offer Kaye
On 29 Mar 2005 10:19:09 -0800, Randal L. Schwartz wrote:
> 
> No, you should change it only when appropriate.  "35.0" is not eq to "35",
> and yet they are numerically equal.
> 

Dratz, foiled again! ;-)

> I hope you don't write the rest of your code like that. :(
> 

In this specific case I had no way to know what the OP has as data,
numbers or strings, so I assumed the general case. If you have strings
and use the "==" operator, you get warnings, no way around that (I'm
assuming "use warnings;" in effect). No only that, use also get a
wrong answer (e.g. "a" == "b" is TRUE).
If you use "eq" and are trying to find "35.0" when the string "35" is
the one you really want, and get a "no match" result, I would say that
is the correct behaviour and the "no match" result is actually
correct, or at least less wrong, since if you have both strings and
numbers I see no way to use "==" for comparison without getting false
results. Am I right?

Regards,
-- 
Offer Kaye

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




Re: File::Find question?

2005-03-30 Thread Offer Kaye
On Tue, 29 Mar 2005 23:31:48 +0200 (CEST), Steven Schubiger wrote:
> 
> print $File::Find::name, "\n" unless /\.txt^/;
> 

No, that should be /\.txt$/ , not /\.txt^/ - you're using the wrong anchor.

-- 
Offer Kaye

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




Re: HTML parsing

2005-03-30 Thread FreeFall
I am new to Perl too and have a little try:

  #!/usr/bin/perl
  use warnings;
  use strict;
  
  my @data;
  while (<>) {
 chomp;
 push @data,$_ if !/^\ wrote:

> Hi all,
> 
> I'm brand new to Perl, and have just a little programming background.  I was 
> tasked with parsing a set of .html files in order to extract the data 
> contained within some terribly formatted tables.  Here is a sample of what I 
> have.
> 
> 
> Data to be extracted 
> 
> DATA DATA DATA
> 
> Need this too
> More data I need to get 
> out
> 
> 
> This is one row from the typical four row table that is returned as a search 
> result.  There are 25 of these four row tables per page.  Could someone point 
> me in the right direction as to how I might go about doing this?  A colleague 
> of mine told me "put the file into an array and use the 'split' 
> command"while I vaguely understand the concept, I'm not sure about the 
> syntax.  Can anyone shed some light?
> 
> Thanks in advance,
> 
> Dan
> 
> 


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

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




Re: .pm and .pl files.

2005-03-30 Thread John W. Krahn
Srikrishna Raghammudi wrote:
Can Any body pls tell me the differnece between .pm and .pl files. 
.pl was used in Perl4 and earlier to designate Perl Libraries and when Perl5 
came out .pm was used to designate Perl Modules.

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