Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > how to translater "CAT" into perl

Reply
Thread Tools

how to translater "CAT" into perl

 
 
red
Guest
Posts: n/a
 
      01-18-2006
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:
?

 
Reply With Quote
 
 
 
 
usenet@DavidFilmer.com
Guest
Posts: n/a
 
      01-18-2006
red wrote:
> 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

 
Reply With Quote
 
 
 
 
Josef Moellers
Guest
Posts: n/a
 
      01-18-2006
red wrote:
> 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-{)
--
Josef Mo"llers (Pinguinpfleger bei FSC)
If failure had no penalty success would not be a prize
-- T. Pratchett

 
Reply With Quote
 
Samwyse
Guest
Posts: n/a
 
      01-18-2006
http://www.velocityreviews.com/forums/(E-Mail 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.
 
Reply With Quote
 
Paul Lalli
Guest
Posts: n/a
 
      01-18-2006
red wrote:
> I've googled "cat perl" and cannot find the answer.


Did you even attempt to google for what "cat" does? Thing like "open"
or "print"?

Have you read *any* Perl documentation?

http://learn.perl.org
http://perldoc.perl.org

are good places for you to go.

 
Reply With Quote
 
Tad McClellan
Guest
Posts: n/a
 
      01-18-2006
red <(E-Mail Removed)> wrote:
> 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


--
Tad McClellan SGML consulting
(E-Mail Removed) Perl programming
Fort Worth, Texas
 
Reply With Quote
 
red
Guest
Posts: n/a
 
      01-19-2006
yes, the "here documents" is what I'm looking for.

thank you.
and thank all the others.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
FAQ 1.4 What are Perl 4, Perl 5, or Perl 6? PerlFAQ Server Perl Misc 0 01-23-2011 05:00 AM
how do you make perl to c++ translater Robin Perl Misc 6 12-31-2010 12:09 PM
TRANSLATER aligurhan Computer Support 8 12-21-2003 01:21 PM
Perl Help - Windows Perl script accessing a Unix perl Script dpackwood Perl 3 09-30-2003 02:56 AM



Advertisments