Comments (7)
Sample of simple Perl code:
#!/usr/bin/perl -w
# comments start with #
# first line can be treated as comment but it's a shebang
use strict;
=head1 DESCRIPTION
Here are samples of Perl code.
This chunk is POD - Plain Old Documentation,
it can contain B<bold>, I<italic>, C<code>, links L<http://example.net>,
entitites E<gt>, filenames F<.bashrc>.
POD starts from =word which haven't any chars before.
Words =pod, =head1, =head2, =head3, =head4, =over, =item, =back, =begin, =end, =for,
and =encoding are marking begin of section; word =cut ends any section.
=head1 SEE ALSO
L<perlpod> or L<< http://perldoc.perl.org/perlpod.html >>
=cut
my $scalar = 42;
my @list = ( 'alice', 'bob', 3.1415926 );
my %hash = ( bare => 7, 'key' => $scalar );
my $refs = {
'scalar' => \$scalar,
'list' => \@list,
'hash' => \%hash,
};
my $aref = \@list;
# Function with parentheses
print
join(' ', $list[1], $hash{'bare'}, $refs->{list}->[3]),
"string can contain variables like $scalar and characters\n",
qq{can\x20too}, qq=and too\cJ=,
`uname -a`, qx<df -h>;
# and without them
my @fruits = qw/ apple banana cucumber duck elephant /;
print
sort { $b cmp $a }
grep { /a/ } @fruits;
# if can be used without parentheses too
printf
"%f = %f. File %s, line %d\n",
$$aref[2], $aref->[2], __FILE__, __LINE__
if $#list == 2;
# Regular expressions
$list[1] =~ s/b/Bh/g
if $list[0] =~ /i/
&& $list[1] =~ m-o-;
my @regexps = ( /\d+/, qr{\w} );
LABEL:
foreach ( @fruits ) {
# implicit using of $_ variable
next LABEL if /c/;
print;
}
As written in http://odd-eyed-code.org/projects/coderay/wiki/ScannerRequests
Provide links to useful information about the language lexic, such as:
- a list of reserved words
http://perldoc.perl.org/perlfunc.html
Here are Perl's functions (including things that look like functions, like some keywords and named operators) arranged by category. Some functions appear in more than one place.
- Functions for SCALARs or strings
chomp
,chop
,chr
,crypt
,fc
,hex
,index
,lc
,lcfirst
,length
,oct
,ord
,pack
,q//
,qq//
,reverse
,rindex
,sprintf
,substr
,tr///
,uc
,ucfirst
,y///
- Regular expressions and pattern matching
m//
,pos
,qr//
,quotemeta
,s///
,split
,study
- Numeric functions
abs, atan2, cos, exp, hex, int, log, oct, rand, sin, sqrt, srand - Functions for real
@ARRAYs
each
,keys
,pop
,push
,shift
,splice
,unshift
,values
- Functions for list data
grep
,join
,map
,qw//
,reverse
,sort
,unpack
- Functions for real
%HASHes
delete
,each
,exists
,keys
,values
- Input and output functions
binmode
,close
,closedir
,dbmclose
,dbmopen
,die
,eof
,fileno
,flock
,format
,getc
,print
,printf
,read
,readdir
,readline rewinddir
,say
,seek
,seekdir
,select
,syscall
,sysread
,sysseek
,syswrite
,tell
,telldir
,truncate
,warn
,write
- Functions for fixed-length data or records
pack
,read
,syscall
,sysread
,sysseek
,syswrite
,unpack
,vec
- Functions for filehandles, files, or directories
-X
(see below),chdir
,chmod
,chown
,chroot
,fcntl
,glob
,ioctl
,link
,lstat
,mkdir
,open
,opendir
,readlink
,rename
,rmdir
,select
,stat
,symlink
,sysopen
,umask
,unlink
,utime
- Keywords related to the control flow of your Perl program
break
,caller
,continue
,die
,do
,dump
,eval
,evalbytes
,exit
,__FILE__
,goto
,last
,__LINE__
,next
,__PACKAGE__
,redo
,return
,sub
,__SUB__
,wantarray
- Keywords related to scoping
caller
,import
,local
,my
,our
,package
,state
,use
- Miscellaneous functions
defined
,formline
,lock
,prototype
,reset
,scalar
,undef
- Functions for processes and process groups
alarm
,exec
,fork
,getpgrp
,getppid
,getpriority
,kill
,pipe
,qx//
,readpipe
,setpgrp
,setpriority
,sleep
,system
,times
,wait
,waitpid
- Keywords related to Perl modules
do
,import
,no
,package
,require
,use
- Keywords related to classes and object-orientation
bless
,dbmclose
,dbmopen
,package
,ref
,tie
,tied
,untie
,use
- Low-level socket functions
accept
,bind
,connect
,getpeername
,getsockname
,getsockopt
,listen
,recv
,send
,setsockopt
,shutdown
,socket
,socketpair
- System V interprocess communication functions
msgctl
,msgget
,msgrcv
,msgsnd
,semctl
,semget
,semop
,shmctl
,shmget
,shmread
,shmwrite
- Fetching user and group info
endgrent
,endhostent
,endnetent
,endpwent
,getgrent
,getgrgid
,getgrnam
,getlogin
,getpwent
,getpwnam
,getpwuid
,setgrent
,setpwent
- Fetching network info
endprotoent
,endservent
,gethostbyaddr
,gethostbyname
,gethostent
,getnetbyaddr
,getnetbyname
,getnetent
,getprotobyname
,getprotobynumber
,getprotoent
,getservbyname
,getservbyport
,getservent
,sethostent
,setnetent
,setprotoent
,setservent
- Time-related functions
gmtime
,localtime
,time
,times
- Non-function keywords
and
,AUTOLOAD
,BEGIN
,CHECK
,cmp
,CORE
,__DATA__
,default
,DESTROY
,else
,elseif
,elsif
,END
,__END__
,eq
,for
,foreach
,ge
,given
,gt
,if
,INIT
,le
,lt
,ne
,not
,or
,UNITCHECK
,unless
,until
,when
,while
,x
,xor
-X
are -r
, -w
, -x
, -o
, -R
, -W
, -X
, -O
, -e
, -s
, -z
, -f
, -d
, -l
, -p
, -S
, -b
, -c
, -t
, -u
, -g
, -k
, -T
, -B
, -M
, -A
, -C
.
- rules for string and number literals
"string with interpolated $variables\n", qq{more}, qq/and more/,
'without them', q{without}, q/them/, q^any symbol after q is OK^, q<but brackets must be paired>,
42, 3.1415926, 1e6, 16_777_216, 012 (octal), 0xFF and 0xff (hexadecimal)
Can a double quoted string contain a newline?
my $multiline = "Yes,
it can.";
- rules for comments
# There is a comment
$var = 42; # life, the Universe, and everything
Does Language have a special syntax for multiline comments?
Yes, it have. See perlpod
- a description of any unusual syntactic features (There's this weird %w() thing in Ruby...)
There is a lot of unusual syntax and Ruby got some of its features :-)
- Strings can be specified with Quote-Like Operators
- Lists can be specified as
('list', 'items')
or asqw( words without quotation marks )
, - Regexps can be written as
/regexp/
or asqr/regexp/
. There are modifiers for regexps. See perlre - Output of system command can be obtained as
command
or asqx(command)
- There are matching and translation operators
s///
,m//
,tr///
,y///
If there are different versions / implementations / dialects of this language: How do they differ?
Hmmm... There is Perl 5 and Perl 6. But I propose to use Perl 5 only.
from coderay.
No plans to support it currently. I don't know enough about Perl, and 'm scared of the language's syntax ;-) Also, what to support, Perl 5 or 6?
Patches are very welcome, but we need a LOT of example code to make sure it doesn't crash even on the most hideous Perl code. Forking the Ruby scanner might be a good start.
from coderay.
Oh, and, as always, I direct you to http://odd-eyed-code.org/projects/coderay/wiki/ScannerRequests.
from coderay.
I'd personally be interested in a Perl 5 scanner.
I would suggest if a scanner were added for either version that both be kept in parallel as perl 6 and perl 5 are fairly different languages and have different futures at the moment. If perl 6 ever really replaces perl 5 I expect that will be many years from now.
Thanks for the link... when I tried to look at that site before it seemed to not be working... i kept getting the same message on every page. It looks to be working now, so I'll take a look at it sometime.
Thanks.
from coderay.
So we should implement a Perl 5 scanner, and make sure it doesn't totally mess up if you give it Perl 6 :-)
Thanks for the link... when I tried to look at that site before it seemed to not be working... i kept getting the same message on every page.
Sorry -.-' I guess that's because we recently upgraded to Ruby 1.9…you know how it goes.
from coderay.
Hello, any news on this? :-)
from coderay.
No progress yet, sorry. I'll announce here when there's anything new.
from coderay.
Related Issues (20)
- Could the API for CodeRay.scan(dataset, :python).term also allow for some variant that works on the file extension? (e. g. "rb" for ruby files, "py" or python files etc..)
- ActionView::Template::Error (Symbol or String expected, but NilClass given.)
- Elixir Scanner HOT 1
- Regex with slashes are broken for Javascript
- add 1C Enterprise syntax
- Placeholder $ character in prepared statements (SQL) is marked invalid
- Misaligned line numbers in diff files with `line_numbers: :inline` HOT 1
- Install coderay with permission error in macosx HOT 1
- Invalid rdoc option in gemspec
- CodeRay hangs on multi-code in content
- Add support for CakePHP ctp template
- Support for Kotlin
- Coderay breaks with embedded backticks
- Uninitialized constant Coderay (Redmine 4.1)
- $ method in Groovy code is highlighted as error
- ruby 3.0: test/unit/suite.rb fails due to change in flatten behavior for subclass of Array
- Support for C#
- Support for GraphQL
- License? HOT 1
- Can we easily redefine the colours? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from coderay.