A
April
Will the following change a single digit to corresponding English
word, like 3 to three, 5 to five, etc?
$char = $numbers[$char]
word, like 3 to three, 5 to five, etc?
$char = $numbers[$char]
April said:Will the following change a single digit to corresponding English
word, like 3 to three, 5 to five, etc?
$char = $numbers[$char]
April said:Will the following change a single digit to corresponding English
word, like 3 to three, 5 to five, etc?
$char = $numbers[$char]
April said:Will the following change a single digit to corresponding English
word, like 3 to three, 5 to five, etc?
$char = $numbers[$char]
April said:Will the following change a single digit to corresponding English
word, like 3 to three, 5 to five, etc?$char = $numbers[$char]
Assuming that the array @numbers contains the string 'three' at index 3,
then yes, after this assignment $char will contain the string 'three'.
In which case $char is a very poor choice for an identifier.
jue
JD> "April said:Will the following change a single digit to corresponding English
word, like 3 to three, 5 to five, etc?
$char = $numbers[$char]
JD> In addition to the answers already given, I thought I would also point
JD> out that there is a module that does this very thing:
JD> http://search.cpan.org/~sburke/Lingua-EN-Numbers-1.01/
I wonder if there's a locale-sensitive way to say numbers from inside
Perl. It must be available (part of glibc I think), since I know `date`
for example can print the day correctly depending on the locale.
I didn't see anything in CPAN, only
http://search.cpan.org/~rgarcia/perl-5.10.0/ext/I18N/Langinfo/Langinfo.pm
The CPAN *Locale* modules were not very useful for this task.
Lingua::Any::Numbers doesn't sniff out the locale automatically, and
doesn't seem to use the glibc facilities (if such exist).
April said:Thanks jue and everyone .. I just stumble on this and would like to
know how this "$char = $numbers[$char]" accually work ... here is the
entire program:
#!/usr/bin/perl -w
use strict;
my @numbers = qw(zero one two three four five six seven eight nine);
print "Enter a string containing a number: ";
chomp(my $answer = <STDIN>);
my @characters = split ("", $answer);
foreach my $char (@characters)
{
$char = $numbers[$char]
if ($char ge "0" && $char le "9");
}
print "The output is: @characters\n";
April said:I just stumble on this and would like to
know how this "$char = $numbers[$char]" accually work
Ted Zlatanov said:The Lingua::*::Numbers
modules are not setting the output encoding; it seems like that's up to
the application.
Gunnar said:April wrote:my @characters = split ("", $answer);
foreach my $char (@characters)
{
$char = $numbers[$char]
if ($char ge "0" && $char le "9");
}
print "The output is: @characters\n";
I suggest that you do some reading first.
perldoc perlintro
perldoc perldata
Henry said:Gunnar said:April said:my @characters = split ("", $answer);
foreach my $char (@characters)
{
$char = $numbers[$char]
if ($char ge "0" && $char le "9");
}
print "The output is: @characters\n";
I suggest that you do some reading first.
perldoc perlintro
perldoc perldata
Unfair, Gunnar:
the key text is in perlsyn:
... the foreach loop index variable is an implicit alias for each item
in the list that you're looping over.
But I didn't know that so the code has improved my education.
BB> Lingua::Any::Numbers seems to be nothing but a wrapper for various
BB> other Perl modules, like the above-mentioned Lingua::JA::Numbers.
I understand, but my point was that it doesn't figure out what you want
based on the locale. For example:
% LANG=bg_BG.utf8 date
вт юни 24 14:41:09 CDT 2008
% LANG=C date
Tue Jun 24 14:41:12 CDT 2008
I don't know how to map any locale to any language in the
Lingua::*::Numbers hierarchy.
In addition, the .utf8* specifier is a
problem (see 'sr_YU.utf8@cyrillic' for example). The Lingua::*::Numbers
modules are not setting the output encoding; it seems like that's up to
the application.
So Lingua::Any::Numbers should have wrappers to
accomodate encodings and auto-detect locale.
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.