gojippo has asked for the wisdom of the Perl Monks concerning the following question:

Powerful monks, I seekth thou Wisdom on my quest to learning the almighty perl language !

I have to write a script to automatize the inflection of a given list of french verbs. I made the following script (still halfway), but it's giving me lots of errors ("Use of uninitialized value in substitution (s///)"). I think there is a problem with the "my" scope. Isn't it possible to declare multiple scalars, and to write like " ($scalar1, $scalar2..) = $otherscalar ?
With the following script, I don't get error messages only for the first scalar in the parenthesis.
Oh, btw, I'm still a learning newbie, so if you have ideas of how to write this script better, please tell me !

#!/usr/bin/perl use strict; use warnings; while (<>){ chomp; s/\r//g; my($verb,$group) = split /\t/; # I take the $verb name and inflect +ion group number if ($group == 1){ #if its first group,... my ($present_1,$present_2,$present_3,$present_4,$present_5) = +$verb; my ($imparfait_1,$imparfait_2,$imparfait_3,$imparfait_4,$imparfait +_5) = $verb; my ($past_1,$past_2,$past_3,$past_4,$past_5,$past_6) = $verb; my ($futur_1,$futur_2,$futur_3,$futur_4,$futur_5,$futur_6) = $verb +; my ($conditional_1,$conditional_2,$conditional_3,$conditional_4,$c +onditional_5) = $verb; my ($subj_imp_1,$subj_imp_2,$subj_imp_3,$subj_imp_4,$subj_imp_5,$s +ubj_imp_6) = $verb; my $pp_ger = $verb; # give them all the $verb value, then... $present_1 =~ s/er$/e/g; $present_2 =~ s/er$/es/g; $present_3 =~ s/er$/ons/g; $present_4 =~ s/er$/ez/g; $present_5 =~ s/er$/ent/g; $imparfait_1 =~ s/er$/ais/g; $imparfait_2 =~ s/er$/ait/g; $imparfait_3 =~ s/er$/ions/g; $imparfait_4 =~ s/er$/iez/g; $imparfait_5 =~ s/er$/aient/g; $past_1 =~ s/er$/ai/g; $past_2 =~ s/er$/as/g; $past_3 =~ s/er$/a/g; $past_4 =~ s/er$/&#20294;mes/g; $past_5 =~ s/er$/&#20294;tes/g; $past_6 =~ s/er$/&#31466;rent/g; $futur_1 =~ s/er$/erai/g; $futur_2 =~ s/er$/eras/g; $futur_3 =~ s/er$/era/g; $futur_4 =~ s/er$/erons/g; $futur_5 =~ s/er$/erez/g; $futur_6 =~ s/er$/eront/g; $conditional_1 =~ s/er$/erais/g; $conditional_2 =~ s/er$/erait/g; $conditional_3 =~ s/er$/erions/g; $conditional_4 =~ s/er$/eriez/g; $conditional_5 =~ s/er$/eraient/g; $subj_imp_1 =~ s/er$/asse/g; $subj_imp_2 =~ s/er$/asses/g; $subj_imp_3 =~ s/er$/&#20294;t/g; $subj_imp_4 =~ s/er$/assions/g; $subj_imp_5 =~ s/er$/assiez/g; $subj_imp_6 =~ s/er$/assent/g; $pp_ger =~ s/er$/ant/g; #change them all to their respective forms print "$verb\t$present_1\t$present_2\t$present_1\t$present_3\t$pre +sent_4\t$present_5\t$imparfait_1\t$imparfait_1\t$imparfait_2\t$imparf +ait_3\t$imparfait_4\t$imparfait_5\t$past_1\t$past_2\t$past_3\t$past_4 +\t$past_5\t$past_6\t$futur_1\t$futur_2\t$futur_3\t$futur_4\t$futur_5\ +t$futur_6\t$conditional_1\t$conditional_1\t$conditional_2\t$condition +al_3\t$conditional_4\t$conditional_5\t$present_1\t$present_2\t$presen +t_3\t$imparfait_3\t$imparfait_4\t$present_5\t$subj_imp_1\t$subj_imp_2 +\t$subj_imp_3\t$subj_imp_4\t$subj_imp_5\t$subj_imp_6\t$present_1\t$pr +esent_3\t$present_4\t$verb\t$pp_ger\t$pp_ger\t$group\n"; } #and print out }

Replies are listed 'Best First'.
Re: Automatic verb inflection script
by samtregar (Abbot) on May 20, 2008 at 03:33 UTC
    No, that won't work. You can do this though:

    my ($present_1,$present_2,$present_3,$present_4,$present_5) = ($verb) x 5;

    Using the x operator on a list produces the specified number of copies of the list - in this case 5 copies of ($verb), equivalent to ($verb,$verb,$verb,$verb,$verb).

    As a side note, any time I see numbered variables I think array. So you might do this instead:

    my @present = ($verb) x 5;

    Then instead of $present_1 you write $present[0].

    -sam

Re: Automatic verb inflection script
by pc88mxer (Vicar) on May 20, 2008 at 03:34 UTC
    Here's your problem:
    my ($present_1,$present_2,$present_3,$present_4,$present_5) = $verb;
    I assume you want all of the variables to be initialized with $verb. Howevr, this statement only sets $present_1 and the rest will be set to undef.

    A quick fix is to write:

    my ($present_1, ...) = ($verb) x 5;

    Another approach to this would be to first compute the verb stem and then just add the appropriate ending:

    my $stem = $verb; $stem =~ s/er$//; my $present_1 = $stem . "e"; my $present_2 = $stem . "es"; ...
    For your group 1 verbs, this can be very compactly written:
    my @present_endings = qw(e es ons ez ent); my @present = map { $stem . $_ } @present_endings; ...etc for the other tenses...
    In fact, you might be able to make use of the module Lingua::Stem::Fr.
      Wow, you and samtregar replied almost at the same time.

      I got my solution thanks to you two. Thank you for your precious help ! I will check out the stem module, could be of good help.