Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: strings with options - how do I do this?

by blakem (Monsignor)
on Feb 27, 2003 at 10:21 UTC ( #239048=note: print w/ replies, xml ) Need Help??


in reply to strings with options - how do I do this?

#!/usr/bin/perl -wT use strict; my $text = "my text [and maybe|and here's] more text [the end|stop]"; my @arr = parseit($text); print "$_\n" for @arr; sub parseit { my $text = shift; for ($text) { s/\[/{/g; s/\]/}/g; s/\|/,/g; } glob($text); } __END__ my text and maybe more text the end my text and maybe more text stop my text and here's more text the end my text and here's more text stop

-Blake


Comment on Re: strings with options - how do I do this?
Download Code
Re: Re: strings with options - how do I do this?
by danmcb (Monk) on Feb 27, 2003 at 10:27 UTC
    thank you Blake - that was damn fast! I'm going to check it out later. Daniel
Re: Re: strings with options - how do I do this?
by Hofmator (Curate) on Feb 27, 2003 at 10:31 UTC
    Works fine with the caveat that the string shouldn't contain any meta characters that glob might want to expand, like '*'. And this:
    for ($text) { s/\[/{/g; s/\]/}/g; s/\|/,/g; }
    could be written as: $text =~ tr/[|]/{,}/;

    -- Hofmator

      Good points... How about this:
      use File::Glob qw(:glob); sub parseit { my $text = shift; $text =~ tr/[|]/{,}/; $text =~ s/([\\?*])/\\$1/g; map {s/\\([\\?*])/$1/g; $_} bsd_glob($text, GLOB_BRACE | GLOB_NOCHECK); }

      -Blake

        thank you people ... that does it perfectly. I learnt my "something new" for today too.
Re^2: strings with options - how do I do this? (KGlob)
by tye (Cardinal) on Feb 27, 2003 at 18:22 UTC

    FYI, some Perl4 code for doing this can be found as part of File::KGlob as the unbrac() subroutine in KGlob.pm. That avoids conflicts with other "wildcard" characters.

                    - tye

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (19)
As of 2014-12-18 14:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (56 votes), past polls