RE: problem printf

2004-10-24 Thread Charles K. Clarkson
deny <[EMAIL PROTECTED]> wrote:

: i ve found a perl script to  calculate the sum of the
: permissions  my principal files 
: 
: the line which is writing in my file is
: 
: foreach $name ( sort @files) {
:($uid,$gid) = (stat $nane)[4,5];
:ici   la ligne $stat = sprintf "%Oo",
: (stat_)[2];// 


That isn't only perl code, it's incomplete, and it
doesn't use 'printf'.  Show us more code and explain
your problem fully.


HTH,

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


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




Re: problem printf

2004-10-25 Thread deny

   That isn't only perl code, it's incomplete, and it
doesn't use 'printf'.  Show us more code and explain
your problem fully.
 

thanks for your help
here is the complete code
#!/usr/bin/perl   

use MD5;
require 'find.pl';
$md5 = new MD5;
@dirs = @ARGV;
foreach $dir ( @dirs ) { find($dir); }
sub wanted { push @files, $name; }
foreach $name ( sort @files) {
   ($uid,$gid) = (stat $nane)[4,5];
   $stat = sprintf "%0o", (stat_)[2];
   unless( -f $name ) {
   printf "$stat\t$uid $gid\t\t\t\t\t\t$name\n";
   next;
   }
  
   $md5->reset();
   open FILE, $name or print(STDERR "can't open file $name\n"), next;
   $md5->addfile(FILE);
   close FILE;
  
   $checksum - $md5->hexdigest();
   printf "$stat\t$uid $gid $checksum\t$name\n";
}   

it aim to calcute sum permission on the dir in @ARGV;
and with diff ,you can see  if files was modified
but the result isnt fine as you can see below
[EMAIL PROTECTED] cgi-bin]$ ./checksum.pl /bin
0   /bin
0   /bin/arch
0   /bin/awk
0   /bin/basename
0   /bin/bash
0   /bin/bash2
0   /bin/cat
0   /bin/chgrp
0   /bin/chmod
thanks
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



Re: problem printf

2004-10-25 Thread Owen
On Mon, 25 Oct 2004 05:17 pm, deny wrote:
> foreach $name ( sort @files) {
>     ($uid,$gid) = (stat $nane)[4,5];

stat $nane or $name?

Owen

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




Re: problem printf

2004-10-25 Thread Flemming Greve Skovengaard
deny wrote:

   That isn't only perl code, it's incomplete, and it
doesn't use 'printf'.  Show us more code and explain
your problem fully.
 

thanks for your help
here is the complete code
#!/usr/bin/perl  
use MD5;
require 'find.pl';

$md5 = new MD5;
@dirs = @ARGV;
foreach $dir ( @dirs ) { find($dir); }
sub wanted { push @files, $name; }
foreach $name ( sort @files) {
   ($uid,$gid) = (stat $nane)[4,5];
   $stat = sprintf "%0o", (stat_)[2];
   unless( -f $name ) {
   printf "$stat\t$uid $gid\t\t\t\t\t\t$name\n";
   next;
   }
 $md5->reset();
   open FILE, $name or print(STDERR "can't open file $name\n"), next;
   $md5->addfile(FILE);
   close FILE;
 $checksum - $md5->hexdigest();
   printf "$stat\t$uid $gid $checksum\t$name\n";
}  

it aim to calcute sum permission on the dir in @ARGV;
and with diff ,you can see  if files was modified
but the result isnt fine as you can see below
[EMAIL PROTECTED] cgi-bin]$ ./checksum.pl /bin
0   /bin
0   /bin/arch
0   /bin/awk
0   /bin/basename
0   /bin/bash
0   /bin/bash2
0   /bin/cat
0   /bin/chgrp
0   /bin/chmod
thanks

Try to add this lines somewhere the top of the file:
use strict;
use warnings;
and report the errors, if any.
--
Flemming Greve Skovengaard   Just a few small tears between
a.k.a Greven, TuxPower   Someone happy and one sad
<[EMAIL PROTECTED]>  Just a thin line drawn between
4112.38 BogoMIPS Being a genius or insane
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



Re: problem printf

2004-10-25 Thread Jenda Krynicky
From: deny <[EMAIL PROTECTED]>
> here is the complete code
> 
> #!/usr/bin/perl   
> 
> use MD5;
> require 'find.pl';
> 
> $md5 = new MD5;
> @dirs = @ARGV;
> 
> foreach $dir ( @dirs ) { find($dir); }
> sub wanted { push @files, $name; }
> 
> foreach $name ( sort @files) {
> ($uid,$gid) = (stat $nane)[4,5];
> $stat = sprintf "%0o", (stat_)[2];
> unless( -f $name ) {
> printf "$stat\t$uid $gid\t\t\t\t\t\t$name\n";

You should either be using print():

print "$stat\t$uid $gid\t\t\t\t\t\t$name\n";

or use printf() the way it was meant tu be. The first argument to 
printf should be "format", then you should specify the variables:

printf "%d\t%d %d\t\t\t\t\t\t%s\n", $stat, $uid, $gid, $name; 

I think the other problem is that you only store the names of the 
files, not paths in the @files array. So stat() is not able to find 
the files.

If would probably be best to do the stat() and print the result 
directly from the wanted() subroutine.

Jenda
P.S.: What the heck is find.pl? You should be using File::Find!

= [EMAIL PROTECTED] === http://Jenda.Krynicky.cz =
When it comes to wine, women and song, wizards are allowed 
to get drunk and croon as much as they like.
-- Terry Pratchett in Sourcery


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




Re: problem printf

2004-10-25 Thread John W. Krahn
deny wrote:

   That isn't only perl code, it's incomplete, and it
doesn't use 'printf'.  Show us more code and explain
your problem fully.
thanks for your help
here is the complete code
#!/usr/bin/perl  
use warnings;
use strict;
use MD5;
use Digest::MD5;
require 'find.pl';
use File::Find;
$md5 = new MD5;
my $md5 = Digest::MD5->new;
@dirs = @ARGV;
foreach $dir ( @dirs ) { find($dir); }
my @files;
find( \&wanted, @ARGV );
sub wanted { push @files, $name; }
You need to push the complete path into the array:
sub wanted { push @files, $File::Find::name }
foreach $name ( sort @files) {
   ($uid,$gid) = (stat $nane)[4,5];
 my ( $uid, $gid ) = ( stat $name )[ 4, 5 ];
   $stat = sprintf "%0o", (stat_)[2];
 ^
If you had strictures enabled (use strict) then perl would have informed you 
of this error and refused to compile your code.

 my $stat = sprintf '%o', (stat _)[2];
   unless( -f $name ) {
 unless( -f _ ) {
   printf "$stat\t$uid $gid\t\t\t\t\t\t$name\n";
 print "$stat\t$uid $gid\t\t\t\t\t\t$name\n";
   next;
   }
 $md5->reset();
   open FILE, $name or print(STDERR "can't open file $name\n"), next;
You should include the $! variable in the error message so you know *why* it 
failed.

   $md5->addfile(FILE);
   close FILE;
 $checksum - $md5->hexdigest();
   printf "$stat\t$uid $gid $checksum\t$name\n";
 print "$stat\t$uid $gid $checksum\t$name\n";
}  

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



Re: problem printf

2004-10-25 Thread deny
Owen a écrit :
On Mon, 25 Oct 2004 05:17 pm, deny wrote:
 

foreach $name ( sort @files) {
   ($uid,$gid) = (stat $nane)[4,5];
   

stat $nane or $name?
 

$name ,
error for me ,the result is the same
if someone want the script for test
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



Re: problem printf

2004-10-25 Thread deny

Try to add this lines somewhere the top of the file:
use strict;
use warnings;
and report the errors, if any.
Global symbol "$md5" requires explicit package name at ./checksum.pl 
line 11.
Global symbol "@dirs" requires explicit package name at ./checksum.pl 
line 12.
Global symbol "$dir" requires explicit package name at ./checksum.pl 
line 14.

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



Re: problem printf

2004-10-26 Thread Flemming Greve Skovengaard
deny wrote:

Try to add this lines somewhere the top of the file:
use strict;
use warnings;
and report the errors, if any.
Global symbol "$md5" requires explicit package name at ./checksum.pl 
line 11.
Global symbol "@dirs" requires explicit package name at ./checksum.pl 
line 12.
Global symbol "$dir" requires explicit package name at ./checksum.pl 
line 14.


Good, now you're on the right track. Declare those variables ( with my ) and
read the reply by John W. Krahn.
--
Flemming Greve SkovengaardThe prophecy of the holy Norns
a.k.a Greven, TuxPowerA tale of death and doom
<[EMAIL PROTECTED]>   Odin saw the final sign
4112.38 BogoMIPS  The end is coming soon
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



Re: problem printf

2004-10-26 Thread deny

Jenda
P.S.: What the heck is find.pl? You should be using File::Find!
 

thanks for your help
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]