- Timestamp:
- 09/06/07 19:43:34 (16 months ago)
- Location:
- examples
- Files:
-
- 20 modified
-
advocacy/motd-i.pl (modified) (1 diff)
-
advocacy/motd.pl (modified) (1 diff)
-
cookbook/07file-access/07-01opening_file.pl (modified) (2 diffs)
-
cookbook/07file-access/07-04making_perl_report_filenames_in_error_messages.pl (modified) (1 diff)
-
games/hangman.pl (modified) (1 diff)
-
games/hangman.pod (modified) (1 diff)
-
golf/tsanta.pl (modified) (4 diffs)
-
irclog2html.pl (modified) (2 diffs)
-
matrix.pl (modified) (1 diff)
-
naive_bayesian/naive_bayesian.pl (modified) (3 diffs)
-
network/hangmanbot.pl (modified) (1 diff)
-
p6explain/p6explain (modified) (1 diff)
-
password-manager.p6 (modified) (4 diffs)
-
perl5/cpan-upload.pl (modified) (1 diff)
-
perldoc.pl (modified) (4 diffs)
-
qotw/019r/qotw-regular-19.pl (modified) (1 diff)
-
qotw/024r/qotw-regular-24.pl (modified) (2 diffs)
-
rpn/p6/Rpn.pm (modified) (1 diff)
-
rules/rpn_calc.pl (modified) (1 diff)
-
rules/unitsdat-grammar.pm (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
examples/advocacy/motd-i.pl
r15167 r17701 14 14 my $dict = canonpath("$progdir/pugspraise"); 15 15 16 my $fh = open($dict) errdie $!;16 my $fh = open($dict) orelse die $!; 17 17 18 18 for =$fh->$line { -
examples/advocacy/motd.pl
r11293 r17701 12 12 my $limit = @*ARGS[0] // '2'; 13 13 my $dict = canonpath("$progdir/pugspraise"); 14 my $fh = open $dict errdie $!;14 my $fh = open $dict orelse die $!; 15 15 my @list = =$fh; 16 16 -
examples/cookbook/07file-access/07-01opening_file.pl
r11293 r17701 10 10 11 11 my $input = open($path, :r) 12 errdie "Could not open $path for reading $!\n";12 orelse die "Could not open $path for reading $!\n"; 13 13 14 14 my $filename = "test_file"; 15 15 my $output = open($filename, :w) 16 errdie "Could not open $filename for writing $!\n";16 orelse die "Could not open $filename for writing $!\n"; 17 17 18 18 … … 29 29 30 30 # Closing the file 31 # $input.close errdie $!;31 # $input.close orelse die $!; 32 32 # close($input); 33 33 -
examples/cookbook/07file-access/07-04making_perl_report_filenames_in_error_messages.pl
r11293 r17701 9 9 10 10 #my $fh = open($path) 11 # errdie "Could not open '$path' for reading: $!\n";11 # orelse die "Could not open '$path' for reading: $!\n"; 12 12 -
examples/games/hangman.pl
r12799 r17701 18 18 sub get_committer_list (Str $dict_file) returns List { 19 19 my @committers; 20 my $dict = open($dict_file) errdie "Couldn't open the AUTHORS file.\nYou must run this script from within the main pugs\ndirectory or within the examples/ sub-directory.";20 my $dict = open($dict_file) orelse die "Couldn't open the AUTHORS file.\nYou must run this script from within the main pugs\ndirectory or within the examples/ sub-directory."; 21 21 22 22 # Skip the intro text -
examples/games/hangman.pod
r6851 r17701 11 11 =head1 sub get_committer_list 12 12 13 C< err> is the low precedence form of C<//> (S03). C<//> is especially useful13 C<orelse> is the low precedence form of C<//> (S03). C<//> is especially useful 14 14 in its assignment form: 15 15 16 16 $x //= $y; 17 17 18 To summarize, C<||> and C<or> relate to truth, while C<//> and C< err> relate18 To summarize, C<||> and C<or> relate to truth, while C<//> and C<orelse> relate 19 19 to definedness. 20 20 -
examples/golf/tsanta.pl
r15167 r17701 24 24 25 25 sub golf_score (Str $script) returns Int { 26 my $fh = open($script) errdie("open '$script' failed: $!");26 my $fh = open($script) orelse die("open '$script' failed: $!"); 27 27 my $golf = 0; 28 28 my $dollar_dot = 0; # Note: $. aka $fh.linenum() not implemented yet … … 32 32 unless $dollar_dot==1 && $line.index("#!") == 0; 33 33 } 34 $fh.close() errdie("close '$script' failed: $!");34 $fh.close() orelse die("close '$script' failed: $!"); 35 35 return $golf; 36 36 } … … 43 43 44 44 sub build_file (Str $fname, Str $data) { 45 my $fh = open($fname, :w) errdie("open '$fname' failed: $!");46 $fh.print($data) errdie("print '$fname' failed: $!");47 $fh.close() errdie("close '$fname' failed: $!");45 my $fh = open($fname, :w) orelse die("open '$fname' failed: $!"); 46 $fh.print($data) orelse die("print '$fname' failed: $!"); 47 $fh.close() orelse die("close '$fname' failed: $!"); 48 48 } 49 49 … … 53 53 print("$label: running: '$cmd'..."); 54 54 # my $out = `$cmd`; 55 system($cmd) errdie("system '$cmd' failed: $!");55 system($cmd) orelse die("system '$cmd' failed: $!"); 56 56 # XXX: get return code. how? $!? (I think $? is obsolete in p6). 57 57 my $rc = 0; 58 my $out = slurp($outtmp) errdie("slurp '$outtmp' failed: $!");58 my $out = slurp($outtmp) orelse die("slurp '$outtmp' failed: $!"); 59 59 # my $rc = $? >> 8; 60 60 say("done (rc=$rc)"); -
examples/irclog2html.pl
r13342 r17701 72 72 73 73 # Pass I 74 my $fh = open @*ARGS[0] errdie "Couldn't open \"@*ARGS[0]\": $!\n";74 my $fh = open @*ARGS[0] orelse die "Couldn't open \"@*ARGS[0]\": $!\n"; 75 75 my $total = 0; 76 76 … … 99 99 100 100 # Pass I 101 $fh = open @*ARGS[0] errdie "Couldn't open \"@*ARGS[0]\": $!\n";101 $fh = open @*ARGS[0] orelse die "Couldn't open \"@*ARGS[0]\": $!\n"; 102 102 103 103 # This is the main coderef which processes a logline and returns HTML. -
examples/matrix.pl
r16636 r17701 69 69 70 70 gather { 71 for slurp '/usr/share/dict/words' :chomp errdie {71 for slurp '/usr/share/dict/words' :chomp orelse die { 72 72 next if /<-[a-z]>/; 73 73 /$re/ and take { word => $_, score => %scores{ .letters }.sum }; -
examples/naive_bayesian/naive_bayesian.pl
r15167 r17701 5 5 sub load_db returns Void { 6 6 return() unless "words.db.pl" ~~ :e; 7 my $db = open("words.db.pl") errdie "Cannot open the words.db.pl file: $!";7 my $db = open("words.db.pl") orelse die "Cannot open the words.db.pl file: $!"; 8 8 for (=$db) -> $_line { 9 9 my $line = $_line; … … 15 15 16 16 sub save_db returns Void { 17 my $db = open("words.db.pl", :w) errdie "Cannot open the words.db.pl file: $!";17 my $db = open("words.db.pl", :w) orelse die "Cannot open the words.db.pl file: $!"; 18 18 for (%words.kv) -> $key, $value { 19 19 $db.say($key ~ "\t" ~ $value); … … 24 24 sub parse_file (Str $file) returns Hash { 25 25 my %words_in_file; 26 my $fh = open("$file") errdie "Cannot open the '$file' file: $!";26 my $fh = open("$file") orelse die "Cannot open the '$file' file: $!"; 27 27 for (=$fh) -> $_line { 28 28 my $line = $_line; -
examples/network/hangmanbot.pl
r12807 r17701 20 20 sub get_committer_list(Str $dict_file) returns List { 21 21 my @committers; 22 my $dict = open($dict_file) err22 my $dict = open($dict_file) orelse 23 23 die "Couldn't open \"$dict_file\": $!\n"; 24 24 -
examples/p6explain/p6explain
r11293 r17701 6 6 7 7 # Parsing the dat 8 my $fh = open $dat errdie "Couldn't open \"$dat\" for reading: $!\n";8 my $fh = open $dat orelse die "Couldn't open \"$dat\" for reading: $!\n"; 9 9 for =$fh { 10 10 state $cur_entry; -
examples/password-manager.p6
r16177 r17701 90 90 91 91 sub xclip(Str $s -->) { 92 my IO $xclip = Pipe.to: 'xclip' errabort 'No xclip - use .p';92 my IO $xclip = Pipe.to: 'xclip' orelse abort 'No xclip - use .p'; 93 93 $xclip.print: $s; 94 94 $xclip.close; … … 98 98 my Str $pw = %pw{$s}<pass> // 99 99 first Str, (%pw{$_}<pass> if /$s/ for %pw.keys) 100 errabort "Couldn't find account $s";100 orelse abort "Couldn't find account $s"; 101 101 xclip $pw; 102 102 cmt if $changed; … … 117 117 118 118 sub cmt(-->) { 119 unlink 'pwd.gpg.old' errabort "Couldn't unlink: $!";120 rename 'pwd.gpg', 'pwd.gpg.old' errabort "Couldn't rename: $!";119 unlink 'pwd.gpg.old' orelse abort "Couldn't unlink: $!"; 120 rename 'pwd.gpg', 'pwd.gpg.old' orelse abort "Couldn't rename: $!"; 121 121 my IO $pwd = Pipe.to: 'gpg --symmetric --force-mdc --cipher-algo AES256 --output pwd.gpg' 122 errabort "Couldn't encrypt: $!";122 orelse abort "Couldn't encrypt: $!"; 123 123 for %pw.keys -> $k { $pwd.say: $k, "\t", %pw{$k}<pass user>.join("\t") } 124 124 if $pwd.close { … … 168 168 %*ENV<PATH> = '/bin:/usr/bin:/usr/bin/X11'; 169 169 umask 0o77; 170 chdir "$+HOME/pw" errdie "Couldn't cd: $!";171 my IO $pwd = Pipe.from: 'gpg --output - --decrypt pwd.gpg' errdie "Couldn't decrypt: $!";170 chdir "$+HOME/pw" orelse die "Couldn't cd: $!"; 171 my IO $pwd = Pipe.from: 'gpg --output - --decrypt pwd.gpg' orelse die "Couldn't decrypt: $!"; 172 172 for =$pwd { 173 173 /<pwent>/ or die 'Malformed line ', $pwd.linenum, ": $_\n"; -
examples/perl5/cpan-upload.pl
r15167 r17701 230 230 #------------------------------------------------------------------- 231 231 _debug(" creating instance of LWP::UserAgent\n"); 232 $agent = LWP::UserAgent.new() errdie "Failed to create UserAgent: $!\n";232 $agent = LWP::UserAgent.new() orelse die "Failed to create UserAgent: $!\n"; 233 233 $agent.agent("$PROGRAM/$VERSION"); 234 234 $agent.from($config.mailto); -
examples/perldoc.pl
r15167 r17701 46 46 sub display_pod { 47 47 my ($podfile) = @_; 48 my $fh = open $podfile errdie "Could not open '$podfile'\n";48 my $fh = open $podfile orelse die "Could not open '$podfile'\n"; 49 49 for =$fh -> $line { 50 50 say $line; … … 62 62 for list_files(dirname($PROGRAM_NAME)) -> $podfile { 63 63 say "Processing '$podfile'"; 64 my $fh = open $podfile errdie "Could not open '$podfile'\n";64 my $fh = open $podfile orelse die "Could not open '$podfile'\n"; 65 65 my $row = 0; 66 66 my $section; … … 86 86 sub list_files ($dir, $full) { 87 87 #say "opening $dir"; 88 my $dh = opendir $dir errdie "Could not open $dir";88 my $dh = opendir $dir orelse die "Could not open $dir"; 89 89 my @entries; 90 90 for $dh.readdir -> $entry { … … 111 111 my ($row, $file) = split /\./, $entry, 2; 112 112 say "here: $file $row"; 113 my $fh = open $file errdie "Could not open $file";113 my $fh = open $file orelse die "Could not open $file"; 114 114 for (0..$row) { 115 115 =$fh; -
examples/qotw/019r/qotw-regular-19.pl
r15167 r17701 9 9 $scale //= 100; 10 10 11 my $FH = open $file errdie "Could't open \"$file\"!\n";11 my $FH = open $file orelse die "Could't open \"$file\"!\n"; 12 12 13 13 for =$FH -> $line { -
examples/qotw/024r/qotw-regular-24.pl
r11275 r17701 2 2 # http://perl.plover.com/qotw/r/solution/024. 3 3 4 my $transition_file = @*ARGS[0] err4 my $transition_file = @*ARGS[0] orelse 5 5 die "Usage: $*PROGRAM_NAME transition_file [initial_tape]\n"; 6 6 … … 15 15 my $tape_loc = 0; 16 16 17 my $trans = open $transition_file err17 my $trans = open $transition_file orelse 18 18 die "Can't open \"$transition_file\" for reading!\n"; 19 19 -
examples/rpn/p6/Rpn.pm
r8662 r17701 17 17 next; 18 18 } 19 my $x = @stack.pop() errdie "Stack underflow\n";20 my $y = @stack.pop() errdie "Stack underflow\n";19 my $x = @stack.pop() orelse die "Stack underflow\n"; 20 my $y = @stack.pop() orelse die "Stack underflow\n"; 21 21 22 22 # given/when is a sexy new P6 construct that can avoid -
examples/rules/rpn_calc.pl
r12581 r17701 50 50 next; 51 51 } 52 my $x = @stack.pop() errdie "Stack underflow\n";53 my $y = @stack.pop() errdie "Stack underflow\n";52 my $x = @stack.pop() orelse die "Stack underflow\n"; 53 my $y = @stack.pop() orelse die "Stack underflow\n"; 54 54 55 55 # given/when is a sexy new P6 construct that can avoid -
examples/rules/unitsdat-grammar.pm
r16652 r17701 732 732 # NumUnit handles most of the traditional unit stuff via units.dat. 733 733 my $unitsdat = open "/usr/share/misc/units.dat" 734 errdie "You don't have a readable /usr/share/misc/units.dat: $!";734 orelse die "You don't have a readable /usr/share/misc/units.dat: $!"; 735 735 cat =$unitsdat ~~ /<UnitsDat>/; 736 736 $unitsdat.close;
