Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

perl program to list all jpg's in folder - help!!

  • 21-08-2009 03:20PM
    #1
    Registered Users, Registered Users 2 Posts: 596 ✭✭✭


    i am trying ot list all jpg's in folder - "/home/user/Pictures/misc" - when i run the program below it does not list anything, it does not read the folder set in $dir. any ideas? thanks.

    #!/usr/bin/perl
    $dir = "/home/user/Pictures/misc";
    opendir (PHOTO, "$dir") || die "Cannot open directory $dir: $!";
    while (readdir(PHOTO)) {
    foreach $file (<*.jpg>) {
    print "$file\n";
    }
    }
    close (PHOTO);


Comments

  • Registered Users, Registered Users 2 Posts: 596 ✭✭✭ambasite


    i'll get my coat..... :rolleyes:

    #!/usr/bin/perl
    @files = </home/user/Pictures/misc/*.jpg>;
    foreach $file(@files) {
    print "$file\n";
    }


  • Closed Accounts Posts: 20 boars.ie


    perl -e 'while(</blah/blah/*.jpg>){print "$_\n";}'

    Isn't it in a manual btw?


Advertisement