iLTC Home
Bookmark iLTC!
iLTC Google Boards

Google Groups
Receive The Code in Email!



Categories

Perl
  • Perl Tutorials Beginners

    Javascript
  • Javascript Tutorials
  • Javascript Tutorials Beginners

    HTML
  • HTML Tutorials



  • Pass the Javascript, please...
    123,719

    iLoveTheCode.com
    Perl > Perl Tutorials How To Easy > Opening and Reading a Directory in Perl

    Opening and Reading a Directory in Perl



    opendir(HU, ".") || print "Can't open... maybe try chmod 777";
    @hu=readdir(HU);
    closedir(HU);


    -The period between quotations means the current directory (the directory the script is in).
    -You could use a relative or root path to a directory you want to read.
    -Your array @hu now contains a list of all the files in the current directory.

    NOTES:
    -The words HU are called a Filehandle. Always use ALL CAPS for filehandles. The HU could be pretty much anything you like except STDIN and STDOUT, which are reserved for other things.
    -The || means or. We said "or print this error if you can't read the directory."


    opendir(HU, "../cities");

    The above line would open the directory cities provided it was one directory up from our script.


    Copy and Paste Perl Code:

    #!/usr/bin/perl

    print "Content-type:text/html\n\n";

    opendir(HU, ".");
    @hu=readdir(HU);
    closedir(HU);

    foreach $hu(@hu) {
    print "$hu<br>";
    }

    exit;


    IN-CASE-YOU-WONDER NOTE: You might notice our script prints a period and a couple more periods. Those symbolize the directories above the one we're in.


    Click HERE to comment or discuss at iLoveTheCode GOOGLE Group
    Previous Article: What's in an Array, Index Numbers
    Next Article: Exit a Loop with Last





    CSS MasteryCSS Mastery

    Andy Budd, Simon C...

    New $23.85

    Dreamweaver CS3Dreamweaver CS3

    David McFarland

    New $29.69

    Creating Web SitesCreating Web Sites

    Matthew MacDonald

    New $19.77

    HTML & XHTMLHTML & XHTML

    Chuck Musciano, Bi...

    New $29.99

    Information Architecture...Information Architecture for the Wor...

    Louis Rosenfeld, P...

    New $26.39

    HTML, XHTML, and CSS, Si...HTML, XHTML, and CSS, Sixth Edition ...

    Elizabeth Castro

    New $23.09

    New Perspectives on HTML...New Perspectives on HTML and XHTML 5...

    Partrick Carey

    New $67.45

    Learning Web DesignLearning Web Design

    Jennifer Niederst ...

    New $26.99

    HTMLHTML

    Gary B. Shelly, Th...

    New $84.55


    Of Interest:
  • If, Elsif, and Else in Perl
  • Create a Subroutine in Perl
  • Use the Perl PRINT FUNCTION
  • Use chmod in Perl
  • Javascript Unshift - Use Unshift to Put Items on the Front of an Array in Javascript
  • Select All or Highlight Text Fields and Textareas Using Javascript
  • Javascript Concat - Use Concat to Join Two Arrays in Javascript
  • Get String Length with Javascript
  • HTML Center
  • Make Italic Text Using HTML
  • HTML Font Code
  • HTML Tables

  • More Articles:
  • Matching at the Beginning and End
  • And, Or, Equal, Not Equal, Greater Than, Less Than in Perl
  • Write a FOR LOOP in Perl
  • Matching at the Beginning and End 2
  • onClick Javascript
  • Close Window with window.close in Javascript
  • If, Else If, and Else in Javascript
  • Focus a Window with self.focus in Javascript
  • PRINT to Browser with document.write Command in Javascript
  • HTML Superscript Text
  • HTML Underline Text
  • HTML Space
  • Make a Line Return Using HTML

  • Search iLTC w/ Google





    Recent Articles

  • Javascript Focus Form Field
  • Javascript Lowercase Text
  • Javascript Uppercase Text
  • Javascript Superscript Text
  • Javascript Subscript Text
  • Make Text Blink Using Javascript
  • Make a String into a Link in Javascript
  • Javascript Italics Text
  • Javascript Bold Text
  • Javascript Redirect
  • HTML Frames
  • HTML Color Chart
  • HTML Link
  • Javascript Status Bar








  • Perl Programming - Javascript Programming - Maybe Some PHP - Free Scripts - ILoveTheCode
    All Content © 2006 iLoveTheCode.com


    Contact Chris | About this Site


    420,480
    Counter by iLoveTheCode.com


    Last Modified: Friday, 23-Jun-2006 07:23:16 EDT