Hello,

I'm a Perl newbie, which should become obvious from the question I am about to ask.

I'm running Perl from the command line on a windows box (Active Perl 5.8.8).

Ultimately, I want to write a program that will search all of the files in a directory for a RegEx and write the results back to a file. It sounds simple enough, but I need to learn to walk first. For starters I'm trying to write a script that will allow me to input the directory name and it will return a list of files in that directory.

My script almost works. Can some one, please, help me? My script is posted below. I think my problem is with my use of <STDIN>.

thanks,
that one guy

#!/usr/bin/perl -w sub namedir { print "Enter the directory path you want to search: "; $dir = <STDIN>; } sub dirme { if (! $dir){ &namedir; } print "\n\nFiles in $dir\n"; opendir(BIN, $dir) or die "Can't open $dir: $!"; while( defined ($file = readdir BIN) ) { # list files print "$file\n"; } closedir(BIN); } &dirme;

2006-04-06 Retitled by g0n, as per Monastery guidelines
Original title: '...a little help, please'


In reply to How to read from STDIN? by that one guy

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.