Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked

Re: 'perl -e' and '__DATA__' What's wrong?

by graff (Chancellor)
on Dec 08, 2007 at 03:03 UTC ( #655798=note: print w/replies, xml ) Need Help??

in reply to 'perl -e' and '__DATA__' What's wrong?

Let's see if I have this right:
  1. you have an AppleScript application, which does some stuff and sets some "AppleScript variables"
  2. then the AppleScript thing invokes a perl command-line ("one-liner") script, which must:
    1. accept some stuff from stdin (some other process invoked by AppleScript is feeding the perl one-liner)
    2. accept some additional command line args? (or maybe not, or maybe this doesn't matter)
    3. accept some additional data which cannot be mixed with the stdin stream, and is not safe to provide as command-line args (for @ARGV), and this data content involves (some of) those "AppleScript variables".

If AppleScript provides a way to open a file for output, write variables to that file, and close it, then the perl script could simply open a given file, and read from that instead of from __DATA__ -- or I suppose you could go to the trouble of writing the whole perl script to a file, including the runtime-determined __DATA__ content, then execute it.

Or maybe you could turn things around: have a perl script that invokes AppleScript (via the "osascript" shell command), and reads the data it needs from that? (Just guessing)

  • Comment on Re: 'perl -e' and '__DATA__' What's wrong?

Replies are listed 'Best First'.
Re^2: 'perl -e' and '__DATA__' What's wrong?
by Skeeve (Vicar) on Dec 10, 2007 at 11:37 UTC

    Okay then! Here is how my AppleScript-invoked perl scripts work. I often put them inside Applescript because this way I can use Drag & Drop or some other nice stuff AppleScript offers.

    Note! This example won't work, because I use -e and DATA

    property some_user_changeable_config_stuff : "this data can be changed by the user of the script usually this is some kind of template, containing placeholders the perl script will fill later. Note: The user usually knows nothing about perl but a bit about AppleScript. So he will happily be using stuff like @ Quotes % etc. " on run tell me to open { choose file } end run on open some_items repeat with this_item in some_items if info for this_item is not folder then do_stuff_with(this_item) end if end repeat en open on do_stuff_with(an_item) do shell script "perl -e " & (quoted form of " use strict; use warnings; # read DATA here e.g.: my $TEMPLATE; { local $/; $TEMPLATE= <DATA>; } # and now process while (<>) { # do something with the line and the # TEMPLATE } __DATA__" & (ASCII character 10) & some_user_changeable_config_stuff) +& " " & (quoted form of POSIX path of an_item) end do_stuff_with

    Of course I can check the "some_user_changeable_config_stuff" variable that a delimiter I choose isn't contained. I just wanted to avoid this, using __DATA__. So this post isn't a request for help, but just for clarification/explanation.

      Then I'd rewrite that as follows
      on do_stuff_with(an_item) do shell script "perl -e " & (quoted form of " use strict; use warnings; use Getopt::Long; # get Template from the command line my $TEMPLATE; GetOptions("template=%s",\$TEMPLATE); # and now process while (<>) { # do something with the line and the # TEMPLATE } ") & " " & (quoted form of "--template=" & some_user_changeable_config +_stuff) & " " & (quoted form of POSIX path of an_item) end do_stuff_with

      yay, first AppleScript hacking I did did do! ;-)

      Dunno whether I got everything right, but the idea is to stuff into a command line argument that which you wanted to stuff into the DATA section.


      _($_=" "x(1<<5)."?\n".q·/)Oo.  G°\        /
                                    /\_¯/(q    /
      ----------------------------  \__(m.====·.(_("always off the crowd"))."·
      ");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}

        You didn't get everything right I fear, but I got the idea!

        Thank you! YOU ARE MY HERO!

        Too bad I just can give 1 ++...


Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://655798]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (7)
As of 2017-04-25 11:20 GMT
Find Nodes?
    Voting Booth?
    I'm a fool:

    Results (449 votes). Check out past polls.