Sponsored Content
Full Discussion: Perl strict
Top Forums Shell Programming and Scripting Perl strict Post 302276545 by spirtle on Wednesday 14th of January 2009 04:26:56 AM
Old 01-14-2009
The "strict" pragma makes it an error to use various potentially unsafe or confusing code constructs. Type man 3 strict to find out which ones. Unless you have a very good reason for using such constructs, you should use "use strict". If you have a good enough reason. you can locally override the restrictions with (e.g.)
Code:
no strict "subs";

because pragmata are lexically scoped.
 

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Strict Argument

Im trying to write a bash script that has an if statment that when the user enters ONLY that exact argument, will echo what follows that conditon. For example: for file in $1 do if then Var1=$(cat hello | egrep "that pattern" | awk '{ print $NF }') cat $Var1 fi done Basically,... (3 Replies)
Discussion started by: oxoxo
3 Replies

2. Shell Programming and Scripting

Passing date formats in Perl: i.e. Jul/10/2007 -> 20070710 (yyyymmdd) - Perl

Hi , This script working for fine if pass script-name.sh Jul/10/2007 ,I want to pass 20070710(yyyymmdd) .Please any help it should be appereciated. use Time::Local; my $d = $ARGV; my $t = $ARGV; my $m = ""; @d = split /\//, $d; @t = split /:/, $t; if ( $d eq "Jan" ) { $m = 0 }... (7 Replies)
Discussion started by: akil
7 Replies

3. Shell Programming and Scripting

New PERL guru's help on strict.pm

I opened strict.pm and found some not understandable stuff, please let me know if you have any Idea on the same. 1) Line 23 => $bits |= (what is $= here how it affect the statement) 2) Line 36 => $^H (what is that I haven't found any statement on this in google) 3) Line 41 =>... (3 Replies)
Discussion started by: jatanig
3 Replies

4. Shell Programming and Scripting

Perl :How to print the o/p of a Perl script on console and redirecting same in log file @ same time.

How can i print the output of a perl script on a unix console and redirect the same in a log file under same directory simultaneously ? Like in Shell script, we use tee, is there anything in Perl or any other option ? (2 Replies)
Discussion started by: butterfly20
2 Replies

5. UNIX for Advanced & Expert Users

perl and HP-UX : instmodsh in combination with software depot : update inventory for installed Perl

we create a HP-UX software depot with a new perl-modul. after installation of the software depot, the perl module i can't find with instmodsh in the inventory for installed Perl modules. - i have learned of using instmodsh command : i find out what modules are already installed on my system. ... (0 Replies)
Discussion started by: bora99
0 Replies

6. Shell Programming and Scripting

Help! Can't locate strict.pm after Cygwin update

I installed gcc4 today using setup.exe from cygwin. However, I cannot run any of my perl program after that. For example, Run@Run-THINK /home $ perl Process.pl Can't locate strict.pm in @INC (@INC contains: /usr/lib/perl5/5.10/i686-cygwin / usr/lib/perl5/5.10... (0 Replies)
Discussion started by: littledeer
0 Replies

7. UNIX for Advanced & Expert Users

Ssh disable strict checking

What are the different ways to disable ssh strict checking? I've seen this mentioned a few times but it doesn't seem to be working. $ ssh -o 'StrictHostKeyChecking no' admin@hostnamehttp://docs.oracle.com/cd/E35328_01/E35336/html/vmcli-ssh.html Is there a file somewhere in /etc that I could... (4 Replies)
Discussion started by: cokedude
4 Replies

8. Shell Programming and Scripting

Perl : Getopts and Strict -How to solve

How do I get past the error when using strict and GetOpts ? #!/usr/bin/perl use strict; use Getopt::Std; # Process the command line options die "Usage: $0 -r <router> -u <username> -p <password> -e <enable password>\n" if (@ARGV < 6); exit if (!getopts('r:u:p:e:')); my... (3 Replies)
Discussion started by: popeye
3 Replies

9. Programming

PERL: In a perl-scripttTrying to execute another perl-script that SETS SOME VARIABLES !

I have reviewed many examples on-line about running another process (either PERL or shell command or a program), but do not find any usefull for my needs way. (Reviewed and not useful the system(), 'back ticks', exec() and open()) I would like to run another PERL-script from first one, not... (1 Reply)
Discussion started by: alex_5161
1 Replies
PERLPRAGMA(1)						 Perl Programmers Reference Guide					     PERLPRAGMA(1)

NAME
perlpragma - how to write a user pragma DESCRIPTION
A pragma is a module which influences some aspect of the compile time or run time behaviour of Perl, such as "strict" or "warnings". With Perl 5.10 you are no longer limited to the built in pragmata; you can now create user pragmata that modify the behaviour of user functions within a lexical scope. A basic example For example, say you need to create a class implementing overloaded mathematical operators, and would like to provide your own pragma that functions much like "use integer;" You'd like this code use MyMaths; my $l = MyMaths->new(1.2); my $r = MyMaths->new(3.4); print "A: ", $l + $r, " "; use myint; print "B: ", $l + $r, " "; { no myint; print "C: ", $l + $r, " "; } print "D: ", $l + $r, " "; no myint; print "E: ", $l + $r, " "; to give the output A: 4.6 B: 4 C: 4.6 D: 4 E: 4.6 i.e., where "use myint;" is in effect, addition operations are forced to integer, whereas by default they are not, with the default behaviour being restored via "no myint;" The minimal implementation of the package "MyMaths" would be something like this: package MyMaths; use warnings; use strict; use myint(); use overload '+' => sub { my ($l, $r) = @_; # Pass 1 to check up one call level from here if (myint::in_effect(1)) { int($$l) + int($$r); } else { $$l + $$r; } }; sub new { my ($class, $value) = @_; bless $value, $class; } 1; Note how we load the user pragma "myint" with an empty list "()" to prevent its "import" being called. The interaction with the Perl compilation happens inside package "myint": package myint; use strict; use warnings; sub import { $^H{myint} = 1; } sub unimport { $^H{myint} = 0; } sub in_effect { my $level = shift // 0; my $hinthash = (caller($level))[10]; return $hinthash->{myint}; } 1; As pragmata are implemented as modules, like any other module, "use myint;" becomes BEGIN { require myint; myint->import(); } and "no myint;" is BEGIN { require myint; myint->unimport(); } Hence the "import" and "unimport" routines are called at compile time for the user's code. User pragmata store their state by writing to the magical hash "%^H", hence these two routines manipulate it. The state information in "%^H" is stored in the optree, and can be retrieved at runtime with "caller()", at index 10 of the list of returned results. In the example pragma, retrieval is encapsulated into the routine "in_effect()", which takes as parameter the number of call frames to go up to find the value of the pragma in the user's script. This uses "caller()" to determine the value of $^H{myint} when each line of the user's script was called, and therefore provide the correct semantics in the subroutine implementing the overloaded addition. Implementation details The optree is shared between threads. This means there is a possibility that the optree will outlive the particular thread (and therefore the interpreter instance) that created it, so true Perl scalars cannot be stored in the optree. Instead a compact form is used, which can only store values that are integers (signed and unsigned), strings or "undef" - references and floating point values are stringified. If you need to store multiple values or complex structures, you should serialise them, for example with "pack". The deletion of a hash key from "%^H" is recorded, and as ever can be distinguished from the existence of a key with value "undef" with "exists". Don't attempt to store references to data structures as integers which are retrieved via "caller" and converted back, as this will not be threadsafe. Accesses would be to the structure without locking (which is not safe for Perl's scalars), and either the structure has to leak, or it has to be freed when its creating thread terminates, which may be before the optree referencing it is deleted, if other threads outlive it. perl v5.12.1 2010-04-26 PERLPRAGMA(1)
All times are GMT -4. The time now is 04:47 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy