Re: Search one character against one string

2014-03-13 Thread Alex Chiang
Thanks all, and thanks Nathan for your detailed explanation. Now I know the list got flattened before passing into subroutine. Cheers. --- Regards ! Alex Chiang

Re: Search one character against one string

2014-03-13 Thread Alex Chiang
Thanks for your reply. I know the built-in index function, but I just can't figure out why it gives me the answer I don't expect :D --- Regards ! Alex Chiang

Re: Search one character against one string

2014-03-13 Thread Uri Guttman
On 03/12/2014 05:14 AM, Alex Chiang wrote: Thanks for your reply. I know the built-in index function, but I just can't figure out why it gives me the answer I don't expect :D you shouldn't expect some answer without checking the documentation. index is well documented so you must be looking

Search one character against one string

2014-03-12 Thread Alex Chiang
Hi there, I got a wired bug with the following perl script: 35 # return non-negative value if particular character is in string array 36 # otherwise, return -1 sub is_in_string { 38 # @s: string array, $c: character 39 # passing array into sub 40 my @s = @_[0]; my $c = $_[1]; 41 for my

Re: Search one character against one string

2014-03-12 Thread Bob goolsby
Mornin' -- Take a look at the index() function, unless you have a real need to reinvent one of the Perl builtin functions. (i.e. your home work assignment from your tescher demands it.) B On Tue, Mar 11, 2014 at 9:58 PM, Alex Chiang pigfly...@gmail.com wrote: Hi there, I got a wired bug

Re: Search one character against one string

2014-03-12 Thread Robert Wohlfarth
On Tue, Mar 11, 2014 at 11:58 PM, Alex Chiang pigfly...@gmail.com wrote: sub is_in_string { 38 # @s: string array, $c: character 39 # passing array into sub 40 my @s = @_[0]; my $c = $_[1]; snip... 44 my @ar = qw(t d s); 45 my $c = d; 46 my $res = is_in_string( @ar, $c); This is a

Re: Search one character against one string

2014-03-12 Thread Jing Yu
Is @_[0] even legit? On 12 Mar 2014, at 04:58, Alex Chiang pigfly...@gmail.com wrote: Hi there, I got a wired bug with the following perl script: 35 # return non-negative value if particular character is in string array 36 # otherwise, return -1 sub is_in_string { 38 # @s:

Re: Search one character against one string

2014-03-12 Thread Nathan Hilterbrand
First: @_[0] is legit, in that it is a 1 element slice of the array @_.. but most likely is not at all what you really want. When an array is passed as a parameter to a subroutine in perl, it is unrolled. In other words, each element of the array is passed as a single parameter. In order