Find the answer to your Linux question:
Results 1 to 7 of 7
I I want tu use some perl in a korn shell script. Is it possible ?? If yes how can i make some perl in a korn shell programm in ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Jul 2006
    Posts
    3

    using perl in a korn shell programm????


    I

    I want tu use some perl in a korn shell script. Is it possible ?? If yes how can i make some perl in a korn shell programm in the same file


    Thx


    Max

  2. #2
    drl
    drl is offline
    Linux Engineer drl's Avatar
    Join Date
    Apr 2006
    Location
    Saint Paul, MN, USA / CentOS, Debian, Slackware, {Free, Open, Net}BSD, Solaris
    Posts
    1,286
    Hi, maxou.

    One way is to use something called a here document. For example, suppose we have a script in a file s1:
    Code:
    #!/bin/sh
    
    # @(#) s1       Demonstrate embedded perl.
    
    echo
    echo " Hello, world (from shell)."
    
    perl <<EOF
    print " Hello, world (from perl).\n";
    EOF
    When you execute this, you get:
    Code:
    perl/embedded-in-shell % ./s1
    
     Hello, world (from shell).
     Hello, world (from perl).
    All the Bourne family shells know how do to this -- sh, bash, ksh. In some situations, you may need the full path to perl, such as /usr/bin/perl.

    However, I would only recommend this for simple tasks. For more durable and maintainable code, I would place the perl code into its own script file. That also makes it accessible to other scripts.

    Now you can experiment on your own ... cheers, drl
    Welcome - get the most out of the forum by reading forum basics and guidelines: click here.
    90% of questions can be answered by using man pages, Quick Search, Advanced Search, Google search, Wikipedia.
    We look forward to helping you with the challenge of the other 10%.
    ( Mn, 2.6.n, AMD-64 3000+, ASUS A8V Deluxe, 1 GB, SATA + IDE, Matrox G400 AGP )

  3. #3
    Just Joined!
    Join Date
    Jul 2006
    Posts
    3
    thx for your response

    I have a other question.

    Betwen perl << EOF
    EOF

    is it possible to put a couple of line of code for example

    perl << EOF
    $cout=5;
    while($cout>0)
    {

    print "$count"
    $count--

    }
    EOF

    If yes why it's not working


    If no how can we call a perl script and grab what the file returns

    thx in advanced

    Max

  4. #4
    Linux Newbie
    Join Date
    Oct 2004
    Posts
    158
    perldoc suggests:

    Code:
    $var1="argument 1"
    $var2="Argument 2"
    perl -e ' perl code here;
               more code;
              '  "$var1"  "$var2"
    The <<EOF structure is called a here document.

    Read this about howto use a here doc:
    http://www.tldp.org/LDP/abs/html/here-docs.html

  5. #5
    Just Joined!
    Join Date
    Jul 2006
    Posts
    3
    Thx for the answer

    is it possible in the perl code to use the $var1 ?????????

    thx in advancd for the answer

    Max

  6. #6
    drl
    drl is offline
    Linux Engineer drl's Avatar
    Join Date
    Apr 2006
    Location
    Saint Paul, MN, USA / CentOS, Debian, Slackware, {Free, Open, Net}BSD, Solaris
    Posts
    1,286
    Hi, max.

    I'm glad to see you experimented. While I would normally agree with perldoc as mentioned by jim mcnamara, I find that the "-e" method is often too cumbersome.

    So adding a few here document features (about which you can read in the LDP document):
    Code:
    #!/bin/sh
    
    # @(#) s2       Demonstrate embedded perl.
    
    perl <<-'EOF'
            $count=5;
            while($count>0)
            {
    
            print "$count\n";
            $count--;
    
            }
    EOF
    This corrects a number of errors in your perl code and adds the quotes plus the tab-allowing minus sign on the here document limit string. When run, you get:
    Code:
    % ./s2
    5
    4
    3
    2
    1
    Best wishes ... cheers, drl
    Welcome - get the most out of the forum by reading forum basics and guidelines: click here.
    90% of questions can be answered by using man pages, Quick Search, Advanced Search, Google search, Wikipedia.
    We look forward to helping you with the challenge of the other 10%.
    ( Mn, 2.6.n, AMD-64 3000+, ASUS A8V Deluxe, 1 GB, SATA + IDE, Matrox G400 AGP )

  7. #7
    Just Joined!
    Join Date
    Mar 2007
    Posts
    1
    Quote Originally Posted by jim mcnamara
    perldoc suggests:

    Code:
    $var1="argument 1"
    $var2="Argument 2"
    perl -e ' perl code here;
               more code;
              '  "$var1"  "$var2"
    The <<EOF structure is called a here document.

    Read this about howto use a here doc:
    http://www.tldp.org/LDP/abs/html/here-docs.html
    how can I user $var2 within the perl ?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •