Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

hi Monks,

I have an array that looks like this.

@head=<reportparameters name="hostname">localhost</reportparameters>;

when I print the array with

print "array @head"

The quotes for the "hostname" are saved.

but when I try to do this.

`perl -pi -e "print '@headinfo ' if \$. == 1" $file`;

the quotes " go missing in the output file

somehow I need to retain the quotes.

in the output file.

please advice.

Code tags added by GrandFather

Replies are listed 'Best First'.
Re: missing quotes
by toolic (Bishop) on Oct 22, 2007 at 20:33 UTC
    The following code will print your string to an output file with double quotes:
    use warnings; use strict; my @head = '<reportparameters name="hostname">localhost</reportparamet +ers>'; open my $OUT_FH, '>', 'out.txt' or die "can not open out.txt: $!\n"; print $OUT_FH "@head\n"; close $OUT_FH;
    This is the contents of the output file "out.txt":
    <reportparameters name="hostname">localhost</reportparameters>

    I'm not sure what you are trying to accomplish with the perl one-liner. Can you elaborate?