0

I have a simple script where I want the user to be able to specify the separator:

#!/usr/bin/perl
use strict;
use warnings;
use Getopt::Long;
my $sep = "&";
GetOptions('sep:s' => \$sep);
my @list = ('a','b','c');
print join($sep,@list);
print "\n";

But if I don't seem to find the way to pass "\t" and be evaluated as a tab in the script:

perl ~/perl_tests/sep.pl -sep \t
perl ~/perl_tests/sep.pl -sep \\t
perl ~/perl_tests/sep.pl -sep '\t'
perl ~/perl_tests/sep.pl -sep '\\t'
perl ~/perl_tests/sep.pl -sep "\t"
perl ~/perl_tests/sep.pl -sep "\\t"

Neither produces my desired output, which is the values separated by tabs in the command-line result.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
719016
  • 9,922
  • 20
  • 85
  • 158

1 Answers1

2

this is really a shell question as you are calling the perl script from a shell

In bash, this works

perl sep.py -sep $'\t'

Also using ctrl v followed by pressing tab and putting that in double quotes works

Vorsprung
  • 32,923
  • 5
  • 39
  • 63