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 ord
Is @_[0] even legit?
On 12 Mar 2014, at 04:58, Alex Chiang 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: string array, $c
On Tue, Mar 11, 2014 at 11:58 PM, Alex Chiang wrote:
> sub is_in_string {
> 38 # @s: string array, $c: character
> 39 # passing array into sub
> 40 my @s = @_[0]; my $c = $_[1];
> 44 my @ar = qw(t d s);
> 45 my $c = "d";
> 46 my $res = &is_in_string( @ar, $c);
This is a good example of how
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 wrote:
> Hi there,
>
> I got a wired bug with the following
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 $