Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things

Bizarre usage of <>

by nevyn (Monk)
on Nov 06, 2003 at 11:53 UTC ( #305024=perlquestion: print w/replies, xml ) Need Help??
nevyn has asked for the wisdom of the Perl Monks concerning the following question:

Even though I think I know quite a bit about perl, having to maintain other peoples perl code can sometimes be "fun" :), one script I got had a construct I'd never seen before and I still can't find any documentation on it, but I assume someone here knows. This demonstrates how it was used...

my @foo = qw(a b c d A "B C" D); # Test data... print join "|", @foo; # What the test data looks like print join "|", <@foo>; # do { Magic } :) I know about using <> for IO and also as a quick way to do csh style shell expansion. But the above usage seems to use it to do some kind of shell argument grouping (it also works differently on win32 vs. Unix).

So, is there any documentation on it that I've overlooked? Is it actually guaranteed to continue doing what it does (it seems to not have changed at least between 5.0005 and 5.8.0).

Whether the person who wrote it was insane or not isn't part of my question :)

James Antill

20031106 Edit by jeffa: Changed title from 'Bizard usage of <>'

Replies are listed 'Best First'.
Re: Bizarre usage of <>
by Abigail-II (Bishop) on Nov 06, 2003 at 12:13 UTC
    @foo is created with 8 elements, the 6th being "B and the 7th is C". @foo interpolated (which happens in the glob operator) gives 'a b c d A "B C" D'. So, if you give that to the shell to expand, you give it a string that parses to seven arguments. None of the arguments contain anything wildcards or other things for the shell to expand, so you get back the same seven arguments, the 6th one being B C (the quotes have been eaten when the shell parsed the string into arguments).


      @foo interpolated (which happens in the glob operator)

      But glob() can't take an array, AFAIK. It just takes a single expression. For instance glob(@foo) turns the @foo into "8", just as doing glob(scalar(@foo)).

      So is the above a known extension to glob() when using <> (everything I'd seen just talked about <> being a shortcut, not having extra features).

      Even 5.8.0's File::Glob doesn't mention anything about being able to do shell argument expansion. And passing the list to bsd_glob() just takes the first argument. It's almost like it is doing a (join " ", @foo) somewhere.

      James Antill
        But the glob function isn't used here. It's all about the glob operator. The fish hooks are quoting constructs, just like double quotes or slashes. And hence, variables, be them scalars or arrays get interpolated.

        It's like doing glob "@foo".


Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://305024]
Approved by skx
Front-paged by broquaint
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (4)
As of 2017-05-28 00:12 GMT
Find Nodes?
    Voting Booth?