Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: Writing many lines to a file

by uday_sagar (Scribe)
on Jul 16, 2012 at 13:10 UTC ( [id://982031]=note: print w/replies, xml ) Need Help??


in reply to Writing many lines to a file

Daxim,

The twist is- I shouldnt copy that file, but put the contents of the file in perl program itself.

gri,

I have different lines, not the same one to be repeated.

Replies are listed 'Best First'.
Re^2: Writing many lines to a file
by cavac (Parson) on Jul 16, 2012 at 13:27 UTC

    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);

    "I know what i'm doing! Look, what could possibly go wrong? All i have to pull this lever like so, and then press this button here like ArghhhhhaaAaAAAaaagraaaAAaa!!!"

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://982031]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (5)
As of 2024-03-29 13:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found