escape characters within command line arguments 
Author Message
 escape characters within command line arguments

I'd like to create a script which allows me to pass command
line arguments which contain escape characters, e.g. /n/r/t.

I've tried a few things, but can't figure out a way to make it work.

A sample script is below.  I'd like to be able to call it via:

perl script.pl -B'\t'

in order to begin each line with a TAB.

What I actually get as output is a '\t' instead of a TAB at the beginning
of the line.  The defaults for $opt_F and $opt_E work fine, but again
if I specify them on the command line, I get the literal values.

Thanks in advance...

-- BEGIN SCRIPT --
require 'getopt.pl';

{
do Getopt('FBE');

$opt_F = "\t" unless $opt_F;
$opt_E = "\n" unless $opt_E;


Quote:
}

-- END SCRIPT
--

Bill Nixon, Systems Integration Services, MORNETPlus Systems Management
Fannie Mae, 3900 Wisconsin Ave NW, 4H-5S-03, Washington, DC 22016


Sat, 26 Jul 1997 08:58:46 GMT  
 escape characters within command line arguments

Quote:
>I'd like to create a script which allows me to pass command
>line arguments which contain escape characters, e.g. /n/r/t.
>I've tried a few things, but can't figure out a way to make it work.
>A sample script is below.  I'd like to be able to call it via:
>perl script.pl -B'\t'
>in order to begin each line with a TAB.
>What I actually get as output is a '\t' instead of a TAB at the beginning
>of the line.  The defaults for $opt_F and $opt_E work fine, but again
>if I specify them on the command line, I get the literal values.
>Thanks in advance...
>-- BEGIN SCRIPT --
>require 'getopt.pl';
>{
>do Getopt('FBE');

perl5 -w is unhappy with this syntax and prefers &Getopt('FBE');

To do the transformation you asked for, add

  $opt_B = eval "qq\001$opt_B\001";

--
Hope this helps,

HansM



Tue, 29 Jul 1997 04:40:21 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Escaping Characters in Command Line Substitution

2. Command line script - how to escape !

3. escape single quotes on command line?

4. shell escaping and command line options

5. Escaping a $ within a variable within a grep...

6. Help! with command line arguments

7. running perl at command line with arguments: script.cgi?text=text

8. Command line arguments.

9. Simple reordering of command line arguments.

10. Command line arguments?

11. Passing form values back to a script as command line arguments

12. How to set varible from command line argument??

 

 
Powered by phpBB® Forum Software