One-Liner Help with -e + ksh heredoc

Discussion in 'Perl Misc' started by s/war/peace/g;, Oct 4, 2006.

  1. I'm in the midst of writing a ksh script. I've got a file of junk I
    need to manipulate with some hash magic in perl, but I'm trying to keep
    the perl code encapsulated in my ksh script. I'm trying to do
    something like this...

    perl -e 'magic' -i file

    But I want the magic to look more like...

    perl -e <<EOF
    magic
    EOF
    -i file

    This way the code is not cryptic. So far I can not seem to make this
    work... am I on crack for thinking I should be able to do something
    like this? Any suggestions?
     
    s/war/peace/g;, Oct 4, 2006
    #1
    1. Advertising

  2. 2006-10-4, 11:50(-07), s/war/peace/g;:
    > I'm in the midst of writing a ksh script. I've got a file of junk I
    > need to manipulate with some hash magic in perl, but I'm trying to keep
    > the perl code encapsulated in my ksh script. I'm trying to do
    > something like this...
    >
    > perl -e 'magic' -i file
    >
    > But I want the magic to look more like...
    >
    > perl -e <<EOF
    > magic
    > EOF
    > -i file

    [...]

    What about

    perl -e '
    magic
    ' -i file

    Or

    perl -e "$(
    cat << \EOF
    magic
    EOF
    )" -i file

    Or

    magic=$(
    cat << \EOF
    magic
    EOF
    )

    perl -e "$magic" -i file

    If your system supports the /dev/fd/<n> thing:

    perl /dev/fd/3 -i file 3<< \EOF
    magic
    EOF

    --
    Stéphane
     
    Stephane CHAZELAS, Oct 4, 2006
    #2
    1. Advertising

  3. s/war/peace/g;

    -berlin.de Guest

    s/war/peace/g; <> wrote in comp.lang.perl.misc:
    > I'm in the midst of writing a ksh script. I've got a file of junk I
    > need to manipulate with some hash magic in perl, but I'm trying to keep
    > the perl code encapsulated in my ksh script. I'm trying to do
    > something like this...
    >
    > perl -e 'magic' -i file
    >
    > But I want the magic to look more like...
    >
    > perl -e <<EOF
    > magic
    > EOF
    > -i file
    >
    > This way the code is not cryptic. So far I can not seem to make this
    > work... am I on crack for thinking I should be able to do something
    > like this? Any suggestions?


    You are misunderstanding ksh here documents. They don't return
    a string, they supply the given text via standard input. Thus in a
    ksh script

    perl <<EOF
    print "hihi\n";
    print "haha\n";
    EOF

    would print the expected two lines. How well that mixes with -i
    I don't know.

    Anno
     
    -berlin.de, Oct 4, 2006
    #3
  4. TYVM!

    I had avoided using the multi line -e ' syntax because I have some
    pipes and quotes in my code and other characters the shell seems to
    like to interpret... hadn't thought about the cat <<EOF though that's a
    neato trick. Many Thanks!

    Stephane CHAZELAS wrote:
    > 2006-10-4, 11:50(-07), s/war/peace/g;:
    > > I'm in the midst of writing a ksh script. I've got a file of junk I
    > > need to manipulate with some hash magic in perl, but I'm trying to keep
    > > the perl code encapsulated in my ksh script. I'm trying to do
    > > something like this...
    > >
    > > perl -e 'magic' -i file
    > >
    > > But I want the magic to look more like...
    > >
    > > perl -e <<EOF
    > > magic
    > > EOF
    > > -i file

    > [...]
    >
    > What about
    >
    > perl -e '
    > magic
    > ' -i file
    >
    > Or
    >
    > perl -e "$(
    > cat << \EOF
    > magic
    > EOF
    > )" -i file
    >
    > Or
    >
    > magic=$(
    > cat << \EOF
    > magic
    > EOF
    > )
    >
    > perl -e "$magic" -i file
    >
    > If your system supports the /dev/fd/<n> thing:
    >
    > perl /dev/fd/3 -i file 3<< \EOF
    > magic
    > EOF
    >
    > --
    > Stéphane
     
    s/war/peace/g;, Oct 4, 2006
    #4
  5. -berlin.de <-berlin.de> wrote:
    > s/war/peace/g; <> wrote in comp.lang.perl.misc:
    >> I'm in the midst of writing a ksh script. I've got a file of junk I
    >> need to manipulate with some hash magic in perl, but I'm trying to keep
    >> the perl code encapsulated in my ksh script. I'm trying to do
    >> something like this...
    >>
    >> perl -e 'magic' -i file
    >>
    >> But I want the magic to look more like...
    >>
    >> perl -e <<EOF
    >> magic
    >> EOF
    >> -i file
    >>
    >> This way the code is not cryptic. So far I can not seem to make this
    >> work... am I on crack for thinking I should be able to do something
    >> like this? Any suggestions?

    >
    > You are misunderstanding ksh here documents. They don't return
    > a string, they supply the given text via standard input.



    they supply the given text right "here" (where the here-doc appears),
    hence the name "here document".


    --
    Tad McClellan SGML consulting
    Perl programming
    Fort Worth, Texas
     
    Tad McClellan, Oct 4, 2006
    #5
  6. 2006-10-4, 12:40(-07), s/war/peace/g;:
    > TYVM!
    >
    > I had avoided using the multi line -e ' syntax because I have some
    > pipes and quotes in my code and other characters the shell seems to
    > like to interpret... hadn't thought about the cat <<EOF though that's a
    > neato trick. Many Thanks!

    [...]

    The shell doesn't interpret anything inside '...'. So, as long
    as you don't have single quotes in your perl code, it should be
    OK.

    --
    Stéphane
     
    Stephane CHAZELAS, Oct 4, 2006
    #6
  7. s/war/peace/g;

    -berlin.de Guest

    Tad McClellan <> wrote in comp.lang.perl.misc:
    > -berlin.de <-berlin.de> wrote:
    > > s/war/peace/g; <> wrote in comp.lang.perl.misc:
    > >> I'm in the midst of writing a ksh script. I've got a file of junk I
    > >> need to manipulate with some hash magic in perl, but I'm trying to keep
    > >> the perl code encapsulated in my ksh script. I'm trying to do
    > >> something like this...
    > >>
    > >> perl -e 'magic' -i file
    > >>
    > >> But I want the magic to look more like...
    > >>
    > >> perl -e <<EOF
    > >> magic
    > >> EOF
    > >> -i file
    > >>
    > >> This way the code is not cryptic. So far I can not seem to make this
    > >> work... am I on crack for thinking I should be able to do something
    > >> like this? Any suggestions?

    > >
    > > You are misunderstanding ksh here documents. They don't return
    > > a string, they supply the given text via standard input.

    >
    >
    > they supply the given text right "here" (where the here-doc appears),
    > hence the name "here document".


    Yes, that's where the text comes from. It goes to stdin of the command
    it (i.e. the leading <<EOF) is part of.

    Anno
     
    -berlin.de, Oct 4, 2006
    #7
  8. -berlin.de <-berlin.de> wrote:
    > Tad McClellan <> wrote in comp.lang.perl.misc:
    >> -berlin.de <-berlin.de> wrote:
    >> > s/war/peace/g; <> wrote in comp.lang.perl.misc:
    >> >> I'm in the midst of writing a ksh script. I've got a file of junk I
    >> >> need to manipulate with some hash magic in perl, but I'm trying to keep
    >> >> the perl code encapsulated in my ksh script. I'm trying to do
    >> >> something like this...
    >> >>
    >> >> perl -e 'magic' -i file
    >> >>
    >> >> But I want the magic to look more like...
    >> >>
    >> >> perl -e <<EOF
    >> >> magic
    >> >> EOF
    >> >> -i file
    >> >>
    >> >> This way the code is not cryptic. So far I can not seem to make this
    >> >> work... am I on crack for thinking I should be able to do something
    >> >> like this? Any suggestions?
    >> >
    >> > You are misunderstanding ksh here documents. They don't return
    >> > a string, they supply the given text via standard input.

    >>
    >>
    >> they supply the given text right "here" (where the here-doc appears),
    >> hence the name "here document".

    >
    > Yes, that's where the text comes from. It goes to stdin of the command
    > it (i.e. the leading <<EOF) is part of.



    I can now see that _I_ am also misunderstanding ksh here documents.

    Sorry.


    --
    Tad McClellan SGML consulting
    Perl programming
    Fort Worth, Texas
     
    Tad McClellan, Oct 4, 2006
    #8
  9. s/war/peace/g;

    -berlin.de Guest

    Tad McClellan <> wrote in comp.lang.perl.misc:
    > -berlin.de <-berlin.de> wrote:
    > > Tad McClellan <> wrote in comp.lang.perl.misc:
    > >> -berlin.de <-berlin.de> wrote:
    > >> > s/war/peace/g; <> wrote in comp.lang.perl.misc:
    > >> >> I'm in the midst of writing a ksh script. I've got a file of junk I
    > >> >> need to manipulate with some hash magic in perl, but I'm trying to keep
    > >> >> the perl code encapsulated in my ksh script. I'm trying to do
    > >> >> something like this...
    > >> >>
    > >> >> perl -e 'magic' -i file
    > >> >>
    > >> >> But I want the magic to look more like...
    > >> >>
    > >> >> perl -e <<EOF
    > >> >> magic
    > >> >> EOF
    > >> >> -i file
    > >> >>
    > >> >> This way the code is not cryptic. So far I can not seem to make this
    > >> >> work... am I on crack for thinking I should be able to do something
    > >> >> like this? Any suggestions?
    > >> >
    > >> > You are misunderstanding ksh here documents. They don't return
    > >> > a string, they supply the given text via standard input.
    > >>
    > >>
    > >> they supply the given text right "here" (where the here-doc appears),
    > >> hence the name "here document".

    > >
    > > Yes, that's where the text comes from. It goes to stdin of the command
    > > it (i.e. the leading <<EOF) is part of.

    >
    >
    > I can now see that _I_ am also misunderstanding ksh here documents.


    So was I before I answered the question.

    Anno
     
    -berlin.de, Oct 5, 2006
    #9
    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. kaeli
    Replies:
    8
    Views:
    1,418
    Harald Kirsch
    Feb 13, 2004
  2. Replies:
    12
    Views:
    2,523
    Magnus Lycka
    Jun 8, 2005
  3. ClassRubyExceptionHandline

    ruby and ksh

    ClassRubyExceptionHandline, Sep 8, 2006, in forum: Ruby
    Replies:
    4
    Views:
    154
    David Vallner
    Sep 9, 2006
  4. Replies:
    4
    Views:
    530
    Tad McClellan
    Dec 10, 2004
  5. Larry
    Replies:
    1
    Views:
    124
    Martien Verbruggen
    Feb 3, 2005
Loading...

Share This Page