Problem with procentage character when reading BAT file to perl array

Discussion in 'Perl Misc' started by wxdeveloper, Aug 3, 2009.

  1. wxdeveloper

    wxdeveloper Guest

    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
     
    wxdeveloper, Aug 3, 2009
    #1
    1. Advertising

  2. wxdeveloper

    wxdeveloper Guest

    Re: Problem with procentage character when reading BAT file to perlarray


    >     while ( <FILEHANDLE> ) {
    >         print;
    >     }
    >
    > See also:
    >
    >     perldoc -f vars
    >
    >         What's wrong with always quoting "$vars"?
    >
    > > The problem is that perl somehow assums that %V is a variable and
    > > tries to replace it with a value.

    >
    > No, the problem is that printf() treats % specially.
    >
    > > Is there any way to prevent this?

    >
    > Don't use printf!
    >
    > --
    > Tad McClellan
    > email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"


    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.
     
    wxdeveloper, Aug 4, 2009
    #2
    1. Advertising

  3. wxdeveloper

    wxdeveloper Guest

    Re: Problem with procentage character when reading BAT file to perlarray

    > 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.
     
    wxdeveloper, Aug 4, 2009
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. KwikRick
    Replies:
    1
    Views:
    381
    Christos TZOTZIOY Georgiou
    Aug 22, 2003
  2. GP
    Replies:
    3
    Views:
    221
  3. Tom Salzmann
    Replies:
    3
    Views:
    290
  4. Replies:
    4
    Views:
    258
  5. Replies:
    19
    Views:
    220
Loading...

Share This Page