Adriano Allora wrote:
> 
> Hi to all,

Hello,

> I've just learnt ( ...   anyway, I'm trying to do it) to select a
> string when it is not preceded (or followed) by another string.

Perhaps you should read up on the positive/negative
look-ahead/look-behind assertions in the perlre document.

perldoc perlre


> My aim is to know the mean of text lines in each newsgroup post, so I
> wrote:
> 
> #!/usr/bin/perl -w
> 
> $nome_del_file = q/text.txt/;
> 
> open(INPUT, $nome_del_file);

You should _always_ verify that the file opened successfully.

open INPUT, $nome_del_file or die "Cannot open $nome_del_file: $!";


> $posts = 0;
> $line4post = 0;
> 
> while (<INPUT>)
> {
> # it cleans the <return carriage> signs
> tr/\015|\012/\n/;

This translates either a carriage return (\015) or a vertical bar (|) or
a linefeed (\012) to a newline (\n) character.  Perhaps you want this
instead:

tr/\015\012/\n/;


> # it makes a lot of <new line> signs only one a time
> tr/\n\r\f\t//s;

You could combine the two transliterations.  :-)

tr/\015\012\n\r\f\t/\n\n\n\r\f\t/s;


> # it counts all the posts
> $posts ++ if /Newsgroups: it\..+/;
> # it deletes the headers of each post
> s/Newsgroups: it\..+|Subject: .+|Date: .+|Message-ID: .+|References:
> ..+|From: .+/\n/g;

Or:

$posts++ if s/^Newsgroups: it\..+//;
s/^(?:Subject|Date|Message-ID|References|From):.+/\n/s;


> # THIS ONE DOESN'T WORKS!!! it should count all the lines except the
> lines of division of each post (========\n)
> $line4post ++ if (/\n/ and $´ !~ /={8}/);

$line4post++ unless /={8}\n/;


> }
> print $posts, " posts in ", $line4post, " lines.\nThe mean is ",
> $line4post / $posts, " lines for post.\n";
> 
> close(INPUT);
> 
> someone knows why for each line of text.txt the Terminal tells me: "Use
> of uninitialized value in pattern match (m//) at [...]" and how can I
                                                   ^^^^^
At what?  Please include the _complete_ warning/error message.

> avoid it?



John
-- 
use Perl;
program
fulfillment

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

Reply via email to