Phoenix.pm: I can't figure it out

Anthony R. Nemmer edelsys at swlink.net
Fri May 7 14:01:35 CDT 1999


At 10:55 AM 5/7/99 -0700, you wrote:
>I am trying to get a friend interested in perl, and have been trying to
>give him a small script that is close to something he wants to do.  The
>idea is that he can modify it to do exactly what he wants, and thereby
>learn some perl.  The problem is that I can't get it to work.  He is a C
>programmer, so I took a script from the cookbook, and I've been 'C'ifing
>it.  The problem is that the original version works, but mine doesn't.  I
>was wondering if any of you can tell me why.  Its probably something
>stupid, but right now I don't see what it is.  Both scripts are supposed to
>recurse directories provided on the command line, and find the largest
>file.  I'm doing this in Winbloze 95.  perl -v says:
>

First of all, use Linux, not Windows.  Second of all, tell your friend
about what really makes perl cool:

  1:  hash tables (associative arrays), built into the core syntax of
      the language, as easy to use as arrays!

  2:  complete powerful regular expression pattern matching language,
      built into the core syntax of the language.

  3:  disappearing $_

  4:  multi-paradigm.

The list goes on, but that's a start.  =)

Tony

>This is perl, version 5.005_02 built for MSWin32-x86-object
>
>Copyright 1987-1998, Larry Wall
>
>Binary build 507 provided by ActiveState Tool Corp.
http://www.ActiveState.com
>Built 15:08:32 Nov 14 1998
>
>Here is the original script:
>
>use File::Find;
>@ARGV = ('.') unless @ARGV;
>my ($saved_size, $saved_name) = (-1, '');
>sub biggest {
>    return unless -f && -s _ > $saved_size;
>    $saved_size = -s _;
>    $saved_name = $File::Find::name;
>}
>find(\&biggest, @ARGV);
>print "Biggest file $saved_name in @ARGV is $saved_size bytes long.\n";
>
>here is my version:
>
>use File::Find;
>
># If no command-line arguments are provided, set to the current directory.
>if(!@ARGV)
>{
>
> @ARGV = ('.');
>
>}
>
>my $file_name = '';
>my $file_size = -1;
>
>find(\&biggest, @ARGV);
>
>print "Biggest file $file_name is $file_size bytes.\n";
>
># biggest
>######################################################################
>
>sub biggest
>{
>
>  # This is just for debugging info.
>  if(-f _)
>  {
>
>    print "$_ $File::Find::name: " . (stat(_))[7] . "\n";
>
>  }
>
>  if((-f _) && ((stat(_))[7] > $file_size))
>  {
>
>    # Get the largest file's filename and size.
>    $file_size = (stat(_))[7];
>    ($file_name = $File::Find::name) =~ s!/!\\!g;
>    print "Biggest file $file_name is $file_size bytes.\n";
>
>  }
>
>} # END: biggest
>
>The problem with my script is that it is returning the correct largest file
>size, but the wrong file name (it is another file in the same directory as
>the true largest file).  Just FYI, I was using '-s _' but was having
>problems with it, so I replaced it with '(stat(_))[7]'.  Any clues are
>greatly appreciated.  Thanks.
>
>Doug and Julie Miles
>
--
-- Anthony R. Nemmer
-- EdelSys Consulting  edelsys at swlink.net
-- http://www.edelsys.com/
-- http://www.swlink.net/~edelsys/
-- Opera r0ks!  http://www.operasoftware.com/
--





More information about the Phoenix-pm mailing list