I am trying a simple code of reading dir content and printing it on cmd prompt. But its not working. What can be problem in here ?
opendir (dir, "C:\Users\Admin\Desktop\Staples files"); @dir_content = readdir(dir); closedir(dir); for $d(@dir_content){ print "$d "; }
This code does not give any error nor does it print output

I have tried it in different ways as follows
opendir dir, "C:\Users\Admin\Desktop\Staples files\"; my @files = readdir(dir); closedir(dir); foreach $file(@files){ print "$file \n"; } print $#files ;
I am getting following errors when I run this code

C:\Users\Admin>perl C:\Users\Admin\Desktop\perl_programs\printDir.pl Scalar found where operator expected at C:\Users\Admin\Desktop\perl_programs\pri ntDir.pl line 6, near "print "$file" (Might be a runaway multi-line "" string starting on line 1) (Do you need to predeclare print?) Backslash found where operator expected at C:\Users\Admin\Desktop\perl_programs\ printDir.pl line 6, near "$file \" (Missing operator before \?) String found where operator expected at C:\Users\Admin\Desktop\perl_programs\pri ntDir.pl line 6, at end of line (Missing semicolon on previous line?) syntax error at C:\Users\Admin\Desktop\perl_programs\printDir.pl line 6, near "p rint "$file " Can't find string terminator '"' anywhere before EOF at C:\Users\Admin\Desktop\p erl_programs\printDir.pl line 6.
open file, "< C:\Users\Admin\Desktop\staples\readfile.txt"; @file_content = <file>; for $f (@file_content){ print "$f \n"; }
This code does not give anu errors. but does not print content of files either.

In reply to Reading DIR content and printing it by manishrathi

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.