Auf ein Minimum, müssen Sie Ihren Code zum Kompilieren bekommen. Der Perl-Compiler ist normalerweise sehr hilfreich, um Ihnen zu sagen, was falsch ist. Hier haben Sie ungültige Paketnamen, einen ungültigen Perl-Pfad, und Sie sollten DATA anstelle von DATA1 verwenden.
Versuchen Sie Ihr Code ausgeführt wird mit diagnostics
wie es informativer ist:
perl -cwT -Mdiagnostics script.pl
Can't locate file/BaseName.pm in @INC (you may need to install the
file::BaseName module) (@INC contains: /etc/perl /usr/local/lib/i386-
...) at foo2.pl line 4.
BEGIN failed--compilation aborted at foo2.pl line 4 (#1)
(F) You said to do (or require, or use) a file that couldn't be found.
Perl looks for the file in all the locations mentioned in @INC, unless
the file name included the full path to the file. Perhaps you need
to set the PERL5LIB or PERL5OPT environment variable to say where the
extra library is, or maybe the script needs to add the library name
to @INC. Or maybe you just misspelled the name of the file.
See "require" in perlfunc and lib.
Uncaught exception from user code:
Can't locate file/BaseName.pm in @INC (you may need to install the
file::BaseName module) (@INC contains: /etc/perl /usr/local/lib/i386-
...) at foo2.pl line 4.
BEGIN failed--compilation aborted at foo2.pl line 4.
Hier ist eine Compilierung Version des Codes:
#!/usr/bin/perl
use strict;
use warnings;
use File::Basename;
use File::Copy;
my @fields;
while(<DATA>) {
my $String='';
$String= $_;
@fields= split(/,/,$String);
my $i = 0;
foreach my $element (@fields) {
print "[$i] : $element\n";
$i++;
}
}
__DATA__
foo,bar,baz
qux,1,2,3
Ausgabe
[0] : foo
[1] : bar
[2] : baz
[0] : qux
[1] : 1
[2] : 2
[3] : 3
Was das ist Error? Was ist in 'DATA1'? Wo deklarieren Sie '$ String'? – fugu
Das sieht wie eine Kopie von http://stackoverflow.com/q/37856440/1331451 aus. – simbabque
Ich habe dafür gestimmt, diese Frage zu schließen, weil wir Code, den wir nicht sehen, nicht debuggen können. Sie müssen ** Ihren echten Code ** einfügen, indem Sie den tatsächlichen, echten Live-Code bearbeiten und kopieren/einfügen. Tippe es nicht noch einmal ein. Poste nichts anderes. Zeigen Sie den echten Code. Niemand kann erraten, was Sie auf Ihrem Computer falsch eingegeben haben. – simbabque