Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic

Re^2: help with a regex

by Athanasius (Chancellor)
on Feb 02, 2013 at 03:27 UTC ( #1016637=note: print w/replies, xml ) Need Help??

in reply to Re: help with a regex
in thread help with a regex

You should print $_ instead

Or, just add the /r modifier to the substitution:

#! perl use v5.14; use warnings; use strict; my %words = (word => 1, word2 => 1, word3 => 1); my ($temp, $temp1) = qw(WORD2 word2); $_ = 'here is word2'; say s/$temp1/$words{$temp1} ? "$temp " : "[$temp] "/er;


13:14 >perl here is WORD2 13:15 >

From s/PATTERN/REPLACEMENT/msixpodualgcer in Regexp Quote Like Operators:

r Return substitution and leave the original string untouched.

Hope that helps,

Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,

Replies are listed 'Best First'.
Re^3: help with a regex
by AnomalousMonk (Chancellor) on Feb 02, 2013 at 12:29 UTC

    It should be made clear that the  s///r regex switch is only available with Perl versions 5.14 and above.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1016637]
[1nickt]: Wow, sometimes "Perl programming" hardly involves Perl! I just spent a couple of days implementing some features in the CPAN Testers API and it was 90% hand-editing JSON Swagger config and test data structs, and writing doc. Maybe that's just the sign of
[Discipulus]: rethatching? a real, old cottage?
[1nickt]: ... a well-crafted project that's easy to extend.

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (8)
As of 2017-11-21 11:51 GMT
Find Nodes?
    Voting Booth?
    In order to be able to say "I know Perl", you must have:

    Results (297 votes). Check out past polls.