Sponsored Content
Top Forums Shell Programming and Scripting PERL : Sort substring occurrences in array of strings Post 302493662 by sinpeak on Thursday 3rd of February 2011 10:05:28 AM
Old 02-03-2011
PERL : Sort substring occurrences in array of strings

Hi,

My developer is on vacation and I am not sure if there is something which is easier for this.

I have an array of strings. Each string in the array has "%" characters in it. I have to get the string(s) which have the least number of "%" in them.

I know how I can get occurrences :
Code:
 
my @str;
...array population here...
my $count = ($str =~ tr/"%"//);

But I am not sure what is the best way to get the string(s) with least number of "%"'s.

Any advise/help is highly appreciated.

Thanks.
sinpeak
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

sort() array of strings in perl

I have a perl script with an array of clients. @arr = ("The ABC Corp", "AA Corp.", "BB Corp"); If I run @a = sort (@arr); I will get @a = ("AA Corp", "BB Corp", "The ABC Corp"); but I want @a = ("AA Corp, "The ABC Corp", "BB Corp"); How do I sort array without changing... (2 Replies)
Discussion started by: photon
2 Replies

2. Shell Programming and Scripting

How to sort lines by substring

Dear all There is a file which contains the following formatted files. I need to sort it by substring(strings after dot) in order to process efficiently. Please give me any idea how to sort it. Sample file: 1AAABBBCCC.20080401 1AAABBBCCC.20080402 2AAABBBCCC.20080401... (3 Replies)
Discussion started by: mr_bold
3 Replies

3. Shell Programming and Scripting

Can we pass an array of strings from a Perl Program to a Shell Script?

Hi Folks, The subject is my question: Can we pass an array of strings from a Perl Program to a Shell Script? Please provide some sample code. Thanks ---------- Post updated at 11:52 PM ---------- Previous update was at 11:43 PM ---------- I got it. Its here:... (0 Replies)
Discussion started by: som.nitk
0 Replies

4. UNIX for Dummies Questions & Answers

Sort after 2. column in array in Perl

Hey How do I sort an array numerically after the second column? My values are integers like 1, 2, 3, 4... and they are not unique, so I can't just reverse my hash and sort by keys. I wanna sort my file/array so that I get the lines with the highest value in the top - that is descending. ... (2 Replies)
Discussion started by: Banni
2 Replies

5. Shell Programming and Scripting

perl sort array by field

Hi Everyone, Any simple code can simplify the code below, please advice. Thanks # cat 2.pl #!/usr/bin/perl use warnings; use strict; my @aaaaa = <DATA>; my @uids; foreach (@aaaaa) { my @ccccc = split (",", $_); push @uids, $ccccc;... (3 Replies)
Discussion started by: jimmy_y
3 Replies

6. UNIX for Dummies Questions & Answers

Print number of occurrences of many different strings

People, I need your help with making a script which will 1. take as an input the number of lines, smth like this: ((RUBROBACTER_1_PE1288 (((SALINISPORA_1_PE1863 SALINISPORA_1_PE1828)100 ((NOCARDIOIDES_2_PE2419 PROPIONIBACTERIUM_1_PE1395)96 ((((((((CORYNEBACTERIUM_1_PE1119... (3 Replies)
Discussion started by: roussine
3 Replies

7. Shell Programming and Scripting

how many occurrences of different strings are there in each FILE.

Hello , I need some help to pull the data from different files, simultaneously for the string provided. I want to search below strings. PTN:3763427632478 IDB:3298734287438 PTN:8734983298738 From the files BELOW CODE_FILE_LOG1 CODE_FILE_LOG2 CODE_FILE_LOG3 CODE_FILE_LOG4 (3 Replies)
Discussion started by: baraghun
3 Replies

8. UNIX for Dummies Questions & Answers

Replace all occurrences of strings with parentheses

Hi, I tried to adapt bartus's solution to my problem, without success. I want to replace all the occurences of this: with: , where something can contain an arbitrary number of balanced parens and brakets. Any ideas ? Best, (1 Reply)
Discussion started by: ff1969ff1969
1 Replies

9. Linux

How to sort the number of occurrences

file:///C:/Users/TSHEPI%7E1.LEB/AppData/Local/Temp/moz-screenshot.pngATM@ubuntu:~$ cat numbers2 | sort -n | uniq -c 1 7 1 11 2 10 3 the 1st numbers are the counts from the command "uniq -c", which represent the number of occurrences of each in the file. The "sort -n"... (4 Replies)
Discussion started by: lebogot
4 Replies

10. Shell Programming and Scripting

GREP between last occurrences of two strings

Hi I have the server.log file as: Server Stopped ABC DEF GHI JKL Server Started MNO PQR STU Server Stopped VWX YZ ABC Server Started Server Stopped 123 456 789 (9 Replies)
Discussion started by: ankur328
9 Replies
MB_ENCODE_NUMERICENTITY(3)						 1						MB_ENCODE_NUMERICENTITY(3)

mb_encode_numericentity - Encode character to HTML numeric string reference

SYNOPSIS
string mb_encode_numericentity (string $str, array $convmap, [string $encoding = mb_internal_encoding()], [bool $is_hex = FALSE]) DESCRIPTION
Converts specified character codes in string$str from character code to HTML numeric character reference. PARAMETERS
o $str - The string being encoded. o $convmap -$convmap is array specifies code area to convert. o $encoding -The $encoding parameter is the character encoding. If it is omitted, the internal character encoding value will be used. o $is_hex - RETURN VALUES
The converted string. CHANGELOG
+--------+---------------------------+ |Version | | | | | | | Description | | | | +--------+---------------------------+ | 5.4.0 | | | | | | | Added $is_hex parameter. | | | | +--------+---------------------------+ EXAMPLES
Example #1 $convmap example <?php $convmap = array ( int start_code1, int end_code1, int offset1, int mask1, int start_code2, int end_code2, int offset2, int mask2, ........ int start_codeN, int end_codeN, int offsetN, int maskN ); // Specify Unicode value for start_codeN and end_codeN // Add offsetN to value and take bit-wise 'AND' with maskN, then // it converts value to numeric string reference. ?> EXAMPLES
Example #2 mb_encode_numericentity(3) example <?php /* Convert Left side of ISO-8859-1 to HTML numeric character reference */ $convmap = array(0x80, 0xff, 0, 0xff); $str = mb_encode_numericentity($str, $convmap, "ISO-8859-1"); /* Convert user defined SJIS-win code in block 95-104 to numeric string reference */ $convmap = array( 0xe000, 0xe03e, 0x1040, 0xffff, 0xe03f, 0xe0bb, 0x1041, 0xffff, 0xe0bc, 0xe0fa, 0x1084, 0xffff, 0xe0fb, 0xe177, 0x1085, 0xffff, 0xe178, 0xe1b6, 0x10c8, 0xffff, 0xe1b7, 0xe233, 0x10c9, 0xffff, 0xe234, 0xe272, 0x110c, 0xffff, 0xe273, 0xe2ef, 0x110d, 0xffff, 0xe2f0, 0xe32e, 0x1150, 0xffff, 0xe32f, 0xe3ab, 0x1151, 0xffff ); $str = mb_encode_numericentity($str, $convmap, "sjis-win"); ?> SEE ALSO
mb_decode_numericentity(3). PHP Documentation Group MB_ENCODE_NUMERICENTITY(3)
All times are GMT -4. The time now is 10:58 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy