Hello,
Given the string 'abcdefghijklmnopq', I wish to add a line break
every 5 characters:
abcde
fghij
klmno
pq
Method 1 below works, but my split() in method 2 captures 'something
unexpected' at each match. Could someone please tell me what is split
capturing that I am not seeing?
Th
Hien Le schreef:
> my @bar2 = split( /([a-z]{5})/, $foo );# Captures white-spaces ?!?
Because of the capturing (), split also returns the separators.
See perldoc -f split.
Suggestion:
my @bar2 = split( /./, $foo );
--
Affijn, Ruud
"Gewoon is een tijger."
--
To unsubscribe, e-
Hien Le wrote:
> Hello,
Hello,
> Given the string 'abcdefghijklmnopq', I wish to add a line break every
> 5 characters:
>
> abcde
> fghij
> klmno
> pq
$ perl -e'
my $foo = q[abcdefghijklmnopq];
print "$foo\n";
$foo =~ s/(.{0,5})/$1\n/g;
print $foo;
'
abcdefghijklmnopq
abcde
fghij
klmno
pq
>
On 08/29/2006 06:52 AM, Hien Le wrote:
[...]
# Method 2
print( "\nMethod 2\n" );
my @bar2 = split( /([a-z]{5})/, $foo );# Captures white-spaces ?!?
[...]
The comments made by Dr. Ruud and John W. Krahn are correct.
Split is returning the empty strings between delimiter
segments in the ori
"Mumia W." schreef:
> Hien Le:
>> [...]
>> # Method 2
>> print( "\nMethod 2\n" );
>> my @bar2 = split( /([a-z]{5})/, $foo );# Captures white-spaces
>> ?!? [...]
>
> The comments made by Dr. Ruud and John W. Krahn are correct.
> Split is returning the empty strings between delimiter
> segments
On 08/29/2006 05:02 PM, Dr.Ruud wrote:
"Mumia W." schreef:
Hien Le:
[...]
# Method 2
print( "\nMethod 2\n" );
my @bar2 = split( /([a-z]{5})/, $foo );# Captures white-spaces
?!? [...]
The comments made by Dr. Ruud and John W. Krahn are correct.
Split is returning the empty strings between
"Mumia W." schreef:
> Dr.Ruud:
>> Mumia W.:
>>> my @bar2 = grep length, split (/([a-z]{5})/, $foo);
>>>
>>> Any substrings with a length of zero will be removed by "grep
>>> length."
>>
>> Huh? Why not just remove the capturing "()"?
>
> Without the capturing parentheses, split will remove every
>
On Aug 30, 2006, at 3:42 AM, Dr.Ruud wrote:
Aaargh, I was suddenly mixing up split /()/ and /()/g. I really
shouldn't post anymore without testing.
Thank you all for the clarifications regarding split(). I should pay
more attention when I read the documentation (or get more sleep).
-Hien.
I have this script that reads in lines from a configuration file, processes
them, and then stores them in a hash. Everything is working (mostly) but I
really don't like the snippet below and wanted to see if anyone could
suggest a better solution. I would call better a syntactically shorter,
les
On 05 Jun 2001 17:49:53 -0700, Peter Cornelius wrote:
>
> local $_ = 'name = "quoted string with space"';
>
If your pattern always looks like this then try:
#!/usr/bin/perl
use strict;#make me behave
my $name; #holds the key part of config
my $value; #the value of par
Hi,
I'm not sure that I got it right, but let's try:
considering you want to parse several substrings from the line, each of them
can be either bareword (== sequence of non-whitespace characters) or a quoted
strings:
my $line = 'whatever "this" \'line is\'';
$line =~ s/\s*$//;
my @parts;
wh
> "Ondrej" == Ondrej Par <[EMAIL PROTECTED]> writes:
Ondrej> my $line = 'whatever "this" \'line is\'';
Ondrej> $line =~ s/\s*$//;
Ondrej> my @parts;
Ondrej> while ($line ne '') {
Ondrej> if ($line =~ m/^\s*(['"])((?:(?:\\.)|[^\\])*?)\1(.*)/) {
Ondrej> push @parts, $2
On Jun 6, Randal L. Schwartz said:
>my @elements;
>push @elements, $1 while
> /\G\s*"(.*?)"/gc or
> /\G\s*'(.*?)'/gc or
> /\G\s*(\S+)/gc;
Randal, would you mind if I used this as an example of \G and /gc in my
regex book? Due credit would be given, of course.
--
Jeff "japhy" Pinyan [E
> "Jeff" == Jeff 'japhy' Pinyan <[EMAIL PROTECTED]> writes:
Jeff> On Jun 6, Randal L. Schwartz said:
>> my @elements;
>> push @elements, $1 while
>> /\G\s*"(.*?)"/gc or
>> /\G\s*'(.*?)'/gc or
>> /\G\s*(\S+)/gc;
Jeff> Randal, would you mind if I used this as an example of \G and /gc in my
Jef
On Wednesday 06 June 2001 18:19, Randal L. Schwartz wrote:
> That's a good approach, but maybe this one is more straightforward:
>
> $_ = q{whatever "this" 'line is'};
>
> my @elements;
> push @elements, $1 while
> /\G\s*"(.*?)"/gc or
> /\G\s*'(.*?)'/gc or
> /\G\s*(\S+)/gc;
>
> print map "<<
- Original Message -
From: Peter Cornelius <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Wednesday, June 06, 2001 2:49 AM
Subject: splitting strings with quoted white space
> I have this script that reads in lines from a configuration file,
processes
> them, and t
On Jun 6, Randal L. Schwartz said:
>> "Jeff" == Jeff 'japhy' Pinyan <[EMAIL PROTECTED]> writes:
>
>Jeff> On Jun 6, Randal L. Schwartz said:
>>> my @elements;
>>> push @elements, $1 while
>>> /\G\s*"(.*?)"/gc or
>>> /\G\s*'(.*?)'/gc or
>>> /\G\s*(\S+)/gc;
>
>Jeff> Randal, would you mind if I u
> "Ondrej" == Ondrej Par <[EMAIL PROTECTED]> writes:
Ondrej> On Wednesday 06 June 2001 18:19, Randal L. Schwartz wrote:
>> That's a good approach, but maybe this one is more straightforward:
>>
>> $_ = q{whatever "this" 'line is'};
>>
>> my @elements;
>> push @elements, $1 while
>> /\G\s*"(
> "Randal" == Randal L Schwartz <[EMAIL PROTECTED]> writes:
Randal> my @elements;
Randal> push @elements, $1 while
Randal> /\G\s*"((?:[^\\"]|\\"|)*)"/gc or
Randal> /\G\s*'((?:[^\\']|\\'|)*)'/gc or
Randal> /\G\s*([^\s'"]\S*)/gc;
Randal> Leaving undefined something like \X as mal
an advantage to doing this?
-Original Message-
From: Randal L. Schwartz [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, June 06, 2001 10:43 AM
To: Ondrej Par
Cc: Peter Cornelius; [EMAIL PROTECTED]
Subject: Re: splitting strings with quoted white space
>>>>> "Ondrej" == Ondr
On Jun 6, Accountant Bob said:
>How about this: (the same but "unrolled")
>
>my @elements;
>push @elements, $1 while
> /\G\s*"([^\\"]*(?:\\["\\][^\\"]*)*)"/gc or
> /\G\s*'([^\\']*(?:\\['\\][^\\']*)*)'/gc or
> /\G\s*([^\s'"]\S*)/gc;
>
>is there actually an advantage to doing this?
Yes, as i
On Wednesday 06 June 2001 22:59, Jeff 'japhy' Pinyan wrote:
> On Jun 6, Accountant Bob said:
> >How about this: (the same but "unrolled")
> >
> >my @elements;
> >push @elements, $1 while
> > /\G\s*"([^\\"]*(?:\\["\\][^\\"]*)*)"/gc or
I think that
/\G\s*"((?:(?:\\.)|[^\\])*?)"/gc
is sh
On Jun 7, Ondrej Par said:
>On Wednesday 06 June 2001 22:59, Jeff 'japhy' Pinyan wrote:
>> On Jun 6, Accountant Bob said:
>> >How about this: (the same but "unrolled")
>> >
>> >my @elements;
>> >push @elements, $1 while
>> > /\G\s*"([^\\"]*(?:\\["\\][^\\"]*)*)"/gc or
>
>I think that
> /\
27; Pinyan [mailto:[EMAIL PROTECTED]]
Sent: Thursday, June 07, 2001 8:38 AM
To: Ondrej Par
Cc: Accountant Bob; "Randal L. Schwartz" <[EMAIL PROTECTED]> Peter
Cornelius; [EMAIL PROTECTED]
Subject: Re: splitting strings with quoted white space
On Jun 7, Ondrej Par said:
>On Wednesda
On Jun 7, Accountant Bob said:
>can any one explain to me why this doesn't seem to work:
> push @elements, $2 while
>/\G\s*(["'])([^\\\1]*(?:\\.[^\\\1]*)*)\1/gc or
>/\G(\s*)(\S+)/gc; # k i know that's kinda kloogy, but I'm
>experimenting.
Let's find out why:
friday:~ $ explain
\G\s*(
25 matches
Mail list logo