Greetings Monks!
I come again seeking wisdom. This code takes the @a and if the contents match a key in the hash %list it pushes the value of the key into my output array, if there is no match it pushes the original input. Works fine until I change line 3 to my @a=<STDIN>; and add chomp (@a); The changes result in an empty array being returned. Can someone tell me why my input from STDIN would look different than the same input from the array, considering that I do chomp it?
TIA
jg
#!/usr/local/bin/perl -w use strict; my @a=(1..99); my (@names,@name_nums); @names=name_nums(@a); print "@names"; sub name_nums { my (%list,@name_nums,$this_num, @input); @input=@_; @list{1..9}=qw(one two three four five six seven eight nine); foreach (@input){ if (exists $list{ $_ }){ push @name_nums, $list{ $_ }; }else{ push (@name_nums,$_); } } return @name_nums; }
_____________________________________________________
Ain't no time to hate! Barely time to wait! ~RH

edit - Petruchio Mon Oct 1 00:04:27 UTC 2001: Minor Formatting adjustments.


In reply to Change from @a=(1..99) to @a=\STDIN\ = problems by jerrygarciuh

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.