Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re^4: Count of patterns in a file without knowing pattern in advance

by roho (Canon)
on Jun 14, 2019 at 13:21 UTC ( #11101346=note: print w/replies, xml ) Need Help??


in reply to Re^3: Count of patterns in a file without knowing pattern in advance
in thread Count of patterns in a file without knowing pattern in advance

Unfortunately, this experimental feature no longer exists in perl version 5.24.1 and forward...produces the following error message:

"Experimental keys on scalar is now forbidden at -e line 1."

"It's not how hard you work, it's how much you get done."

  • Comment on Re^4: Count of patterns in a file without knowing pattern in advance

Replies are listed 'Best First'.
Re^5: Count of patterns in a file without knowing pattern in advance
by hippo (Chancellor) on Jun 14, 2019 at 13:41 UTC

    Odd - works fine for me:

    $ cat foo one two one two three one four $ perl -anE '$h{$F[0]}++}{say qq|$_ appeared $h{$_}| for sort keys %h' + foo four appeared 1 one appeared 3 three appeared 1 two appeared 2 $ perl -v | head -3 This is perl 5, version 26, subversion 1 (v5.26.1) built for x86_64-li +nux-gnu-thread-multi (with 62 registered patches, see perl -V for more detail) $

    Are you sure you substituted single quotes as NetWallah advised?

Re^5: Count of patterns in a file without knowing pattern in advance
by haukex (Chancellor) on Jun 14, 2019 at 13:37 UTC
    perl -anE "$h{$F[0]}++}{say qq|$_ appeared $h{$_}| for sort keys %h" *YOUR-FILE*
    Unfortunately, this experimental feature no longer exists in perl version 5.24.1 and forward...produces the following error message: "Experimental keys on scalar is now forbidden at -e line 1."

    Are you sure? I don't see that feature being used in this script, did you perhaps make a typo when copying it? (Update: Note the $h vs. %h in the final example below.)

    $ perl -v This is perl 5, version 28, subversion 1 (v5.28.1) built for x86_64-li +nux ... $ cat foo.txt one two three one five two ten one $ perl -anE '$h{$F[0]}++}{say qq|$_ appeared $h{$_}| for sort keys %h' + foo.txt five appeared 1 one appeared 3 ten appeared 1 three appeared 1 two appeared 2 $ perl -anE '$h{$F[0]}++}{say qq|$_ appeared $h{$_}| for sort keys $h' + foo.txt Experimental keys on scalar is now forbidden at -e line 1. Type of arg 1 to keys must be hash or array (not scalar dereference) a +t -e line 1, at EOF Execution of -e aborted due to compilation errors.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://11101346]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (3)
As of 2019-12-07 08:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Strict and warnings: which comes first?



    Results (160 votes). Check out past polls.

    Notices?