Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?

hereto doc

by Anonymous Monk
on Jun 03, 2010 at 20:43 UTC ( #843001=perlquestion: print w/replies, xml ) Need Help??
Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi All, I want to use a HTD b/c its the best way I can think of for my small amount of code. I need to run a system image called an ignite on HPUX, but I also need to exclude many directories. Here is my code but my hereto doc (HTD) does not work. Any ideas?

#!/usr/bin/env perl use strict; use warnings; $ENV{PATH} = qq(/usr/bin:/bin:/usr/sbin:/sbin:/opt/ignite/bin); my $host = qx(/usr/bin/hostname); my $log = qq(/root/admin/logs/ignite/DR.log); my $svr = q/172.x.x.x/; ### Give me non-system mount point names ### my ($bdf,@excludes); for $bdf (qx|bdf|) { next if $bdf =~ /:?vg00/ || $bdf =~ /:?mounted/i; push @excludes, (split(" ", $bdf, 0))[5]; } my $string = <<`EOC`; -x exclude=$_ foreach (@excludes); EOC print $string; __DATA__ proper syntax is $ make_net_recovery -v -s "IP addr" -x inc_entire=vg00 \ -x exclude=/usrb -x exclude=/cache array contains /usrb /cache /journal . . .
thank you!

Replies are listed 'Best First'.
Re: hereto doc
by choroba (Chancellor) on Jun 03, 2010 at 20:57 UTC
    You probably mean something like
    my $string = join " -x exclude=$_" ,q(),@excludes;
    You can use shell commands in back-quoted here doc, as in
    print <<`EOF`; ls cd / ls EOF

    Update: join used instead of for. Why do I always correct just a half of the problem? :)

Re: hereto doc
by almut (Canon) on Jun 03, 2010 at 20:56 UTC
    my $string = <<`EOC`; -x exclude=$_ foreach (@excludes); EOC

    Not really sure I understand, but maybe you want something like this (?)

    my @excludes = qw(/usrb /cache /journal); my $string = join " ", map "-x exclude=$_", @excludes; print $string; __END__ -x exclude=/usrb -x exclude=/cache -x exclude=/journal
Re: hereto doc
by Krambambuli (Curate) on Jun 04, 2010 at 17:52 UTC
    If you're still concerned about the here-doc not working:

    it seems you're using backquotes instead of apostrophes, ` instead of ' or ", in

    my $string = <<`EOC`;

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://843001]
Approved by Corion
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (5)
As of 2017-03-30 23:04 GMT
Find Nodes?
    Voting Booth?
    Should Pluto Get Its Planethood Back?

    Results (364 votes). Check out past polls.