i want to split it into an array becoz i want to convert the user input into regular expression with some loops

You don't need to split into an array of characters for performing the task you described. The "program" you'll need looks probably like:

... my $input = <STDIN>; chomp $input; my $regex; $regex = transform_string_to_optimal_matching_regex($input); if( $input =~ /$regex/ ) { print "regex |$regex| to input |$input| mapping succeeded\n"; } ...

Perl is really good at finding strings that match a given regular expression, but rather bad at finding regular expressions that *would match* given strings 'optimally'. The remaining task for you is therefore to enter your favorite algorithm to do that between the curly braces of the subroutine 'transform_string_to_optimal_matching_regex()':

sub transform_string_to_optimal_matching_regex { my $given_string = shift; my $regex = ''; my $optimal_solution_found = 0; while(! $optimal_solution_found ) { # # construct optimal regex by some # stochastic algorithm, possibly # long running Monte Carlo-solver # } return $regex; }

This is really an interesting thing to do. Maybe there are some approaches already published (none of which I know from).

Regards

mwa


In reply to Re: how can i split a string to an array and convert it into regular expression by mwah
in thread how can i split a string to an array and convert it into regular expression by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.