in reply to Prevent Strings From Being Interpreted As A File Handle
However, my question is: How can I disambiguate a method call on a string so that it is always resolved as a class method call, and not as a call on an IO instance?
You can't :) apparently filehandles rule the typeglob, thats why it hasn't been recommended for a long time
$ perl -fle " sub Snacks::Ahoy { q{Nom} } open Snacks, q{>}, \q{}; pri +nt $Snacks::{Ahoy}->() " Nom $ perl -fle " sub Snacks::Ahoy { q{Nom} } open Snacks, q{>}, \q{}; pri +nt bless(\(my$q=\{Snacks}),q{Snacks})->Ahoy " Nom $ perl -fle " sub Snacks::Ahoy { q{Nom} } sub Snacks { q{Rice} } print + Snacks::->Ahoy " Nom $ perl -fle " sub Snacks::Ahoy { q{Nom} } open Snacks , q{<}, \q{Rice} +; print Snacks::->Ahoy " Can't locate object method "Ahoy" via package "IO::File" at -e line 1.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Prevent Strings From Being Interpreted As A File Handle
by Anonymous Monk on Apr 27, 2014 at 11:13 UTC | |
by amon (Scribe) on Apr 27, 2014 at 14:33 UTC | |
by tobyink (Canon) on Apr 27, 2014 at 14:05 UTC |