Passing arguments to a Perl script

I am playing around with Perl and wrote the script below that is executed from the command line, it will split data up in a file based on a value supplied. When executed you provide two arguments - the file that contains the data to be split and the character you want to split by. It works as intended, but the "split value" has to be surround by double quotes for it to work. It is a minor annoyance, but I would like to figure out how to have this work without having to use the double quotes. Any help would be appreciated. Thank you. Here is the script:
Code:

#!/usr/local/bin/perl
chomp($which_file=@ARGV[0]);
chomp($split_val=@ARGV[1]);
if (length($which_file)==0||length($split_val)==0)
   {print "You must provide a file and split value!\n";}
else
  {
   if (!-e $which_file)
      {print "$which_file does not exist!\n";}
   else
      {
       open (spfile,"<$which_file") or die ("Cannot open $which_file");
       $temp_var=<spfile>;
       close spfile;
       @split_arr=split(/$split_val/,$temp_var);
       $new_file=$which_file.".split";
       open (newf,">$new_file") or die ("Cannot open $new_file");
       foreach  $split(@split_arr){
                print newf "$split\n";
       }
       close newf;
      }
  }

I execute it like so: ./law_split file_name "split value"
This is used on a UNIX box running IBM's AIX. Perl version 5.005_02 built for aix

I have few things here ....

1).

In the above ..... u do n't need "newf" at all ....

2)Also ... yr code assumes a file containing a single line.
your code does n't work for file having muliple lines.

3) Have these changes and run yr code again ...
i have no issues in getting the result.

chomp($which_file=@ARGV[0]);
chomp($split_val=@ARGV[1]);

This should read $ARGV[0] etc. instead. If you have the -w flag on, it will give you a warning. And I don't think you need a chomp() on command line arguments anyway.

Putting a pair of quotes around the value is required by the shell. You can probably workaround it by

$split_val = join(' ', @ARGV[1..(@ARGV-1)]);

to have Perl absorbs all command line parameters delimited by whitespace and glues them into a single string, but the reconstructed string may not be identical to the original string you intended to get. Who says that one space is always the delimiter? For instance by giving the following as command line arguments

a  b c

Note the two spaces between a and b, which are treated as one whitespace delimiter by the shell and the code above transforms it to (thus the value of $split_val)

a b c 

This arrangement is probably okay if the arguments are like a composite command, and whitespace is not significant. But literally, the string has been modified, and this is unlikely to be what you want.

So use the quotes to avoid such problems.

Thank you both for your responses. I will take a look at your suggestions and make the appropriate changes. As you can tell I am just learning how to work with Perl so your help is appreciated. Merry Christmas!

I actually prefer to pass arguments to Perl scripts using the -S option for perl. An example of a program which accepted and checked two arguments would look like this:

#! /bin/perl -s

# Check Arguments
if (!$input || !$char) {
print STDERR "Error: invalid arguments.\nUsage: script.pl -input=<file name> -char=<split char>\n";
exit(1);
}

...

Just how I prefer to do it.