implicit split to @_ is deprecated ? but, but,

Discussion in 'Perl Misc' started by Wes Groleau, Feb 6, 2006.

  1. Wes Groleau

    Wes Groleau Guest

    "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
     
    Wes Groleau, Feb 6, 2006
    #1
    1. Advertising

  2. 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
     
    Joachim Pense, Feb 6, 2006
    #2
    1. Advertising

  3. Wes Groleau

    MSG Guest

    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.
     
    MSG, Feb 6, 2006
    #3
  4. 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
     
    John W. Krahn, Feb 6, 2006
    #4
  5. Wes Groleau

    Keith Keller Guest

    On 2006-02-06, Joachim Pense <> 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

    --
    -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
     
    Keith Keller, Feb 6, 2006
    #5
  6. Wes Groleau

    Paul Lalli Guest

    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
     
    Paul Lalli, Feb 6, 2006
    #6
  7. Wes Groleau

    Wes Groleau Guest

    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
     
    Wes Groleau, Feb 7, 2006
    #7
  8. Wes Groleau

    Wes Groleau Guest

    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.
     
    Wes Groleau, Feb 7, 2006
    #8
  9. Wes Groleau

    Wes Groleau Guest

    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
     
    Wes Groleau, Feb 7, 2006
    #9
  10. Wes Groleau

    Paul Lalli Guest

    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...ul author:Lalli&rnum=1&hl=en#66a7666442c770f2
    )

    > 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
     
    Paul Lalli, Feb 7, 2006
    #10
  11. 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.



    I can remember you doing it less than a month ago:

    Subject: Where do you report perl bugs?
    Message-Id:


    > 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.



    perldoc perldata

    See the "Context" section.


    > In other words, _others_
    > foolishly gave me the answer,



    Exactly so.


    > 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.



    Typing

    perldoc -q bug
    and
    perldoc -f split

    does not require navigating stacks of awesome documentation.

    Your credibility suffers, in my observations of your posting history.


    --
    Tad McClellan SGML consulting
    Perl programming
    Fort Worth, Texas
     
    Tad McClellan, Feb 8, 2006
    #11
  12. Wes Groleau

    Wes Groleau Guest

    Re: implicit split to @_ is deprecated ? but, but,

    Paul Lalli wrote:
    > solve the problem for yourself. If you had simply said "I read
    > `perldoc -f split`, but I still don't understand this warning. . . "


    :) I couldn't have done that because two days ago I had never
    heard of "perldoc -f"

    This is odd, but I have read three or more perl books cover to
    cover, and I don't remember ANY of them paying any attention
    to man pages or other electronic documentation.

    "perldoc -f" I suspect I won't forget that one. :)

    --
    Wes Groleau
    "Ideas are more powerful than guns,
    We would not let our enemies have guns;
    why should we let them have ideas?"
    -- Jozef Stalin
     
    Wes Groleau, Feb 8, 2006
    #12
  13. Wes Groleau

    Wes Groleau Guest

    Re: implicit split to @_ is deprecated ? but, but,

    Tad McClellan wrote:
    > Wes Groleau <> wrote:
    >>For what it's worth, never in my decades of Usenet use can I remember
    >>asking a question without doing some research.

    >
    > I can remember you doing it less than a month ago:
    >
    > Subject: Where do you report perl bugs?
    > Message-Id:


    Apparently your memory is no better than mine.
    I abandoned gbronline a heck of a lot longer
    than a month ago. Long enough that I can't be certain
    I did any research on that question. I do know that it
    wouldn't be like me to not try to figure it out on my own.

    But of course, you will believe whatever you want to
    believe about me. Enjoy.

    --
    Wes Groleau
    "Ideas are more powerful than guns,
    We would not let our enemies have guns;
    why should we let them have ideas?"
    -- Jozef Stalin
     
    Wes Groleau, Feb 8, 2006
    #13
  14. Re: implicit split to @_ is deprecated ? but, but,

    Wes Groleau <> wrote in news:ZqdGf.146643
    $7l4.54121@trnddc05:

    > Paul Lalli wrote:
    >> solve the problem for yourself.


    This is badly quoted out of context. Paul did not say "solve the problem
    yourself". Instead, he said:

    <blockquote author="Paul Lalli">
    My problem was that you gave no indication you had attempted to
    solve the problem for yourself.
    </blockquote>

    >> if you had simply said "I read `perldoc -f split`, but I still
    >> don't understand this warning. . . "

    >
    >:) I couldn't have done that because two days ago I had never
    > heard of "perldoc -f"


    That statement also means that you have not read the posting guidelines
    before posting here:

    http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html#must

    Since you chose not to satisfy the most basic requirement for receiving
    help here, Paul's warning was entirely appropriate.

    > "perldoc -f" I suspect I won't forget that one. :)


    That's good because it is becoming less and less likely that you'd be
    able to get help any other way.

    So long.

    Sinan
    --
    A. Sinan Unur <>
    (reverse each component and remove .invalid for email address)

    comp.lang.perl.misc guidelines on the WWW:
    http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html
     
    A. Sinan Unur, Feb 8, 2006
    #14
  15. Wes Groleau

    Wes Groleau Guest

    I over-reacted.

    Wes Groleau wrote:
    > 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."


    Amusing that I had to BE a snot to introduce a quote
    about being a snot.

    Sorry.

    --
    Wes Groleau
    Heroes, Heritage, and History
    http://freepages.genealogy.rootsweb.com/~wgroleau/
     
    Wes Groleau, Feb 9, 2006
    #15
  16. Re: implicit split to @_ is deprecated ? but, but,

    Wes Groleau <> wrote:
    > Tad McClellan wrote:
    >> Wes Groleau <> wrote:
    >>>For what it's worth, never in my decades of Usenet use can I remember
    >>>asking a question without doing some research.

    >>
    >> I can remember you doing it less than a month ago:
    >>
    >> Subject: Where do you report perl bugs?
    >> Message-Id:

    >
    > Apparently your memory is no better than mine.



    Apparently we have entered the Twilight Zone then, as that
    message ID appears on both my news server and on google groups.


    > I abandoned gbronline a heck of a lot longer
    > than a month ago.



    So that wasn't you using your name in that thread?


    --
    Tad McClellan SGML consulting
    Perl programming
    Fort Worth, Texas
     
    Tad McClellan, Feb 9, 2006
    #16
  17. Wes Groleau

    Paul Lalli Guest

    Re: implicit split to @_ is deprecated ? but, but,

    Tad McClellan wrote:
    > Wes Groleau <> wrote:
    > > Tad McClellan wrote:
    > >> Wes Groleau <> wrote:
    > >>>For what it's worth, never in my decades of Usenet use can I remember
    > >>>asking a question without doing some research.
    > >>
    > >> I can remember you doing it less than a month ago:
    > >>
    > >> Subject: Where do you report perl bugs?
    > >> Message-Id:

    > >
    > > Apparently your memory is no better than mine.


    > Apparently we have entered the Twilight Zone then, as that
    > message ID appears on both my news server and on google groups.
    > > I abandoned gbronline a heck of a lot longer
    > > than a month ago.

    >
    > So that wasn't you using your name in that thread?



    Er, Tad?
    http://groups.google.com/group/comp.lang.perl.misc/msg/a37edfc9d1eb0a73
    shows a date of Jan 16, 2005. Not 2006.

    Paul Lalli


    >
    >
    > --
    > Tad McClellan SGML consulting
    > Perl programming
    > Fort Worth, Texas
     
    Paul Lalli, Feb 9, 2006
    #17
  18. Re: implicit split to @_ is deprecated ? but, but,

    Tad McClellan <> wrote:
    > Wes Groleau <> wrote:


    >> For what it's worth, never in my decades of Usenet use can I remember
    >> asking a question without doing some research.

    >
    >
    > I can remember you doing it less than a month ago:
    >
    > Subject: Where do you report perl bugs?
    > Message-Id:



    Doh!

    That was January 200_5_, not 2006.

    I guess my $current_year++ takes a few months to finish executing. :)


    --
    Tad McClellan SGML consulting
    Perl programming
    Fort Worth, Texas
     
    Tad McClellan, Feb 9, 2006
    #18
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Barney Barumba
    Replies:
    0
    Views:
    571
    Barney Barumba
    Jul 23, 2003
  2. Replies:
    2
    Views:
    475
  3. Carlos Ribeiro
    Replies:
    11
    Views:
    712
    Alex Martelli
    Sep 17, 2004
  4. Generic Usenet Account
    Replies:
    3
    Views:
    840
    Generic Usenet Account
    Jul 14, 2005
  5. Daryle Walker
    Replies:
    0
    Views:
    246
    Daryle Walker
    Nov 2, 2011
Loading...

Share This Page