Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: How can I use $1 in an assigned string

by Wonko the sane (Deacon)
on May 28, 2003 at 15:28 UTC ( #261338=note: print w/replies, xml ) Need Help??


in reply to How can I use $1 in an assigned string

There are more robust ways to do this, but this does what you want.

I changed your filter pattern a bit to make it more robust.
#!/usr/local/bin/perl use strict; my $filter = q{user ([^\s]+) has ([^\n\r]+)$}; my $log_string = "user bob has logged on"; $log_string =~ s/$filter/user $1 has accessed the system and is $2/; print qq{LINE: [$log_string]\n};

Outputs
:!./t2.pl LINE: [user bob has accessed the system and is logged on]
Wonko

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://261338]
help
Chatterbox?
[choroba]: Google suggests Bytes::Random:: Secure, but it's so 2015
[Yaerox]: At least I believe it's safer then Math::Random:: Secure (2010) tho. Thanks.

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (7)
As of 2016-12-06 10:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    On a regular basis, I'm most likely to spy upon:













    Results (102 votes). Check out past polls.