<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Perl: array elements in Operating System - Linux</title>
    <link>https://community.hpe.com/t5/operating-system-linux/perl-array-elements/m-p/3708561#M103459</link>
    <description>There are of course two different interpretations of array's are equal:&lt;BR /&gt;&lt;BR /&gt;The actual content of (1..10) is the same as (5..10,1..4), but the match would fail.&lt;BR /&gt;Furthermore, you could use Test::More instead of Array::Compare, as Test::More is a core module, and you don't have to install extra modules:&lt;BR /&gt;&lt;BR /&gt;lt09:/home/merijn 104 &amp;gt; perl -MTest::More=no_plan -le'@a=1..10;@b=5..9,1..4,10;is_deeply(\@a,\@b,"Array contents match")'&lt;BR /&gt;not ok 1 - Array contents match&lt;BR /&gt;#   Failed test 'Array contents match'&lt;BR /&gt;#   in -e at line 1.&lt;BR /&gt;#     Structures begin differing at:&lt;BR /&gt;#          $got-&amp;gt;[0] = '1'&lt;BR /&gt;#     $expected-&amp;gt;[0] = '5'&lt;BR /&gt;1..1&lt;BR /&gt;# Looks like you failed 1 test of 1.&lt;BR /&gt;Exit 1&lt;BR /&gt;lt09:/home/merijn 105 &amp;gt; perl -MTest::More=no_plan -le'@a=1..10;@b=1..10;is_deeply(\@a,\@b,"Array contents match")'&lt;BR /&gt;ok 1 - Array contents match&lt;BR /&gt;1..1&lt;BR /&gt;lt09:/home/merijn 106 &amp;gt;&lt;BR /&gt;&lt;BR /&gt;But you can of course also sort, but note that default sorting is alphanumeric&lt;BR /&gt;&lt;BR /&gt;lt09:/home/merijn 106 &amp;gt; perl -MTest::More=no_plan -le'@a=1..10;@b=sort 5..9,1..4,10;is_deeply(\@a,\@b,"Array contents match")'&lt;BR /&gt;not ok 1 - Array contents match&lt;BR /&gt;#   Failed test 'Array contents match'&lt;BR /&gt;#   in -e at line 1.&lt;BR /&gt;#     Structures begin differing at:&lt;BR /&gt;#          $got-&amp;gt;[1] = '2'&lt;BR /&gt;#     $expected-&amp;gt;[1] = '10'&lt;BR /&gt;1..1&lt;BR /&gt;# Looks like you failed 1 test of 1.&lt;BR /&gt;Exit 1&lt;BR /&gt;lt09:/home/merijn 107 &amp;gt; perl -MTest::More=no_plan -le'@a=1..10;@b=sort{$a&amp;lt;=&amp;gt;$b}5..9,1..4,10;is_deeply(\@a,\@b,"Array contents match")'&lt;BR /&gt;ok 1 - Array contents match&lt;BR /&gt;1..1&lt;BR /&gt;lt09:/home/merijn 108 &amp;gt;&lt;BR /&gt;&lt;BR /&gt;Best thing about is_deeply () is that it also accepts hashes and hashes of hashes, lists of hashes, hashes of lists of lists of hashes of lists ...&lt;BR /&gt;&lt;BR /&gt;If you just want to test the array's, Test::More also provides eq_array (), and friends, so:&lt;BR /&gt;&lt;BR /&gt;lt09:/home/merijn 115 &amp;gt; perl -MTest::More=no_plan -le'@a=1..10;@b=1..10;ok print"Arrays ",eq_array(\@a,\@b)?"do":"dont"," match";'&lt;BR /&gt;Arrays do match&lt;BR /&gt;ok 1&lt;BR /&gt;1..1&lt;BR /&gt;lt09:/home/merijn 116 &amp;gt; perl -MTest::More=no_plan -le'@a=1..10;@b=5..10,1..4;ok print"Arrays ",eq_array(\@a,\@b)?"do":"dont"," match";'&lt;BR /&gt;Arrays dont match&lt;BR /&gt;ok 1&lt;BR /&gt;1..1&lt;BR /&gt;lt09:/home/merijn 117 &amp;gt;&lt;BR /&gt;&lt;BR /&gt;But for you, the best function would be eq_set ()&lt;BR /&gt;&lt;BR /&gt;Enjoy, Have FUN! H.Merijn</description>
    <pubDate>Fri, 13 Jan 2006 04:22:22 GMT</pubDate>
    <dc:creator>H.Merijn Brand (procura</dc:creator>
    <dc:date>2006-01-13T04:22:22Z</dc:date>
    <item>
      <title>Perl: array elements</title>
      <link>https://community.hpe.com/t5/operating-system-linux/perl-array-elements/m-p/3708558#M103456</link>
      <description>Hi!&lt;BR /&gt;I have a small problem:&lt;BR /&gt;&lt;BR /&gt;How do I check all elements of an array whether thay are the same (for example all elements are true and then I make some output, and if only one is false I break it)&lt;BR /&gt;&lt;BR /&gt;Thank you!</description>
      <pubDate>Fri, 13 Jan 2006 03:27:54 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/perl-array-elements/m-p/3708558#M103456</guid>
      <dc:creator>Kalin Evtimov</dc:creator>
      <dc:date>2006-01-13T03:27:54Z</dc:date>
    </item>
    <item>
      <title>Re: Perl: array elements</title>
      <link>https://community.hpe.com/t5/operating-system-linux/perl-array-elements/m-p/3708559#M103457</link>
      <description>Hi, You can use Array::Compare perl module do this, &lt;BR /&gt;&lt;BR /&gt;&lt;A href="http://search.cpan.org/~davecross/Array-Compare-1.13/lib/Array/Compare.pm" target="_blank"&gt;http://search.cpan.org/~davecross/Array-Compare-1.13/lib/Array/Compare.pm&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;my @arr1 = 0 .. 10;&lt;BR /&gt;my @arr2 = 0 .. 10;&lt;BR /&gt;&lt;BR /&gt;my $comp = Array::Compare-&amp;gt;new;&lt;BR /&gt;&lt;BR /&gt;  if ($comp-&amp;gt;compare(\@arr1, \@arr2)) {&lt;BR /&gt;    print "Arrays are the same\n";&lt;BR /&gt;  } else {&lt;BR /&gt;    print "Arrays are different\n";&lt;BR /&gt;  }&lt;BR /&gt;&lt;BR /&gt;-Arun</description>
      <pubDate>Fri, 13 Jan 2006 03:44:07 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/perl-array-elements/m-p/3708559#M103457</guid>
      <dc:creator>Arunvijai_4</dc:creator>
      <dc:date>2006-01-13T03:44:07Z</dc:date>
    </item>
    <item>
      <title>Re: Perl: array elements</title>
      <link>https://community.hpe.com/t5/operating-system-linux/perl-array-elements/m-p/3708560#M103458</link>
      <description>This will work, of course, but I need a script with no additional modules used in it. I may have a look at the implementation of that module.&lt;BR /&gt;10x a lot!</description>
      <pubDate>Fri, 13 Jan 2006 03:48:45 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/perl-array-elements/m-p/3708560#M103458</guid>
      <dc:creator>Kalin Evtimov</dc:creator>
      <dc:date>2006-01-13T03:48:45Z</dc:date>
    </item>
    <item>
      <title>Re: Perl: array elements</title>
      <link>https://community.hpe.com/t5/operating-system-linux/perl-array-elements/m-p/3708561#M103459</link>
      <description>There are of course two different interpretations of array's are equal:&lt;BR /&gt;&lt;BR /&gt;The actual content of (1..10) is the same as (5..10,1..4), but the match would fail.&lt;BR /&gt;Furthermore, you could use Test::More instead of Array::Compare, as Test::More is a core module, and you don't have to install extra modules:&lt;BR /&gt;&lt;BR /&gt;lt09:/home/merijn 104 &amp;gt; perl -MTest::More=no_plan -le'@a=1..10;@b=5..9,1..4,10;is_deeply(\@a,\@b,"Array contents match")'&lt;BR /&gt;not ok 1 - Array contents match&lt;BR /&gt;#   Failed test 'Array contents match'&lt;BR /&gt;#   in -e at line 1.&lt;BR /&gt;#     Structures begin differing at:&lt;BR /&gt;#          $got-&amp;gt;[0] = '1'&lt;BR /&gt;#     $expected-&amp;gt;[0] = '5'&lt;BR /&gt;1..1&lt;BR /&gt;# Looks like you failed 1 test of 1.&lt;BR /&gt;Exit 1&lt;BR /&gt;lt09:/home/merijn 105 &amp;gt; perl -MTest::More=no_plan -le'@a=1..10;@b=1..10;is_deeply(\@a,\@b,"Array contents match")'&lt;BR /&gt;ok 1 - Array contents match&lt;BR /&gt;1..1&lt;BR /&gt;lt09:/home/merijn 106 &amp;gt;&lt;BR /&gt;&lt;BR /&gt;But you can of course also sort, but note that default sorting is alphanumeric&lt;BR /&gt;&lt;BR /&gt;lt09:/home/merijn 106 &amp;gt; perl -MTest::More=no_plan -le'@a=1..10;@b=sort 5..9,1..4,10;is_deeply(\@a,\@b,"Array contents match")'&lt;BR /&gt;not ok 1 - Array contents match&lt;BR /&gt;#   Failed test 'Array contents match'&lt;BR /&gt;#   in -e at line 1.&lt;BR /&gt;#     Structures begin differing at:&lt;BR /&gt;#          $got-&amp;gt;[1] = '2'&lt;BR /&gt;#     $expected-&amp;gt;[1] = '10'&lt;BR /&gt;1..1&lt;BR /&gt;# Looks like you failed 1 test of 1.&lt;BR /&gt;Exit 1&lt;BR /&gt;lt09:/home/merijn 107 &amp;gt; perl -MTest::More=no_plan -le'@a=1..10;@b=sort{$a&amp;lt;=&amp;gt;$b}5..9,1..4,10;is_deeply(\@a,\@b,"Array contents match")'&lt;BR /&gt;ok 1 - Array contents match&lt;BR /&gt;1..1&lt;BR /&gt;lt09:/home/merijn 108 &amp;gt;&lt;BR /&gt;&lt;BR /&gt;Best thing about is_deeply () is that it also accepts hashes and hashes of hashes, lists of hashes, hashes of lists of lists of hashes of lists ...&lt;BR /&gt;&lt;BR /&gt;If you just want to test the array's, Test::More also provides eq_array (), and friends, so:&lt;BR /&gt;&lt;BR /&gt;lt09:/home/merijn 115 &amp;gt; perl -MTest::More=no_plan -le'@a=1..10;@b=1..10;ok print"Arrays ",eq_array(\@a,\@b)?"do":"dont"," match";'&lt;BR /&gt;Arrays do match&lt;BR /&gt;ok 1&lt;BR /&gt;1..1&lt;BR /&gt;lt09:/home/merijn 116 &amp;gt; perl -MTest::More=no_plan -le'@a=1..10;@b=5..10,1..4;ok print"Arrays ",eq_array(\@a,\@b)?"do":"dont"," match";'&lt;BR /&gt;Arrays dont match&lt;BR /&gt;ok 1&lt;BR /&gt;1..1&lt;BR /&gt;lt09:/home/merijn 117 &amp;gt;&lt;BR /&gt;&lt;BR /&gt;But for you, the best function would be eq_set ()&lt;BR /&gt;&lt;BR /&gt;Enjoy, Have FUN! H.Merijn</description>
      <pubDate>Fri, 13 Jan 2006 04:22:22 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/perl-array-elements/m-p/3708561#M103459</guid>
      <dc:creator>H.Merijn Brand (procura</dc:creator>
      <dc:date>2006-01-13T04:22:22Z</dc:date>
    </item>
    <item>
      <title>Re: Perl: array elements</title>
      <link>https://community.hpe.com/t5/operating-system-linux/perl-array-elements/m-p/3708562#M103460</link>
      <description>I noted that I missed some parens.&lt;BR /&gt;&lt;BR /&gt;@b = (5..9,2..4,10,1);&lt;BR /&gt;&lt;BR /&gt;Now for the full demo:&lt;BR /&gt;&lt;BR /&gt;--&amp;gt;8---&lt;BR /&gt;#!/pro/bin/perl&lt;BR /&gt;&lt;BR /&gt;use strict;&lt;BR /&gt;use warnings;&lt;BR /&gt;&lt;BR /&gt;use Test::More 'no_plan';&lt;BR /&gt;&lt;BR /&gt;my @a = (1 .. 10);&lt;BR /&gt;my @b = (5 .. 9, 2 .. 4, 10, 1);&lt;BR /&gt;&lt;BR /&gt;isnt ("@a", "@b", "Plain in interpolation");&lt;BR /&gt;&lt;BR /&gt;ok (!eq_array  (\@a, \@b), "eq_array");&lt;BR /&gt;ok ( eq_array  ([sort @a], [sort @b]), "eq_array on sorted ref");&lt;BR /&gt;     is_deeply ([sort @a], [sort @b], "is_deeply on sorted ref");&lt;BR /&gt;ok ( eq_array  ([sort { $a &amp;lt;=&amp;gt; $b } @a], [sort { $a &amp;lt;=&amp;gt; $b } @b]), "eq_array on num-sorted ref");&lt;BR /&gt;     is_deeply ([sort { $a &amp;lt;=&amp;gt; $b } @a], [sort { $a &amp;lt;=&amp;gt; $b } @b], "is_deeply on num-sorted ref");&lt;BR /&gt;&lt;BR /&gt;     eq_set    (\@a, \@b, "eq_set");&lt;BR /&gt;--&amp;gt;8---&lt;BR /&gt;&lt;BR /&gt;pc09:/home/merijn 105 &amp;gt; perl xx.pl&lt;BR /&gt;ok 1 - Plain in interpolation&lt;BR /&gt;ok 2 - eq_array&lt;BR /&gt;ok 3 - eq_array on sorted ref&lt;BR /&gt;ok 4 - is_deeply on sorted ref&lt;BR /&gt;ok 5 - eq_array on num-sorted ref&lt;BR /&gt;ok 6 - is_deeply on num-sorted ref&lt;BR /&gt;1..6&lt;BR /&gt;pc09:/home/merijn 106 &amp;gt;&lt;BR /&gt;&lt;BR /&gt;Enjoy, Have FUN! H.Merijn</description>
      <pubDate>Fri, 13 Jan 2006 06:37:30 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/perl-array-elements/m-p/3708562#M103460</guid>
      <dc:creator>H.Merijn Brand (procura</dc:creator>
      <dc:date>2006-01-13T06:37:30Z</dc:date>
    </item>
  </channel>
</rss>

