in reply to gimme some sed
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: gimme some sed
by perlAffen (Sexton) on Oct 06, 2006 at 13:55 UTC | |
by swampyankee (Parson) on Oct 06, 2006 at 14:30 UTC | |
by GrandFather (Saint) on Oct 06, 2006 at 18:52 UTC |