Re: Perl invocations

2017-10-29 Thread Chas. Owens
Shawn Corey misstated the issue, it isn't that -w can't be turned off, the
problem is that it is turned on globally rather than lexically. That is, it
forces warnings onto modules that may have been designed to not use
warnings:

$ cat T.pm
package T;

sub foo {
my $x = shift;
# undef or string is perfectly cromulant here
return $x + 1;
}

1;
$ cat t.pl
#!/usr/bin/perl

use strict;
use warnings;

use T;

print T::foo, "\n";
$ perl t.pl
1
$ perl -w t.pl
Use of uninitialized value $x in addition (+) at T.pm line 6.
1




On Sun, Oct 29, 2017 at 7:29 PM John W. Krahn  wrote:

> On Sun, 2017-07-02 at 11:16 -0400, Shawn H Corey wrote:
> > On Sun, 2 Jul 2017 14:29:25 +0200
> > Eric de Hont  wrote:
> >
> > > What it boils down to: use warnings as well as -w works, but -w is
> > > considered old fashioned.
> >
> > The problem with -w is that it can't be turned off.
>
> $ perl -le'
> use warnings;
> my $x;
> {   no warnings;
> print $x;
> }
> print $x;
> '
>
> Use of uninitialized value $x in print at -e line 7.
>
> $ perl -wle'
> my $x;
> {   local $^W = 0;
> print $x;
> }
> print $x;
> '
>
> Use of uninitialized value $x in print at -e line 6.
>
> --
> To unsubscribe, e-mail: beginners-unsubscr...@perl.org
> For additional commands, e-mail: beginners-h...@perl.org
> http://learn.perl.org/
>
>
>


Re: Perl invocations

2017-10-29 Thread John W. Krahn
On Sun, 2017-07-02 at 11:16 -0400, Shawn H Corey wrote:
> On Sun, 2 Jul 2017 14:29:25 +0200
> Eric de Hont  wrote:
> 
> > What it boils down to: use warnings as well as -w works, but -w is 
> > considered old fashioned.
> 
> The problem with -w is that it can't be turned off.

$ perl -le'
use warnings;
my $x;
{   no warnings;
print $x;
}
print $x;
'

Use of uninitialized value $x in print at -e line 7.

$ perl -wle'
my $x;
{   local $^W = 0;
print $x;
}
print $x;
'

Use of uninitialized value $x in print at -e line 6.

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Perl invocations

2017-07-02 Thread Eric de Hont

Op 02-07-17 om 17:16 schreef Shawn H Corey:


On Sun, 2 Jul 2017 14:29:25 +0200
Eric de Hont  wrote:


What it boils down to: use warnings as well as -w works, but -w is
considered old fashioned.

The problem with -w is that it can't be turned off. Sometimes a module
has to do something dangerous and having a warning appear is annoying
at best and can cause worry and stress in a programmer. `use
warnings;` can be turned off:

{
 no warnings;
 # do something dangerous
}
# end of scope restores warnings to the previous value `use` or `no`

Thanks! Didn't know that.

--
Eric de Hont

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Perl invocations

2017-07-02 Thread Shawn H Corey
On Sun, 2 Jul 2017 14:29:25 +0200
Eric de Hont  wrote:

> What it boils down to: use warnings as well as -w works, but -w is 
> considered old fashioned.

The problem with -w is that it can't be turned off. Sometimes a module
has to do something dangerous and having a warning appear is annoying
at best and can cause worry and stress in a programmer. `use
warnings;` can be turned off:

{
no warnings;
# do something dangerous
}
# end of scope restores warnings to the previous value `use` or `no`

> 
> A space in the perlbang (shebang) line is not perls problem but your 
> shell's. I would NOT use a space.
> If your shell doesn't choke on such a space: lucky you.

A space after the shebang tells the C-shell csh(1) not to interpret the
script as a C-shell script. Other shells, like bash(1) and the POSIX
sh(1) ignore the space but the Bourne shell may not.


-- 
Don't stop where the ink does.

Shawn H Corey

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Perl invocations

2017-07-02 Thread Lars Noodén
On 07/02/2017 03:29 PM, Eric de Hont wrote:
[snip]
> Apart from the perldocs also have a look at https://perlmaven.com/hashbang
[snip]

Thanks.   That was a good link.

perlintro(1) was good to review but the perlmaven link went into some
nice depth.  They say opposite things about using '#!/usr/bin/env perl'
in a production environment though.  But overall, it answers the
questions I had.

Regards
Lars

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Perl invocations

2017-07-02 Thread Eric de Hont

Op 02-07-17 om 10:52 schreef Lars Noodén:

I've grepped the first lines of a large project's source files for
instances of the string perl as a word.  Sorted, ranked, and slightly
edited, the results can be seen below.  What I am wondering is that can
anything general, independent of context be said about the invocations?

For example, is the 'use warnings;' pragma better than launching with
-w?  Same for launching perl via '#!/usr/bin/env perl' rather than
'#!/usr/bin/perl' instead?  What about a leading whitespace like with
'#! /usr/bin/perl' instead of '#!/usr/bin/perl' ?

Regards,
Lars

  493 #!/usr/bin/perl -w
  492 #!./perl
  288 #!/usr/bin/perl
  166 #!./perl -w


8<

Hi Lars,

(My excuses for answering off list, I clicked the wrong button...)

Lots of questions are answered in the documentation that comes with Perl.

When you type 'perldoc perlintro' the third paragraph 'Running Perl 
programs' instructs you how

to invoke perl in a script.

It also points you to 'perldoc perlrun' for in depth information on the 
subject.


What it boils down to: use warnings as well as -w works, but -w is 
considered old fashioned.


A space in the perlbang (shebang) line is not perls problem but your 
shell's. I would NOT use a space.

If your shell doesn't choke on such a space: lucky you.

When you have only one Perl, #!/usr/bin/env perl and #!/usr/bin/perl 
have the same effect.


However, when you use perlbrew, which I recommend for development 
purposes, you should use
#!/usr/bin/env. In production using env is considered dangerous by some, 
because you have less

controll over which Perl is invoked.

Apart from the perldocs also have a look at https://perlmaven.com/hashbang

A great source of information for beginners.

Greetings,
Eric de Hont

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/