Perl Fitxers i Directoris

695 views
658 views

Published on

Perl Poetry with IO syntax

Published in: Technology, News & Politics
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
695
On SlideShare
0
From Embeds
0
Number of Embeds
5
Actions
Shares
0
Downloads
10
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Perl Fitxers i Directoris

  1. 1. Fitxers I Directoris
  2. 2. Poesia del Perl
  3. 3. open my $me,<,$0 or die $!while (<$me>) { chomp; say if length;}my $beyond = <$me> and print "there is $beyond me !";close $me;
  4. 4. Variables Explícites open my $me,<,$0 or die $! while (my $line=<$me>) { chomp $line; say $line if length; } my $beyond = <$me> and print "there is $beyond me !"; close $me;
  5. 5. FileHandler● <$filehandler>
  6. 6. Openopen my $filehandler,”MODE”,$filename or die $!;
  7. 7. Modes<>>>+<
  8. 8. Modes< : open my $fhr,<,”filename”>>>+<
  9. 9. Modes<> : open my $fhw,>,”filename”>>+<
  10. 10. More info● perldoc perlopentut● perldoc perlfaq5
  11. 11. closingclose $fh or die $!;
  12. 12. Reading● Readline: <>
  13. 13. Reading● Readline: <> while (my $line=<$fh>) { chomp $line; say "Read a line $line"; }
  14. 14. Readingmy @contents = <$fh>;print @contents
  15. 15. Writingopen my $fh_out , > , ”output.txt” or die $!;for my $number ( 1 .. 9 ) { print $fh_out “$numbern”;}close $fh_out or die $!;
  16. 16.   special variables● $.● $/● $|
  17. 17. Directoris i Pathsopendir my $dir,”tasks/circus”;while (my $task = readdir $dir){ next if /^./; print “$taskn”;}
  18. 18. ­X● -f● -d● -r● -z● perldoc -f -r
  19. 19. rename● rename OLDNAME,NEWNAME rename $oldname,$newname or die “No puc renombrar $oldname a $newname”
  20. 20. copy and move● use File::Copy
  21. 21. unlinkunlink $filename or die “No puc esborrar $filename. $!”;
  22. 22. chdirchdir $directori or die “No puc anar a $directori. $!”;
  23. 23. Executar codiopen my $fh, ”-|” , ”ls” or die $!;while (<$fh>) { print;}close $fh
  24. 24. Executar codiopen my $spam,|- ,mailx -s “assumpte” algu@domini.edu or die $!;for my $lletra ( a .. z ) { print $spam “$lletran”;}close $spam;
  25. 25. close $show;
  26. 26. close $show or die $!;

×