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

I am trying to set the following variables but running into syntax errors.Can anyone advise the correct syntax;

$options{v} =~s/\/\.\.\.//; my $optv_modem= $options{v}"/modem/..."; print "\n$optv_modem\n"; my $optv_apps=$options{v}"/apps/..."; print "\n$optv_apps\n";

Replies are listed 'Best First'.
Re: Syntax errors in setting path..
by Khen1950fx (Canon) on Mar 12, 2011 at 07:28 UTC
    Use concatenation...
    #!/usr/bin/perl use strict; my %options; $options{'v'} =~s/\/\.\.\.//; my $optv_modem = $options{'v'} . "/modem/..."; print "\n$optv_modem\n"; my $optv_apps = $options{'v'} . "/apps/..."; print "\n$optv_apps\n";
      Thanks.Also I just want to use 'msm' as an option,no value should be entered for it,how do I make sure that option msm is given but there should be no value.Will the following work?how to make the options case-insensitive?Thanks
      use Getopt::Long; #Getting the command-line options my %options = (); GetOptions (\%options,'msm','des=s', 'a=s', 'd=s', 'r=i', 'v=s'); if($options(msm)){....}
        Make msm a flag...
        #!/usr/bin/perl use strict; use warnings; use Getopt::Long; my $string = 'string'; my $length = 'length'; my $msm = 'msm'; my $result = GetOptions ('des=s' => \$string, 'a=s' => \$string, 'd=s' => \$string, 'r=i' => \$length, 'v=s' => \$string, 'msm' => \$msm);
        Or simply my $msm;
      Thanks.Also I just want to use 'msm' as an option,no value should be entered for it,how do I make sure that option msm is given but there should be no value.Will the following work?how to make the options case-insensitive?Thanks Update:Ignore the query but i would like to know how to I stop on an unknown option given?
      use Getopt::Long; #Getting the command-line options my %options = (); GetOptions (\%options,'msm','des=s', 'a=s', 'd=s', 'r=i', 'v=s'); if($options(msm)){....}
      Thanks.Also i would like to know how to I stop on an unknown option given?
      use Getopt::Long; #Getting the command-line options my %options = (); GetOptions (\%options,'msm','des=s', 'a=s', 'd=s', 'r=i', 'v=s'); if($options(msm)){....}
        GetOptions displays an error message and returns false when it encounters an unrecognised option.

      ... or interpolation.

      >perl -wMstrict -le "my %options = qw(v foo/...); $options{'v'} =~ s{ /\.\.\. }{}xms; my $optv_modem = qq{$options{'v'}/modem/...}; print qq{'$optv_modem'}; " 'foo/modem/...'