Can't modify constant item in scalar assignment

E

emrefan

I have the follow script for printing out the Last Modification Time
of a file and it has been working on Solaris with Perl 5.6.1 and on
Redhat with Perl 5.8.0 without any problems.

fileLastModTm = localtime( (stat shift)[9] );
$fileLastModTm[4]++; # month no. was zero-based, change that
$fileLastModTm[5] += 1900; # year no. was 1900-based, change that
fileLastModTm[ 5, 4, 3 ]; # spit it out, in yyyymmdd format

But somebody who needed the script could not use it, getting an error
such as follows:

Can't modify constant item in scalar assignment at flmtime.pl line 1,
near ");"
Can't use subscript on constant item at flmtime.pl line 4, near "3 ]"
Execution of flmtime.pl aborted due to compilation errors.

So, what went wrong? Now, I am asking the person to give me her perl's
version, but meanwhile, I think you clever bunch can still spot the
error for me? :) Thanks.
 
U

Uri Guttman

e> I have the follow script for printing out the Last Modification Time
e> of a file and it has been working on Solaris with Perl 5.6.1 and on
e> Redhat with Perl 5.8.0 without any problems.

e> fileLastModTm = localtime( (stat shift)[9] );

that isn't a perl variable. where is @?

e> $fileLastModTm[4]++; # month no. was zero-based, change that
e> $fileLastModTm[5] += 1900; # year no. was 1900-based, change that
e> fileLastModTm[ 5, 4, 3 ]; # spit it out, in yyyymmdd format

that isn't a perl variable. where is @?

e> So, what went wrong? Now, I am asking the person to give me her perl's
e> version, but meanwhile, I think you clever bunch can still spot the
e> error for me? :) Thanks.

the code was butchered somehow as neither of those lines has a proper
perl variable.

besides that it would be better done with strftime.

uri
 
E

emrefan

e> I have the follow script for printing out the Last Modification Time
e> of a file and it has been working on Solaris with Perl 5.6.1 and on
e> Redhat with Perl 5.8.0 without any problems.

e> fileLastModTm = localtime( (stat shift)[9] );

that isn't a perl variable. where is @?

e> $fileLastModTm[4]++; # month no. was zero-based, change that
e> $fileLastModTm[5] += 1900; # year no. was 1900-based, change that
e> fileLastModTm[ 5, 4, 3 ]; # spit it out, in yyyymmdd format

that isn't a perl variable. where is @?

e> So, what went wrong? Now, I am asking the person to give me her perl's
e> version, but meanwhile, I think you clever bunch can still spot the
e> error for me? :) Thanks.

the code was butchered somehow as neither of those lines has a proper
perl variable.

besides that it would be better done with strftime.

uri

I asure you that the whole script was quoted and nothing was butchered
off. I have not been an active perl programmer but I guess @_ (i.e.
@ARGV) was implied to the shift command? As I said, the script does
run fine on two platforms, that's why I am puzzled.
 
K

Keith Keller

"e" == emrefan <[email protected]> writes:

e> fileLastModTm = localtime( (stat shift)[9] );

that isn't a perl variable. where is @?

e> fileLastModTm[ 5, 4, 3 ]; # spit it out, in yyyymmdd format

that isn't a perl variable. where is @?
I asure you that the whole script was quoted and nothing was butchered
off.

Then the script is broken. Fix it. Your script should include

use strict;
use warnings;

which would have pointed out these obvious errors for you.
I have not been an active perl programmer but I guess @_ (i.e.
@ARGV) was implied to the shift command?

Irrelevant, as fileLastModTm is not a Perl variable, which is where both
your problems lie.
As I said, the script does
run fine on two platforms, that's why I am puzzled.

I'm skeptical, but it still doesn't matter, as the script as you posted
it is wrong (or at the very least poorly written).

You should consider reading the Posting Guidelines, which help you write
a post which is likely to get you a helpful response.

--keith
 
E

emrefan

e> I have the follow script for printing out the Last Modification Time
e> of a file and it has been working on Solaris with Perl 5.6.1 and on
e> Redhat with Perl 5.8.0 without any problems.

e> fileLastModTm = localtime( (stat shift)[9] );

that isn't a perl variable. where is @?

e> $fileLastModTm[4]++; # month no. was zero-based, change that
e> $fileLastModTm[5] += 1900; # year no. was 1900-based, change that
e> fileLastModTm[ 5, 4, 3 ]; # spit it out, in yyyymmdd format

that isn't a perl variable. where is @?

e> So, what went wrong? Now, I am asking the person to give me her perl's
e> version, but meanwhile, I think you clever bunch can still spot the
e> error for me? :) Thanks.

the code was butchered somehow as neither of those lines has a proper
perl variable.

besides that it would be better done with strftime.

uri

Ah, I looked at the thing closely just now and boy what blunder did I
make! So a @ was missing from the 1st line and "print $" was missing
from the last line. Gosh, I never imagined a cut-n-paste job could be
messed up like that. But I was to blame too, I didn't look before I
jump, er, ask. Sorry for wasting the bandwidth and your time. I've
learnt something from this though, if that's any comfort - I will not
make such a silly mistake, in public especially, again.
 

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,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top