Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- while(<$fh>)
- {
- next if 1..1; # skip first record
- ...
- }
- $ perl -wle 'my $x = 3; print $ x'
- 3
- $ perl -lwe '*4 = sub { print "yes" }; 4->()'
- yes
- $ perl -wle 'print !!4'
- 1
- $ perl -wle 'print !!"0 but true"'
- 1
- $ perl -wle 'print !!0'
- (empty line)
- $ perl -Mstrict -wle 'print q bJet another perl hacker.b'
- Jet another perl hacker.
- m xabcx
- # same as m/abc/
- s{
- ^ # make sure to get whole filename
- (
- [^'] + # at least one non-quote
- . # extension dot
- (?: # now either suffix
- gz
- | Z
- )
- )
- z # through the end
- }{gzcat '$1' |}xs for @ARGV;
- while (<>) {
- print;
- }
- $x = $a || $b;
- # $x = $a, if $a is true.
- # $x = $b, otherwise
- $x = $a || $b || $c || 0;
- my $_ = "a"
- print -$_
- my $_ = "a"
- print -$_
- my $_ = "a"
- print -$_
- print ++$_
- $_ = 'z'
- print ++$_
- *My::Namespace:: = %Your::Namespace
- my $method = 'foo';
- my $obj = My::Class->new();
- $obj->$method( 'baz' ); # calls $obj->foo( 'baz' )
- *foo = sub { print "Hello world" };
- use subs 'unlink';
- sub unlink { print 'No.' }
- BEGIN{
- *CORE::GLOBAL::unlink = sub {print 'no'}
- };
- unlink($_) for @ARGV
- my $url = q{http://my.url.com/any/arbitrary/path/in/the/url.html};
- my $var = q#some string where the pound is the final escape.#;
- my $var2 = q{A more pleasant way of escaping.};
- my $var3 = q(Others prefer parens as the quote mechanism.);
- my $var4 = qq{This "$mechanism" is broken. Please inform "$user" at "$email" about it.};
- my $output = qx{type "$path"}; # get just the output
- my $moreout = qx{type "$path" 2>&1}; # get stuff on stderr too
- sub MyRegexCheck {
- my ($string, $regex) = @_;
- if ($string)
- {
- return ($string =~ $regex);
- }
- return; # returns 'null' or 'empty' in every context
- }
- my $regex = qr{http://[w].com/([w]+/)+};
- @results = MyRegexCheck(q{http://myurl.com/subpath1/subpath2/}, $regex);
- my @allowed = qw(A B C D E F G H I J K L M N O P Q R S T U V W X Y Z { });
- my @badwords = qw(WORD1 word2 word3 word4);
- my @numbers = qw(one two three four 5 six seven); # works with numbers too
- my @list = ('string with space', qw(eight nine), "a $var"); # works in other lists
- my $arrayref = [ qw(and it works in arrays too) ];
- for ($item)
- {
- s/ / /g;
- s/<.*?>/ /g;
- $_ = join(" ", split(" ", $_));
- }
- my @list = ('abc', 'def', 'ghi', 'jkl');
- my @list = qw(abc def ghi jkl);
- print 1, 2, 3, ;
- print
- results_of_foo(),
- results_of_xyzzy(),
- results_of_quux(),
- ;
- my @lines = <DATA>;
- for (@lines) {
- print if /bad/;
- }
- __DATA__
- some good data
- some bad data
- more good data
- more good data
- sub do_stuff_with_a_hash (&%) {
- my ( $block_of_code, $hash_ref ) = @_;
- while ( my ( $k, $v ) = each %$hash_ref ) {
- $block_of_code->( $k, $v );
- }
- }
- use Data::Dumper;
- do_stuff_with_a_hash {
- local $Data::Dumper::Terse = 1;
- my ( $k, $v ) = @_;
- say qq(Hey, the key is "$k"!);
- say sprintf qq(Hey, the value is "%v"!), Dumper( $v );
- } %stuff_for
- ;
- perl -MLib::DB -MLib::TL -e 'run_expensive_database_delete() if $hour_of_day < AM_7';
- my $old_die_handler = $SIG{__DIE__};
- $SIG{__DIE__}
- = sub { say q(Hey! I'm DYIN' over here!); goto &$old_die_handler; }
- ;
- overload::constant
- integer => sub {
- my $lit = shift;
- return $lit > 2_000_000_000 ? Math::BigInt->new( $lit ) : $lit
- };
- print '-' x 80; # print row of dashes
- print for (1, 4, 9) x 3; # print 149149149
- ls |perl -lne 'print $_; }{ print "$. Files"'
- LINE: while (defined($_ = <ARGV>)) {
- print $_; }{ print "$. Files";
- }
- $a = 5 <=> 7; # $a is set to -1
- $a = 7 <=> 5; # $a is set to 1
- $a = 6 <=> 6; # $a is set to 0
- while( <> ){
- print "top of loopn";
- chomp;
- next if /next/i;
- last if /last/i;
- print "bottom of loopn";
- }continue{
- print "continuen";
- }
- while(/G(bw*b)/g) {
- print "$1n";
- }
- while (<>) {
- ... # code for each line
- }
- BEGIN {
- eval {
- require 'config.local.pl';
- };
- if ($@) {
- require 'config.default.pl';
- }
- }
- rename("$_.part", $_) for "data.txt";
- print ~~ localtime;
- print scalar localtime;
- print localtime;
- SKIP: {
- skip() if $something;
- print "Never printed";
- }
- sub skip {
- no warnings "exiting";
- last SKIP;
- }
- local $SIG{__WARN__} = sub { die @_ };
- $num = "two";
- $sum = 1 + $num;
- print "Never reached";
- $_ = "foo bar";
- my $count =()= /[aeiou]/g; #3
- sub foo {
- return @_;
- }
- $count =()= foo(qw/a b c d/); #4
Add Comment
Please, Sign In to add comment