Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

in-code checking of perl switches

Is there any way to check whitch of perl command line switches have been activated ? For instance if I run my program like perl -C foo.pl, I would like to be able to check whether the -C switch has been activated or not. Any help would be greatly appreciated.

like image 408
Pierre Avatar asked May 24 '12 06:05

Pierre


People also ask

How does the switch statement work in Perl?

The switch statement takes a single scalar argument of any type, specified in parentheses. The value is followed by a block, which may contain one or more case statement followed by a block of Perl statement (s).

How does Perl program work?

Almost every Perl program starts out like this: This is a UNIX construct, which tells a shell that executes the file directly what program to pass the rest of the input to. You can add any of Perl's command line switches to this line, and they will be treated as if they were part of the command line after the switches provided there.

What is the difference between-N and-P in Perl?

Perl's -n switch allows you to run a program (usually specified with -e) against every line on standard input. These are equivalent: ... ... The -p switch is the same as -n, except that it prints whatever is in $_ after every line. If you combine the -i switch, Perl will edit your file in place.

How to debug Perl code at the command line?

Quickly Debug your Perl code at the command line 1 One liner basics. Perl has a ton of command line switches (see perldoc perlrun ), but I’m just going to cover the ones you’ll commonly need to debug code. 2 V is for version. ... 3 Load modules with M. ... 4 Turn on warnings with w. ... 5 Use I to include directories. ... 6 Wrap-up. ...


1 Answers

From the perlrun manpage:

The -C flag controls some of the Perl Unicode features.... The read-only magic variable ${^UNICODE} reflects the numeric value of this setting. This variable is set during Perl startup and is thereafter read-only.

There are other magic variables for some other commandline switches. Either perlrun or perlvar should have the information you seek.

like image 75
friedo Avatar answered Oct 04 '22 04:10

friedo