peppiv has asked for the wisdom of the Perl Monks concerning the following question:
Thanks for reading this. I'm having difficulty with a simple substitution that I want to occur only once. I've RTFM'd (Cookbook) but can't find the exact solution.
Let's see what silly things I've done.(The following code is stripped down for time/space convenience)
Any ideas? Any direction someone could point me to?
peppiv
Let's see what silly things I've done.(The following code is stripped down for time/space convenience)
I'd like it to print 'Tunnel 1/2 HR PT'. But what I get is 'Part Time No Clockunnel 1/2 HR PPart Time No Clock'. The substitutions for the single letters matches also. I'd only want them to match exactly on single letter values. I've tried using the match exact {1} but I couldn't get it to work.#!/usr/bin/perl -Tw use strict; $result = "43 P"; #comes from somewhere else in the program interpret_clock($result); sub interpret_clock { $_[0] =~ s/43 F/Tunnel 1\/2 Hr FT/o; $_[0] =~ s/43 P/Tunnel 1\/2 Hr PT/o; $_[0] =~ s/45 F/Tunnel No Lunch FT/o; $_[0] =~ s/45 P/Tunnel No Lunch PT/o; $_[0] =~ s/F/Full Time No Clock/o; $_[0] =~ s/O/On Call No Clock/o; $_[0] =~ s/P/Part Time No Clock/o; $_[0] =~ s/T/Temporary No Clock/o; } print $result;
Any ideas? Any direction someone could point me to?
peppiv
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Regex Substitution in sub
by Ovid (Cardinal) on Jun 04, 2003 at 18:12 UTC | |
by Juerd (Abbot) on Jun 04, 2003 at 18:51 UTC | |
by Ovid (Cardinal) on Jun 04, 2003 at 19:07 UTC | |
Re: Regex Substitution in sub
by dws (Chancellor) on Jun 04, 2003 at 18:16 UTC | |
Re: Regex Substitution in sub
by thelenm (Vicar) on Jun 04, 2003 at 18:18 UTC | |
by peppiv (Curate) on Jun 04, 2003 at 18:26 UTC | |
Re: Regex Substitution in sub
by artist (Parson) on Jun 04, 2003 at 18:16 UTC | |
Re: Regex Substitution in sub
by pzbagel (Chaplain) on Jun 04, 2003 at 18:16 UTC | |
Re: Regex Substitution in sub
by Aristotle (Chancellor) on Jun 04, 2003 at 23:31 UTC | |
by Juerd (Abbot) on Jun 04, 2003 at 23:36 UTC | |
by Aristotle (Chancellor) on Jun 04, 2003 at 23:46 UTC | |
by Juerd (Abbot) on Jun 05, 2003 at 07:06 UTC | |
Re: Regex Substitution in sub
by peppiv (Curate) on Jun 04, 2003 at 18:04 UTC |
Back to
Seekers of Perl Wisdom