Can't modify constant item in scalar assignment

Discussion in 'Perl Misc' started by emrefan, Jun 5, 2007.

  1. emrefan

    emrefan Guest

    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.
     
    emrefan, Jun 5, 2007
    #1
    1. Advertising

  2. emrefan

    Uri Guttman Guest

    >>>>> "e" == emrefan <> 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.stemsystems.com
    --Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
    Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
     
    Uri Guttman, Jun 5, 2007
    #2
    1. Advertising

  3. emrefan

    emrefan Guest

    On Jun 5, 10:30 am, Uri Guttman <> wrote:
    > >>>>> "e" == emrefan <> 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.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.
     
    emrefan, Jun 5, 2007
    #3
  4. emrefan

    Keith Keller Guest

    On 2007-06-05, emrefan <> wrote:
    > On Jun 5, 10:30 am, Uri Guttman <> wrote:
    >> >>>>> "e" == emrefan <> 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


    --
    -francisco.ca.us
    (try just my userid to email me)
    AOLSFAQ=http://www.therockgarden.ca/aolsfaq.txt
    see X- headers for PGP signature information
     
    Keith Keller, Jun 5, 2007
    #4
  5. emrefan

    emrefan Guest

    On Jun 5, 10:30 am, Uri Guttman <> wrote:
    > >>>>> "e" == emrefan <> 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.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.
     
    emrefan, Jun 5, 2007
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Purl Gurl
    Replies:
    0
    Views:
    922
    Purl Gurl
    Aug 18, 2003
  2. Replies:
    0
    Views:
    1,010
  3. CoolPint
    Replies:
    20
    Views:
    1,823
    Old Wolf
    Jul 26, 2004
  4. Clint Olsen
    Replies:
    6
    Views:
    401
    Jeff 'japhy' Pinyan
    Nov 13, 2003
  5. Mark

    Replace scalar in another scalar

    Mark, Jan 27, 2005, in forum: Perl Misc
    Replies:
    4
    Views:
    191
    Arndt Jonasson
    Jan 27, 2005
Loading...

Share This Page