in reply to writing to a file when using diamond operator
You need to open the file before you start the loop and close it after you finish reading it.
#!/usr/bin/perl use warnings; use strict; my $fichier_sortie = 'sortie.txt'; open my $sortie, '>', $fichier_sortie or die "Can't open $Fichiersor +tie: $!"; while (<>){ chomp; my $voir = $_; $voir =~ s/o/y/g; say {$sortie} $voir; } close $sortie;
Update: Fixed a bug (I said "after you finish", but didn't).
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: writing to a file when using diamond operator
by paschacroutt (Acolyte) on May 03, 2024 at 15:20 UTC | |
by choroba (Cardinal) on May 03, 2024 at 15:34 UTC | |
by paschacroutt (Acolyte) on May 03, 2024 at 16:08 UTC | |
by choroba (Cardinal) on May 03, 2024 at 16:13 UTC | |
by paschacroutt (Acolyte) on May 03, 2024 at 16:17 UTC |