![]() |
implicit split to @_ is deprecated ? but, but,
"Use of implicit split to @_ is deprecated at
/Users/wgroleau/bin/INDENTREC.cgi line 95." Huh ? sub RecType { my $Key = shift; my $GedRec = split (/\n/, $Params{$Key}, 1); # line 95 I am trying to split off the first line of the multi-line record from the hash, into GedRec. I don't see how it is going into @_ -- Wes Groleau Even if you do learn to speak correct English, whom are you going to speak it to? -- Clarence Darrow |
Re: implicit split to @_ is deprecated ? but, but,
Am Mon, 06 Feb 2006 04:14:59 GMT schrieb Wes Groleau:
> "Use of implicit split to @_ is deprecated at > /Users/wgroleau/bin/INDENTREC.cgi line 95." > > Huh ? > > sub RecType > { > my $Key = shift; > my $GedRec = split (/\n/, $Params{$Key}, 1); # line 95 > > I am trying to split off the first line of the multi-line > record from the hash, into GedRec. I don't see how it is > going into @_ The result of a split is an array, not a scalar. You call split in a scalar context (as $GedRec is a scalar), so what happens is that the result of the split will be put into @_ implicitly, and $GedRec will receive the element count of @_. Joachim |
Re: implicit split to @_ is deprecated ? but, but,
Wes Groleau wrote: > "Use of implicit split to @_ is deprecated at > /Users/wgroleau/bin/INDENTREC.cgi line 95." > > Huh ? > > sub RecType > { > my $Key = shift; > my $GedRec = split (/\n/, $Params{$Key}, 1); # line 95 > > I am trying to split off the first line of the multi-line > record from the hash, into GedRec. I don't see how it is > going into @_ > > -- > Wes Groleau > > Even if you do learn to speak correct English, > whom are you going to speak it to? > -- Clarence Darrow my ($GedRec) = split (/\n/, $Params{$Key}, 1); -----^-------------^----------------------------------------------- split returns a list. |
Re: implicit split to @_ is deprecated ? but, but,
Wes Groleau wrote:
> "Use of implicit split to @_ is deprecated at > /Users/wgroleau/bin/INDENTREC.cgi line 95." > > Huh ? > > sub RecType > { > my $Key = shift; > my $GedRec = split (/\n/, $Params{$Key}, 1); # line 95 > > I am trying to split off the first line of the multi-line > record from the hash, into GedRec. I don't see how it is > going into @_ When split() is used in void or scalar context the results are stored in the @_ array. To do what you want you have to either put the scalar in a list: my ( $GedRec ) = split /\n/, $Params{ $Key }; # line 95 Or use a list slice on split(): my $GedRec = ( split /\n/, $Params{ $Key } )[ 0 ]; # line 95 Also, using 1 as the third argument does not do what you appear to think it does: $ perl -le' @x = split /X/, "oneXtwoXthreeXfourX"; print for @x ' one two three four $ perl -le' @x = split /X/, "oneXtwoXthreeXfourX", 1; print for @x ' oneXtwoXthreeXfourX So your original statement is the same as writing: my $GedRec = $Params{$Key}; John -- use Perl; program fulfillment |
Re: implicit split to @_ is deprecated ? but, but,
On 2006-02-06, Joachim Pense <spam-collector@pense-online.de> wrote:
> > The result of a split is an array, not a scalar. This has already been posted correctly elsewhere, but I thought it worthwhile to followup to be explicit: the result of a split is not an array, but a list. You can of course store the result in an array, but you don't have to; the other solutions have it being stored in a list of scalars, for example. Yes, that's pedantic, but the list/array distinction is confusing enough to beginners. :) --keith -- kkeller-usenet@wombat.san-francisco.ca.us (try just my userid to email me) AOLSFAQ=http://wombat.san-francisco.ca.us/cgi-bin/fom see X- headers for PGP signature information |
Re: implicit split to @_ is deprecated ? but, but,
Wes Groleau wrote:
> "Use of implicit split to @_ is deprecated at > /Users/wgroleau/bin/INDENTREC.cgi line 95." > > Huh ? > > sub RecType > { > my $Key = shift; > my $GedRec = split (/\n/, $Params{$Key}, 1); # line 95 > > I am trying to split off the first line of the multi-line > record from the hash, into GedRec. I don't see how it is > going into @_ Other posters have given you the answer, but I'm forced to wonder if you even *tried* to figure it out on your own first. Please make sure you check the built-in perl documentation for the functions your using, especially if the warning message is nice enough to tell you exactly what function is not working correctly: perldoc -f split In scalar context, returns the number of fields found and splits into the "@_" array. Use of split in scalar context is deprecated, however, because it clobbers your subroutine arguments. Paul Lalli |
Re: implicit split to @_ is deprecated ? but, but,
Paul Lalli wrote:
> Other posters have given you the answer, but I'm forced to wonder if > you even *tried* to figure it out on your own first. Please make sure > you check the built-in perl documentation for the functions your using, > especially if the warning message is nice enough to tell you exactly > what function is not working correctly: For what it's worth, never in my decades of Usenet use can I remember asking a question without doing some research. With perl, usually I spend 5-10 minutes with perltoc or perlfaq or ... trying to figure out which of the 131 perl man pages (157 K lines) to look in, 5-10 minutes figuring out it ain't in that one, .... how many reps of that depends on how tired I am. About half (?) the time, I find the right one and don't need to troll Usenet for RTFMs. > perldoc -f split > In scalar context, returns the number of fields > found and splits into the "@_" array. Use of split > in scalar context is deprecated, however, because it > clobbers your subroutine arguments. You don't have to believe me, but the biggest problem was that in spite of having been doing off and on perl for ten years, I actually did not realize the implications of trying to treat "one item" as if it were "a list containing one item" as being the same. In other words, _others_ foolishly gave me the answer, while you nobly upheld the finest traditions of Usenet by bestowing upon me well-deserved and elegantly worded contempt for my lack of skill at navigating the stacks of the awesome Perl Public Library. OTOH, I realize not everyone agrees with those traditions. For example, Larry Wall: "There ain't nothin' in this world that's worth being a snot over." -- Wes Groleau Those who make peaceful revolution impossible will make violent revolution inevitable. -- John F. Kennedy |
Re: implicit split to @_ is deprecated ? but, but,
Keith Keller wrote:
> worthwhile to followup to be explicit: the result of a split is not an > array, but a list. You can of course store the result in an array, but > you don't have to; the other solutions have it being stored in a list of > scalars, for example. > > Yes, that's pedantic, but the list/array distinction is confusing > enough to beginners. :) Well, as I have hinted elsewhere, in this case the distinction that was hidden by my OldTimer's disease was that a scalar is not the same thing as a list containing one scalar. Many thanks to Joachim, MSG, and John for giving my spinning wheels a little helpful shove. I still don't understand the third parameter. I thought I had read that it meant split off that many and ignore the rest. -- Wes Groleau The man who says, "I can do it!" may sometimes fail. The man who says, "Impossible!" will never succeed. |
Re: implicit split to @_ is deprecated ? but, but,
Wes Groleau wrote:
> Many thanks to Joachim, MSG, and John for giving my spinning wheels > a little helpful shove. Wouldn't you know, now that I know how to make it work, I've discovered I don't need that sub after all. :-) -- Wes Groleau I've noticed lately that the paranoid fear of computers becoming intelligent and taking over the world has almost entirely disappeared from the common culture. Near as I can tell, this coincides with the release of MS-DOS. -- Larry DeLuca |
Re: implicit split to @_ is deprecated ? but, but,
Wes Groleau wrote:
> Paul Lalli wrote: > > Other posters have given you the answer, but I'm forced to wonder if > > you even *tried* to figure it out on your own first. Please make sure > > you check the built-in perl documentation for the functions your using, > > especially if the warning message is nice enough to tell you exactly > > what function is not working correctly: > > For what it's worth, never in my decades of Usenet use can I remember > asking a question without doing some research. Good! Unfortunately, that puts you in the vast minority. > With perl, usually > I spend 5-10 minutes with perltoc or perlfaq or ... trying to figure out > which of the 131 perl man pages (157 K lines) to look in, 5-10 minutes > figuring out it ain't in that one, I can understand that frustration. But in this case, it seemed obvious that if you are having a problem with split(), then you should look at the docs for split(). > > perldoc -f split > > In scalar context, returns the number of fields > > found and splits into the "@_" array. Use of split > > in scalar context is deprecated, however, because it > > clobbers your subroutine arguments. > > You don't have to believe me, but the biggest problem was that in spite > of having been doing off and on perl for ten years, I actually did not > realize the implications of trying to treat "one item" as if it were "a > list containing one item" as being the same. I believe you just fine. That's not a completely foolish error to make. My problem was that you gave no indication you had attempted to solve the problem for yourself. If you had simply said "I read `perldoc -f split`, but I still don't understand this warning. . . " I'd have had no problem, and probably wouldn't have posted at all. > In other words, _others_ foolishly gave me the answer, As I noted in the very first line of my post. > while you nobly upheld the finest > traditions of Usenet by bestowing upon me well-deserved and elegantly > worded contempt for my lack of skill at navigating the stacks of the > awesome Perl Public Library. No no. I bestowed upon you contempt for seemingly not attempting to help yourself before asking thousands of other people to help you. Read the Posting Guidelines for this group. They will inform you that your best bet to receive help is to explicitly state what you have tried to solve your problem on your own. By not stating any such thing, you implied that you had made no effort. Indeed, if you had said that you read the docs, but still didn't understand the warning, then we could have deduced that you did not understand that assigning to a scalar was forcing split() to be called in a scalar context, and could have helped you better. (FWIW, this exact issue happened to me about a year ago in this group - I was seeing odd behavior with the .. operator, and read the docs, but my post did not indicate that. I was justly chided for not reading the documentation, when in fact the issue was me not realizing my code was using .. in a scalar context: http://groups.google.com/group/comp....a7666442c770f2 ) > OTOH, I realize not everyone agrees with those traditions. > For example, Larry Wall: "There ain't nothin' in this world > that's worth being a snot over." I am truly sorry if you considered my post to be snotty. That was not the intent. The intent was both to inform you of where you could have found the answer on your own, and to help anyone lurking learn where they could have found the answer had they had a similar problem. Regards, Paul Lalli |
| All times are GMT. The time now is 03:11 AM. |
Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.