Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re^4: Working with Binary Numbers

by salva (Canon)
on Sep 25, 2007 at 14:50 UTC ( [id://640955]=note: print w/replies, xml ) Need Help??


in reply to Re^3: Working with Binary Numbers
in thread Working with Binary Numbers

That's what bash docs says about the matter:
Brace Expansion Brace expansion is a mechanism by which arbitrary strings may b +e gener- ated. This mechanism is similar to pathname expansion, but t +he file- names generated need not exist. Patterns to be brace expanded +take the form of an optional preamble, followed by either a series of co +mma-sep- arated strings or a sequence expression between a pair of brace +s, fol- lowed by an optional postscript. The preamble is prefixed + to each string contained within the braces, and the postscript is then +appended to each resulting string, expanding left to right. Brace expansions may be nested. The results of each expande +d string are not sorted; left to right order is preserved. For +example, a{d,c,b}e expands into `ade ace abe'. A sequence expression takes the form {x..y}, where x and y ar +e either integers or single characters. When integers are supplied, the + expres- sion expands to each number between x and y, inclusive. When + charac- ters are supplied, the expression expands to each character + lexico- graphically between x and y, inclusive. Note that both x and y + must be of the same type. Brace expansion is performed before any other expansions, and a +ny char- acters special to other expansions are preserved in the result +. It is strictly textual. Bash does not apply any syntactic interpreta +tion to the context of the expansion or the text between the braces. A correctly-formed brace expansion must contain unquoted ope +ning and closing braces, and at least one unquoted comma or a valid +sequence expression. Any incorrectly formed brace expansion is left un +changed. A { or , may be quoted with a backslash to prevent its being co +nsidered part of a brace expression. To avoid conflicts with paramete +r expan- sion, the string ${ is not considered eligible for brace expans +ion. This construct is typically used as shorthand when the common p +refix of the strings to be generated is longer than in the above example +: mkdir /usr/local/src/bash/{old,new,dist,bugs} or chown root /usr/{ucb/{ex,edit},lib/{ex?.?*,how_ex}} Brace expansion introduces a slight incompatibility with hi +storical versions of sh. sh does not treat opening or closing braces s +pecially when they appear as part of a word, and preserves them in the + output. Bash removes braces from words as a consequence of brace ex +pansion. For example, a word entered to sh as file{1,2} appears identi +cally in the output. The same word is output as file1 file2 after expan +sion by bash. If strict compatibility with sh is desired, start bash +with the +B option or disable brace expansion with the +B option to the +set com- mand (see SHELL BUILTIN COMMANDS below).

Replies are listed 'Best First'.
Re^5: Working with Binary Numbers ({not,here})
by tye (Sage) on Sep 25, 2007 at 15:18 UTC

    Just to be clearer, if you read the first two sentences of the long section you quoted, it answers your original concern:

    Brace expansion is a mechanism by which arbitrary strings may be generated. This mechanism is similar to pathname expansion, but the filenames generated need not exist.

    So, no, this is not a bug.

    - tye        

Re^5: Working with Binary Numbers
by ikegami (Patriarch) on Sep 25, 2007 at 15:19 UTC

    If bash had any bearing in the matter — glob is based on csh's expansion mechanism — it seems to me you just disproved yourself. "the filenames generated need not exist."

      it seems to me you just disproved yourself.

      yes, that was my intention :-)

      I was not trying to maintain my position but just to follow the "The documentation I could find isn't great on this point" on blokhead response.

      That's also why I used bash docs instead of csh, because they looked more clear to me and with regard to brace expansion, both shells behave the same.

        Okay, so it's clear I don't understand how blokhead is using glob in this clever way. If I had files in the current directory that looked like one of the bit-vector patterns ("0000", "1-01", etc.) would that break his/her scheme? Can I trouble someone to break down that magic line of his:
        my @data = qw( 000- 0101 011- 1-0- ); my @expanded = map { (my $s = $_) =~ s/-/{0,1}/g; glob($s) } @data;
        There is a CPAN module Text::Glob that looks like it does what this usage intends, without involving file globbing. The disadvantage is that it takes hundreds of lines to do what blokhead does in one line.

        That's Perl though!
        Thanks Again!

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (3)
As of 2024-04-24 05:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found