Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re^2: Find the common beginning substring in an array of strings (Updated)

by brx (Pilgrim)
on Jun 07, 2012 at 11:50 UTC ( [id://974922]=note: print w/replies, xml ) Need Help??

Help for this page

Select Code to Download


  1. or download this
    my @array_of_test_names = (
        "History--abcdef",
    ...
        "History--123",
        "History--1X",
    );
    
  2. or download this
    my $mask = '';
    $mask ^= $_ ^ $array_of_test_names[0] for @array_of_test_names;
    $mask =~ m[^(\0+)] and $len = length( $1 );
    print substr $array_of_test_names[ 0 ], 0, $len;
    print "\n";
    
  3. or download this
    my $res = '';
    for my $i ( 0 .. (length($array_of_test_names[0]) -1)) {
    ...
        $res .= $letter;
    };
    print $res,"\n";
    

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (8)
As of 2024-04-23 22:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found