[oclug] really basic perl help
bstrosberg at rcpsc.edu
Mon Jan 6 10:23:41 EST 2003
> I see you are using some sort of special reserved
> variable (the $1). I
> think I need to find a list of those and review them :-) I'm
> having trouble
> with the perl documentation. I'm sure all the information I
> need is there,
> but it's written assuming you know more of the subject than I do. The
> regular linux man pages usually seem to be written more clearly.
> To be fair, if somebody else went to all the work of
> creating the tools
> I need, then complaining about learning how to use them is
> pretty childish
> on my part.
> PS Why did you choose to write $a .= $1; ? Why not $a = $a.$1 ?
> I realize both do the same thing, but the second form
> seems so much
> clearer to me I wonder why people write it the other way.
Brevity and less typing re. the .= statement. It is a well known convention
in the Perl community, therefore to the cognisenti, it is very clear. Give
yourself a little time and you too will default to using this and other
(initially) obscure Perl shortcuts.
The $1 ($2 etc.) variables are regular expression placeholders for parts of
a regular expression matching statement you wish to "keep" for other use in
replacements. Perl, vim and all RegEx engines typically support their use.
There are different syntax variants, but it will become clear quickly.
The best treatise on Regular Expressions I've seen if the O'Reilly Book,
"Mastering Regular Expressions". It clearly delineates Perl RegEx versus
More information about the OCLUG