Being the fledgling Perl Programmer that I am and trying to learn about the "splice" function, I searched the Monastery for "splice". Then being somewhat confused about the description I searched my handy/dandy Programming Perl book and found the same equally cryptic text. I thought that I would use "splice" to remove elements from an array. But, I'm getting confused as to the syntax. Below is a small program that I wrote to test the function.


#!/usr/bin/perl -w # # this is a test of the splice command # # # use strict; my $x = "how about this"; my $y = "this is the new line"; open (IN_FILE, "test.dat") or die "test.dat will not open: $!\n"; my @ary = <IN_FILE>; close (IN_FILE) or die "test.dat will not close: $!\n"; # print "Print the array before the change:\n @ary\n"; my $z = splice (@ary,$x,2); print "Printing the array:\n @ary\n\n\n"; print $z;


This is the output:

Print the array before the change:
this is a column|this is another|this is a also on
this could be|a column is this|and so is this
how about this|or maybe this| of this

Argument "how about this" isn't numeric in splice at ./test.pl line 16.
Print the array after the change:
how about this|or maybe this| of this



Print the splice value:this could be|a column is this|and so is this

I must be missing the point of the function.

"The Universe is not only more complex than we imagine, it is more complex than we can imagine." - Albert Einstein

In reply to A Splice of life by void

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.