Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Perl Misc (http://www.velocityreviews.com/forums/f67-perl-misc.html)
-   -   One-Liner Help with -e + ksh heredoc (http://www.velocityreviews.com/forums/t900190-one-liner-help-with-e-ksh-heredoc.html)

s/war/peace/g; 10-04-2006 06:50 PM

One-Liner Help with -e + ksh heredoc
 
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?


Stephane CHAZELAS 10-04-2006 06:59 PM

Re: One-Liner Help with -e + ksh heredoc
 
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

anno4000@radom.zrz.tu-berlin.de 10-04-2006 07:18 PM

Re: One-Liner Help with -e + ksh heredoc
 
s/war/peace/g; <smalder73@gmail.com> 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

s/war/peace/g; 10-04-2006 07:40 PM

Re: One-Liner Help with -e + ksh heredoc
 
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



Tad McClellan 10-04-2006 07:43 PM

Re: One-Liner Help with -e + ksh heredoc
 
anno4000@radom.zrz.tu-berlin.de <anno4000@radom.zrz.tu-berlin.de> wrote:
> s/war/peace/g; <smalder73@gmail.com> 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
tadmc@augustmail.com Perl programming
Fort Worth, Texas

Stephane CHAZELAS 10-04-2006 08:01 PM

Re: One-Liner Help with -e + ksh heredoc
 
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

anno4000@radom.zrz.tu-berlin.de 10-04-2006 10:19 PM

Re: One-Liner Help with -e + ksh heredoc
 
Tad McClellan <tadmc@augustmail.com> wrote in comp.lang.perl.misc:
> anno4000@radom.zrz.tu-berlin.de <anno4000@radom.zrz.tu-berlin.de> wrote:
> > s/war/peace/g; <smalder73@gmail.com> 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

Tad McClellan 10-04-2006 10:34 PM

Re: One-Liner Help with -e + ksh heredoc
 
anno4000@radom.zrz.tu-berlin.de <anno4000@radom.zrz.tu-berlin.de> wrote:
> Tad McClellan <tadmc@augustmail.com> wrote in comp.lang.perl.misc:
>> anno4000@radom.zrz.tu-berlin.de <anno4000@radom.zrz.tu-berlin.de> wrote:
>> > s/war/peace/g; <smalder73@gmail.com> 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
tadmc@augustmail.com Perl programming
Fort Worth, Texas

anno4000@radom.zrz.tu-berlin.de 10-05-2006 05:58 AM

Re: One-Liner Help with -e + ksh heredoc
 
Tad McClellan <tadmc@augustmail.com> wrote in comp.lang.perl.misc:
> anno4000@radom.zrz.tu-berlin.de <anno4000@radom.zrz.tu-berlin.de> wrote:
> > Tad McClellan <tadmc@augustmail.com> wrote in comp.lang.perl.misc:
> >> anno4000@radom.zrz.tu-berlin.de <anno4000@radom.zrz.tu-berlin.de> wrote:
> >> > s/war/peace/g; <smalder73@gmail.com> 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


All times are GMT. The time now is 08:43 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.