Steve Hemond wrote:
> 
> Hi again,

Bonjour,

> As you know, I am trying to insert a string at the beginning of a file
> without overwriting its contents. Since my file is an HP/GL2 output
> file, I put every hp/gl2 command and stack them into an array. I then
> truncate the file, insert my specific string, and then put back all the
> commands after that string :
> 
> open (FILE, "+>>$ARGV[0]") or die ("Can`t open file! : $!\n");
               ^^^
You should use '+<' instead of '+>>'.

> # We put contents of the file in a temporary scalar
> my $in = <FILE>;

You are assigning the first record of the file to $in, not the entire
contents.

> # Clear the file
> truncate (FILE,0) or die ("Can't truncate file! : $! \n");

You don't really need to truncate the file because the new file will be
longer then the old file.

> # Build the string to insert at the beginning
> my $jobname = $ARGV[1];         #ARGV[0] is the file to be modified
> my $pjl = '@PJL JOB NAME = "' . $jobname . '"' . '\n'; # What a dumb way
> to build the string, any better ideas?
> printf FILE "\e%-12345X ";

printf() uses the '%' character to indicate the start of a format
string, in this case '%-12345X' which will print a 12,345 long string. 
Is that what you want?  Or did you mean to use print() instead?

> print $pjl;

Before you can print to the file, you have to seek() to the beginning of
the file or it will not work properly.

> As you can see, I wasn't able to build the string like this :
> printf FILE "\e%-12345X @PJL JOB NAME = $ARGV[1] \n";
> 
> Because between double quotes the @ of @PJL will be interpolated, which
> I don't want.

Just put a backslash in front of it: "\e%-12345X [EMAIL PROTECTED] JOB NAME =
$ARGV[1] \n"

> When running the script I get this error :
> Use of uninitialized value in printf at ./hptable.pl line 126, <FILE>
> line 1.
> line 126 = printf FILE "\e%-12345X ";

"uninitialized value" implies that there is a variable with the value
undef being printed.

$ perl -le'use warnings; use strict; my $x; printf "abcd  %-12X\n", $x;'
Use of uninitialized value in printf at -e line 1.
abcd  0           

But you don't have any variables on that line.



John
-- 
use Perl;
program
fulfillment

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to