Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Please help me with this script split.pl

Status
Not open for further replies.

Julia23

IS-IT--Management
Mar 21, 2007
25
GR
Halo,

I have this script and I want to run it on a cacm.all collection but I become always this error:

perl split.pl cacm.all

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

I think the code is right but IO::Fileworks probably not on my PC.
The cacm.all data is here
Is the Script ok? If that script runs on your PC, please pack and upload the document collection on rapidshare. Ireallyneed the document collection splitet for one application.

Thank you very much

The Perl Script code:

#!/usr/sw/perl/default/bin/perl
######################### -*- Mode: Perl -*- #########################
##
## File : $RCSfile$
##
##
## 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,
# default options
qw( help
version
),
# 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)) {
# 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(^\.)) {
# other header line; "@" does not occur in cacm.all
s(^\.)(@);
$d .= $_;
} else {
# append line
$d .= $_;
}
}
# 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).


=cut
 
We're here to help you solve technical problems, not to do your job for you...

Steve

[small]"Every program can be reduced by one instruction, and every program has at least one bug. Therefore, any program can be reduced to one instruction which doesn't work." (Object::perlDesignPatterns)[/small]
 
Ok and please sorry for my stupid request...
 
Yea. The request is a bit over the top mate. Maybe change this line:

$f->print($d);

to:

$f->print($d) or next;

and see if gets the code to at least get past the error message.

------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
Thanks Kevin and I will try this out. Sorry again for my request! It was realy stupid and I did not want to make anyone to make the work for me. Thanks again!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top