[lug] Perl question

bdoctor at ps-ax.com bdoctor at ps-ax.com
Mon Jun 25 07:42:55 MDT 2001


Something like this may work

my $img_root = "/home/httpd/icons";

 if ( $line =~ m/(patt_match)/ ) { 
         my $file = $1;
         my $sys_file = join('/', $img_root,$file);
       
          if ( -f $sys_file ) {
                my $md5sum = (md5sum command); # Digest::MD5?
                # Create new name here, whatever
                if ( length($md5sum > 0) ) { # ?? some check anyway
                     $line =~ (s/$file/$md5sum/);
                } # length check
           } # if exist
             else {
                print "No such file: $sys_file\n";
          } # else, file does not exist
      next;
   } # if match

That is the general idea anyway.

-brad

> Greetings,
> 
> I'm writing a perl script to rewrite <img src=imgfile.gif> tags (as well 
> as some other stuff) in html.  I want to change imgfile.gif into a name 
> derived by calculating the md5sum of imgfile.gif.
> 
> Since urls and tags can span across lines, I have perl in "slurp mode" 
> where I have declared { local $/;  .....}
> 
> What I think I want to do is find the img src tags and get the file name 
> from a sub pattern, for example, $1 in the pattern
> /<img[^>]*src\s*=\s*"([^">]*)"([^>]*)>/soig;
> However, I need to use the original file name to call md5sum to get the 
> new name.
> 
> Another alternative is to find a way to take the stretch of characters 
> that match the pattern and remove any newlines (\n) from it.
> 
> If anyone has any suggestions on how to solve the problem, I'd 
> appreciate it.
> 
> Thanks.
> 
> Chip
> 
> _______________________________________________
> Web Page:  http://lug.boulder.co.us
> Mailing List: http://lists.lug.boulder.co.us/mailman/listinfo/lug
> 




More information about the LUG mailing list