Your path delimiters are invalid. You need to use \\ to get a literal backslash (although you can use / in perl on windows and all will be OK) - see Paths in Perl. You don't want a space after the last \\ Also you need a chdir() or the full path for your open. Finally if you use || you need to do open(FU, $name) || die 'blah' with parentheses due to binding precedence of || being higher than the , operator. Alternatively most people use or operator as shown where you can skip parentheses as or is lower binding precedence than , This should work:

Note you would expect that '\' should represent a literal \ (non interpolating single quotes) but perl sometimes gets confused with that so you typically use "\\" which works reliably.

$dir="C:\\Windows\\Desktop\\Perl\\scriptz\\miei\\opendir\\1\\"; opendir DIR, $dir or die "no $dir?: $!"; foreach $name (sort readdir(DIR)) { # skip anything that is not a file ie . .. and other dirs next unless -f $dir.$name; print "$dir$name\n"; open FU, $dir.$name or die "can't open $dir.$name :$!"; my @contfile=<FU>; $url=substr($contfile[1],8,); print "$url\n"; close FU or die "$!"; }

$countfile[1] is the second line in your file as the first line is $countfile[0]. If you just want a single line you only need to read the file that far ie

my $line; my $line_you_want = 2; $line = <FU> for 1..$line_you_want; # $line will now contain just the content of line number $line_you_wan +t;

This avoids reading the whole file into memory and storing it in an array when you only want one line. If you actually just want the first line only than you can use $line = <FU>; which will just read in the first line.

cheers

tachyon

s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print


In reply to Re: Favorite Links printer by tachyon
in thread Favorite Links printer by Anonymous Monk

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.