Problem with procentage character when reading BAT file to perl array

W

wxdeveloper

Hello

I want to read a BAT file to some array and then process it line by
line.
The problem is that the BAT file has some DOS variables inside (for
example, %VARIABLE%).

I read the file to an array like this:
@my_array = <FILEHANDLE>

Then I want to process each line

foreach (@my_array)
{
printf "$_";
}

The problem is that perl somehow assums that %V is a variable and
tries to replace it with a value.
The result is that I get string 0ARIABLE%.
Is there any way to prevent this?

Thank you
J. Grabis
 
W

wxdeveloper

    while ( <FILEHANDLE> ) {
        print;
    }

See also:

    perldoc -f vars

        What's wrong with always quoting "$vars"?


No, the problem is that printf() treats % specially.


Don't use printf!

I want to modify some lines of the BAT file and then store the
modified version in some other file.
Printf allows me to provide a handle to a file where I want to store
the result... Could I send the result to a file without printf ?


Thank you
J.
 
W

wxdeveloper

Have you read the documentation for the function you are using?
    perldoc -f printf

The 3rd word of the description names another function that can
be passed a filehandle, but that does not treat percent signs specially.

Using print with a file handle solves my problem.


Thank you for your help
J.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,822
Latest member
israfaceZa

Latest Threads

Top