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

Look at this:
--------------------------------------
The code is:
(Sorry for any inconvenience about previous code I paste)
#!/usr/bin/perl use warnings; #Chapter 3, Exercise 2 @name = qw / fred betty barney dino Wilma pebbles bamm-bamm /; @getnum = map {chomp; $_} <STDIN>; foreach $num(@getnum) { print "\nNo".$num."\tname:".$name[${num}-1]."\n"; }
--------------------------------------

If I input like this:

2
3
Ctrl^Z

It works well.
But if like this:

asd
xc
Ctrl^Z

It print a warning:


Argument "asd" isn't numeric in subtraction (-) at ......\Untitled1.cgi line 9, <STDIN> line 2.

Noasd name:bamm-bamm
Argument "xc" isn't numeric in subtraction (-) at ......\Untitled1.cgi line 9, <STDIN> line 2.

Noxc name:bamm-bamm


Then, my question is how can I print my array even I give a alpha string withou warnings? Thanks.
  • Comment on Basic question:ow can I print my array even I give a alpha string withou warnings?
  • Download Code

Replies are listed 'Best First'.
Re: Basic question:how to sort either numeric or alpha string?
by moritz (Cardinal) on Dec 09, 2008 at 09:22 UTC
    It print a warning: Argument "ssb" isn't numeric in subtraction (-) at ...

    Don't ignore the ... - in the real output there are line numbers there which give you important clues on what's going on. In this case it would have told you that you haven't showed us the relevant part of your code.

    And if you use perl-5.10, it will tell you which variables are uninitialized.

Re: Basic question:how to sort either numeric or alpha string?
by ccn (Vicar) on Dec 09, 2008 at 09:15 UTC
    Those warnings come from somwhere outside the code given by you.
Re: Basic question:how to sort either numeric or alpha string?
by hawtin (Prior) on Dec 09, 2008 at 12:28 UTC
      Thanks. I'd like to view it.
A reply falls below the community's threshold of quality. You may see it by logging in.