in reply to Favorite Links printer
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
|
|---|