Hello People,
I'm stumped, I was trying to write an obfuscation,
and (don't shoot me for this ;))) I included my
own some kind of splittish thing.
And I found something VERY weird.
I wrote up the included code, and output, and I would
REALLY appreciate your view on this:
#!/usr/bin/perl -w
use strict;
sub Case1
{
print "AtUnderscore: ",(join ",",@_),"\n";
print "shift: ",shift,"\n";
# string is now gone from @_ , which means
# that $_[1] should be 5, and $_[2] is undef
# This shows to be true (see output Case1)
print "AtUnderscore after shift: @_\n";
print "\$_[1]: $_[1]\n";
print "\$_[2]: $_[2]\n";
};
sub Case2
{
print "AtUnderscore: ",(join ",",@_),"\n";
# Please explain to me HOW I can shift @_
# here, but still have access to the original
# $_[2] (see var $Rubbish)...
my $Rubbish=join "",(split //,shift)[$_[1]..$_[2]];
# But HERE I lost the access to $_[2].
# its gone!!!
print "Rubbish: $Rubbish\n";
print "1: $_[1]\n";
print "2: $_[2]\n";
};
print "\n\nCase1:\n";
Case1("This_is_a_string",3,5);
print "\n\nCase2:\n";
Case2("This_is_a_string",3,5);
The resulting output :
Case1:
AtUnderscore: This_is_a_string,3,5
shift: This_is_a_string
AtUnderscore after shift: 3 5
$_[1]: 5
Use of uninitialized value in concatenation (.) at ./mysplit line 16.
$_[2]:
Case2:
AtUnderscore: This_is_a_string,3,5
Rubbish: s_i
1: 5
Use of uninitialized value in concatenation (.) at ./mysplit line 34.
2:
Am I losing my mind, or just missing the point ?
Thank you in advance for any comment you might have
GreetZ!,
print "profeth still\n" if /bird|devil/;
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.