2017-02-01 5 views
0

Ich versuche, R zu verwenden, um ein Perl-Skript in eine Textdatei zu schreiben. Ich kann einfach nicht herausfinden, wie ich bestimmten Charakteren entkommen kann.In Textdatei schreiben, Sonderzeichen aber umgehen

Ich habe Backslash (einfach und doppelt), eckige Klammern, "\\ Q ... \\ E" usw. verwendet, aber es kann immer noch nicht funktionieren.

Jede Hilfe wäre willkommen. Danke im Voraus!

taskFilename = "example.txt" 

cat(" 
    #!/usr/bin/perl 
    use strict; 
    use warnings; 

    use File::Find; 
    use File::Temp qw(tempfile); 

    my @imagedir_roots = ("/Users/Ross/Desktop/images"); 

    my $parallel = 8; 

    my $exiftool_command = 'exiftool -all= -tagsfromfile @ -all:all --gps:all --xmp:geotag -unsafe -icc_profile -overwrite_original'; 

    # Create the (temporary) [email protected] files 
    my @atfiles; 
    my @atfilenames; 
    for (my $i = 0; $i < $parallel; ++$i) { 
    my ($fh, $filename) = tempfile(UNLINK => 1); 
    push @atfiles, $fh; 
    push @atfilenames, $filename; 
    } 

    # Gather all JPG image files and distribute them over the [email protected] files 
    my $nr = 0; 
    find(sub { print { $atfiles[$nr++ % $parallel] } "$File::Find::name\n" if (-f && /\.(?:jpg|jpeg)/i); }, @imagedir_roots); 

    # Process all images in parallel 
    printf("Processing %d JPG files...\n", $nr); 
    for (my $i = 0; $i < $parallel; ++$i) { 
    close($atfiles[$i]); 
    my $pid = fork(); 
    if (!$pid) { 
    # Run exiftool in the background 
    system qq{$exiftool_command [email protected] \"$atfilenames[$i]\"}; 
    last; 
    } 
    } 

    # Wait for processes to finish 
    while (wait() != -1) {} 

    ", fill = TRUE, file = taskFilename 
) 

Antwort

1

Ich spielte auch mit diesem einmal. Wenn ich mich richtig erinnere:

  • die doppelten Anführungszeichen müssen Sie mit \
  • entkommen, wenn Sie einen \ schreiben möchten Sie auch fliehen müssen, um es mit \
  • , wenn Sie einen \ schreiben wollen“Sie müssen „

taskFilename = "example.txt"

cat(" 
    #!/usr/bin/perl 
    use strict; 
    use warnings; 

    use File::Find; 
    use File::Temp qw(tempfile); 

    my @imagedir_roots = (\"/Users/Ross/Desktop/images\"); 

    my $parallel = 8; 

    my $exiftool_command = 'exiftool -all= -tagsfromfile @ -all:all --gps:all --xmp:geotag -unsafe -icc_profile -overwrite_original'; 

    # Create the (temporary) [email protected] files 
    my @atfiles; 
    my @atfilenames; 
    for (my $i = 0; $i < $parallel; ++$i) { 
    my ($fh, $filename) = tempfile(UNLINK => 1); 
    push @atfiles, $fh; 
    push @atfilenames, $filename; 
    } 

    # Gather all JPG image files and distribute them over the [email protected] files 
    my $nr = 0; 
    find(sub { print { $atfiles[$nr++ % $parallel] } \"$File::Find::name\n\" if (-f && /\\.(?:jpg|jpeg)/i); }, @imagedir_roots); 

    # Process all images in parallel 
    printf(\"Processing %d JPG files...\n\", $nr); 
    for (my $i = 0; $i < $parallel; ++$i) { 
    close($atfiles[$i]); 
    my $pid = fork(); 
    if (!$pid) { 
    # Run exiftool in the background 
    system qq{$exiftool_command [email protected] \\\"$atfilenames[$i]\\\"}; 
    last; 
    } 
    } 

    # Wait for processes to finish 
    while (wait() != -1) {} 

    ", fill = TRUE, file = taskFilename 
) 

+0

Vielen Dank an \\! Perfekt funktioniert. – Ross