Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I have a file containing many lines of data such as:
Me|http://myURL.com|Me@myURL.com|147|Hi,Guys!|Monday, July 28th 2003 1 +1:12PM
I'm simply trying to split it, but I'm getting a funny error:
Use of implicit split to @_ is deprecated at \perl.pl line 7. Use of uninitialized value in pattern match (m//) at perl.pl line 7, < +ALL> line 173. Died at \perl.pl line 7, <ALL> line 173.
I've done this kind of split before with no problems, so I'm not sure where I've gone wrong. I'm on Windows with Active state perl 5.6.1
here is my code:
use strict; use warnings; open(ALL,"all2.txt") || die $!; for (<ALL>){ my($name,$url,$email,$id,$comment,$date) =~ split(/\|/,$_) || die $!; print $url; }
Thanks

Replies are listed 'Best First'.
Re: spliting problems on $_ ?
by pzbagel (Chaplain) on Nov 05, 2003 at 18:20 UTC

    lose the '~' in the '=~'

    Nuff said

Re: spliting problems on $_ ?
by duct_tape (Hermit) on Nov 05, 2003 at 18:20 UTC
    Change the =~ to = split returns a list.
Re: spliting problems on $_ ?
by TomDLux (Vicar) on Nov 05, 2003 at 19:57 UTC

    You save all the variables, but only use one of them. One option is to only save the ones you need, and not bother with variables at the end of the list:

    my(undef, $url) = split ....

    Better is to extract only the elements you want:

    my( $url ) = (split( /\|/, $_ ))[1];

    --
    TTTATCGGTCGTTATATAGATGTTTGCA

Re: spliting problems on $_ ?
by Anonymous Monk on Nov 05, 2003 at 18:27 UTC
    This should work
    #!/usr/bin/perl use strict; use warnings; while (<DATA>) { my($name,$url,$email,$id,$comment,$date) = split(/\|/); print $url; } __DATA__ Me|http://myURL.com|Me@myURL.com|147|Hi,Guys!|Monday, July 28th 2003 1 +1:12PM