Help for this page

Select Code to Download


  1. or download this
    my %chart = (
      name => 'vote',
    ...
    
    print $chart{name}, "\n";   # 'vote'
    print $chart{colors}, "\n"; # oops: 'red,green,blue,shape,cubic'
    
  2. or download this
    if ($true) {
      $var = $value;
      next;
    }
    
  3. or download this
    while (1) {
      warn 1, 2, 3, last if 1;
    }
    
  4. or download this
    $ perl -MO=Deparse,-p -e 'while (1) { warn 1, 2, 3, last if 1 }'
    while (1) {
      warn(1, 2, 3, last);
    }
    -e syntax OK
    
  5. or download this
    my %chart = (
      name => 'vote',
    ...
    
    print $chart{name}, "\n";   # 'vote'
    print $chart{colors}, "\n"; # 'red,green,blue'
    
  6. or download this
    while (1) {
      warn(1, 2, 3), last if 1;
    }
    
  7. or download this
    while (1) {
      if (1) {
    ...
        last;
      }
    }
    
  8. or download this
    $ perl -e 'print chr $ARGV[0], $ARGV[1]' 66 67
    B67
    
  9. or download this
    $ perl -MO=Deparse,-p -e 'print chr $ARGV[0], $ARGV[1]' 66 67
    print(chr($ARGV[0]), $ARGV[1]);
    -e syntax OK
    
  10. or download this
    $ perl -e 'print time, "TZ"'
    1191177816TZ
    
  11. or download this
    my $line = 'book|perl|programming';
    my @fields = split /\|/, $line;
    
  12. or download this
    my $line = 'book|perl|programming';
    my @fields = split /\|/, $line, 2;
    
  13. or download this
    my $line = 'Practical extraction and report language';
    my $part = substr $line, 10;
    
  14. or download this
    my $line = 'Practical extraction and report language';
    my $what = substr $line, 10, 21; # extraction and report
    
  15. or download this
    sub upstream {
      my(@source, @destination) = @_;
    ...
    my @src = qw(here sender OK);
    my @dest = qw(there recipient UNKNOWN);
    upstream(@src, @dest);
    
  16. or download this
    sub upstream {
      my($source, $destination) = @_;
    ...
    my @src = qw(here sender OK);
    my @dest = qw(there recipient UNKNOWN);
    upstream(\@src, \@dest);
    
  17. or download this
    sub get_group {
      my $user_id = shift;
    ...
    my(@specail, @normal) = get_group(1002);
    print $special[-1]; # 'games'
    print $normal[0]; # undefined
    
  18. or download this
    sub get_group {
      my $user_id = shift;
    ...
    my($specail, $normal) = get_group(1002);
    print $special->[-1]; # 'games'
    print $normal->[-1]; # 'committee'
    
  19. or download this
    # syntax: <c>keys HASH</c>
    my $rgb = { red => 0x00f, green => 0xf00, blue => 0x0f0 }; # from perl
    +data
    ...
    my $another_members = [qw(ray tom dave)];
    push $another_members, @names; # fatal: Type of arg 1 to push must be 
    +array
    push @$another_members, @names; # correct
    
  20. or download this
    sub mypush {
      my(@target_array, @new_elements) = @_;
      ...
    }