Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Perl Fitxers i Directoris

751 views

Published on

Perl Poetry with IO syntax

Published in: Technology, News & Politics
  • Be the first to comment

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 $!;

×