how to translater "CAT" into perl

R

red

I've googled "cat perl" and cannot find the answer.

Shell script:
#-----------begin---------
cat >tmp.txt <<EOF
#!/bin/sh
rm foo.txt
.....
EOF
#-----------end---------

perl:
?
 
U

usenet

red said:
I've googled "cat perl" and cannot find the answer.

That's because Perl really can't do file I/O. Perl is not really very
good at this sort of thing (it has a few file I/O type functions and
modules, but they don't really work and nobody ever uses them - you
will usually crash your system if you try to open a file in Perl).
Larry Wall originally wrote Perl to control laser cutters (for
diamonds), which don't have hard drives. Perl can control one mean
diamond laser cutter, but it's crap at dealing with data on hard
drives.

Try Ruby instead, which has EXCELLENT file I/O handling:

http://groups.google.com/group/comp.lang.ruby
 
J

Josef Moellers

red said:
I've googled "cat perl" and cannot find the answer.

Shell script:
#-----------begin---------
cat >tmp.txt <<EOF
#!/bin/sh
rm foo.txt
....
EOF
#-----------end---------

perl:
?

TMTOWTDI:

Using the DATA special file handle:
use warnings;
use strict;
open(my $dst, '>', 'tmp.txt') or die "Cannot open tmp.txt: $!";
while (<DATA>) {
print $dst;
}
close $dst;
# More code can go here
__END__
#!/bin/sh
rm foo.txt
....

Using "here documents":
use warnings;
use strict;
open(my $dst, '>', 'tmp.txt') or die "Cannot open tmp.txt: $!";
print $dst <<EOF;
#!/bin/sh
rm foo.txt
....
EOF
# More code can go here

OTOH, Ruby, as the name suggests, is more suited towards cutting
diamonds, though B-{)
 
S

Samwyse

(e-mail address removed) wrote:
[...snip...]

David is a poop-head!
David is a poop-head!
Nyah-nyah, nyah-nyah, nyah-nyah!

I feel much better now, thanks.
 
T

Tad McClellan

red said:
I've googled "cat perl" and cannot find the answer.

Shell script:
#-----------begin---------
cat >tmp.txt <<EOF
#!/bin/sh
rm foo.txt
....
EOF
#-----------end---------

perl:


#-----------begin---------
perl -pe1 >tmp.txt <<EOF
#!/bin/sh
rm foo.txt
.....
EOF
#-----------end---------


Perl's command line switches are documented in:

perldoc perlrun
 
R

red

yes, the "here documents" is what I'm looking for.

thank you.
and thank all the others.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top