From: papapep <[EMAIL PROTECTED]>

> First of all I beg your pardon for such a stupid question, but I'm new
> to programming and also to Perl.
> 
> The question is I've got one text message with a great amount of
> numbers, like this:
> 
> 2384523590021084804680153165100015156418641481200000004418484150000000
> 0041848464143995
> 
> (There are a lot of lines like this)
> 
> First, I have to cut the line to, for example, 25 characters. After I
> would like to insert in certain places (in every line, of course), for
> example betwen the 12 an 13 character and between the 24 and 25, and
> so on, some characters to split the line in fields (really this data
> are a text exportation of a database).

You should start with a decent introductory book :-)

The script might be something like this:

#!perl
use strict;

my $file = shift()
        or die "Usage: reformat.pl inputfilename outputfilename\n";
my $outfile = shift()
        or die "Usage: reformat.pl inputfilename outputfilename\n";

open IN, '< '.$file
        or die "Cannot open file '$file' for reading: $!\n";
open OUT, '> '.$outfile
        or die "Cannot open file '$outfile' for writing: $!\n";

while (<IN>) { # read the file line by line
        chomp(); # strip the newline
        $_ = substr $_, 0, 25; # only use the first 25 characters
        $_ =~ s/^(.{12})(.{12})(.*)$/$1 $2 $3/;
                # put a space after first and second 12 characters
        print OUT $_,"\n";
                # print the result and a newline
}
close IN;
close OUT;
__END__

HTH, Jenda=========== [EMAIL PROTECTED] == http://Jenda.Krynicky.cz 
==========
When it comes to wine, women and song, wizards are allowed 
to get drunk and croon as much as they like.
        -- Terry Pratchett in Sourcery


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to