Hi John

Refer to the comments

foreach $i (@dir) {
*#$i here refers to each content of your array @dir, which are file names*
my @title = split /\./, $dir[$i];
*#$i here refers to the array index, which should be number*
$name = $title[0];
print FH "<P ALIGN=CENTER><A HREF=\"$dir[$i]\" TARGET=\"_blank\">$name</A></
**P>\n";
}

Zheng

2012/6/10 John M Rathbun <jmrath...@bellsouth.net>

> Hello and thanks for volunteering your time!
>
> I'm returning to PERL after about a year and am struggling to remaster
> some syntax:
>
> #!/usr/local/bin/perl
> use warnings;
> use strict;
> use diagnostics;
>
> # Converts current directory to a list of links
>
> my @dir;
> my $name;
> my $i = 0;
>
> opendir DH, "." or die "\nCouldn't open current directory: $!\n";
>
> while ($_ = readdir(DH)) {
> next if $_ eq "." or $_ eq ".." or -d $_ or $_ eq "zlinks.pl" or $_ eq
> "zout.txt";
> $dir[$i++] = $_;
> }
>
> open FH, "> zout.txt" or die $!;
>
> foreach $i (@dir) {
> my @title = split /\./, $dir[$i];
> $name = $title[0];
> print FH "<P ALIGN=CENTER><A HREF=\"$dir[$i]\"
> TARGET=\"_blank\">$name</A></**P>\n";
> }
>
> I get an error for the line <<my @title = split /\./, $dir[$i];>>
> Argument "filename.ext" isn't numeric in array element
>
> Well, I wasn't expecting it to be, but apparently I implied it and can't
> figure out how.
>
> Interestingly, the program executes with the error but only considers the
> first file it finds in the directory. If there are N files, it will print N
> links, but all using the first file name.
>
> HELP!
>
> --
> To unsubscribe, e-mail: beginners-unsubscr...@perl.org
> For additional commands, e-mail: beginners-h...@perl.org
> http://learn.perl.org/
>
>
>

Reply via email to