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
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
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
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
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
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
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;
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
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
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
--- 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
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
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
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
- 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]
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,
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
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 @
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
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
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
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_
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
>
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|
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
>
>
>
>
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
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(
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
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
*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
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
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
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
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
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
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
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;
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
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.
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
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
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
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
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
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
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.
>
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!
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
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
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;
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**
[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
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/^(.*?),
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
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
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
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
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
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
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
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
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
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
>>
>>
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
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/
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
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
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
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
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:
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
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
>$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
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.
>
>
>
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
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
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
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
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
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
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
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
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
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
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 - 100 of 116 matches
Mail list logo