how to translater "CAT" into perl

Discussion in 'Perl Misc' started by red, Jan 18, 2006.

  1. red

    red Guest

    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:
    ?
     
    red, Jan 18, 2006
    #1
    1. Advertising

  2. red

    Guest

    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
     
    , Jan 18, 2006
    #2
    1. Advertising

  3. 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
     
    Josef Moellers, Jan 18, 2006
    #3
  4. red

    Samwyse Guest

    wrote:
    [...snip...]

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

    I feel much better now, thanks.
     
    Samwyse, Jan 18, 2006
    #4
  5. red

    Paul Lalli Guest

    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.
     
    Paul Lalli, Jan 18, 2006
    #5
  6. 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:



    #-----------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
    Perl programming
    Fort Worth, Texas
     
    Tad McClellan, Jan 18, 2006
    #6
  7. red

    red Guest

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

    thank you.
    and thank all the others.
     
    red, Jan 19, 2006
    #7
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Yadagiri Rao KP
    Replies:
    3
    Views:
    420
    Joseph Millar
    Aug 9, 2003
  2. Spendius
    Replies:
    2
    Views:
    3,080
    Rogan Dawes
    Dec 13, 2004
  3. Replies:
    1
    Views:
    383
    Sudsy
    Dec 19, 2004
  4. Mark Adams
    Replies:
    5
    Views:
    545
    Inger Helene Falch-Jacobsen
    Aug 20, 2004
  5. Robin
    Replies:
    6
    Views:
    182
    Peter J. Holzer
    Dec 31, 2010
Loading...

Share This Page