Sure, you can use Inline::C. Here is an example :

#!/usr/bin/perl #use strict; #use warnings; use Inline C; if( scalar(@ARGV) < 2 ){ print "Usage: $0 [directory] [file extension]\n"; exit 1; } my $count = count_file_extension_matches(@ARGV); print $count,"\n"; __END__ __C__ /* * recursively search for a file extension * within the directory given. * */ int count_file_extension_matches(const char* dirname,const char* exten +sion){ DIR *tmp = opendir(dirname); struct dirent *file; struct stat file_stat; int total_count = 0; char* result; if( tmp != NULL ){ if( chdir(dirname) == -1 ){ printf("chdir failed\n"); return 0; } while( (file = readdir(tmp)) ){ /* make sure we don't have . or .. */ if( (strcmp(file->d_name,"..")) == 0 || (strcmp(file->d_na +me,".") == 0) ) continue; /* setup file_stat struct */ if( (stat(file->d_name,&file_stat)) == -1) continue; /* if its a directory, recurse */ if( S_ISDIR(file_stat.st_mode) ){ total_count += count_file_extension_matches(file->d_na +me,extension); if( chdir("..") == -1 ){ printf("chdir .. failed\n"); return 0; } continue; } /* only look at regular files */ if( S_ISREG(file_stat.st_mode) ){ /* continue unless our extension is found within the f +ilename */ if( ( result = strstr(file->d_name,extension) ) == NUL +L ) continue; /* result should match extension, continue otherwise * +/ if( strcmp(extension,result) != 0 ) continue; total_count += 1; } } closedir(tmp); }else{ printf("Error opening directory: %s\n",dirname); exit(1); } return total_count; }

cp
----
"Never be afraid to try something new. Remember, amateurs built the ark. Professionals built the Titanic."

In reply to Re: Faster Method for Gathering Data by crouchingpenguin
in thread Faster Method for Gathering Data by APA_Perl

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.