[FR/EN] string conversion.

A

Alextophi

FR
-------------------------------------------------------------------------
Bonjour, voici mon problème :

- C'est une conversion de jour de semaine, du français vers l'anglais
et le '-I' n'est pas utile.

- '$my_str_in' peut contenir un ou plusieur mot; ' Lu-I Ma-I Me-I Je-I
Ve-I Sa-I Di-I Tlj-I Lu-F Ma-F Me-F Je-F Ve-F Sa-F Di-F Tlj-F '


- Je dois convertir la chaine, '$my_str_in' = "Lu-I Ma-I Me-I"; en
chaine : '$my_str_out' = "Mon-Tue-Wed";


Comment faire ?


merci, christophe



EN
------------------------------------------------------------------------

hello, here my problem:

- It is a conversion of day of week, from French towards English and it
'-I' is not useful.

- '$my_str_in' can contain one or plusior word; ' Lu-I Ma-I Me-I Je-I
Ve-I Sa-I Di-I Tlj-I Lu-F Ma-F Me-F Je-F Ve-F Sa-F Di-F Tlj-F '

- I must convert the chains, '$my_str_in' = "Lu-I Ma-I Me-I"; en chaine
: '$my_str_out' = "Mon-Tue-Wed";

How to make this fonction ?

thank you, Christophe







for ($i=0;$i<100;$i++) {print "I am really null";}
*------------------------------------------------*
 
J

Josef Moellers

Alextophi said:
FR
-------------------------------------------------------------------------
Bonjour, voici mon problème :

- C'est une conversion de jour de semaine, du français vers l'anglais
et le '-I' n'est pas utile.

- '$my_str_in' peut contenir un ou plusieur mot; ' Lu-I Ma-I Me-I Je-I
Ve-I Sa-I Di-I Tlj-I Lu-F Ma-F Me-F Je-F Ve-F Sa-F Di-F Tlj-F '


- Je dois convertir la chaine, '$my_str_in' = "Lu-I Ma-I Me-I"; en
chaine : '$my_str_out' = "Mon-Tue-Wed";


Comment faire ?


merci, christophe



EN
------------------------------------------------------------------------

hello, here my problem:

- It is a conversion of day of week, from French towards English and it
'-I' is not useful.

- '$my_str_in' can contain one or plusior word; ' Lu-I Ma-I Me-I Je-I
Ve-I Sa-I Di-I Tlj-I Lu-F Ma-F Me-F Je-F Ve-F Sa-F Di-F Tlj-F '

- I must convert the chains, '$my_str_in' = "Lu-I Ma-I Me-I"; en chaine
: '$my_str_out' = "Mon-Tue-Wed";

How to make this fonction ?

Just write it!

If it doesn't work as expected, come here again and show us what you've
tried.
 
A

Alextophi

ok I understand, here the code:

#Call function
&funct_conv("Lu-I Ma-I Me-I");
print "string_out"; # see "Mon-Tue-Wed"



------------------------------------------------------
sub funct_conv {
my @SCHED = split(" ", $_[0]);


my %day = ('Lu-I' => "Mon",
'Ma-I' => "Tue",
'Me-I' => "Wed",
'Je-I' => "Thu",
'Ve-I' => "Fri",
'Sa-I' => "Sat",
'Di-I' => "Sun",
'Lu-F' => "Mon",
'Ma-F' => "Tue",
'Me-F' => "Wed",
'Je-F' => "Thu",
'Ve-F' => "Fri",
'Sa-F' => "Sat",
'Di-F' => "Sun",
'Tlj-' => "Mon-Tue-Wed-Thu-Fri-Sat-Sun"
);

foreach my $SCHED(@SCHED){
my $DayEN = $day{substr($SCHED,0,4)};


$string_out = $DayEN # how to make a list of result?

}

return ($string_out);

} # end
 
B

Babacio

Try that :


print funct_conv("Lu-I Ma-I Me-I");

sub funct_conv {
my @SCHED = split(" ", $_[0]);

my %day = ('Lu-I' => "Mon", 'Ma-I' => "Tue", 'Me-I' => "Wed",
'Je-I' => "Thu", 'Ve-I' => "Fri", 'Sa-I' => "Sat",
'Di-I' => "Sun", 'Lu-F' => "Mon", 'Ma-F' => "Tue",
'Me-F' => "Wed", 'Je-F' => "Thu", 'Ve-F' => "Fri",
'Sa-F' => "Sat", 'Di-F' => "Sun",
'Tlj-' => "Mon-Tue-Wed-Thu-Fri-Sat-Sun"
);

my @result;

foreach my $SCHED(@SCHED){
my $DayEN = $day{substr($SCHED,0,4)};
push @result, $DayEN;
}
return join("-",@result);
}
 
J

Josef Moellers

Alextophi said:
ok I understand, here the code:

#Call function
&funct_conv("Lu-I Ma-I Me-I");
print "string_out"; # see "Mon-Tue-Wed"



------------------------------------------------------
sub funct_conv {
my @SCHED = split(" ", $_[0]);


my %day = ('Lu-I' => "Mon",
'Ma-I' => "Tue",
'Me-I' => "Wed",
'Je-I' => "Thu",
'Ve-I' => "Fri",
'Sa-I' => "Sat",
'Di-I' => "Sun",
'Lu-F' => "Mon",
'Ma-F' => "Tue",
'Me-F' => "Wed",
'Je-F' => "Thu",
'Ve-F' => "Fri",
'Sa-F' => "Sat",
'Di-F' => "Sun",
'Tlj-' => "Mon-Tue-Wed-Thu-Fri-Sat-Sun"
);

foreach my $SCHED(@SCHED){
my $DayEN = $day{substr($SCHED,0,4)};


$string_out = $DayEN # how to make a list of result?

}

return ($string_out);

} # end

Ok, no need to send in the Panzers B-{)

One way to do it would be to store the intermediate result in an array,
then join the array members to return them:

my @result;
foreach my $SCHED(@SCHED){
my $DayEN = $day{substr($SCHED,0,4)};


push @result, $DayEN;

}

return join(" ", @result);
} # end

Josef
 
B

Babacio

Josef Moellers.
my @result;
foreach my $SCHED(@SCHED){
my $DayEN = $day{substr($SCHED,0,4)};


push @result, $DayEN;

}

return join(" ", @result);
} # end

Darn, were you first to reply? And even the same variable name!
Gosh, this is supranatural, I'll find smoe garlic.
 
G

Gunnar Hjalmarsson

Alextophi said:
ok I understand,

What do you understand?
here the code:

See proposed changes below.
#Call function
&funct_conv("Lu-I Ma-I Me-I");
print "string_out"; # see "Mon-Tue-Wed"

Replace that with

print funct_conf("Lu-I Ma-I Me-I");
sub funct_conv {
my @SCHED = split(" ", $_[0]);

Declare an array where days are temporarily stored in English:

my @daysEN;
my %day = ('Lu-I' => "Mon",
'Ma-I' => "Tue",
'Me-I' => "Wed",
'Je-I' => "Thu",
'Ve-I' => "Fri",
'Sa-I' => "Sat",
'Di-I' => "Sun",
'Lu-F' => "Mon",
'Ma-F' => "Tue",
'Me-F' => "Wed",
'Je-F' => "Thu",
'Ve-F' => "Fri",
'Sa-F' => "Sat",
'Di-F' => "Sun",
'Tlj-' => "Mon-Tue-Wed-Thu-Fri-Sat-Sun"
);

foreach my $SCHED(@SCHED){
my $DayEN = $day{substr($SCHED,0,4)};


$string_out = $DayEN # how to make a list of result?

push @daysEN, $DayEN;
}

return ($string_out);

return join '-', @daysEN;
 
A

Alextophi

Thank you with all,

- that functions!!

there is just a trick : return join("-", @result);

the result does not have it '-' between the values! !

thank you very much, Christophe
 
B

Babacio

"Alextophi".
there is just a trick : return join("-", @result);

the result does not have it '-' between the values! !

I don't understand what you mean. I think I am the one you're talking
to, because I wrote this join with a '-' ; (I sure wrote "-", but '-'
is better). If there is stull something wrong, feel free to write to
me directly (in french ;)
 
A

Alextophi

ok

en fait le "-" (trait-d'union) n'apparait pas dans la chaine @result

ex: "Mon Tue Wed Thu Fri"


ch.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,997
Messages
2,570,240
Members
46,830
Latest member
HeleneMull

Latest Threads

Top