Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Can't modify constant item in scalar assignment

Reply
Thread Tools

Can't modify constant item in scalar assignment

 
 
emrefan
Guest
Posts: n/a
 
      06-05-2007
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.

 
Reply With Quote
 
 
 
 
Uri Guttman
Guest
Posts: n/a
 
      06-05-2007
>>>>> "e" == emrefan <(E-Mail Removed)> writes:

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

--
Uri Guttman ------ http://www.velocityreviews.com/forums/(E-Mail Removed) -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
 
Reply With Quote
 
 
 
 
emrefan
Guest
Posts: n/a
 
      06-05-2007
On Jun 5, 10:30 am, Uri Guttman <(E-Mail Removed)> wrote:
> >>>>> "e" == emrefan <(E-Mail Removed)> writes:

>
> 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
>
> --
> Uri Guttman ------ (E-Mail Removed) --------http://www.stemsystems.com
> --Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
> Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org


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.

 
Reply With Quote
 
Keith Keller
Guest
Posts: n/a
 
      06-05-2007
On 2007-06-05, emrefan <(E-Mail Removed)> wrote:
> On Jun 5, 10:30 am, Uri Guttman <(E-Mail Removed)> wrote:
>> >>>>> "e" == emrefan <(E-Mail Removed)> 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


--
http://www.velocityreviews.com/forums/(E-Mail Removed)-francisco.ca.us
(try just my userid to email me)
AOLSFAQ=http://www.therockgarden.ca/aolsfaq.txt
see X- headers for PGP signature information

 
Reply With Quote
 
emrefan
Guest
Posts: n/a
 
      06-05-2007
On Jun 5, 10:30 am, Uri Guttman <(E-Mail Removed)> wrote:
> >>>>> "e" == emrefan <(E-Mail Removed)> writes:

>
> 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
>
> --
> Uri Guttman ------ (E-Mail Removed) --------http://www.stemsystems.com
> --Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
> Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org


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.

 
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
Assignment from scalar to user-defined type Richard Cavell C++ 2 03-06-2005 09:26 AM
Replace scalar in another scalar Mark Perl Misc 4 01-27-2005 02:48 PM
Shorthand for($scalar) loops and resetting pos($scalar) Clint Olsen Perl Misc 6 11-13-2003 12:50 AM
Re: Error: can't modify scalar reference nobull@mail.com Perl 0 08-18-2003 04:56 PM
Re: Error: can't modify scalar reference Purl Gurl Perl 0 08-18-2003 07:51 AM



Advertisments