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: I dont understand this particular sub: Edit Log



popeye
Novice

Dec 5, 2013, 6:36 AM


Views: 1629
I dont understand this particular sub

I dont understand what is going on with this sub. I have the need to compare 3 vars and searched the web for examples. I found this but dont understand what the sub is doing

Code
#!/usr/bin/perl 

my $a = 2;
my $b = 2;
my @arr = qw( 2 2 2 );

if (all_equal_ints($a, $b, @arr)) {
print "They're all equal!\n"
} else {
print "They're not all equal!\n";
}

sub all_equal_ints {
my $first = shift; #why shift and where is $first coming from
for (@_) { #I understand this is reading the list of vars passed
return 0 unless $first == $_; #Not sure what this is saying
}
return 1; # suppose if the test above fails, sets return to "true"
}


Thanks for helping this nooby out in advance !! My transition from Ksh to perl continues with lots of frustration and "stucks". .. but Im determined. Crazy


(This post was edited by popeye on Dec 5, 2013, 6:36 AM)


Edit Log:
Post edited by popeye (Novice) on Dec 5, 2013, 6:36 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