Domanda

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.

È stato utile?

Soluzione

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

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top