in reply to Re: Writing many lines to a file
in thread Writing many lines to a file
Ok, what you are saying is, you want to include that data within the perl script and write it out as a text file, correct?
First approach is to copy the data into the __DATA__ segment of the script:
#!/usr/bin/env perl use strict; use warnings; open(my $ofh, '>', 'outfile.txt') or die($!); while((my $line = <DATA>)) { print $ofh $line; } close($ofh); __DATA__ Line 1 Line 2 Line 3 Line 4
Or, you can use HEREDOCs
#!/usr/bin/env perl use strict; use warnings; open(my $ofh, '>', 'outfile.txt') or die($!); print $ofh <<ENDFILE; Line 1 Line 2 Line 3 Line 4 ENDFILE close($ofh);
|
|---|