Perl Directory List Help

I am currently trying to find all files with extensions .gif .jpg .png .wav and .au in a current directory and count them.
I am trying to count them based on there extension only.

#!/usr/bin/perl
$gif =`ls *.gif | uniq -cf 1`;
$jpg =`ls *.jpg | uniq -cf 1`;
$png =`ls *.png | uniq -cf 1`;
$wav =`ls *.wav | uniq -cf 1`;
$au  =`ls *.au  | uniq -cf 1`;
print "$gif $jpg $png $wav $au";

This is what I currently got and it is not doing what I want it to at all. It locates all the image files but doesnt print just there extension. I was thinking I needed to use AWK but my AWK skills suck. Can anyone help me or guide me in the right direction? I'd really appreciate it.

$
$ ls -1 *.gif *.jpg *.png *.wav *.au
file1.au
file1.gif
file1.jpg
file1.png
file1.wav
file2.au
file2.gif
file2.jpg
file2.png
file3.gif
file3.png
file4.png
$
$
$ perl -le 'for (glob "*.gif *.jpg *.png *.wav *.au"){s/^.*\.//; $x{$_}++} END {while (($k, $v) = each %x){print "$k => $v"}}'
au => 2
png => 4
jpg => 2
gif => 3
wav => 1
$
$

tyler_durden

1 Like

Thanks Tyler this is exactly what I wanted I didn't even need to use AWK.