File::Copy Adds a ?

S

Sylvie Stone

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.
 
G

Glenn Jackman

Malcolm Dew-Jones said:
Sylvie Stone ([email protected]) 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";
 
M

Malcolm Dew-Jones

Sylvie Stone ([email protected]) 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 ? .
 
T

Tulan W. Hu

Sylvie Stone said:
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.
 
S

Sylvie Stone

Glenn Jackman said:
Malcolm Dew-Jones said:
Sylvie Stone ([email protected]) 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.
 

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

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,479
Members
44,899
Latest member
RodneyMcAu

Latest Threads

Top