Had you used strict, the perl compiler would have tould you the error. This

if(-d BUS)

doesn't do what you want. BUS is a bareword here which is just a symbol that can be used e.g. as a directory handle (not under strict, though). Then, even if it was a directory entry (which it isn't), you need to prepend $path to correctly name it's location.You can use either of

if ( $_ eq "BUS" and -d "$path/$_" ) # string equality test if ( /^BUS$/ && -d "$path/$_" ) # pattern match on $_

But it is not necessary to read the contents of a directory to test for existence of a directory within whose name you know beforehand. You could as well just do

use strict; use warnings; my $path='/home/something/something/something'; if ( -d "$path/BUS" ) { opendir my $VEH, "$path/BUS" or die"couldnt open the directory\n"; while(readdir $VEH ) { print "$_\n"; } }
perl -le'print map{pack c,($-++?1:13)+ord}split//,ESEL'

In reply to Re: Read Directory by shmem
in thread Read Directory by Nansh

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.