Characters

Characters

am 01.08.2011 14:14:12 von Emeka

--bcaec51a74a8a9263f04a9709150
Content-Type: text/plain; charset=ISO-8859-1

Hello All,

I would like to know how to access character from string lateral.

Say I have
$foo = "From Big Brother Africa";
I would want to print each of the characters of $foo on its own.

In some languages string type is just array/list of characters. What is it
in Perl?


Emeka
--
*Satajanus Nig. Ltd


*

--bcaec51a74a8a9263f04a9709150--

Re: Characters

am 01.08.2011 14:17:37 von Shawn H Corey

On 11-08-01 08:14 AM, Emeka wrote:
> Hello All,
>
> I would like to know how to access character from string lateral.
>
> Say I have
> $foo = "From Big Brother Africa";
> I would want to print each of the characters of $foo on its own.
>
> In some languages string type is just array/list of characters. What is it
> in Perl?

It's a scalar. But you can easily convert it to a list and store it in
an array.

my @characters = split //, $foo;


--
Just my 0.00000002 million dollars worth,
Shawn

Confusion is the first step of understanding.

Programming is as much about organization and communication
as it is about coding.

The secret to great software: Fail early & often.

Eliminate software piracy: use only FLOSS.

"Make something worthwhile." -- Dear Hunter

--
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
http://learn.perl.org/

Re: Characters

am 01.08.2011 14:49:22 von AKINLEYE

--001636c9337176dba604a9710f89
Content-Type: text/plain; charset=ISO-8859-1

my @characters = split /[\s]/, $foo;
foreach my $letter(@characters )
{
print $letter ;

}

or

my @characters = split /[\s]/, $foo;
print join("\n" , @characters);


Untested code though.


OP----------------

Hello All,

I would like to know how to access character from string lateral.

Say I have
$foo = "From Big Brother Africa";
I would want to print each of the characters of $foo on its own.

In some languages string type is just array/list of characters. What is it
in Perl?


Emeka

On Mon, Aug 1, 2011 at 1:17 PM, Shawn H Corey wrote:

> On 11-08-01 08:14 AM, Emeka wrote:
>
>> Hello All,
>>
>> I would like to know how to access character from string lateral.
>>
>> Say I have
>> $foo = "From Big Brother Africa";
>> I would want to print each of the characters of $foo on its own.
>>
>> In some languages string type is just array/list of characters. What is it
>> in Perl?
>>
>
> It's a scalar. But you can easily convert it to a list and store it in an
> array.
>
> my @characters = split //, $foo;
>
>
> --
> Just my 0.00000002 million dollars worth,
> Shawn
>
> Confusion is the first step of understanding.
>
> Programming is as much about organization and communication
> as it is about coding.
>
> The secret to great software: Fail early & often.
>
> Eliminate software piracy: use only FLOSS.
>
> "Make something worthwhile." -- Dear Hunter
>
> --
> To unsubscribe, e-mail: beginners-unsubscribe@perl.org
> For additional commands, e-mail: beginners-help@perl.org
> http://learn.perl.org/
>
>
>


--
Akinleye Adedamola

--001636c9337176dba604a9710f89--

Re: Characters

am 01.08.2011 15:45:25 von jwkrahn

Emeka wrote:
> Hello All,

Hello,

> I would like to know how to access character from string lateral.
>
> Say I have
> $foo = "From Big Brother Africa";
> I would want to print each of the characters of $foo on its own.
>
> In some languages string type is just array/list of characters. What is it
> in Perl?

A string.

In Perl there are a few ways to do what you want:

$ perl -le'my $foo = "From Big Brother Africa"; print for split //, $foo'
F
r
o
m

B
i
g

B
r
o
t
h
e
r

A
f
r
i
c
a
$ perl -le'my $foo = "From Big Brother Africa"; print for $foo =~ /./sg'
F
r
o
m

B
i
g

B
r
o
t
h
e
r

A
f
r
i
c
a
$ perl -le'my $foo = "From Big Brother Africa"; print for map substr(
$foo, $_, 1 ), 0 .. length( $foo ) - 1'
F
r
o
m

B
i
g

B
r
o
t
h
e
r

A
f
r
i
c
a
$ perl -le'my $foo = "From Big Brother Africa"; print for unpack "(a)*",
$foo'
F
r
o
m

B
i
g

B
r
o
t
h
e
r

A
f
r
i
c
a





John
--
Any intelligent fool can make things bigger and
more complex... It takes a touch of genius -
and a lot of courage to move in the opposite
direction. -- Albert Einstein

--
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
http://learn.perl.org/

Re: Characters

am 01.08.2011 15:52:17 von Shlomi Fish

On Mon, 1 Aug 2011 13:49:22 +0100
AKINLEYE wrote:

> my @characters =3D split /[\s]/, $foo;
> foreach my $letter(@characters )
> {
> print $letter ;
>=20
> }
>=20
> or
>=20
> my @characters =3D split /[\s]/, $foo;
> print join("\n" , @characters);
>=20

That won't work because split/[\s]/ will split the string on any whitespace
character into words that don't contain whitespace. As a result:

<<<
shlomif:~$ perl -e 'print map { "$_\n" } split/[\s]/, "Big Brother From Afr=
"'
Big
Brother
From
Afr
shlomif:~$=20
>>>

To convert a string to characters one can use split based on the empty rege=
x,
as Shawn showed:

<<<
shlomif:~$ perl -e 'print map { "$_\n" } split//, "Big Brother From Afr"'
B
i
g
=20
B
r
o
t
h
e
r
=20
F
r
o
m
=20
A
f
r
>>>

One can also access individual characters without splitting and populating =
an
array using http://perldoc.perl.org/functions/substr.html . Here's a demo:

<<<
#!/usr/bin/perl

use strict;
use warnings;

my $s =3D "Big Brother From Afr";

foreach my $pos (0 .. length($s)-1)
{
my $c =3D substr($s, $pos, 1);
print "Character No. $pos =3D '$c'.\n"
}
>>>

>=20
> Untested code though.
>=20

Untested indeed, and please avoid top posting.

Regards,

Shlomi Fish

--=20
------------------------------------------------------------ -----
Shlomi Fish http://www.shlomifish.org/
Original Riddles - http://www.shlomifish.org/puzzles/

Comedy is simply a funny way of being serious.
â€=94 http://en.wikiquote.org/wiki/Peter_Ustinov

Please reply to list if it's a mailing list post - http://shlom.in/reply .

--
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
http://learn.perl.org/

Re: Characters

am 01.08.2011 16:00:49 von Emeka

--000e0cd2547af7b8c404a9720e8c
Content-Type: text/plain; charset=ISO-8859-1

John,

Thanks and thanks :)

Emeka

On Mon, Aug 1, 2011 at 2:45 PM, John W. Krahn wrote:

> Emeka wrote:
>
>> Hello All,
>>
>
> Hello,
>
>
> I would like to know how to access character from string lateral.
>>
>> Say I have
>> $foo = "From Big Brother Africa";
>> I would want to print each of the characters of $foo on its own.
>>
>> In some languages string type is just array/list of characters. What is it
>> in Perl?
>>
>
> A string.
>
> In Perl there are a few ways to do what you want:
>
> $ perl -le'my $foo = "From Big Brother Africa"; print for split //, $foo'
> F
> r
> o
> m
>
> B
> i
> g
>
> B
> r
> o
> t
> h
> e
> r
>
> A
> f
> r
> i
> c
> a
> $ perl -le'my $foo = "From Big Brother Africa"; print for $foo =~ /./sg'
> F
> r
> o
> m
>
> B
> i
> g
>
> B
> r
> o
> t
> h
> e
> r
>
> A
> f
> r
> i
> c
> a
> $ perl -le'my $foo = "From Big Brother Africa"; print for map substr( $foo,
> $_, 1 ), 0 .. length( $foo ) - 1'
> F
> r
> o
> m
>
> B
> i
> g
>
> B
> r
> o
> t
> h
> e
> r
>
> A
> f
> r
> i
> c
> a
> $ perl -le'my $foo = "From Big Brother Africa"; print for unpack "(a)*",
> $foo'
> F
> r
> o
> m
>
> B
> i
> g
>
> B
> r
> o
> t
> h
> e
> r
>
> A
> f
> r
> i
> c
> a
>
>
>
>
>
> John
> --
> Any intelligent fool can make things bigger and
> more complex... It takes a touch of genius -
> and a lot of courage to move in the opposite
> direction. -- Albert Einstein
>
> --
> To unsubscribe, e-mail: beginners-unsubscribe@perl.org
> For additional commands, e-mail: beginners-help@perl.org
> http://learn.perl.org/
>
>
>


--
*Satajanus Nig. Ltd


*

--000e0cd2547af7b8c404a9720e8c--

Re: Characters

am 01.08.2011 17:39:15 von Emeka

--000e0cd2547a05e93904a9736fc5
Content-Type: text/plain; charset=windows-1252
Content-Transfer-Encoding: quoted-printable

Shlomi,

Yea, that makes sense now.

Emeka

On Mon, Aug 1, 2011 at 2:52 PM, Shlomi Fish wrote:

> On Mon, 1 Aug 2011 13:49:22 +0100
> AKINLEYE wrote:
>
> > my @characters =3D split /[\s]/, $foo;
> > foreach my $letter(@characters )
> > {
> > print $letter ;
> >
> > }
> >
> > or
> >
> > my @characters =3D split /[\s]/, $foo;
> > print join("\n" , @characters);
> >
>
> That won't work because split/[\s]/ will split the string on any whitespa=
ce
> character into words that don't contain whitespace. As a result:
>
> <<<
> shlomif:~$ perl -e 'print map { "$_\n" } split/[\s]/, "Big Brother From
> Afr"'
> Big
> Brother
> From
> Afr
> shlomif:~$
> >>>
>
> To convert a string to characters one can use split based on the empty
> regex,
> as Shawn showed:
>
> <<<
> shlomif:~$ perl -e 'print map { "$_\n" } split//, "Big Brother From Afr"'
> B
> i
> g
>
> B
> r
> o
> t
> h
> e
> r
>
> F
> r
> o
> m
>
> A
> f
> r
> >>>
>
> One can also access individual characters without splitting and populatin=
g
> an
> array using http://perldoc.perl.org/functions/substr.html . Here's a demo=
:
>
> <<<
> #!/usr/bin/perl
>
> use strict;
> use warnings;
>
> my $s =3D "Big Brother From Afr";
>
> foreach my $pos (0 .. length($s)-1)
> {
> my $c =3D substr($s, $pos, 1);
> print "Character No. $pos =3D '$c'.\n"
> }
> >>>
>
> >
> > Untested code though.
> >
>
> Untested indeed, and please avoid top posting.
>
> Regards,
>
> Shlomi Fish
>
> --
> ------------------------------------------------------------ -----
> Shlomi Fish http://www.shlomifish.org/
> Original Riddles - http://www.shlomifish.org/puzzles/
>
> Comedy is simply a funny way of being serious.
> =97 http://en.wikiquote.org/wiki/Peter_Ustinov
>
> Please reply to list if it's a mailing list post - http://shlom.in/reply =
..
>
> --
> To unsubscribe, e-mail: beginners-unsubscribe@perl.org
> For additional commands, e-mail: beginners-help@perl.org
> http://learn.perl.org/
>
>
>


--=20
*Satajanus Nig. Ltd


*

--000e0cd2547a05e93904a9736fc5--

Re: Characters

am 01.08.2011 19:21:04 von Rob Dixon

On 01/08/2011 13:14, Emeka wrote:
>
> I would like to know how to access character from string lateral.
>
> Say I have
> $foo = "From Big Brother Africa";
> I would want to print each of the characters of $foo on its own.
>
> In some languages string type is just array/list of characters. What is it
> in Perl?

Hi Emeka

Perl is rich with string-handling operators. Take a look at

perldoc perlfunc

and look at "Perl Functions by Category". Part of it reads

> Functions for SCALARs or strings
> "chomp", "chop", "chr", "crypt", "hex", "index", "lc", "lcfirst",
> "length", "oct", "ord", "pack", "q//", "qq//", "reverse", "rindex",
> "sprintf", "substr", "tr///", "uc", "ucfirst", "y///"
>
> Regular expressions and pattern matching
> "m//", "pos", "quotemeta", "s///", "split", "study", "qr//"

So what you would ordinarily do in C by indexing an array of characters
can have many better solutions in Perl.

As has been mentioned by others,

my @chars = split //, $string;

will give you an array of one-character strings that you may be able to
handle as if you were using a different language, but that is rarely the
way to go if you are writing a Perl program.

Perl regular expressions are very felxible and comprehensive, and you
will find that most string operations are best expressed that way rather
than using split, index, substr and so on.

If you describe your goal then we would be able to help you better.

Rob

--
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
http://learn.perl.org/

Re: Characters

am 01.08.2011 20:00:46 von rvtol+usenet

On 2011-08-01 15:52, Shlomi Fish wrote:

> To convert a string to characters one can use split based on the empty regex,

That should be "a pattern matching the empty string".

The "empty regex" works differently:

perl -wle '
my $text = "abcdefghi";
$text =~ /[aeiou]/;
$text =~ /x/;
my @result = $text =~ //g;
print "@result";
'
a e i

(admire how 'regex' and 'regular expression' are avoided in perldoc -f
split)

--
Ruud

--
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
http://learn.perl.org/

Re: Characters

am 01.08.2011 20:20:32 von Rob Dixon

On 01/08/2011 19:00, Dr.Ruud wrote:
> On 2011-08-01 15:52, Shlomi Fish wrote:
>
>> To convert a string to characters one can use split based on the empty
>> regex,
>
> That should be "a pattern matching the empty string".
>
> The "empty regex" works differently:
>
> perl -wle '
> my $text = "abcdefghi";
> $text =~ /[aeiou]/;
> $text =~ /x/;
> my @result = $text =~ //g;
> print "@result";
> '
> a e i
>
> (admire how 'regex' and 'regular expression' are avoided in perldoc -f split)

Please Shlomi, you have taught me nothing despite repeated reading of
your post. Please tell me what is wrong with the OP's

> To convert a string to characters one can use split based on the empty regex

Are you trying to say that any regular expression that can match zero
character will also suffice? How does your code demonstrate the point
you are making?

Rob







--
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
http://learn.perl.org/

Re: Characters

am 02.08.2011 00:29:53 von Jim Gibson

On 8/1/11 Mon Aug 1, 2011 11:20 AM, "Rob Dixon"
scribbled:

> On 01/08/2011 19:00, Dr.Ruud wrote:
>> On 2011-08-01 15:52, Shlomi Fish wrote:
>>
>>> To convert a string to characters one can use split based on the empty
>>> regex,
>>
>> That should be "a pattern matching the empty string".
>>
>> The "empty regex" works differently:
>>
>> perl -wle '
>> my $text = "abcdefghi";
>> $text =~ /[aeiou]/;
>> $text =~ /x/;
>> my @result = $text =~ //g;
>> print "@result";
>> '
>> a e i
>>
>> (admire how 'regex' and 'regular expression' are avoided in perldoc -f
>> split)
>
> Please Shlomi, you have taught me nothing despite repeated reading of
> your post. Please tell me what is wrong with the OP's
>
>> To convert a string to characters one can use split based on the empty regex
>
> Are you trying to say that any regular expression that can match zero
> character will also suffice? How does your code demonstrate the point
> you are making?

Rob:

I believe you are responding to Dr. Ruud's post, not Shlomi's, and the term
"empty regex" is Shlomi's, not the OP (Emeka).

Dr. Ruud is demonstrating the little-known but documented feature of Perl
that the explicit empty regex // repeats the last, successful regex within
its scope. Thus, in Dr. Ruud's sample program, the line

my @result = $text =~ //g;

is equivalent to the line

my @result = $text =~ /[aeiou]/g;

because that was the regex used in the last successful match.

Of course, in a beginner's list, it is better to explain such exceptional
cases, rather than just showing the statements. or people may miss the point
entirely. But not everyone has the time or inclination to do so,
unfortunately.



--
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
http://learn.perl.org/

Re: Characters

am 02.08.2011 04:39:09 von Brian Fraser

--00151748de9cf9b19e04a97ca6c6
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

On Mon, Aug 1, 2011 at 9:14 AM, Emeka wrote:

>
> In some languages string type is just array/list of characters. What is i=
t
> in Perl?
>
>
There's no string type in Perl, internals notwithstanding. There's scalars,
and a scalar can hold a string - If you care to dig deeper, that string is
stored a series of octets, which may or may not be encoded in UTF-8.

The problem with thinking of strings as arrays of characters is pretty
simple: What's a character? õ, "\x{F5}" (LATIN SMALL LETTER O WITH TIL=
DE) is
a character, but what about õ, "o\x{303}", (LATIN SMALL LETTER O, COMB=
INING
TILDE)? What should string[0] return there? Can you get everyone to agree o=
n
that? : ) (For example, I had the displeasure of working with a fairly
ancient version of Ruby where string[0] returned an octet, and there was no
simple way of changing this. It was absolute hell. Never versions appear to
be quite an improvement over that, though admittedly I haven't used those
much)

Also, this is a bit of a nitpick, but every solution shown so far is fairly
worthless with Unicode data:
Consider È­, "o\x{303}\x{304}", LATIN SMALL LETTER O, COMBINING TILDE,
COMBINING MACRON. Blindly doing /(.)/g on that will return a list with thos=
e
three characters, and be mostly worthless.
What you generally want is /(\X)/g, which will return the a single element
list, that element being a string with all three components of the actual
character (i.e. an extended grapheme cluster).

Tom Christiansen explains this and much more in his Unicode Essentials talk=
,
which you can read here: http://training.perl.com/OSCON2011/index.html and
is probably the newest tour de force for almost any Perl programmer.

--00151748de9cf9b19e04a97ca6c6--

Re: Characters

am 02.08.2011 06:45:57 von Emeka

--000e0cd152247da4ee04a97e6c3e
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

Brian,

Thanks for re-directing me back to my original question, and thank again fo=
r
your well researched comment. I intend to dig deeper into string...hopefull=
y
know a bit of the internals.

Emeka

On Tue, Aug 2, 2011 at 3:39 AM, Brian Fraser wrote:

> On Mon, Aug 1, 2011 at 9:14 AM, Emeka wrote:
>
>>
>> In some languages string type is just array/list of characters. What is =
it
>> in Perl?
>>
>>
> There's no string type in Perl, internals notwithstanding. There's scalar=
s,
> and a scalar can hold a string - If you care to dig deeper, that string i=
s
> stored a series of octets, which may or may not be encoded in UTF-8.
>
> The problem with thinking of strings as arrays of characters is pretty
> simple: What's a character? õ, "\x{F5}" (LATIN SMALL LETTER O WITH T=
ILDE) is
> a character, but what about õ, "o\x{303}", (LATIN SMALL LETTER O, CO=
MBINING
> TILDE)? What should string[0] return there? Can you get everyone to agree=
on
> that? : ) (For example, I had the displeasure of working with a fairly
> ancient version of Ruby where string[0] returned an octet, and there was =
no
> simple way of changing this. It was absolute hell. Never versions appear =
to
> be quite an improvement over that, though admittedly I haven't used those
> much)
>
> Also, this is a bit of a nitpick, but every solution shown so far is fair=
ly
> worthless with Unicode data:
> Consider È­, "o\x{303}\x{304}", LATIN SMALL LETTER O, COMBINING TILDE=
,
> COMBINING MACRON. Blindly doing /(.)/g on that will return a list with th=
ose
> three characters, and be mostly worthless.
> What you generally want is /(\X)/g, which will return the a single elemen=
t
> list, that element being a string with all three components of the actual
> character (i.e. an extended grapheme cluster).
>
> Tom Christiansen explains this and much more in his Unicode Essentials
> talk, which you can read here:
> http://training.perl.com/OSCON2011/index.html and is probably the newest
> tour de force for almost any Perl programmer.
>
>


--=20
*Satajanus Nig. Ltd


*

--000e0cd152247da4ee04a97e6c3e--

Re: Characters

am 02.08.2011 06:49:08 von Emeka

--000e0cd2547ad43cca04a97e77af
Content-Type: text/plain; charset=ISO-8859-1

Rob,

I have already picked up those functions. I think they are virtually the
same in all languages. Thanks

Emeka

On Mon, Aug 1, 2011 at 6:21 PM, Rob Dixon wrote:

> On 01/08/2011 13:14, Emeka wrote:
>
>>
>> I would like to know how to access character from string lateral.
>>
>> Say I have
>> $foo = "From Big Brother Africa";
>> I would want to print each of the characters of $foo on its own.
>>
>> In some languages string type is just array/list of characters. What is it
>> in Perl?
>>
>
> Hi Emeka
>
> Perl is rich with string-handling operators. Take a look at
>
> perldoc perlfunc
>
> and look at "Perl Functions by Category". Part of it reads
>
> Functions for SCALARs or strings
>> "chomp", "chop", "chr", "crypt", "hex", "index", "lc", "lcfirst",
>> "length", "oct", "ord", "pack", "q//", "qq//", "reverse", "rindex",
>> "sprintf", "substr", "tr///", "uc", "ucfirst", "y///"
>>
>> Regular expressions and pattern matching
>> "m//", "pos", "quotemeta", "s///", "split", "study", "qr//"
>>
>
> So what you would ordinarily do in C by indexing an array of characters
> can have many better solutions in Perl.
>
> As has been mentioned by others,
>
> my @chars = split //, $string;
>
> will give you an array of one-character strings that you may be able to
> handle as if you were using a different language, but that is rarely the
> way to go if you are writing a Perl program.
>
> Perl regular expressions are very felxible and comprehensive, and you
> will find that most string operations are best expressed that way rather
> than using split, index, substr and so on.
>
> If you describe your goal then we would be able to help you better.
>
> Rob
>



--
*Satajanus Nig. Ltd


*

--000e0cd2547ad43cca04a97e77af--

Re: Characters

am 02.08.2011 19:11:49 von Rob Dixon

On 01/08/2011 23:29, Jim Gibson wrote:
> On 8/1/11 Mon Aug 1, 2011 11:20 AM, "Rob Dixon"
> scribbled:
>
>> On 01/08/2011 19:00, Dr.Ruud wrote:
>>> On 2011-08-01 15:52, Shlomi Fish wrote:
>>>
>>>> To convert a string to characters one can use split based on the empty
>>>> regex,
>>>
>>> That should be "a pattern matching the empty string".
>>>
>>> The "empty regex" works differently:
>>>
>>> perl -wle '
>>> my $text = "abcdefghi";
>>> $text =~ /[aeiou]/;
>>> $text =~ /x/;
>>> my @result = $text =~ //g;
>>> print "@result";
>>> '
>>> a e i
>>>
>>> (admire how 'regex' and 'regular expression' are avoided in perldoc -f
>>> split)
>>
>> Please Shlomi, you have taught me nothing despite repeated reading of
>> your post. Please tell me what is wrong with the OP's
>>
>>> To convert a string to characters one can use split based on the empty regex
>>
>> Are you trying to say that any regular expression that can match zero
>> character will also suffice? How does your code demonstrate the point
>> you are making?
>
> Rob:
>
> I believe you are responding to Dr. Ruud's post, not Shlomi's, and the term
> "empty regex" is Shlomi's, not the OP (Emeka).
>
> Dr. Ruud is demonstrating the little-known but documented feature of Perl
> that the explicit empty regex // repeats the last, successful regex within
> its scope. Thus, in Dr. Ruud's sample program, the line
>
> my @result = $text =~ //g;
>
> is equivalent to the line
>
> my @result = $text =~ /[aeiou]/g;
>
> because that was the regex used in the last successful match.
>
> Of course, in a beginner's list, it is better to explain such exceptional
> cases, rather than just showing the statements. or people may miss the point
> entirely. But not everyone has the time or inclination to do so,
> unfortunately.

Thanks Jim. Ruud's post makes a lot more sense in the light of your post.

My apologies to Shlomi and Ruud for misattributing their contributions.

Rob

--
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
http://learn.perl.org/

Re: Characters

am 02.08.2011 19:26:38 von Brandon McCaig

On Mon, Aug 1, 2011 at 6:29 PM, Jim Gibson wrote:
> Dr. Ruud is demonstrating the little-known but documented feature of Perl
> that the explicit empty regex // repeats the last, successful regex withi=
n
> its scope. Thus, in Dr. Ruud's sample program, the line
>
>  my @result =3D $text =3D~ //g;
>
> is equivalent to the line
>
>  my @result =3D $text =3D~ /[aeiou]/g;
>
> because that was the regex used in the last successful match.
>
> Of course, in a beginner's list, it is better to explain such exceptional
> cases, rather than just showing the statements. or people may miss the po=
int
> entirely. But not everyone has the time or inclination to do so,
> unfortunately.

I had some trouble finding it with some lazy perldoc /searching so I
had #perl help out. :-X This is documented in perldoc perlop under the
heading "The empty pattern" (if anybody else has troubling finding
it). :)

It took me executing Dr. Ruud's example before I believed the result.
:P Then it took adding print statements on every line to demonstrate
that the variable wasn't changing throughout his program (not that I
thought it should be, but I just didn't know what was happening). Then
it took reading perldoc -f split to understand WTF was happening. By
then I just had to find the official documentation for the feature to
satisfy my curiosity. :\


--=20
Brandon McCaig
V zrna gur orfg jvgu jung V fnl. Vg qbrfa'g nyjnlf fbhaq gung jnl.
Castopulence Software ..org>

--
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
http://learn.perl.org/

Re: Characters

am 02.08.2011 19:34:42 von Shawn H Corey

On 11-08-02 01:26 PM, Brandon McCaig wrote:
> By
> then I just had to find the official documentation for the feature to
> satisfy my curiosity. :\

Yes, it's the bane of restful nights and many a dead cat. :)


--
Just my 0.00000002 million dollars worth,
Shawn

Confusion is the first step of understanding.

Programming is as much about organization and communication
as it is about coding.

The secret to great software: Fail early & often.

Eliminate software piracy: use only FLOSS.

"Make something worthwhile." -- Dear Hunter

--
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
http://learn.perl.org/