in reply to Re: Adding an element to an array
in thread Adding an element to an array

Its getting there, I am getting an error as:
Can't use string ("3") as an ARRAY ref while "strict refs"
Any idea why?

Replies are listed 'Best First'.
Re^3: Adding an element to an array
by davido (Cardinal) on Oct 15, 2015 at 06:59 UTC

    Witness the following:

    $ perl -Mstrict -Mdiagnostics -E 'my $a = "3"; say $a->[0];' Can't use string ("3") as an ARRAY ref while "strict refs" in use at - +e line 1 (#1) (F) You've told Perl to dereference a string, something which use strict blocks to prevent it happening accidentally. See "Symbolic references" in perlref. This can be triggered by an @ o +r $ in a double-quoted string immediately before interpolating a varia +ble, for example in "user @$twitter_id", which says to treat the conten +ts of $twitter_id as an array reference; use a \ to have a literal @ symbol followed by the contents of $twitter_id: "user \@$twitter_i +d". Uncaught exception from user code: Can't use string ("3") as an ARRAY ref while "strict refs" in use +at -e line 1.

    If you are getting this message, then your code is doing what my code demonstrates. It may take a more complex path to get there, but the result it the same; some variable that you think has an array reference in it actually has the string "3", and you are attempting to dereference it.


    Dave

Re^3: Adding an element to an array
by poj (Abbot) on Oct 14, 2015 at 20:10 UTC

    You will need to show the code that gives that error

    poj
      Fixed it , bad data, thank you!
      We can do this with sort and uniq commands in Unix. Keep all the data in file and try below commands
      cat 1.txt|sort |uniq -c
      Output would be 1 Jane B,. Squere Rd., House 1 3 John Doe, Main Street, House 1 2 Maria D., Pat street, House B 4 Mary Lou, Central Street, House 1 the numbers before name are the number of houses the person has I can still provide you the output in required format using awk