Adriano Allora wrote:
hi to all,
I'd like to know two things:

1 - Perl vs. AWK
I'm learning Perl to use it in text processing. Recently I start to argue with a friend of mine about the best language to process texts (clear them, or markup them, tokenize them or parse them), he says awk is better - quicker than perl, for example, and easier -.
I want to learn perl also for cging, but I'm curious about its skills with texts (my friend also forwarded me a mail of AWK mailing list in which someone who did a benchmark demonstrated the speed of awk...)
Someone want to tell me somethong about it?

Easier is subjective, I know Perl already and while Awk may be related I wouldn't want to have to learn new syntax/language just to process some files, so Perl is easier *to me*. As far as speed, your friend could very well be right, but to what extent. If it takes your program .5 ms to parse a file with perl and .3 ms to parse it with AWK, then yes it is faster, but it isn't likely in most situations that it matters that much, sure in others it does. Ask your friend how he connects to a database in awk? Or about the OOP features of Awk. Or about the list of publicly available pre-written modules to handle all kinds of tasks in Awk. Awk is great at one thing, which is why it is fast at that thing, Perl is great at lots of stuff, but not as fast as any one product in its own particular ability. Why is an orange better than an apple?


2 - an unexplicable difference
I wrote two scripts in order to extract parts of text from a file and put these parts in two arrays.
The first one works very well, but the second one doesn't. Because of the scripts are identical in all but for the second regexp (but the regexp is not erroneous), I cannot undestand this difference.
Some advice?

I don't completely understand what your doing here. Can you give an example of the input and desired output?


THIS ONE WORKS:
#!/usr/bin/perl -w
my $file_name = "cicci.txt";
my $num = 0;
my $new = "";
open (INPUT, $file_name);
while (<INPUT>)
{
s/\s.+/\n/g;
foreach ($.)
    {
    m/\n/;
    $new[$.] = $`;
    }
}
close (INPUT);
print @new;
print "\n";

THIS ONE DOESN'T WORK:
#!/usr/bin/perl -w
my $file_name = "cicci.txt";
my $num = 0;
my $new = "";
open (INPUT, $file_name);
while (<INPUT>)
{
foreach (s/(\S|\S\S|\S\S\S)(     )//g)
# typing here "print;" I saw that the regexp works;
    {
    print;
    m/\n/;
    $new[$.] = $`;
    }
}
close (INPUT);
print @new;
print "\n";

all'adr



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

Reply via email to