substring

2005-08-17 Thread marcos rebelo
If I'm not wrong, Changing this lines: my @col = grep(!/\t/, split(/(\t)/, $line)); push(@col, "") if $line =~ /\t$/; by $line .= "\t"; my @col; my $lastIndex = 0; foreach my $actualIndex (0..length

Substring retrieval

2001-06-04 Thread Nathaniel Mallet
Hi, I'm trying to retrieve a substring from a string, but I'm not sure exactly where and how big that substring is. The substring is delimited by a start and end special character. It was suggested to me to write two regular expression, one that would match everything up to and

substring replacement

2001-06-20 Thread Mark Bedish
This is my first posting so forgive my ignorance. I am using substrings in a screipt and wondered if there was a better perlish way to do it. I am taking data from a mainframe system and reformatting it but the substring seems to be quite slow, like visual basic, the original. Any pointers on a

substring problems

2003-03-18 Thread tao wang
Hi Everyone, I'm having a problem with extracting certain strings within a line. I tried several ways, but not very inefficient. Can somebody help me with it? thanks a lot. The line might be one of the following: KEY1 3 4 T KEY2 KEY1 3 4 T KEY2 456 67 KEY3 KEY1 3 4 T KEY2

about substring

2005-05-09 Thread Aditi Gupta
Hi everybody, Can we use substr function for a string like: $file = atom 12 N VAL A 1 12.435 13.66 34.6 32.1 32 a N can the decimal numbers be extracted using $x= substr($file, offset, length) (the exact field lenghts of each field are known). Thanks in advance.. -- To unsubscribe, e-ma

Re: substring

2005-08-17 Thread Jeff 'japhy' Pinyan
On Aug 17, marcos rebelo said: my @col = grep(!/\t/, split(/(\t)/, $line)); push(@col, "") if $line =~ /\t$/; Wow. That could have just been my @col = split /\t/, $line; push @col, "" if $line =~ /\t$/; which should REALLY have been written as my @col = split /\t/, $line, -1; The

Re: substring

2005-08-17 Thread Paul Johnson
On Wed, Aug 17, 2005 at 06:26:16PM +0100, marcos rebelo wrote: > If I'm not wrong, Changing this lines: > > my @col = grep(!/\t/, split(/(\t)/, $line)); > push(@col, "") if $line =~ /\t$/; > > > by > > > $line .= "\t"; > my @col;

Re: substring

2005-08-17 Thread marcos rebelo
On 8/17/05, Paul Johnson <[EMAIL PROTECTED]> wrote: > On Wed, Aug 17, 2005 at 06:26:16PM +0100, marcos rebelo wrote: > > > If I'm not wrong, Changing this lines: > > > > my @col = grep(!/\t/, split(/(\t)/, $line)); > > push(@col, "") if $line =~ /\t$/; > > > > > > b

Re: Substring retrieval

2001-06-04 Thread Eduard Grinvald
Ok, the best way (in my opinion), would be, assuming 's' and 'e' are the start/end special characters: $string =~ s/^.*?(s.*e).*$/$1/; - Original Message - From: "Nathaniel Mallet" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Monday

Re: Substring retrieval

2001-06-04 Thread Hasanuddin Tamir
On Mon, 4 Jun 2001, Nathaniel Mallet <[EMAIL PROTECTED]> wrote, > Date: Mon, 4 Jun 2001 21:06:43 -0400 > From: Nathaniel Mallet <[EMAIL PROTECTED]> > To: [EMAIL PROTECTED] > Subject: Substring retrieval > > Hi, > > I'm trying to retrieve a

Re: Substring retrieval

2001-06-05 Thread Paul
--- Nathaniel Mallet <[EMAIL PROTECTED]> wrote: > Hi, > > I'm trying to retrieve a substring from a string, but I'm not > sure exactly where and how big that substring is. The substring is > delimited by a start and end special character. It was suggest

Re: Substring retrieval

2001-06-05 Thread Carl Rogers
Good day; At 08:17 AM 6/5/2001 -0700, Paul wrote: >--- Nathaniel Mallet <[EMAIL PROTECTED]> wrote: > > Hi, > > > > I'm trying to retrieve a substring from a string, but I'm not > > sure exactly where and how big that substring is. The substring

Re: Substring retrieval

2001-06-05 Thread Nathaniel Mallet
t; <[EMAIL PROTECTED]> To: "Nathaniel Mallet" <[EMAIL PROTECTED]> Cc: <[EMAIL PROTECTED]> Sent: Monday, June 04, 2001 10:21 PM Subject: Re: Substring retrieval > On Mon, 4 Jun 2001, Nathaniel Mallet <[EMAIL PROTECTED]> wrote, > > > Date: Mon, 4 Ju

Re: Substring retrieval

2001-06-05 Thread Hasanuddin Tamir
On Tue, 5 Jun 2001, Nathaniel Mallet <[EMAIL PROTECTED]> wrote, > The Index function isn't listed on the perl.com website, which was the only > place I looked for documentation up until now. I haven't recieved my Perl > books from Fatbrain yet. ;-) It's always right there (among other functions

Re: Substring retrieval

2001-06-06 Thread Will W
- Original Message - From: Hasanuddin Tamir <[EMAIL PROTECTED]> To: Nathaniel Mallet <[EMAIL PROTECTED]> Cc: <[EMAIL PROTECTED]> Sent: Tuesday, June 05, 2001 8:38 PM Subject: Re: Substring retrieval > On Tue, 5 Jun 2001, Nathaniel Mallet <[EMAIL PROTECTED]

Re: substring replacement

2001-06-20 Thread Michael Fowler
On Wed, Jun 20, 2001 at 11:41:29PM +0100, Mark Bedish wrote: > I am using substrings in a screipt and wondered if there was a better > perlish way to do it. I am taking data from a mainframe system and > reformatting it but the substring seems to be quite slow, like visual > basic,

Re: substring replacement

2001-06-21 Thread Michael Fowler
On Thu, Jun 21, 2001 at 08:29:05PM +0100, Mark Bedish wrote: > I am putting tabs between the fields and then changing the a13 which is > a tso overpunch to its decimal equiv, e.g. 1234} means -123.40 . How.. odd. > As I hinted, my code is very procedural as I am not used to Perl yet. Procedur

Re: substring replacement

2001-06-21 Thread Mark Bedish
On 20/6/01 at 3:44 pm, [EMAIL PROTECTED] (Michael Fowler) wrote: Thank for your help, I'll try some of it out and let you know. The data comes from a mainframe system and going to be loaded into MS SQL Server database. I am really impressed by Perl, it can do easy things so quickly. > > > my @

Re: substring problems

2003-03-18 Thread Rob Dixon
Tao Wang wrote: > Hi Everyone, > > I'm having a problem with extracting certain strings > within a line. I tried several ways, but not very > inefficient. Can somebody help me with it? thanks a > lot. > > The line might be one of the following: > KEY1 3 4 T KEY2 > > KEY1 3 4 T KEY2 45

Re: substring problems

2003-03-18 Thread Wiggins d'Anconia
tao wang wrote: Hi Everyone, I'm having a problem with extracting certain strings within a line. I tried several ways, but not very inefficient. Can somebody help me with it? thanks a lot. The line might be one of the following: KEY1 3 4 T KEY2 KEY1 3 4 T KEY2 456 67 KEY3 K

Re: substring problems

2003-03-18 Thread John W. Krahn
Tao Wang wrote: > > Hi Everyone, Hello, > I'm having a problem with extracting certain strings > within a line. I tried several ways, but not very > inefficient. Can somebody help me with it? thanks a > lot. > > The line might be one of the following: > KEY1 3 4 T KEY2 > > KEY1 3

Re: substring problems

2003-03-19 Thread tao wang
thanks a lot. But there is one problem - this is my fault. The KEY1, KEY2 don't exactly look like this. There are six KEYS. Three are related to KEYS, but the rest of them are A_BEG A_END, B_OPTIONS, and I need to extract information between them. I used one variable $op=KEY1|KEY2|KEY3|A_BEG|A_

Re: substring problems

2003-03-19 Thread John W. Krahn
Tao Wang wrote: > > thanks a lot. But there is one problem - this is my > fault. The KEY1, KEY2 don't exactly look like this. > There are six KEYS. Three are related to KEYS, but the > rest of them are A_BEG A_END, B_OPTIONS, and I need to > extract information between them. I used one variable >

Re: substring problems

2003-03-19 Thread Wiggins d'Anconia
tao wang wrote: thanks a lot. But there is one problem - this is my fault. The KEY1, KEY2 don't exactly look like this. There are six KEYS. Three are related to KEYS, but the rest of them are A_BEG A_END, B_OPTIONS, and I need to extract information between them. I used one variable $op=KEY1|

Re: substring problems

2003-03-19 Thread tao wang
no special order. thanks. - tao --- Wiggins d'Anconia <[EMAIL PROTECTED]> wrote: > > > tao wang wrote: > > thanks a lot. But there is one problem - this is > my > > fault. The KEY1, KEY2 don't exactly look like > this. > > There are six KEYS. Three are related to KEYS, but > the > > rest of

Re: substring problems

2003-03-19 Thread Rob Dixon
Tao Wang wrote: > thanks a lot. But there is one problem - this is my > fault. The KEY1, KEY2 don't exactly look like this. > There are six KEYS. Three are related to KEYS, but the > rest of them are A_BEG A_END, B_OPTIONS, and I need to > extract information between them. I used one variable > $o

Re: substring problems

2003-03-19 Thread tao wang
thanks a lot. - tao --- "John W. Krahn" <[EMAIL PROTECTED]> wrote: > Tao Wang wrote: > > > > thanks a lot. But there is one problem - this is > my > > fault. The KEY1, KEY2 don't exactly look like > this. > > There are six KEYS. Three are related to KEYS, but > the > > rest of them are A_BEG A

doubt in substring

2011-01-12 Thread Sunita Rani Pradhan
Hi All I have a string as; $str = "the cat sat on the mat" . How the following command works substr($str , 4, -4) on the string ? What should be the output? Thanks Sunita

Re: about substring

2005-05-09 Thread Wiggins d'Anconia
Aditi Gupta wrote: > Hi everybody, > > Can we use substr function for a string like: > $file = atom 12 N VAL A 1 12.435 13.66 34.6 32.1 32 a N > can the decimal numbers be extracted using > $x= substr($file, offset, length) > (the exact field lenghts of each field are known). > > Thanks

Re: about substring

2005-05-09 Thread Edward WIJAYA
On Mon, 09 May 2005 21:34:08 +0800, Aditi Gupta <[EMAIL PROTECTED]> wrote: Can we use substr function for a string like: $file = atom 12 N VAL A 1 12.435 13.66 34.6 32.1 32 a N can the decimal numbers be extracted using $x= substr($file, offset, length) (the exact field lenghts of each f

Re: about substring

2005-05-09 Thread Edward WIJAYA
After second thought This line: my @y = grep { $_ if ($_ =~ /\d+/)} @list; could be simplified with this: my @y = grep { /\d+/ } split(/\s+/,$file); Since grep { $_ if /\d+/ } wouldn't match on 0, but grep /\d+/ would. I'm still wondering how can I do that with "unpack" :-( -- Regards, Edward WIJAY

Re: about substring

2005-05-10 Thread FreeFall
Or you can try: __BEGIN__ #!/usr/bin/perl use warnings; use strict; my @decimals; $_ = 'atom 12 N VAL A 1 12.435 13.66 34.6 32.1 32 a N'; push @decimals,$1 while (/(\d+\.?\d*)/g); print "@decimals\n"; __END__ On Mon, 9 May 2005 19:04:08 +0530 Aditi Gupta <[EMAIL PROTECTED]> wrote: > H

Re: about substring

2005-05-10 Thread John Doe
Am Dienstag, 10. Mai 2005 09.14 schrieb FreeFall: > use warnings; > use strict; > > my @decimals; > $_ =  'atom 12 N  VAL  A  1  12.435  13.66 34.6  32.1 32   a N'; > push @decimals,$1 while (/(\d+\.?\d*)/g); > > print "@decimals\n"; Or, shorter (no need to use while _and_ //g): use warnings; use

Re: about substring

2005-05-10 Thread FreeFall
On Tue, 10 May 2005 09:22:31 +0200 John Doe <[EMAIL PROTECTED]> wrote: > my @decimals= /(\d+\.?\d*)/g; cool! Thanks! -- Whatever you do will be insignificant,but the important is you do it! It doesn't matter who you are, it's what you do that takes you far! -- To unsubscribe, e-mail: [EMAI

Re: about substring

2005-05-10 Thread Ing. Branislav Gerzo
John Doe [JD], on Tuesday, May 10, 2005 at 09:22 (+0200) made these points: JD> Or, shorter (no need to use while _and_ //g): JD> use warnings; JD> use strict; JD> $_ = 'atom 12 N VAL A 1 12.435 13.66 34.6 32.1 32 a N'; JD> my @decimals= /(\d+\.?\d*)/g; JD> print "@decimals\n"; very nice

Re: Substring and Sort

2002-10-21 Thread david
Anthony Akens wrote: > I'm attempting to use the following code to read a file > in the format of: > > directory name:displayname > > I want to sort the list by the "displayname", looking > at the first letter for each display name in the file. > If it's unique, I want to print it. This should

Re: Substring and Sort

2002-10-21 Thread Larry Coffin
At 3:03 PM -0400 10/21/02, Akens, Anthony wrote: >I'm attempting to use the following code to read a file >in the format of: > >directory name:displayname > >I want to sort the list by the "displayname", looking >at the first letter for each display name in the file. >If it's unique, I want to prin

RE: Substring and Sort

2002-10-21 Thread Akens, Anthony
print $displayname; print "<\/a>\n"; } } - -Original Message- From: Larry Coffin [mailto:lc2002@;PointInfinity.com] Sent: Monday, October 21, 2002 2:53 PM To: Akens, Anthony; [EMAIL PROTECTED] Subject: Re: Substring and Sort At 3:03 PM -0400 10/21

Re: Substring and Sort

2002-10-21 Thread Michael Fowler
On Mon, Oct 21, 2002 at 04:32:27PM -0500, Akens, Anthony wrote: [snip] It looks like you forgot -w and use strict. > open (NAMES, $namefile) > or print "Could not open $namefile $!"; Do you really want to continue and read the file if the open fails? > while() > { > ($key, $value

Re: doubt in substring

2011-01-12 Thread ashwin ts
the output will be cat sat on the all the characters in the string $str except four characters from the left and right will be displayed... Regards Ashwin Thayyullathil Surendran On Thu, Jan 13, 2011 at 9:57 AM, Sunita Rani Pradhan < sunita.prad...@altair.com> wrote: > Hi All > > > >

Re: doubt in substring

2011-01-12 Thread C.DeRykus
On Jan 12, 8:27 pm, sunita.prad...@altair.com ("Sunita Rani Pradhan") wrote: > Hi All > >             I have a string as; $str =  "the cat sat on the mat" . > > How the following command works substr($str , 4, -4)  on the string ? > What should be the output? > See: perldoc -f substr Check the do

Re: doubt in substring

2011-01-13 Thread Shawn H Corey
On 11-01-12 11:27 PM, Sunita Rani Pradhan wrote: I have a string as; $str = "the cat sat on the mat" . How the following command works substr($str , 4, -4) on the string ? What should be the output? TITS (Try It To See) perl -le '$str = "the cat sat on the mat";print substr(

Re: doubt in substring

2011-01-14 Thread Emeka
Setting environment for using XAMPP for Windows. rmicro@RMICRO-PC C:\Program Files\xampp # perl -le '$str = "the cat sat on the mat";print substr( $str, 4, -4 )' Can't find string terminator "'" anywhere before EOF at -e line 1. rmicro@RMICRO-PC C:\Program Files\xampp # It failed to work for me

Re: doubt in substring

2011-01-15 Thread John Delacour
On 15 January 2011 07:52, Emeka wrote: > # perl -le '$str = "the cat sat on the mat";print substr( $str, 4, -4 )' > Can't find string terminator "'" anywhere before EOF at -e line 1. > > rmicro@RMICRO-PC C:\Program Files\xampp > # > > It failed to work for me. Why? Because you can't use single

Re: doubt in substring

2011-01-15 Thread Emeka
*If I were beginning with Perl, I certainly would not practise in the console but get an editor, such as SciTE* Yes, I am. On Sat, Jan 15, 2011 at 3:04 PM, John Delacour wrote: > On 15 January 2011 07:52, Emeka wrote: > > > # perl -le '$str = "the cat sat on the mat";print substr( $str, 4, -4

Re: doubt in substring

2011-01-15 Thread Dr.Ruud
On 2011-01-15 08:52, Emeka wrote: rmicro@RMICRO-PC C:\Program Files\xampp # perl -le '$str = "the cat sat on the mat";print substr( $str, 4, -4 )' Can't find string terminator "'" anywhere before EOF at -e line 1. On Windows it should probably look like: # perl -wle "$s=q{abc def ghi jkl};pr

Re: doubt in substring

2011-01-15 Thread Kenneth Wolcott
On Sat, Jan 15, 2011 at 03:20, Dr.Ruud wrote: > On 2011-01-15 08:52, Emeka wrote: > >> rmicro@RMICRO-PC C:\Program Files\xampp >> # perl -le '$str =  "the cat sat on the mat";print substr( $str, 4, -4 )' >> Can't find string terminator "'" anywhere before EOF at -e line 1. > > On Windows it should

Measuring Substring with Hash

2005-04-08 Thread Edward Wijaya
Hi, I have following code that measure the substring. It basically the number of positions of substrings that occur (dotted count) CASE A: ...... .. GATTACGAGTGGCGCTCGTGTAACGGCA#Score 21 GATTACGGCGCTCG AACGGCA CASE B: .... #Score 4

grep and substring then uc

2009-01-09 Thread Erik Witkop
Here is what I am trying to do, I want to grep on a semicolon, and then upper case the next character. So if my input data is in the format of Witkop; erik I want to find the semicolon and then uppercase the 'e' in erik. Any help? -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org Fo

RE: Measuring Substring with Hash

2005-04-08 Thread Wagner, David --- Senior Programmer Analyst --- WGO
Edward Wijaya wrote: > Hi, > > I have following code that measure the substring. > It basically the number of positions of substrings > that occur (dotted count) > > CASE A: > ...... .. > GATTACGAGTGGCGCTCGTGTAACGGCA#Score 21 > GATTACGGC

Re: Measuring Substring with Hash

2005-04-08 Thread John W. Krahn
Edward Wijaya wrote: Hi, Hello, I have following code that measure the substring. It basically the number of positions of substrings that occur (dotted count) CASE A: ...... .. GATTACGAGTGGCGCTCGTGTAACGGCA#Score 21 GATTACGGCGCTCG AACGGCA CASE B

Re: Measuring Substring with Hash

2005-04-08 Thread John W. Krahn
John W. Krahn wrote: It looks like this will do what you want: sub score { my ( $str, $array ) = @_; my $total_score = 0; for my $frag ( @$array ) { my $len = length $frag; my $idx = index $str, $frag; if ( $idx >= 0 and substr $str, $idx, $len, '' ) { $total_score += $len;

RE: Measuring Substring with Hash

2005-04-08 Thread Wagner, David --- Senior Programmer Analyst --- WGO
John W. Krahn wrote: > John W. Krahn wrote: >> >> It looks like this will do what you want: John, Since you are not using the offset, and you have the same value GG twice and index starts over from the first, you are counting the same GG twice. If you remove the last GG

Re: Measuring Substring with Hash

2005-04-08 Thread John W. Krahn
Wagner, David --- Senior Programmer Analyst --- WGO wrote: John W. Krahn wrote: John W. Krahn wrote: It looks like this will do what you want: John, Since you are not using the offset, and you have the same value GG twice and index starts over from the first, you are counting the same GG twice.

RE: Measuring Substring with Hash

2005-04-08 Thread Wagner, David --- Senior Programmer Analyst --- WGO
John W. Krahn wrote: > Wagner, David --- Senior Programmer Analyst --- WGO wrote: >> John W. Krahn wrote: >> >>> John W. Krahn wrote: >>> It looks like this will do what you want: >> >> John, >> Since you are not using the offset, and you have the same value >> GG twice and index starts

Re: Measuring Substring with Hash

2005-04-08 Thread John W. Krahn
modify it which ensures that the same substring is not found twice. Another way to do it: sub score { my ( $str, $array ) = @_; my $total_score = 0; for my $frag ( @$array ) { $total_score += length $frag if $str =~ s/\Q$frag//; } return $total_score; } John -- use Perl; program

Re: Measuring Substring with Hash

2005-04-08 Thread Edward Wijaya
Hi John and David, Thanks so much for your reply. I forgot to mentioned another variances of scoring apart from this two ...... .. GATTACGAGTGGCGCTCGTGTAACGGCA#Score 21 GATTACGGCGCTCG AACGGCA CASE B: .... #Score 4 GATTACGAGTGGCGCTCGTGTAACGGCA

Re: Measuring Substring with Hash

2005-04-08 Thread John W. Krahn
Edward Wijaya wrote: Hi John and David, Hello, Don't mean to nitpick. Just wondering if it's possible to modify Krahn's snippet to accomodate the overlapping cases? No, it won't work if they overlap. John -- use Perl; program fulfillment -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional c

Re: Measuring Substring with Hash

2005-04-09 Thread John W. Krahn
Edward Wijaya wrote: Hi John and David, Hello, I forgot to mentioned another variances of scoring apart from this two They are cases where they overlap: CASE C: . ... #score 16 GATTACGAGTGGCGCTCGTGTAACGGCA GATTACG TTACGAG CGTGTAA CASE D: GCTCGTG

Using regexp to get a substring

2002-01-06 Thread David
Hello All, I am beginner and need some helps. Thanks a lot! The question is, if I have a string, for example "C:\PerlScripts\TestSamples\StringTest.pl", how do I use regexp to parse this string and get substring after the last backslash ("StringTest.pl"). Thanks in advanc

Re: grep and substring then uc

2009-01-09 Thread Mr. Shawn H. Corey
On Thu, 2009-01-08 at 18:23 -0800, Erik Witkop wrote: > Here is what I am trying to do, > > I want to grep on a semicolon, and then upper case the next character. > > So if my input data is in the format of > > Witkop; erik > > I want to find the semicolon and then uppercase the 'e' in erik. >

substring of a string delimited by "/"

2007-05-11 Thread Nishi
Hi: I have a string of the format - abc/def/ghi or abc\def\ghi I want to strip of abc and return just def/ghi or def\ghi How do I do that? Thanks!

Re: Using regexp to get a substring

2002-01-06 Thread Jos I. Boumans
x27;ll see it yields the same. a note to make: File::Spec->splitpath will work on any platform.. your regex will have to be modified to work on windows/unix/macos hth, jos - Original Message - From: "David" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Sunday, Jan

Re: Using regexp to get a substring

2002-01-06 Thread Shawn
ngTest.pl", how do I use regexp to parse > this string and get substring after the last backslash ("StringTest.pl"). Hey David, This should work for you: use strict; my $String='C:\PerlScripts\TestSamples\StringTest.pl'; (my $substring =$string) =~s/.*\\(.*)/$1/; Shawn

Re: Using regexp to get a substring

2002-01-06 Thread John W. Krahn
ieve me. $ perl -le'$string = "C:\PerlScripts\TestSamples\StringTest.pl"; print $string' C:PerlScriptsTestSamplesStringTest.pl > how do I use regexp to parse > this string and get substring after the last backslash ("StringTest.pl"). use File::Basename;

Re: substring of a string delimited by "/"

2007-05-11 Thread Rob Dixon
Nishi wrote: I have a string of the format - abc/def/ghi or abc\def\ghi I want to strip of abc and return just def/ghi or def\ghi How do I do that? use strict; use warnings; foreach (qw( abc/def/ghi abc\def\ghi )) { (my $trim = $_) =~ s|.*?[/\\]||; print "$_ -> $trim\n"; } **OUTPUT**

RegEx speed (was: Using regexp to get a substring)

2002-01-06 Thread Gary Hawkins
[mailto:[EMAIL PROTECTED]] > Sent: Sunday, January 06, 2002 1:03 PM > To: [EMAIL PROTECTED]; David > Subject: Re: Using regexp to get a substring > > > "David" <[EMAIL PROTECTED]> wrote in message > [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... > > H

Sorting an array by a substring of its members

2008-12-15 Thread Christopher Yee Mon
I have an array of strings whose members consist of a number followed by a comma followed by a text string e.g. 1,fresh 2,testurl I want to sort by descending numerical order according to the number part so I made this sort subroutine sub by_counter_field { my($a, $b) = @_; $a =~ s/^(.*?),

Extract substring from offset to space or full stop

2010-04-18 Thread Mimi Cafe
ack cat climbed the green tree"; $substring = substr( $s, 1, 15); # this will return "The black cat c". How can I have this return the whole word climbed rather than the c (i.e. I need to get "The black cat climbed")? I need to get the remaining characters from the l

Extract substring from offset to space or full stop

2010-04-18 Thread Mimi Cafe
offset I used, so I should be fine I think. Mimi -Original Message- From: John W. Krahn [mailto:jwkr...@shaw.ca] Sent: 18 April 2010 17:03 To: Perl Beginners Subject: Re: Extract substring from offset to space or full stop Mimi Cafe wrote: > I used MySQL substr function to extra 10

substring first 100 words from a string in perl

2011-07-28 Thread Khabza Mkhize
I want to substring words, I might be using wrong terminology. But I tried the following example the only problem I have it cut word any where it likes. eg "breathtaking" on my string is only bre. $string = "This is an awe-inspiring tour to the towering headland know

Re: RegEx speed (was: Using regexp to get a substring)

2002-01-07 Thread Jos I. Boumans
s" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]>; "David" <[EMAIL PROTECTED]> Sent: Sunday, January 06, 2002 11:48 PM Subject: RegEx speed (was: Using regexp to get a substring) > That'll work, but on a finer point, if you need to be thinking about > optimi

Re: Sorting an array by a substring of its members

2008-12-15 Thread Brian Tillman
I'm probably missing something, but what's wrong with?: sort {$b <=> $a} @array; On Dec 15, 2008, at 6:33 PM, Christopher Yee Mon > wrote: I have an array of strings whose members consist of a number followed by a comma followed by a text string e.g. 1,fresh 2,testurl I want to sort by

Re: Sorting an array by a substring of its members

2008-12-15 Thread John W. Krahn
Christopher Yee Mon wrote: I have an array of strings whose members consist of a number followed by a comma followed by a text string e.g. 1,fresh 2,testurl I want to sort by descending numerical order according to the number part so I made this sort subroutine sub by_counter_field { my($a

Re: Sorting an array by a substring of its members

2008-12-15 Thread Christopher Yee Mon
well if the contents of the array are '1,fresh' and '2,testurl' I think that'll try to do a numerical sort on the pair of strings which wouldn't do anything. I have tried { $b <=> $a } and it didn't work. I want the sort to take the two strings and sort the strings but only sort by the numerical p

Re: Sorting an array by a substring of its members

2008-12-15 Thread John W. Krahn
Brian Tillman wrote: I'm probably missing something, but what's wrong with?: sort {$b <=> $a} @array; Nothing, unless you have, as you really should, warnings enabled: $ perl -le' use warnings; my @array = ( "1,fresh", "2,testurl" ); @array = sort { $b <=> $a } @array; print for @array; ' Arg

Re: Sorting an array by a substring of its members

2008-12-15 Thread Mr. Shawn H. Corey
On Mon, 2008-12-15 at 20:33 -0500, Christopher Yee Mon wrote: > I have an array of strings whose members consist of a number followed by > a comma followed by a text string > > e.g. > 1,fresh > 2,testurl > > I want to sort by descending numerical order according to the number > part so I made t

Re: Sorting an array by a substring of its members

2008-12-15 Thread Christopher Yee Mon
hmm. i just tried it and it worked. I guess it's one of those situations. thanks Christopher John W. Krahn wrote: > Christopher Yee Mon wrote: >> I have an array of strings whose members consist of a number followed >> by a comma followed by a text string >> >> e.g. >> 1,fresh >> 2,testurl >> >>

Re: Sorting an array by a substring of its members

2008-12-15 Thread Rob Dixon
Christopher Yee Mon wrote: > I have an array of strings whose members consist of a number followed by > a comma followed by a text string > > e.g. > 1,fresh > 2,testurl > > I want to sort by descending numerical order according to the number > part so I made this sort subroutine > > sub by_cou

Re: Extract substring from offset to space or full stop

2010-04-18 Thread Akhthar Parvez K
me achieve what I need to. > > > > Let's say I have: > > > > $s = "The black cat climbed the green tree"; > > $substring = substr( $s, 1, 15); # this will return "The black cat c". > > > > > > > > > -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/

Re: Extract substring from offset to space or full stop

2010-04-18 Thread Shawn H Corey
Mimi Cafe wrote: $s = "The black cat climbed the green tree"; $substring = substr( $s, 1, 15); # this will return "The black cat c". How can I have this return the whole word climbed rather than the c (i.e. I need to get "The black cat climbed")? I need to get

Re: Extract substring from offset to space or full stop

2010-04-18 Thread Akhthar Parvez K
Hi Shawn, > $str =~ m{ \A ( .{15} .*? ) \s }msx; I don't think this would work if the value given in the match string (15 as per above eg.) is greater than the character count of the particular string. Right? Regards, Akhthar Parvez K http://Tips.SysAdminGUIDE.COM UNIX is basically a simple ope

RE: Extract substring from offset to space or full stop

2010-04-18 Thread Mimi Cafe
lto:akht...@sysadminguide.com] Sent: 18 April 2010 15:45 To: beginners@perl.org Subject: Re: Extract substring from offset to space or full stop Hi Shawn, > $str =~ m{ \A ( .{15} .*? ) \s }msx; I don't think this would work if the value given in the match string (15 as per above eg.) is gr

Re: Extract substring from offset to space or full stop

2010-04-18 Thread Akhthar Parvez K
Hi, > It works fine and I like it. My regex is not that good, but I can see what > is doing. I modified it a bit (to capture up till a full stop sign). Kewl. Good to hear that! Regards, Akhthar Parvez K http://Tips.SysAdminGUIDE.COM UNIX is basically a simple operating system, but you have to be

Re: Extract substring from offset to space or full stop

2010-04-18 Thread Shawn H Corey
Akhthar Parvez K wrote: Hi Shawn, $str =~ m{ \A ( .{15} .*? ) \s }msx; I don't think this would work if the value given in the match string (15 as per above eg.) is greater than the character count of the particular string. Right? No, it will fail if $str is less than 15 characters. Try:

Re: Extract substring from offset to space or full stop

2010-04-18 Thread John W. Krahn
uot;The black cat climbed the green tree"; $substring = substr( $s, 1, 15); # this will return "The black cat c". No it will not. It will return "he black cat cl" because in perl offsets start at 0 and not 1: $ perl -le' my $s = "The black cat climbed

Re: Extract substring from offset to space or full stop

2010-04-18 Thread John W. Krahn
the next white space or end of a phrase. Any other way to overcome this limitation? How can I use regex here? $ perl -le' my $s = "The black cat climbed the green tree"; my $length = length $s; my ( $substring ) = $s =~ / \A ( .{15,$length}? \b ) /x; print $substring; ' The bl

Re: Extract substring from offset to space or full stop

2010-04-18 Thread Akhthar Parvez K
>$str =~ m{ \A ( .{0,15} .*? ) \s }msx; Yeah, this would do. I talked about the scenario where you didn't put "{0,15}", but just "{15}". In that case, it wouldn't work if the value given in the match string (15 as per above eg.) is greater than the character count of the particular string

Re: substring first 100 words from a string in perl

2011-07-28 Thread Rob Coops
On Thu, Jul 28, 2011 at 3:23 PM, Khabza Mkhize wrote: > I want to substring words, I might be using wrong terminology. But I tried > the following example the only problem I have it cut word any where it > likes. eg "breathtaking" on my string is only bre. > > >

Re: substring first 100 words from a string in perl

2011-07-28 Thread timothy adigun
Hi Rob Coops, " I want to substring words, I might be using wrong terminology. But I tried the following example the only problem I have it cut word any where it likes. eg "breathtaking" on my string is only bre." -- If you count your $string alphabeth by alphabeth fro

Re: substring first 100 words from a string in perl

2011-07-28 Thread timothy adigun
Hello Khabza, " I want to substring words, I might be using wrong terminology. But I tried the following example the only problem I have it cut word any where it likes. eg "breathtaking" on my string is only bre." -- If you count your $string alphabeth by alphabeth fro

Re: substring first 100 words from a string in perl

2011-07-28 Thread Rob Dixon
On 28/07/2011 14:23, Khabza Mkhize wrote: I want to substring words, I might be using wrong terminology. But I tried the following example the only problem I have it cut word any where it likes. eg "breathtaking" on my string is only bre. $string = "This is an awe-in

Re: substring first 100 words from a string in perl

2011-07-28 Thread timothy adigun
k Khabza wants words but counted in alphabeths! lol! On Thu, Jul 28, 2011 at 8:05 PM, Rob Dixon wrote: > On 28/07/2011 14:23, Khabza Mkhize wrote: > >> >> I want to substring words, I might be using wrong terminology. But I tried >> the following example the only problem

RE: substring first 100 words from a string in perl

2011-07-29 Thread Bob McConnell
phabeths! > lol! > > On Thu, Jul 28, 2011 at 8:05 PM, Rob Dixon wrote: > >> On 28/07/2011 14:23, Khabza Mkhize wrote: >> >>> >>> I want to substring words, I might be using wrong terminology. But I tried >>> the following example th

Re: substring first 100 words from a string in perl

2011-08-01 Thread Dr.Ruud
On 2011-07-28 15:23, Khabza Mkhize wrote: I want to substring words, I might be using wrong terminology. But I tried the following example the only problem I have it cut word any where it likes. eg "breathtaking" on my string is only bre. $string = "This is an awe-in

Re: substring first 100 words from a string in perl

2011-08-01 Thread Rob Dixon
On 01/08/2011 19:14, Dr.Ruud wrote: my ($rtioverview) = $string =~ /(.{0,100})\b/; That would have to be my ($rtioverview) = $string =~ /(.{0,99})\S\b/; to avoid terminating at the start of a non-space sequence. Rob -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional

A subroutine to find every occurrence of a substring in a string?

2010-06-09 Thread Peng Yu
I can't find an existing perl subroutine (in the library) to find every occurrence of a substring in a string. The following webpage "Example 3b. How to find every occurrence" uses a loop to do so. But I'd prefer a subroutine. Could you let me know if such a subroutine is avail

Identifying words containing a specific substring in a sentence (was: a simple question)

2004-06-16 Thread David Dorward
Tip: This is a beginners list, therefore many questions will be simple. Aim for more descriptive subject lines and life will be easier for users of the list archives. On 16 Jun 2004, at 17:10, Kevin Zhang wrote: For the following string: " axyzb cxyzd " What is the command to extrac

AW: A subroutine to find every occurrence of a substring in a string?

2010-06-09 Thread Thomas Bätzler
Peng Yu asked: > I can't find an existing perl subroutine (in the library) to find > every occurrence of a substring in a string. The following webpage > "Example 3b. How to find every occurrence" uses a loop to do so. But > I'd prefer a subroutine. Could you let

Re: A subroutine to find every occurrence of a substring in a string?

2010-06-10 Thread Chas. Owens
On Wed, Jun 9, 2010 at 22:17, Peng Yu wrote: > I can't find an existing perl subroutine (in the library) to find > every occurrence of a substring in a string. The following webpage > "Example 3b. How to find every occurrence" uses a loop to do so. But > I'd prefe

  1   2   >