%s in variable, how to work correctly?

Discussion in 'Perl Misc' started by Mirco Wahab, Apr 16, 2007.

  1. Mirco Wahab

    Mirco Wahab Guest

    Dick Pluim wrote:
    > I read out an Oracle-parameter log_archive_format. This one containts
    > also %s in the value (%t_%s_%r.dbf).
    > If I just let it print it show me the %s, but if I add the text to
    > another string I loose the %s, and it looks like
    > %t__%r.dbf .
    > How can I keep the %s in it? I've been googling around but can't find a
    > solution sofar.


    How do you "add it to another string"?

    I can only guess. Maybe it's something
    like this:

    ...

    my $pathname = '/path/to/my/files/';
    my $filename = '%t_%s_%r.dbf';

    my $trial1 = $pathname . $filename;
    print $trial1, "\n"; # ==> %t_%s_%r

    my $trial2 = "$pathname$filename";
    print $trial2, "\n"; # ==> %t_%s_%r

    my $trial3 = sprintf "$pathname$filename";
    print $trial3, "\n"; # ==> %t__%r

    ...

    Compare how $trial2 and $trial3 are constructed ...


    But you should provide some more information
    on *what* you did.

    Regards

    M.
     
    Mirco Wahab, Apr 16, 2007
    #1
    1. Advertising

  2. Mirco Wahab

    Dick Pluim Guest

    Hello,

    I'm co-working on an application for Oracle-dba-activities and encounter the
    following problem:

    I read out an Oracle-parameter log_archive_format. This one containts also
    %s in the value (%t_%s_%r.dbf).
    If I just let it print it show me the %s, but if I add the text to another
    string I loose the %s, and it looks like
    %t__%r.dbf .
    How can I keep the %s in it? I've been googling around but can't find a
    solution sofar.
    Thanx in advance.

    Dick
     
    Dick Pluim, Apr 16, 2007
    #2
    1. Advertising

  3. Dick Pluim wrote:
    > I read out an Oracle-parameter log_archive_format. This one containts
    > also %s in the value (%t_%s_%r.dbf).
    > If I just let it print it show me the %s, but if I add the text to
    > another string I loose the %s, and it looks like
    > %t__%r.dbf .


    Assuming you mean concatenate when you are talking about adding, then I
    can't reproduce your problem:

    C:\tmp>type t.pl
    use strict; use warnings;
    my $string = '%t_%s_%r.dbf';
    print $string, "\n";
    my $another = 'foo>'.$string.'<bar';
    print $another, "\n";

    C:\tmp>t.pl
    %t_%s_%r.dbf
    foo>%t_%s_%r.dbf<bar

    As you can clearly see the %s is still printed by print(), even after
    concatenating more text to it.

    jue
     
    Jürgen Exner, Apr 16, 2007
    #3
  4. Mirco Wahab

    Dick Pluim Guest

    "Michele Dondi" <> schreef in bericht
    news:...
    > On Mon, 16 Apr 2007 12:24:09 +0200, "Dick Pluim"
    > <> wrote:
    >
    >>I read out an Oracle-parameter log_archive_format. This one containts also
    >>%s in the value (%t_%s_%r.dbf).
    >>If I just let it print it show me the %s, but if I add the text to another
    >>string I loose the %s, and it looks like
    >>%t__%r.dbf .
    >>How can I keep the %s in it? I've been googling around but can't find a
    >>solution sofar.

    >
    > This does not make sense unless you specify *how* you "add the text to
    > another string".
    >
    > pilsner:~ [12:39:39]$ perl -le '$a="%t_%s_%r.dbf"; $b="foo${a}bar";
    > print for $a,$b'
    > %t_%s_%r.dbf
    > foo%t_%s_%r.dbfbar
    >
    > I suspect you may be messing with (s)printf().


    Thanx. It had indeed to do with print and/or printf. When I did the test to
    let me show the value I used print and in the final part where the program
    has to come up with errormessages printf was being used. Changed this to
    print and now it's working fine.

    Dick
     
    Dick Pluim, Apr 16, 2007
    #4
  5. Dick Pluim <> wrote:
    > "Michele Dondi" <> schreef in bericht
    > news:...
    >> On Mon, 16 Apr 2007 12:24:09 +0200, "Dick Pluim"
    >> <> wrote:
    >>
    >>>I read out an Oracle-parameter log_archive_format. This one containts also
    >>>%s in the value (%t_%s_%r.dbf).
    >>>If I just let it print it show me the %s, but if I add the text to another
    >>>string I loose the %s, and it looks like
    >>>%t__%r.dbf .


    >> I suspect you may be messing with (s)printf().

    >
    > Thanx. It had indeed to do with print and/or printf. When I did the test to
    > let me show the value I used print and in the final part where the program
    > has to come up with errormessages printf was being used. Changed this to
    > print and now it's working fine.



    That is a prime example of why you should always enable warnings
    when developing Perl code.

    If you had turned on warnings the problem would have been pointed
    out within a few milliseconds.


    --
    Tad McClellan SGML consulting
    Perl programming
    Fort Worth, Texas
     
    Tad McClellan, Apr 17, 2007
    #5
    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. tshad
    Replies:
    9
    Views:
    501
    tshad
    Jun 10, 2005
  2. Carlos Henrique
    Replies:
    0
    Views:
    473
    Carlos Henrique
    Aug 18, 2003
  3. La'ie Techie
    Replies:
    0
    Views:
    425
    La'ie Techie
    Sep 26, 2003
  4. Tiddley-Pom
    Replies:
    5
    Views:
    441
    Mark Parnell
    Oct 15, 2003
  5. Wiseguy
    Replies:
    2
    Views:
    346
    Jonathan Turkanis
    Jan 18, 2004
Loading...

Share This Page