RE: perl/Tk and piping questions

2006-08-28 Thread John Cortland Morgan \(ZG/ETK\)
Hi,

  Thanks for the tip about  

 The book Mastering Perl/Tk has a pretty good Chapter 3 on Geometry
Management.  
 You can probably read it for free with an sign up at
http://safari.oreilly.com/


about the piping question, it's not an either/or situation. It could be
both.
A good example is the unix wc command. First create a small file

echo hello  hello.txt # 6 chars hello + \n

then do:

# piped input but no command line options (so uses default options)
cat hello.txt | wc
1   1   6

# both piped input and command line options
cat hello.txt | wc -c
6

# only command line options
wc -c hello.txt
6

I have tried similar to your suggestion (many different combinations):

 This will test for a pipe

 #!/usr/bin/perl
 # -t tests if a tty is input, else it's a pipe 
 
 if (@ARGV == 0 and -t) {
  die Usage: $0 INPUT\n;
  }
 
 while () {
  ## process input file(s) here 
  }
 __END__


The problem(s) with using -t and  (as above) are:

if you give only command line line options, the program will
hang waiting for input. 

If I change it to if-else type decision making, -t causes the
piped input to be ignored.


As I said, I hacked together a subroutine from examples in the
Perl Cookbook, but it's not very elegant:


sub piper {
my @_ARGV = @ARGV; @ARGV = ();  # save command line options (if
any)
my @input = ();

   $SIG{ALRM} = sub { die timeout };

   my $pid;
   if ($pid = open(CHILD, -|)) {  # parent code
while(CHILD) {# gets piped
input from CHILD (if any)
push @input, $_;
}
close CHILD;
alarm(0);
}
else {  # child code
die cannot fork: $! unless defined $pid;

eval {
alarm(1);
while() { print; }# piped input
goes to parent (if any)
alarm(0);
};
exit;
}

@ARGV = @_ARGV; # restore so we can
parse any options
return @input;  # this is any data which
was piped in
}


any comments/suggestions about this solution are greatly appreciated. As
I said, surely there is
a module out there that does this type of thing better?

regards,

John

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Image split....

2006-08-28 Thread Nagasamudram, Prasanna Kumar
Hi All

 

Can anybody suggest me any module/script that can be used to split and
image into pieces?

 

I tried to search in CPAN also googled a lot.

 

I could only find image splitting software..but I need command line
utility.

 

 

Thanks

Prasanna



Re: Image split....

2006-08-28 Thread Gretar Mar Hreggvidsson

Hi

I would probably use the module Imager (see CPAN), and it's crop() 
function.  The function doesn't modify the source, it returns a new, 
cropped image based on the coordinates you submit to it.


Best regards,
Grétar Mar

Nagasamudram, Prasanna Kumar wrote:

Hi All

 


Can anybody suggest me any module/script that can be used to split and
image into pieces?

 


I tried to search in CPAN also googled a lot.

 


I could only find image splitting software..but I need command line
utility.

 

 


Thanks

Prasanna





--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




RE: Image split....

2006-08-28 Thread Nagasamudram, Prasanna Kumar
-Original Message-
From: Gretar Mar Hreggvidsson [mailto:[EMAIL PROTECTED] 
Sent: Monday, August 28, 2006 5:29 PM
To: Nagasamudram, Prasanna Kumar
Cc: beginners@perl.org
Subject: Re: Image split

Hi

I would probably use the module Imager (see CPAN), and it's crop() 
function.  The function doesn't modify the source, it returns a new, 
cropped image based on the coordinates you submit to it.

Best regards,
Grétar Mar

Nagasamudram, Prasanna Kumar wrote:
 Hi All
 
  
 
 Can anybody suggest me any module/script that can be used to split and
 image into pieces?
 
  
 
 I tried to search in CPAN also googled a lot.
 
  
 
 I could only find image splitting software..but I need command line
 utility.
 
  
 
  
 
 Thanks
 
 Prasanna
 
 




Hi Gretar


Thanks a lot and that's exactly what I needed.

I have a small query related to this.


The following is my code which works perfectly fine for a BMP.

use Imager;

my $img = Imager-new();
$img-read(file='p.bmp', type='bmp') or die $img-errstr();

$newimg = $img-crop(left=0, right=510, top=0, bottom=384); 
$newimg-write(file=t1.bmp) or die $newimg-errstr();



But If I change the following line

$img-read(file='p.bmp', type='bmp') or die $img-errstr();

   TO
$img-read(file='p.jpg', type='jpg') or die $img-errstr();



I get the following error.


format 'jpg' not supported at i.pl line 4.


The same is for other formatsexcept bmp.

Is this a limitation or I'm I doing something wrong?

Thanks
Prasanna

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Image split....

2006-08-28 Thread Gretar Mar Hreggvidsson


But If I change the following line

$img-read(file='p.bmp', type='bmp') or die $img-errstr();

   TO
$img-read(file='p.jpg', type='jpg') or die $img-errstr();



I get the following error.


format 'jpg' not supported at i.pl line 4.


The same is for other formatsexcept bmp.

Is this a limitation or I'm I doing something wrong?

The format is called 'jpeg'.  To get a list a supported formats try 
something like:


  perl -e 'use Imager; print $_\n for keys %Imager::formats;'

If, on the other hand, jpeg is not listed there, you are probably 
missing the jpeg libraries (/usr/lib/libjpeg*)


G.

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




hash lookup table

2006-08-28 Thread Derek B. Smith
All, 

I am trying to run logic that will copy/delete  3
versions of log.\d+ files to their respective
directories.  Because there are so many directories, I
have built a hash table instead of using a bunch of
if else conditions with reg exps. My problem is it
is not returning the words_num translation from the
print sub routine call words_to_num.  

BEGIN CODE


foreach my $log (@twoweekdir_contents) {
  $NBlogs2[$i++] = 
  $log if ($log =~
   /bpcd\/log|bpdbm\/log|bptm\/log.\d+/);
}

##-- Build a hash look-up table for subdirs --##

  my %subdir_for = (
'admin'= 0,  'bp' = 1, 
'bparchive'= 2, 'bpbackup'= 3,  
'bpbkar'   = 4, 'bpbrm'   = 5,
'bpbrmds'  = 6, 'bpbrmvlt'= 7, 
'bpcd' = 8,'bpcompatd'= 9,  
'bpcoord'  = 10,'bpdb2'   = 11,
'bpdbjobs' = 12, 'bpdbm'  = 13,
'bpdbsbdb2'= 14,'bpdbsbora'   = 15, 
'bpdm' = 16,'bpdynamicclient' = 17,
'bpfilter' = 18, 'bpfis'  = 19,
'bpfsmap'  = 20,
'bphdb'= 21, 'bpinst'  = 22,
'bpjava-msvc'  = 23,'bpjava-susvc' = 24, 
'bpjava-usvc'  = 25,'bpjobd'= 26,
'bpkeyutil'= 27, 'bplist'  = 28,
'bpmount'  = 29, 'bpnbat' =30, 
'bporaexp' = 31,'bporaimp'= 32,
'bporaimp64'   = 33, 'bppfi'   = 34,
'bprd' = 35,'bprestore'   = 36, 
'bpsched' = 37,'bpsynth'  = 38,
'bptm' = 39, 'dbclient'= 40,
'infxbsa'  = 41,'mtfrd'   = 42, 
'nbpushdata'  = 43,'nbvault'  = 44,
'sybackup' = 45, 'symlogs' = 46,
'tar'  = 47,'vault'  = 48, 
'vnetd'   = 49,'vopied'   = 50,
'bporaexp64'   = 51, 'mklogdir'= 52,

);

sub words_to_num {
   my $words = @_;

##-- Treat each sequence of \S+ as a word --##
   my @words = split /\s+/, $words;

##-- Translate each word to its appropriate
number --##
my $num = q{};
foreach my $word (@words) {
   my $digit = $subdir_for{lc $word};
   if (defined $digit) {
  $num .= $digit;
   }
}

return $num;

} ##-- End routine words_to_num --##

print words_to_num('vopied admin'),\n;

snippet {}

So instead of doing the code below because the subdirs
are unique but all log file names are the same,
log.\d+,  I want
to use a hash table to decide what log files to copy
where based on the subdir names or the key/value
relationship.

if (@NBlogs2) {
  for my $log(@NBlogs2) {
  if ($log =~ 'bpcd') {
 qx(cp $log $oldir/bpcd/);   
  }
  elsif ($log =~ 'bpdbm') {
 qx(cp $log $oldir/bpdbm);
  }
  elsif ($log =~ 'bptm') {
 qx(cp $log $oldir/bptm);
  }
 } 
}

thank you
derek


__
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




odd variable result

2006-08-28 Thread Curt Shaffer
List,

 

I am trying to set a variable based on a system call. Here is my code:

 

#!/usr/bin/perl

 

use strict;

 

 

my $test = system `/usr/bin/snmpget -v1 10.1.11.18 -c secret
.1.3.6.1.4.1.710.7.1.5.1.23.1.13.1|awk '{print $4}'`;

print $test\n;

 

When I run that command from the command line it works as desired. When I
run the script with the system command in  rather than ` it returns the
whole value rather than the $4 that I need, then the print $test returns 0.
When I run the script as above the print $test it appears to set the
variable but produces a -1 which is not in the value that is returned at
all. Anyone have some guidance for me on how to do this properly?

 

Thanks

 

Curt



re: hash lookup table

2006-08-28 Thread Lawrence Statton XE1/N1GAK

Trivial problem.
What does $words *really* contain in your subrotuine words_to_num?


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: odd variable result

2006-08-28 Thread Derek B. Smith
try this syntax:


my $test = system (/usr/bin/snmpget -v1 10.1.11.18
-c secret
.1.3.6.1.4.1.710.7.1.5.1.23.1.13.1|awk '{print $4}');

or 

my $test = qx(you command above w/no quotes needed);

or 

open (SNMP, snmpget -v1 10.1.11.18 -c secret
.1.3.6.1.4.1.710.7.1.5.1.23.1.13.1 ) or die failed
opening snmpget $!;

foreach (SNMP) {
   my $test = (split)[4];
}


close SNMP or warn $!;

--- Curt Shaffer [EMAIL PROTECTED] wrote:

 List,
 
  
 
 I am trying to set a variable based on a system
 call. Here is my code:
 
  
 
 #!/usr/bin/perl
 
  
 
 use strict;
 
  
 
  
 
 my $test = system `/usr/bin/snmpget -v1 10.1.11.18
 -c secret
 .1.3.6.1.4.1.710.7.1.5.1.23.1.13.1|awk '{print
 $4}'`;
 
 print $test\n;
 
  
 
 When I run that command from the command line it
 works as desired. When I
 run the script with the system command in  rather
 than ` it returns the
 whole value rather than the $4 that I need, then the
 print $test returns 0.
 When I run the script as above the print $test it
 appears to set the
 variable but produces a -1 which is not in the value
 that is returned at
 all. Anyone have some guidance for me on how to do
 this properly?
 
  
 
 Thanks
 
  
 
 Curt
 
 


__
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




RE: odd variable result

2006-08-28 Thread Curt Shaffer
They all seem to skip the awk command. For your open example, I am confused.
It gives me the error:

failed opening snmpget No such file or directory at ./test.pl line 5.

Thanks

-Original Message-
From: Derek B. Smith [mailto:[EMAIL PROTECTED] 
Sent: Monday, August 28, 2006 10:05 AM
To: Curt Shaffer; Perl List
Subject: Re: odd variable result

try this syntax:


my $test = system (/usr/bin/snmpget -v1 10.1.11.18
-c secret
.1.3.6.1.4.1.710.7.1.5.1.23.1.13.1|awk '{print $4}');

or 

my $test = qx(you command above w/no quotes needed);

or 

open (SNMP, snmpget -v1 10.1.11.18 -c secret
.1.3.6.1.4.1.710.7.1.5.1.23.1.13.1 ) or die failed
opening snmpget $!;

foreach (SNMP) {
   my $test = (split)[4];
}


close SNMP or warn $!;

--- Curt Shaffer [EMAIL PROTECTED] wrote:

 List,
 
  
 
 I am trying to set a variable based on a system
 call. Here is my code:
 
  
 
 #!/usr/bin/perl
 
  
 
 use strict;
 
  
 
  
 
 my $test = system `/usr/bin/snmpget -v1 10.1.11.18
 -c secret
 .1.3.6.1.4.1.710.7.1.5.1.23.1.13.1|awk '{print
 $4}'`;
 
 print $test\n;
 
  
 
 When I run that command from the command line it
 works as desired. When I
 run the script with the system command in  rather
 than ` it returns the
 whole value rather than the $4 that I need, then the
 print $test returns 0.
 When I run the script as above the print $test it
 appears to set the
 variable but produces a -1 which is not in the value
 that is returned at
 all. Anyone have some guidance for me on how to do
 this properly?
 
  
 
 Thanks
 
  
 
 Curt
 
 


__
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Very dangerous code

2006-08-28 Thread Nath, Alok (STSD)
Hi, 

I have this web page which saves data in an xml.

The web page has few textfields which takes input
and has a submit button.The data is saved in an XML 
when pressed the submit button.

I am using CGI module for web page and XML::twig 
module to save the data.

Sometimes I have observed while saving the data
the explorer crashes.If the XML is opened it will
definetly crash probably while writing into it.

Can anybody point out what is wrong ?

Thanx,
Alok
my $registerFile = Register.xml ;
my $twig = XML::Twig-new( pretty_print = 'indented' );
$twig-parsefile( $registerFile );


#This is the code to save and write into the XML
if (pressed submit button execute this)
{
my $node = XML::Twig::Elt-new(
'User', {'name' = $usr},
XML::Twig::Elt-new( 'email' =
$email )) ;
$node-paste( last_child = $twig-root ) ;
$twig-print_to_file( $registerFile ) ; 

print h3 Saved Successfully !! /h3 ;
}

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: odd variable result

2006-08-28 Thread John W. Krahn
Curt Shaffer wrote:
 List,

Hello,

 I am trying to set a variable based on a system call.

In Perl a system call would be open() or link() or crypt(), etc.  You mean
that you are trying to set a variable based on the output of an external 
program.


 Here is my code:
 
 #!/usr/bin/perl

use warnings;

 use strict;
 
 my $test = system `/usr/bin/snmpget -v1 10.1.11.18 -c secret
 .1.3.6.1.4.1.710.7.1.5.1.23.1.13.1|awk '{print $4}'`;

You are using back-quotes AND system() so if your external command displayed
the text:

1234

then the back-quotes would return 1234\n and system() would run the program
1234\n and return the exit status of the program 1234\n.

It looks like you may want something like:

my $test = ( split ' ', `/usr/bin/snmpget -v1 10.1.11.18 -c secret
.1.3.6.1.4.1.710.7.1.5.1.23.1.13.1` )[ 3 ];

Or perhaps you need to use one of the SNMP modules at:
http://search.cpan.org/search?m=moduleq=snmps=1n=100



John
-- 
use Perl;
program
fulfillment

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: hash lookup table

2006-08-28 Thread John W. Krahn
Derek B. Smith wrote:
 All, 

Hello,

 I am trying to run logic that will copy/delete  3
 versions of log.\d+ files to their respective
 directories.  Because there are so many directories, I
 have built a hash table instead of using a bunch of
 if else conditions with reg exps. My problem is it
 is not returning the words_num translation from the
 print sub routine call words_to_num.  
 
 BEGIN CODE
 
 
 foreach my $log (@twoweekdir_contents) {
   $NBlogs2[$i++] = 
   $log if ($log =~
/bpcd\/log|bpdbm\/log|bptm\/log.\d+/);

Your pattern says match the string 'bpcd/log' OR 'bpdbm/log' OR 'bptm/log'
followed by any character followed by one or more digits and the pattern can
be located anywhere in the $log variable.  Are you sure that you don't want
digits after 'bpcd/log' or 'bpdbm/log'?


 }
 
 ##-- Build a hash look-up table for subdirs --##
 
   my %subdir_for = (
 'admin'= 0,  'bp' = 1, 
 'bparchive'= 2, 'bpbackup'= 3,  
 'bpbkar'   = 4, 'bpbrm'   = 5,
 
 [ snip ]
 
 'tar'  = 47,'vault'  = 48, 
 'vnetd'   = 49,'vopied'   = 50,
 'bporaexp64'   = 51, 'mklogdir'= 52,
 
 );
 
 sub words_to_num {
my $words = @_;

An array in scalar context returns the number of elements in that array.  You
want to use either:

my $words = shift;

Or:

my $words = $_[ 0 ];

Or:

my ( $words ) = @_;


 ##-- Treat each sequence of \S+ as a word --##
my @words = split /\s+/, $words;
 
 ##-- Translate each word to its appropriate
 number --##
 my $num = q{};
 foreach my $word (@words) {
my $digit = $subdir_for{lc $word};
if (defined $digit) {
   $num .= $digit;
}
 }
 
 return $num;

That could be written as:

sub words_to_num {
no warnings 'uninitialized';
join '', @subdir_for{ split ' ', lc shift }
}




John
-- 
use Perl;
program
fulfillment

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: odd variable result

2006-08-28 Thread John W. Krahn
Curt Shaffer wrote:
 
 From: John W. Krahn [mailto:[EMAIL PROTECTED] 
 
 Curt Shaffer wrote:

my $test = system `/usr/bin/snmpget -v1 10.1.11.18 -c secret
.1.3.6.1.4.1.710.7.1.5.1.23.1.13.1|awk '{print $4}'`;
 
 You are using back-quotes AND system() so if your external command displayed
 the text:
 
 1234
 
 then the back-quotes would return 1234\n and system() would run the
 program
 1234\n and return the exit status of the program 1234\n.
 
 It looks like you may want something like:
 
 my $test = ( split ' ', `/usr/bin/snmpget -v1 10.1.11.18 -c secret
 .1.3.6.1.4.1.710.7.1.5.1.23.1.13.1` )[ 3 ];
 
 Or perhaps you need to use one of the SNMP modules at:
 http://search.cpan.org/search?m=moduleq=snmps=1n=100
 
 I got it by doing the following:

 my $sig=0;
 $sig = qx(/usr/bin/snmpget -v1 $host -c secret
 .1.3.6.1.4.1.710.7.1.5.1.23.1.13.1);
 my @test=$sig;

Why?

 my @test=split(/ /,$sig);

split(/ /,$sig) splits on a single space character so if the output has
multiple spaces or tabs separating the fields then this won't work correctly.


 $sig=$test[3];


John
-- 
use Perl;
program
fulfillment

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




number rounding problem

2006-08-28 Thread Howard, Chris

Hi,

I don't know if this is the right mailing list for this question.
Let me know if I should go somewhere else.

The issue is a number rounding problem.

Here is my perl snippet:


$credit = 64.63;
$amount = $credit * 1000;

printf credit %s,  amount %12.12d\n, $credit, $amount;

$amount = $amount / 10;

printf credit %s,  amount %12.12d\n, $credit, $amount;



What starts out as 64.63  ends up being 0006462

That's bad.  Any ideas on how to fix, work around etc?

I've reproduced this on my main server (HP-UX,
Perl 5.08.05) and on another machine  (Red Hat Enterprise
Linux also Perl 5.08.05)

Thanks!



--
Chris Howard  
CIS Database Administrator   Platte River Power Authority
[EMAIL PROTECTED]   (970) 229-5248 

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: number rounding problem

2006-08-28 Thread Adriano Ferreira

Chris,


printf credit %s,  amount %12.12d\n, $credit, $amount;


What really went wrong was to use a %d specifier. It says to truncate
a floating number into integer. Like it happens in

$ perl -e 'print int 1000*shift' 64.63
64629

If you use %f, it may improve

$ perl -e 'printf %f,  1000*shift' 64.63
64630.00

But I am not sure you would like %12.12f

$ perl -e 'printf %12.12f,  1000*shift' 64.63
64629.9993

Maybe %12.2f

$ perl -e 'printf %12.2f,  1000*shift' 64.63
   64630.00

Regards,
Adriano Ferreira

On 8/28/06, Howard, Chris [EMAIL PROTECTED] wrote:

I don't know if this is the right mailing list for this question.
Let me know if I should go somewhere else.

The issue is a number rounding problem.

Here is my perl snippet:


$credit = 64.63;
$amount = $credit * 1000;

printf credit %s,  amount %12.12d\n, $credit, $amount;

$amount = $amount / 10;

printf credit %s,  amount %12.12d\n, $credit, $amount;



What starts out as 64.63  ends up being 0006462

That's bad.  Any ideas on how to fix, work around etc?


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: number rounding problem

2006-08-28 Thread Dr.Ruud
Howard, Chris schreef:

 What starts out as 64.63  ends up being 0006462

No, it ends up beint printed as that. Replace your %12.12d by one of
(%s, %f, %g) to get different representations.

See also

   perldoc -q decimals

-- 
Affijn, Ruud

Gewoon is een tijger.



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




RE: number rounding problem

2006-08-28 Thread Howard, Chris

But the file output format I'm required to produce 
is 12 positions with leading zeros and no decimal.

:-(

Chris



-Original Message-
From: Dr.Ruud [mailto:[EMAIL PROTECTED]
Sent: Monday, August 28, 2006 11:17 AM
To: beginners@perl.org
Subject: Re: number rounding problem


Howard, Chris schreef:

 What starts out as 64.63  ends up being 0006462

No, it ends up beint printed as that. Replace your %12.12d by one of
(%s, %f, %g) to get different representations.

See also

   perldoc -q decimals

-- 
Affijn, Ruud

Gewoon is een tijger.



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response



--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




RE: number rounding problem

2006-08-28 Thread John Cortland Morgan \(ZG/ETK\)

Something with word size of multiplying by 1000, I'd venture. 
This works as you need, I think:

$credit = 64.63;
$amount = $credit * 100;
printf credit %s,  amount %12.12d\n, $credit, $amount;

$amount = $amount * 10;
printf credit %s,  amount %12.12d\n, $credit, $amount;

$amount = $amount / 10;
printf credit %s,  amount %12.12d\n, $credit, $amount;


but that begs the question, Why are you doing ( x * 1000 / 10 ) 
and not just ( x * 100 ) to start with?

John


-Original Message-
From: Howard, Chris [mailto:[EMAIL PROTECTED] 
Sent: Monday, August 28, 2006 7:29 PM
To: Dr.Ruud; beginners@perl.org
Subject: RE: number rounding problem


But the file output format I'm required to produce is 12 positions with
leading zeros and no decimal.

:-(

Chris



-Original Message-
From: Dr.Ruud [mailto:[EMAIL PROTECTED]
Sent: Monday, August 28, 2006 11:17 AM
To: beginners@perl.org
Subject: Re: number rounding problem


Howard, Chris schreef:

 What starts out as 64.63  ends up being 0006462

No, it ends up beint printed as that. Replace your %12.12d by one of
(%s, %f, %g) to get different representations.

See also

   perldoc -q decimals

--
Affijn, Ruud

Gewoon is een tijger.



--
To unsubscribe, e-mail: [EMAIL PROTECTED] For additional
commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
http://learn.perl.org/first-response



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response



--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: number rounding problem

2006-08-28 Thread Dr.Ruud
Howard, Chris schreef:

[next time, do not toppost, and quote more effectively]

 Ruud:
 Chris:

 What starts out as 64.63  ends up being 0006462

 No, it ends up beint printed as that. Replace your %12.12d by one of
 (%s, %f, %g) to get different representations.

 But the file output format I'm required to produce
 is 12 positions with leading zeros and no decimal.

Then make sure that the numerical value of the variable is what you want
it to be, for example:

  $amount = int(0.5 + $amount / 10) ;

Alternative format: %012d.

-- 
Affijn, Ruud

Gewoon is een tijger.



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: hash lookup table

2006-08-28 Thread Derek B. Smith


--- John W. Krahn [EMAIL PROTECTED] wrote:

 Derek B. Smith wrote:
  All, 
 
 Hello,
 
  I am trying to run logic that will copy/delete  3
  versions of log.\d+ files to their respective
  directories.  Because there are so many
 directories, I
  have built a hash table instead of using a bunch
 of
  if else conditions with reg exps. My problem is
 it
  is not returning the words_num translation from
 the
  print sub routine call words_to_num.  
  
  BEGIN CODE
  
  
  foreach my $log (@twoweekdir_contents) {
$NBlogs2[$i++] = 
$log if ($log =~
 /bpcd\/log|bpdbm\/log|bptm\/log.\d+/);
 
 Your pattern says match the string 'bpcd/log' OR
 'bpdbm/log' OR 'bptm/log'
 followed by any character followed by one or more
 digits and the pattern can
 be located anywhere in the $log variable.  Are you
 sure that you don't want
 digits after 'bpcd/log' or 'bpdbm/log'?
 
 



No I do not want to do thisnice catch. It should
read /bpcd\/log|bpdbm\/log|bptm\/log\.\d+/);
so that I catch log and a period and number after the
period.

thank you
derek



__
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: hash lookup table

2006-08-28 Thread Mumia W.

On 08/28/2006 08:37 AM, Derek B. Smith wrote:
All, 

I am trying to run logic that will copy/delete  3 
versions of log.\d+ files to their respective 
directories.  Because there are so many directories, I 
have built a hash table instead of using a bunch of 
if else conditions with reg exps. 
[...]


So instead of doing the code below because the subdirs 
are unique but all log file names are the same, 
log.\d+,  I want 
to use a hash table to decide what log files to copy 
where based on the subdir names or the key/value 
relationship.


if (@NBlogs2) {
  for my $log(@NBlogs2) {
  if ($log =~ 'bpcd') {
 qx(cp $log $oldir/bpcd/);   
  }

  elsif ($log =~ 'bpdbm') {
 qx(cp $log $oldir/bpdbm);
  }
  elsif ($log =~ 'bptm') {
 qx(cp $log $oldir/bptm);
  }
 } 
}




This was the only code in your post that I was able to 
understand because I wasn't able to figure out what 
words_to_num() was supposed to do. Here are two ways to go 
about something like what you want to do:



# This is ultra-simple and doesn't do
# what you want.

if (@NBlogs2) {
  for my $log (@NBlogs2) {
if ($log =~ m{([[:alpha:]]+)/log.\d+}) {
  my $word = $1;
  qx(echo cp $log $oldir/$word);
}
  }
}


# This might come closer to what you want.

foreach my $log (@NBlogs2) {
  if ($log =~ m{([[:alpha:]]+)/log.\d+}) {
my $word = $1;
my $number = $subdir_for{$word};
qx(echo cp $log $oldir/$number);
  }
}

I decided to echo the command rather than to execute it. ALL 
CODE UNTESTED.



thank you
derek



You're welcome.



--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




RE: number rounding problem

2006-08-28 Thread Howard, Chris


Thanks!


-Original Message-
From: Dr.Ruud [mailto:[EMAIL PROTECTED]
Sent: Monday, August 28, 2006 12:00 PM
To: beginners@perl.org
Subject: Re: number rounding problem


Howard, Chris schreef:

[next time, do not toppost, and quote more effectively]

 Ruud:
 Chris:

 What starts out as 64.63  ends up being 0006462

 No, it ends up beint printed as that. Replace your %12.12d by one of
 (%s, %f, %g) to get different representations.

 But the file output format I'm required to produce
 is 12 positions with leading zeros and no decimal.

Then make sure that the numerical value of the variable is what you want
it to be, for example:

  $amount = int(0.5 + $amount / 10) ;

Alternative format: %012d.

-- 
Affijn, Ruud

Gewoon is een tijger.



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response



--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




RE: perl/Tk and piping questions

2006-08-28 Thread Ken Foskey
On Mon, 2006-08-28 at 12:27 +0200, John Cortland Morgan (ZG/ETK) wrote:
 
  This will test for a pipe
 
  #!/usr/bin/perl
  # -t tests if a tty is input, else it's a pipe 
  
  if (@ARGV == 0 and -t) {
   die Usage: $0 INPUT\n;
   }
  
  while () {
   ## process input file(s) here 
   }
  __END__
 
 
 The problem(s) with using -t and  (as above) are:
 
 if you give only command line line options, the program will
 hang waiting for input. 
 

If you use getopts it will consume the options,  just put the test after
the getopts processing.

Other alternative is to use a simple shift.

-- 
Ken Foskey
FOSS developer


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: hash lookup table

2006-08-28 Thread John W. Krahn
Derek B. Smith wrote:
 
 --- John W. Krahn [EMAIL PROTECTED] wrote:
 
Derek B. Smith wrote:

I am trying to run logic that will copy/delete  3
versions of log.\d+ files to their respective
directories.  Because there are so many
directories, I
have built a hash table instead of using a bunch
of
if else conditions with reg exps. My problem is
it
is not returning the words_num translation from
the
print sub routine call words_to_num.  

BEGIN CODE


foreach my $log (@twoweekdir_contents) {
  $NBlogs2[$i++] = 
  $log if ($log =~
   /bpcd\/log|bpdbm\/log|bptm\/log.\d+/);
Your pattern says match the string 'bpcd/log' OR
'bpdbm/log' OR 'bptm/log'
followed by any character followed by one or more
digits and the pattern can
be located anywhere in the $log variable.  Are you
sure that you don't want
digits after 'bpcd/log' or 'bpdbm/log'?
 
 No I do not want to do thisnice catch. It should
 read /bpcd\/log|bpdbm\/log|bptm\/log\.\d+/);
 so that I catch log and a period and number after the
 period.

If you want all the logs to end with '\.\d+' then you need something like:

m!bp(?:cd|dbm|tm)/log\.\d+!



John
-- 
use Perl;
program
fulfillment

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Reading Excel spreadsheet into variables

2006-08-28 Thread Stephan Gross
I'm reading in an Excel spreadsheet using Win32::OLE.  I want to read in
the entire spreadsheet.  I found a piece of code that does that:
$everything = $sheet-UsedRange()-{Value};
for (@$everything) 
{
for (@$_) 
{
print defined($_) ? $_| : undef|;
}

print \n;
}

However, I don't understand what @$everything and @$_ are; arrays,
arrays of arrays, hashes?  It looks like the entire spreadsheet goes
into $everything, which is more confusing since it is a scalar.  I'd
like to extract the second and fifth elements of a row and create a hash
out of them.
 
On another note, I have to run my script three times to get it to work.
The first time it doesn't run at all, the second time it hangs and the
third time it works properly.  I assume this is a function of the code
that starts/stops the excel application (the spreadsheet only becomes
visible on the third try).  Any ideas on this?
 
Thanks!

__
Steve Gross  Tel:
212-284-6558
Director of Information Technology Cell:
917-575-4028
JESNA Fax:
212-284-6951
www.jesna.org

 


How do i open excel files under linux

2006-08-28 Thread Toddy Prawiraharjo
Is it possible to open excel files under linux? I read about libwin32,
and it seems it doesn't work under linux. Is this true?
 
Thank in advance
 
Toddy


RE: How do i open excel files under linux

2006-08-28 Thread Timothy Johnson
This is true, however I believe Spreadsheet::ParseExcel still works
under Linux.



-Original Message-
From: Toddy Prawiraharjo [mailto:[EMAIL PROTECTED] 
Sent: Monday, August 28, 2006 4:05 PM
To: beginners@perl.org
Subject: How do i open excel files under linux

Is it possible to open excel files under linux? I read about libwin32,
and it seems it doesn't work under linux. Is this true?
 


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




RE: Reading Excel spreadsheet into variables

2006-08-28 Thread Timothy Johnson
$everything is a scalar reference to an array.  You can dereference the
array with the '@$everything' notation or the '@{$everything}' notation.
(The second one removes any ambiguity about the reference, but 99% of
the time the first way is okay.)

You can access elements of the array by either doing this:

   ${$everything}[0];

or this:

   $everything-[0];

The second way is easier to read for most people.


This also works for hashes.

   my $hash = {name = 'Tim', age = 29};

   print keys %{$hash};

   print $hash-{age};


As for the second question, you would have to show us more of your code
to be sure.





-Original Message-
From: Stephan Gross [mailto:[EMAIL PROTECTED] 
Sent: Monday, August 28, 2006 3:44 PM
To: beginners@perl.org
Subject: Reading Excel spreadsheet into variables

snip

However, I don't understand what @$everything and @$_ are; arrays,
arrays of arrays, hashes?  
snip
 
On another note, I have to run my script three times to get it to work.
The first time it doesn't run at all, the second time it hangs and the
third time it works properly.  I assume this is a function of the code
that starts/stops the excel application (the spreadsheet only becomes
visible on the third try).  Any ideas on this?
 
Thanks!

snip

 


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: How do i open excel files under linux

2006-08-28 Thread Sastry

Use Open Office

On 8/29/06, Toddy Prawiraharjo [EMAIL PROTECTED] wrote:


Is it possible to open excel files under linux? I read about libwin32,
and it seems it doesn't work under linux. Is this true?

Thank in advance

Toddy




RE: How do i open excel files under linux

2006-08-28 Thread Toddy Prawiraharjo
LOL
 
Thanks all, Im using Spreadsheet::ParseExcel, ::Read, and ::ReadSXC. I'm
rolling now. Found out also xls2csv is very2x helpful.
 
 
Cheers!
 
Toddy Prawiraharjo

-Original Message-
From: Sastry [mailto:[EMAIL PROTECTED] 
Sent: Tuesday, 29 August 2006 1:45 PM
To: [EMAIL PROTECTED]
Cc: beginners@perl.org
Subject: Re: How do i open excel files under linux



Use Open Office


On 8/29/06, Toddy Prawiraharjo [EMAIL PROTECTED] wrote: 

Is it possible to open excel files under linux? I read about libwin32,
and it seems it doesn't work under linux. Is this true?

Thank in advance

Toddy






how to make http cgi-perl script work for https

2006-08-28 Thread krishna prasad
Hi,
I an very new to CGI and want to know how to make the
CGI(with perl) pages presently working on http work on
https.

I have the following webpage Logout.cgi.

#!/opt/plat/bin/perl

use strict;
use Time::localtime;
use CGI;
use CGI::Carp 'fatalsToBrowser';
use lib /opt/appl/web/cgi-bin;
use GS;
use Funct;

my $input = new CGI;
my $gs = GS-new();

print $input-header;

use Session;
my $sess = Session-new();
my $sessCookie = $input-cookie('session');
my $userId = undef;
my $sessId = undef;
if (defined $sessCookie)
{
  ($userId, $sessId) =
$sess-validateSession($sessCookie);
}

if ((not defined $userId) or (not defined $sessId))
{
  Func::DisplayAccessDeniedPage();
  exit;
}

if (not defined $input-param)
{
  print html\nheadtitleLogout/titlelink
rel='stylesheet' type='text/css'
href='/style/WorkSpace.css'/head;
  print \nbody;

  Funct::DisplayHeader(Logout);
  Func::BeginContentTable();

  Func::DisplayInfoMessage(This will terminate your
login session, Are you sure you want to continue?);

  print  br centerform action='logout.cgi'
METHOD=post TARGET=_top   input name=logout
TYPE=submit VALUE=Logout /form/center;

  Func::EndContentTable();
  Func::DisplayFooter();
}
else
{
  $sess-deleteSession($userId, $sessId);

  print htmltitleLink to login screen/title
body onload=deleteCookie('session')meta
http-equiv=\refresh\ content=\0;
URL=/cgi-in/logon.cgi\
script language=javascript src='/js/Validation.js'
type='text/javascript'/script /body /html;
}

print $input-end_html();


Presently the above script works fine for http, when I
invoke by http://ip address/logout.cgi. I want to
know if any changes has to be made to the above script
to make it work with https i.e by https://ip
address/logout.cgi.

Also want to know if any configuration changes need to
be made in the apache web server.

Thanks in advance

Regards
Krishna

__
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response