#1
  1. The Queen of Typos
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Sep 2004
    Location
    San Clemente
    Posts
    1,471
    Rep Power
    190

    What Exactly Does "Use of implicit split to @_ is deprecated" mean?


    I've seen the perl docs that says it clobbers the subroutine, but I don't understand what clobbering is either.

    I'm fairly new to Perl so I find this perplexing.

    The code I am receiving this error on is the following:

    $ver = split "-", $ver;

    $ver is a variable coming from an array.

    Thanks!
  2. #2
  3. Y? Y!?
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Oct 2003
    Location
    Brisbane, Australia
    Posts
    1,573
    Rep Power
    48
    Usually with the split function you need the lvalue to be an array:
    Code:
    my @array = split '-', $scalar;
    If the lvalue is a scalar as you have it, then (I think) it only returns the first element of the array.

    I am puzzled exactly what you are trying to do with that line though. Can you describe what you are trying to accomplish?

    [EDIT]
    Back to your original question. An implicit split (a split without an lvalue) such as:
    Code:
    split '-', $val;
    will split the $val scalar and place the results into the @_ default array variable.

    The problem occurs if that line of code is placed in a subroutine, since subroutine parameters are passed in @_. What this means is that when you enter a subroutine, its parameters reside in @_. Then you replace those (possibly imporatant) parameters with whatever is returned from the split function. You have effectively 'clobbered' the subroutine parameters - they won't exist anymore.
    Last edited by mlh2003; October 27th, 2004 at 08:13 PM.
    print join'',(reverse sort map{/\d([a-z])\d/}split/\W/,'$5l6@314&60f%3h4#moo^1m2'),(map{/\d(\d)/}grep/\w\d/,reverse split/\W/,'a2&2b#9i*30%42'),(unpack"AA",(chr(0b110000).chr(0b110011)));
  4. #3
  5. The Queen of Typos
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Sep 2004
    Location
    San Clemente
    Posts
    1,471
    Rep Power
    190
    My problem is that I am reading in from a csv and then outputting to another csv.

    Each file contains two columns, one for OS and another for Version.

    If the data I had was clean it wouldn't be a problem but since it's not some of the versions appear as "11.2-12.0" instead of just each version individually.

    I am trying to split out the hyphen and just copy out what is left to the new csv.

    After parsing the file, I push the values to an array.
  6. #4
  7. Y? Y!?
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Oct 2003
    Location
    Brisbane, Australia
    Posts
    1,573
    Rep Power
    48
    Originally Posted by elkehinze
    My problem is that I am reading in from a csv and then outputting to another csv.

    Each file contains two columns, one for OS and another for Version.

    If the data I had was clean it wouldn't be a problem but since it's not some of the versions appear as "11.2-12.0" instead of just each version individually.

    I am trying to split out the hyphen and just copy out what is left to the new csv.

    After parsing the file, I push the values to an array.
    So in the output csv file, do you want just the 11.2 (and not the 12.0)?

    If so, then:
    Code:
    my ($new_version, @temp) = split '-', $old_version;
    # then store $new_version in the output csv
    Maybe I am misunderstanding you, but I don't see how a hyphen will break a csv file in the first place...
    print join'',(reverse sort map{/\d([a-z])\d/}split/\W/,'$5l6@314&60f%3h4#moo^1m2'),(map{/\d(\d)/}grep/\w\d/,reverse split/\W/,'a2&2b#9i*30%42'),(unpack"AA",(chr(0b110000).chr(0b110011)));
  8. #5
  9. Contributing User
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Oct 2004
    Location
    Sunny Southern California
    Posts
    2,687
    Rep Power
    861
    the error message you are getting is because you are not splitting the string ($ver) into a list (an @array) so Perl tries to return the number of fields found and split it into the @_ array.
  10. #6
  11. The Queen of Typos
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Sep 2004
    Location
    San Clemente
    Posts
    1,471
    Rep Power
    190
    [QUOTE=mlh2003]So in the output csv file, do you want just the 11.2 (and not the 12.0)?

    In the output file I want the 11.2 and the 12.0, but each on a different line so it would appear something like:

    OS Version
    CISCO 11.2
    CISCO 12.0
  12. #7
  13. Contributing User
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Oct 2004
    Location
    Sunny Southern California
    Posts
    2,687
    Rep Power
    861
    [QUOTE=elkehinze]
    Originally Posted by mlh2003
    So in the output csv file, do you want just the 11.2 (and not the 12.0)?

    In the output file I want the 11.2 and the 12.0, but each on a different line so it would appear something like:

    OS Version
    CISCO 11.2
    CISCO 12.0
    this could be a problem because some version numbers might contain a legitimate hyphen, so you may never get it 100% accurate, but you could use a regexp that sees if the line contains a hyphen and then either split the line or use a regexp to grab the version numbers, here is one possible method using split (where $name holds the value of the software, like CISCO):


    Code:
    if ($ver =~ /-/) {
       @versionarray = split /-/, $ver;
    }
    
    if (@versionarray) {
       print FILEHANDLE "$name $_\n" for @versionarray;
    }
  14. #8
  15. Y? Y!?
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Oct 2003
    Location
    Brisbane, Australia
    Posts
    1,573
    Rep Power
    48
    You could still split on the hyphen into an array. If there is no hyphen in the string, it will simply populate the first element of the array.

    Code:
    my @array = split '-', $ver;
    foreach (@array) {
        print CSV "$os $_\n";
    }
    where CSV is the opened filehandle of the csv file you are writing to, and $os is the OS obtained from the outer loop that reads each line in from the original csv file.
    print join'',(reverse sort map{/\d([a-z])\d/}split/\W/,'$5l6@314&60f%3h4#moo^1m2'),(map{/\d(\d)/}grep/\w\d/,reverse split/\W/,'a2&2b#9i*30%42'),(unpack"AA",(chr(0b110000).chr(0b110011)));
  16. #9
  17. Contributing User
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Oct 2004
    Location
    Sunny Southern California
    Posts
    2,687
    Rep Power
    861
    Originally Posted by mlh2003
    You could still split on the hyphen into an array. ...
    Good point

IMN logo majestic logo threadwatch logo seochat tools logo