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

Dear monks,

I have a small perl script, myscript.pl called by a c program via the system command with command line arguments, as follows:

myscript.pl set <variable_name> <variable_value>

The code of myscript.pl is very basic, as follows:
#!/usr/bin/perl use warnings; use strict; my ($command, $pathname, $value); $command = shift @ARGV; $pathname = shift @ARGV; if (defined $pathname and $pathname ne '') { if (($command eq "set") or ($command eq "add") or ($command eq +"del")) { $value = shift @ARGV; } else ..... } ...
I found that if <variable_value> is a string starting with a hash (#), then $value remains undefined. If I enclose the string in "", then $value is properly defined. However, I do not have (easy) access to the c program that calls myscript.pl.

Is there another way to solve this?

Cheers,
Athanasia

Update : Thanks to all who responded to my query. All suggested solutions helped me address the issue in one way or another.

Replies are listed 'Best First'.
Re: Capture string that starts with #
by johngg (Canon) on Dec 04, 2008 at 10:00 UTC

    Not addressing your problem but you could save some typing when testing your $command.

    ... if ( $command =~ m{^(?:set|add|del)$} ) { ...

    I hope this is of interest.

    Cheers,

    JohnGG

Re: Capture string that starts with #
by Anonymous Monk on Dec 04, 2008 at 09:32 UTC
    It has nothing to do with myscript.pl and everything to do with calling program, be it the shell or some c program.
Re: Capture string that starts with #
by lakshmananindia (Chaplain) on Dec 04, 2008 at 11:11 UTC
    If you are using bash then set -f is used to disable the expansion of metacharacter.
Re: Capture string that starts with #
by viji_india (Initiate) on Dec 04, 2008 at 11:12 UTC
    We can call system() in the following way:
    system("myscript.pl set a \\#value");