praktikantin
Goto Top

Perl script split.pl

Hallo Leute,
Ich habe diesen Code hier:

#!/usr/sw/perl/default/bin/perl
-*- Mode: Perl -*- #########################
##
## File : $RCSfile$
##
## Author : Kai Großjohann
## Created On : Thu Dec 12 18:40:50 2002
## Last Modified : Time-stamp: <2002-12-21 21:46:42 kai>
##
## Description :
##
## $Id$
##

use strict;
use warnings;

use Pod::Usage;
use Getopt::Long;
use IO::File;

our $VERSION;
'$Name$ 0_0' =~ /(\d+)[-_](\d+)/; $VERSION = sprintf '%d.%03d', $1, $2;


my %OPT = ();

GetOptions( \%OPT,
  1. default options
qw( help
version
),
  1. application specific options
qw()
) or pod2usage(2);


pod2usage(VERBOSE => 2) if $OPT{help};
print $VERSION, "\n" and exit if $OPT{version};

my $d = ''; # document
my $n = 0; # number
while (<>) {
if (m(^\.I)) {
  1. beginning of document
my $fname = sprintf("doc/%04d", $n);
my $f = IO::File->new($fname, "w");
$f->print($d);
$f->close();
$d = '';
$n++;
} elsif (m(^\.)) {
  1. other header line; "@" does not occur in cacm.all
s(^\.)(@);
$d .= $_;
} else {
  1. append line
$d .= $_;
}
}

  1. write out last document
my $fname = sprintf("doc/%04d", $n);
my $f = IO::File->new($fname, 'w');
$f->print($d);
$f->close();

## ################################
## subs
## #################################


__END__
## #################################
## pod
## ##################################

=head1 NAME

split.pl - Kai Großjohann is too lazy to provide a description?!

=head1 SYNOPSIS

B<split.pl>
[B<-help>] [B<-version>]
[B<file>...]

=head1 DESCRIPTION

Read C<cacm.all> format from the given files or from standard input.
Output is written to the F<doc> subdir, one document per file.
Files are named after the document number. The C<.I> line is not
written to the output files. The field indicators like C<.W> are
rewritten to use the at sign instead of dot, as in C<@W>.

=head1 OPTIONS

Option names may be abbreviated to uniqueness.

=over

=item B<-help>

Show this manual.

=item B<-version>

Show program version.

=back

=head1 EXAMPLES
% split.pl cacm/cacm.all

has the effect of writing files F<doc/0001> through F<doc/3338>, where
each file contains one document.

=head1 BUGS

Yes. Please let me know!

=head1 SEE ALSO

perl(1).

=head1 AUTHOR

Kai Großjohann E<lt>F<kai@ls6.cs.uni-dortmund.de>E<gt>

=cut





Die Datei für die das Program laufen soll heißt cacm.all (http://rapidshare.com/files/59055129/cacm.tar.gz). Leider kann ich gar

nichts damit anfangen. Es ist ein sehr merkwürdiges Script. Und diese Head1

befehle kenne ich schon gar nicht. Ich dachte ich muss hier den Pfand eingenben:
my $d = ''; # document
oder hier:
my $fname = sprintf("doc/%04d", $n);
Aber das klappt nicht. Wenn ich das Programm laufe kommt dieser Fehler:


Serverfehler!
Die Anfrage kann nicht beantwortet werden, da im Server ein interner Fehler

aufgetreten ist.

Fehlermeldung:
Can't call method "print" on an undefined value at

C:/xampp/htdocs/modperl/split.pl line 65. ,

Sofern Sie dies für eine Fehlfunktion des Servers halten, informieren Sie bitte

den Webmaster hierüber.

Error 500
localhost
10/07/07 18:16:46
Apache/2.2.4 (Win32) DAV/2 mod_ssl/2.2.4 OpenSSL/0.9.8e mod_autoindex_color

PHP/5.2.3 mod_perl/2.0.3 Perl/v5.8.8

Auch wenn ich mit cmd diesen Befehl eingebe kommt der selbe Fehler:
perl split.pl cacm.all

Dieser code muss die Ansammlung der 3200 Dokumente trennen und diese enzeln auf

einem Ordner auf der Festplatte speichern. Ich weiß aber nicht wo ich den Pfand

für die Datei cacm.all eingeben muss oder wo ich den Ordner in der die 3200

Dokumente gespeichert werden eingeben soll. Ich habe ausserdem eine split.man

Datei dabei. Leute bitte hilft mir ganz schnell denn dieser Code ist wirklich

sehr wichtig für mich.
Danke und viele Grüße


Hier die split.man Datei (weiß garnicht was das für eine Datei ist):





.\" Automatically generated by Pod::Man v1.32, Pod::Parser v1.13
.\"
.\" Standard preamble:
.\" ===================================
.de Sh \" Subsection heading
.br
.if t .Sp
.ne 5
.PP
\fB\\$1\fR
.PP
..
.de Sp \" Vertical space (when we can't use .PP)
.if t .sp .5v
.if n .sp
..
.de Vb \" Begin verbatim text
.ft CW
.nf
.ne \\$1
..
.de Ve \" End verbatim text
.ft R
.fi
..
.\" Set up some character translations and predefined strings. \*(-- will
.\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left
.\" double quote, and \*(R" will give a right double quote. | will give a
.\" real vertical bar. \*(C+ will give a nicer C++. Capital omega is used to
.\" do unbreakable dashes and therefore won't be available. \*(C` and \*(C'
.\" expand to `' in nroff, nothing in troff, for use with C<>.
.tr \(*W-|\(bv\*(Tr
.ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p'
.ie n \{\
. ds -- \(*W-
. ds PI pi
. if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch
. if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch
. ds L" ""
. ds R" ""
. ds C` ""
. ds C' ""
'br\}
.el\{\
. ds -- \|\(em\|
. ds PI \(*p
. ds L" ``
. ds R" ''
'br\}
.\"
.\" If the F register is turned on, we'll generate index entries on stderr for
.\" titles (.TH), headers (.SH), subsections (.Sh), items (.Ip), and index
.\" entries marked with X<> in POD. Of course, you'll have to process the
.\" output yourself in some meaningful fashion.
.if \nF \{\
. de IX
. tm Index:\\$1\t\\n%\t"\\$2"
..
. nr % 0
. rr F
.\}
.\"
.\" For nroff, turn off justification. Always turn off hyphenation; it makes
.\" way too many mistakes in technical documents.
.hy 0
.if n .na
.\"
.\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2).
.\" Fear. Run. Save yourself. No user-serviceable parts.
. \" fudge factors for nroff and troff
.if n \{\
. ds #H 0
. ds #V .8m
. ds #F .3m
. ds #[ \f1
. ds #] \fP
.\}
.if t \{\
. ds #H ((1u-(\\\\n(.fu%2u))*.13m)
. ds #V .6m
. ds #F 0
. ds #[ \&
. ds #] \&
.\}
. \" simple accents for nroff and troff
.if n \{\
. ds ' \&
. ds ` \&
. ds ^ \&
. ds , \&
. ds ~ ~
. ds /
.\}
.if t \{\
. ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u"
. ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u'
. ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u'
. ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u'
. ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u'
. ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u'
.\}
. \" troff and (daisy-wheel) nroff accents
.ds :

\\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\

*(#V'
.ds 8 \h'\*(#H'\(*b\h'-\*(#H'
.ds o

\\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#]
.ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H'
.ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u'
.ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#]
.ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#]
.ds ae a\h'-(\w'a'u*4/10)'e
.ds Ae A\h'-(\w'A'u*4/10)'E
. \" corrections for vroff
.if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u'
.if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u'
. \" for low resolution devices (crt and lpr)
.if \n(.H>23 .if \n(.V>19 \
\{\
. ds : e
. ds 8 ss
. ds o a
. ds d- d\h'-1'\(ga
. ds D- D\h'-1'\(hy
. ds th \o'bp'
. ds Th \o'LP'
. ds ae ae
. ds Ae AE
.\}
.rm #[ #] #H #V #F C
.\" ========================================================
.\"
.IX Title "SPLIT 1"
.TH SPLIT 1 "2002-12-21" "perl v5.6.1" "User Contributed Perl Documentation"
.SH "NAME"
split.pl \- Kai Großjohann is too lazy to provide a description?!
.SH "SYNOPSIS"
.IX Header "SYNOPSIS"
\&\fBsplit.pl\fR
[\fB\-help\fR] [\fB\-version\fR]
[\fBfile\fR...]
.SH "DESCRIPTION"
.IX Header "DESCRIPTION"
Read \f(CW\*(C`cacm.all\*(C'\fR format from the given files or from standard

input.
Output is written to the \fIdoc\fR subdir, one document per file.
Files are named after the document number. The \f(CW\*(C`.I\*(C'\fR line is not
written to the output files. The field indicators like \f(CW\*(C`.W\*(C'\fR are
rewritten to use the at sign instead of dot, as in \f(CW@W\fR.
.SH "OPTIONS"
.IX Header "OPTIONS"
Option names may be abbreviated to uniqueness.
.IP "\fB\-help\fR" 4
.IX Item "-help"
Show this manual.
.IP "\fB\-version\fR" 4
.IX Item "-version"
Show program version.
.SH "EXAMPLES % split.pl cacm/cacm.all"
.IX Header "EXAMPLES % split.pl cacm/cacm.all"
has the effect of writing files \fIdoc/0001\fR through \fIdoc/3338\fR, where
each file contains one document.
.SH "BUGS"
.IX Header "BUGS"
Yes. Please let me know!
.SH "SEE ALSO"
.IX Header "SEE ALSO"
\&\fIperl\fR\|(1).
.SH "AUTHOR"
.IX Header "AUTHOR"
Kai Großjohann <\fIkai@ls6.cs.uni\-dortmund.de\fR>

Content-Key: 70331

Url: https://administrator.de/contentid/70331

Printed on: April 24, 2024 at 18:04 o'clock

Member: ratzla
ratzla Oct 07, 2007 at 16:52:29 (UTC)
Goto Top
Die =head... Einträge sind für die Dokumentation. Perl baut damit halbautomatisch aus em Code die Dokumentation (perldoc) zusammen.
Das Ding teilt eine Datei in mehrere kleine auf.
Die my $d = '' sind lediglich variablendeklarationen mit einer Vorbelegung als leere datei.

mit -h sollte dieses kleine Manual kommen:

Read C<cacm.all> format from the given files or from standard input.
Output is written to the F<doc> subdir, one document per file.
Files are named after the document number. The C<.I> line is not
written to the output files. The field indicators like C<.W> are
rewritten to use the at sign instead of dot, as in C<@W>.

split.pl cacm/cacm.all
has the effect of writing files F<doc/0001> through F<doc/3338>, where
each file contains one document.
Member: Praktikantin
Praktikantin Oct 07, 2007 at 17:00:58 (UTC)
Goto Top
Hallo ratzla,

ich habe mal meinen Beitrag editiert. Ich bin etwas dumm, aber ich weißwirklich gar nichts von perl. Was genau muss uch jetzt machen damit er meine cacm.all Datei splittet?Welchen Befehlmuss ich in der cmd von Windows eingeben? Beim Befehl perl split.pl cacm/cacm.all kommt immer wieder dieser Fehler : Fehlermeldung:
Can't call method "print" on an undefined value at C:/xampp/htdocs/modperl/split.pl line 65.

Vielen dank für Deine schnelle Antwort!
Member: Praktikantin
Praktikantin Oct 07, 2007 at 18:07:22 (UTC)
Goto Top
Ich habe den befehl perl split.pl -h versucht und das Hilfe Manual ist erschienen. Dan habe ich den Befehl perl split.pl cacm/cacm.all versucht und das war die Antwort:

cant call print .... line 49 usw

split.pl cacm\cacm.all öffnet nur die Date.Ich weiß wirklich nicht weiter!face-sad
Member: ratzla
ratzla Oct 10, 2007 at 07:31:25 (UTC)
Goto Top
OK so wie es aussieht prüft das script nicht ob alle CPAN Module von Perl da sind.
Der Fehler dürfte hier entstehen:

my $fname = sprintf("doc/%04d", $n);
my $f = IO::File->new($fname, 'w');
$f->print($d);
$f->close();

Um das in den Griff zu bekommen benötigst Du das Perl-Modul IO::File welches offenbar in deinem Perl nicht vorhanden ist. Das Modul gibts zum Download im CPAN (Coprehensive Perl Archive Network). Mit Windows habe ich das noch nie gemacht (ich mache da mehr unter Linux) sollte aber genauso funktionieren.

Von der Kommandozeile folgendes Aufrufen
perl -MCPAN -e shell
install IO::File

Der erste Befehl startet die shell für das CPAN "nachlademodul".
Der zweite Befehl installiert das benötigte Modul.
Es kann sein dass einige Submodule von IO::File benötigt werden, bzw. erstmal die Downloadquellen ausgewählt werden müssen. Das ganze geht dialogorientiert und sollte machbar sein.

Gruß
Christian
Member: Praktikantin
Praktikantin Oct 10, 2007 at 11:51:52 (UTC)
Goto Top
Hallo Christian und vielen dank!

Ich lade mir gerade das Modul runter. Ich hoffe es klappt aber wenn es bei dir klappt dann wird es schon gehen. Ich kenne mich ganz und gar nicht mit den Perl Compiler aus...

Vielen und viele Grüße
Julia
Member: Praktikantin
Praktikantin Oct 11, 2007 at 12:58:25 (UTC)
Goto Top
Hallo Christian,

ich habegenau dasgemacht was Du mir gesagt hast aber es klappt immer noch nicht.... Läuft es denn bei Dir? Die Fehlermeldung ist immer gleich:

perl split.pl cacm.all
Can´t call Method "print" on an undefined value at split.pl line 49, <> line 1

Läuft denn das Programm bei Dir? Ich glaube schon. Konntest Du biiitte das Programm bei Dir laufen lassen und mir die Dokumente in einem Archiv schicken? Es wäre wirklich ein große Hilfe für mich!!! Die cacm Sammlung ist hier: http://rapidshare.com/files/59055129/cacm.tar.gz und das Programm soll für die erste Datei laufen: cacm.all
Du kannst Sie einfach auf Rapidshare uploaden oder per email (schickmir eine Nachricht). Bitte es ist sehr wichtig!

Viele Grüße
Member: ratzla
ratzla Oct 12, 2007 at 14:34:19 (UTC)
Goto Top
Da ich etwas krank bin komme ich da gerade nicht dazu.
Du hast das Archiv (tar.gz) vorher schon komplett entpackt ?
Falls nicht Filzip kann damit umgehen /Unter Linux tar -xzf cacm.tar.gz
Member: Praktikantin
Praktikantin Oct 14, 2007 at 13:12:59 (UTC)
Goto Top
Ok, danke und ich versuche es nocheinmal!

Viele Grüße
Member: Praktikantin
Praktikantin Oct 16, 2007 at 11:29:00 (UTC)
Goto Top
Hallo ratzla,
das hier war der Fehler: "my $fname = sprintf("doc/%04d", $n);"
Windows kann keine Dokumente mit einen solchen Namen erstellen "doc/0001". Ichhabe es total zuffälig entdeckt!!! Vielleicht läuft es in Linux aber nicht windows! Endlich läuft der Code und ich habe meine Docs erstellt! Vielen dankfür Deine Hilfe!

Viele Grüße Praktikantin
Member: ratzla
ratzla Oct 19, 2007 at 16:43:58 (UTC)
Goto Top
Sorry konnte nicht mehr helfen - ich war krank und bin unmittelbar danach im Büro mit tausend Dingen überfallen worden.
Schön dass es doch geklappt hat.
Member: Praktikantin
Praktikantin Oct 26, 2007 at 09:59:39 (UTC)
Goto Top
Hallo Christian,

Du hast mir wirklich mehr als geholfen. Vielen Dank und es hat bei mir auch alles geklappt und Du bist Hoffentlich mittleweile wieder Kerngesund!

Viele Grüße
die Praktikantin