I don't know for sure where you are going with this, but the code as you have it won't work. as you are missing the tilde after the $line= in both your conditionals. Anyhow I think this is what you meant:
my $line='0x160001a \"fubar - BlahBlahBlah - Blah Blah (1:23)\": ("Foo +" "Bar") Baz'; if ($line=~/\)/){ $line="$`)"; } if ($line=~/-\s/){ $line=$'; }
But as anything else you can always set the values of $' and $` to a variable and use those variables later on:
use strict; use warnings; my ($prematch,$postmatch); my $line='0x160001a \"fubar - BlahBlahBlah - Blah Blah (1:23)\": ("Foo +" "Bar") Baz'; if ($line=~/\)/){$line="$`)"; $prematch = $`;} if ($line=~/-\s/){$line=$'; $postmatch = $';} print $prematch,$/; print $postmatch,$/; print $line,$/;
And you can use both $' and $` after you get a successful match in the current dynamic scope (as long as you are still in the current dynamic scope). Though I would probably solve the problem differently than you are doing by the same reasoning as you above.

Here comes my simple question: since the first - occurs before the values that I want, and because the first ) occurs afterwards,

use strict; use warnings; my $line='0x160001a \"fubar - BlahBlahBlah - Blah Blah (1:23)\": ("Foo +" "Bar") Baz'; if ( $line =~ /- ([^\)]+\))/ ) { print $1; $line = $1;}
which captures in $1 what you described, and doesn't suffer from the performance penalty of using $' or $`

-enlil


In reply to Re: Simple re question by Enlil
in thread Simple re question by DarknessX

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.