himanshu.padmanabhi has asked for the wisdom of the Perl Monks concerning the following question:

This is regarding my thread. Replace number by args<number>. http://www.perlmonks.org/?node_id=751951
$cmd =~ s/([0-9])/args$1/g;
This solution is working well.But a small chance here,I wanted actually like this,
$in{'cmd'} =~ s/([0-9])/$in{args$1}/g;
I am getting error here as,
Can't call method "args" without a package or object reference at /usr +/file1.cgi line 399.
What should I do?

Replies are listed 'Best First'.
Re: Can't call method "args" without a package or object reference
by Corion (Patriarch) on Apr 08, 2009 at 07:34 UTC

    When Perl sees

    args$1

    it interprets that as:

    args($1)

    that is, a function call. You want to have args$1 as a string and to use it as a hash lookup. This means you have to quote it:

    "args$1"
      it interprets that as:
      args($1)

      I think it's rather seeing it as args $1 (indirect method call, like in args SomePkgOrObj). With args($1), it should complain Undefined subroutine &main::args called at...
      </nitpick>

      Thank you very much. It is solved.
Re: Can't call method "args" without a package or object reference
by himanshu.padmanabhi (Acolyte) on Apr 08, 2009 at 07:21 UTC
    $in{'cmd'} are in this type,
    1. -p 1 -t 2 3 2. 1:2 3. --name 1 --limit 2
    I want it to change to,
    1. -p $in{'args1'} -t $in{'args2'} $in{'args3'} 2. $in{'args1'}:$in{'args2'} 3. --name $in{'args1'} --limit $in{'args2'}