Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: Pattern Matching Query

by davorg (Chancellor)
on Sep 17, 2002 at 12:52 UTC ( [id://198475]=note: print w/replies, xml ) Need Help??


in reply to Pattern Matching Query

Regexes aren't always the answer. This solution uses substr and the magical autoincrement properties of strings.

#!/usr/bin/perl -w use strict; while (<DATA>) { chomp; my $card = substr $_, 0, 1; my $run = 1; foreach my $x (1 .. 4) { ++$card ne substr $_, $x, 1 and $run = 0, last; } print "$_ - ", $run ? 'yep' : 'nope', "\n"; } __DATA__ abcde abcef fghij acghm

Update: Argh! Or either of the previous answers would probably be better :(

--
<http://www.dave.org.uk>

"The first rule of Perl club is you do not talk about Perl club."
-- Chip Salzenberg

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://198475]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (3)
As of 2024-04-19 16:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found