in reply to Directory Structure parsing
#!/usr/bin/perl -w use strict; # Here go all the top-level categories my @categories = qw(clocks daisies); # And the subcategories. my @subcats = qw(vert red); # Directory contents. You could also loop through STDIN or # something. See the comment below the foreach loop. my @names = qw(clocks001.jpg clocks002.jpg clocksvert001.jpg clocksvert002.jpg clocksvertred001.jpg daisies001.jpg); foreach my $name (@names) { # while (my $name = <STDIN>) { # chomp($name) # Get image number and strip off the extension my $output = "$name -> "; my ($im_no) = $1 if $name =~ s/(\d+)\..+$//g; foreach my $cat (@categories) { if ($name =~ s/^$cat//) { $output .= "category: $cat; "; next; } } $output .= "subcats:"; foreach my $subcat (@subcats) { if (not $name) { $output .= " null/null"; last; } if ($name =~ s/^$subcat//) { $output .= " $subcat/1"; } } $output .= " IM#: $im_no"; print "$output\n"; }
Arjen
Update: Fixed a small bug in the output.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Directory Structure parsing
by Aragorn (Curate) on Apr 01, 2003 at 20:18 UTC |