The_Evil_One has asked for the wisdom of the Perl Monks concerning the following question:
I am learning Perl using a book downloaded from the internet.
Opal is a system for charging fares on public transport in NSW Australia. I have had four Opal cards and they identified by 16 digit numbers. I have four target directories into which the files related to these cards go and I have tried to set up a hash to map between card numbers and the destination directories but it does not work and the error messages make no sense to me.
This is the current form of the hash definition which is at line 26 in the script:-
my %OCN_PFX_To_TDir=( 3085220111379778 => '3085220111379788_Rexx', 3085220334620644 => '3085220334620644_Spare', 3085220346432582 => '3085220346432582_Rexx2', 3085220352420034 => '3085220352420034_Algol' ); This is the input followed by the error messages I get:- carl@md-tower-004:~$ perl ~/bin/copy_opal1.plx Can't modify constant item in scalar assignment at /home/carl/bin/copy +_opal1.plx line 26, near ");" Execution of /home/carl/bin/copy_opal1.plx aborted due to compilation +errors (#1) (F) You aren't allowed to assign to the item indicated, or otherwi +se try to change it, such as with an auto-increment. Uncaught exception from user code: Can't modify constant item in scalar assignment at /home/carl/bin/ +copy_opal1.plx line 26, near ");" Execution of /home/carl/bin/copy_opal1.plx aborted due to compilat +ion errors.
I am writing a small program to copy Opal related files from my downloads directory to the appropriate destination directories.
Basically it tells me that I am trying to assign a scalar value to the % sign representing the modulus operator which cannot receive such a value but the % sign is to mark the variable as being a hash. I have tried various changes on the definition, originally I had both keys and values in double quotes now I have the values in single quotes, originally I used commas to separate key value pairs. No matter what I change the error messages remain the same.
It may be that the book I downloaded is old and some syntax suggested in the book no longer works but no matter how many queries I have put into Google and how many AI overviews I have seen and hit list links that I have followed nothing has confirmed this.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Problem Declaring a hash
by Corion (Patriarch) on Nov 05, 2025 at 20:39 UTC | |
by The_Evil_One (Initiate) on Nov 07, 2025 at 02:09 UTC | |
by soonix (Chancellor) on Nov 07, 2025 at 08:33 UTC | |
|
Re: Problem Declaring a hash
by choroba (Cardinal) on Nov 05, 2025 at 22:06 UTC | |
|
Re: Problem Declaring a hash
by jwkrahn (Abbot) on Nov 05, 2025 at 20:40 UTC |