truthseeker66 has asked for the wisdom of the Perl Monks concerning the following question:
Dear Monks,
1. '$first' and '$second' are 2 different variables. Why is
'$_[0] . $_1' used instead of '$_[0] . $_[0]' to combine
two strings? Doesn't the first '$_' for '$first' and the
second '$_' for '$second'?
2. In this code " . $_[0] . $_1 . "\n"; I understand why there
are two dots. But I don't understand why the third dot is
there.
#!/usr/bin/perl #prompt user for two strings. Remove newline and #store into variables print "\nEnter the first string: "; chomp($first = <STDIN>); print "\nEnter the second string: "; chomp($second = <STDIN>); sub combine{ print "\nThe combined strings are: " . $_[0] . $_[1] . "\n"; } &combine($first,$second);
C:\JPARK\JPERL>sub-ex.pl
Enter the first string: I go
Enter the second string: to school.
The combined strings are: I go to school.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: subroutine function
by roboticus (Chancellor) on Oct 11, 2012 at 19:05 UTC | |
Re: subroutine function
by blue_cowdawg (Monsignor) on Oct 11, 2012 at 19:07 UTC | |
by tobyink (Canon) on Oct 11, 2012 at 19:55 UTC | |
by runrig (Abbot) on Oct 11, 2012 at 20:43 UTC | |
by truthseeker66 (Novice) on Oct 11, 2012 at 19:52 UTC | |
by bimleshsharma (Beadle) on Oct 12, 2012 at 09:46 UTC | |
by Mr. Muskrat (Canon) on Oct 12, 2012 at 14:28 UTC |
Back to
Seekers of Perl Wisdom