Re: About the hash case insensitive ~~~

2009-10-27 Thread Shlomi Fish
On Tuesday 27 Oct 2009 13:50:16 Majian wrote:
> Hello,all:
> I had a question about the perl hash case insensitive .
> 
> And I had  this script :
> ==
> #!/usr/bin/perl
> use warnings;

Just a note - you're missing the "use strict;" pragma which is a big no no in 
production code. See:

http://perl-begin.org/tutorials/perl-for-newbies/part2/#page--my--use_strict--
PAGE

(Sorry for the broken link - either paste the remaining part or search for 
"use strict" on the page.)

People may refuse to help you with such code because it may contain many 
subtle bugs.

Regards,

Shlomi Fish

[snipped]

-- 
-
Shlomi Fish   http://www.shlomifish.org/
What Makes Software Apps High Quality -  http://shlom.in/sw-quality

Chuck Norris read the entire English Wikipedia in 24 hours. Twice.

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: About the hash case insensitive ~~~

2009-10-27 Thread Majian
Thanks all ~

when I  type this command "perldoc -f uc", then find this :

  uc EXPR
  uc
Returns an uppercased version of EXPR.  This is the internal function
implementing the "\U"
 escape in double-quoted strings.  Respects current LC_CTYPE locale if "use
locale" in force.
  See perllocale and perlunicode for more details about locale and Unicode
support.  It does
   not attempt to do titlecase mapping on initial letters.  See "ucfirst"
for that
   If EXPR is omitted, uses $_.



On Tue, Oct 27, 2009 at 8:11 PM, Thomas Bätzler wrote:

> Majian  asked:
>
>
> > %courses = (
> >  "2CPR2B"=> "C Language",
> >  "1UNX1B"=> "Intro to Unix",
> >  "3SH414"=> "Shell Programming",
> >  "4PL400"=>  "Perl Programming",
> > );
> >
> > print "\n\"EDP\" NUMBERS AND ELECTIVES:\n";
> > while (($num, $value) = each (%courses))
> > {
> > print "-\n";
> > printf "%-10s | %s\n ", $num, $value;
> > }
> >
> > print "\nWhat is the EOP number of the course you wish to take : $num";
> > chomp ($num = );
> > print "The course you will be taking is: \"$courses{$num}\"\n";
> > ===
> > The question was :
> >
> > If I type  the "4PL400",  then it will output the value ---"Perl
> > Programming";
> > But I want to type the "4pl400" , and the result should be printed "Perl
> > Programming"
> >
> > How could I  come it  true?
>
> Use "chomp ($num = uc() )" to uppercase the input and make sure that
> all your keys are in upper case, too.
>
> HTH,
> Thomas
>


AW: About the hash case insensitive ~~~

2009-10-27 Thread Thomas Bätzler
Majian  asked:


> %courses = (
>  "2CPR2B"=> "C Language",
>  "1UNX1B"=> "Intro to Unix",
>  "3SH414"=> "Shell Programming",
>  "4PL400"=>  "Perl Programming",
> );
> 
> print "\n\"EDP\" NUMBERS AND ELECTIVES:\n";
> while (($num, $value) = each (%courses))
> {
> print "-\n";
> printf "%-10s | %s\n ", $num, $value;
> }
> 
> print "\nWhat is the EOP number of the course you wish to take : $num";
> chomp ($num = );
> print "The course you will be taking is: \"$courses{$num}\"\n";
> ===
> The question was :
> 
> If I type  the "4PL400",  then it will output the value ---"Perl
> Programming";
> But I want to type the "4pl400" , and the result should be printed "Perl
> Programming"
> 
> How could I  come it  true?

Use "chomp ($num = uc() )" to uppercase the input and make sure that all 
your keys are in upper case, too.

HTH,
Thomas

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




RE: About the hash case insensitive ~~~

2009-10-27 Thread Hack, Gabi (ext)
use uc() to convert to upper case (see below): chomp ($num = uc());

-Original Message-
From: Majian [mailto:jian...@gmail.com] 
Sent: Tuesday, October 27, 2009 12:50 PM
To: Perl Beginners
Subject: About the hash case insensitive ~~~

Hello,all:
I had a question about the perl hash case insensitive .

And I had  this script :
==
#!/usr/bin/perl
use warnings;
%courses = (
 "2CPR2B"=> "C Language",
 "1UNX1B"=> "Intro to Unix",
 "3SH414"=> "Shell Programming",
 "4PL400"=>  "Perl Programming",
);

print "\n\"EDP\" NUMBERS AND ELECTIVES:\n";
while (($num, $value) = each (%courses))
{
print "-\n";
printf "%-10s | %s\n ", $num, $value;
}

print "\nWhat is the EOP number of the course you wish to take : ";
chomp ($num = uc());
print "The course you will be taking is: \"$courses{$num}\"\n";
===
The question was :

If I type  the "4PL400",  then it will output the value ---"Perl
Programming";
But I want to type the "4pl400" , and the result should be printed "Perl
Programming"

How could I  come it  true?

Thanks for any suggestions ~~~

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: About the hash case insensitive ~~~

2009-10-27 Thread Dermot
2009/10/27 Majian :
> Hello,all:
> I had a question about the perl hash case insensitive .
>
> And I had  this script :
> ==
> #!/usr/bin/perl
> use warnings;
> %courses = (
>             "2CPR2B"    => "C Language",
>             "1UNX1B"    => "Intro to Unix",
>             "3SH414"    => "Shell Programming",
>             "4PL400"    =>  "Perl Programming",
>        );
>
> print "\n\"EDP\" NUMBERS AND ELECTIVES:\n";
> while (($num, $value) = each (%courses))
> {
>    print "-\n";
>    printf "%-10s | %s\n ", $num, $value;
> }
>
> print "\nWhat is the EOP number of the course you wish to take : $num";
> chomp ($num = );
> print "The course you will be taking is: \"$courses{$num}\"\n";
> ===
> The question was :
>
> If I type  the "4PL400",  then it will output the value ---"Perl
> Programming";
> But I want to type the "4pl400" , and the result should be printed "Perl
> Programming"

One obvious solution would be to make the hash keys lowercase and then
lc($num) to resolve the keys.
Dp.

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




About the hash case insensitive ~~~

2009-10-27 Thread Majian
Hello,all:
I had a question about the perl hash case insensitive .

And I had  this script :
==
#!/usr/bin/perl
use warnings;
%courses = (
 "2CPR2B"=> "C Language",
 "1UNX1B"=> "Intro to Unix",
 "3SH414"=> "Shell Programming",
 "4PL400"=>  "Perl Programming",
);

print "\n\"EDP\" NUMBERS AND ELECTIVES:\n";
while (($num, $value) = each (%courses))
{
print "-\n";
printf "%-10s | %s\n ", $num, $value;
}

print "\nWhat is the EOP number of the course you wish to take : $num";
chomp ($num = );
print "The course you will be taking is: \"$courses{$num}\"\n";
===
The question was :

If I type  the "4PL400",  then it will output the value ---"Perl
Programming";
But I want to type the "4pl400" , and the result should be printed "Perl
Programming"

How could I  come it  true?

Thanks for any suggestions ~~~