Being cutesie is all very fine so long as you give us the actual information - in this case the error message.

There are a number of issues with the code snippet as shown:

$arg1 = $ARGV[0];

assigns the first parameter to $arg1 as I'm sure you intend, but doesn't remove the parameter from the argument list. If you want to remove the first arg you should:

my $arg1 = shift @ARGV;

The second line:

$restargs = @ARGV;

assigns the number of parameters to $restargs, which I'm fairly sure is not what you intend. An array in scalar context returns the number of items in the array. One of the following is more likely what you want:

my @restargs = @ARGV[1..$#ARGV]; # An array of all the args except the + first (uses array slice) my $restargs = "@ARGV"; # A string containing all the args concatenate +d together with spaces between them my $restargs = "@ARGV[1..$#ARGV]"; # As above excluding the first argu +ment

and finally

$restargs = ~s/$arg1 //g;

is not at all what you expect. The space between = and ~ turns the expression into an assignment to $restargs of the complement of the success result of applying the substitution to the default variable ($_).

I strongly recommend that you use strict; use warnings in all the Perl you write!

Update: add shift example


DWIM is Perl's answer to Gödel

In reply to Re: gimme some sed by GrandFather
in thread gimme some sed by perlAffen

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.