dnamonk has asked for the wisdom of the Perl Monks concerning the following question:
I am just trying to understand the array mechanism in PERL. Given the below code can you tell me why the same array isn't working in qw same like the first one above?
Thank you in advance for help.#!/bin/bash/perl @tests = ("ABCGE ABCGE", "ABCGE FGCGB", "ABCGE JHAGT"); my @tests = ( [qw{ABCGE ABCGE}], [qw{ABCGE FGCGB}], [qw{ABCGE JHAGT}], ); foreach $strings (@tests) { my $diff = 0; for my $i (0 .. length($strings->[0]) - 1) { my @chars = map substr($strings->[$_], $i, 1), 0, 1; ++$diff if $chars[0] ne $chars[1]; } print "@$strings $diff\n"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Array qw difference
by AnomalousMonk (Archbishop) on Nov 30, 2021 at 00:26 UTC | |
|
Re: Array qw difference
by hippo (Archbishop) on Nov 29, 2021 at 23:36 UTC | |
by dnamonk (Acolyte) on Nov 29, 2021 at 23:41 UTC | |
by AnomalousMonk (Archbishop) on Nov 30, 2021 at 00:32 UTC | |
|
Re: Array qw difference
by davido (Cardinal) on Nov 30, 2021 at 16:21 UTC | |
|
Re: Array qw difference
by Anonymous Monk on Nov 30, 2021 at 16:28 UTC |