my %chart = ( name => 'vote', data => get_vote_data(), # assumed to return a scalar colors => join ',', 'red', 'green', 'blue', shape => 'bar', ); print $chart{name}, "\n"; # 'vote' print $chart{colors}, "\n"; # oops: 'red,green,blue,shape,cubic' #### if ($true) { $var = $value; next; } #### while (1) { warn 1, 2, 3, last if 1; } #### $ perl -MO=Deparse,-p -e 'while (1) { warn 1, 2, 3, last if 1 }' while (1) { warn(1, 2, 3, last); } -e syntax OK #### my %chart = ( name => 'vote', data => get_vote_data(), # assumed to return a scalar colors => join(',', 'red', 'green', 'blue'), shape => 'bar', ); print $chart{name}, "\n"; # 'vote' print $chart{colors}, "\n"; # 'red,green,blue' #### while (1) { warn(1, 2, 3), last if 1; } #### while (1) { if (1) { warn 1, 2, 3; last; } } #### $ perl -e 'print chr $ARGV[0], $ARGV[1]' 66 67 B67 #### $ perl -MO=Deparse,-p -e 'print chr $ARGV[0], $ARGV[1]' 66 67 print(chr($ARGV[0]), $ARGV[1]); -e syntax OK #### $ perl -e 'print time, "TZ"' 1191177816TZ #### my $line = 'book|perl|programming'; my @fields = split /\|/, $line; #### my $line = 'book|perl|programming'; my @fields = split /\|/, $line, 2; #### my $line = 'Practical extraction and report language'; my $part = substr $line, 10; #### my $line = 'Practical extraction and report language'; my $what = substr $line, 10, 21; # extraction and report #### sub upstream { my(@source, @destination) = @_; my $src_place = $source[0]; # 'here' my $dest_place = $destination[0]; # undefined } my @src = qw(here sender OK); my @dest = qw(there recipient UNKNOWN); upstream(@src, @dest); #### sub upstream { my($source, $destination) = @_; my $src_place = $source->[0]; # 'here' my $dest_place = $destination->[0]; # 'there' } my @src = qw(here sender OK); my @dest = qw(there recipient UNKNOWN); upstream(\@src, \@dest); #### sub get_group { my $user_id = shift; my @special_groups = get_special_group($user_id); # ex: 'cdrom', 'games' my @normal_groups = get_normal_group($user_id); # ex: 'westteam', 'marketing', 'committee' return @special_groups, @normal_groups; } my(@specail, @normal) = get_group(1002); print $special[-1]; # 'games' print $normal[0]; # undefined #### sub get_group { my $user_id = shift; my @special_groups = get_special_group($user_id); # ex: 'cdrom', 'games' my @normal_groups = get_normal_group($user_id); # ex: 'westteam', 'marketing', 'committee' return \@special_groups, \@normal_groups; } my($specail, $normal) = get_group(1002); print $special->[-1]; # 'games' print $normal->[-1]; # 'committee' #### # syntax: keys HASH my $rgb = { red => 0x00f, green => 0xf00, blue => 0x0f0 }; # from perldata my @keys = keys $rgb; # fatal: Type of arg 1 to keys must be hash my @keys = keys %$rgb; # correct my @keys = keys %ENV; # correct # syntax: push ARRAY,LIST # first example my @names = original_member(); my @new_members = get_new_members('20071001'); push @names, @new_members; # second example 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 #### sub mypush { my(@target_array, @new_elements) = @_; ... }