Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi, i am trying to write a scipt so that the value of $ARGV[2] can be a user specified number from the command line, e.g $ARGV[2] = 150. My problem is that when i specify this from the command line it just says "150 -no such file or directory". where am i going wrong??
#! /usr/local/bin/perl -w use strict; my $num_of_params; $num_of_params = @ARGV; if ($num_of_params < 3) { die ("\n Not enough parameters have been entered!!!!\n"); } open (INPUT, $ARGV[0]) or die "unable to open file, perl says $!"; open (OUTFILE, ">$ARGV[1]"); my $count = 1; my $line; my $limit = $ARGV[2]; while (<>) { chomp; $line = $_; $line =~ s/(.{60})/$1\n/g; if (/>/) { ++$count; } print "\>$count\n", $line , "\n\n" if length $_ >= $limi t; print OUTFILE "\>$count\n", $line, "\n\n" if length $_ > = $limit; } close INPUT; close OUTFILE;
thanks all advice appreciated.

Edit kudra, 2002-05-17 Put in &#091; and &#093; to replace literals in arrays out of code context

Replies are listed 'Best First'.
Re: specifying numeric values for scalar variables with $ARGV
by Biker (Priest) on May 17, 2002 at 10:15 UTC

    You still have the same problem(s) in your code as when you first asked the question here. Didn't you read the answers to the question last time?

    Update: Someone proposed in the CB that it may be homework, and that you're in the same class as the person who asked the question I referred to in my link above. If this should be true, then you should be very much ashamed. For two obvious reasons:

    1. By letting other people solve your homework problems, you're cheating in class.
    2. You're showing disrespect to people that sincerely want to help people with real life Perl problems.

    I sincerely hope that you just were too lazy to read the answers from your first question. Please, convince us that this is so.
    Everything went worng, just as foreseen.

Re: specifying numeric values for scalar variables with $ARGV
by Dog and Pony (Priest) on May 17, 2002 at 12:15 UTC
    Use:
    while (<INPUT>)
    instead of
    while (<>)
    <> is in this case the same as <ARGV> - and you know what is in there, yes? :)
    You have moved into a dark place.
    It is pitch black. You are likely to be eaten by a grue.
Re: specifying numeric values for scalar variables with $ARGV
by rinceWind (Monsignor) on May 17, 2002 at 09:49 UTC
    Hi there,

    More information is required: Which operating system (and shell) are you running?

    The expansion of wildcards on filename parameters (called globbing) happens outside the Perl script. This is something done by the Unix shell, and is emulated by the operating system specific perl wrapper if the O/S does not do globbing. For example, on VMS the globbing is done by the C runtime library before argv gets passed to perl.

    Also, what command line are you passing? Normally shells don't glob if there are no wildcards present.

    Update: On second thoughts, it looks as if your number is being picked up by $ARGV[0]. The globbing stuff might be a red herring.

    What order are you intending to supply arguments?