Re: perl -s and use strict



On 3/29/07, Sarthak Patnaik <sarthak.patnaik@xxxxxxxxxxx> wrote:
snip
Is there any workaround for this, so that I can use strict and -s together.
snip

Short answer: yes, the vars pragma

#!/usr/bin/perl -ws

use strict;
use vars qw($k);

print "$k\n"

Long answer: It is however a bad idea. -s does not do what you think
it does. It looks like what you want is the Getopt::Std module:

#!/usr/bin/perl

use warnings;
use strict;
use Getopt::Std;

my %opts;
getopt('k:', \%opts);

my $k = exists $opts{k} ? $opts{k} : "Default";

print "$k\n";
.



Relevant Pages

  • Re: perl -s and use strict
    ... snip> Is there any workaround for this, so that I can use strict and -s together. ... The vars pragma has been depreciated for about a decade. ...
    (perl.beginners)
  • Re: Please explain @{$y}
    ... from perldoc strict ... This generates a runtime error if you use symbolic references ... 'compile-time error' and 'runtime error' qualifications are at the start ...
    (perl.beginners)
  • Re: Web standards: smaller filesize?
    ... I'm trying to move from 4.01 Transitional to XHTML 1.0 ... Judge for yourself, www.High.St - all hand written on RISCOS, feedback ... I think that technically I could go to 1.0 Strict quite easily but one ...
    (comp.sys.acorn.misc)
  • Re: out of memory problem
    ... use strict; ... variable in the error message so you know *why* it ... foreach my $dir { ...
    (perl.beginners)
  • Re: How to extract the HTML tag?
    ... snip> And it should handle other rare cases, ... And right there you showed why regexes are not good for parsing HTML ... use strict; ... use warnings; ...
    (perl.beginners)