Warning: opendir(/var/www/html/web1/serendipity/plugins/serendipity_event_dpsyntaxhighlighter/sh/3.0.83.2/scripts/): failed to open dir: No such file or directory in /var/www/html/web1/serendipity/plugins/serendipity_event_dpsyntaxhighlighter/serendipity_event_dpsyntaxhighlighter.php on line 26

Warning: Invalid argument supplied for foreach() in /var/www/html/web1/serendipity/plugins/serendipity_event_dpsyntaxhighlighter/serendipity_event_dpsyntaxhighlighter.php on line 170
Skip to content

sposition.pl - String Positioning

The Script will find the line number and positions of the @ symbols in pos.txt.
 
# cat pos.txt
 
00000000000000000000000@00000000000000000000000000
0000000000000000@000000000000000000000000000000000
00000000000000000000000000000000000000000@0@000000
000000000000000000000@0000000000000000000000000000
00000000000000000000000000@000@0000000000000000000
 
# ./sposition.pl
1-23, 2-16, 3-41, 3-43, 4-21, 5-26, 5-30,

 
Here is the code
 
#!/usr/bin/perl
use strict;
use warnings;

my $dict = 'pos.txt';
my $c = 0;

open DICT, '<', $dict
  or
die "Cannot open '$dict': $!";

while (<DICT>) {
       
        my $string = $_;
        my $char = '@';
        my $offset = 0;
        my $result =
index($string, $char, $offset);

       
$c++;

        while ($result != -1) {
               
print "$c-$result" .", ";
                $offset = $result + 1;
                $result =
index($string, $char, $offset);
        }
}
print "\n";
close DICT;
 

Trackbacks

No Trackbacks

Comments

Display comments as Linear | Threaded

No comments

Add Comment


To prevent automated Bots from commentspamming, please enter the string you see in the image below in the appropriate input box. Your comment will only be submitted if the strings match. Please ensure that your browser supports and accepts cookies, or your comment cannot be verified correctly.
CAPTCHA 1CAPTCHA 2CAPTCHA 3CAPTCHA 4CAPTCHA 5


Textile-formatting allowed
You can use [geshi lang=lang_name [,ln={y|n}]][/geshi] tags to embed source code snippets.
Form options
Imprint | Contact | Privacy Statement

Warning: opendir(/var/www/html/web1/serendipity/plugins/serendipity_event_dpsyntaxhighlighter/sh/3.0.83.2/scripts/): failed to open dir: No such file or directory in /var/www/html/web1/serendipity/plugins/serendipity_event_dpsyntaxhighlighter/serendipity_event_dpsyntaxhighlighter.php on line 26

Warning: Invalid argument supplied for foreach() in /var/www/html/web1/serendipity/plugins/serendipity_event_dpsyntaxhighlighter/serendipity_event_dpsyntaxhighlighter.php on line 170