I'm not sure if shift (@results) . $line; and shift @results . $line
would work differently. It depends on whether the order of operations
gives precedence to . or to handing an argument to a function. My
guess is that . gets precedence, in which case shift @results . $line;
will give you something weird that you don't want.
I suggest you look up the perldocs on shift, but basically if you have
any array, like:
my @arr = ('a', 'b', 'c');
the result of:
print shift (@arr);
will be:
a
and @arr will now only be:
('b', 'c')
In other words, it takes the first element off of the array. It is
often used to get arguments to a function:
sub foo {
my $arg1 = shift;
my $arg2 = shift;
print $arg1 . " " . $arg2;
}
foo ("hello", "world");
would print:
hello world
So, shift (@results) . $line; is taking the next value from @results
and appending $line to it.
That value will then be the next value in @newresults.
It takes a bit of getting used to. I suggest reading a little about
functional programming to fully grasp the list manipulation functions
like map, grep, split, join, etc.
-David
On Fri, 10 Sep 2004 14:37:28 -0500, Errin Larsen <[EMAIL PROTECTED]> wrote:
> On Fri, 10 Sep 2004 15:01:34 -0400, David Greenberg
> <[EMAIL PROTECTED]> wrote:
> > Opps, I missed that. Instead of:
> > @results = map { my $line = $_; chomp $line; $line =~ s/\s+//g; $line } (@data);
> > try:
> > my @newresults = map { my $line = $_; chomp $line; $line =~ s/\s+//g;
> > shift (@results) . $line } (@data);
> > @results = @newresults;
> >
> > -David
> >
>
> Ok ... please forgive my n00b-ness, but can you help me understand a
> couple of things here. This part:
>
> shift (@results) . $line
>
> Is it the same as:
>
> shift @results . $line
>
> I'm thinking "no". But I don't know what the difference is. I also
> don't understand what exactly that shift is doing, but if I understand
> the difference with the parens maybe It'll start to make more sense to
> me.
>
> --Errin
>
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>