CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
"my $check_str = shift;" what means 'shift'

 



jumpding
New User

Mar 10, 2002, 6:54 PM

Post #1 of 3 (785 views)
"my $check_str = shift;" what means 'shift' Can't Post

 


mhx
Enthusiast / Moderator

Mar 10, 2002, 10:47 PM

Post #2 of 3 (781 views)
Re: [jumpding] "my $check_str = shift;" what means 'shift' [In reply to] Can't Post

Cool post. Why use the message body if there's a subject line? Wink


In Reply To

Code
my $check_str = shift;

what means 'shift';


Depends on where you call it. If not used within a subroutine or format, it is equivalent to:


Code
my $check_str = shift @ARGV;


So it shifts the first element off the array @ARGV and stores it in $check_str.
If it's for example encapsulated in a subroutine, it is equivalent to:


Code
my $check_str = shift @_;


Here it shifts the first element off the @_ array, which is implicitly used to pass arguments to a subroutine.

See also the [url=http://www.perldoc.com/perl5.6.1/pod/func/shift.html]shift manpage.
Hope this helps.

-- mhx

At last with an effort he spoke, and wondered to hear his own words, as if some other will was using his small voice. "I will take the Ring," he said, "though I do not know the way."

-- Frodo



Paul
Enthusiast

Mar 11, 2002, 3:26 AM

Post #3 of 3 (775 views)
Re: [mhx] "my $check_str = shift;" what means 'shift' [In reply to] Can't Post

and likewise if you are using objects and wish to get rid of $self you can do:

my $check_str = pop;

....to get the last element (if only two args are passed)....or....

shift;
my $arg = shift;


(This post was edited by RedRum on Mar 11, 2002, 3:27 AM)

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives