|
Prev: Archive::Zip - how to create huge zip files ?
Next: Validating Date-Time Ranges in a Schedule Database
From: s/war/peace/g; on 4 Oct 2006 14:50 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?
From: Stephane CHAZELAS on 4 Oct 2006 14:59 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
From: anno4000 on 4 Oct 2006 15:18 s/war/peace/g; <smalder73(a)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
From: s/war/peace/g; on 4 Oct 2006 15:40 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
From: Tad McClellan on 4 Oct 2006 15:43 anno4000(a)radom.zrz.tu-berlin.de <anno4000(a)radom.zrz.tu-berlin.de> wrote: > s/war/peace/g; <smalder73(a)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(a)augustmail.com Perl programming Fort Worth, Texas
|
Next
|
Last
Pages: 1 2 Prev: Archive::Zip - how to create huge zip files ? Next: Validating Date-Time Ranges in a Schedule Database |