Reputation: 11
I tried to create a word list starting with 0500000000 to 0600000000 with Perl code
#!/bin/perl -w
$k = 10;
$width = 10;
for $i ( 500000000 .. 600000000 ) {
printf "%${width}.${k}ld\n", $i;
}
I need to print the result to a text file. Can anyone help?
Upvotes: 1
Views: 305
Reputation: 231
Using filehandles. For instance:
#!/usr/bin/env perl
use strict;
use warnings FATAL => 'all';
use autodie qw(:all);
open my $FILE, '>', 'filename.txt';
my $k = 10;
my $width = 10;
for $i ( 500000000 .. 600000000 ) {
printf {$FILE} "%${width}.${k}ld\n", $i;
}
close $FILE;
Use file mode >
to truncate any existing file, or >>
to append to it.
Upvotes: 4
Reputation: 1421
Why not use STDOUT redirection?
# perl yourscript.pl > yourfile.txt
Upvotes: 2
Reputation: 118118
$ perl -e 'print "$_\n" for "0500000000" .. "0600000000"' > output.txt
Upvotes: 5