PDA

View Full Version : Perl basics, as well as regex references


]|V|[agnus
07-27-2005, 01:58 AM
I don't write Perl, and I'm only vaguely familiar with it. I need to get a better idea of some of the basics, as well as the regex syntax used, because I am trying to port John Gruber's Markdown [http://daringfireball.com/projects/markdown/] to ColdFusion.

The idea came to me while working on some custom tags to do HTML formatting myself. I realized a lot of great work had already been done with Markdown, noticed it'd been ported to PHP, and thought it'd be a fun project to port it to ColdFusion.

For starters, I don't understand this line I'm seeing in Markdown and examples everywhere at the beginning of a function:

my $var = shift;

What is 'shift' doing?

So yes... as odd as it sounds, I think I just need some basic sort of primers, but also a good overview of Perl's regex syntax, as I know that ColdFusion differs.

Thanks!

FishMonger
07-27-2005, 02:57 AM
perldoc -f shift
shift ARRAY
shift Shifts the first value of the array off and returns it,
shortening the array by 1 and moving everything down. If there
are no elements in the array, returns the undefined value. If
ARRAY is omitted, shifts the @_ array within the lexical scope
of subroutines and formats, and the @ARGV array at file scopes
or within the lexical scopes established by the "eval ''",
"BEGIN {}", "INIT {}", "CHECK {}", and "END {}" constructs.

See also "unshift", "push", and "pop". "shift" and "unshift" do
the same thing to the left end of an array that "pop" and "push"
do to the right end.


The best recommendation I can make for you to learn the basics of Perl is to pick up a copy of "Learning Perl". For regex info "Mastering Regular Expressions" is considered to be the definitive book; it focuses on Perl but since it discusses the various regex engines, it covers most languages.

http://www.oreilly.com/catalog/learnperl4/
http://www.oreilly.com/catalog/regex2/

edit
If you want, you can read the book online.
http://safari.oreilly.com/?x=1&mode=section&sortKey=title&sortOrder=asc&view=&xmlid=0-596-00132-0&g=&catid=itbooks.prog.perl&s=1&b=1&f=1&t=1&c=1&u=1&r=&o=1&n=1&d=1&p=1&a=0&page=0

]|V|[agnus
07-27-2005, 03:08 AM
excellent. i digs the o'reillys... that's my biggest hurdle with this endeavour, the regular expression syntaxes, and of course they're an invaluable tool. so now, ++! thanks. :)