in reply to difference between ($scalar) and $scalar
my ($fortune) = `fortune`;When the backtick detects "array context", it splits up the lines returned by the command into an array and returns it. $fortune then gets the first element/line and the rest go unassigned.
my $fortune = `fortune`;In scalar context, the entire result is returned in one string, meaning that the linefeeds are not split.
This prints, for me at least: "42 / Sat Jul 21 03:02:42 2001", which shows you how important those brackets can be.my ($time1) = localtime; my $time2 = localtime; print "$time1 / $time2\n";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: difference between ($scalar) and $scalar
by John M. Dlugosz (Monsignor) on Jul 22, 2001 at 01:08 UTC |