Hi Perl Monks,

I have a string which can take of 2 forms which I have mentioned below, which is part of the code

$def1 = "!defined(FLOAT_CODE)"; $def2 = "defined(FIXED_CODE)";
The string can be either of 2 forms and I need to split in the first case like

! FLOAT_CODE

and in the second case like

FIXED_CODE

but a single statement has to do it, I do not want 2 separate case for each one. Below is my perl code with different variant I have tried.

Variant:1

m/^(!defined|defined)\((.*?)\)$/; print "$1----$2\n";
This gives me like
output case1: !defined----FLOAT_CODE output case2: defined----FIXED_CODE
Variant 2:
m/^(\!|defined)(.*?)$/; print "$1----$2\n";
output case1: !----defined(FLOAT_CODE) output case2: defined----(FIXED_CODE)

But both are not helping me in solving the issue can you please help in solving this or any other method avaliable.

Regards,

-Prassi


In reply to extracting data from string by prassi

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.