<?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 perl: delete element in an array? in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/perl-delete-element-in-an-array/m-p/5243702#M676879</link>
    <description>Hey;&lt;BR /&gt;&lt;BR /&gt;I find myself having to delete an arbitrary element in an array - not necessarily the first nor the last.  &lt;BR /&gt;&lt;BR /&gt;Is there some clever way of doing that short of &lt;BR /&gt;&lt;BR /&gt;for (my $x=0; $x&amp;lt;$curr; $x++)&lt;BR /&gt;{  $new[$x] = $old[$x]; }&lt;BR /&gt;for (my $x=$curr+1; $x&amp;lt;$#old; $x++)&lt;BR /&gt;{  $new[$x-1] = $old[$x]; }&lt;BR /&gt;@old = @new;&lt;BR /&gt;&lt;BR /&gt;And, no, I don't know if that works yet - that was just done off the fly.  I'm curious if there's a different algorithm for doing this out there somewhere..&lt;BR /&gt;&lt;BR /&gt;Thanks for any hints/tips/suggestions.&lt;BR /&gt;&lt;BR /&gt;Doug</description>
    <pubDate>Mon, 14 Jun 2010 16:54:23 GMT</pubDate>
    <dc:creator>Doug O'Leary</dc:creator>
    <dc:date>2010-06-14T16:54:23Z</dc:date>
    <item>
      <title>perl: delete element in an array?</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/perl-delete-element-in-an-array/m-p/5243702#M676879</link>
      <description>Hey;&lt;BR /&gt;&lt;BR /&gt;I find myself having to delete an arbitrary element in an array - not necessarily the first nor the last.  &lt;BR /&gt;&lt;BR /&gt;Is there some clever way of doing that short of &lt;BR /&gt;&lt;BR /&gt;for (my $x=0; $x&amp;lt;$curr; $x++)&lt;BR /&gt;{  $new[$x] = $old[$x]; }&lt;BR /&gt;for (my $x=$curr+1; $x&amp;lt;$#old; $x++)&lt;BR /&gt;{  $new[$x-1] = $old[$x]; }&lt;BR /&gt;@old = @new;&lt;BR /&gt;&lt;BR /&gt;And, no, I don't know if that works yet - that was just done off the fly.  I'm curious if there's a different algorithm for doing this out there somewhere..&lt;BR /&gt;&lt;BR /&gt;Thanks for any hints/tips/suggestions.&lt;BR /&gt;&lt;BR /&gt;Doug</description>
      <pubDate>Mon, 14 Jun 2010 16:54:23 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/perl-delete-element-in-an-array/m-p/5243702#M676879</guid>
      <dc:creator>Doug O'Leary</dc:creator>
      <dc:date>2010-06-14T16:54:23Z</dc:date>
    </item>
    <item>
      <title>Re: perl: delete element in an array?</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/perl-delete-element-in-an-array/m-p/5243703#M676880</link>
      <description>Hi Doug:&lt;BR /&gt;&lt;BR /&gt;Have a look at 'splice':&lt;BR /&gt;&lt;BR /&gt;# perl -le '@a=qw(a b c d e f);@a=splice(@a,3,2);print @a'&lt;BR /&gt;de&lt;BR /&gt;&lt;BR /&gt;# perl -le '@a=qw(a b c d e f);@a=splice(@a,1,-1);print @a'&lt;BR /&gt;bcde&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Mon, 14 Jun 2010 17:11:25 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/perl-delete-element-in-an-array/m-p/5243703#M676880</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2010-06-14T17:11:25Z</dc:date>
    </item>
    <item>
      <title>Re: perl: delete element in an array?</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/perl-delete-element-in-an-array/m-p/5243704#M676881</link>
      <description>Hi (again):&lt;BR /&gt;&lt;BR /&gt;Sorry, I meant to add this too!&lt;BR /&gt;&lt;BR /&gt;# perl -le '@a=qw(a b c d e f);splice(@a,3,2);print @a'&lt;BR /&gt;abcf&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Mon, 14 Jun 2010 17:19:11 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/perl-delete-element-in-an-array/m-p/5243704#M676881</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2010-06-14T17:19:11Z</dc:date>
    </item>
    <item>
      <title>Re: perl: delete element in an array?</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/perl-delete-element-in-an-array/m-p/5243705#M676882</link>
      <description>Hey;&lt;BR /&gt;&lt;BR /&gt;That works pretty well; here's the playing around I did.  This'll be exactly what I need.  I appreciate it.&lt;BR /&gt;&lt;BR /&gt;Doug&lt;BR /&gt;&lt;BR /&gt;my @a = qw (one two three four five six seven eight nine ten );&lt;BR /&gt;my @b = @a;&lt;BR /&gt;my $cur = $ARGV[0];&lt;BR /&gt;print "$a[$cur]\n";&lt;BR /&gt;@a = splice(@b, 0, $cur);&lt;BR /&gt;print "A: @a" . "\n";&lt;BR /&gt;print "B: @b" . "\n";&lt;BR /&gt;push(@a, splice(@b,1));&lt;BR /&gt;print "A: @a" . "\n";&lt;BR /&gt;print "B: @b" . "\n";&lt;BR /&gt;&lt;BR /&gt;./junk 3 # results in:&lt;BR /&gt;four&lt;BR /&gt;A: one two three&lt;BR /&gt;B: four five six seven eight nine ten&lt;BR /&gt;&lt;BR /&gt;A: one two three five six seven eight nine ten&lt;BR /&gt;B: four</description>
      <pubDate>Mon, 14 Jun 2010 17:37:39 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/perl-delete-element-in-an-array/m-p/5243705#M676882</guid>
      <dc:creator>Doug O'Leary</dc:creator>
      <dc:date>2010-06-14T17:37:39Z</dc:date>
    </item>
  </channel>
</rss>

