Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re^2: split problem

by stevieb (Canon)
on Nov 29, 2016 at 23:16 UTC ( #1176872=note: print w/replies, xml ) Need Help??


in reply to Re: split problem
in thread split problem

There must be something else the issue here, as if you remove all of the trailing tabs from the string, it works fine on all versions of perl I have installed currently.

Works:

use warnings; use strict; my $value = "A\tB\tC\tD\tE\tF"; my @flds = split(/\t/, $value); $flds[16] = undef; $flds[8] = 0; print scalar @flds; __END__ 17

Broken:

use warnings; use strict; my $value = "A\tB\tC\tD\tE\tF\t\t\t\t\t\t"; my @flds = split(/\t/, $value); $flds[16] = undef; $flds[8] = 0;

Replies are listed 'Best First'.
Re^3: split problem ( Modification of a read-only value attempted , Devel::Peek )
by Anonymous Monk on Nov 29, 2016 at 23:32 UTC

    Use Devel::Peek with working/nonworking to see the difference

    Sounds like a bug in perl

    #!/usr/bin/perl -- use strict; use warnings; use Devel::Peek qw/ Dump /; eval { my $value = "A\tB\tC\tD\tE\tF"; my @flds = split(/\t/, $value); $flds[16] = undef; $flds[8] = 0; Dump( \@flds ); print scalar @flds, "\n", '#'x5,"\n"; 1; } or warn $@; eval { my $value = "A\tB\tC\tD\tE\tF\t\t\t\t\t\t"; my @flds = split(/\t/, $value); Dump( \@flds ); $flds[16] = undef; $flds[8] = 0; print scalar @flds, "\n", '#'x5,"\n"; 1; } or warn $@; __END__
Re^3: split problem
by kcott (Archbishop) on Nov 30, 2016 at 00:17 UTC

    I've updated my post. The part about "past the end of the array" was completely wrong and is now stricken.

    I didn't originally try without the trailing tabs. I have now done so and it works fine for me too.

    — Ken

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1176872]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (5)
As of 2022-08-18 07:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?