jc23,
If you are trying to determine if a string contains a substring - then you probably want to use
substr index instead of a regex.
#!/usr/bin/perl -w
use strict;
my $string = 'copyright 2001, 2002';
if ( index($string,'2003') == -1 ) {
$string .= ', 2003';
}
The part I don't understand (and apparently neither did
Dragonchild) is why you can't just search for 2003. Are you saying that if it is part of a range 2000-2003 that you want to add it again?
#!/usr/bin/perl -w
use strict;
my $string = 'copyright 2000-2003';
$string .= ', 2003' if $string ~= /\b2003\b/;
If you were a little more clear on exactly what you wanted to do - with examples of different cases, we would be glad to be of more help.
Cheers - L~R
update: Thanks to tedrek for pointing out substr should have been index. /me places dunce hat on and sits in corner
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.