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

Re: searching for strings

by shoness (Friar)
on Aug 06, 2007 at 12:06 UTC ( [id://630801]=note: print w/replies, xml ) Need Help??


in reply to searching for strings

What do you do when the pattern you search for is at a boundary, taking either increment or decrement out of range? In your example above, you match near 'AAA30'. Do you only look for 'AAA30' and 'AAA31'? Do you also look for 'AAA29'? If so, the hash-key idea won't work, because you're not only changing the last character. You could do something like this for each of pattern:
my ($pat, $char) = $pattern =~ m/(.*)(.)$/; my $char_up = $char; my $char_down = $char; ++$char_up unless ($char =~ m/[9Z]/i); --$char_down unless ($char =~ m/[0A]/i); my $search = qr/$pat$char|$pat$char_up|$pat$char_down/; print $search;
How many patterns do you have anyway? How many lines do you search?

Replies are listed 'Best First'.
Re^2: searching for strings
by CountZero (Bishop) on Aug 06, 2007 at 15:21 UTC
    the -- decrement operator is not magical for non-digits.

    CountZero

    A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

      Sorry! How strange of Perl to be asymmetric! Why is "--" not as magical as "++"? This will work instead...
      $char_up =~ tr/A-Z0-9/B-ZZ1-99/; $char_down =~ tr/A-Z0-9/AA-Y00-8/;
        cauz if so it wouldn't be symmetric :)

        suppose you have "A00", if you -- you'll get "99" and then if you ++ you'll get "100"

        Oha

Log In?
Username:
Password:

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

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

    No recent polls found