can anyone explain the last two lines to me?thanks!

B

biomahui

#!/usr/bin/perl
$_='OTcommailDngATghiliaguans';
1 while s/(.{5})(.{5})?/$_{$2}=$1,$2/e;
print while $_=$_{$_};
 
F

Fabian Pilkowski

#!/usr/bin/perl
$_='OTcommailDngATghiliaguans';
1 while s/(.{5})(.{5})?/$_{$2}=$1,$2/e;
print while $_=$_{$_};

It's unusual to put all your text into the posting's subject. It is
possible to ask your question in the posting's body next time? ;-)

Nevertheless, "you" are looking for the first two parts of $_, each 5
chars long. With »$_{$2}=$1« these two parts becomes a key-value-pair in
the hash »%_«. Then you substitutes these two parts with the second one,
i.e. you simply deletes the first 5 chars of $_. That's all your loop is
doing, but successively until your string $_ is shorter than 5 chars. In
your example above this first while loop will give you the hash

%_ = (
'mailD' => 'OTcom',
'ngATg' => 'mailD',
'hilia' => 'ngATg',
'guans' => 'hilia'
'' => 'guans'
);

Now, the string $_ is empty. The second while loop takes the element $_
of %_ and assigns its value to $_ again. So its first pass gets $_{''}
so that $_ contains 'guans' afterwards. print() without params will
print out the content of $_. The next pass is looking for the hash
element 'guans', so it returns 'hilia', etc. Hence, the following
strings arrives one after the other your console:

guans
hilia
ngATg
mailD
OTcom

Reading this as one line could be interpreted as a mailaddress. Btw,
next time you could change your code to


$_='OTcommailDngATghiliaguans';
print "\$_{'$2'}='$1' --> \$_ = '$_'\n" while s/(.{5})(.{5})?/$_{$2}=$1,$2/e;
use Data::Dumper;
print Dumper(\%_);
print "$_\n" while $_=$_{$_};
__END__


to figure out by yourself what happens. ;-)

regards,
fabian
 
B

biomahui

Thank you very much, Fabian.
Your explaination and script gives me excellent idea how it works.
Thanks again!

hui
 
B

biomahui

a problem encountered when I created my own email address as follows:

#!/usr/bin/perl
$_='comil.gmaui@mahbio';
1 while s/(.{2})(.{2})?/$_{$2}=$1,$2/e;
print $_ while $_=$_{$_};

If I use $_='(e-mail address removed)'; the program will never stop.
what's the problem?
 
R

Richard Gration

a problem encountered when I created my own email address as follows:

#!/usr/bin/perl
$_='comil.gmaui@mahbio';
1 while s/(.{2})(.{2})?/$_{$2}=$1,$2/e;
print $_ while $_=$_{$_};

If I use $_='(e-mail address removed)'; the program will never stop.
what's the problem?

Check your hash keys. You're in a loop.
 
B

biomahui

Thank you, Richard.
I find I have two "om" for my hash. I guess it is the reason.
Thanks for the guidance.
 
J

Joe Smith

A. Sinan Unur said:
(e-mail address removed) wrote in @f14g2000cwb.googlegroups.com:


Huh?

The OP is referring to the misfeature on http://groups-beta.google.com
in which ' b i o m a h u i @ g m a i l . c o m ' is displayed
as '(e-mail address removed)'. He or she is assuming that everyone
reads USENET newsgroups via a web interface where context can be
found on the screen one inch above the reply.

http://groups-beta.google.com/group..._frm/thread/8b03f848d20faaaa/618250eaa4dd1bc1
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top