http://qs1969.pair.com?node_id=1177188


in reply to Re^2: How do I determine if a variable contains a type glob?
in thread How do I determine if a variable contains a type glob?

Man, you really talk a lot of twaddle!

The OP asked about globs (e.g. *ARGV)

And what do you think *fh is. (It's rhetorical.)

Furthermore, use of ref instead of reftype will fail if the referenced var is blessed.

How can "the reference be blessed", when (as you unnecessarily pointed out yourself) he asked about *GLOB not \*GLOB. It can't; because my suggestion was that he take the reference himself.

Ie. His sub becomes something like:

sub isIt{ local $^W; ref( \$_[0] ) =~ m[GLOB] ? 1 : 0; }

And it is used like this:

[0]{} Perl> printf "%s: %d\n", $_, isIt( $_ ) for *ARGV, *INC, *SIG, * +MATCH, *FH, *A, *B, *STDOUT, *CORE::say;; # *anything *main::ARGV: 1 *main::INC: 1 *main::SIG: 1 *main::MATCH: 1 *main::FH: 1 *main::A: 1 *main::B: 1 *main::STDOUT: 1 *CORE::say: 1

And

... if the referenced var is blessed.

You don't (*CAN'T*) bless a var; only a reference to one!

You can pop-down now.


With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority". The enemy of (IT) success is complexity.
In the absence of evidence, opinion is indistinguishable from prejudice.

Replies are listed 'Best First'.
Re^4: How do I determine if a variable contains a type glob? (bless)
by tye (Sage) on Dec 05, 2016 at 07:08 UTC

    Just FYI, when you bless a reference, the blessing is actually stored in the referenced variable. So, due to this current implementation detail, your code can actually be tripped up by such a weird scenario:

    my $glob = *X; my $ref = bless \$glob; print ref(\$glob); __END__ main

    - tye        

Re^4: How do I determine if a variable contains a type glob?
by ikegami (Patriarch) on Dec 05, 2016 at 07:18 UTC

    And what do you think *fh is.

    A glob, what you should have used instead of \*fh.

    You don't (*CAN'T*) bless a var; only a reference to one!

    Actually, you have that backwards. I've never seen a blessed reference. You have to pass a reference to bless, but it's the var that gets blessed. Otherwise, the following would fail:

    sub foo { CORE::say "ok" } my %h; my $ref1 = \%h; my $ref2 = \%h; bless($ref1); $ref2->foo();

    How can "the reference be blessed",

    I said ref would fail if the glob is blessed.

    $ perl -MScalar::Util=reftype -e' CORE::say ref(\*FOO); CORE::say reftype(\*FOO); bless(\*FOO); CORE::say ref(\*FOO); CORE::say reftype(\*FOO); ' GLOB GLOB main GLOB
Re^4: How do I determine if a variable contains a type glob?
by dpchrist (Initiate) on Dec 07, 2016 at 02:16 UTC

    I like the way you disable all warnings. :-) But, why? (I have some ideas, but I ask just to be sure.)

    local $^W;
      But, why?

      That code was typed straight into the web page and not tested. In general if you have an isItSomething() routine returning a bool, you don't want it to produce any warnings, just return false if what you've been passed isn't what you're testing for.

      The fact that there appears to be nothing you can give to ref that produces a warning means it is probably redundant.


      With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority". The enemy of (IT) success is complexity.
      In the absence of evidence, opinion is indistinguishable from prejudice.
Re^4: How do I determine if a variable contains a type glob?
by dpchrist (Initiate) on Dec 07, 2016 at 02:21 UTC

    Why are you using a regular expression match, rather than string equality 'eq'?

    ref( \$_[0] ) =~ m[GLOB]

      Because it was typed straight into the website, and I was probably thinking about:

      print \*ARGV;; GLOB(0x28a860)

      when I typed it.


      With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority". The enemy of (IT) success is complexity.
      In the absence of evidence, opinion is indistinguishable from prejudice.