P e r l d o c B r o w s e r
●
5 . 0 0 5 _ 0 3
L a t e s t
5 . 4 0 . 0
5 . 3 8 . 2
5 . 3 8 . 1
5 . 3 8 . 0
5 . 3 6 . 3
5 . 3 6 . 2
5 . 3 6 . 1
5 . 3 6 . 0
5 . 3 4 . 3
5 . 3 4 . 2
5 . 3 4 . 1
5 . 3 4 . 0
5 . 3 2 . 1
5 . 3 2 . 0
5 . 3 0 . 3
5 . 3 0 . 2
5 . 3 0 . 1
5 . 3 0 . 0
5 . 2 8 . 3
5 . 2 8 . 2
5 . 2 8 . 1
5 . 2 8 . 0
5 . 2 6 . 3
5 . 2 6 . 2
5 . 2 6 . 1
5 . 2 6 . 0
5 . 2 4 . 4
5 . 2 4 . 3
5 . 2 4 . 2
5 . 2 4 . 1
5 . 2 4 . 0
5 . 2 2 . 4
5 . 2 2 . 3
5 . 2 2 . 2
5 . 2 2 . 1
5 . 2 2 . 0
5 . 2 0 . 3
5 . 2 0 . 2
5 . 2 0 . 1
5 . 2 0 . 0
5 . 1 8 . 4
5 . 1 8 . 3
5 . 1 8 . 2
5 . 1 8 . 1
5 . 1 8 . 0
5 . 1 6 . 3
5 . 1 6 . 2
5 . 1 6 . 1
5 . 1 6 . 0
5 . 1 4 . 4
5 . 1 4 . 3
5 . 1 4 . 2
5 . 1 4 . 1
5 . 1 4 . 0
5 . 1 2 . 5
5 . 1 2 . 4
5 . 1 2 . 3
5 . 1 2 . 2
5 . 1 2 . 1
5 . 1 2 . 0
5 . 1 0 . 1
5 . 1 0 . 0
5 . 8 . 9
5 . 8 . 8
5 . 8 . 7
5 . 8 . 6
5 . 8 . 5
5 . 8 . 4
5 . 8 . 3
5 . 8 . 2
5 . 8 . 1
5 . 8 . 0
5 . 6 . 2
5 . 6 . 1
5 . 6 . 0
5 . 0 0 5 _ 0 4
5 . 0 0 5 _ 0 3
5 . 0 0 5 _ 0 2
5 . 0 0 5 _ 0 1
5 . 0 0 5
●
D e v
b l e a d
5 . 4 1 . 2
5 . 4 1 . 1
5 . 4 0 . 0 - R C 2
5 . 4 0 . 0 - R C 1
5 . 3 9 . 1 0
5 . 3 9 . 9
5 . 3 9 . 8
5 . 3 9 . 6
5 . 3 9 . 5
5 . 3 9 . 4
5 . 3 9 . 3
5 . 3 9 . 2
5 . 3 9 . 1
5 . 3 7 . 1 1
5 . 3 7 . 1 0
5 . 3 7 . 9
5 . 3 7 . 8
5 . 3 7 . 7
5 . 3 7 . 6
5 . 3 7 . 5
5 . 3 7 . 4
5 . 3 7 . 3
5 . 3 7 . 2
5 . 3 7 . 1
5 . 3 7 . 0
●
D o c u m e n t a t i o n
P e r l
I n t r o
T u t o r i a l s
F A Q s
R e f e r e n c e
O p e r a t o r s
F u n c t i o n s
V a r i a b l e s
M o d u l e s
U t i l i t i e s
C o m m u n i t y
H i s t o r y
E x p a n d
p e r l r u n
( s o u r c e ,
C P A N )
Y o u a r e v i e w i n g t h e v e r s i o n o f t h i s d o c u m e n t a t i o n f r o m P e r l 5 . 0 0 5 _ 0 3 .
V i e w t h e l a t e s t v e r s i o n
●
N A M E
●
S Y N O P S I S
●
D E S C R I P T I O N
●
# ! a n d q u o t i n g o n n o n - U n i x s y s t e m s
●
L o c a t i o n o f P e r l
●
S w i t c h e s
●
E N V I R O N M E N T
# N A M E
p e r l r u n - h o w t o e x e c u t e t h e P e r l i n t e r p r e t e r
# S Y N O P S I S
p e r l [ - s T u U ] [ - h v ] [ - V [ : c o n f i g v a r ] ] [ - c w ] [ - d [ : d e b u g g e r ] ] [ - D [ n u m b e r / l i s t ] ] [ - p n a ] [ - F p a t t e r n ] [ - l [ o c t a l ] ] [ - 0 [ o c t a l ] ] [ - I d i r ] [ - m [ - ] m o d u l e ] [ - M [ - ] ' m o d u l e . . . ' ] [ - P ] [ - S ] [ - x [ d i r ] ] [ - i [ e x t e n s i o n ] ] [ - e ' c o m m a n d ' ] [ - - ] [ p r o g r a m f i l e ] [ a r g u m e n t ] . . .
# D E S C R I P T I O N
U p o n s t a r t u p , P e r l l o o k s f o r y o u r s c r i p t i n o n e o f t h e f o l l o w i n g p l a c e s :
S p e c i f i e d l i n e b y l i n e v i a - e s w i t c h e s o n t h e c o m m a n d l i n e .
C o n t a i n e d i n t h e f i l e s p e c i f i e d b y t h e f i r s t f i l e n a m e o n t h e c o m m a n d l i n e . ( N o t e t h a t s y s t e m s s u p p o r t i n g t h e # ! n o t a t i o n i n v o k e i n t e r p r e t e r s t h i s w a y . S e e " L o c a t i o n o f P e r l " . )
P a s s e d i n i m p l i c i t l y v i a s t a n d a r d i n p u t . T h i s w o r k s o n l y i f t h e r e a r e n o f i l e n a m e a r g u m e n t s - - t o p a s s a r g u m e n t s t o a S T D I N s c r i p t y o u m u s t e x p l i c i t l y s p e c i f y a " - " f o r t h e s c r i p t n a m e .
W i t h m e t h o d s 2 a n d 3 , P e r l s t a r t s p a r s i n g t h e i n p u t f i l e f r o m t h e b e g i n n i n g , u n l e s s y o u ' v e s p e c i f i e d a - x s w i t c h , i n w h i c h c a s e i t s c a n s f o r t h e f i r s t l i n e s t a r t i n g w i t h # ! a n d c o n t a i n i n g t h e w o r d " p e r l " , a n d s t a r t s t h e r e i n s t e a d . T h i s i s u s e f u l f o r r u n n i n g a s c r i p t e m b e d d e d i n a l a r g e r m e s s a g e . ( I n t h i s c a s e y o u w o u l d i n d i c a t e t h e e n d o f t h e s c r i p t u s i n g t h e _ _ E N D _ _
t o k e n . )
T h e # ! l i n e i s a l w a y s e x a m i n e d f o r s w i t c h e s a s t h e l i n e i s b e i n g p a r s e d . T h u s , i f y o u ' r e o n a m a c h i n e t h a t a l l o w s o n l y o n e a r g u m e n t w i t h t h e # ! l i n e , o r w o r s e , d o e s n ' t e v e n r e c o g n i z e t h e # ! l i n e , y o u s t i l l c a n g e t c o n s i s t e n t s w i t c h b e h a v i o r r e g a r d l e s s o f h o w P e r l w a s i n v o k e d , e v e n i f - x w a s u s e d t o f i n d t h e b e g i n n i n g o f t h e s c r i p t .
B e c a u s e m a n y o p e r a t i n g s y s t e m s s i l e n t l y c h o p o f f k e r n e l i n t e r p r e t a t i o n o f t h e # ! l i n e a f t e r 3 2 c h a r a c t e r s , s o m e s w i t c h e s m a y b e p a s s e d i n o n t h e c o m m a n d l i n e , a n d s o m e m a y n o t ; y o u c o u l d e v e n g e t a " - " w i t h o u t i t s l e t t e r , i f y o u ' r e n o t c a r e f u l . Y o u p r o b a b l y w a n t t o m a k e s u r e t h a t a l l y o u r s w i t c h e s f a l l e i t h e r b e f o r e o r a f t e r t h a t 3 2 c h a r a c t e r b o u n d a r y . M o s t s w i t c h e s d o n ' t a c t u a l l y c a r e i f t h e y ' r e p r o c e s s e d r e d u n d a n t l y , b u t g e t t i n g a - i n s t e a d o f a c o m p l e t e s w i t c h c o u l d c a u s e P e r l t o t r y t o e x e c u t e s t a n d a r d i n p u t i n s t e a d o f y o u r s c r i p t . A n d a p a r t i a l - I s w i t c h c o u l d a l s o c a u s e o d d r e s u l t s .
S o m e s w i t c h e s d o c a r e i f t h e y a r e p r o c e s s e d t w i c e , f o r i n s t a n c e c o m b i n a t i o n s o f - l a n d - 0 . E i t h e r p u t a l l t h e s w i t c h e s a f t e r t h e 3 2 c h a r a c t e r b o u n d a r y ( i f a p p l i c a b l e ) , o r r e p l a c e t h e u s e o f - 0 d i g i t s by B E G I N { $ / = " \ 0 d i g i t s " ; }
.
P a r s i n g o f t h e # ! s w i t c h e s s t a r t s w h e r e v e r " p e r l " i s m e n t i o n e d i n t h e l i n e . T h e s e q u e n c e s " - * " a n d " - " a r e s p e c i f i c a l l y i g n o r e d s o t h a t y o u c o u l d , i f y o u w e r e s o i n c l i n e d , s a y
#!/bin/sh -- # -*- perl -*- -p
eval 'exec /usr/bin/perl -wS $0 ${1+"$@"}'
if $running_under_some_shell;
t o l e t P e r l s e e t h e - p s w i t c h .
I f t h e # ! l i n e d o e s n o t c o n t a i n t h e w o r d " p e r l " , t h e p r o g r a m n a m e d a f t e r t h e # ! i s e x e c u t e d i n s t e a d o f t h e P e r l i n t e r p r e t e r . T h i s i s s l i g h t l y b i z a r r e , b u t i t h e l p s p e o p l e o n m a c h i n e s t h a t d o n ' t d o # ! , b e c a u s e t h e y c a n t e l l a p r o g r a m t h a t t h e i r S H E L L i s / u s r / b i n / p e r l , a n d P e r l w i l l t h e n d i s p a t c h t h e p r o g r a m t o t h e c o r r e c t i n t e r p r e t e r f o r t h e m .
A f t e r l o c a t i n g y o u r s c r i p t , P e r l c o m p i l e s t h e e n t i r e s c r i p t t o a n i n t e r n a l f o r m . I f t h e r e a r e a n y c o m p i l a t i o n e r r o r s , e x e c u t i o n o f t h e s c r i p t i s n o t a t t e m p t e d . ( T h i s i s u n l i k e t h e t y p i c a l s h e l l s c r i p t , w h i c h m i g h t r u n p a r t - w a y t h r o u g h b e f o r e f i n d i n g a s y n t a x e r r o r . )
I f t h e s c r i p t i s s y n t a c t i c a l l y c o r r e c t , i t i s e x e c u t e d . I f t h e s c r i p t r u n s o f f t h e e n d w i t h o u t h i t t i n g a n e x i t ( ) o r d i e ( ) o p e r a t o r , a n i m p l i c i t e x i t ( 0 )
i s p r o v i d e d t o i n d i c a t e s u c c e s s f u l c o m p l e t i o n .
# # ! a n d q u o t i n g o n n o n - U n i x s y s t e m s
U n i x ' s # ! t e c h n i q u e c a n b e s i m u l a t e d o n o t h e r s y s t e m s :
# O S / 2
P u t
extproc perl -S -your_switches
a s t h e f i r s t l i n e i n * . c m d
f i l e ( - S
d u e t o a b u g i n c m d . e x e ' s ` e x t p r o c ' h a n d l i n g ) .
# M S - D O S
C r e a t e a b a t c h f i l e t o r u n y o u r s c r i p t , a n d c o d i f y i t i n A L T E R
N A T I V E _ S H E B A N G
( s e e t h e d o s i s h . h f i l e i n t h e s o u r c e d i s t r i b u t i o n f o r m o r e i n f o r m a t i o n ) .
# W i n 9 5 / N T
T h e W i n 9 5 / N T i n s t a l l a t i o n , w h e n u s i n g t h e A c t i v e w a r e p o r t o f P e r l , w i l l m o d i f y t h e R e g i s t r y t o a s s o c i a t e t h e . p l e x t e n s i o n w i t h t h e p e r l i n t e r p r e t e r . I f y o u i n s t a l l a n o t h e r p o r t o f P e r l , i n c l u d i n g t h e o n e i n t h e W i n 3 2 d i r e c t o r y o f t h e P e r l d i s t r i b u t i o n , t h e n y o u ' l l h a v e t o m o d i f y t h e R e g i s t r y y o u r s e l f . N o t e t h a t t h i s m e a n s y o u c a n n o l o n g e r t e l l t h e d i f f e r e n c e b e t w e e n a n e x e c u t a b l e P e r l p r o g r a m a n d a P e r l l i b r a r y f i l e .
# M a c i n t o s h
M a c i n t o s h p e r l s c r i p t s w i l l h a v e t h e a p p r o p r i a t e C r e a t o r a n d T y p e , s o t h a t d o u b l e - c l i c k i n g t h e m w i l l i n v o k e t h e p e r l a p p l i c a t i o n .
# V M S
P u t
$ perl -mysw 'f$env("procedure")' 'p1' 'p2' 'p3' 'p4' 'p5' 'p6' 'p7' 'p8' !
$ exit++ + ++$status != 0 and $exit = $status = undef;
a t t h e t o p o f y o u r s c r i p t , w h e r e - m y s w
a r e a n y c o m m a n d l i n e s w i t c h e s y o u w a n t t o p a s s t o P e r l . Y o u c a n n o w i n v o k e t h e s c r i p t d i r e c t l y , b y s a y i n g p e r l s c r i p t
, o r a s a D C L p r o c e d u r e , b y s a y i n g @ s c r i p t
( o r i m p l i c i t l y v i a D C L $ P A T H b y j u s t u s i n g t h e n a m e o f t h e s c r i p t ) .
T h i s i n c a n t a t i o n i s a b i t m u c h t o r e m e m b e r , b u t P e r l w i l l d i s p l a y i t f o r y o u i f y o u s a y p e r l
" - V : s t a r t p e r l "
.
C o m m a n d - i n t e r p r e t e r s o n n o n - U n i x s y s t e m s h a v e r a t h e r d i f f e r e n t i d e a s o n q u o t i n g t h a n U n i x s h e l l s . Y o u ' l l n e e d t o l e a r n t h e s p e c i a l c h a r a c t e r s i n y o u r c o m m a n d - i n t e r p r e t e r ( *
, \
a n d "
a r e c o m m o n ) a n d h o w t o p r o t e c t w h i t e s p a c e a n d t h e s e c h a r a c t e r s t o r u n o n e - l i n e r s ( s e e - e
b e l o w ) .
O n s o m e s y s t e m s , y o u m a y h a v e t o c h a n g e s i n g l e - q u o t e s t o d o u b l e o n e s , w h i c h y o u m u s t N O T d o o n U n i x o r P l a n 9 s y s t e m s . Y o u m i g h t a l s o h a v e t o c h a n g e a s i n g l e % t o a % % .
F o r e x a m p l e :
# Unix
perl -e 'print "Hello world\n"'
# MS-DOS, etc.
perl -e "print \"Hello world\n\""
# Macintosh
print "Hello world\n"
(then Run "Myscript" or Shift-Command-R)
# VMS
perl -e "print ""Hello world\n"""
T h e p r o b l e m i s t h a t n o n e o f t h i s i s r e l i a b l e : i t d e p e n d s o n t h e c o m m a n d a n d i t i s e n t i r e l y p o s s i b l e n e i t h e r w o r k s . I f 4 D O S w a s t h e c o m m a n d s h e l l , t h i s w o u l d p r o b a b l y w o r k b e t t e r :
perl -e "print <Ctrl-x>"Hello world\n<Ctrl-x>""
C M D . E X E i n W i n d o w s N T s l i p p e d a l o t o f s t a n d a r d U n i x f u n c t i o n a l i t y i n w h e n n o b o d y w a s l o o k i n g , b u t j u s t t r y t o f i n d d o c u m e n t a t i o n f o r i t s q u o t i n g r u l e s .
U n d e r t h e M a c i n t o s h , i t d e p e n d s w h i c h e n v i r o n m e n t y o u a r e u s i n g . T h e M a c P e r l s h e l l , o r M P W , i s m u c h l i k e U n i x s h e l l s i n i t s s u p p o r t f o r s e v e r a l q u o t i n g v a r i a n t s , e x c e p t t h a t i t m a k e s f r e e u s e o f t h e M a c i n t o s h ' s n o n - A S C I I c h a r a c t e r s a s c o n t r o l c h a r a c t e r s .
T h e r e i s n o g e n e r a l s o l u t i o n t o a l l o f t h i s . I t ' s j u s t a m e s s .
# L o c a t i o n o f P e r l
I t m a y s e e m o b v i o u s t o s a y , b u t P e r l i s u s e f u l o n l y w h e n u s e r s c a n e a s i l y f i n d i t . W h e n p o s s i b l e , i t ' s g o o d f o r b o t h / u s r / b i n / p e r l a n d / u s r / l o c a l / b i n / p e r l t o b e s y m l i n k s t o t h e a c t u a l b i n a r y . I f t h a t c a n ' t b e d o n e , s y s t e m a d m i n i s t r a t o r s a r e s t r o n g l y e n c o u r a g e d t o p u t ( s y m l i n k s t o ) p e r l a n d i t s a c c o m p a n y i n g u t i l i t i e s , s u c h a s p e r l d o c , i n t o a d i r e c t o r y t y p i c a l l y f o u n d a l o n g a u s e r ' s P A T H , o r i n a n o t h e r o b v i o u s a n d c o n v e n i e n t p l a c e .
I n t h i s d o c u m e n t a t i o n , # ! / u s r / b i
n / p e r l
o n t h e f i r s t l i n e o f t h e s c r i p t w i l l s t a n d i n f o r w h a t e v e r m e t h o d w o r k s o n y o u r s y s t e m .
# S w i t c h e s
A s i n g l e - c h a r a c t e r s w i t c h m a y b e c o m b i n e d w i t h t h e f o l l o w i n g s w i t c h , i f a n y .
#!/usr/bin/perl -spi.bak # same as -s -p -i.bak
S w i t c h e s i n c l u d e :
# - 0 [ d i g i t s ]
s p e c i f i e s t h e i n p u t r e c o r d s e p a r a t o r ( $ /
) a s a n o c t a l n u m b e r . I f t h e r e a r e n o d i g i t s , t h e n u l l c h a r a c t e r i s t h e s e p a r a t o r . O t h e r s w i t c h e s m a y p r e c e d e o r f o l l o w t h e d i g i t s . F o r e x a m p l e , i f y o u h a v e a v e r s i o n o f f i n d w h i c h c a n p r i n t f i l e n a m e s t e r m i n a t e d b y t h e n u l l c h a r a c t e r , y o u c a n s a y t h i s :
find . -name '*.bak' -print0 | perl -n0e unlink
T h e s p e c i a l v a l u e 0 0 w i l l c a u s e P e r l t o s l u r p f i l e s i n p a r a g r a p h m o d e . T h e v a l u e 0 7 7 7 w i l l c a u s e P e r l t o s l u r p f i l e s w h o l e b e c a u s e t h e r e i s n o l e g a l c h a r a c t e r w i t h t h a t v a l u e .
# - a
t u r n s o n a u t o s p l i t m o d e w h e n u s e d w i t h a - n or - p . A n i m p l i c i t s p l i t c o m m a n d t o t h e @ F a r r a y i s d o n e a s t h e f i r s t t h i n g i n s i d e t h e i m p l i c i t w h i l e l o o p p r o d u c e d b y t h e - n or - p .
perl -ane 'print pop(@F), "\n";'
i s e q u i v a l e n t t o
while (<>) {
@F = split(' ');
print pop(@F), "\n";
}
A n a l t e r n a t e d e l i m i t e r m a y b e s p e c i f i e d u s i n g - F .
# - c
c a u s e s P e r l t o c h e c k t h e s y n t a x o f t h e s c r i p t a n d t h e n e x i t w i t h o u t e x e c u t i n g i t . A c t u a l l y , i t w i l l e x e c u t e B E G I N
, E N D
, a n d u s e
b l o c k s , b e c a u s e t h e s e a r e c o n s i d e r e d a s o c c u r r i n g o u t s i d e t h e e x e c u t i o n o f y o u r p r o g r a m .
# - d
r u n s t h e s c r i p t u n d e r t h e P e r l d e b u g g e r . S e e p e r l d e b u g .
# - d : f o o
r u n s t h e s c r i p t u n d e r t h e c o n t r o l o f a d e b u g g i n g o r t r a c i n g m o d u l e i n s t a l l e d a s D e v e l : : f o o . E . g . , - d : D P r o f e x e c u t e s t h e s c r i p t u s i n g t h e D e v e l : : D P r o f p r o f i l e r . S e e p e r l d e b u g .
# - D l e t t e r s
# - D n u m b e r
s e t s d e b u g g i n g f l a g s . T o w a t c h h o w i t e x e c u t e s y o u r s c r i p t , u s e - D t l s . ( T h i s w o r k s o n l y i f d e b u g g i n g i s c o m p i l e d i n t o y o u r P e r l . ) A n o t h e r n i c e v a l u e i s - D x , w h i c h l i s t s y o u r c o m p i l e d s y n t a x t r e e . A n d - D r d i s p l a y s c o m p i l e d r e g u l a r e x p r e s s i o n s . A s a n a l t e r n a t i v e , s p e c i f y a n u m b e r i n s t e a d o f l i s t o f l e t t e r s ( e . g . , - D 1 4 i s e q u i v a l e n t t o - D t l s ) :
1 p Tokenizing and parsing
2 s Stack snapshots
4 l Context (loop) stack processing
8 t Trace execution
16 o Method and overloading resolution
32 c String/numeric conversions
64 P Print preprocessor command for -P
128 m Memory allocation
256 f Format processing
512 r Regular expression parsing and execution
1024 x Syntax tree dump
2048 u Tainting checks
4096 L Memory leaks (needs C<-DLEAKTEST> when compiling Perl)
8192 H Hash dump -- usurps values()
16384 X Scratchpad allocation
32768 D Cleaning up
65536 S Thread synchronization
A l l t h e s e f l a g s r e q u i r e - D D E B U G
G I N G
w h e n y o u c o m p i l e t h e P e r l e x e c u t a b l e . T h i s f l a g i s a u t o m a t i c a l l y s e t i f y o u i n c l u d e - g
o p t i o n w h e n C o n f i g u r e
a s k s y o u a b o u t o p t i m i z e r / d e b u g g e r f l a g s .
# - e c o m m a n d l i n e
m a y b e u s e d t o e n t e r o n e l i n e o f s c r i p t . I f - e i s g i v e n , P e r l w i l l n o t l o o k f o r a s c r i p t f i l e n a m e i n t h e a r g u m e n t l i s t . M u l t i p l e - e c o m m a n d s m a y b e g i v e n t o b u i l d u p a m u l t i - l i n e s c r i p t . M a k e s u r e t o u s e s e m i c o l o n s w h e r e y o u w o u l d i n a n o r m a l p r o g r a m .
# - F p a t t e r n
s p e c i f i e s t h e p a t t e r n t o s p l i t o n i f - a i s a l s o i n e f f e c t . T h e p a t t e r n m a y b e s u r r o u n d e d b y /
/
, " "
, o r ' '
, o t h e r w i s e i t w i l l b e p u t i n s i n g l e q u o t e s .
# - h
p r i n t s a s u m m a r y o f t h e o p t i o n s .
# - i [ e x t e n s i o n ]
s p e c i f i e s t h a t f i l e s p r o c e s s e d b y t h e < >
c o n s t r u c t a r e t o b e e d i t e d i n - p l a c e . I t d o e s t h i s b y r e n a m i n g t h e i n p u t f i l e , o p e n i n g t h e o u t p u t f i l e b y t h e o r i g i n a l n a m e , a n d s e l e c t i n g t h a t o u t p u t f i l e a s t h e d e f a u l t f o r p r i n t ( ) s t a t e m e n t s . T h e e x t e n s i o n , i f s u p p l i e d , i s u s e d t o m o d i f y t h e n a m e o f t h e o l d f i l e t o m a k e a b a c k u p c o p y , f o l l o w i n g t h e s e r u l e s :
I f n o e x t e n s i o n i s s u p p l i e d , n o b a c k u p i s m a d e a n d t h e c u r r e n t f i l e i s o v e r w r i t t e n .
I f t h e e x t e n s i o n d o e s n ' t c o n t a i n a *
t h e n i t i s a p p e n d e d t o t h e e n d o f t h e c u r r e n t f i l e n a m e a s a s u f f i x .
I f t h e e x t e n s i o n d o e s c o n t a i n o n e o r m o r e *
c h a r a c t e r s , t h e n e a c h *
i s r e p l a c e d w i t h t h e c u r r e n t f i l e n a m e . I n p e r l t e r m s y o u c o u l d t h i n k o f t h i s a s :
($backup = $extension) =~ s/\*/$file_name/g;
T h i s a l l o w s y o u t o a d d a p r e f i x t o t h e b a c k u p f i l e , i n s t e a d o f ( o r i n a d d i t i o n t o ) a s u f f i x :
$ perl -pi'bak_*' -e 's/bar/baz/' fileA # backup to 'bak_fileA'
O r e v e n t o p l a c e b a c k u p c o p i e s o f t h e o r i g i n a l f i l e s i n t o a n o t h e r d i r e c t o r y ( p r o v i d e d t h e d i r e c t o r y a l r e a d y e x i s t s ) :
$ perl -pi'old/*.bak' -e 's/bar/baz/' fileA # backup to 'old/fileA.bak'
T h e s e s e t s o f o n e - l i n e r s a r e e q u i v a l e n t :
$ perl -pi -e 's/bar/baz/' fileA # overwrite current file
$ perl -pi'*' -e 's/bar/baz/' fileA # overwrite current file
$ perl -pi'.bak' -e 's/bar/baz/' fileA # backup to 'fileA.bak'
$ perl -pi'*.bak' -e 's/bar/baz/' fileA # backup to 'fileA.bak'
F r o m t h e s h e l l , s a y i n g
$ perl -p -i.bak -e "s/foo/bar/; ... "
i s t h e s a m e a s u s i n g t h e s c r i p t :
#!/usr/bin/perl -pi.bak
s/foo/bar/;
w h i c h i s e q u i v a l e n t t o
#!/usr/bin/perl
$extension = '.bak';
while (<>) {
if ($ARGV ne $oldargv) {
if ($extension !~ /\*/) {
$backup = $ARGV . $extension;
}
else {
($backup = $extension) =~ s/\*/$ARGV/g;
}
rename($ARGV, $backup);
open(ARGVOUT, ">$ARGV");
select(ARGVOUT);
$oldargv = $ARGV;
}
s/foo/bar/;
}
continue {
print; # this prints to original filename
}
select(STDOUT);
e x c e p t t h a t t h e - i f o r m d o e s n ' t n e e d t o c o m p a r e $ A R G V t o $ o l d a r g v t o k n o w w h e n t h e f i l e n a m e h a s c h a n g e d . I t d o e s , h o w e v e r , u s e A R G V O U T f o r t h e s e l e c t e d f i l e h a n d l e . N o t e t h a t S T D O U T i s r e s t o r e d a s t h e d e f a u l t o u t p u t f i l e h a n d l e a f t e r t h e l o o p .
A s s h o w n a b o v e , P e r l c r e a t e s t h e b a c k u p f i l e w h e t h e r o r n o t a n y o u t p u t i s a c t u a l l y c h a n g e d . S o t h i s i s j u s t a f a n c y w a y t o c o p y f i l e s :
$ perl -p -i'/some/file/path/*' -e 1 file1 file2 file3...
or
$ perl -p -i'.bak' -e 1 file1 file2 file3...
Y o u c a n u s e e o f
w i t h o u t p a r e n t h e s e s t o l o c a t e t h e e n d o f e a c h i n p u t f i l e , i n c a s e y o u w a n t t o a p p e n d t o e a c h f i l e , o r r e s e t l i n e n u m b e r i n g ( s e e e x a m p l e i n " e o f " i n p e r l f u n c ) .
I f , f o r a g i v e n f i l e , P e r l i s u n a b l e t o c r e a t e t h e b a c k u p f i l e a s s p e c i f i e d i n t h e e x t e n s i o n t h e n i t w i l l s k i p t h a t f i l e a n d c o n t i n u e o n w i t h t h e n e x t o n e ( i f i t e x i s t s ) .
F o r a d i s c u s s i o n o f i s s u e s s u r r o u n d i n g f i l e p e r m i s s i o n s a n d - i
, s e e " W h y d o e s P e r l l e t m e d e l e t e r e a d - o n l y f i l e s ? W h y d o e s - i c l o b b e r p r o t e c t e d f i l e s ? I s n ' t t h i s a b u g i n P e r l ? " i n p e r l f a q 5 .
Y o u c a n n o t u s e - i t o c r e a t e d i r e c t o r i e s o r t o s t r i p e x t e n s i o n s f r o m f i l e s .
P e r l d o e s n o t e x p a n d ~
, s o d o n ' t d o t h a t .
F i n a l l y , n o t e t h a t t h e - i s w i t c h d o e s n o t i m p e d e e x e c u t i o n w h e n n o f i l e s a r e g i v e n o n t h e c o m m a n d l i n e . I n t h i s c a s e , n o b a c k u p i s m a d e ( t h e o r i g i n a l f i l e c a n n o t , o f c o u r s e , b e d e t e r m i n e d ) a n d p r o c e s s i n g p r o c e e d s f r o m S T D I N t o S T D O U T a s m i g h t b e e x p e c t e d .
# - I d i r e c t o r y
D i r e c t o r i e s s p e c i f i e d b y - I a r e p r e p e n d e d t o t h e s e a r c h p a t h f o r m o d u l e s ( @ I N C
) , a n d a l s o t e l l s t h e C p r e p r o c e s s o r w h e r e t o s e a r c h f o r i n c l u d e f i l e s . T h e C p r e p r o c e s s o r i s i n v o k e d w i t h - P ; b y d e f a u l t i t s e a r c h e s / u s r / i n c l u d e a n d / u s r / l i b / p e r l .
# - l [ o c t n u m ]
e n a b l e s a u t o m a t i c l i n e - e n d i n g p r o c e s s i n g . I t h a s t w o e f f e c t s : f i r s t , i t a u t o m a t i c a l l y c h o m p s " $ /
" ( t h e i n p u t r e c o r d s e p a r a t o r ) w h e n u s e d w i t h - n or - p , a n d s e c o n d , i t a s s i g n s " $ \
" ( t h e o u t p u t r e c o r d s e p a r a t o r ) t o h a v e t h e v a l u e o f o c t n u m s o t h a t a n y p r i n t s t a t e m e n t s w i l l h a v e t h a t s e p a r a t o r a d d e d b a c k o n . I f o c t n u m i s o m i t t e d , s e t s " $ \
" t o t h e c u r r e n t v a l u e o f " $ /
" . F o r i n s t a n c e , t o t r i m l i n e s t o 8 0 c o l u m n s :
perl -lpe 'substr($_, 80) = ""'
N o t e t h a t t h e a s s i g n m e n t $ \ = $
/
i s d o n e w h e n t h e s w i t c h i s p r o c e s s e d , s o t h e i n p u t r e c o r d s e p a r a t o r c a n b e d i f f e r e n t t h a n t h e o u t p u t r e c o r d s e p a r a t o r i f t h e - l s w i t c h i s f o l l o w e d b y a - 0 s w i t c h :
gnufind / -print0 | perl -ln0e 'print "found $_" if -p'
T h i s s e t s $ \
t o n e w l i n e a n d t h e n s e t s $ /
t o t h e n u l l c h a r a c t e r .
# - m [ - ] m o d u l e
# - M [ - ] m o d u l e
# - M [ - ] ' m o d u l e . . . '
# - [ mM ] [ - ] m o d u l e = a r g [ , a r g ] . . .
- m
m o d u l e e x e c u t e s u s e
m o d u l e ( )
;
b e f o r e e x e c u t i n g y o u r s c r i p t .
- M
m o d u l e e x e c u t e s u s e
m o d u l e ;
b e f o r e e x e c u t i n g y o u r s c r i p t . Y o u c a n u s e q u o t e s t o a d d e x t r a c o d e a f t e r t h e m o d u l e n a m e , e . g . , - M ' m o d u l e q w ( f o o b a r ) '
.
I f t h e f i r s t c h a r a c t e r a f t e r t h e - M
or - m
i s a d a s h ( -
) t h e n t h e ' u s e ' i s r e p l a c e d w i t h ' n o ' .
A l i t t l e b u i l t i n s y n t a c t i c s u g a r m e a n s y o u c a n a l s o s a y - m m o d u
l e = f o o , b a r
or - M m o d u l e = f o o , b a r
a s a s h o r t c u t f o r - M ' m o d u l e q w ( f o o
b a r ) '
. T h i s a v o i d s t h e n e e d t o u s e q u o t e s w h e n i m p o r t i n g s y m b o l s . T h e a c t u a l c o d e g e n e r a t e d b y - M m o d u l e = f o o , b a r
is u s e m o d u l e
s p l i t ( / , / , q { f o o , b a r } )
. N o t e t h a t t h e =
f o r m r e m o v e s t h e d i s t i n c t i o n b e t w e e n - m
a n d - M
.
# - n
c a u s e s P e r l t o a s s u m e t h e f o l l o w i n g l o o p a r o u n d y o u r s c r i p t , w h i c h m a k e s i t i t e r a t e o v e r f i l e n a m e a r g u m e n t s s o m e w h a t l i k e s e d - n or a w k :
while (<>) {
... # your script goes here
}
N o t e t h a t t h e l i n e s a r e n o t p r i n t e d b y d e f a u l t . S e e - p t o h a v e l i n e s p r i n t e d . I f a f i l e n a m e d b y a n a r g u m e n t c a n n o t b e o p e n e d f o r s o m e r e a s o n , P e r l w a r n s y o u a b o u t i t , a n d m o v e s o n t o t h e n e x t f i l e .
H e r e i s a n e f f i c i e n t w a y t o d e l e t e a l l f i l e s o l d e r t h a n a w e e k :
find . -mtime +7 -print | perl -nle 'unlink;'
T h i s i s f a s t e r t h a n u s i n g t h e -
e x e c
s w i t c h o f f i n d b e c a u s e y o u d o n ' t h a v e t o s t a r t a p r o c e s s o n e v e r y f i l e n a m e f o u n d .
B E G I N
a n d E N D
b l o c k s m a y b e u s e d t o c a p t u r e c o n t r o l b e f o r e o r a f t e r t h e i m p l i c i t l o o p , j u s t a s i n a w k .
# - p
c a u s e s P e r l t o a s s u m e t h e f o l l o w i n g l o o p a r o u n d y o u r s c r i p t , w h i c h m a k e s i t i t e r a t e o v e r f i l e n a m e a r g u m e n t s s o m e w h a t l i k e s e d :
while (<>) {
... # your script goes here
} continue {
print or die "-p destination: $!\n";
}
I f a f i l e n a m e d b y a n a r g u m e n t c a n n o t b e o p e n e d f o r s o m e r e a s o n , P e r l w a r n s y o u a b o u t i t , a n d m o v e s o n t o t h e n e x t f i l e . N o t e t h a t t h e l i n e s a r e p r i n t e d a u t o m a t i c a l l y . A n e r r o r o c c u r r i n g d u r i n g p r i n t i n g i s t r e a t e d a s f a t a l . T o s u p p r e s s p r i n t i n g u s e t h e - n s w i t c h . A - p o v e r r i d e s a - n s w i t c h .
B E G I N
a n d E N D
b l o c k s m a y b e u s e d t o c a p t u r e c o n t r o l b e f o r e o r a f t e r t h e i m p l i c i t l o o p , j u s t a s i n a w k .
# - P
c a u s e s y o u r s c r i p t t o b e r u n t h r o u g h t h e C p r e p r o c e s s o r b e f o r e c o m p i l a t i o n b y P e r l . ( B e c a u s e b o t h c o m m e n t s a n d c p p d i r e c t i v e s b e g i n w i t h t h e # c h a r a c t e r , y o u s h o u l d a v o i d s t a r t i n g c o m m e n t s w i t h a n y w o r d s r e c o g n i z e d b y t h e C p r e p r o c e s s o r s u c h a s " i f " , " e l s e " , o r " d e f i n e " . )
# - s
e n a b l e s s o m e r u d i m e n t a r y s w i t c h p a r s i n g f o r s w i t c h e s o n t h e c o m m a n d l i n e a f t e r t h e s c r i p t n a m e b u t b e f o r e a n y f i l e n a m e a r g u m e n t s ( o r b e f o r e a - - ) . A n y s w i t c h f o u n d t h e r e i s r e m o v e d f r o m @ A R G V a n d s e t s t h e c o r r e s p o n d i n g v a r i a b l e i n t h e P e r l s c r i p t . T h e f o l l o w i n g s c r i p t p r i n t s " t r u e " i f a n d o n l y i f t h e s c r i p t i s i n v o k e d w i t h a - x y z s w i t c h .
#!/usr/bin/perl -s
if ($xyz) { print "true\n"; }
# - S
m a k e s P e r l u s e t h e P A T H e n v i r o n m e n t v a r i a b l e t o s e a r c h f o r t h e s c r i p t ( u n l e s s t h e n a m e o f t h e s c r i p t c o n t a i n s d i r e c t o r y s e p a r a t o r s ) . O n s o m e p l a t f o r m s , t h i s a l s o m a k e s P e r l a p p e n d s u f f i x e s t o t h e f i l e n a m e w h i l e s e a r c h i n g f o r i t . F o r e x a m p l e , o n W i n 3 2 p l a t f o r m s , t h e " . b a t " a n d " . c m d " s u f f i x e s a r e a p p e n d e d i f a l o o k u p f o r t h e o r i g i n a l n a m e f a i l s , a n d i f t h e n a m e d o e s n o t a l r e a d y e n d i n o n e o f t h o s e s u f f i x e s . I f y o u r P e r l w a s c o m p i l e d w i t h D E B U G G I N G t u r n e d o n , u s i n g t h e - D p s w i t c h t o P e r l s h o w s h o w t h e s e a r c h p r o g r e s s e s .
I f t h e f i l e n a m e s u p p l i e d c o n t a i n s d i r e c t o r y s e p a r a t o r s ( i . e . i t i s a n a b s o l u t e o r r e l a t i v e p a t h n a m e ) , a n d i f t h e f i l e i s n o t f o u n d , p l a t f o r m s t h a t a p p e n d f i l e e x t e n s i o n s w i l l d o s o a n d t r y t o l o o k f o r t h e f i l e w i t h t h o s e e x t e n s i o n s a d d e d , o n e b y o n e .
O n D O S - l i k e p l a t f o r m s , i f t h e s c r i p t d o e s n o t c o n t a i n d i r e c t o r y s e p a r a t o r s , i t w i l l f i r s t b e s e a r c h e d f o r i n t h e c u r r e n t d i r e c t o r y b e f o r e b e i n g s e a r c h e d f o r o n t h e P A T H . O n U n i x p l a t f o r m s , t h e s c r i p t w i l l b e s e a r c h e d f o r s t r i c t l y o n t h e P A T H .
T y p i c a l l y t h i s i s u s e d t o e m u l a t e # ! s t a r t u p o n p l a t f o r m s t h a t d o n ' t s u p p o r t # ! . T h i s e x a m p l e w o r k s o n m a n y p l a t f o r m s t h a t h a v e a s h e l l c o m p a t i b l e w i t h B o u r n e s h e l l :
#!/usr/bin/perl
eval 'exec /usr/bin/perl -wS $0 ${1+"$@"}'
if $running_under_some_shell;
T h e s y s t e m i g n o r e s t h e f i r s t l i n e a n d f e e d s t h e s c r i p t t o / b i n / s h , w h i c h p r o c e e d s t o t r y t o e x e c u t e t h e P e r l s c r i p t a s a s h e l l s c r i p t . T h e s h e l l e x e c u t e s t h e s e c o n d l i n e a s a n o r m a l s h e l l c o m m a n d , a n d t h u s s t a r t s u p t h e P e r l i n t e r p r e t e r . O n s o m e s y s t e m s $ 0 d o e s n ' t a l w a y s c o n t a i n t h e f u l l p a t h n a m e , s o t h e - S t e l l s P e r l t o s e a r c h f o r t h e s c r i p t i f n e c e s s a r y . A f t e r P e r l l o c a t e s t h e s c r i p t , i t p a r s e s t h e l i n e s a n d i g n o r e s t h e m b e c a u s e t h e v a r i a b l e $ r u n n i n g _ u n d e r _ s o m e _ s h e l l i s n e v e r t r u e . I f t h e s c r i p t w i l l b e i n t e r p r e t e d b y c s h , y o u w i l l n e e d t o r e p l a c e $ {
1 + " $ @ " }
w i t h $ *
, e v e n t h o u g h t h a t d o e s n ' t u n d e r s t a n d e m b e d d e d s p a c e s ( a n d s u c h ) i n t h e a r g u m e n t l i s t . T o s t a r t u p s h r a t h e r t h a n c s h , s o m e s y s t e m s m a y h a v e t o r e p l a c e t h e # ! l i n e w i t h a l i n e c o n t a i n i n g j u s t a c o l o n , w h i c h w i l l b e p o l i t e l y i g n o r e d b y P e r l . O t h e r s y s t e m s c a n ' t c o n t r o l t h a t , a n d n e e d a t o t a l l y d e v i o u s c o n s t r u c t t h a t w i l l w o r k u n d e r a n y o f c s h , s h , o r P e r l , s u c h a s t h e f o l l o w i n g :
eval '(exit $?0)' && eval 'exec /usr/bin/perl -wS $0 ${1+"$@"}'
& eval 'exec /usr/bin/perl -wS $0 $argv:q'
if $running_under_some_shell;
# - T
f o r c e s " t a i n t " c h e c k s t o b e t u r n e d o n s o y o u c a n t e s t t h e m . O r d i n a r i l y t h e s e c h e c k s a r e d o n e o n l y w h e n r u n n i n g s e t u i d o r s e t g i d . I t ' s a g o o d i d e a t o t u r n t h e m o n e x p l i c i t l y f o r p r o g r a m s r u n o n a n o t h e r ' s b e h a l f , s u c h a s C G I p r o g r a m s . S e e p e r l s e c . N o t e t h a t ( f o r s e c u r i t y r e a s o n s ) t h i s o p t i o n m u s t b e s e e n b y P e r l q u i t e e a r l y ; u s u a l l y t h i s m e a n s i t m u s t a p p e a r e a r l y o n t h e c o m m a n d l i n e o r i n t h e # ! l i n e ( f o r s y s t e m s w h i c h s u p p o r t t h a t ) .
# - u
c a u s e s P e r l t o d u m p c o r e a f t e r c o m p i l i n g y o u r s c r i p t . Y o u c a n t h e n i n t h e o r y t a k e t h i s c o r e d u m p a n d t u r n i t i n t o a n e x e c u t a b l e f i l e b y u s i n g t h e u n d u m p p r o g r a m ( n o t s u p p l i e d ) . T h i s s p e e d s s t a r t u p a t t h e e x p e n s e o f s o m e d i s k s p a c e ( w h i c h y o u c a n m i n i m i z e b y s t r i p p i n g t h e e x e c u t a b l e ) . ( S t i l l , a " h e l l o w o r l d " e x e c u t a b l e c o m e s o u t t o a b o u t 2 0 0 K o n m y m a c h i n e . ) I f y o u w a n t t o e x e c u t e a p o r t i o n o f y o u r s c r i p t b e f o r e d u m p i n g , u s e t h e d u m p ( ) o p e r a t o r i n s t e a d . N o t e : a v a i l a b i l i t y o f u n d u m p i s p l a t f o r m s p e c i f i c a n d m a y n o t b e a v a i l a b l e f o r a s p e c i f i c p o r t o f P e r l . I t h a s b e e n s u p e r s e d e d b y t h e n e w p e r l - t o - C c o m p i l e r , w h i c h i s m o r e p o r t a b l e , e v e n t h o u g h i t ' s s t i l l o n l y c o n s i d e r e d b e t a .
# - U
a l l o w s P e r l t o d o u n s a f e o p e r a t i o n s . C u r r e n t l y t h e o n l y " u n s a f e " o p e r a t i o n s a r e t h e u n l i n k i n g o f d i r e c t o r i e s w h i l e r u n n i n g a s s u p e r u s e r , a n d r u n n i n g s e t u i d p r o g r a m s w i t h f a t a l t a i n t c h e c k s t u r n e d i n t o w a r n i n g s . N o t e t h a t t h e - w s w i t c h ( o r t h e $ ^ W
v a r i a b l e ) m u s t b e u s e d a l o n g w i t h t h i s o p t i o n t o a c t u a l l y g e n e r a t e t h e t a i n t - c h e c k w a r n i n g s .
# - v
p r i n t s t h e v e r s i o n a n d p a t c h l e v e l o f y o u r P e r l e x e c u t a b l e .
# - V
p r i n t s s u m m a r y o f t h e m a j o r p e r l c o n f i g u r a t i o n v a l u e s a n d t h e c u r r e n t v a l u e o f @ I N C .
# - V : n a m e
P r i n t s t o S T D O U T t h e v a l u e o f t h e n a m e d c o n f i g u r a t i o n v a r i a b l e .
# - w
p r i n t s w a r n i n g s a b o u t v a r i a b l e n a m e s t h a t a r e m e n t i o n e d o n l y o n c e , a n d s c a l a r v a r i a b l e s t h a t a r e u s e d b e f o r e b e i n g s e t . A l s o w a r n s a b o u t r e d e f i n e d s u b r o u t i n e s , a n d r e f e r e n c e s t o u n d e f i n e d f i l e h a n d l e s o r f i l e h a n d l e s o p e n e d r e a d - o n l y t h a t y o u a r e a t t e m p t i n g t o w r i t e o n . A l s o w a r n s y o u i f y o u u s e v a l u e s a s a n u m b e r t h a t d o e s n ' t l o o k l i k e n u m b e r s , u s i n g a n a r r a y a s t h o u g h i t w e r e a s c a l a r , i f y o u r s u b r o u t i n e s r e c u r s e m o r e t h a n 1 0 0 d e e p , a n d i n n u m e r a b l e o t h e r t h i n g s .
Y o u c a n d i s a b l e s p e c i f i c w a r n i n g s u s i n g _ _ W A R N _ _
h o o k s , a s d e s c r i b e d i n p e r l v a r a n d " w a r n " i n p e r l f u n c . S e e a l s o p e r l d i a g a n d p e r l t r a p .
# - x d i r e c t o r y
t e l l s P e r l t h a t t h e s c r i p t i s e m b e d d e d i n a m e s s a g e . L e a d i n g g a r b a g e w i l l b e d i s c a r d e d u n t i l t h e f i r s t l i n e t h a t s t a r t s w i t h # ! a n d c o n t a i n s t h e s t r i n g " p e r l " . A n y m e a n i n g f u l s w i t c h e s o n t h a t l i n e w i l l b e a p p l i e d . I f a d i r e c t o r y n a m e i s s p e c i f i e d , P e r l w i l l s w i t c h t o t h a t d i r e c t o r y b e f o r e r u n n i n g t h e s c r i p t . T h e - x s w i t c h c o n t r o l s o n l y t h e d i s p o s a l o f l e a d i n g g a r b a g e . T h e s c r i p t m u s t b e t e r m i n a t e d w i t h _ _ E N D _ _
i f t h e r e i s t r a i l i n g g a r b a g e t o b e i g n o r e d ( t h e s c r i p t c a n p r o c e s s a n y o r a l l o f t h e t r a i l i n g g a r b a g e v i a t h e D A T A f i l e h a n d l e i f d e s i r e d ) .
# E N V I R O N M E N T
# H O M E
U s e d i f c h d i r h a s n o a r g u m e n t .
# L O G D I R
U s e d i f c h d i r h a s n o a r g u m e n t a n d H O M E i s n o t s e t .
# P A T H
U s e d i n e x e c u t i n g s u b p r o c e s s e s , a n d i n f i n d i n g t h e s c r i p t i f - S i s u s e d .
# P E R L 5 L I B
A c o l o n - s e p a r a t e d l i s t o f d i r e c t o r i e s i n w h i c h t o l o o k f o r P e r l l i b r a r y f i l e s b e f o r e l o o k i n g i n t h e s t a n d a r d l i b r a r y a n d t h e c u r r e n t d i r e c t o r y . I f P E R L 5 L I B i s n o t d e f i n e d , P E R L L I B i s u s e d . W h e n r u n n i n g t a i n t c h e c k s ( b e c a u s e t h e s c r i p t w a s r u n n i n g s e t u i d o r s e t g i d , o r t h e - T s w i t c h w a s u s e d ) , n e i t h e r v a r i a b l e i s u s e d . T h e s c r i p t s h o u l d i n s t e a d s a y
use lib "/my/directory";
# P E R L 5 O P T
C o m m a n d - l i n e o p t i o n s ( s w i t c h e s ) . S w i t c h e s i n t h i s v a r i a b l e a r e t a k e n a s i f t h e y w e r e o n e v e r y P e r l c o m m a n d l i n e . O n l y t h e - [ D I M U d m w ] s w i t c h e s a r e a l l o w e d . W h e n r u n n i n g t a i n t c h e c k s ( b e c a u s e t h e s c r i p t w a s r u n n i n g s e t u i d o r s e t g i d , o r t h e - T s w i t c h w a s u s e d ) , t h i s v a r i a b l e i s i g n o r e d . I f P E R L 5 O P T b e g i n s w i t h - T , t a i n t i n g w i l l b e e n a b l e d , a n d a n y s u b s e q u e n t o p t i o n s i g n o r e d .
# P E R L L I B
A c o l o n - s e p a r a t e d l i s t o f d i r e c t o r i e s i n w h i c h t o l o o k f o r P e r l l i b r a r y f i l e s b e f o r e l o o k i n g i n t h e s t a n d a r d l i b r a r y a n d t h e c u r r e n t d i r e c t o r y . I f P E R L 5 L I B i s d e f i n e d , P E R L L I B i s n o t u s e d .
# P E R L 5 D B
T h e c o m m a n d u s e d t o l o a d t h e d e b u g g e r c o d e . T h e d e f a u l t i s :
BEGIN { require 'perl5db.pl' }
# P E R L 5 S H E L L ( s p e c i f i c t o W I N 3 2 p o r t )
M a y b e s e t t o a n a l t e r n a t i v e s h e l l t h a t p e r l m u s t u s e i n t e r n a l l y f o r e x e c u t i n g " b a c k t i c k " c o m m a n d s o r s y s t e m ( ) . D e f a u l t i s c
m d . e x e / x / c
o n W i n d o w s N T a n d c o
m m a n d . c o m / c
o n W i n d o w s 9 5 . T h e v a l u e i s c o n s i d e r e d t o b e s p a c e d e l i m i t e d . P r e c e d e a n y c h a r a c t e r t h a t n e e d s t o b e p r o t e c t e d ( l i k e a s p a c e o r b a c k s l a s h ) w i t h a b a c k s l a s h .
N o t e t h a t P e r l d o e s n ' t u s e C O M S P E C f o r t h i s p u r p o s e b e c a u s e C O M S P E C h a s a h i g h d e g r e e o f v a r i a b i l i t y a m o n g u s e r s , l e a d i n g t o p o r t a b i l i t y c o n c e r n s . B e s i d e s , p e r l c a n u s e a s h e l l t h a t m a y n o t b e f i t f o r i n t e r a c t i v e u s e , a n d s e t t i n g C O M S P E C t o s u c h a s h e l l m a y i n t e r f e r e w i t h t h e p r o p e r f u n c t i o n i n g o f o t h e r p r o g r a m s ( w h i c h u s u a l l y l o o k i n C O M S P E C t o f i n d a s h e l l f i t f o r i n t e r a c t i v e u s e ) .
# P E R L _ D E B U G _ M S T A T S
R e l e v a n t o n l y i f p e r l i s c o m p i l e d w i t h t h e m a l l o c i n c l u d e d w i t h t h e p e r l d i s t r i b u t i o n ( t h a t i s , i f p e r l - V : d _ m y m a l l o c
i s ' d e f i n e ' ) . I f s e t , t h i s c a u s e s m e m o r y s t a t i s t i c s t o b e d u m p e d a f t e r e x e c u t i o n . I f s e t t o a n i n t e g e r g r e a t e r t h a n o n e , a l s o c a u s e s m e m o r y s t a t i s t i c s t o b e d u m p e d a f t e r c o m p i l a t i o n .
# P E R L _ D E S T R U C T _ L E V E L
R e l e v a n t o n l y i f y o u r p e r l e x e c u t a b l e w a s b u i l t w i t h - D D E B U G G I N G , t h i s c o n t r o l s t h e b e h a v i o r o f g l o b a l d e s t r u c t i o n o f o b j e c t s a n d o t h e r r e f e r e n c e s .
P e r l a l s o h a s e n v i r o n m e n t v a r i a b l e s t h a t c o n t r o l h o w P e r l h a n d l e s d a t a s p e c i f i c t o p a r t i c u l a r n a t u r a l l a n g u a g e s . S e e p e r l l o c a l e .
A p a r t f r o m t h e s e , P e r l u s e s n o o t h e r e n v i r o n m e n t v a r i a b l e s , e x c e p t t o m a k e t h e m a v a i l a b l e t o t h e s c r i p t b e i n g e x e c u t e d , a n d t o c h i l d p r o c e s s e s . H o w e v e r , s c r i p t s r u n n i n g s e t u i d w o u l d d o w e l l t o e x e c u t e t h e f o l l o w i n g l i n e s b e f o r e d o i n g a n y t h i n g e l s e , j u s t t o k e e p p e o p l e h o n e s t :
$ENV{PATH} = '/bin:/usr/bin'; # or whatever you need
$ENV{SHELL} = '/bin/sh' if exists $ENV{SHELL};
delete @ENV{qw(IFS CDPATH ENV BASH_ENV)};
P e r l d o c B r o w s e r i s m a i n t a i n e d b y D a n B o o k ( D B O O K ) . P l e a s e c o n t a c t h i m v i a t h e G i t H u b i s s u e t r a c k e r or e m a i l r e g a r d i n g a n y i s s u e s w i t h t h e s i t e i t s e l f , s e a r c h , o r r e n d e r i n g o f d o c u m e n t a t i o n .
T h e P e r l d o c u m e n t a t i o n i s m a i n t a i n e d b y t h e P e r l 5 P o r t e r s i n t h e d e v e l o p m e n t o f P e r l . P l e a s e c o n t a c t t h e m v i a t h e P e r l i s s u e t r a c k e r , t h e m a i l i n g l i s t , o r I R C t o r e p o r t a n y i s s u e s w i t h t h e c o n t e n t s o r f o r m a t o f t h e d o c u m e n t a t i o n .