Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > File::Copy Adds a ?

Reply
Thread Tools

File::Copy Adds a ?

 
 
Sylvie Stone
Guest
Posts: n/a
 
      10-08-2003
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.
 
Reply With Quote
 
 
 
 
Glenn Jackman
Guest
Posts: n/a
 
      10-08-2003
Malcolm Dew-Jones <(E-Mail Removed)> wrote:
> Sylvie Stone ((E-Mail Removed)) 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
http://www.velocityreviews.com/forums/(E-Mail Removed)
 
Reply With Quote
 
 
 
 
Malcolm Dew-Jones
Guest
Posts: n/a
 
      10-08-2003
Sylvie Stone ((E-Mail Removed)) 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 ? .

 
Reply With Quote
 
Tulan W. Hu
Guest
Posts: n/a
 
      10-08-2003

"Sylvie Stone" <(E-Mail Removed)> 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.



 
Reply With Quote
 
Sylvie Stone
Guest
Posts: n/a
 
      10-09-2003
Glenn Jackman <(E-Mail Removed)> wrote in message news:<(E-Mail Removed)>...
> Malcolm Dew-Jones <(E-Mail Removed)> wrote:
> > Sylvie Stone ((E-Mail Removed)) 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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
download adds extra extension nico assinck Firefox 2 02-01-2005 08:07 PM
Extension that adds icons to our bookmarks? Galaxy Firefox 0 06-28-2004 04:07 AM
Ver. 1.5 adds ".jpe" extension to ".jpg. files SBN Firefox 5 01-15-2004 05:03 PM
Mozilla Adds ".jfif" Extension to all JPEG Files Downloaded? cvnorris@charterinternet.com Firefox 1 10-28-2003 05:36 AM
Microsoft adds more specializations MCSE World MCSE 2 09-04-2003 02:44 PM



Advertisments