Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
So, I have a big directory full of images. The naming pattern is <Number>.<Counter>.jpg (where counter is 000, 001, 002...). I have a list of numbers which match up with Numbers that I want to keep (so for a given Number in the list, keep Number.000.jpg, Number.001.jpg, etc).

As far as I can tell, the following code should work, but the numbers it reports don't match up. Any idea what's going on?

The current output is:

33600 images in photos (8321 unique). 6571 numbers in numbers_only.txt. 5999 numbers slated for deletion.
#!/usr/bin/perl -w use strict; my $num_file = "numbers_only.txt"; my %currentlist; my $i = 0; open(CURRFILE, "<$num_file") or die "couldn't open the num file: $!\n" +; while (<CURRFILE>) { chomp; $currentlist{$_}++; $i++; } close CURRFILE; my $dir = "images/photos"; opendir FILEDIR, $dir or die "Couldn't open $dir: $!\n"; my @filelist = grep !/^\.\.?$/, readdir FILEDIR; closedir FILEDIR; my %uniquelist; my %deletelist; my $h = 0; foreach my $pic (@filelist) { next unless ($pic =~ /jpg$/); $pic =~ s/^(\d+).*/$1/; $h++; $uniquelist{$pic}++; next if ($currentlist{$pic}); $deletelist{$pic}++; } my $output = "delete_list.txt"; open OUT, ">$output" or die "Couldn't open output: $!\n"; my $j = 0; foreach my $del (sort keys %deletelist) { print OUT "$del\n"; $j++; } close OUT; my $k = 0 + keys %uniquelist; print "$h images in photos ($k unique). $i numbers in numbers_only.txt +. $j numbers slated for deletion.\n"; exit;

In reply to Build a list of files that are NOT in a list by amelinda

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



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (4)
As of 2024-04-25 17:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found