File::Copy Adds a ?

Discussion in 'Perl Misc' started by Sylvie Stone, Oct 8, 2003.

  1. Sylvie Stone

    Sylvie Stone Guest

    Hi group -

    Can someone tell me why this command is adding a question mark to the file name:

    #!/usr/bin/perl
    $month=`/bin/date | awk '{print \$2\$6}'`;

    if (blah blah blah) {
    copy("total.txt","total.$month");
    }



    [root]# ls -l total.*
    -rw-rw-r-- 1 root root 13 Oct 8 12:31 total.Oct2003?
    -rw-rw-rw- 1 nobody nobody 13 Oct 8 07:35 total.txt
    [root@alert StandardsAlert]# more total.Oct2003?
    1|0|0|0|0|1|1
    [root@alert StandardsAlert]# more total.Oct2003
    total.Oct2003: No such file or directory


    THANK YOU!

    Syl.
     
    Sylvie Stone, Oct 8, 2003
    #1
    1. Advertising

  2. Malcolm Dew-Jones <> wrote:
    > Sylvie Stone () wrote:
    >
    > The date command may be able to output the format you want without using
    > awk.
    >
    > $ date '+%b%Y'
    > Oct2003


    Or don't use date at all:
    use POSIX qw(strftime);
    $month = strftime "%b%Y", localtime;

    > : #!/usr/bin/perl
    > : $month=`/bin/date | awk '{print \$2\$6}'`;

    [...]
    > Perhaps it isn't a `?', I will guess the ? is a place holder to indicate a
    > control character in the name, such as a new-line from the end of the awk
    > output.


    Indeed:
    $month=`/bin/date | awk '{print \$2\$6}'`;
    $len = length $month;
    print "'$month' is $len characters long\n";


    --
    Glenn Jackman
    NCF Sysadmin
     
    Glenn Jackman, Oct 8, 2003
    #2
    1. Advertising

  3. Sylvie Stone () wrote:
    : Hi group -

    : Can someone tell me why this command is adding a question mark to the
    file name:

    The date command may be able to output the format you want without using
    awk.

    $ date '+%b%Y'
    Oct2003


    : #!/usr/bin/perl
    : $month=`/bin/date | awk '{print \$2\$6}'`;

    : if (blah blah blah) {
    : copy("total.txt","total.$month");
    : }


    : [root]# ls -l total.*
    : -rw-rw-r-- 1 root root 13 Oct 8 12:31 total.Oct2003?


    Perhaps it isn't a `?', I will guess the ? is a place holder to indicate a
    control character in the name, such as a new-line from the end of the awk
    output.

    Try chomp($month)

    : [root@alert StandardsAlert]# more total.Oct2003?
    : 1|0|0|0|0|1|1

    That may work because ? is a wild card, so it matches any character (i.e.
    a control character) in the file name, not because the filename has a
    literal ? .
     
    Malcolm Dew-Jones, Oct 8, 2003
    #3
  4. Sylvie Stone

    Tulan W. Hu Guest

    "Sylvie Stone" <> wrote in message ...
    > Hi group -
    >
    > Can someone tell me why this command is adding a question mark to the file

    name:
    >
    > #!/usr/bin/perl
    > $month=`/bin/date | awk '{print \$2\$6}'`;


    **** chomp($month); # maybe the ? is a newline.
    >
    > if (blah blah blah) {
    > copy("total.txt","total.$month");
    > }
    >
    >
    >
    > [root]# ls -l total.*
    > -rw-rw-r-- 1 root root 13 Oct 8 12:31 total.Oct2003?
    > -rw-rw-rw- 1 nobody nobody 13 Oct 8 07:35 total.txt
    > [root@alert StandardsAlert]# more total.Oct2003?
    > 1|0|0|0|0|1|1
    > [root@alert StandardsAlert]# more total.Oct2003
    > total.Oct2003: No such file or directory
    >
    >
    > THANK YOU!
    >
    > Syl.
     
    Tulan W. Hu, Oct 8, 2003
    #4
  5. Sylvie Stone

    Sylvie Stone Guest

    Glenn Jackman <> wrote in message news:<>...
    > Malcolm Dew-Jones <> wrote:
    > > Sylvie Stone () wrote:
    > >
    > > The date command may be able to output the format you want without using
    > > awk.
    > >
    > > $ date '+%b%Y'
    > > Oct2003

    >
    > Or don't use date at all:
    > use POSIX qw(strftime);
    > $month = strftime "%b%Y", localtime;
    >
    > > : #!/usr/bin/perl
    > > : $month=`/bin/date | awk '{print \$2\$6}'`;

    > [...]
    > > Perhaps it isn't a `?', I will guess the ? is a place holder to indicate a
    > > control character in the name, such as a new-line from the end of the awk
    > > output.

    >
    > Indeed:
    > $month=`/bin/date | awk '{print \$2\$6}'`;
    > $len = length $month;
    > print "'$month' is $len characters long\n";



    Thank you all for the reply's. I ended up using the POSIX commend and
    it's works great. Thanks -

    Syl.
     
    Sylvie Stone, Oct 9, 2003
    #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. Steven Knight
    Replies:
    0
    Views:
    1,207
    Steven Knight
    Aug 18, 2004
  2. Alex
    Replies:
    2
    Views:
    1,270
  3. UJ
    Replies:
    2
    Views:
    2,085
    Joerg Jooss
    Sep 16, 2006
  4. Replies:
    26
    Views:
    2,157
    Roland Pibinger
    Sep 1, 2006
  5. jodleren
    Replies:
    4
    Views:
    459
    jodleren
    Nov 26, 2007
Loading...

Share This Page