For Programmers: Free Programming Magazines  


Home > Archive > PERL Beginners > October 2007 > One sprintf() initializations problem









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author One sprintf() initializations problem
Jiangfan

2007-10-30, 8:00 am

Hi,

What is wrong with this statement?

my $time = sprintf( "0x%08x", `date +%s` );

I got

"Use of uninitialized value in sprintf at /opt/MoteWorks/tos/../make/
scripts/ident_flags line 15."

Thanks.

Jiangfan

Matthew Whipple

2007-10-30, 7:00 pm

jiangfan wrote:
> Hi,
>
> What is wrong with this statement?
>
> my $time = sprintf( "0x%08x", `date +%s` );
>
> I got
>
> "Use of uninitialized value in sprintf at /opt/MoteWorks/tos/../make/
> scripts/ident_flags line 15."
>
> Thanks.
>
> Jiangfan
>
>
>

Works for me. Check to ensure that "date +%s" is returning what you
expect from the command line.
Tom Phoenix

2007-10-30, 7:00 pm

On 10/29/07, jiangfan <Jiangfan.Shi@gmail.com> wrote:

> What is wrong with this statement?
>
> my $time = sprintf( "0x%08x", `date +%s` );


I don't know what's wrong with it on your machine, but I'd change the
command in backticks to be Perl's time operator:

my $time = sprintf("0x%08x", time);

Doesn't that do the same thing? Most simple shell commands aren't
needed from Perl.

> "Use of uninitialized value in sprintf at /opt/MoteWorks/tos/../make/
> scripts/ident_flags line 15."


Maybe your date command doesn't support that format. But Perl's time
operator should work everywhere.

Cheers!

--Tom Phoenix
Stonehenge Perl Training
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2009 codecomments.com