ChOas has asked for the wisdom of the Perl Monks concerning the following question:
The resulting output :#!/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);
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:
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: strange shift @_ problem
by ahunter (Monk) on Jan 18, 2001 at 16:50 UTC | |
|
Re: strange shift @_ problem
by stefan k (Curate) on Jan 18, 2001 at 16:37 UTC | |
|
Re: strange shift @_ problem
by Anonymous Monk on Jan 18, 2001 at 16:38 UTC | |
|
Re: strange shift @_ problem
by repson (Chaplain) on Jan 19, 2001 at 09:13 UTC | |
by dchetlin (Friar) on Jan 19, 2001 at 10:37 UTC | |
|
Re: strange shift @_ problem
by flocto (Pilgrim) on Jan 18, 2001 at 17:05 UTC | |
by ChOas (Curate) on Jan 18, 2001 at 17:10 UTC | |
by flocto (Pilgrim) on Jan 18, 2001 at 17:18 UTC |